akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

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

typedef long long ll;
typedef unsigned int uint;

int main(void)
{
    int N,K;
    cin >> N >> K ;
    string S;
    cin >> S;

    vector<int> V;

    int ret = 0;
    int count = 0;
    string presubS = S.substr(0,1);
    rep(i,S.length()){
        if (S.substr(i,1) == presubS ) {
            count++;
            //cout << "count" <<  count << endl;
        } else {
            //cout << "count" <<  count << "->push" << endl;
            presubS = S.substr(i,1);
            V.push_back(count);
            count = 1;
        }
    }
    if (count != 0) V.push_back(count);

    //rep(i,V.size()) cout << V.at(i) << ",";
    //cout << endl;

    int start = S.substr(0,1) == "0" ? 0 : 1;
    
    if (start == 1 && V.size() == 1) {
        cout << V.at(0) << endl;
        return 0;
    }

    int pre = 0;
    int max_v = -1;
    for(int i = start; i < V.size(); i+=2){

        if (i == start) {
            int t = i;
            if (t-1 >= 0) pre+= V.at(t-1);
            rep(j,K) {
                //cout << "t: " << t << "," << pre << endl;
                if (t < V.size()) pre += V.at(t);
                if (t+1 < V.size()) pre += V.at(t+1);
                t+=2;
                if (t >= V.size()) break;
            }
            //cout << pre << endl;
        } else {
            if (i-3 >= 0) {pre -= V.at(i-3);}
            if (i-2 >= 0) {pre -= V.at(i-2);}
            if (i+(K-1)*2 < V.size()) {pre += V.at(i+(K-1)*2);}
            if (i+(K-1)*2+1 < V.size()) {pre += V.at(i+(K-1)*2+1);}
            //cout << pre << endl;
        }

        if (pre > max_v) max_v = pre;
        //cout << "max" << max_v << endl;
    }

    cout << max_v << endl;

    return 0;
}


Measured memory_bytes: 1020
import sys
input = sys.stdin.readline
n = int(input())

Order = []
for _ in range(n):
    o = input().split()
    Order.append(o)

class Node:
    def __init__(self, key, value, left, right):
        self.key = key
        self.value = value
        self.left = left
        self.right = right
        
class BinaryTree:
    def __init__(self):
        self.root = None
        
    def insert(self, key, value):
        if self.root == None:
            node = Node(key, value, None, None)
            self.root = node
        else:
            node = Node(key, value, None, None)
            cmp_node = self.root
            while 1:
                if cmp_node.value > value and cmp_node.left == None:
                    cmp_node.left = node
                    break
                elif cmp_node.value > value and cmp_node.left != None:
                    cmp_node = cmp_node.left
                elif cmp_node.value < value and cmp_node.right == None:
                    cmp_node.right = node
                    break
                elif cmp_node.value < value and cmp_node.right != None:
                    cmp_node = cmp_node.right
        
def mid_search(node):
    if node == None:
        return
    mid_search(node.left)
    print('', node.key, end='')
    mid_search(node.right)
    
def fast_search(node):
    if node == None:
        return
    print('', node.key, end='')
    fast_search(node.left)
    fast_search(node.right)    
        
T = BinaryTree()
for o in Order:
    if o[0] == 'insert':
        T.insert(int(o[1]), int(o[1]))
    if o[0] == 'print':
        mid_search(T.root)
        print()
        fast_search(T.root)
        print()
        








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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int lli;

