akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;
const ll INFTY = 1e12;

struct edge{
    int to;
    ll cost;
};

int main(){
    int N;
    cin >> N;
    vector<edge> list[N];
    for(int i=0;i<N-1;i++){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--;b--;
        list[a].push_back({b,c});
        list[b].push_back({a,c});
    }

    int q,k;
    cin >> q >> k; k--;
    ll dist[N];
    for(int i=0;i<N;i++) dist[i] = INFTY;
    queue<int> Q;
    Q.push(k);
    dist[k] = 0;
    while(!Q.empty()){
        int u = Q.front(); Q.pop();
        for(auto e : list[u]){
            if(dist[e.to] == INFTY){
                dist[e.to] = dist[u] + e.cost;
                Q.push(e.to);
            }
        }
    }

    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        x--;y--;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;

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;
}
int keta(ll a){
    int k=0,num=1;
    while(a > num){
        k++;
        num *= 10;
    }
    return k;
}

const double PI = acos(-1);



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double theta = (h/6 -11*m/360)*PI;
    double ans2 = a*a + b*b -2*a*b*cos(theta);
    double ans = sqrt(ans2);

    cout << setprecision(11) <<ans  << endl;

    return 0;
}


Measured memory_bytes: 4272
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

int func(std::vector< int >& vn, std::vector< int >& ope, bool& wrote, int i)
{
  if (i == 3) {
    int sum = 0;
    for (int i = 0; i < 4; i++) {
      sum += vn[i] * ope[i];
    }
    if (sum == 7 && !wrote) {
      std::cout << vn[0];
      for (int i = 1; i < 4; i++) {
	std::cout << (ope[i] == +1 ? '+' : '-');
	std::cout << vn[i];
      }
      std::cout << "=7"<< std::endl;
      wrote = true;
    }
    return 0;
  }

  ope[i+1] = -1;
  func(vn, ope, wrote, i+1);
  ope[i+1] = +1;
  func(vn, ope, wrote, i+1);

  return 0;
}

int main(int argc, char* argv[])
{
  std::string s;
  std::vector< int > vn;
  std::vector< int >::iterator it;

  std::cin >> s;

  for (int i = 0; i < 4; i++) {
    int tmp = s[i] - '0';
    vn.push_back(tmp);
  }

  // -1:- 1:+
  std::vector< int > ope(4, 0);
  ope[0] = 1;

  bool wrote = false;
  func(vn, ope, wrote, 0);

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		new Sol().Solve();
	}
}

class Sol{
	public void Solve(){
		
		while(true){
			var d=ria();
			N=d[0];M=d[1];P=d[2];
			if(N==0&&M==0&&P==0)return;
			int Inf=(int)1e9;
			int[][] WF=new int[N][];
			for(int i=0;i<N;i++){
				WF[i]=new int[N];
				for(int j=0;j<N;j++){
					WF[i][j]=(i==j)?0:Inf;
				}
			}
			
			E=new List<Pair>[N];
			for(int i=0;i<N;i++)E[i]=new List<Pair>();
			int[] From=new int[M],To=new int[M],Cost=new int[M];
			
			
			
			for(int i=0;i<M;i++){
				d=ria();
				WF[d[0]][d[1]]=WF[d[1]][d[0]]=d[2];
				From[i]=d[0];To[i]=d[1];Cost[i]=d[2];
			}
			
			for(int k=0;k<N;k++){
				for(int i=0;i<N;i++){
					for(int j=0;j<N;j++){
						WF[i][j]=Math.Min(WF[i][j],WF[i][k]+WF[k][j]);
					}
				}
			}
			
			//0->N-1????????????????????????edge????????????
			for(int i=0;i<M;i++){
				if(WF[From[i]][N-1]==WF[To[i]][N-1]+Cost[i])E[From[i]].Add(new Pair(To[i],Cost[i]));
				if(WF[To[i]][N-1]==WF[From[i]][N-1]+Cost[i])E[To[i]].Add(new Pair(From[i],Cost[i]));
			}
			
			//0->N-1???????????????????????????????????§??????????????????
			//???????????????
			Pair[] tmp=new Pair[N];
			for(int i=0;i<N;i++){
				tmp[i]=new Pair(i,WF[i][N-1]);//???->N-1??????????????¢
			}
			Array.Sort(tmp,(x,y)=>x.Cost>y.Cost?-1:x.Cost<y.Cost?1:0);
			
			double[] dp=new double[N];//dp[i]:0??????i???????????????????????°
			dp[0]=1;
			for(int i=0;i<N;i++){
				int now=tmp[i].Pos;
				foreach(var next in E[now]){
					dp[next.Pos]+=dp[now];
				}
			}
//for(int i=0;i<N;i++)Console.WriteLine("{0}-{1}",tmp[i].Pos,tmp[i].Cost);			
			for(;P>0;P--){
				int c=ri();
				double[] dp2=new double[N];//dp2[i]:c??????i???????????????????????°
				dp2[c]=1;
				for(int i=0;i<N;i++){
					int now=tmp[i].Pos;
					foreach(var next in E[now]){
//Console.WriteLine("now={0},0->now:{1} +now->next;{2} +next->N-1:{3},next={4},C:{5}",now,WF[0][now],next.Cost,WF[next.Pos][N-1],next.Pos,WF[0][N-1]);
						dp2[next.Pos]+=dp2[now];
					}
				}
//Console.WriteLine("0->{0}:{1},->N-1:{2},tot={3}",c,dp[c],dp2[N-1],dp[N-1]);
				Console.WriteLine("{0:F12}",dp[c]/dp[N-1]*dp2[N-1]);
			}
			Console.WriteLine();
		
		}
	}
	
