akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        Map<Integer, Set<Integer>> tree = new HashMap<>();
        for (int i : IntStream.range(0, N - 1).toArray()) {
            int a = Integer.parseInt(scan.next());
            int b = Integer.parseInt(scan.next());
            Set<Integer> map = tree.getOrDefault(a, new HashSet<>());
            map.add(b);
            tree.put(a, map);
            map = tree.getOrDefault(b, new HashSet<>());
            map.add(a);
            tree.put(b, map);
        }

        int blackCount = bfs(tree, N);
        if (blackCount > 0) {
            System.out.println("Fennec");
        } else {
            System.out.println("Snuke");
        }

    }

    static int bfs(Map<Integer, Set<Integer>> tree, int N) {
        int[] nodes = new int[N+1];
        nodes[1] = 1;
        nodes[N] = -1;
        LinkedList<List<Integer>> deque = new LinkedList<>();
        deque.addFirst(Arrays.asList(1, 1));
        deque.addFirst(Arrays.asList(N, -1));
        while (!deque.isEmpty()) {
            List<Integer> node = deque.removeLast();
            for (int next : tree.get(node.get(0))) {
                if(nodes[next] != 0) {
                    continue;
                }
                nodes[next] = node.get(1);
                deque.addFirst(Arrays.asList(next, node.get(1)));
            }
        }
        return Arrays.stream(nodes).sum();
    }

}


Measured memory_bytes: 92720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mxn=101;
const long long mxweight=(10e+5) +1;
ll dp[mxn][mxweight]={0};
ll sack (vector<ll>& w , vector<ll>& v, ll n , ll weight){
    if(n==0 || weight==0){return 0;}
    if(dp[n][weight]!=0){return dp[n][weight];}
    if(w[n-1]>weight){dp[n][weight]=sack(w,v,n-1,weight); return dp[n][weight];}
    dp[n][weight]=max(sack(w,v,n-1,weight),sack(w,v,n-1,weight-w[n-1])+v[n-1]);
    return dp[n][weight];
}

int main(){
    ll n;
    ll mxw;
    cin>>n>>mxw;
    vector<ll>w(n);
    vector<ll>v(n);
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    cout<<sack(w,v,n,mxw);

    return 0;

}


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

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

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

    ll N;
    cin>>N;
    vector<ll> S(N);
    for (ll n = 0; n < N; n++) cin>>S[n];
    ll ans = accumulate(begin(S), end(S), 0);
    if (ans % 10 != 0) {
        cout<<ans<<endl;
        return 0;
    }
    sort(begin(S), end(S));
    for (ll n = 0; n < N; n++) {
        if (S[n] % 10 != 0) {
            ans -= S[n];
            break;
        }
    }

    if (ans % 10 != 0) cout<<ans<<endl;
    else cout<<0<<endl;

    return 0;
}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
using namespace std;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a!=c?1:0)<<endl;
    return 0;
}





Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>


using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
#define ll long long
#define int long long
#define INF 1e18
#define ar array
#define MAX 1000004
#define wt(x) int x;cin>>x;while(x--)

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 
}
ll power(ll a,ll b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    ll res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
  

 int32_t main() {

c_p_c();
int n;
    cin >> n;
    int ans = 0;
    for(int i = 2; i *i <= n; i++)
    {
        if(n % i)
            continue;
        int ct = 0;
        while(n % i == 0)
        {
            n /= i;
            ct++;
        }
        int cur = 1;
        while(cur <= ct)
        {
            ans++;
            ct -= cur;
            cur++;
        }
    }
    if(n > 1)
        ans++;
    cout << ans;
    

return 0;

}

    


   

        



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod 1000000007
#define pi 3.14159265358979323
using namespace std;
vector<int> v[100005];
int sz[100005],depth[100005],p[100005],color[100005];
int T1[100005],T2[100005];
int siz1 = 0;
int siz2 = 0;
void dfs(int node,int par)
{
    sz[node] = 1;
    p[node] = par;
    for(auto u:v[node])
        if(u != par)
        {
            dfs(u,node);
            sz[node] += sz[u];
        }
}
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n-1; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(n,-1);

    int u = 1;
    int sum = 1;
    while(p[u] != n)
    {
        u = p[u];
        T1[u] = sum;
        sum+=2;
    }

    memset(sz,0,sizeof(sz));
    dfs(1,-1);
    u = n;
    sum = 2;

    siz1 = sz[1] - sz[n];
    siz2 = sz[n];

    while(p[u] != 1)
    {
        int last = u;
        u = p[u];
        if(sum < T1[u])
        {
            siz1 -= (sz[u] - sz[last]);
            siz2 += (sz[u] - sz[last]);
        }
        sum+=2;
    }
    if(siz1 > siz2)
        cout << "Fennec\n";
    else
        cout << "Snuke\n";


}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

template<typename T>
struct fenwick
{
    int n;
    vector<T> f;
    fenwick(int n = 500005) : n(n), f(n + 1) {}

