akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  int anser = max(a, b) - min(a + w, b + w);
  if (anser < 0) {
    anser = 0;
  }
  cout << anser << endl;
  return 0;
}

Measured memory_bytes: 256
# insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
def InsertionSort(A, N):
   for i in range(N):
      v = A[i]
      j = i - 1
      while(j >= 0 and A[j] > v):
         A[j+1] = A[j]
         j-=1
      A[j+1] = v
      print(*A)

N = int(input())
A = list(map(int, input().split())) # 「1 2 3…」のような配列入力
# print(*A) # リストの出力を数字とスペースのみにしてくれる
InsertionSort(A, N)


Measured memory_bytes: 5980
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>
#include <functional>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;

vector<vector<int> > opposite_graph(vector<vector<int> > const & g) {
    int n = g.size();
    vector<vector<int> > h(n);
    repeat (i, n) for (int j : g[i]) h[j].push_back(i);
    return h;
}
pair<int, vector<int> > decompose_to_strongly_connected_components(vector<vector<int> > const & g, vector<vector<int> > const & g_rev) {
    int n = g.size();
    vector<int> acc(n); {
        vector<bool> used(n);
        function<void (int)> dfs = [&](int i) {
            used[i] = true;
            for (int j : g[i]) if (not used[j]) dfs(j);
            acc.push_back(i);
        };
        repeat (i,n) if (not used[i]) dfs(i);
        whole(reverse, acc);
    }
    int size = 0;
    vector<int> component_of(n); {
        vector<bool> used(n);
        function<void (int)> rdfs = [&](int i) {
            used[i] = true;
            component_of[i] = size;
            for (int j : g_rev[i]) if (not used[j]) rdfs(j);
        };
        for (int i : acc) if (not used[i]) {
            rdfs(i);
            ++ size;
        }
    }
    return { size, move(component_of) };
}
vector<vector<int> > decomposed_graph(int size, vector<int> const & component_of, vector<vector<int> > const & g) {
    int n = g.size();
    vector<vector<int> > h(size);
    repeat (i, n) for (int j : g[i]) {
        if (component_of[i] != component_of[j]) {
            h[component_of[i]].push_back(component_of[j]);
        }
    }
    repeat (k, size) {
        whole(sort, h[k]);
        h[k].erase(whole(unique, h[k]), h[k].end());
    }
    return h;
}

constexpr int mod = 1e9+7;
int main() {
    int n, m; scanf("%d%d", &n, &m);
    vector<vector<int> > g(n);
    repeat (i, m) {
        int s, d; scanf("%d%d", &s, &d); -- s; -- d;
        g[s].push_back(d);
    }
    int size; vector<int> component_of; tie(size, component_of) = decompose_to_strongly_connected_components(g, opposite_graph(g));
    vector<vector<int> > h = decomposed_graph(size, component_of, g);
    vector<vector<int> > h_rev = opposite_graph(h);
    int result = 1;
    function<int (int)> go = [&](int i) {
        int acc = 1;
        for (int j : h_rev[i]) {
            acc = acc *(ll) go(j) % mod;
        }
        return acc + 1;
    };
    repeat (i, size) {
        if (h[i].empty()) {
            result = result *(ll) go(i) % mod;
        }
    }
    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 2916
def main():
	N, M = map(int, input().split())
	S = [[] for _ in range(M)]

	for i in range(M):
		s = list(map(int, input().split()))
		S[i] = s[1:]
	P = list(map(int, input().split()))
	num = 2**N
	ans = 0
	for i in range(num):
		cur = list(P)
		for j in range(M):
			for e in S[j]:
				if (i >> e-1)&1 == 1:
					cur[j] += 1
		if all(x%2==0 for x in cur):
			ans += 1
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
N = int(input())
A = input().split()
A = [int(x) for x in A]
B = input().split()
B = [int(x) for x in B]

c = 0
for i in range(N):
  if A[i] >= B[i]:
    c += B[i]
  else:
    c +=A[i]
    x = A[i+1] - (B[i]-A[i])
    if x >= 0:
      c += B[i]-A[i]
      A[i+1] = x
    else:
      c += A[i+1]
      A[i+1] = 0
print(c)
    

Measured memory_bytes: 19648
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	d := make([]int, n)
	for i := 0; i < n; i++ {
		d[i] = nextInt()
	}

	sum := 0
	for l := 0; l < n-1; l++ {
		for r := l+1; r < n; r++ {
			sum += d[l] * d[r]
		}
	}


	fmt.Println(sum)
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdint>

int main() {
  int N, T;
  scanf("%d %d", &N, &T);

  intmax_t res=0, last;
  scanf("%jd", &last);

  if (N == 1) {
    printf("%d\n", T);
    return 0;
  }

  for (int i=1; i<N; ++i) {
    int t;
    scanf("%d", &t);

    if (last + T > t) {
      res += t - last;
    } else {
      res += T;
    }

    last = t;
  }

  res += T;
  printf("%jd\n", res);
  return 0;
}


Measured memory_bytes: 128
import sys
n = int(input())
a = []
count = [0 for _ in range(200001)]
for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(200000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))