	int N,M,P;
	List<Pair>[] E;
	
	class Pair{
		public int Pos,Cost;
		public Pair(int p,int c){
			Pos=p;Cost=c;
		}
	}
	
	
	

	public Sol(){
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 6644
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> C(13);
	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		++C[x];
	}
	bool zero = false;
	vector<int> sure = { 0 }, dec;
	for (int i = 0; i <= 12; ++i) {
		int limit = 3 - (i == 0 || i == 12 ? 1 : 0);
		if (C[i] >= limit) {
			zero = true;
		}
		else if (C[i] == limit - 1) {
			sure.push_back(i);
			if (limit == 3) sure.push_back(24 - i);
		}
		else if (C[i] == 1) {
			dec.push_back(i);
		}
	}
	int ans = 0;
	for (int i = 0; i < 1 << dec.size(); ++i) {
		vector<int> result = sure;
		for (int j = 0; j < dec.size(); ++j) {
			if ((i >> j) & 1) {
				result.push_back(dec[j]);
			}
			else {
				result.push_back(24 - dec[j]);
			}
		}
		sort(result.begin(), result.end());
		result.push_back(24);
		int val = 24;
		for (int j = 1; j < result.size(); ++j) {
			val = min(val, result[j] - result[j - 1]);
		}
		ans = max(ans, val);
	}
	cout << (zero ? 0 : ans) << endl;
	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

struct LazyRMQSeg{
  int n;
  vector<ll>node,lazy;
  LazyRMQSeg(vector<ll>v){
    int sz=v.size();
    n=1;
    while(n<sz)n*=2;
    node.resize(2*n-1,INF);
    lazy.resize(2*n-1,INF);
    for(int i=0;i<sz;i++)node[n-1+i]=v[i];
    for(int i=n-2;i>=0;i--)node[i]=min(node[2*i+1],node[2*i+2]);
  }
  ll operator[](int x){
    return getmin(x,x+1);
  }
  void eval(int k){
    if(lazy[k]!=INF){
      node[k]=lazy[k];
      if(2*k+2<2*n-1){
        lazy[2*k+1]=lazy[k];
        lazy[2*k+2]=lazy[k];
      }
      lazy[k]=INF;
    }
  }
  void update(int x,ll v){
    x=n-1+x;
    node[x]=v;
    while(x>=0){
      x=(x-1)/2;
      node[x]=min(node[2*x-1],node[2*x+2]);
    }
  }
  void update(int a,int b,ll v,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    eval(k);
    if(r<=a||b<=l)return;
    if((a<=l&&r<=b)){
      lazy[k]=v;
      eval(k);
    }
    else{
      update(a,b,v,2*k+1,l,(l+r)/2);
      update(a,b,v,2*k+2,(l+r)/2,r);
      node[k]=min(node[2*k+1],node[2*k+2]);
    }
  }
  ll getmin(int a,int b,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    eval(k);
    if(r<=a||b<=l)return INF;
    if(a<=l&&r<=b)return node[k];
    ll vl=getmin(a,b,2*k+1,l,(l+r)/2);
    ll vr=getmin(a,b,2*k+2,(l+r)/2,r);
    return min(vl,vr);
  }
};

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

  int N,Q;
  cin>>N>>Q;
  vector<ll>S(N),T(N),X(N),D(Q);
  for(int i=0;i<N;i++)cin>>S[i]>>T[i]>>X[i]; for(int i=0;i<Q;i++)cin>>D[i];
  LazyRMQSeg seg(vector<ll>(Q,INF));
  vector<tuple<ll,ll,ll>>memo;
  for(int i=0;i<N;i++){
    int r=Q;
    int l=-1;
    int m;
    while(r-l>1){
      m=(r+l)/2;
      if(S[i]-X[i]>D[m])l=m;
      else r=m;
    }
    int r2=Q;
    int l2=r-1;
    int m2;
    while(r2-l2>1){
      m2=(r2+l2)/2;
      if(T[i]-X[i]-1>=D[m2])l2=m2;
      else r2=m2;
    }
    tuple<ll,ll,ll>a(X[i],r,r2);
    memo.push_back(a);
  }
  sort(rng(memo));
  reverse(rng(memo));
  for(auto it:memo)seg.update(get<1>(it),get<2>(it),get<0>(it));
  for(int i=0;i<Q;i++){
    ll res=seg.getmin(i,i+1);
    if(res==INF)cout<<-1<<endl;
    else cout<<res<<endl;
  }
  return 0;
}


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