    T query(int p)
    {
        T ret = 0;
        for (++p; p > 0; p -= p & -p)
            ret += f[p];
        return ret;
    }

    void update(int p, T x)
    {
        for (++p; p <= n; p += p & -p)
            f[p] += x;
    }
};

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n; string s;
	cin >> n >> s;
	vector<fenwick<int>> f(26);
	for (int i = 0; i < n; ++i)
		f[s[i]-'a'].update(i, +1);

	int q;
	cin >> q;
	char x;
	for (int t, l, r; q--; )
	{
		cin >> t >> l;
		if (t == 1)
		{
			cin >> x;
			f[s[l-1]-'a'].update(l-1, -1);
			s[l-1] = x;
			f[s[l-1]-'a'].update(l-1, +1);
		}
		else
		{
			cin >> r;
			int ans = 0;
			for (int i = 0; i < 26; ++i)
				ans += f[i].query(r-1) - f[i].query(l-2) > 0;
			cout << ans << "\n";
		}
	}

	return 0;
}


Measured memory_bytes: 51740
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0147().doIt();
	}
	
	class AOJ0147{
		int[] waitTime;
		State[] states;
		void doIt(){
			waitTime = new int[100];
			LinkedList<WaitState> q = new LinkedList<WaitState>();
			states = new State[17];
			for(int i=0;i<17;i++)states[i] = new State(-1, -1);
			for(int i=0;i<1000*5;i++){
//			for(int i=0;i<100;i++){
				removeState(i);
				if(i%5==0&&i/5<=99)q.add(new WaitState(i/5, (i/5)%5==1? 5:2, i));//stack
				int index = -1;
				if(q.size()>0)index = canPush(q.get(0));
				while(index >= 0){
					waitTime[q.get(0).ban] = i-q.get(0).startTime;
					setState(q.remove(), index, i);
					if(q.size()==0)break;
					index = canPush(q.get(0));
//					System.out.println(q.get(0).ban+" "+q.get(0).num+" "+q.get(0).startTime+" "+index);
				}
//				printState(i);
//				System.out.println("stacks are ");
//				for(int s=0;s<q.size();s++)System.out.println(q.get(s).ban+" "+q.get(s).num);
//				System.out.println("--------------");
			}
			while(in.hasNext())System.out.println(getResult(in.nextInt()));
		}
		
		void printState(int time){
			for(int i=0;i<17;i++){
				System.out.println((time)+":"+states[i].ban+" _ "+states[i].endTime);
			}
		}
		
		void removeState(int time){
			for(int i=0;i<17;i++)if(states[i].ban>=0&&states[i].endTime<=time)
				states[i] = new State(-1, -1);
		}
		
		void setState(WaitState j,int index,int currentTime){
			int endTime = 17*(j.ban%2)+3*(j.ban%3)+19; 
			for(int i=index;i<index+j.num;i++){
				states[i] = new State(j.ban, endTime+currentTime);
			}
		}
		
		int canPush(WaitState j){
			for(int i=0;i<17;i++)if(states[i].ban == -1){
				int cnt = 0;
				for(int s=i;s<i+j.num;s++)if(s<17&&states[s].ban == -1)cnt++;
				if(cnt==j.num)return i;
			}
			return -1;
		}
		
		int getResult(int n){
			return waitTime[n];
		}
		
		class WaitState{
			int ban,num,startTime;
			public WaitState(int _ban,int _num,int _startTime) {
				ban = _ban;
				num = _num;
				startTime = _startTime;
			}
		}
		
		class State{
			int ban,endTime;
			public State(int _ban,int _endTime){
				ban = _ban;
				endTime = _endTime;
			}
		}
		
	}
	
}

Measured memory_bytes: 19532
object Main extends App {
	val strAry = io.StdIn.readLine().split(' ')
	// val num1 = strAry(0).toInt
	// val num2 = strAry(1).toInt
	// val num3 = strAry(2).toInt
	
	val str = strAry.sorted.mkString(" ")
	
	println(str)
}


Measured memory_bytes: 43704
#encoding:utf-8
def find_the_LCM array #arrayの要素は文字
 array.length.times do |i|
  array[i] = array[i].to_i
 end
 i = 1
 while true
  if array[0]*i%array[1] == 0
   break
  end
  i += 1
 end
 return array[0]*i
end

def find_the_GCD array #arrayの要素は文字
 #ユークリッドの互除法を用いる 「アルゴリズムのキホン」p108参照
 array.length.times do |i|
  array[i] = array[i].to_i
 end
 x,y,r = array[0],array[1],array[0]%array[1]
 until r == 0
  x = y
  y = r
  r = x%y
 end
 return y
end

numbers = []
while gets
 numbers.push $_.split
end

i = 0
while i < numbers.length
 print "#{find_the_GCD numbers[i]} #{find_the_LCM numbers[i]}\n"
 i += 1
end

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