Measured memory_bytes: 14004
A, B, C, D = gets.split("").map(&:to_i)

def plus_minus(candidate, next_number)
  next_candidate = [] 
  candidate.each do |i|
  next_candidate << i + next_number
  next_candidate << i - next_number
  end
  return next_candidate
end

candidate_untilB = plus_minus([A], B)
candidate_untilC = plus_minus(candidate_untilB, C)
candidate_untilD = plus_minus(candidate_untilC, D)

index_7 = candidate_untilD.index(7)

def plusOrMinus(oneOrZero)
  if oneOrZero == 1
    return "-"
  end
  if oneOrZero == 0
    return "+"
  end
end

divided3 = index_7
remainder3 = divided3 % 2
plusOrMinus3 = plusOrMinus(remainder3)

divided2 = divided3 / 2
remainder2 = divided2 % 2
plusOrMinus2 = plusOrMinus(remainder2)

divided1 = divided2 / 2
remainder1 = divided1 % 2
plusOrMinus1 = plusOrMinus(remainder1)

answer = A.to_s + plusOrMinus1 + B.to_s + plusOrMinus2 + C.to_s + plusOrMinus3 + D.to_s
puts answer + "=7"

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

int main()
{
    int n,m;
    std::cin>>n>>m;
    std::vector<int> x(m);
    for(int i=0;i<m;i++)std::cin>>x[i];
    std::sort(x.begin(),x.end());
    std::vector<int> k(m-1); //各座標の間をとる(これの和を最小化する)
    for(int i=1;i<m;i++){k[i-1] = x[i]-x[i-1];}
    std::sort(k.begin(),k.end());
    int ans = 0;
    for(int i=0;i<m-n;i++){
        ans += k[i];
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 
vector<int> h[100001];
int used[100001]={};
const int t0=2, z=0;
int keisan(int n0,int m,int l,int k){
    int t=max(z,k-min(l,t0)-m)%MOD;
    int co=0;

    for(int i=0;i<h[n0].size();i++){
        if(used[h[n0][i]]==0){
            used[h[n0][i]]=1;
             t=(t*keisan(h[n0][i],co,l+1,k))%MOD;
             co++;
        }
       
            }
    return t;
}
 
signed main(){
    int n,k;
    cin>>n>>k;
    
    int a,b;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        if(a>b)swap(a,b);
   
        h[a-1].push_back(b-1);
        h[b-1].push_back(a-1);
    }
    used[0]=1;
   cout<<keisan(0,0,0,k);
    return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
int main()
{
int r,g,b,sum;
cin>>r>>g>>b;
if(((r*100)+(g*10)+b)%4==0){
    cout<<"YES";}
    else
        cout<<"NO";


return 0;
}


Measured memory_bytes: 256
INF = 10**10
n,m,R = map(int,input().split())
r=list(map(int,input().split()))
for i in range(R):
    r[i]-=1
d = [[INF]*n for i in range(n)] 
# 入力
for i in range(m):
    a,b,c = map(int,input().split())
    a,b = a-1, b-1
    d[a][b] = c
    d[b][a] = c # 無向グラフ
for i in range(n):
    d[i][i] = 0

def FW():
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
FW()
from itertools import permutations, combinations
ans=INF
for v in permutations(r):
    tmp=0
    for i in range(R-1):
        tmp+=d[v[i]][v[i+1]]
    ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 46568
num_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(num_list[n-1])


Measured memory_bytes: 2940
read = lambda: list(map(int, input().split()))
card = read()
k = int(input())
for _ in range(k):
    if card[0] >= card[1]:
        card[1] *= 2
    elif card[1] >= card[2]:
        card[2] *= 2

if card[0] < card[1] < card[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

ll cal(ll n,ll m){
    ll res=0;
    for(ll i=m;i>=1;i--){
        ll k=powl(n,(dd)1/i);
        if((ll)powl(k,i)==n){
            n/=k;
            res+=k;
        }/*else if((ll)powl(k,i)>n){//ないはず
            
        }*/else{
            n=(n+k)/(k+1);
            res+=(k+1);
        }
    }
    return res;
}

int main(){fastio
    ll n,a;cin>>n>>a;
    ll ans=inf;
    rep(m,1,42){
        ll sum=cal(n,m);
        //cout<<sum<<endl;
        Min(ans,sum+(m-1)*a);
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

class Procon {
    static void Main (string[] agrs) {
        var N = Int();
        var M = Int();

        var maxL = 0;
        var minR = 10000000;
        for ( int i = 0; i < M; i++ ) {
            var L = Int();
            var R = Int();
            maxL = Math.Max(maxL, L);
            minR = Math.Min(minR, R);
        }

        if (maxL > minR) {
            Console.WriteLine(0);
        } else {
            Console.WriteLine(minR - maxL + 1);
        }
    }

    static string String () => Scanner.nextString ();
    static int Int () => int.Parse (Scanner.nextString ());
    static long Long () => long.Parse (Scanner.nextString ());
    static double Double () => double.Parse (Scanner.nextString ());
    static char[] Chars () => String ().ToCharArray ();
    static string[] Strings () => Console.ReadLine ().Split (' ');
    static int[] Ints () => Strings ().Select (v => int.Parse (v)).ToArray ();
    static long[] Longs () => Strings ().Select (v => long.Parse (v)).ToArray ();
    static double[] Doubles () => Strings ().Select (v => double.Parse (v)).ToArray ();
    const int M = 1000000007;
}

class PriorityQueue<T> where T : IComparable<T> {
    public T[] heap;
    public int size;
    public int sign;
    public PriorityQueue (int N, bool descend = false) {
        heap = new T[N];
        sign = 1;
        if (descend) sign = -1;
    }
    public int Compare (T x, T y) {
        return x.CompareTo (y) * sign;
    }
    public void Push (T x) {
        int i = size++;
        while (i > 0) {
            int p = (i - 1) / 2;
            if (Compare (x, heap[p]) >= 0) {
                break;
            }
            heap[i] = heap[p];
            i = p;
        }
        heap[i] = x;
    }
    public T Pop () {
        T ret = heap[0];
        T x = heap[--size];
        int i = 0;
        while (i * 2 + 1 < size) {
            int a = i * 2 + 1;
            int b = i * 2 + 2;
            if (b < size && Compare (heap[a], heap[b]) > 0) {
                a = b;
            }
            if (Compare (heap[a], x) >= 0) {
                break;
            }
            heap[i] = heap[a];
            i = a;
        }
        heap[i] = x;
        return ret;
    }
    public int Count () {
        return size;
    }
}

class Scanner {
    static string[] s = new string[0];
    static int i = 0;
    static int max_i = 0;
    static public string nextString () {
        if (i >= s.Length) {
            s = Console.ReadLine ().Split (' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0) {
                return "";
            }
            return s[i++];
        }
        return s[i++];
    }
}


Measured memory_bytes: 17340
n,m = map(int, input().split())

h = [int(x) for x in input().split()]

n_list = [1]*n

for i in range(m):
    a,b = map(int, input().split())
    if h[a-1]  > h[b-1]:
        n_list[b-1] = 0
    elif h[b-1] > h[a-1]:
        n_list[a-1] = 0
    elif h[b-1] == h[a-1]:
        n_list[a-1] = 0
        n_list[b-1] = 0
print(sum(n_list))


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;

int digit(int n)
{
    int res=0;
    while(n){
        int m=n%10;
        res+=m;
        n/=10;
    }
    return res;
}



int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n;

	(n%digit(n)==0)?cout<<"Yes"<<endl:cout<<"No"<<endl;



}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            double x1 = double.Parse(s[0]);
            double y1 = double.Parse(s[1]);
            double x2 = double.Parse(s[2]);
            double y2 = double.Parse(s[3]);

            double a = x2 - x1;
            double b = y2 - y1;

            double d = Math.Sqrt(a * a + b * b);
            d = Math.Round(d, 8);
            Console.WriteLine(d);
        }
    }
}

Measured memory_bytes: 9572
/*input
1
11 11
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, a, b; cin >> k >> a >> b;
    for(int i = a; i < b + 1; i++) if(!(i % k))
    {
    	cout << "OK";
    	return 0;
    }
    cout << "NG";

    return 0;
}

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

int main(){
 
  int N, M, X, i, j, bit, p_min = 1200001;
  cin >> N >> M >> X;
  vector<vector<int>> A(N, vector<int>(M, 0));
  vector<int> C(N);
  
  //入力
  for(i = 0; i < N; i++){
    cin >> C.at(i);
    for(j = 0; j < M; j++){
      
      cin >> A.at(i).at(j);
    }
  }
  
  //bit全探索
  for(bit = 0; bit < (1 << N); bit++){
    
    int p_sum = 0, flag = 0;
    vector<int> S;
    vector<int> A_sum(M);
    
    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        S.push_back(i);
      }
    }
    
    for (i = 0; i < S.size(); i++) {
      for(j = 0; j < M; j++){
      
        A_sum.at(j) += A.at(S.at(i)).at(j);
      }
      p_sum += C.at(S.at(i));
    }
    
    for(i = 0; i < M; i++){
     
       if(A_sum.at(i) < X) {
         flag = 1;
       }
      
    }
    if(p_sum < p_min && flag == 0) p_min = p_sum;
  }
  
  //結果の表示
  if (p_min == 1200001){
    cout << -1 << endl;
    return 0;
  }
  cout << p_min << endl;
  return 0;
}

Measured memory_bytes: 3636
N = int(input())
L = list(map(int, input().split()))
num = 0
for i in range(N-2):
  for j in range(i, N-1):
    for k in range(j, N):
      a = L[i]
      b = L[j]
      c = L[k]
      if a != b and a != c and b != c:
        if a+b > c and a+c > b and b+c > a:
          num += 1
          
print(num)

Measured memory_bytes: 9208
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();

        if (k * 500 >= x)
            System.out.println("Yes");
        else 
            System.out.println("No");
    }
}

Measured memory_bytes: 21332
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

struct P {
    int y, x;
    this (int _y, int _x) {
        y = _y; x = _x;
    }
}

struct Q {
    P from, to;
    this (P f, P t) {
        from = f; to = t;
    }
}

void main() {
    int h, w; readf("%d %d\n",&h,&w);
    int[][] a;
    foreach (i; 0..h)
        a ~= reads();

    Q[] ans;
    foreach (y; 0..h-1) foreach (x; 0..w) {
        if (!(a[y][x] & 1)) continue;
        a[y][x]--;
        a[y+1][x]++;
        ans ~= Q(P(y, x), P(y+1, x));
    }

    int y = h - 1;
    foreach (x; 0..w-1) {
        if (!(a[y][x] & 1)) continue;
        a[y][x]--;
        a[y][x+1]++;
        ans ~= Q(P(y, x), P(y, x + 1));
    }

    writeln(ans.length);
    foreach (q; ans) {
        writefln("%(%s %)", [q.from.y, q.from.x, q.to.y, q.to.x]
                .map!("a+1")
                .array);
    }
}

Measured memory_bytes: 17916
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

// こちらを参考にした
// https://drken1215.hatenablog.com/

func main() {
	var A int
	var B float64
	fmt.Scan(&A, &B)
	B100 := int(math.Round(B * 100))
	ans := (A * B100) / 100
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 1856
#include <stdio.h>

int main(){
  
  int N,M,P,X[1000],Xsum,kake,win,i;
  
  kake=0;
  Xsum=0;
  win=0;
  while(1){
    scanf("%d%d%d",&N,&M,&P);
    if(N==0 && M==0 &&P==0)break;
    for(i=0;i<N;i++)X[i]=0;
    for(i=1;i<=N;i++){
      scanf("%d",&X[i]);
      Xsum += X[i];
      if(M==i)win=X[i];
    }
    if(win==0)printf("0\n");
    else{ kake=(Xsum*100-(Xsum*100*P/100))/win;
      printf("%d\n",kake);
    }
    Xsum=0;
  }
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int M;
string S;
int L;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	int ret=0;
	FORR(c,S) {
		if(c=='g') {
			if(L) {
				L--;
				ret++;
			}
			else {
				L++;
			}
		}
		else {
			if(L) {
				L--;
			}
			else {
				L++;
				ret--;
			}
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 512
import itertools
N = int(input())
L = list(map(int, input().split()))

cnt = 0
for i in itertools.combinations(L, 3):
    # print(i)
    # print(i[0],i[1],i[2])

    if i[0] == i[1] or i[0] == i[2] or i[1] == i[2]:
        continue

    ij = i[0]+i[1] > i[2]
    ik = i[0]+i[2] > i[1]
    jk = i[1]+i[2] > i[0]

    if ij + ik + jk == 3:
        cnt += 1

print(cnt)

Measured memory_bytes: 9192
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val n1 = n % 10
    if(n1 == 2 || n1 == 4 || n1 == 5 || n1 == 7 || n1 == 9){
        println("hon")
    }else if(n1 == 0 || n1 == 1 || n1 == 6 || n1 == 8){
        println("pon")
    }else{
        println("bon")
    }
}


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

int main() {
    int n, t, a;
    cin >> n >> t >> a;

    int h, index = 0;
    double min_t = 1000, tmp;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (abs(a - (t - h * 0.006)) < min_t) {
            index = i + 1;
            min_t = abs(a - (t - h * 0.006));
        }
    }

    cout << index << endl;

    return 0;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod=1e9+7;

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

signed main()
{   
    string s; cin>>s;
    int N=s.size();
    reverse(s.begin(),s.end());

    int ans=0;
    int cnt=0;
    for(int i=N-1;i>=0;i--){
        if(s[i]=='0') continue;
        int tmp=mod_pow(2,cnt)*mod_pow(3,i)%mod;
        ans=(ans+tmp)%mod;
        cnt++;
    }
    ans=(ans+mod_pow(2,cnt))%mod;
    cout<<ans<<endl;
}   


Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int num[110000];

int main(){
  bool flag=false,flag2=false;;
  vector<int> S,T;
  string s,t;
  cin>>s>>t;

  for(int i=0;i<(int)s.size();i++){
    S.push_back(s[i]-'a');
  }

  for(int i=0;i<(int)t.size();i++){
    T.push_back(t[i]-'a');
  }

  sort(S.begin(),S.end());
  sort(T.begin(),T.end(),greater<int>());

  for(int i=0;i<(int)min(S.size(),T.size());i++){
    if(S[i]<T[i]){
      flag=true;
      break;
    }else if(S[i]>T[i]){
      flag2=true;
      break;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else if(flag2){
    cout<<"No"<<endl;
  }else{
    if(S.size()<T.size()){
      cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 888
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        boolean b = false;
        while(true){
        if(cal(x)) break;
        x++;
        }
        System.out.println(x);
    }
    public static boolean cal(int n){
    // nが1以下ならfalse
    if(n<=1){
        return false;
    }
    // nが2または3ならtrue
    if(2==n || 3==n){
        return true;
    }
    // nが2の倍数ならfalse
    if(0==n%2){
        return false;
    }
    // nの平方根を整数で取得(5なら2, 10なら3)
    int square_root = (int)Math.sqrt((double)n);
    // nがnの平方根以下の、3以上の奇数(3,5,7,9,11,...)で1回でも割れたらfalse
    for(int i=3; i<=square_root; i+=2){
        if(0==n%i){
            return false;
        }
    }
    // 上記すべて回避したらtrue
    return true;
    }
}


Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dh[8] = {-1,-1,-1,0,1,1,1,0};
int dw[8] = {-1,0,1,1,1,0,-1,-1};
int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    rep(i, h) {
         rep(j, w) {
             if(s[i][j] == '.') {
                 int cnt = 0;
                 rep(d, 8) {
                     int nh = i + dh[d];
                     int nw = j + dw[d];
                     if(nh<0||nw<0||nh>=h||nw>=w) continue;
                     if(s[nh][nw]=='#') cnt++;
                 }
                 s[i][j] = '0' + cnt;
             }
         }
    }
    rep(i, h) cout << s[i] << endl;
}


Measured memory_bytes: 256
import sys
from collections import Counter
import time

class Osa_k:
    def __init__(self, n):
        self.n = n
        self.min_factor = [int(x) for x in range(n+1)]
        
        self.is_prime = [True] * (self.n + 1)
        self.is_prime[0] = False
        self.is_prime[1] = False
        for j in range(4, self.n+1, 2):
            self.is_prime[j] = False
            self.min_factor[j] = 2
        for i in range(3, int(self.n**0.5) + 1, 2):
            if not self.is_prime[i]:
                continue
            for j in range(i * 2, self.n + 1, i):
                self.is_prime[j] = False
                if self.min_factor[j] >= i:
                	self.min_factor[j] = i
        


    def calculate(self, x):
        ans = []
        while x > 1:
            key = self.min_factor[x]
            while x%key == 0:
                ans.append(key)
                x //= key
        counter = Counter(ans)
        return counter

def main():
    input = sys.stdin.readline
    mod = pow(10,9)+7
    n = int(input())
    a = [int(x) for x in input().split()]
    prime_list = dict()
    osa_k = Osa_k(max(a))
    for i in range(n):
        primes = osa_k.calculate(a[i])
        for key, value in primes.items():
            if key in prime_list:
                if prime_list[key] < value:
                    prime_list[key] = value
            else:
                prime_list[key] = value
              
    L = 1
    for key, value in prime_list.items():
        L *= pow(key, value, mod)
        L %= mod
        
    ans = 0
    for i in range(n):
        ans += (L*pow(a[i], mod-2, mod))%mod
        ans %= mod
    print(ans)

    

if __name__ == "__main__":
    main()

Measured memory_bytes: 51944
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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


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

	ll x; cin >> x;
	ll  ans = (x / 11)*2;
	if (x%11 > 0) ans++; 
	if (x%11 > 6) ans++;
	cout << ans << endl;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

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

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}

int calc(string &s){
  int ret = 0;
  for(int i= 0; i < s.length(); i++){
    int tmp = 0;
    int start = i;
    for(int j = 0; j < s.length(); j++){
      if(s[j] == s[i+j]){
        tmp++;
      }else{
        tmp = 0;
        start = i+j+1;
      }
      if(j<start){
        ret = max(ret, tmp);
      }else{
        tmp=0;
        start = i+j+1;
      }
    }
  }

  return ret;
}

void solve(){
  int n ;
  string s;
  cin >> n;
  cin >> s;
  cout << calc(s) << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
   ll n,m=hell;
   cin>>n;
   ll a[n];
   for(int i=0;i<n;i++)
   cin>>a[i];
   for(ll i=1;i<=100;i++)
   {
       ll y=0;
       for(int j=0;j<n;j++)
       {
           y=y+(a[j]-i)*(a[j]-i);
       }
       m=min(m,y);
   }
   cout<<m;}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int n,m;
	cin >> n >> m;
	int cnt[100] = {};
	rep(i,m){
		int a,b;
		cin >> a >> b;
		cnt[a-1]++;
		cnt[b-1]++;
	}
	rep(i,n)cout << cnt[i] << endl;



	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc061.contest.atcoder.jp/tasks/abc061_b

Measured memory_bytes: 3612
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << endl
template <class T>
using VV = vector<vector<T>>;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}
#pragma endregion

int main() {
  int A, B;
  cin >> A >> B;
  int ans = max(A - 2 * B, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N; cin >> N;
    vector<int> B;
    for (int i = 0; i < N-1; i++)
    {
        int b; cin >> b;
        B.push_back(b);
    }
    long ans = B[0]+B[N-2];
    for (int i = 1; i < N-1; i++)
    {
        ans += min(B[i-1], B[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(char a, char b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	vint b(n);
	int x;
	rep(i, n) {
		cin >> x;
		if (i == 0)a[i] = x;
		else a[i] = a[i - 1] + x;
	}
	rep(i, n) {
		cin >> b[i];
	}
	for (int i = n - 1;0 <= i;i--) {
		if (i == n - 1)continue;
		b[i] += b[i + 1];
	}
	int mx = 0;
	rep(i, n) {
		mx = max(a[i] + b[i], mx);
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n;
  cin >> n;
  vector<pair<ll,ll>> vec[n];
  rep(i,n-1){
    cin >> t1 >> t2 >> t3;
    vec[t1].emplace_back(make_pair(t3,t2));
    vec[t2].emplace_back(make_pair(t3,t1));
  }
  vector<ll> visited(n,0);
  vector<ll> dis(n,0);
  priority_queue<pair<ll,ll>> pq;
  pq.push(make_pair(0,0));
  pair<ll,ll> pa;
  while(!pq.empty()){
    pa = pq.top();
    pq.pop();
    t1 = pa.first;
    t2 = pa.second;
    if(!visited[t2]){
      visited[t2] = 1;
      dis[t2] = -t1;
      for(auto itr:vec[t2]){
        pq.push(make_pair(t1 - itr.first,itr.second));
      }
    }
  }
  ll piv = -1;
  ll pivscore = 0;
  rep(i,n){
    if(pivscore < dis[i]){
      pivscore = dis[i];
      piv = i;
    }
  }
  ll ans = 0;
  rep(i,n){
    visited[i] = 0;
    dis[i] = 0;
  }
  pq.push(make_pair(0,piv));
  while(!pq.empty()){
    pa = pq.top();
    pq.pop();
    t1 = pa.first;
    t2 = pa.second;
    if(!visited[t2]){
      visited[t2] = 1;
      dis[t2] = -t1;
      for(auto itr:vec[t2]){
        pq.push(make_pair(t1 - itr.first,itr.second));
      }
    }
  }
  rep(i,n){
    if(ans < dis[i]){
      ans = dis[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12700
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

struct BIT {
	vector<int> bit;

	BIT(int n) : bit(n+1) {}

	int sum(int i) {
		int s = 0;
		while(i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i,int x) {
		while(i <= bit.size()) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int main() {
	int n, m;
	while(cin >> n >> m) {
		if(n == 0 && m == 0) break;

		BIT bit(100005);
		rep(i, n-1) {
			int a;
			cin >> a;

			bit.add(i+1, a);
		}

		int cur = 1;
		ll ans = 0;

		rep(i, m) {
			int a;
			cin >> a;

			ans += abs(bit.sum(cur+a-1) - bit.sum(cur-1));
			ans %= 100000;
			// cout << "i:" << i << " cur:" << cur << " ans:" << ans << " cur+a:" << bit.sum(cur+a-1) << " ," << bit.sum(cur-1) << " add:" << bit.sum(cur+a-1) -bit.sum(cur-1) << endl;
			cur += a;
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1536
N, x = map(int,input().split())
a = sorted(list(map(int,input().split())))

for k in range(N):
    x -= a[k]
    if x < 0:
        print(k)
        exit(0)
    if x == 0:
        print(k+1)
        exit(0)
if x > 0:
    print(N-1)
else:
    print(N)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}

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

template<class Monoid>
class SegmentTree {
private:
    using T = typename Monoid::T;
    const size_t n;
    vector<T> d;

    void build(){
        for(size_t b = n - 1; b > 0; b--) d[b] = Monoid::op(d[b << 1], d[b << 1 | 1]);
    }

public:
    SegmentTree(size_t n)
        : n(n), d(2 * n, Monoid::identify()) {}

    template<typename InputItr>
        SegmentTree(InputItr first, InputItr last)
        : n(distance(first, last)), d(2 * n, Monoid::identify()){
            copy(first, last, next(d.begin(), n));
            build();
        }

    /* set one value */
    void modify(size_t k, T v){
        for(d[k += n] = v; k > 1; k >>= 1) d[k >> 1] = Monoid::op(d[k], d[k ^ 1]);
    }

    /* return [l, r) value */
    T query(size_t l, size_t r){
        T res {Monoid::identify()};
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l&1) res = Monoid::op(res, d[l++]);
            if (r&1) res = Monoid::op(res, d[--r]);
        }
        return res;
    }

    void dump(){
        FOR(i, n, 2 * n) cout << i - n << ": " << d[i] << endl;
    }
};

