akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
    string s;
    int Q;
    cin >> s >> Q;

    int dir = 1;
    string L, R;
    while (Q--) {
        int T;
        cin >> T;
        if (T == 1) {
            dir *= -1;
        } else {
            int F;
            char C;
            cin >> F >> C;
            if (dir == 1) {
                (F == 1) ? (L += C) : (R += C);
            } else {
                (F == 1) ? (R += C) : (L += C);
            }
        }
    }
    reverse(L.begin(), L.end());
    s = L + s + R;
    if (dir == -1) reverse(s.begin(), s.end());
    
    cout << s << endl;
    return 0;
}



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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

double p[500000];
int main() {
   ll i,j;
    ll n,k;
    double max=0,ans=0;
    
    cin >> n>>k;
    for(i=0; i<n; i++)
    {
      
      cin >>p[i];
      p[i]=(p[i]+1)/2;
      // cout << p[i] <<endl;
    }

    for(i=0; i<k; i++)
    {
      max+=p[i];
      // cout<<max<<endl;
    }

double num=max;
    for(i=0; i<n-k; i++)
    {
      num=num-p[i]+p[i+k];
      
      if(num>max)
      {
        max=num;
      }
    }
    cout <<fixed;
  cout <<setprecision(7)<< max << endl;
}



Measured memory_bytes: 1792
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define be begin
#define sz(a) (ll)a.size()
#define INF 1e18
 
typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
 
// ll mod=1e9+7;
// ll gcd(ll a, ll b){
//     if(a<b) swap(a,b);
//     if(b==0) return a;
//     return gcd(b,a%b);
// }
 
// ll fun(ll x, ll y){
//     ll rem=1;
//     while(y!=0){
//         if(y%2==1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y/=2;
//     }
//     return rem;
// }

ll n,m;
ve<ve<ll>>ar(100001);
ll dp[100001]={0};
ll dp1[100001]={0};
ll ans[100001]={0};
ll par[100001]={0};
void dfs(ll x,ll p){
	dp[x]=1;
	par[x]=p;
	ll y=1;
	ve<ll>tr;
	for(auto i:ar[x]){
		if(i!=p){
			tr.pb(i);
			dp1[i]=y;
			dfs(i,x); y=(y*dp[i])%m;
		}
	}
	dp[x]=(dp[x]+y)%m;
	y=1;
	for(ll i=sz(tr)-1;i>=0;i--){
		dp1[tr[i]]=(dp1[tr[i]]*y)%m;
		y=(y*dp[tr[i]])%m;
	}
}