int main()
{
	int N;
	int A[100001];
	int B[100001];

	cin >> N;

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

	for (int i = 0; i < N; i++)
	{
		B[A[i]-1] = i+1;
	}

	for (int i = 0; i < N; i++)
	{
		if (i == N - 1)cout << B[i];
		else cout << B[i] << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
	float	Xa,Xb,Xc,Xd,Ya,Yb,Yc,Yd;
	while(scanf("%f %f %f %f %f %f %f %f",&Xa,&Ya,&Xb,&Yb,&Xc,&Yc,&Xd,&Yd)!=EOF){
		if((Xa-Xb)*(Xc-Xd)+(Ya-Yb)*(Yc-Yd)==0) puts("YES");
		else 								   puts("NO");
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);

ll n;

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

    cin >> n;
    vector<ll> a(n);
    double ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ans += 1.0 / a[i];
    }
    cout << fixed << setprecision(10) << 1.0 / ans << endl;
}

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

using namespace std;

int n,m,z[2323];
bool vis[2323];
int main(){
	bool flag=0;
cin>>n>>m;

for(int i=0;i<m;i++){
	int a,b; cin>>a>>b;
    if(z[a]!=b){if(vis[a]==1){flag=1;break;
	}else{z[a]=b;vis[a]=1;}}
	else vis[a]=1;
}
if(n==1&&z[1]==0){cout<<0;return 0;
}
if(flag==1 ||(vis[1]==1&& z[1]==0)){cout<<-1;return 0;
}
if(vis[1]==0)z[1]=1;
for(int i=2;i<=n;i++){
	if(vis[i]==0)z[i]=0;
}
for(int i=1;i<=n;i++)cout<<z[i];
return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
int n,k;
double ans;

signed main(){
  cin >> n >> k;
  FOR(i,n){
    int now = i;
    int a = 0;
    while(now<k){
      now *= 2;
      a ++;
    }
    ans += 1.0 / pow(2,a);
  }
  ans /= n;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int,input().split(' ')))
    tmp = 0
    for n,i in enumerate(a):
        if n%2 ==0:
           tmp += i
        else:
            tmp -=i
    print(tmp,'',end='')
    x_1 = tmp
    for i in a[0:n]:
        next = 2*i-tmp
        print(next,'',end='')
        tmp = next

if __name__ == '__main__':
    main()

Measured memory_bytes: 14616
#include<stdio.h>

int main(){
  int a[1000];
  int n,m,all,i,c;
  all=0;
  c=0;
  scanf("%d %d",&n,&m);
  
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    all=all+a[i];
  }
  
  for(i=0;i<n;i++){
    if(a[i]*(4*m)>=all){
      c++;
    }
  }
  
  if(c>=m){
  printf("Yes");
  }else{
    printf("No");
  }
  
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	cout << t + s << endl;
}

Measured memory_bytes: 256
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    s = input()
    t = input()

    for i in range(len(s)):
        if s == t:
            print('Yes')
            return
        s = s[-1] + s[:-1]

    print('No')


if __name__ == '__main__':
    main()


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