int main()
{
	fio;
	int a,b;
	cin>>a>>b;
	int n=b-a;
	for(int i=0;(i*(i+1))/2<499500;i++)
	{
		int x=(i*(i+1))/2;
		int y=((i+1)*(i+2))/2;
		if(y-x==n)
		{
			cout<<x-a<<endl;
			return 0;
		}
	}
	cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

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

long long M;
int N;
std::vector< std::vector< int > > g(100000);
long long ans[100001];
long long dp[100000];

void dfs(int cur,int par){
  dp[cur]=1;
  for(int dst:g[cur]){
    if(dst==par)continue;
    dfs(dst,cur);
    dp[cur]=dp[cur]*(dp[dst]+1)%M;
  }
}

void dfs2(int cur,int par){
  
  long long tmp=dp[cur];
  
  ans[cur]=1;
  for(int dst:g[cur]){
    ans[cur]=ans[cur]*(dp[dst]+1)%M;
  }
  
  int n=g[cur].size();
  std::vector<long long> l(n);
  std::vector<long long> r(n);
  
  l[0]=1;
  for(int i=1;i<n;++i){
    l[i]=l[i-1]*(dp[g[cur][i-1]]+1)%M;
  }
  r[n-1]=1;
  for(int i=n-2;i>=0;--i){
    r[i]=r[i+1]*(dp[g[cur][i+1]]+1)%M;
  }
  for(int i=0;i<n;++i){
    if(g[cur][i]==par)continue;
    dp[cur]=l[i]*r[i]%M;
    dfs2(g[cur][i],cur);
  }
  
  dp[cur]=tmp;
  

}

int main(){
  
  std::cin>>N;
  std::cin>>M;
  
  if(N==1){
    std::cout<<1<<std::endl;
    return 0;
  }
  
  for(int i=0;i<N-1;++i){
    int x,y;
    std::cin>>x;
    std::cin>>y;
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(0,-1);
  dfs2(0,-1);
  for(int i=0;i<N;++i){
    std::cout<<ans[i]<<std::endl;
  }
  return 0;
}


Measured memory_bytes: 19584
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int,int> PII;

bool myComp(PII x, PII y){
  return x.second < y.second;
}

int main(void){
  vector<PII> queries;
  int n, qnum;
  int ans,t;

  cin >> n >> qnum;
  for (int i=0; i<qnum; i++){
    int a,b;
    cin >> a >> b;
    queries.push_back(make_pair(a, b));
  }
  sort(queries.begin(), queries.end(), myComp);

  t = queries[0].second;
  ans = 1;
  for (int i=1; i<qnum; i++){
    if (queries[i].first >= t){
      ans++;
      t = queries[i].second;
    }
  }
  cout << ans << endl;

  return 0;
}


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

// マクロ
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

int main() {

	int x, y, z;

	cin >> x >> y >> z;

	cout << (z % max(x, y) == 0 ? z / max(x, y) : z / max(x, y) + 1) << endl;

}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    connect[a].append(b)
    connect[b].append(a)

color = [-1]*n
color[0] = 0
explored = {0}
next = deque([0])
exploring =deque()
Yes = True
explored.add(0)
while next:
    now = next.popleft()
    for a in connect[now]:
        if color[a] != -1:
            if color[a] != (color[now]+1)%2:
                Yes = False
            continue
        color[a] = (color[now]+1)%2
        next.append(a)
        
        
    '''
    exploring.extend(connect[now])
    while exploring:
        a = exploring.popleft()
        if color[a] == -1:
            color[a]=(color[now]+1)%2
        elif color[a] == (color[now]+1)%2:
            pass
        else:
            Yes = False
        if a not in explored:
            next.append(a)
        explored.add(a)
        '''
if Yes:
    s=sum(color)
    print(s*(n-s)-m)
else:
    print(n*(n-1)//2-m)

Measured memory_bytes: 26840
n,k = map(int,input().split())
a = list(map(int,input().split()))
d = {}
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
if len(d) <= k:
  print(0)
else:
  d = sorted(d.values())
  ans = 0
  for i in range(len(d)-k):
    ans += d[i]
  print(ans)

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define MOD 1000000007
const double PI=3.14159265358979323846;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> T Ceil(T a, T b){return (a+b-1)/b;}

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

int main() {
    cout<<fixed<<setprecision(10);

    string s; cin>>s;

    vint rui(s.size()+1,0);
    ll mul = 1;
    repr(i,s.size()){
        rui[i] = rui[i+1] + (s[i]-'0')*mul;
        rui[i] %= 2019;
        mul = (mul*10)%2019;
    }
    vint cnt(2019,0);
    for(auto e:rui) cnt[e]++;
    ll ans = 0;
    for(auto e:cnt) ans += e*(e-1)/2;
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 5172
n, m = gets.strip.split.map(&:to_i)
lrd = readlines.map {|line| line.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
lrd.each do |l, r, d|
  graph[l] << [r, d]
  graph[r] << [l, -d]
end

checker = Array.new(n+1)

def bfs(start, checker, graph)
  checker[start] = 0
  queue = [start]
  until queue.empty?
    current = queue.shift
    graph[current].each do |to, cost|
      if checker[to].nil?
        checker[to] = checker[current] + cost
        queue.push(to)
      else
        return false if checker[to] != checker[current] + cost
      end
    end
  end
  true
end

if (1..n).all? {|num| checker[num] || bfs(num, checker, graph) }
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 57536
using System;

class A{
	public static void Main(){

		string[] s =  Console.ReadLine().Split(' ');
		
		int[,] A = new int[ int.Parse(s[0]) ,int.Parse(s[1]) ];
		int[] b = new int[ int.Parse(s[1]) ];



		for (int i = 0; i<int.Parse(s[0]); i++) {
			string[] ins = Console.ReadLine ().Split (' ');
			for (int x = 0; x<int.Parse(s[1]); x++) {
				A [i, x] = int.Parse(ins [x]);
			}
		}

		for (int i=0; i<int.Parse(s[1]); i++) {
			b [i] = int.Parse (Console.ReadLine ());
		}

		for (int i = 0; i<int.Parse(s[0]); i++) {
			int c = 0;
			for (int x = 0; x<int.Parse(s[1]); x++) {
				c += (A [i, x] * b [x]);
			}
			Console.WriteLine (c);
		}


	}
}

Measured memory_bytes: 9396
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, t;
  cin >> n >> t;
  std::vector<int> time(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> time[i];
  }
  int64_t result = 0;
  for (int i = 0; i < n - 1; i++) {
    if (time[i + 1] - time[i] < t) {
      result += (time[i + 1] - time[i]);
    } else {
      result += t;
    }
  }
  result += t;
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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 ll = long long;

ll H, W;
std::string A[10];

int main()
{
  std::cin >> H >> W;
  
  rep( i, H )
    std::cin >> A[i];

  ll cnt = 0;

  rep( i, H ) rep( j, W )
    cnt += A[i][j] == '#';

  std::cout << (cnt == H+W-1 ? "Possible" : "Impossible") << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    int cur = a[0];
    ll ans = 1000;
    ll S = 1000;
    ll c = 0;
    bool flag = true;
    for(int i = 1; i < n; ++i){
        if(flag){
            if(a[i] <= cur) cur = a[i];
            else{
                ll buy = S / cur;
                c += buy;
                S -= buy * cur;
                cur = a[i];
                flag = false;
            }
        }
        else{
            if(a[i] >= cur) cur = a[i];
            else{
                S += cur * c;
                cur = a[i];
                c = 0;
                flag = true;
                chmax(ans, S);
            }
        }
    }
    if(c > 0)   S += c * a.back();
    chmax(ans, S);
    cout << ans << endl;
}

Measured memory_bytes: 3656
fun main(args: Array<String>) {
    val (a, b, c, d) = readInputLine().split(" ").map { it.toInt() }
    
    if (a * b > c * d) {
        println(a * b)
    } else {
        println(c * d)
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main(){
  vector<int> time(5);
  for(auto& x:time)
    cin >> x;
  int mudamax = -1;
  for(auto& x:time){
    int tmp;
    tmp = x;
    x = ((x+10-1)/10)*10;
    int muda = x-tmp;
    if(muda > mudamax)
      mudamax = muda;
  }
  int ans = accumulate(time.begin(),time.end(),0) - mudamax;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		double r;
		final double pi=3.141592653589;
		double s,l;
		Scanner sc=new Scanner(System.in);
		r=sc.nextDouble();
		s=r*r*pi;
		l=2*r*pi;
		System.out.println(String.format("%.6f",s)+" "+String.format("%.6f",l));
    }
}


Measured memory_bytes: 28184
s=input('')
if s==('SSS'):
    print(0)
elif s==('SSR') or s==('SRS') or s==('RSS'):
    print(1)
elif s==('RSR'):
    print(1)
elif s==('RRS') or s==('SRR'):
    print(2)
elif s==('RRR'):
    print(3)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
int ans;
char c1,c2;
int main()
{
    c1=getchar();c2=getchar();
    while(c2=='W'||c2=='B') {if(c1!=c2) ans++;c1=c2;c2=getchar();}
    printf("%d",ans);
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

ll check_keyence(string A){
  ll flag = 1;

  if (A[0] != 'k') {
    flag = 0;
  }

  if (A[1] != 'e') {
    flag = 0;
  }

  if (A[2] != 'y') {
    flag = 0;
  }

  if (A[3] != 'e') {
    flag = 0;
  }

  if (A[4] != 'n') {
    flag = 0;
  }

  if (A[5] != 'c') {
    flag = 0;
  }

  if (A[6] != 'e') {
    flag = 0;
  }


  return flag;
}

int main(int argc, char const *argv[]) {
  string S;
  std::cin >> S;

  ll len = S.size();
  ll flag = 0;

  for (size_t i = 0; i < 8; i++) {
    string e;
    for (size_t j = 0; j < 7; j++) {
      if (j < i) {
        e+= S[j];
      }else{
        e+=S[len - 7 + j];
      }
    }
    // std::cout << e << '\n';
    if (check_keyence(e) == 1) {
      flag = 1;
    }
  }

  if (flag == 1) {
    std::cout << "YES" << '\n';
  }else{
    std::cout << "NO" << '\n';
  }


  return 0;
}


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

using namespace std;

int main(int argc, char *argv[])
{
    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("in.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int hh, mm, ss, S;
    cin >> S;
    hh = S/3600;
    S = S%3600;
    mm = S/60;
    ss = S%60;
    cout << hh << ':' << mm << ':' << ss << endl;
    return 0;
}


Measured memory_bytes: 3216
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] c = new int[4];
        for (int i=0;i<n;i++){
            String s = sc.next();
            if (s.equals("AC"))c[0]++;
            else if (s.equals("WA"))c[1]++;
            else if (s.equals("TLE"))c[2]++;
            else if (s.equals("RE"))c[3]++;
        }
        System.out.println("AC x "+c[0]);
        System.out.println("WA x "+c[1]);
        System.out.println("TLE x "+c[2]);
        System.out.println("RE x "+c[3]);
    }
}


Measured memory_bytes: 58880
A, B, C, D, E, F = map(int, input().split())


def create_candidates(w_x, w_y, F):
    """
    >>> create_candidates(2,11,15)
    {0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 15}
    """
    candidates = set()
    for x in range(F):
        if w_x * x > F:
            break
        for y in range(F):
            a = w_x * x + w_y * y
            if a <= F:
                candidates.add(a)
            else:
                break
    return candidates


candidates_a = create_candidates(100 * A, 100 * B, F)
candidates_b = create_candidates(C, D, F)
candidates_a.remove(0)

max_dense = -float("inf")
max_a = -1
max_b = -1
for a in candidates_a:
    for b in candidates_b:
        if a + b <= F and b <= a * E / 100 and 100 * b / (a + b) > max_dense:
            max_dense = 100 * b / (a + b)
            max_a = a
            max_b = b

print(max_a + max_b, max_b)


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

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

    if (a<=b)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
    return 0;
}


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

int main(){
	int n, m, x, y; cin >> n >> m >> x >> y;
	vector<int> X(n), Y(m);
	for(int i = 0; i < n; ++i) cin >> X[i];
	for(int i = 0; i < m; ++i) cin >> Y[i];
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	for(int i = x+1; i <= y; ++i){
		if(X[n-1] < i && Y[0] >= i) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A
// Kruskal's algorithm
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

struct node { int root, rank; node(): root(-1), rank(1) {} };

int root(vector<node> &U, int r)
{
        int a = r;
        while (U[a].root >= 0)
                a = U[a].root;
        while (U[r].root >= 0) {
                int s = U[r].root;
                U[r].root = a;
                r = s;
        }
        return r;
}

bool same(vector<node> &U, int a, int b)
{
        int ra = root(U, a), rb = root(U, b);
        return ra == rb;
}

void unite(vector<node> &U, int a, int b) {
        int ra = root(U, a), rb = root(U, b);
        if (U[ra].rank < U[rb].rank) {
                U[ra].root = rb;
                U[rb].rank = max(U[rb].rank, U[ra].rank + 1);
        }
        else {
                U[rb].root = ra;
                U[ra].rank = max(U[ra].rank, U[rb].rank + 1);
        }
}

int main(int arg, char **argv)
{
        int V, E;
        cin >> V >> E;
        vector<pair<int, pair<int, int>>> A(E);
        for (int i = 0; i < E; i++) {
                int s, t, w;
                cin >> s >> t >> w;
                A[i] = { w, { s,  t } };
        }
        sort(A.begin(), A.end());
        vector<node> U(V);
        int sum = 0;
        for (auto &a: A) {
                if (same(U, a.second.first, a.second.second)) 
                        continue;
                sum += a.first;
                unite(U, a.second.first, a.second.second);
        }
        cout << sum << endl;
        return 0;
}

Measured memory_bytes: 4028
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
    long long A, B, C;
    cin >> A >> B >> C;
    long long answer = 0;
    answer += 2 * B;
    C -= B;
    B = 0;
    if(A < C){
        answer += A + 1;
    }else{
        answer += C;
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

i64 N, K; cin >> N >> K;
VI A(N), F(N); invec(A), invec(F);
sort(ALL(A));
sort(ALL(F), greater<i64>());
i64 maxi = 0;
rep(i, 0, N) maxi = max(maxi, A[i] * F[i]);

i64 ng = -1, ok = maxi;
while(ok - ng > 1){
    i64 mid = (ok + ng) / 2;

    // 全員のタイムを　mid  以下にするための最小修行回数
    i64 train = 0;
    rep(i, 0, N) if (A[i]*F[i] > mid) 
        train += A[i] - mid / F[i];

    if (train <= K) ok = mid;
    else ng = mid;
}


cout << ok << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 3456
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 40000; i > 1; i--) {
            if (i * i <= n) {
                System.out.println(i * i);
                return;
            }
        }
        System.out.println(1);
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;

int main()
{
	int i,j;
	long long N,V,a[1000],b[1000],c[1000],d[1000],ans=0;
	map<long long,long long> p;
	
	cin >> N >> V;
	for(i=0;i<=N-1;i++) cin >> a[i];
	for(i=0;i<=N-1;i++) cin >> b[i];
	for(i=0;i<=N-1;i++) cin >> c[i];
	for(i=0;i<=N-1;i++) cin >> d[i];
	
	for(i=0;i<=N-1;i++)
	{
		for(j=0;j<=N-1;j++)
		{
			p[a[i]+b[j]]++;
		}
	}
	for(i=0;i<=N-1;i++)
	{
		for(j=0;j<=N-1;j++)
		{
			ans+=p[V-c[i]-d[j]];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 127992
#include<stdio.h>
#include<string.h>

struct cell{
    struct cell *prev;
    struct cell *next;
    int flag;
}s[10000],*now;

int main(){
    int i,flag,m,n,tmp;
    char str[10000],t[10000];

    while(scanf("%d%d",&m,&n),m+n){
        tmp = m;
        for(i = 0;i <= m;i++){
            if(i)s[i].prev = &s[i - 1];
            else s[i].prev = &s[m - 1];
            if(i == m - 1)s[i].next = &s[0];
            else s[i].next = &s[i + 1];
            s[i].flag = 1;
        }
        now = &s[0];

        for(i = 1;i <= n;i++){
            scanf("%s",str);
            if(tmp == 1)continue;
            if(i % 3 == 0){
                if(i % 5 == 0){
                    flag = strcmp(str,"FizzBuzz");
                }else{
                    flag = strcmp(str,"Fizz");
                }
            }else if(i % 5 == 0){
                flag = strcmp(str,"Buzz");
            }else{
sprintf(t,"%d",i);
flag = strcmp(str,t);
/*
                if(i == atoi(str))flag=0;///////
                else flag=1;*/
            }
            if(flag){
                now -> prev -> next = now -> next;
                now -> next -> prev = now -> prev;
                now -> flag = 0;
                tmp--;
            }
            now = now -> next;
        }

        for(i = 0,flag = 0;i < m;i++){
            if(s[i].flag == 1){
                if(!flag){
                    printf("%d",i+1);
                    flag = 1;
                }else{
                    printf(" %d",i+1);
                }
            }
        }
        puts("");
    }
    return 0;
}

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

long long int N, M, a, S, ans;
unordered_map<long long, long long> m;

int main(){
    cin >> N >> M;
    m[0] = 1;
    for(int i = 1; i <= N; ++i){
        cin >> a;
        S += a;
        S %= M;
        ans += m[S]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {

    int D;
    cin >> D;
    if (D == 25) {
        cout << "Christmas" << endl;
    } else if (D == 24) {
        cout << "Christmas Eve" << endl;
    }if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    }if (D == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
 
using namespace std;

int main(){
    double W,H;
    cin>>W>>H;
    double X,Y;
    cin>>X>>Y;
    double harfe = 2.0;
    if(W/harfe == X && H/harfe == Y){
        // cout<<(double)(W*H/harfe)<<" "<<1<<endl;
        printf("%lf 1\n",W*H/harfe);
    }else printf("%lf 0\n",W*H/harfe);
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 *                 |
 * [-gcd prefix1-][i][-gcd suffix-] remove element i
 *                 |
 */

int gcd(const int a, const int b)
{ return b==0 ? a : gcd(b,a%b); }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        VI A(n+1);
        FOR(i,1,n+1)
            cin >> A[i];
        VI pre,suf; pre = suf = VI(n+2);
        FOR(i,1,n+1)
            pre[i] = gcd(pre[i-1],A[i]);
        FORR(i,n,0)
            suf[i] = gcd(suf[i+1],A[i]);
        int ans = 1;
        FOR(i,1,n+1)
            ans = max(ans, gcd(pre[i-1],suf[i+1]));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
// [Tag]
// #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <map>
using namespace std;

/** Type Define **/
typedef long long int           ll;
typedef pair<ll, ll>            p_ll;
typedef vector<string>          vs;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
typedef unsigned char           uchar;
typedef unsigned int            ui;
typedef unsigned long long int  ull;

constexpr int               INF = 1001001001;
constexpr long long         MOD = 1000000007LL;
/*************************************************/
int H, W;   //Height, Width
vs M;       //Map

int dh[4] = { 1, -1,  0,  0 };
int dw[4] = { 0,  0,  1, -1 };

int BFS(int h, int w) {
    queue <pair <int, int>> Q;    // 검사할 좌표를 Breath-first로 저장.
    vvi dist(H, vi(W, INF));    // 들르지 않은 좌표는 INF, BFS라서 최초 저장되는 값이 최소이므로 두번 비교필요없음.
    Q.push({ h, w });
    dist[h][w] = 0;
    int mx_dist(0);

    while (!Q.empty()) {
        pair<int, int> P = Q.front(); Q.pop();
        for (int i = 0; i < 4; i++) {
            int nh(P.first + dh[i]), nw(P.second + dw[i]);
            if (0 <= nh && nh < H && 0 <= nw && nw < W) {
                if (M[nh][nw] == '.' && dist[nh][nw] == INF) {
                    dist[nh][nw] = dist[P.first][P.second] + 1;
                    if (dist[nh][nw] > mx_dist)
                        mx_dist = dist[nh][nw];
                    Q.push({ nh, nw });
                }
            }
        }
    }

    return mx_dist;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    /*INPUT*/
    cin >> H >> W; // distinquish each cells by 0..(H*W-1) number.
    M.resize(H);
    for (auto& m : M) cin >> m;


    int ans(0);
    for(int h=0; h<H; h++)
        for (int w = 0; w < W; w++)
            if (M[h][w] == '.') ans = max(ans, BFS(h, w));
        

    cout << ans << '\n';

    /*Get_Answer*/
    //sol();
    return 0;
}

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

const double EPS = 1e-5;

double dp[51][5000];
int X, Y, Z, V[4];
int event[51], event_A[51];

int main(){
    while(1){
        scanf("%d%d%d",&X,&Y,&Z);
        if(!X)break;
        
        for(int i = 0; i < X; i++){
            cin >> V[i];
        }
        fill(event, event+51, 0);
        for(int i = 0; i < Z; i++){
            int a, b, c;
            cin >> a >> b >> c;
            event[a] = b, event_A[a] = c;
        }
        for(int i = 0; i <= Y; i++){
            fill(dp[i], dp[i]+5000, 0);
        }
        dp[0][0] = 1;
        for(int i = 0; i < Y; i++){
            for(int j = 0; j < 5000; j++){
                for(int k = 0; k < X; k++){
                    if(abs(dp[i][j])==0) continue;
                    int nx = min(Y, i + V[k]), mn = j;
                    if(event[nx] == 2) mn += event_A[nx];
                    else if(event[nx] == 3) mn = max(0, j-event_A[nx]);
                    else if(event[nx] == 1) nx = min(Y, nx + event_A[nx]);
                    dp[nx][mn] += dp[i][j] / X;
                }
            }
        }
        double ans = 0;
        for(int i = 0; i < 5000; i++) ans += i * dp[Y][i];
        printf("%d\n", (int)(ans+EPS));
    }
    return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))

int main(void){
	char S[5];
	scanf("%s",S);
	int ok=0;
	for(int i=0;i<3;i++){
		if(S[i]==S[i+1]){
			ok=1;
			printf("Bad");
			return 0;
		}
	}
	if(ok==0)printf("Good");
	return 0;
}

Measured memory_bytes: 128
k, x = map(int, input().split())

count = (k - 1) * 2 + 1
ans_arr = []

for i in range(x - (k - 1), x):
    ans_arr.append(str(i))

for i in range(x, x + k):
    ans_arr.append(str(i))

print(' '.join(ans_arr))


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

template <class T>
inline bool read(T &ret)
{
    char c;
    int sgn;
    if (c = getchar(), c == EOF)
    {
        return 0;
    }
    while (c != '-' && (c < '0' || c > '9'))
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    ret *= sgn;
    return 1;
}

template <class T>
inline void write(T x)
{
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

string sr1,sr2;

int main()
{
    cin>>sr1>>sr2;
    int ans=0;
    for(int i=0;i<sr1.size();i++)
        if(sr1[i]==sr2[i])
            ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  GVI(W, N);
  int sum = accumulate(ALL(W), 0);
  int now = 0;
  int ans = 1e9;
  FOR(t, N - 1) {
    now += W[t];
    ans = min(ans, abs(now - sum + now));
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX_M 1000000

bool f[MAX_M];

int main() {
  int s;
  cin >> s;
  int ans = 1;
  while (true) {
    if (f[s]) break;
    f[s] = true;
    ans++;
    if (s % 2)
      s = 3 * s + 1;
    else
      s /= 2;
  }
  cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  long long tmp, snuke = 0, ans = LONG_MAX;
  for(int i = 0; i < n - 1; i++) {
    snuke += a.at(i);
    tmp = sum - snuke;
    ans = min(abs(snuke - tmp), ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
using System;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
           while(true)
           {

                string Date = Console.ReadLine();
                string[] date = Date.Split(' ');
                int H = int.Parse(date[0]);
                int W = int.Parse(date[1]);

                if (H == 0 && W == 0)       //H,W??±???0????????????
                {
                    break;
                }
                for(int i = 1; i <= H; i++)
                {
                    for (int n = 1; n < W; ++n)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine("#");
                }
                Console.WriteLine();
            }
        }
    }
}

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

int main(){
  int N;
  string K;
  string output;
  cin >> N;
  cin >> K;
  if(K.size()>N){
    output = K.substr(0,N);
    output += "...";
  }else{
  output = K;
  }

  cout << output << endl;
  return 0;
}

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

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

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    string s; cin >> s;
    ll K; cin >> K;
    int N=s.size();
    for(int i=0;i<N;i++){
        ll res=('z'-s[i]);
        if(s[i]=='a') continue;
        if(K>=(res+1)){
            K-=(res+1);
            s[i]='a';
        }
    }

    ll res=K%26;
    for(int i=1;i<=res;i++){
        s[N-1]++;
        if((s[N-1]-'a')==26){
            s[N-1]='a';
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 3752
#include<iostream>
#include<cmath>
using namespace std;
int p,q;
int main(){
	while(cin>>p){
		q=0;
		for(int i=0;i<(p+1)/2;i++){
			if(i==0)q+=1;
			else{q+=(int)pow(3,i-1)*4;}
		}
		if(p%2==0)q+=pow(3,p/2-1);
		cout<<q<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)

typedef struct _pair_t
{
	string str;
	uint32_t num;
}pair_t;

class cfind
{
	const string& str;
public:
	cfind(const string& _str) :str(_str) {}
	bool operator()(const pair_t& arg)
	{
		if (arg.str != str) { return false; }
		return true;
	}
};


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

	vector<pair_t> s;
	pair_t pair;
	string str;
	for (uint32_t i = 0; i < n; i++) {
		cin >> str;
		auto ite = find_if(s.begin(), s.end(), cfind(str));
		if (ite == s.end()) {
			pair.str = str;
			pair.num = 1;
			s.push_back(pair);
			continue;
		}
		ite->num++;
	}

	uint32_t m;
	cin >> m;
	for (uint32_t i = 0; i < m; i++) {
		cin >> str;
		auto ite = find_if(s.begin(), s.end(), cfind(str));
		if (ite == s.end()) { continue; }
		if (ite->num) { ite->num--; }
	}

	uint32_t result = 0;
	for (uint32_t i = 0; i < s.size(); i++) {
		if (s[i].num <= result) { continue; }
		result = s[i].num;
	}

	printf("%d\n", result);
	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256
import java.util.*;

public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < 5; ++i)
		{
			int a = stdIn.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		for(int i = list.size() - 1; i > 0; --i)
		{
			System.out.print(list.get(i) + " ");
		}
		System.out.println(list.get(0));
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
int main()
{
    int n,d,x,a[110],i,j,s=0,m;
    scanf("%d%d%d",&n,&d,&x);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    s+=x;
    for(i=1;i<=n;i++)
    {
        j=1;m=a[i];
        s++;
        m=a[i]*j+1;
        j++;
        while(m<=d)
        {
            s++;
            m=a[i]*j+1;
            j++;
        }
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128
from collections import deque
n=int(input());G=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)


import numpy as np
def bfs(i):
    dist=[-1]*n
    dist[i]=0
    queue=deque([[i,j] for j in G[i]])
    while queue:
        now,to=queue.pop()
        if dist[to]!=-1 : continue
        dist[to]=dist[now]+1
        for p in G[to]:
            queue.appendleft([to,p])
    return np.argmax(dist), np.max(dist)

v,_ = bfs(0)
u,R= bfs(v)
R+=1

if R%3==2:
    print("Second")
else:
    print("First")

Measured memory_bytes: 80572
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
int n;
string a,b;
int main()
{
    cin>>n;
    cin>>a>>b;
    ll all=1;
    int now;
    int type;
    if(a[0]==b[0])
    {
        now=1;
        all=3;
        type=1;
    }
    else
    {
        now=2;
        all=6;
        type=2;
    }
    while(now<n)
    {
        if(a[now]==b[now])
        {
            if(type==1)
            {
                all=all*2%mod;
                type=1;
            }
            else
            {
                all=all%mod;
                type=1;
            }
        }
        else
        {
            if(type==1)
            {
                all=all*2%mod;
                type=2;
            }
            else
            {
                all=all*3%mod;
                type=2;
            }
        }
        now+=type;
    }
    cout << all << endl;
    //cout << "Hello world!" << endl;
    return 0;
}
/*
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int max_n=200005;
int a[max_n],b[max_n];
long long sum1[max_n],sum2[max_n];
long long max(long long a,long long b)
{
	return a>=b?a:b;
}
int main()
{
	int ans=0;
	long long n,m,k;cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum1[i]=sum1[i-1]+a[i];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>b[i];
		sum2[i]=sum2[i-1]+b[i];
	}
	for(int i=0;i<=n;i++)
	{
		if(sum1[i]<=k)
		ans=max(ans,i+upper_bound(sum2+1,sum2+1+m,k-sum1[i])-sum2-1);
		else break;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8288
import java.util.*;

public class Main{
  
  	public static void main(String[] args){
      	
      	Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      
      	if(N == 1){
          System.out.println("Hello World");
        }else if(N == 2){
          int A = sc.nextInt();
          int B = sc.nextInt();
          System.out.println(A+B);
        }
    }
}

Measured memory_bytes: 27036
#include<stdio.h>
#define MAX 40000
int N,P[MAX],F[MAX]={0},i,j,p=0,r;

int main()
{
	for(i=2;i<MAX;i++)if(!F[i]){P[p++]=i;for(j=i*2;j<MAX;j+=i)F[j]=1;}
	for(;scanf("%d",&N),N;)
	{
		r=0;
		for(i=0;P[i]&&P[i]<=N/2;i++)
			if(!F[N-P[i]])
				r++;
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 776
/*Never Give up*/
/*
Problem  :
Verdict     :
Time         :
Memory  :
*/
#include<bits/stdc++.h>
using namespace std;
#define sf(a)          scanf("%d",&a)
#define sff(a,b)         scanf("%d%d",&a,&b)
#define sfff(a,b,c)         scanf("%d%d%d",&a,&b,&c)
#define sffff(a,b,c,d)         scanf("%d%d%d%d",&a,&b,&c,&d)
#define sl(a)          scanf("%lld",&a)
#define sll(a,b)         scanf("%lld%lld",&a,&b)
#define slll(a,b,c)         scanf("%lld%lld%lld",&a,&b,&c)
#define sllll(a,b,c,d)         scanf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define sc(a) scanf("%c",&a)
#define sz(a)              a.size()
#define ff first
#define ss second
#define all(a)          a.begin(), a.end()
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pf         printf
#define pf1        pf("%d\n");
#define ll           long long
#define ull        unsigned long long
#define pb        push_back
#define vi           vector<int>
#define vl           vector<ll>
#define li            list<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define mp         map
#define nl         printf("\n")
#define en        pf("Entered\n")
#define en1      pf("Entered 2\n")
#define gcd(a,b) __gcd(a,b)

// priority_queue<int, vector<int>, greater<int> > Q;//for smaller values

#define MAX    100000

//int dx[] = {-1, 0, 1, 0};
//int dy[] = {0, 1, 0, -1};
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/

//'A'=65,'Z'=90 'a'=97 'z'=122 '0'=48
mp<int, bool>cc;
ull arr[MAX];
int main()
{
int a,b;
sff(a,b);
for(int i=1;i<=1000;i++){
     arr[i]=(i*(i+1))/2;
    cc[arr[i]]=true;
}
for(int i=1;i<1000;i++)
{
    if(arr[i]>=a)
    {
        int xx=arr[i]-a;
        if(cc[xx+b]&&arr[i+1]==xx+b)
        {
            cout<<xx<<endl;
            return 0;
        }
    }
}


return 0;
}
/*
Ref:
*/



Measured memory_bytes: 384
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    ab = [list(map(int, (str(i) + " " + input().rstrip('\n')).split())) for i in range(n)]
    ab.sort(reverse=True)
    cnt = 0
    for i, a, b in ab:
        if (a + cnt) % b != 0:
            cnt += (b - (a + cnt) % b)
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 56540
f=lambda:map(int,input().split())
N,M=f()
q=[list(f()) for _ in [0]*M]
res=-1
A=list(range(10**(N-1),10**N))
if N==1:A=[0]+A
for i in A:
    for j in range(M):
        if str(i)[q[j][0]-1]!=str(q[j][1]):
            break
    else:
        res=i
        break
print(res)

Measured memory_bytes: 9148
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
typedef pair<ll,ll>pll;
const  ll MAX=100000000;
int main()
{



     ll n;

     cin>>n;

   vector<pll>v;

   ll cnt=0;

   while(n%2==0)
   {
       n/=2;
       cnt++;
   }
   if(cnt)v.eb(2,cnt);

   cnt=0;

   for(ll i=3;i*i<=n;i+=2)
   {
       cnt=0;

       while(n%i==0)
       {
           n/=i;
           cnt++;
       }

       v.eb(i,cnt);
   }
   if(n>1)v.eb(n,1);

   ll ans=0;

  for(auto x:v)
  {
      ll j=2;

      for(ll i=1;i<=x.se;)
      {
        ans++;
        i+=j;
        j++;

      }

  }

  cout<<ans<<endl;




}



Measured memory_bytes: 11536
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    String[] s = new String[N];
    for(int i = 0;i < N;i++){
      s[i] = sc.next();
    }
    Arrays.sort(s);
    for(int i = 0;i < N;i++){
      System.out.print(s[i]);
    }
  }
}


Measured memory_bytes: 23120