void dfs1(ll x,ll p){
	if(p==0) ans[x]=(dp[x]-1+m)%m;
	else{
		dp1[x]=dp1[x]*(dp1[p]+1)%m;
		ans[x]=(dp[x]-1+m)%m*(dp1[x]+1)%m;
	}
	for(auto i:ar[x]){
		if(i!=p){
			dfs1(i,x);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(ll i=1,u,v;i<n;i++){
		cin>>u>>v;
		ar[u].pb(v);
		ar[v].pb(u);
	}
	dfs(1,0);
	dp1[1]=0;
	dfs1(1,0);
	for(ll i=1;i<=n;i++){
		cout << ans[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 18944
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
const int MOD=1e9+7;
int main() {
  int n;
  cin >> n;
  int a[n]={},b[n]={};
  long long ans=1;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  if(n%2==0) {
    int j=0;
    for(int i=n-1; i>=1; i-=2) {
      b[j]=b[j+1]=i;
      j+=2;
    }
    for(int i=0; i<n; i++) {
      if(a[i]!=b[i]) {
        cout << 0 << endl;
        return 0;
      }
    }
    for(int i=0; i<n/2; i++) {
      ans=(ans*2)%MOD;
    }
    cout << ans << endl;
  }
  else {
    int j=0;
    for(int i=n-1; i>=0; i-=2) {
      if(i==0) {
        b[j]=i;
      }
      b[j]=b[j+1]=i;
      j+=2;
    }
    for(int i=0; i<n; i++) {
      if(a[i]!=b[i]) {
        cout << 0 << endl;
        return 0;
      }
    }
    for(int i=0; i<n/2; i++) {
      ans=(ans*2)%MOD;
    }
    cout << ans << endl;
  }
}

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

class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    // メンバ変数---
    string S;
    // -------------

    void calc()
    {
        S = cin.next();
        List<string> dreamarray = new List<string> { "dream", "dreamer", "erase", "eraser" };
        bool judge = false;
        while(S.Length > 0)
        {
            judge = false;
            foreach (var test in dreamarray)
            {
                if (S.EndsWith(test))
                {
                    S = S.Substring(0,S.Length - test.Length);
                    judge = true;
                    break;
                }
            }
            if (!judge)
            {
                break;
            }
        }

        if (judge)
        {
            Write<string>("YES");
        }
        else
        {
            Write<string>("NO");
        }

    }

    void Write<T>(T v)
    {
        Console.WriteLine(v);
    }

    int Pow(int x, int y)
    {
        return (int)Math.Pow(double.Parse(x.ToString()), double.Parse(y.ToString()));
    }

    double Pow(double x, double y)
    {
        return Math.Pow(x, y);
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}


Measured memory_bytes: 32028
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
#define N 200005
int n,fa[N],cnt,head[N],vis[N],mk[N],f[N],len;
struct edge{int to,nxt;}e[N];
void adde(int x,int y){e[++cnt].to=y;e[cnt].nxt=head[x];head[x]=cnt;}
void dfs(int u){
	for (int i=head[u];i;i=e[i].nxt) if (!mk[e[i].to]) dfs(e[i].to);
	for (int i=head[u];i;i=e[i].nxt) if (!mk[e[i].to]) vis[f[e[i].to]]=1;//注意这里一定要分开写！！否则不同儿子的dfs会相互影响
	while (vis[f[u]]) f[u]++;
	for (int i=head[u];i;i=e[i].nxt) if (!mk[e[i].to]) vis[f[e[i].to]]=0;
}
int main(){
	scanf("%d",&n);
	rep (i,1,n) scanf("%d",&fa[i]),adde(fa[i],i);
	int now=1;
	for (;!vis[now];now=fa[now]) vis[now]=1;
	for (;!mk[now];now=fa[now]) mk[now]=1;
	memset(vis,0,sizeof(vis));
	int Mx=0,Mi=1e9;
	rep (i,1,n) if (mk[i]){
		dfs(i);len++;
		Mx=max(Mx,f[i]);
		Mi=min(Mi,f[i]);
	}
	if (Mx==Mi&&(len&1)) puts("IMPOSSIBLE");else puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 5632
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.lang.Math;

class Main{

    private final static int DATA_TYPE_INTEGER = 1;
    private final static double DATA_TYPE_DOUBLE = 2.0;
    
    public static void main(String[] args){
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(inputStreamReader);
        

        // ----- 共通変数 ----- //
        int[] num;
        int DataType = DATA_TYPE_INTEGER;
        //double[] num;
        //double DataType = DATA_TYPE_DOUBLE;
        boolean flag = false; // 提出時はfalse

        // ----- 課題別変数 ----- //
        int carNum = 0;
        int[] Cars = new int[100];
        
        try {
            while(flag || reader.ready()){
                // データの取得
                num = changeNum(reader.readLine(), DataType);

                // ----- データ処理 ----- //
                switch(num[0]) {
                    case 0  : System.out.println(Cars[--carNum]); break;
                    default : Cars[carNum++] = num[0]; break;
                }
                
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    // ----- 自作関数（課題別） ----- //


    // ----- 自作関数（共通） ----- //

    private static int[] changeNum(String str, int DataType){
    //private static double[] getNum(String str){
        String[] data = str.split(" "); 
        int[] num = new int[data.length];

        for (int i = 0; i < data.length; i++){
            num[i] = Integer.parseInt(data[i]);
        }

        return num;
    }

    private static double[] changeNum(String str, double DataType){
        String[] data = str.split(" "); 
        double[] num = new double[data.length];

        for (int i = 0; i < data.length; i++){
            num[i] = Double.parseDouble(data[i]);
        }
            
        return num;
    }

    private static int[] extractList(int[] originalList, int begin, int end){
        int[] list = new int[end - begin];
        int p = 0;

        for (int i = begin; i <= end; i++) {
            list[p++] = originalList[i];
        }

        return list;
    }

    private static double[] extractList(double[] originalList, int begin, int end){
        double[] list = new double[end - begin];
        int p = 0;

        for (int i = begin; i < end; i++) {
            list[p++] = originalList[i];
        }

        return list;
    }

    private static void swap(int[] box, int a, int b) {
        int temp = box[a];
        box[a] = box[b];
        box[b] = temp;
    }

    private static void swap(double[] box, int a, int b) {
        double temp = box[a];
        box[a] = box[b];
        box[b] = temp;
    }
}


Measured memory_bytes: 24156
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map[T](converter)
  }

  implicit val idConverter: String => String = s => s
  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = get[Int]
    val as = getArray[Long].sorted

    var product = BigInt(1)
    for (a <- as) {
      product *= a
      if ( product > 1000000000000000000L) {
        out.println(-1)
        out.flush()
        return
      }
    }

    out.println(product)
    out.flush()
  }
}

Measured memory_bytes: 70308
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  int N,K;
  cin >> N >> K;
  int A[N];
  // 2進表現で1が32回
  ll MAX_SUM = (1LL<<62)-1;

  REP(i,N){
    cin >> A[i];
  }
  int N_PATTERNS = (N*(N+1))/2;
  ll AA[N_PATTERNS];
  REP(i,N_PATTERNS){
    AA[i] = 0LL;
  }

  // 連続する部分列の和
  int cnt = 0;
  REP(i,N){
    REP(j,N){
      if (i<=j){
        for(int index=i;index<=j;index++){
          AA[cnt] +=A[index]; 
        }
        cnt++;
      }
    }
  }


  // REP(i,N_PATTERNS){
  //   cout << AA[i] << endl;
  // }

  // bool dp[MAX_SUM][N_PATTERNS];

  // REP(i,MAX_SUM){
  //   REP(j,N_PATTERNS){
  //     dp[i][j] = false;
  //   }
  // }

  vector<ll> v;
  int keta;
  for(int i=61;i>=0;i--){
    int cnt_exist = 0;
    v.clear();
    REP(j,N_PATTERNS){
      if (AA[j] & 1LL<<i){
        v.push_back(AA[j]);
        cnt_exist++;
      }
    }
    if (cnt_exist >= K){
      keta = i;
      break;
    }
  }

  // REP(i,SZ(v)){
  //   cout << v[i] << endl;
  // }

  vector<ll> vv;

  for(int i=keta-1;i>=0;i--){
    int cnt_exist = 0;
    vv.clear();
    REP(j,SZ(v)){
      if (v[j] & 1LL<<i){
        cnt_exist++;
        vv.push_back(v[j]);
      }
    }
    if (cnt_exist >= K){
      v = vv;
      // cout << "cnt_exist > K" << endl;
    }
    // cout << "i: " << i << endl;
    // REP(j,SZ(vv)){
    //   cout << vv[j] << endl;
    // }
  }

  // cout << "result " << endl;
  ll result = MAX_SUM;
  REP(j,SZ(v)){
    result &= v[j];
    // cout << v[j] << endl;
  }
  cout << result << endl;




  return 0;
}


Measured memory_bytes: 5748
#include<bits/stdc++.h>
#define mxn 1000010
#define LL long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define node(a,b,c) (node){a,b,c}
using namespace std;
const int inf=1e9,mod=1e9+7;
int n,x,y,sl,fh;
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();x=rd();y=rd();
	printf("%d\n",min(y,n*x));
	return 0;
}

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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;

	cout << (n - 1) * n / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a,n) for(int i = 0; i < n; i++) cin >> a[i];
#define ffor(n) for(int i = 0; i < n; i++)
 
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef unordered_map<string,int> umsi;
 
 
int32_t main()
{
    fast_io;
    int n,k;
    cin>>n>>k;
    vi a(n);
    c(a,n);
    int m=1e9+7;
    vii dp(n,vi(k+1,0));
    for(int i=0;i<=min(k,a[0]);i++)dp[0][i]=1;
    int z=1;
    for(int i=1;i<n;i++)
    {
        vector<int>sum(k+1,0);
        sum[0]=dp[i-1][0];
        for(int j=1;j<=k;j++)sum[j]=(sum[j-1]%m+dp[i-1][j]%m)%m;
        for(int j=0;j<=k;j++)
        {
            int l=j-min(j,a[i])-1;
            dp[i][j]=sum[j];
            if(l>=0)
            dp[i][j]=(dp[i][j]-sum[l]+m)%m;
        }

        
    }
    
    
    cout<<dp[n-1][k]<<lc;
    return 0;
}

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

int main()
{
    string str;

    int c[26];
    for(int i=0;i<26;i++)
    {
        c[i] = 0;
    }
    
    while(getline(cin, str))
    {
    for(int j=0;j<str.size();j++)
    {
        if('A' <= str[j] && str[j] <= 'Z') {
            c[str[j]-'A']++;
        } else if('a' <= str[j] && str[j] <= 'z') {
            c[str[j]-'a']++;
        }
    }
    }
    
    for(int i=0;i<26;i++)
    {
        char l = i + 'a';
        cout << l << " : " << c[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3240
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

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

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	A, B, Q := sc.nextInt(), sc.nextInt(), sc.nextInt()
	S := sc.nextIntSlice(A)
	T := sc.nextIntSlice(B)
	X := sc.nextIntSlice(Q)
	for i := 0; i < Q; i++ {
		x := X[i]
		a1, a2 := search(x, S)
		b1, b2 := search(x, T)
		da1, da2, db1, db2 := abs(x-a1), abs(x-a2), abs(x-b1), abs(x-b2)
		ans := INF
		ans = min(ans, max(da1, db1))
		ans = min(ans, max(da2, db2))
		ans = min(ans, min(da1, db2)*2+max(da1, db2))
		ans = min(ans, min(da2, db1)*2+max(da2, db1))
		fmt.Fprintln(wtr, ans)
	}
}

func search(key int, a []int) (int, int) {
	ng := len(a)
	ok := -1
	for abs(ok-ng) > 1 {
		mid := (ok + ng) / 2
		// 西をさがす
		if a[mid] <= key {
			ok = mid
		} else {
			ng = mid
		}
	}
	if ok == -1 {
		return -INF, a[0]
	} else {
		if ok+1 < len(a) {
			return a[ok], a[ok+1]
		} else {
			return a[ok], INF
		}
	}
}


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

int main(){
    string s;
    while(cin >> s){
        int n = s.size();
        int ioi = 0, joi = 0;
        for(int i=0;i<n-2;i++){
            if(s.substr(i,3)=="IOI") ioi++;
            if(s.substr(i,3)=="JOI") joi++;
        }
        cout << joi << '\n' << ioi << endl;
    }
    return 0;
}



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

using namespace std;

const int max_n = 200222, inf = 1000111222;

int n, c1, c2;
char s[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%s", &n, s);
    for (int i = 0; i < n; ++i) {
        if (s[i] == '.') {
            ++c1;
        } else {
            ++c2;
        }
    }
    int ans = inf;
    int cur1 = 0, cur2 = 0;
    for (int i = 0; i <= n; ++i) {
        ans = min(ans, cur2 + c1 - cur1);
        if (i < n && s[i] == '.') {
            ++cur1;
        } else {
            ++cur2;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class Main {

	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens()) {
				String cad = br.readLine();
				if (cad == null)
					return null;
				tk=new StringTokenizer(cad);
			}
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public long nextLong() throws NumberFormatException, IOException{
			return Long.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}
	
	static class Node {
		int id;
		int color;
		int dist;
		int incoming;
		ArrayList<Integer> e;
		ArrayList<Integer> w;
		public Node(int id) {
			this.id = id;
			color = -1;
			e = new ArrayList<Integer>();
			w = new ArrayList<Integer>();
			dist = -1;
			incoming = 0;
		}
	}
	
	static boolean dfs(int id, int dist) {
		if (a[id].color == 0)
			return false;
		if (a[id].color == 1)
			return dist == a[id].dist;
		a[id].color = 0;
		a[id].dist = dist;
		for(int i = 0; i < a[id].e.size(); i++) {
			int next = a[id].e.get(i);
			int w = a[id].w.get(i);
			if (!dfs(next, dist + w))
				return false;
		}
		a[id].color = 1;
		return true;
	}
	
	static int N, M;
	static Node[] a;
	
	public static void main(String args[]) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		N = sc.nextInt();
		M = sc.nextInt();
		a = new Node[N];
		for(int i = 0; i < N; i++)
			a[i] = new Node(i);
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt() - 1;
			int D = sc.nextInt();
			a[L].e.add(R);
			a[L].w.add(D);
			a[R].incoming++;
		}
		for(int i = 0; i < N; i++) {
			if (a[i].incoming == 0 && !dfs(i, 0)) {
				System.out.println("No");
				return;
			}
		}
		for(int i = 0; i < N; i++) {
			if (a[i].color == -1) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


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

using namespace std;

int main(){
  int N; cin >> N;
  string s;
  for(int i=0;i<N;++i){
	string t; cin >> t;
	s += t;
  }

  set<int> memo;
  for(int l=1;l<4;++l)
	for(int i=0;i+l<=N;++i){
	  memo.insert(atoi(s.substr(i,l).c_str()));
	}

  for(int i=0;;++i)
	if(!memo.count(i)){
	  cout << i << endl;
	  break;
	}  
  
  return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
int a[200010],b[200010];
int tmp[200010];
int n;
int find(int k){
    int l=1,r=n+1;
    while(l<r){
        int mid=(l+r)>>1;
        if(tmp[mid]>=k)	r=mid;
		else			l=mid+1;
    }
    return l;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)	scanf("%d",a+i);
    for(int i=1;i<=n;i++)	scanf("%d",b+i);
    int ans=0;
    for(int k=1;k<=29;k++){
        for(int i=1;i<=n;i++)	tmp[i]=b[i]%(1<<k);
        sort(tmp+1,tmp+n+1);
        int cnt=0; 
        for(int i=1;i<=n;i++){
            cnt+=n-find((1<<(k-1))-(a[i]%(1<<k)))+1;
            cnt-=find((1<<k)+(1<<(k-1))-a[i]%(1<<k))-find((1<<k)-(a[i]%(1<<k)));
    	}
		ans+=(cnt&1)*(1<<(k-1));
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int ans=0;
  cin>>N;
  ans=N/1.08;
  if(floor(ans*1.08)==N){
    cout<<ans<<endl;
  }
  else if(floor((ans+1)*1.08)==N){
    cout<<ans+1<<endl;
  }
  else{
    cout<<":("<<endl;
  }
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int x, y;
    cin >> x >> y;
    if ((x+y)%3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x+y)/3;
    x -= n; y -= n;
    combination c(x+y);
    mint ans = c(x+y,x);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13828
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;

int nearest_checkpoint(int x, int y, int m, int c[], int d[]) {
  int ret = 0, ds = INF;
  for (int i = 0; i < m; i++) {
    int nds = abs(x - c[i]) + abs(y - d[i]);
    if (nds < ds) {
      ds = nds;
      ret = i + 1;
    }
  }
  return ret;
}

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int c[m], d[m];
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < n; i++) {
    cout << nearest_checkpoint(a[i], b[i], m, c, d) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin  >> a >> b;

    FOR(i,1,100000){
        int aa = (int)floor(((double)i * 0.08));
        int bb = (int)floor(((double)i * 0.10));
        if(a == aa && b == bb){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b;
  ci(a>>b);
  vec c(a);
  For(i,0,a)
    ci(c[i]);
  sort(c,c);
  vec d(a-b+1);
  For(i,0,a-b+1)
    d[i]=c[b+i-1]-c[i];
  sort(d,d);
  co(d[0]);
  }

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

ll n,ans;

int main(void)
{
	cin>>n;
	ans=n-1;
	for (ll i=(int)floor(sqrt(n)); i>=1; i--)
	{
		ll j=n/i;
		if(i*j==n)
		{
			ans=i+j;
			break;
		}
	}
	cout<<ans-2;
	return 0;
}

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

using namespace std;
typedef long long LL;

#define LOG(...) fprintf (stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fll;

const int N = 100005;
int n, a[N], cnt[2][N], nd[2][N], nw;
bool cmp(int x, int y){return cnt[nw][x] > cnt[nw][y];}
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {scanf("%d", &a[i]); ++cnt[i % 2][a[i]];}


    for (int i = 1; i <= 100000; i++) nd[0][i] = nd[1][i] = i; 
    for (int i = 0; i < 2; i++) {nw = i; sort(nd[i] + 1, nd[i] + 100000 + 1, cmp);} 

    if (nd[0][1] != nd[1][1]) {
        cout << n - cnt[0][nd[0][1]] - cnt[1][nd[1][1]] << endl; 
        return 0; 
    }
    else {
        cout << n - max(cnt[0][nd[0][1]] + cnt[1][nd[1][2]], cnt[0][nd[0][2]] + cnt[1][nd[1][1]]) << endl; 
        return 0; 
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll dp[n][n];
    rep(i,n) dp[i][i]=a.at(i);
    for (int i=1;i<n;i++){
        rep(j,n-i){
            dp[j][j+i]=max(a.at(j)-dp[j+1][j+i],a.at(j+i)-dp[j][j+i-1]);
        }
    }
    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 70400
(defun betweenp (num inf sup)
  (if (>= num inf)
      (if (<= num sup)
          t
          nil)
      nil))

(defun convert-data (str)
  (list (parse-integer (subseq str 0 2)) (parse-integer (subseq str 2 4))))
(defun monthp (num)
  (betweenp num 1 12))

(defun yearp (num)
  (betweenp num 0 99))

(defun yymmp (lst)
  (and (yearp (car lst))
       (monthp (cadr lst))))

(defun mmyyp (lst)
  (and (monthp (car lst))
       (yearp (cadr lst))))

(defparameter input (read-line))
(let ((data (convert-data input)))
  (cond ((and (yymmp data)
              (mmyyp data)) (format t "AMBIGUOUS"))
        ((and (yymmp data)
              (not (mmyyp data))) (format t "YYMM"))
        ((and (not (yymmp data))
              (mmyyp data)) (format t "MMYY"))
        (t (format t "NA"))
        ))

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

int main(){
    string S;
    cin >> S;
    int length = S.size();
    
    //１文字目と同じものがあるか？
    for(int i = 1;i<length;i++){
        if(S[0]==S[i]){
            switch(i){
                case 1://2文字目の1文字目が同一だった場合。
                    if(S[2]==S[3]&&S[0]!=S[2]) 
                        cout<<"Yes";
                    else
                        cout << "No";
                    break;
                case 2:
                    if (S[1] == S[3] && S[0] != S[1])
                        cout << "Yes";
                    else
                        cout << "No";
                    break;
                case 3:
                    if (S[1] == S[2] && S[0] != S[1])
                        cout << "Yes";
                    else
                        cout<< "No";
                    break;
            }
            return 0;
        }
    }
    cout<<"No";
    return 0;

}

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

using namespace std;

typedef long long LL;

const int N = 55, M = N * N;

struct Edge{
    int a, b;
}e[M];

int n, m;

int p[N];
int find(int x)
{
    if(p[x] != x)  p[x] = find(p[x]);
    return p[x];
}

int main()
{
    scanf("%d%d", &n, &m);
    
    for(int i = 0; i < m; i ++)  scanf("%d%d", &e[i].a, &e[i].b);
    
    int res = 0;
    for(int k = 0; k < m; k ++)
    {
        for(int i = 1; i <= n; i ++)  p[i] = i;
        
        int cnt = 0;
        for(int i = 0; i < m; i ++)
        {
            if(i == k)  continue;
            
            int a = e[i].a, b = e[i].b;
            int pa = find(a),  pb = find(b);
            if(pa != pb)
            {
                p[pa] = pb;
                cnt ++;
            }
        }
        if(cnt < n - 1)  res ++;
    }
    printf("%d\n", res);
    return 0;
}

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

int main(){
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a(n+1);
	for(int i=1; i<= n; i++) scanf("%d",&a[i]);
	vector<int> b(n+1);
	int j = 1;
	int i;
	for( i = 1;i<n+3; i++){
		if (b[j] !=0){
			break;
		}
		b[j] = i;
		j = a[j];
	}
	if(k-b[j]+1>0){
		int tmp = (k-b[j]+1) % (i - b[j]);
		for(i =0;i<tmp;i++){
			j = a[j];
		}
		cout << j << endl;
	}else{
		j = 1;
		for(i = 0; i<k;i++){
			j = a[j];
		}
		cout << j << endl;
	}
	return 0;
}


Measured memory_bytes: 4924
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int H,W,N;
    cin>>H>>W>>N;
    int sr,sc;
    cin>>sr>>sc;
    string S,T;
    cin>>S>>T;
    bool ok=true;
    vector<int> dp_L(2*N+1,0),dp_R(2*N+1,0),dp_U(2*N+1,0),dp_D(2*N+1,0);
    dp_L[0]=sc;
    dp_R[0]=sc;
    dp_U[0]=sr;
    dp_D[0]=sr;
    REP(i,2*N){
        dp_L[i+1]=dp_L[i];
        dp_R[i+1]=dp_R[i];
        dp_U[i+1]=dp_U[i];
        dp_D[i+1]=dp_D[i];
        
        if(i%2==0){//Takahshiのターン
            if(S[i/2]=='L'){
                dp_L[i+1]--;
            }
            if(S[i/2]=='R'){
                dp_R[i+1]++;
            }
            if(S[i/2]=='U'){
                dp_U[i+1]--;
            }
            if(S[i/2]=='D'){
                dp_D[i+1]++;
            }
        }else{
            if(T[i/2]=='R'&&dp_L[i+1]<W){
                dp_L[i+1]++;
            }
            if(T[i/2]=='L'&&dp_R[i+1]>1){
                dp_R[i+1]--;
            }
            if(T[i/2]=='D'&&dp_U[i+1]<H){
                dp_U[i+1]++;
            }
            if(T[i/2]=='U'&&dp_D[i+1]>1){
                dp_D[i+1]--;
            }
        }
        if(dp_L[i+1]<=0) ok=false;
        if(dp_R[i+1]>=W+1) ok=false;
        if(dp_U[i+1]<=0) ok=false;
        if(dp_D[i+1]>=H+1) ok=false;
        
    }
    
    

    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 9836
s=input()
q=int(input())
head=[]
tail=[]
rev=False
for _ in range(q):
  tmp=list(input().split())
  if tmp[0]=='1':
    if rev==False:
      rev=True
    else:
      rev=False
  if tmp[0]=='2':
    if rev==False:
      if tmp[1]=='1':
        head.append(tmp[2])
      if tmp[1]=='2':
        tail.append(tmp[2])
    if rev==True:
      if tmp[1]=='1':
        tail.append(tmp[2])
      if tmp[1]=='2':
        head.append(tmp[2])
head=''.join(map(str,head))
tail=''.join(map(str,tail))
ans=head[::-1]+s+tail
if rev==True:
  ans=ans[::-1]
print(ans)

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

using namespace std;

#pragma GCC optimize "-O3"

#define watch(x) cout << (#x) << " is " << (x) << endl

#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a-1;i>=b;i--)
#define nl          cout<<endl;
#define test()      lli t;cin>>t;while(t--)
#define sp(n)       setprecision(n)

#define lli     long long int
#define ulli    unsigned long long int
#define ld      long double
#define uld     unsigned long double
#define S       string
#define C       char
#define elif    else if
 
#define pb      push_back
#define pp      pop_back
#define plli    pair<lli,lli>
#define vlli    vector<lli>
#define vulli   vector<ulli>
#define vld     vector<ld>
#define vs      vector<string>

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define vsort(v) sort(v.begin(),v.end())

// #define max1 1000001    //10^6 + 1
// #define max2 10000001   //10^7 + 1
// #define max3 1000000007 //10^9 + 7
#define inf  1000000009 //10^9 + 9

const int N = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli n,w;
 	cin >> n >> w;
 	// vector<lli> dp(w+1,0);
 	vlli value(n);
 	vlli weight(n);
 	for (int i = 0; i < n; ++i)
 	{
 		cin >> weight[i] >> value[i];
 	}	
 	lli sum_values = 0;

 	for (int i = 0; i < n; ++i)
 	{
 		sum_values += value[i];
 	}

 	vlli dp(sum_values+3, inf);
 	dp[0] = 0;

 	// dp[i] stores max value when weight is i
 	for (lli i = 0; i < n; ++i)
 	{
 		for (lli value_alr= sum_values-value[i]; value_alr >= 0 ; --value_alr)
 		{
 			dp[value_alr + value[i]] = min(dp[value_alr + value[i]], dp[value_alr] + weight[i]);
 		}
 	}
 	lli ans=0;
 	for (lli i = 0; i <= sum_values; ++i)
 	{
 		if(dp[i] <= w)
 			ans = max(i ,ans);
 	}
 	cout << ans << '\n';
 	// lli a[n],b[n],c[n];
 	// lli ite[n];
    
    return 0;
}


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

int main () {
    int N, D;
    cin >> N >> D;
    vector <double> vec(N), date(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i) >> date.at(i);
    }

    int count=0;

    for (int i=0; i<N; i++) {
        if (sqrt(vec.at(i)*vec.at(i)+date.at(i)*date.at(i)+0.0)<=D) {
            count++;
        }
    }
    cout << count << endl;
}


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

int main()
{
  int x, y;
  cin >> x >> y;
  int count = 0;
  for (int i = 0; i <= x; i++)
  {
    int k, t = 0;
    k = i;
    t = x - i;

    if(y==k*4+t*2){
      ++count;
    }
  }
  if(count >0){
    cout << "Yes" << endl;
  }else if(count == 0){
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
	bool num[250000] = {true,true,};
	for(int i=2; i<500; i++){
		if(!num[i]){
			for(int j=i*i; j<250000; j+=i){
				num[j] = true;
			}
		}
	}
	for(;;){
		int n,sum = 0;
		cin >>n;
		if(!n){break;}
		for(int i=n+1; i<=n*2; i++){
			if(!num[i]){sum++;}
		}
		cout <<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
using namespace std;
 
#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
 
typedef long long ll;
 
int main() {
    
    int N, M;
    cin >> N >> M;
	int res = 0;
	bool flg;
	vector<vector<int>> favoFoods;
	for (int i = 0; i < N; i++) {
		int num;
		cin >> num;
		vector<int> favoFood;
		for (int j = 0; j < num; j++) {
			int favFoodNum;
			cin >> favFoodNum;
			favoFood.push_back(favFoodNum);
		}
		favoFoods.push_back(favoFood);
	}
	if (favoFoods.size() == 1) {
		cout << favoFoods.at(0).size() << endl;
		return 0;
	}
	
	for (int i = 0; i < favoFoods.at(0).size(); i++) {
		for (int j = 1; j < N; j++) {
			flg = false;
			for (int k = 0; k < favoFoods.at(j).size(); k++) {
				if (favoFoods.at(0).at(i) == favoFoods.at(j).at(k)) {
					flg = true;
					if (j == N - 1) res++;
 					break;
				} 
			}
			if (!flg) break;
		}
	}

 	cout << res << endl;
    return 0;
}

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

vector<pair<int64_t, int64_t>> primeFactorization(int64_t n) {
    vector<pair<int64_t, int64_t>> result;
    for (int64_t i = 2; i * i <= n; i++) {
        int64_t num = 0;
        while (n % i == 0) {
            n /= i;
            num++;
        }
        if (num != 0) {
            result.push_back({ i, num });
        }
    }

    if (n != 1) {
        result.push_back({ n, 1 });
    }

    return result;
}

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for (int64_t& a : A) {
        cin >> a;
    }

    int64_t g = 0;
    for (int64_t a : A) {
        g = gcd(g, a);
    }

    if (g != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    set<int64_t> prime_set;
    for (int64_t a : A) {
        vector<pair<int64_t, int64_t>> primes = primeFactorization(a);
        for (const auto& p : primes) {
            if (prime_set.count(p.first) != 0) {
                cout << "setwise coprime" << endl;
                return 0;
            }
            prime_set.insert(p.first);
        }
    }

    cout << "pairwise coprime" << endl;
}

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

#include <random>
signed main() {

	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];

	set<int> s;
	rep(i, N) s.insert(a[i]);

	// 全部同じかチェック
	bool ans = true;

	if(s.size()==1 && a[0]==0) {
		Yes;
		return 0;
	}

	if (N %3 == 0) {
		sort(a.begin(), a.end());
		if (s.size() > 3) { ans = false; No; return 0; }

		// 種類数が2 or 3
		if(s.size()==3){
			vector<int> v(s.begin(), s.end());

			// 数える
			int c[3] = { 0,0,0 };
			rep(i, N) {
				if (a[i] == v[0]) c[0]++;
				if (a[i] == v[1]) c[1]++;
				if (a[i] == v[2]) c[2]++;
			}
			if (c[0] != c[1] || c[1] != c[2]) {
				ans = false; No;  return 0;
			}

			if ((v[0] == (v[1] ^ v[2])) && (v[1] == (v[2] ^ v[0])) && (v[2] == (v[0] ^ v[1])))
				ans = true;
			else
				ans = false;
		}
		else {
			vector<int> v(s.begin(), s.end());

			// 数える
			int c[2] = { 0,0 };
			rep(i, N) {
				if (a[i] == v[0]) c[0]++;
				if (a[i] == v[1]) c[1]++;
			}
			if (c[0] != c[1] * 2 && c[1] != c[0] * 2) { ans = false; No; return 0; }

			if (v[0] == 0 || v[N - 1] == 0) {
				ans = true;
				Yes;
				return 0;
			}
			else {
				ans = false;
				No;
				return 0;
			}

			random_device seed_gen;
			mt19937 engine(seed_gen());
			uniform_int_distribution<> dist(0, 1);
			int result = dist(engine);
			if (result == 0) Yes;
			else No;
		}
	}
	else {
		ans = false;
	}

	if (ans) Yes;
	else No;

	
	return 0;
}

Measured memory_bytes: 4480
N,M = map(int, input().split())
H = list(map(int, input().split()))
ans = [1]*N

for i in range(M):
    A,B = map(int, input().split())
    if H[A-1] >= H[B-1]:
        ans[B-1] = 0
    if H[A-1] <= H[B-1]:
        ans[A-1] = 0

print(sum(ans))

Measured memory_bytes: 20144
#include<stdio.h>
int main(void)
{
    int a,b,c=1,d=0;
    while(scanf("%d %d",&a,&b)!=EOF){
        c=1,d=0;
        while(1){
            c=10*c;
            d++;
            if((a+b)/c==0){
                printf("%d\n",d);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string n;
	cin >> n;
	if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3628
rooms = []
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])

num = int(raw_input())
for i in range(num):
    b,f,r,v = map(int, raw_input().split())
    rooms[b-1][f-1][r-1] += v

for number, room in enumerate(rooms):
    for row in room:
        print " %d %d %d %d %d %d %d %d %d %d" % (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9])
    if len(rooms) - 1 > number:
        print('####################')

Measured memory_bytes: 6468
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	string strs[9]={{".,!? "},{"abc"},{"def"},{"ghi"},{"jkl"},{"mno"},{"pqrs"},{"tuv"},{"wxyz"}};
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string ans="",tmp;
		cin>>tmp;
		int a=0,b=0;//aがb回押された
		for(int j=0;j<tmp.size();j++){
			if(tmp[j]=='0'&&b>=1){
			ans+=strs[a-1][(b+strs[a-1].size()-1)%strs[a-1].size()];
			a=0,b=0;
			}
			if(tmp[j]=='0')continue;
			else {
				a=tmp[j]-'0';
				b++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x = read::<i64>();
    let t = read::<i64>();
    println!("{}", std::cmp::max(0, x - t));
}


Measured memory_bytes: 4352