int main() {
  string S;
  cin >> S;
  int result;
  for (int i = 1; i < S.size(); ++i) {
    string si = S.substr(0, S.size() - i);
    if (si.size() % 2 != 0) {
      continue;
    }
    int half = si.size() / 2;
    string f = si.substr(0, half);
    string l = si.substr(half, half);
    if (f == l) {
      result = half * 2;
      break;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<algorithm>
#define ll long long
using namespace std;
int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		if (a % 2 && i % 2)cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 3184
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>

using namespace std;
#define ll long long

int main(){
    int N, a, b, c, d, k, ans = 0;
    int y = 0, tmp;
    cin >> N;
    vector<pair<int, int> > red(N);
    vector<pair<int, int> > blue(N);
    vector<bool> pair_f(N,false);
    // xは昇順,yは降順にソートする
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        red[i] = make_pair(a, b);
    }
    for(int i = 0; i < N; i++){
        cin >> c >> d;
        blue[i] = make_pair(c, d);
    }
    sort(red.begin(), red.end(), greater<pair<int, int> >());
    sort(blue.begin(), blue.end());
    // for(int i = 0; i < N; i++){
    //     red[i].second = -red[i].second
    //     blue[i].second = -
    // }
    for(int i = 0; i < N; i++){
        // bool blue_f = false;
        y = -1;
        for(int j = 0; j < N; j++){
            if(red[j].first < blue[i].first && red[j].second < blue[i].second && !pair_f[j]){
                if(y < red[j].second){
                    y = red[j].second;
                    tmp = j;
                }
            }
        }
        if(y != -1){
            pair_f[tmp] = true;
            ans++;
            // cout << "red: " << red[tmp].first << red[tmp].second << " bule: " << blue[i].first << blue[i].second << endl;
        }
    }

    cout << ans << endl;
}

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

const int MOD=1000000007;

ll gcd(ll x, ll y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
    return x * y / gcd(x, y);
}

void solve(std::string S){
    ll cnt=1, len, sum=0;
    string lhs, rhs;
    lhs = S[0];
    map<string,ll> M;
    len = S.length();

    M[lhs]++;
    for (ll i = 1; i < len; i++) {
        rhs = S[i];
        if ( lhs == rhs ) {
            if (i==len-1){
                break;
            } else {
                rhs = rhs + S[i+1];
            }
            i++;
        }
        lhs = rhs;
        M[lhs]++;
    }

    for(auto itr : M){
        sum += itr.second;
    }

    cout << sum << endl;

    // for (ll i = 1; i < len; i++) {
    //     rhs = S[i];
    //     if ( lhs == rhs ) {
    //         rhs = rhs + S[i+1];
    //         i++;
    //     }
    //     lhs = rhs;
    //     cnt++;
    // }
    // if ( S[len-1] == S[len-2] ) {
    //     cnt--;
    // }
    // cout << cnt << endl;

    // ll cnt=0;
    // for (ll i = 0; i < S.length(); i++) {
    //     if (S[i] == S[i+1]){
    //         cnt++;
    //     }
    // }
    // cout << S.length() - cnt + 1 << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 772
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<ll,ll>> pc;
//int ABS(int a){return max(a,-a);}
//int a[100001];
ll gcd(ll a,ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}
int main(){
   int a,b,k;
   cin>>a>>b>>k;
   int num;
   num=gcd(a,b);
  k--;
   int i=num;
   while(k>0){
            i--;
       if(num%i==0){
           k--;
       }
   }
   cout<<i;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  int num;
  if(a > b) num = a + a - 1;
  else if(a == b) num = 2 * a;
  else num = b + b - 1;
  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
x=list(map(int,input().split()))
m=10**9
for i in range(n-k+1):
  a=x[i];b=x[i+k-1]
  if a*b<0:
    a=abs(a)
    t=min(a,b)*2+max(a,b)
  else:
    t=max(abs(a),abs(b))
  m=min(m,t)
print(m)

Measured memory_bytes: 14392
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
int main()
{
    ll a,b;
    string s,t,u;
    cin>>s>>t>>a>>b>>u;
    if(s==u) a--;
    else b--;
    cout<<a<<" "<<b;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int votes[100] = {};
    int N, M;
    scanf("%d %d", &N, &M);
    for(int i=0; i < N; i++){
        int K;
        int A;
        scanf("%d", &K);
        for(int j=0; j < K; j++){
            scanf("%d", &A);
            votes[A]++;
        }
    }

    int res = 0;
    for(int i = 1; i <= M; i++){
        if(votes[i] == N){
            res++;
        }
    }
    printf("%d\n", res);
    return 0;
}

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


int main() {
  ll n, k, q, tmp;
  cin >> n >> k >> q;
  vector<int>a(n);
  rep(i,n) a[i] = (k-q);
  rep(i,q) {
    cin >> tmp;
    tmp--;
    a[tmp]++;
  }
  
  rep(i,n) {
    if(a[i]<=0) {
      cout << "No" << endl;
    }else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}
  
  
  
  


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Objects;
import java.lang.StringBuilder;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();

    int cnt = 0;
    while(C > cnt && B >= A){
      B -= A;
      cnt++;
    }

    System.out.println(cnt);

  }
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
typedef struct Node * node;
struct Node{
   int val;
   node left;
   node right; // pointer
   node parent;
};
node insert(node T, int z){
    //find the parnet
    //printf("%d",T);
    node y = NULL;
    node temp = T;
    while(temp!=NULL){
        y = temp;
        if(z<temp->val){
            temp = temp->left;
        } else {
            temp = temp->right;
        }
    }
    node insert = (node)malloc(sizeof(node));
    insert->val = z;
    if(y==NULL){ //empty tree{
        T = insert;
    }
    else if(z<(y->val)){
        y->left = insert;
    } else {
        y->right = insert;
    }
    return T;
}
void inorder(node root){
    if(root == NULL) return;
    inorder(root->left);
    printf(" %d",root->val);
    inorder(root->right);
}

void preorder(node root){
    if(root == NULL) return;
    printf(" %d",root->val);
    preorder(root->left);
    
    preorder(root->right);
}
void print(node root){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}
int main()
{
    int n;
    scanf("%d",&n);
    node root = NULL;
    for(int i = 0; i<n; i++){
        char str[10];
        int val;
        scanf("%s %d",&str, &val);
        if(str[0] == 'i'){//insert
            root = insert(root,val);
        } else{ // print
            print(root);
        }
    }
    return 0;
}


Measured memory_bytes: 18200
#include <algorithm>
#include <iostream>
#include <string>

int dp[1000001][2];

int main()
{
    constexpr int INF = 1e9;
    std::string x;
    std::cin >> x;
    const int l = static_cast<int>(x.length());
    dp[0][0] = 0;
    dp[0][1] = INF;
    for(int i = 1; i <= l; ++i)
    {
        const int d = x.at(l - i) - '0';
        dp[i][0] = std::min(dp[i-1][0] + d, dp[i-1][1] + (d+1));
        dp[i][1] = std::min(dp[i-1][0] + (10 - d), dp[i-1][1] + (10 - (d+1)));
    }
    dp[l+1][0] = std::min(dp[l][0], dp[l][1]+1);
    std::cout << dp[l+1][0] << std::endl;
}

Measured memory_bytes: 9204
N = int(input())
src = [0] + list(map(int,input().split())) + [0]
cums = [0]
for a,b in zip(src,src[1:]):
    d = abs(a-b)
    cums.append(cums[-1] + d)

ans = []
for i in range(N):
    tmp = cums[i] + abs(src[i] - src[i+2]) + cums[-1] - cums[i+2]
    ans.append(tmp)
print(*ans, sep='\n')


Measured memory_bytes: 64492
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long n;
    cin >> n;
    vector<int> t(n + 1);
    vector<int> x(n + 1);
    vector<int> y(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    x[0] = 0;
    y[0] = 0;
    t[0] = 0;
    for (int i = 1; i <= n; i++) {
        int num = 0;
        num = abs(x[i] + y[i] - x[i - 1] - y[i - 1]);
        // cout << num << endl;
        if (t[i] - t[i - 1] < num) {
            cout << "No" << endl;
            return 0;
        } else if ((t[i] - t[i - 1] - num) % 2 == 0) {
            continue;
        } else {
            no();
        }
    }
    yes();
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ary[]= new int[n];
		int a,b;
		for (int i=0;i<n;++i){
			ary[i]=sc.nextInt();
		}

		for (int i=0;i<n;++i){
			for (int j=i;j>0;--j){
				a= Math.min(ary[j],ary[j-1]);
				b= Math.max(ary[j], ary[j-1]);
				ary[j-1]=a;
				ary[j]=b;
			}
			for (int k=0;k<n;++k){
				if (k!=n-1)System.out.print(ary[k]+" ");
				else System.out.print(ary[k]);
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 31000
n=int(input())

def sieve(x):
  p=[2]
  b=[1]*x
  for i in range(2,x,2):  b[i]=0
  for i in range(3,x,2):
    if b[i]:
      p+=[i]
      for j in range(2*i,x,i): b[j]=0
  return p
def prime_factor(x):
  d={}
  for i in sieve(int(x**0.5)+1):
    while x%i<1:  x//=i;  d[i]=d.get(i,0)+1
    if x<2: break
  if x>1: d[x]=1
  return d

d=prime_factor(n)
a=0
for i in d.values():
  t=c=0
  while t+c<i: c+=1; t+=c
  a+=c
print(a)

Measured memory_bytes: 20272
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int main(){
  int N;
  cin >> N;

  ll T = 0;
  ll A = 0;
  rep(i, N){
    ll t, a;
    cin >> t >> a;
    if(i == 0){
      T = t;
      A = a;
    }else{
      ll x = max((T - 1) / t, (A - 1) / a) + 1;
      T = x * t;
      A = x * a;
    }
  }

  ll ans = T + A;
  cout << ans << endl;
  return 0;
} 


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    
    // Scc
    long a = Math.min(N, M/2);
    N -= a;
    M -= 2*a;
    
    // cc > S, Scc
    long b = M/4;
    
    System.out.println(a + b);
  }
}

Measured memory_bytes: 21972
#include<cstdio>
#include<vector>
#include<functional>


using namespace std;
using vi=vector<int>;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvi=vector<vi>;


int main(void)
{
	int n, m, q;

	while(scanf("%d%d%d", &n, &m, &q)==3)
	{
		vvi f(n+2);

		for(auto&mf:f) mf.assign(n+2, 0);

		for(int i=0;i<m;i++)
		{
			int l, r;
			scanf("%d%d", &l, &r);
			f[l][r]++;
		}
		for(int r=1;r<=n;r++)
		{
			for(int l=n;l>0;l--)
			{
				f[l][r]+=f[l+1][r];
			}
		}
		for(int l=1;l<=n;l++)
		{
			for(int r=1;r<=n;r++)
			{
				f[l][r]+=f[l][r-1];
			}
		}
		for(int i=0;i<q;i++)
		{
			int p, q;
			scanf("%d%d", &p, &q);
			printf("%d\n", f[p][q]);
		}
	}
	return 0;
}


Measured memory_bytes: 1920
//ΔAGC034A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 222222;
int n,a,b,c,d,f[N];
char s[N];
void no(){
	cout<<"No";
	exit(0);
}
void yes(){
	cout<<"Yes";
	exit(0);
}
int main()
{
	int i,l,r;
	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s+1);
	for(i=1;i<=n;i=i+1)
		f[i]=s[i]=='.';
	if(c<d){
		for(i=a+1;i<c;i=i+1)
			if(!f[i]&&!f[i+1])
				no();
		for(i=b+1;i<d;i=i+1)
			if(!f[i]&&!f[i+1])
				no();
		yes();
	}
	else{
		for(i=a+1;i<c;i=i+1)
			if(!f[i]&&!f[i+1])
				no();
		for(i=b;i<=d;i=i+1)
			if(f[i-1]&&f[i]&&f[i+1])
				yes();
		no();
	}
	return 0;
}

Measured memory_bytes: 1152
# C: Slimes

N = int(input())
S = input()

s_shrinked = str()

for i in range(N):
    if s_shrinked == '':
        s_shrinked += S[i]
    else:
        if s_shrinked[-1] != S[i]:
            s_shrinked += S[i]
            
print(len(s_shrinked))

Measured memory_bytes: 3316
if __name__ == '__main__':
    S=input()
    T=input()
    MA={}
    IMA={}
    ok=True
    for i in range(len(S)):
        s=S[i]
        t=T[i]
        if list(MA.keys()).count(s)>0:
            if MA[s]!=t:
                ok=False
        if list(IMA.keys()).count(t) > 0:
            if IMA[t] != s:
                ok = False
        MA[s]=t
        IMA[t]=s
    if ok:
        print("Yes")
    else:
        print("No")


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

using namespace std;

#define int long long
#define PB push_back
#define MP make_pair
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> pipi;

constexpr int INF = 1LL << 60;
constexpr int MOD = 1000000007;
constexpr int MAX_N = 100005;
constexpr int dx[] = { 0, 1, 0, -1 };
constexpr int dy[] = { 1, 0, -1, 0 };

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

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

Measured memory_bytes: 256
#include<stdio.h>
    int main(void){
    
    int a,b;//数字
    char c;//演算子
    
    while(1){
        scanf("%d %c %d",&a,&c,&b);
        if(c=='?'){
            break;
        }
        if(c=='+'){//演算子を判別する
            printf("%d\n",a+b);
        }
        else if(c=='-'){
            printf("%d\n",a-b);
        }
        else if(c=='/'){
            printf("%d\n",a/b);
        }
        else if(c=='*'){
            printf("%d\n",a*b);
        }
        
    }
    return 0;
    }



Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define NMAX 22
using namespace std;
int n,a[NMAX][NMAX];
long long dp[NMAX][1<<22];
const long long MOD=1e9+7;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[0][i])
            dp[0][1<<i]=1;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[i][j])
            {
                for(int k=1;k<(1<<n);k++)
                {
                    if(!((1<<j)&k))
                    {
                        dp[i][k^(1<<j)]=(dp[i][k^(1<<j)]+dp[i-1][k])%MOD;
                    }
                }
            }
        }
    }
    cout<<dp[n-1][(1<<n)-1];
    return 0;
}