/* Range Max Query */
template<typename U = ll>
struct RMQ {
    using T = U;
    static T op(const T& a, const T& b){ return max<T>(a, b); };
    static constexpr T identify(){ return numeric_limits<T>::min(); }
};

int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;

    reverse(s.begin(), s.end());

    SegmentTree<RMQ<>> t(n + m + 1);
    REP(i, n + 1) {
        if (s[i] == '0') t.modify(i, i);
    }

    vector<int> pos{0};
    int p = 0;

    while (p < n) {
        int p2 = t.query(p, p + m + 1);
        if (p == p2) {
            cout << -1 << endl;
            return 0;
        }
        pos.push_back(p2);
        p = p2;
    }
    
    reverse(pos.begin(), pos.end());

    REP(i, pos.size() - 1) {
        cout << pos[i] - pos[i + 1] << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

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

	string s;
	cin >> s;
	cout << s;
	if (s.back() == 's') cout << "es\n";
	else cout << "s\n";

	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int n,m;
    cin >> n >> m;
    vvll den(m);
    for(int i=0;i<m;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int z;
            cin >> z;
            z--;
            den.at(i).push_back(z);
        }
    }
    vector<int>p(m);
    for(int i=0;i<m;i++){
        cin >> p.at(i);
    }
    int res = 0;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int>che(m,0);//on
        for(int i=0;i<m;i++){
            for(int j=0;j<den.at(i).size();j++){
                int to = den.at(i).at(j);
            if(bit&(1<<to))che.at(i)++;
            }
        }
        bool ans = true;
        for(int i=0;i<m;i++){
        int d = che.at(i)%2;
        if(d!=p.at(i))ans=false;
        }
        if(ans)res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256