int main(void){
   int A,B,H,M;
   cin>>A>>B>>H>>M;
   double L=30.0*(double)H+0.5*(double)M;
   double S=6.0*(double)M;
   double kaku=max(L,S)-min(L,S);
   if(kaku>=180.0) kaku=360-kaku;
   double pi=3.141592653589;
   double result=pow(A,2)+pow(B,2)-2*A*B*cos(kaku*pi/180.0);
   cout<<fixed;
   cout<<setprecision(10)<<sqrt(result)<<endl;
   return 0;
}



Measured memory_bytes: 4224
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var answer = "";
            for (var i = 0; i < s.Length; i++)
            {
                if (s[i] == '1') answer += "9";
                if (s[i] == '9') answer += "1";
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;

  set<string> st;
  for (ll i = 0; i < N; i++) {
    string s; cin >> s;
    st.insert(s);
  }
  ll ans = st.size();
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 19216
package main
import "fmt"
func main(){
    var num [6]int
    for i := 0; i < 6; i++ {
        fmt.Scan(&num[i])
    }
    if num[4] - num[0] > num[5]{
        fmt.Println(":(")
        return
    }
    fmt.Println("Yay!")
}


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

int main(){

  long long N, A, B;

  cin>>N>>A>>B;
  
  if(A>B||(N==1&&A!=B)){
    cout<<0<<endl;
    return 0;
  }
  
  cout<<(N-2)*(B-A)+1<<endl;
  
  return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayLong();
            var N = input[0];
            var M = input[1];
            var cnt = new long[N + 1];
            for (int i = 0; i < M; i++) cnt[ReadInt()] = -1;
            var mod = (long)Math.Pow(10, 9) + 7;
            if (N == 1)
            {
                Console.WriteLine(cnt[1] != -1 ? 1 : 0);
                return;
            }
            if (cnt[1] != -1) cnt[1] = 1;
            if (cnt[2] != -1) cnt[2] = 1;
            for (int i = 1; i < N - 1; i++)
            {
                if (cnt[i] != -1)
                {
                    if (cnt[i + 1] != -1)
                    {
                        cnt[i + 1] += cnt[i];
                        cnt[i + 1] %= mod;
                    }
                    if (cnt[i + 2] != -1)
                    {
                        cnt[i + 2] += cnt[i];
                        cnt[i + 2] %= mod;
                    }
                }
            }
            if (cnt[N - 1] != -1)
            {
                cnt[N] += cnt[N - 1];
                cnt[N] %= mod;
            }

            Console.WriteLine(cnt[N]);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 15968
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String str = sc.nextLine();
    int min = line.length();
    for(int i = 0;i <= line.length() - str.length();i++){
      int temp = 0;
      for(int j = 0;j < str.length();j++){
        if(!String.valueOf(line.charAt(i + j)).equals(String.valueOf(str.charAt(j)))){
          temp++;
        }
      }
      if(temp < min){
        min = temp;
      }
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 52400
//package atcoder;
 
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
//import java.math.BigDecimal;
 
public class Main {
	public static void main(String [] args) {
	    int K,N;
	    
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		int p[] = new int [N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		/*for(int k=0;k<N;k++) {
			System.out.println(p[k]);
		}*/
		int goukei = 0;
		for(int j=0;j<K;j++) {
			goukei = goukei+p[j];
		}
		System.out.println(goukei);
		
	}
}

Measured memory_bytes: 39268
// AOJ 3047 Shiritori
// 2019.8.13 bal4u

#include <stdio.h>
#include <string.h>

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#else
#define gc() getchar()
#define pc(x) putchar(x)
#endif

int in() { // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

/*******************************************/
/* Dinic's Max Flow Algorithm 
/*******************************************/

#define INF 10005
#define VMAX 30
typedef struct { int to; int cap; int rev; } EDGE;
EDGE edge[VMAX][VMAX*2]; int hi[VMAX];
int level[VMAX], iter[VMAX];
int queue[VMAX], qtop;

void add_edge(int from, int to, int cap) {
	int f, t; EDGE *e;
	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = cap, e->rev = t;
	e = &edge[to][t], e->to = from, e->cap = 0, e->rev = f;
}

void bfs(int s) {
	int i, v; EDGE *e;
	memset(level, -1, sizeof(level));
	level[s] = 0;
	queue[0] = s, qtop = 1;
	while (qtop) {
		v = queue[--qtop];
		for (i = 0; i < hi[v]; i++) {
			e = &edge[v][i];
			if (e->cap > 0 && level[e->to] < 0) {
				level[e->to] = level[v] + 1;
				queue[qtop++] = e->to;
			}
		}
	}
}
 
int dfs(int v, int t, int f) {
	int *i, d; EDGE *e;
	if (v == t) return f;
	for (i = &iter[v]; *i < hi[v]; (*i)++) {
		e = &edge[v][*i];
		if (e->cap > 0 && level[v] < level[e->to]) {
			d = dfs(e->to, t, f <= e->cap? f: e->cap);
			if (d > 0) {
				e->cap -= d;
				edge[e->to][e->rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
 
int maxFlow(int s, int t) {
	int f, flow = 0;
	while (1) {
		bfs(s);
		if (level[t] < 0) break;
		memset(iter, 0, sizeof(iter));
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
	return flow;
}

//// 本問題関係
int rel[30][30];
char s[103];
char f[30];

int main()
{
	int i, j, k, N, S, T;

	N = in();
	while (N--) {
		int a, b, w = ins(s);
		a = s[0] - 'a', b = s[w-1] - 'a';
		if (a != b) rel[a][b]++;
		f[b] = 1;
	}
	T = 26;
	for (i = 0; i < 26; i++) if (f[i]) {
		int fi = 0, fo = 0;
		for (j = 0; j < 26; j++) fo += rel[i][j];
		S = i;
		memset(hi, 0, sizeof(hi));
		for (j = 0; j < 26; j++) for (k = 0; k < 26; k++) if (rel[j][k]) {
			if (k == i) add_edge(j, T, rel[j][k]);
			else        add_edge(j, k, rel[j][k]);
		}
		if (maxFlow(S, T) == fo) pc('a'+i), pc('\n');
	}
	return 0;
}



Measured memory_bytes: 2148
#include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>

using namespace std;

int F[100] = {0};
int P[100][11] = {{0}};

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

  int N;
  cin >> N;

  for (int i = 0; i < N; ++i) {
    int b = 0;
    for (int j = 0; j < 10; ++j) {
      cin >> b;
      F[i] |= b << j;
    }
  }

  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= 10; ++j)
      cin >> P[i][j];

  long long ans = INT_MIN;
  for (int i = 1; i < 1024; ++i) {
    long long sum = 0;
    for (int j = 0; j < N; ++j) {
      const int n = bitset<16>(F[j] & i).count();
      sum += P[j][n];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,t,a,h,c,d,i;
	long b=1000000000;

	scanf("%d%d%d",&n,&t,&a);

	for(i=1;i<=n;i++){
		scanf("%d",&h);
		d=abs((t*1000-h*6)-a*1000);
		if(d<b){
			b=d;
			c=i;
		}
	}
	printf("%d",c);
	return 0;
}

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

int main() {
	ULL N; cin >> N;
	string ans;
	while (N) {
		N--;
		ans += char(N % 26 + 'a');
		N /= 26;
	}

	reverse(ans.begin(), ans.end());
	cout << ans;

	return 0;
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());

  int result = 1e9 + 10;
  for (int i = 0; i + K - 1 < N; i++) {
    int diff = A[i + K - 1] - A[i];
    result = min(result, diff);
  }
  printf("%d\n", result);

  return 0;
}


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

using namespace std;

int main()
{
    int n, m, t[100]={}, p[100]={}, x[100]={};
    
    cin >> n;
    for(int i=0; i<n; i++) cin >> t[i];
    cin >> m;
    for(int i=0; i<m; i++) cin >> p[i] >> x[i];

    int sum[100]={};
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            sum[i] += p[i]-1==j ? x[i] : t[j];
        }
    }

    for(int i=0; i<m; i++){
        cout << sum[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int m,f,b;
    cin>>m>>f>>b;
    if(m>=b){
        cout<<0<<endl;
    }
    else if(m+f>=b){
        cout<<b-m<<endl;
    }
    else {
        cout<<"NA"<<endl;
    }
}



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

#define mp make_pair
#define X first
#define Y second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

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

const int N = 2e5 + 10;

char s[N], t[N];
int sumS[N], sumT[N], q;

int main(){
    if (fopen("inp.txt", "r")){
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> (s + 1) >> (t + 1);

    FOR(i, 1, strlen(s + 1))
        sumS[i] = sumS[i - 1] + (s[i] == 'A'? 1 : 2);
    FOR(i, 1, strlen(t + 1))
        sumT[i] = sumT[i - 1] + (t[i] == 'A'? 1 : 2);

    cin >> q;
    while (q--){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << (abs((sumS[b] - sumS[a - 1]) - (sumT[d] - sumT[c - 1])) % 3 == 0? "YES" : "NO") << endl;
    }

    return 0;
}


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

int n;
int M[101010]={};
ll dp[101010]={};
ll cnt=0;


int main(){
   int m;
   cin>>n;
   rep(i,n){
     cin>>M[i];
   }
   dp[0]=0;
   dp[1]=abs(M[0]-M[1]);
   rep(i,n-2){
      dp[i+2]=min(abs(M[i]-M[i+2])+dp[i],abs(M[i+1]-M[i+2])+dp[i+1]);
   }
   cout<<dp[n-1]<<endl;
   return 0;
}



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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> A(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) cin >> A[i][j];
  }
  int cnt = 0;
  for (int i; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int total = 0;
      for (int k = 0; k < D; k++) {
        int tmp = pow(A[i][k] - A[j][k], 2);
        total += tmp;
      }
      if(ceil(sqrt(total)) == floor(sqrt(total))) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

using namespace std;



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

    int a, b;
    cin >> a >> b;
    
    int res = -(1 << 28);
    res = max(res, a + b);
    res = max(res, a - b);
    res = max(res, a * b);

    cout << res << "\n";

    return 0;
}

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

using namespace std;



int main() {
	int n;
	//vector<int> h;

	cin >> n;

	int count = 0;
	int highest = 0;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		//h.push_back(x);

		if (x >= highest)
		{
			count += 1;
			highest = x;
		}
	}

	cout << count << endl;
}



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

int seq[100005];
int tab[50005];

int tot = 0;
bool exist = false;

void bsearch(int * arr, int begin, int end, int target);

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> seq[i];
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
        cin >> tab[i];

    for (int i = 0; i < q; i++)
    {
        exist = false;
        bsearch(seq, 0, n - 1, tab[i]);
        if (exist == true)
            tot++;
    }
    cout << tot << endl;
    return 0;
}

void bsearch(int * arr, int begin, int end, int target)
{
    int mid = (begin + end) / 2;
    if (arr[mid] == target)
    {
        exist = true;
        return;
    }

    if (begin >= end)
    {
        return;
    }

    if (arr[mid] > target)
        bsearch(arr, begin, mid, target);
    else
        bsearch(arr, mid + 1, end, target);
    return;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repk(i,k, n) for (int i = k; i < (int)(n); ++i)
#define MAX 500010
typedef long long int ll;

using namespace std;

ll N, ans, cnt;
string s;


int main() {
	int A, B;
	cin >> A >> B;

	if (A > 9 || B > 9) {
		cout << -1 << endl;
	}
	else {
		cout << A * B << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N, T;
	int A[100000];
    scanf("%d %d", &N, &T);
	int i;
	for(i=0;i<N;i++) {
		scanf("%d", &A[i]);
	}
	int min = A[0];
	int maxv = 0;
	int count = 1;
	for (i = 0; i < N; i++) {
		if(min > A[i]) min = A[i];
		if(maxv == (A[i] - min) ) count++;
		else if(maxv < A[i] - min) {
			maxv = A[i] - min;
			count = 1;
		}
	}
	printf("%d", count);
	
	return 0;
}

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

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

    int ans;
    if(a == b && b == c){
        if(a % 2 == 0)  ans = -1;
        else            ans = 0;
    }else{
        ans = 0;
        while(a%2 == 0 && b%2 == 0 && c%2 == 0){
            int na = (b+c)/2, nb = (c+a)/2, nc = (a+b)/2;
            ans++;
            a = na, b = nb, c = nc;
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
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; }

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

const int INF = 1001001001;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    if (n%2==1)cout << "No" << endl;
    else {
        bool flag = true;
        rep(i, n/2) {
            if (s[i] != s[i+n/2]) {
                flag = false;
                break;
            }
        }
        if (flag==true) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


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

using namespace std;

unsigned long dfs(string &s, const unsigned int i, const unsigned int j, const unsigned int n, unsigned long ret);

unsigned long dfs(string &s, const unsigned int i, const unsigned int j, const unsigned int n, unsigned long ret){
  if(i == n){
    return ret;
  }
  else if(j == n)
    return 0;
  return  dfs(s, j+1, j+1, n,ret + stol(s.substr(i, j-i+1))) + dfs(s, i, j+1, n, ret);
}

int main(void){
  unsigned int n;
  string s;
  cin >> s;
  n = s.size();
  cout << dfs(s, 0, 0, n, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int[][] map = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                map[i][j] = scan.nextInt();
            }
        }
        boolean found = true;
        // a1-a2
        if (map[0][0] - map[1][0] != map[0][1] - map[1][1] || map[0][1] - map[1][1] != map[0][2] - map[1][2]) {
            found = false;
        }
        // a2-a3
        if (map[1][0] - map[2][0] != map[1][1] - map[2][1] || map[1][1] - map[2][1] != map[1][2] - map[2][2]) {
            found = false;
        }
        // a3-a1
        if (map[2][0] - map[0][0] != map[2][1] - map[0][1] || map[2][1] - map[0][1] != map[2][2] - map[0][2]) {
            found = false;
        }
        // b1-b2
        if (map[0][0] - map[0][1] != map[1][0] - map[1][1] || map[1][0] - map[1][1] != map[2][0] - map[2][1]) {
            found = false;
        }
        // b2-b3
        if (map[0][1] - map[0][2] != map[1][1] - map[1][2] || map[1][1] - map[1][2] != map[2][1] - map[2][2]) {
            found = false;
        }
        // b3-b1
        if (map[2][2] - map[2][0] != map[1][2] - map[1][0] || map[1][2] - map[1][0] != map[0][2] - map[0][0]) {
            found = false;
        }
        System.out.println(found ? "Yes" : "No");
    }
}


Measured memory_bytes: 23252
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-13 06:59:44
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int a, b; cin >> a >> b;
  if (a >= 13) {
    cout << b << endl;
  } else if (a <= 5) {
    cout << 0 << endl;
  } else {
    cout << b / 2 << endl;
  }

  return 0;
}

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

long a[66], b[66];
int main() {
    int n, p = 1e9 + 7;
    cin >> n;
    for(int i = 0; i < n; i++) {
        long A;
        scanf("%ld", &A);
        for(int j = 0; j < 60; j++)
            (A & 1l << j ? a[j] : b[j])++;
    }
    long r = 0;
    for(int j = 0; j < 60; j++)
        (r += a[j] * b[j] % p * ((1l << j) % p)) %= p;
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int i,max=0;
	double a[50],max1=0.0,min1=1000000.0,sa;
	for(i=0;i<50;i++){
		int ret=scanf("%lf",&a[i]);
		if(ret==EOF) break;
		if(i>max) max=i;
	}
	for(i=0;i<=max;i++){
		if(a[i]>max1) max1=a[i];
		if(a[i]<min1) min1=a[i];
		sa=max1-min1;
	}
	printf("%.1f\n",sa);
	return 0;
}


Measured memory_bytes: 1976
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int a; cin >> a;
	cout << a + a * a + a * a * a << endl;
}

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

signed main() {
 	ios::sync_with_stdio(false);
  			cout.tie(nullptr);
  			cin.tie(nullptr);
  string s;
  bool flag = false;
 	cin >> s;
 	int N = s.length();
 
  for (int i = 0; i<(N-1)/2;i++)
  {
  	if(s.compare(i,1,s,N-1-i,1)==0){
  	flag = true;
 
  	}
  	else{
  	flag = false;
  
  	break;
  	}
  }

  	if(flag){
  		string a = s.substr(0,(N-1)/2);
  		

  		for (int i = 0; i<(N-3)/2 + 1;i++)
  {
  
  	if(a.compare(i,1,a,(N-1)/2-i-1,1)==0){
  	flag = true;

  	}
  	else{
  	flag = false;
  
  	break;
  	}
  	}
  }
 
  if(flag){
string x = s.substr((N+3)/2-1,(N-1)/2);
  		for (int i = 0; i<(N-3)/2 + 1;i++)
  {
  	if(x.compare(i,1,x,(N-1)/2-i-1,1)==0){
  	flag = true;
  	}
  	else{
  	flag = false;
  	break;
  	}
  	}
  
  }
 
  if(flag){
  	cout << "Yes";
  }
  else{
  	cout << "No";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

template <ll mod>
struct modular {
    ll value;
    modular(ll x = 0) {
        value = x % mod;
        if (value < 0) value += mod;
    }
    modular& operator+=(modular other) {
        if ((value += other.value) >= mod) value -= mod;
        return *this;
    }
    modular& operator-=(modular other) {
        if ((value -= other.value) < 0) value += mod;
        return *this;
    }
    modular& operator*=(modular other) {
        value = value * other.value % mod;
        return *this;
    }
    modular& operator/=(modular other) {
        ll a = 0, b = 1, c = other.value, m = mod;
        while (c != 0) {
            ll t = m / c;
            m -= t * c;
            swap(c, m);
            a -= t * b;
            swap(a, b);
        }
        a %= mod;
        if (a < 0) a += mod;
        value = value * a % mod;
        return *this;
    }
    modular& operator^=(modular other) {
        ll r = 1, x = value, n = other.value;
        while (n > 0) {
            if (n & 1) r = r * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        value = r;
        return *this;
    }
    modular operator+(modular rhs) {
        return modular(*this) += rhs;
    }
    modular operator-(modular rhs) {
        return modular(*this) -= rhs;
    }
    modular operator*(modular rhs) {
        return modular(*this) *= rhs;
    }
    modular operator/(modular rhs) {
        return modular(*this) /= rhs;
    }
    modular operator^(modular rhs) {
        return modular(*this) ^= rhs;
    }
    bool operator==(modular rhs) {
        return value == rhs.value;
    };
    bool operator!=(modular rhs) {
        return value != rhs.value;
    };
    bool operator<(modular rhs) {
        return value < rhs.value;
    }
};
template <ll mod>
string to_string(modular<mod> x) {
    return to_string(x.value);
}
template <ll mod>
ostream& operator<<(ostream& stream, modular<mod> x) {
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream << x.value;
}
template <ll mod>
istream& operator>>(istream& stream, modular<mod>& x) {
    stream >> x.value;
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream;
}
const ll mod = 1e9 + 7;
using mint = modular<mod>;

vector<mint> fac, finv;
inline void cinit(int n) {
    fac.resize(n, 1);
    finv.resize(n, 1);
    for (int i = 2; i < n; i++) {
        fac[i] = fac[i - 1] * i;
        finv[i] = finv[i - 1] / i;
    }
}
inline mint C(int n, int k) {
    if (n < k || k < 0 || n < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
inline mint H(int n, int k) {
    return C(n + k - 1, k);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cinit(n + 1);
    mint ans = 0;
    for (int i = 0; i < n; i++) {
        ans += fac[i] * fac[n - 1 - i] * C(i - 1, n - i - 1);
    }
    cout << fac[n] - ans << endl;
    return 0;
}

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

// // TLEとなってしまう実装
// int fib(int n)
// {
//   // ベースケース
//   if (n == 0)
//   {
//     return 1;
//   }
//   if (n == 1)
//   {
//     return 1;
//   }
//   // 再帰ステップ
//   return fib(n - 1) + fib(n - 2);
// }

vector<int> F(100, 0);

int fib(int n)
{
  // n項目を計算済みのとき
  if (F.at(n) > 0)
  {
    return F.at(n);
  }
  // n項目を未計算のとき
  if (n == 0 || n == 1)
  {
    F.at(n) = 1;
  }
  else
  {
    F.at(n) = fib(n - 1) + fib(n - 2);
  }
  return F.at(n);
}

int main()
{
  int n;
  cin >> n;
  cout << fib(n) << endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll ans[MAXn],tmp[MAXn];
int main(){
    IOS();
    ll n,q;
    cin >> n >> q;
    vector<ll> stk;
    stk.eb(n);
    while (q--) {
        ll x;
        cin >> x;
        while (SZ(stk) && stk.back() >= x) stk.pop_back();
        stk.eb(x);
    }
    debug(stk);

    int tt = SZ(stk);
    tmp[tt-1] = 1;
    for (int i=tt-1;i>=0;i--) {
        ll k = stk[i];
        while (k > 0) {
            int it = (int)(lower_bound(ALL(stk),k) - stk.begin());
            debug(it);
            if (it == 0) break;
            tmp[it-1] += (k / stk[it-1]) * tmp[i];
            k %= stk[it-1];
        }
        debug(k);
        if (k != 0) {
            ans[1] += tmp[i];
            ans[k+1] -= tmp[i];
        }
    }
    for (int i=1;i<=n;++i) {
        ans[i] += ans[i-1];
    }
    for (int i=1;i<=n;++i) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 5552
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
using namespace std;
const int INF=LLONG_MAX-1e10;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;
SET have;
main()
{
    IOS
    cin>>n>>m;
    fun(i)b[i]=1;
    fum(i)
    {
        int x;
        cin>>x;
        fu(i,1,x)cin>>a[i],b[a[i]]=0;

    }
    fun(i)if(b[i])ans++;
    out(ans)
    return 0;
}

Measured memory_bytes: 3664
# frozen_string_literal: true

k = gets.to_i
sum = 0
ab = []
k.times do |a|
  k.times do |b|
    ab << (a+1).gcd(b+1)
  end
end
ab.each do |i|
  (1..k).each do |j|
    sum+= i.gcd(j)
  end
end
puts sum


Measured memory_bytes: 14956
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define inf 1000000007
using namespace std;
signed main(){
	int r,c,n;
	cin>>r>>c>>n;
	vector<pair<int,int> > v;
	for(int i=0;i<n;i++){
		int x1,y1,x2,y2;
		int n1=0,n2=0;
		cin>>x1>>y1>>x2>>y2;
		if( ( x1>0 && x1<r && y1>0 && y1<c) || ( x2>0 && x2<r && y2>0 && y2<c)){
			n1 = -1;
			n2 = -1;
		}
		else{
			if(x1==0){
				n1 = y1;
			}
			else if( x1 == r){
				n1 = 2*c+r-y1;
			}
			else if( y1 == c){
				n1 = c+x1;
			}
			else{
				n1 = 2*c+2*r-x1;
			}
			if(x2==0){
				n2 = y2;
			}
			else if( x2 == r){
				n2 = 2*c+r-y2;
			}
			else if( y2 == c){
				n2 = c+x2;
			}
			else{
				n2 = 2*c+2*r-x2;
			}
		}
		if( n1 != -1){
			v.pb(mp(n1,i));
			v.pb(mp(n2,i));
		}
	}
	/* for(int i=0;i<v.size();i++){
		cout<<v[i].first<<" "<<v[i].second<<endl;
	} */
	sort(v.begin(),v.end());
	stack<int> sta;
	for(int i=0;i<v.size();i++){
		int ci = v[i].second;
		if( (!sta.empty() ) && sta.top() == ci){
			sta.pop();
		}
		else{
			sta.push(ci);
		}
	}
	if(sta.empty()){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std ;

int main(void){
  
  string s;
  //string S_renketsu = "";
  long long int K = 0;
  
  cin >> s;
  
  
  if (scanf("%lld", &K) != 1) {
   printf("Failed to read integer.\n");
  }
  
  /* //このように素直に定数倍するだけでは、数が非常に大きい場合にメモリ関連のエラーを吐く
  for( int i = 0 ; i < K ; i++ ){
   S_renketsu += s; 
  }
  */

  //cout << S_renketsu << endl;S_renketsu内には繰り返し文字列が格納されている。
  
  char tmp_ch = 'X';
  int num_renzoku_kugiri = 0;
  int num_moji_renzoku = 1;
  int answer_number = 0;
  long long int cnt = 0;//最終的に出力する数字
  
  int all_same = 0;//文字が全て同じがチェックする変数

  //文字列の先端と末端の同じ文字数を調べる
  char s_first = s[0];
  char s_end   = s[ s.size() - 1 ];
  int count_first_same = 0;
  int count_end_same = 0;
  int mattan_flag = 0;

  
  if( s.size() == 1 )cnt = (int)(K / 2);
  else{
   
   char check_all_same_word = s[0];
   for( int i = 0; i < s.size() ; i++){
    if( s[i] != check_all_same_word){
      all_same = 1;
    }
     check_all_same_word = s[i];
   }
  }
  
  if( all_same == 0 )cnt = (long long int)(K * s.size() / 2);
  
  
  else{
    for( int i = 0  ; s[i] == s_first ; i++)count_first_same++;
    for( int i = s.size() - 1  ; s[i] == s_end ; i--)count_end_same++;
    if( count_first_same + count_end_same >= 5 && (count_first_same + count_end_same) % 2 == 1)mattan_flag = 1;
    
    for(int i = 0; i <= s.size(); i++){//~~~~~~~~~~~~~~~~~~~~~
      char ch;
      if( i != s.size())ch = s[i];
      else{
        ch = 'X';
      }
    
   	 if( tmp_ch == ch && num_moji_renzoku <2){
    	  num_moji_renzoku++;
     	 num_renzoku_kugiri = 1;
         
   	 }
     else{
     	 num_renzoku_kugiri = 0;
     }
      
     if( i == s.size()){
         num_renzoku_kugiri = 0;
     }
      
     if( num_moji_renzoku >= 2 && num_renzoku_kugiri == 0  ){
     	 answer_number = answer_number + (int)( num_moji_renzoku / 2 );
       s[i - 1] = 'X';
      	num_moji_renzoku = 1;
   	 }
    
     tmp_ch = ch;
    }//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //printf("このとき、%d\n", answer_number);
    //cout << s << endl;
  
    if( s[0] == s[ s.size()-1 ] )cnt = answer_number * K + (K - 1) - (K * mattan_flag) + 1 * mattan_flag;
    //if( s[0] == s[ s.size()-1 ] )cnt = answer_number * K + (K - 1);
    else{cnt = (long long int)answer_number * (long long int)K;}
    }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

string s;
cin >> s;
int n = s.length(), i, k = 0;
for(i = 0; i < n; ++i){
	if(i % 2 == 0){
		if(s[i]=='R' || s[i]=='U' || s[i]=='D') k++; 
	}
	else{
		if(s[i]=='L' || s[i]=='U' || s[i]=='D') k++; 	
	}
}
if(k == n) cout << "Yes";
else cout << "No";
return 0;
}

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

int main()
{
    string S;
    cin >> S;

    int ans = 0;
    int num = 0;
    for (int i=0; i<(int)(S.length()); i++)
    {
        if (S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T')
        {
            num++;
            ans = max(num, ans);
        }
        else
        {
            ans = max(num, ans);
            num = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3544
n = int(input())
res = ""
#res += chr(ord("a") -1 + (n % 27))
#n -= 1

c = 0
while True:
    n -= 26 ** c
    if n < 0:
        break
    ch = (n % (26 ** (c+1))) // (26 ** c)
    #print(ch, chr(ord("a") + ch))
    res += chr(ord("a") + ch)
    c += 1

print(res[::-1])



Measured memory_bytes: 61552
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String inputed = new String(in.readLine());

		String value[] = inputed.split("[\\s]+");
		//int intInputed = Integer.parseInt(inputed);

		int first  = Integer.parseInt(value[0]);
		int second = Integer.parseInt(value[1]);
		int third  = Integer.parseInt(value[2]);

		int[] intvalue = new int[3];
		intvalue[0] = first;
		intvalue[1] = second;
		intvalue[2] = third;

		intvalue = sort(intvalue, 0, 1);
		intvalue = sort(intvalue, 1, 2);
		intvalue = sort(intvalue, 0, 1);

		System.out.println(intvalue[0] + " " + intvalue[1] + " " + intvalue[2]);




	}
	public static int[] sort(int[] array, int number, int number2) {
		if (array[number] > array[number2]) {
			int pos1 = array[number];
			int pos2 = array[number2];

			array[number]  = pos2;
			array[number2] = pos1;
		}

			return array;


	}
}

Measured memory_bytes: 24336
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define pb push_back
#define int long long
#define pii pair<int, int>
#define tupint tuple<int, int, int>
#define tupint2 tuple<int, int, int, int>
#define str string
using namespace std;
const int M = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<int> H(n);
    for (int i = 0; i < n; i++) cin >> H[i];
    vector<int> dp = {0, abs(H[0] - H[1])};
    for (int i = 2; i < n; i++) {
        dp.pb(min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2])));
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 2168