Measured memory_bytes: 375040
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,y,cnt;
int main(){
  cin>>a>>b>>c;
  x=7*a+b;
  cnt+=c/x*7;
  y=c%x;
  if(y>0)cnt+=min((y-1+a)/a,7);
  cout<<cnt<<endl;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    long long a;
    long long b;
    long long c;
    long long d;

    cin >> a >> b >> c >> d;
    
    long long results[4] = {a * c, a * d, b * c, b * d};

    cout << *max_element(results, results + 4) << endl;

    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<sstream>
#include<cmath>
#include<iterator>
#include<bitset>
#include<stdio.h>
using namespace std;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long LL;
const int INF = 1 << 30;
const int maxn = 1000005;


int main()
{

    int a,b;
    while(cin>>a>>b){
        if(abs(a-b)<2){
            puts("Yay!\n");
        }
        else cout<<":("<<endl;
    }
    
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef struct jinde{
	char c;
	int number;
	int i;
}temp;

void bubbleSort(struct jinde c[], int n);
void selectionSort(struct jinde c[], int n);

int main (void){
	int n, i;
	scanf("%d", &n);
	struct jinde miku[n], miku2[n];
	
	for(i=0; i<n; i++) scanf(" %c%d", &miku[i].c, &miku[i].number);
	for(i=0; i<n; i++){
		miku[i].i=i;
		miku2[i] = miku[i];
	}
	
	bubbleSort(miku, n);
	selectionSort(miku2, n);
	return 0;
}

void bubbleSort(struct jinde c[], int n){
	int i, j, count=0;
	struct jinde x;
	
	for(i=0; i<n; i++){
		for(j=n-1; i+1<=j; j--){
			if(c[j].number < c[j-1].number){
				x=c[j];
				c[j]=c[j-1];
				c[j-1]=x;
			}
		}
	}

	for(i=0; i<n-1; i++) printf("%c%d ", c[i].c, c[i].number);
	printf("%c%d\n", c[i].c, c[i].number);
	
	for(i=0; i<n-1; i++){
		if(c[i].number==c[i+1].number){
			if(c[i].i<c[i+1].i){
				printf("Stable\n");
				break;
			}
			else{
				printf("Not stable\n");
				break;
			}
		}
		if(c[i].number!=c[i+1].number) count++;
	}
	
	if(count==n-1) printf("Stable\n");
}

void selectionSort(struct jinde c[], int n){
	int i, j, minj, count=0;
	struct jinde x;
	for(i=0; i<n; i++){
		minj=i;
		for(j=i; j<n; j++){
			if(c[j].number < c[minj].number){
				minj=j;
			}
		}
		x=c[i];
		c[i]=c[minj];
		c[minj]=x;
	}
	
	for(i=0; i<n-1; i++) printf("%c%d ", c[i].c, c[i].number);
	printf("%c%d\n", c[i].c, c[i].number);
	
	for(i=0; i<n-1; i++){
		if(c[i].number==c[i+1].number){
			if(c[i].i<c[i+1].i) count++;
		}
		if(c[i].number!=c[i+1].number) count++;
	}
	if(count!=n-1) printf("Not stable\n");
	else printf("Stable\n");
}


Measured memory_bytes: 2092
n=int(input())
d,x=map(int,input().split())

ans=0
a=[]
for _ in range(n):
	a.append(int(input()))

Sum=0
for i in range(n):
	day=1
	while True:
		if(day<=d):
			Sum+=1
			day+=a[i]
		else:
			break

print(Sum+x)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll dp[110][100007];
int main(){
  ll n, W;
  cin >> n >> W;
  vi w(n+1,0);
  vi v(n+1,0);
  rep(i,n){
    cin >> w[i+1] >> v[i+1];
  }
  rep(i,n+1){
    rep(j,1000*n+1){
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for (ll i = 1; i <= n; i++){
    dp[i][0] = 0;
    for (ll j = 1; j <= 1000 * n; j++){
      if(j<=v[i]){
        dp[i][j] = min(dp[i - 1][j], w[i]);
      }
      else{
      dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i-1][j]);
      }
    }
  }
  ll ans = 0;
  for (ll i = 1000 * n; i >= 0; i--){
    if(dp[n][i]<=W){
      ans = i;
      break;
    }
  }
  print(ans);
}

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

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int odd = 0;
  odd += (a & 1);
  odd += (b & 1);
  odd += (c & 1);

  int res = 0;
  if (odd == 1 || odd == 2) {
    res++;
    a += (a & 1) != (odd & 1);
    b += (b & 1) != (odd & 1);
    c += (c & 1) != (odd & 1);
  }
  int h = max({a, b, c});
  res += (h - a) / 2;
  res += (h - b) / 2;
  res += (h - c) / 2;
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include ".vscode/debug_print.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1050000000;
constexpr long long INF64 = 4000000000000000000;
constexpr int MOD7        = 1000000007;
constexpr int MOD53       = 998244353;
constexpr long double PI  = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    int x;
    scan(x);
    int a  = x / 500;
    int b  = (x % 500) / 5;
    ll ans = 1000 * a + 5 * b;
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1

/*
 p: parent
 l: left-child
 r: right sibling
 */
struct Node{
  int p, l, r;
};
struct Node T[MAX]; // Tree
int n;
int depth(int u){
  int d = 0, i;
  for(i=u; T[i].p!=NIL; i=T[i].p, d++);
  return d;
}
void print(int u){

  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,depth(u));
   
  if( T[u].p == NIL) printf("root, [");
  else if(T[u].l == NIL) printf("leaf, [");
  else printf("internal node, [");
   
  if( T[u].l != NIL){
    while(1){
      if(T[T[u].l].r == NIL){
	printf("%d",T[u].l);
	break;
      }
      else {
	printf("%d, ",T[u].l);
	T[u].l = T[T[u].l].r;
      }
    }
  }
  
  printf("]\n");
}

main(){
  int i, j, d, v, c, l,tmp;
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      
      if(j == 0){
	T[v].l = c;
	T[c].p = v;
	tmp = c;
      }
      else{
	T[tmp].r = c;
	T[c].p = v;
	tmp = c;
      }
    }
  }
  
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

Measured memory_bytes: 1784
import sys

count = [0]*26
lines = sys.stdin.readlines()

for line in lines:
    for c in line.lower():
        if 97 <= ord(c) <= 123:
            count[ord(c) - 97] += 1
            
for i in range(26):
    print(chr(i + 97), ':', count[i])


Measured memory_bytes: 5576
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;
vector<int> v(3);
vector<int> q(3);
int k;

bool check(vector<int> &v) {
	return v[0] < v[1] && v[1] < v[2];
}

bool t(int turn) {
	if(turn == k) {
		// for(auto& el: q) cout << el << " ";
		// cout << "\n";
		return check(q);
	}
	if(turn == 0) {
		q = v;
	}
	for(int i = 0; i < 3; ++i) {
		q[i] *= 2;
		if(t(turn + 1)){
			return true;
		}
		q[i] /= 2;
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    cin >> v[0] >> v[1] >> v[2];
    cin >> k;

    if(t(0)) {
    	cout << "Yes\n";
    } else {
    	cout << "No\n";
    }
	return 0;
}


Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
const int nmax=100001;
int main(){
    int n; cin>>n;
    int a[nmax]={};
    LLI ans=0;
    int oddnum=0;
    LLI csum=0;
    FOR(i,0,n){
        cin>>a[i];
        if(a[i]){
            if(a[i]%2){
                oddnum=1-oddnum;
            }
            csum+=a[i];
        }else{
            ans+=(csum-oddnum)/2;
            csum=0;
            oddnum=0;
        }
    }
    ans+=(csum-oddnum)/2;
    co(ans);
}


Measured memory_bytes: 640
s = list(map(int, input()))

ideal1 = [0 for _ in range(len(s))]
for i in range(len(s)):
  if i % 2 == 0:
    ideal1[i] = 1
  else:
    ideal1[i] = 0

ideal2 = [0 for _ in range(len(s))]
for i in range(len(s)):
  if i % 2 == 0:
    ideal2[i] = 0
  else:
    ideal2[i] = 1

count1 = 0
count2 = 0

for i in range(len(s)):
  if s[i] != ideal1[i]:
    count1 += 1
  elif s[i] != ideal2[i]:
    count2 += 1

print(min(count1, count2))



Measured memory_bytes: 5536
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from heapq import heappush, heappop\n"
"n=int(input())\n"
"a=list(map(int,input().split()))\n"
"l=[]\n"
"for v in a[:n]:\n"
"  heappush(l,v)\n"
"suml=[sum(a[:n])]\n"
"for i in range(n):\n"
"  suml.append(suml[i]+a[n+i])\n"
"  heappush(l,a[n+i])\n"
"  suml[i+1]-=heappop(l)\n"
"r=[]\n"
"for v in a[2*n:]:\n"
"  heappush(r,(10**10-v,v))\n"
"sumr=[sum(a[2*n:])]\n"
"for i in range(n):\n"
"  sumr.append(sumr[i]+a[2*n-i-1])\n"
"  heappush(r,(10**10-a[2*n-i-1],a[2*n-i-1]))\n"
"  _,t=heappop(r)\n"
"  sumr[i+1]-=t\n"
"ans=-10**20\n"
"for i in range(n+1):\n"
"  ans=max(ans,suml[i]-sumr[n-i])\n"
"print(ans)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 39608
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    static final int MODULUS = 1_000_000_007;
    static String TARGET = "ABC";

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

        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static int solve(String S) {
        int wildCount = (int) S.chars().filter(ch -> ch == '?').count();
        int[] threePowers = new int[wildCount + 1];
        threePowers[0] = 1;
        for (int i = 1; i < threePowers.length; ++i) {
            threePowers[i] = multiplyMod(threePowers[i - 1], 3);
        }

        int result = 0;
        Map<String, Integer> subToCount = new HashMap<>();
        subToCount.put("", 1);
        for (char ch : S.toCharArray()) {
            Map<String, Integer> nextSubToCount = new HashMap<>();

            for (String sub : subToCount.keySet()) {
                if (sub.length() <= 2) {
                    nextSubToCount.put(sub, addMod(nextSubToCount.getOrDefault(sub, 0), subToCount.get(sub)));

                    String nextSub = String.format("%s%c", sub, ch);
                    if (check(nextSub)) {
                        nextSubToCount.put(nextSub,
                                addMod(nextSubToCount.getOrDefault(nextSub, 0), subToCount.get(sub)));
                    }
                }
            }

            for (String nextSub : nextSubToCount.keySet()) {
                if (nextSub.length() == 3) {
                    result = addMod(result, multiplyMod(nextSubToCount.get(nextSub),
                            threePowers[wildCount - (int) nextSub.chars().filter(c -> c == '?').count()]));
                }
            }

            subToCount = nextSubToCount;
        }

        return result;
    }

    static int addMod(int x, int y) {
        return (x + y) % MODULUS;
    }

    static int multiplyMod(int x, int y) {
        return (int) ((long) x * y % MODULUS);
    }

    static boolean check(String sub) {
        for (int i = 0; i < sub.length(); ++i) {
            if (sub.charAt(i) != '?' && sub.charAt(i) != TARGET.charAt(i)) {
                return false;
            }
        }

        return true;
    }
}

Measured memory_bytes: 242572
N = int(input())
arr = [i for i in range(1, N + 1)]
# N == len(arr)
nums = N*[0]
for j in range(N):
    target = arr[j]
    num = 0
    while target % 2 == 0:
        num += 1
        target /= 2
    nums[j] = num

# print(nums)

max = 0
for k in range(N):
    if nums[k] > max:
        max_index = k
        max = nums[k]
    elif N == 1:
        max_index=0
 
print(arr[max_index])

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

    #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
    #define F0R(i,a) FOR(i,0,a)
    #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
    #define R0F(i,a) ROF(i,0,a)

    using ll = long long;
    ll INF = LLONG_MAX;
    
    using vc = vector<char>;
    using vi = vector<int>;
    using vll = vector<ll>;

    int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        ll M, K; cin >> M >> K;
        if (K >= pow(2, M) || (M == 1 && K == 1)) {
            cout << -1 << endl;
            return 0;
        }
        if (M == 1 && K == 0) {
            cout << "0 1 1 0" << endl;
            return 0;
        }
        vll arr;
        F0R(i, pow(2, M)) if (i != K) arr.push_back(i);
        cout << K << " ";
        F0R(i, arr.size()) cout << arr[i] << " ";
        cout << K << " ";
        R0F(i, arr.size()) cout << arr[i] << " ";
        cout << endl;

    }

Measured memory_bytes: 2932