akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (b - a <= 0) {
			System.out.println("delicious");
		} else {
			if (b - a > x) {
				System.out.println("dangerous");
			} else {
				System.out.println("safe");
			}
		}
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int m=n,d=0;
	while (m>0)
	{
		d+=m%10;
		m/=10;
	}
	if (n%d==0)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
int N;
bool fld[100][100];

bool end(int y,int x){
	int cnt = 0;
	for(int i=0;i<4;i++){
		int ny,nx;
		ny = y+dy[i]; nx = x+dx[i];
		if(ny<0 || N<=ny || nx<0 || N<=nx) continue;
		if(fld[ny][nx]) cnt++;
	}
	if(cnt>=2) return true;
	return false;
}

void dfs(int n,int dir,int y,int x){
	if(n<2) return;
	int cnt = 2;
	if(n==N) cnt = 3;
	for(int i=0;i<cnt;i++){
		for(int j=0;j<n-1;j++){
			y += dy[dir]; x += dx[dir];
			if(end(y,x)) return;
			fld[y][x] = true;
		}
		dir = (dir+1)%4;
	}
	dfs(n-2,dir,y,x);
}

int main(){
	int ds;
	cin>>ds;
	for(int k=0;k<ds;k++){
		if(k!=0) puts("");
		cin>>N;
		fill_n((bool*)fld,100*100,false);
		fld[N-1][0] = true; dfs(N,0,N-1,0);
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(fld[i][j]) printf("#");
				else printf(" ");
			}puts("");
		}
	}
	return 0;
}

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

int num_of_div(int n) {
  int res = 0;
  
  for (int i = 1; i * i <= n; i++) {
    if (i * i == n) {
      res++;
      continue;
    }
    
    if (n % i == 0) res += 2;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    if (num_of_div(i) == 8) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,g,b,max,gg,bb;
  string ans="No";
  cin>>r>>g>>b>>max;
  //r<g<b
  gg=g;
  bb=b;
  for(int i=0;i<=max;i++){
    if(i==0){
    	gg=g;
    }else{
    	gg=g*pow(2,i);
    }  
    for(int j=0;j<=max-i;j++){
      if(j==0){
    	bb=b;
      }else{
    	bb=b*pow(2,j);
      }
      if((gg>r)&&(bb>gg)){
    	ans="Yes";
        break;
  	  }
      //cout<<gg<<" "<<bb<<endl;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4100
N,L = map(int,input().split())
Apple = []
compare = []
for i in range(N):
  Apple.append(L + i)
tot = sum(Apple)
for i in range(N):
  a = Apple[i]  
  Apple.remove(a)
  compare.append(abs(tot - sum(Apple)))
  Apple.insert(i,a)
Apple.remove(Apple[compare.index(min(compare))])
print(sum(Apple))

Measured memory_bytes: 3064
S = input()

S = S[:-2]
flg = True
while flg:
    flg = False
    x = 0
    for i in range(len(S)//2):
        if S[x] != S[len(S)//2 + x]:
            flg = True
            S = S[:-2]
            break
        x += 1

print(len(S))


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");

        int h = Integer.valueOf(arr01[0]);
        int n = Integer.valueOf(arr01[1]);

        Stream<String> stream = Arrays.stream(arr02);
        int arr03[] = stream.mapToInt(Integer::parseInt).toArray();

        int mysum = Arrays.stream(arr03).sum();

        System.out.println(h <= mysum ? "Yes" : "No");

    }

}


Measured memory_bytes: 38028
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
int n;
int cost = 3000;
vector<int> l;
vector<int> a;

int rec(vector<int> sums, vector<int> nums, int id)
{
    if (id == n)
    {
        for (int i = 0; i < 3; i++)
        {
            if (nums[i] == 0)
                return INF;
        }
        long long score = 0;
        for (int i = 0; i < 3; i++)
        {
            score += abs(sums[i] - a[i]);
            score += (nums[i] - 1) * 10;
        }
        return score;
    }
    int res = INF;
    res = min(res, rec(sums, nums, id + 1));
    for (int i = 0; i < 3; ++i)
    {
        sums[i] += l[id], nums[i]++;
        res = min(res, rec(sums, nums, id + 1));
        sums[i] -= l[id], nums[i]--;
    }
    return res;
}

int main()
{
    cin >> n;
    a.resize(3);
    for (int i = 0; i < 3; ++i)
    {
        cin >> a[i];
    }
    l.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    vector<int> sums(3, 0), nums(3, 0);
    cout << rec(sums, nums, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mod 1000000007
using namespace std;
//const ll N=100005;
//ll fact[N];
//bool v[N];
ll power(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n%2) res=(x*res)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return res;
}
ll invmod(ll x)
{return power(x,mod-2);}
void solve()
{
    ll n,m,q,a,b,c,d,e,s,x;
    scanf("%lld",&n);
    map<ll,ll> hm;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&x);
        hm[x]++;
    }
    if(n%2 && hm[0]!=1) printf("0");
    else
    {   bool f=0;
        ll cnt=0;
        for(auto y:hm)
        {if(y.first==0) continue;
            if(y.second!=2) f=1;
            else cnt++;}
        if(f) printf("0");
        else printf("%lld",power(2,cnt));
    }
}
int main()
{
 //speed_up;
 ll t=1;
/* fact[0]=1;
 for(ll i=1;i<N;i++) fact[i]=(fact[i-1]*i)%mod;*/
 //cin>>t;
 while(t--)
    solve();


}


Measured memory_bytes: 4224
#include <iostream>
#include <string.h>
using namespace std;
int main(){
	int i , n ;
	string str , st , s ;
	cin >> str ;
	cin >> s ;
	st = str + str + str;
	n = st.find(s);
	if( n != -1 )
		cout <<"Yes" << endl;
	else 
		cout << "No" << endl;
}

Measured memory_bytes: 3224
from heapq import *

class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

n=int(input())
X=[[0,0] for i in range(n)]
Y=[[0,0] for i in range(n)]
edge=[[0,0] for i in range(n)]
for i in range(n):
  x,y=map(int,input().split())
  X[i]=[x,i]
  Y[i]=[y,i]
  edge[i]=[x,y]
X.sort()
Y.sort()
hq=[]
heapify(hq)
for i in range(n-1):
  x1,j1=X[i]
  x2,j2=X[i+1]
  y1,k1=Y[i]
  y2,k2=Y[i+1]
  heappush(hq,(x2-x1,j1,j2))
  heappush(hq,(y2-y1,k1,k2))
ans=0
uf=UnionFind(n)
while hq:
  w,s,t=heappop(hq)
  if uf.find(s)!=uf.find(t):
    uf.unite(s,t)
    ans+=w
print(ans)

Measured memory_bytes: 67240
#include <stdio.h>

int main(void)
{
	float weight;
	
	while (scanf("%f", &weight) != EOF){
		if (weight <= 48.00){
			printf("light fly\n");
		}
		else if (weight <= 51.00){
			printf("fly\n");
		}
		else if (weight <= 54.00){
			printf("bantam\n");
		}
		else if (weight <= 57.00){
			printf("feather\n");
		}
		else if (weight <= 60.00){
			printf("light\n");
		}
		else if (weight <= 64.00){
			printf("light welter\n");
		}
		else if (weight <= 69.00){
			printf("welter\n");
		}
		else if (weight <= 75.00){
			printf("light middle\n");
		}
		else if (weight <= 81.00){
			printf("middle\n");
		}
		else if (weight <= 91.00){
			printf("light heavy\n");
		}
		else {
			printf("heavy\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 604
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    while True:
        w,h = LI()
        if h == 0:
            break
        a = [LI() for _ in range(h)]
        s = t = None
        for i in range(h):
            for j in range(w):
                if a[i][j] == 2:
                    s = (i,j)
                    a[i][j] = 0
                elif a[i][j] == 3:
                    t = (i,j)
        q = set([(s,tuple())])
        tr = -1
        for i in range(1,11):
            nq = set()
            for c,l in q:
                l = list(l)
                for di,dj in dd:
                    ni = c[0]
                    nj = c[1]
                    while 0 <= ni < h and 0 <= nj < w and (a[ni][nj] == 0 or (ni,nj) in l):
                        ni += di
                        nj += dj
                    if (ni,nj) == t:
                        tr = i
                        break
                    if ni < 0 or ni >= h or nj < 0 or nj >= w:
                        continue
                    ni -= di
                    nj -= dj
                    if ni != c[0] or nj != c[1]:
                        nq.add(((ni,nj), tuple(sorted(l + [(ni+di,nj+dj)]))))
                if tr > 0:
                    break
            if tr > 0:
                break
            q = nq
        rr.append(tr)

    return '\n'.join(map(str, rr))



print(main())



Measured memory_bytes: 31164
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.nextLine
    val ans = Array.fill[Char](s.size)('x')
    println(ans.mkString(""))
  }
}


Measured memory_bytes: 27452
N=int(input())
p=list(map(int,input().split()))

i=0
op=0
while i<N:
    if i+1==p[i]:
        cnt=0
        j=i
        while j<N and p[j]==j+1:
            cnt+=1
            j+=1
        
        op+=(cnt+1)//2
        i=j
    else:
        i+=1

print(op)

Measured memory_bytes: 14008
#include <iostream>
#include<map>
using namespace std;
typedef long long ll;
ll n,s[26],d[365][26],t[365],ans,u[26],q,a,b,c,MAX=-10000000,L,A[365];
int main(void){
    cin>>n;
    for(int i=0;i<26;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<26;j++){
            cin>>d[i][j];
        }
    }
    
    
    for(int i=0;i<n;i++){
            t[i]=i%26+1;
        }
        
        
    q=1000;
    while(q--){
        a=rand()%n;
        b=rand()%26;
        ans=0;
        for(int i=0;i<26;i++)u[i]=0;
        
        c=t[a];
        t[a]=b+1;
        
        for(int i=0;i<n;i++){
            ans+=d[i][t[i]-1];
            u[t[i]-1]=i+1;
            for(int j=0;j<26;j++){
                ans-=s[j]*(i+1-u[j]);
            }
        }
        if(MAX<ans){
            MAX=ans;
            for(int i=0;i<n;i++){
                A[i]=t[i];
            }
        }
        else t[a]=c;
    }
    
    for(int i=0;i<n;i++){
        cout<<A[i]<<endl;
    }
    //cout<<MAX<<endl;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h> 
using namespace std;
 
typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()
 
const int oo=1000000000;
 
int n,m;
int f[1<<15][16][16];
int g[16][16];
 
int main()
{
	while (cin>>n>>m)
	{
		memset(g,255,sizeof(g));
		REP(i,m)
		{
			int x,y,z;
			cin>>x>>y>>z;
			--x;
			--y;
			g[x][y]=g[y][x]=z;
		}
		REP(set,two(n))
		{
			REP(x,n) REP(y,n) f[set][x][y]=oo;
			if (!contain(set,0)) continue;
			if (contain(set,n-1) && set!=two(n)-1) continue;
			REP(x,n) f[set][x][x]=0;
			for (int set1=set-1;set1>0;set1=((set1-1)&set))
			{
				if (!contain(set1,0)) continue;
				int set2=(set^set1);
				int base=0;
				REP(x,n) if (contain(set1,x)) REP(y,n) if (contain(set2,y) && g[x][y]>=0) base+=g[x][y];
				REP(x,n) if (contain(set1,x)) REP(y,n) if (contain(set1,y)) 
					REP(z,n) if (contain(set2,z) && g[y][z]>=0)
					{
						ckmin(f[set][x][z],base+f[set1][x][y]-g[y][z]);
					}
			}
		}
		printf("%d\n",f[two(n)-1][0][n-1]);
	return 0;
	}
}


Measured memory_bytes: 33024
import itertools
n = int(input())
arr = [input()[0] for i in range(n)]
word = ['M','A','R','C','H']
ans = 0
con = list(itertools.combinations(word,3))
for i in con:
    ans += arr.count(i[0]) * arr.count(i[1]) * arr.count(i[2])
print(ans)

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

int main(){
    int h,w; cin >> h >> w;
    char s[h][w];
    for (int i = 0; i < h; i++) cin >> s[i];

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int cnt = 0;
            if (s[i][j] == '.') {
                for (int k = -1; k <= 1 ; k++) {
                    for (int l = -1; l <= 1; l++) {
                        if (0 <= i + k && i + k < h && 0 <= j + l && j + l < w && s[i + k][j + l] == '#') cnt++;
                    }
                }
                cout << cnt;
            } else {
                cout << '#';
            }
        }
        cout << endl;
    }    
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int N;
int val[MN];
int num[16];
int dp[1 << 15];
int ret;
bool zero[1 << 15];

int main() {
	cin >> N;

	rep(i, N-1) {
		int a, b, e;
		cin >> a >> b >> e;
		val[a] ^= e;
		val[b] ^= e;
	}

	rep(i, N) num[val[i]]++;
	
	int f = 0;

	for (int i = 1; i < 16; ++i) {
		ret += num[i] / 2;
		num[i] %= 2;
		f |= (num[i] << (i-1));
	}

	rep(i, 1 << 15) {
		int xo = 0;
		rep(j, 15) {
			if ((i >> j) & 1) {
				xo ^= (j + 1);
			}
		}
		zero[i] = (xo == 0);
	}

	for (int i = 1; i < (1<<15); ++i) {
		for (int j = i; j >= 0; --j) {
			j &= i;
			if (j == 0) break;
			if (zero[j]) {
				dp[i] = max(dp[i], dp[i^j] + 1);
			}
		}
	}

	cout << ret + __builtin_popcount(f) - dp[f] << endl;

	return 0;

}

Measured memory_bytes: 896
/**
 * Author  : dhakad_123
 * Created : 23.08.2020
 **/

#include<bits/stdc++.h>
using namespace std;


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


	string n;
	cin >> n;

	int ans = 0;
         
	for(int i = 0; i < n.length(); i++){

		ans += n[i] - '0';
	}


	if(ans % 9 == 0){
		cout <<"Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 3756
def stopped_at(position, turn, value, loses, backs, steps, lost_steps, squares)
  if position > squares
    stopped_at(squares * 2 - position, turn, value, loses, backs, steps, lost_steps, squares)
    return
  end
  if loses.include?(position)
    lost_steps[turn][position] += value
    return
  end
  if backs.include?(position)
    steps[turn][0] += value
    return
  end
  steps[turn][position] += value
end
while true
  parameters = gets.split(" ").map(&:to_i)
  break if parameters.all?{|number| number == 0}
  squares, turns, loses, backs = parameters
  lose_squares = []
  loses.times do
    lose_squares.push(gets.to_i)
  end
  back_squares = []
  backs.times do 
    back_squares.push(gets.to_i)
  end

  steps = Array.new(turns + 1) do 
    Array.new(squares + 1){0}
  end
  lost_steps = Array.new(turns + 1) do 
    Array.new(squares + 1){0}
  end

  steps[0][0] = 1

  turns.times do |i|
    steps[i].each.with_index do |value, j|
      steps[i + 1][j] += value * 6 if j == squares
      6.times do |k|
        stopped_at(j + k  + 1, i + 1, value, lose_squares, back_squares, steps, lost_steps, squares) if  value != 0 && j != squares
      end
    end
    lost_steps[i].each.with_index do |value, j|
      steps[i + 1][j] += value * 6 unless value == 0
    end
  end

  result =  (steps[turns][squares] / (6 ** turns).to_f).round(6)
  puts sprintf("%.6f", result)
end

Measured memory_bytes: 10800
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    li=[int(readline()) for _ in range(5)]

    res=10
    res_i=0
    for i in range(5):
        if li[i]%10==0:
            pass
        else:
            if li[i]%10<res:
                res=li[i]%10
                res_i=i

    ans=0
    for i in range(5):
        if i!=res_i:
            if li[i]%10==0:
                ans+=li[i]
            else:
                ans+=li[i]+10-li[i]%10

        else:
            ans+=li[i]

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 9160
import java.math.BigInteger
import kotlin.math.pow

fun main() {
    val n = readInt()
    val aList = readListLong()
    var result = BigInteger.ONE
    if (0 in aList) {
        println(0)
        return
    }
    aList.forEach {
        result = result.multiply(BigInteger.valueOf(it))
        if (result > BigInteger.valueOf((10.0.pow(18)).toLong())) {
            println("-1")
            return
        }
    }
    println(result)
}

private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 63204
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
char field[21][21];
char visit[21][21];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int W,H;
void dfs(int y, int x){
  visit[y][x] = 1;
  rep(i,4){
    int ny = y+dy[i];
    int nx = x+dx[i];
    if(field[ny][nx] == '.'
       && visit[ny][nx] == 0
       && nx >= 0
       && nx < W
       && ny >= 0
       && ny < H){
          dfs(ny,nx);
        }
  }
}
int main(){
  while(cin >> W >> H && W){
    int y,x;
    rep(i,H){
      rep(j,W){
        cin >> field[i][j];
        if(field[i][j] == '@') y=i,x=j;
      }
    }
    memset(visit,0,sizeof(visit));
    dfs(y,x);
    int ans = 0;
    rep(i,H){
      rep(j,W){
        ans += visit[i][j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}




Measured memory_bytes: 3088
import java.util.*;
import java.io.*;
public class Main {
	
	static int cc=0;
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		//入力部
		int n=cin.nextInt();
		List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++) {
			A.add(Integer.parseInt(cin.next()));
		}
		
		/*int m=cin.nextInt();
		List<Integer> B=new ArrayList<>();
		for(int i=0;i<m;i++)B.add(Integer.parseInt(cin.next()));*/
		
		//マージ
		List<Integer> C=mergeSort(A);
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=0;i<C.size()-1;i++) {
			out.print(C.get(i)+" ");
		}
		out.println(C.get(C.size()-1));
		out.println(cc);
		out.flush();
	}
	
	static List<Integer> merge(Queue<Integer> A, Queue<Integer> B) {
		
		List<Integer> C=new ArrayList<>();
		
		while(!A.isEmpty() && !B.isEmpty()) {
			cc++;
			int a=A.element(),b=B.element();
			
			if(a<b) {
				C.add(A.remove());
				//A.remove(0);
			}
			else if(a>b) {
				C.add(B.remove());
				//B.remove(0);
			}
			else {
				C.add(A.remove());C.add(B.remove());
				//A.remove(0);B.remove(0);
				cc++;
			}
		}
		
		if(A.isEmpty()) {
			while(!B.isEmpty()) {
				C.add(B.remove());
				//B.remove(0);
				cc++;
			}
		}
		else {
			while(!A.isEmpty()) {
				C.add(A.remove());
				//A.remove(0);
				cc++;
			}
		}
		
		return C;
	}

	static List<Integer> mergeSort(List<Integer> args) {
		int size=args.size();
		//System.out.println(list.size());
		//exit
		if(size==1)return args;
		
		//divide
		int mid=size/2;
		List<Integer> left=new ArrayList<>(args.subList(0, mid)),right=new ArrayList<>(args.subList(mid, size));
		//System.arraycopy(list, 0, left, 0, mid);
		//System.arraycopy(list, mid, right, 0, list.size()-mid);
		
		Queue<Integer>l=new ArrayDeque<>(mergeSort(left));
		Queue<Integer>r=new ArrayDeque<>(mergeSort(right));
		
		return merge(l,r);
	}

}




Measured memory_bytes: 305512
#include<iostream>
#include<cstdio>
#include<cstring>

namespace Big_Water_Problem
{
	inline bool check_min(int a,int &b){return a<b?b=a,1:0;}
	const int L=810,INF=1000000007;
	const int mv[4][2]={-1,0,1,0,0,-1,0,1};

	inline int got(){for(char c;c=getchar();)if(c=='.')return 1;else if(c=='#')return 0;else if(c=='S')return 2;}
	int G[L][L],f[L][L];
	int n,m,k,ans;
	int sx,sy;

	void initialize()
	{
		scanf("%d%d%d",&n,&m,&k);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if((G[i][j]=got())==2)sx=i,sy=j;
	}
	void play()
	{
		static int Q[L*L][2];
		int u=0,d=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				f[i][j]=INF;
		f[Q[++u][0]=sx][Q[u][1]=sy]=0;
		while(u>d)
		{
			int x=Q[++d][0],y=Q[d][1],tx,ty;
			for(int v=0;v<4;v++)
				if(G[tx=x+mv[v][0]][ty=y+mv[v][1]] && check_min(f[x][y]+1,f[tx][ty]))
					Q[++u][0]=tx,Q[u][1]=ty;
		}
	}
	int calc(int x,int y)
	{
		int ret=std::min(x-1,n-x);
		check_min(std::min(y-1,m-y),ret);
		return ret/k+(ret%k!=0);
	}
	void solve()
	{
		initialize();
		play();
		int ans=INF;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(f[i][j]<=k)
					check_min(1+calc(i,j),ans);
		printf("%d\n",ans);
	}
}

int main()
{
	Big_Water_Problem::solve();
	return 0;
}


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

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

  int r = 0, b = 0;

  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '0') {
      r++;
    } else {
      b++;
    }
  }

  int ans = min(r, b) * 2;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	ll n,W;
	cin>>n>>W;
	ll w[n],v[n];
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	ll dp[W+1]={0};
	
	for(int i=0;i<n;i++){
		for(ll j=W;j>=w[i];j--){
			dp[j]=max(dp[j], dp[j-w[i]]+v[i]);
		}
	}
	cout<<dp[W]<<endl;
	return 0;
	
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, ans;
ll a[100100];
map<ll, int> num;
map<ll, ll> sq;
vector<ll> p;
vector<pair<ll, ll>> cand;
bool d[100100];

int main () {

        fo(i, 2, 100100) if (!d[i]) {
                p.PB(i);
                for (int j = i+i; j < 100100; j += i) d[j] = 1;
                sq[1ll * i * i] = i;
        }

        scanf("%d", &N);

        fo(i, 0, N) {
                scanf("%lld", &a[i]);

                ll m = 1ll, l = a[i];

                for (ll j : p) {
                        if (j > 2200 || j > a[i]) break;
                        int n = 0;
                        while (a[i]%j == 0) a[i] /= j, l /= j, n++;
                        fo(x, 0, n%3) l *= j;
                        if (n%3) fo(x, 0, 3 - (n%3)) m *= j;
                }

                num[l]++;
                if (num[l] >= 2) continue;

                if (sq.count(a[i])) {
                        m *= sq[a[i]];
                } else {
                        if (m <= ((ll) 1e12) / a[i]) m *= a[i];
                        else m = 0;
                        if (m <= ((ll) 1e12) / a[i]) m *= a[i];
                        else m = 0;
                }

                cand.PB(MP(l, m));
        }

        if (num[1ll]) ans++, num[1ll] = 0;
        for (auto i : cand) {
                if (!num[i.first]) continue;
                ans += max(num[i.first], num[i.second]);
                num[i.first] = num[i.second] = 0;
        }

        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 13424
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;


     string str;

   bool flag=true;

   double ds;
      cin>>n>>ds;

        for(i=0; i<n; i++)
        {

            double aa,bb;

            cin>>aa>>bb;

            double cc=(aa*aa)+(bb*bb);

            cc=sqrt(cc);

           // cout<<cc<<endl;
            if(cc<=ds)cnt++;
        }

        cout<<cnt<<endl;



}



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

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define repr(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define repf(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define inf 1e9

template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

using namespace std;
using ll = long long;

int kakuinowa(int num, int a, int n)
{
    string tmp = to_string(num);
    vector<int> keta(10, 0);

    for (int i = 0; i < tmp.size(); i++)
    {
        keta[i] = tmp[i] - '0';
    }

    ll sum = accumulate(all(keta), 0);

    return pow(sum + a, n);
}

int main(int argc, char const *argv[])
{
    int f;
    cin >> f;
    cout << (f - 30) / 2 << endl;

    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;
typedef pair<double, double >pd;

const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second






int main() {
	ll n, a[100010], ans = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		ans += a[i] - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>


using namespace std;

int main(void){
    int inp[3]={0};
    int max,sum=0;
    int i,j,k;
    int rem;
    cin >> inp[0] >> inp[1] >> inp[2];
    cin >> k;

    for(j=0;j<k;j++){
        max = inp[0];
        rem = 0;
        for(i=1;i<=2;i++){
            if(max<inp[i]){
                max = inp[i];
                rem = i;
            }
        }
        inp[rem] = max * 2;
    }

    for(i=0;i<3;i++){
        sum += inp[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3532
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
int main(){
  string s;
  cin >> s;
  ll k;
  cin >> k;

  char c = s[0];
  bool flag = true;
  for(char now:s){
    if(now != c)flag = false;
  }

  if(flag){
    cout << (ll)(s.size() * k)/2 << endl;
    return 0;
  }

  ll cnt_self = 0;
  ll cnt_margin = 0;

  string s1 = s;
  for(int i = 0;i < s1.size()-1;i++){
    if(s1[i] == s1[i+1]){
      s1[i+1] = '*';
      cnt_self++;
    }
  }

  string s2 = s + s;
  for(int i = 0;i < s2.size()-1;i++){
    if(s2[i] == s2[i+1]){
      s2[i+1] = '*';
      cnt_margin++;
    }
  }

  cnt_margin -= cnt_self;

  cout << cnt_self + (k-1) * cnt_margin << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		Set<String> s = new HashSet<>();

		for (int i = 0; i < N; i++) {
			s.add(sc.next());
		}

		sc.close();

		if (s.size() == 3) {
			out.println("Three");
		} else {
			out.println("Four");
		}

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


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

int main() {
    string str;
    cin >> str;
    int n = str.length(), ans;
    for(int i = n - 1; i >= 0; i--) {
        if(str.at(i) == 'Z') {
            ans = i + 1;
            break;
        }
    }
    for(int i = 0; i < n; i++) {
        if(str.at(i) == 'A') {
            ans -= i;
            break;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int main() {

	int a, b;
	cin >> a >> b;
	if (a + b >= 10)cout << "error" << Endl;
	else cout << a + b << Endl;

	return 0;
}

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

#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl "\n"
const int MAX = 3e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

ll n,a,b,x,ans;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>a>>b;
    while(n--){
    	cin>>x;
    	if(x<a||x>=b)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
a=[0]*N
b=[0]*N
c=[0]*N
for i in range(N):
  a[i],b[i]= map(int,input().split())
  c[i]=(a[i],b[i])
  
c.sort(key=lambda x: x[0])
cnt=0

for j in range(N):
  cnt += c[j][1]
  if cnt>=K:
    print(c[j][0])
    break

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

int main() {
  int a,b;
  cin >> a >> b;
  int ans = a+b;
  ans = max(ans,a-b);
  ans = max(ans,a*b);
  cout << ans << endl;
}

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

void solve()
{
    int n,k;
    cin >> n >> k;
    int a[n];
    vector<int>  dp(n,0);
    for(int i=0;i<n;i++)
        cin >> a[i];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        int best = INT_MAX,cnt = 0;;
        for(int j=i-1;j>=0 && cnt<k;j--)
        {
            best = min(best,abs(a[i]-a[j])+dp[j]);
            cnt++;
        }
        dp[i] = best;
    }
    cout << dp[n-1];

    
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3996
s = input()
while 1:
    flag = False
    if s[-5:] in ['dream', 'erase']:
        s = s[:-5]
        flag = True
    elif s[-6:] == 'eraser':
        s = s[:-6]
        flag = True
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        flag = True
    if not flag:
        break
if not s:
    print('YES')
else:
    print('NO')
    


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

signed main(){
    int N, M; cin >> N >> M;
    priority_queue<int> que;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        que.push(a);
    }
    for(int i = 0; i < M; i++){
        int x = que.top(); que.pop();
        x /= 2; que.push(x);
    }
    int ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

void mkPrime(int n,bool p[]){
	int i,j;
	p[0]=p[1]=0;
	for(i=2;i<=n;i++) p[i]=1;
	for(i=2;i<=sqrt(n);i++) if(p[i]) for(j=i*2;j<=n;j+=i) p[j]=0;
}

int main(void){
	int a,d,n;
	bool p[1000050];

	mkPrime(1000040,p);
	while(cin>>a>>d>>n && (a||d||n)){
		for(;n!=0;a+=d) if(p[a]) n--;
		cout<<a-d<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (20)

int main(int argc, char *argv[]) {
  // read inputs
  int N, ps[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &ps[i]);
  }

  // solve
  int ans = 0;
  for (int i = 1; i < N - 1; i++) {
    if ((ps[i - 1] < ps[i] && ps[i] < ps[i + 1]) ||
        (ps[i - 1] > ps[i] && ps[i] > ps[i + 1])) {
      ans++;
    }
  }
  printf("%d\n", ans);

  return 0;
}


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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


ans = B - A + 1
ans -= (B // C + B // D) - ((A - 1) // C + (A - 1) // D)
E = lcm(C, D)
ans += B // E - (A - 1) // E

print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
class itp1_11_a{
  public static void Main(){
    String[] str = Console.ReadLine().Split(' ');
    Dice d = new Dice(str[0], str[1], str[2], str[3], str[4], str[5]);
    Rotate rtt = new Rotate();
    String order = Console.ReadLine();
    foreach(char c in order){
      switch(c){
        case 'N':
          rtt.north(d);
          break;
        case 'S':
          rtt.south(d);
          break;
        case 'E':
          rtt.east(d);
          break;
        case 'W':
          rtt.west(d);
          break;
        default:
          break;
      }
    }
    Console.WriteLine(d.top);
  }
}


class Rotate{
  public void north(Dice d){
    int temp = d.top;
    d.top = d.front;
    d.front = d.bottom;
    d.bottom = d.behind;
    d.behind = temp;
  }
  public void south(Dice d){
    int temp = d.top;
    d.top = d.behind;
    d.behind = d.bottom;
    d.bottom = d.front;
    d.front = temp;
  }
  public void east(Dice d){
    int temp = d.top;
    d.top = d.left;
    d.left = d.bottom;
    d.bottom = d.right;
    d.right = temp;
  }
  public void west(Dice d){
    int temp = d.top;
    d.top = d.right;
    d.right = d.bottom;
    d.bottom = d.left;
    d.left = temp;
  }
}

class Dice{
  public int top { get; set; }
  public int front { get; set; }
  public int right { get; set; }
  public int left { get; set; }
  public int behind { get; set; }
  public int bottom { get; set; }
  public Dice(){
    top = 1;
    front = 2;
    right = 3;
    left = 4;
    behind = 5;
    bottom = 6;
  }
  public Dice(int t, int f, int r, int l, int be, int bo){
    top = t;
    front = f;
    bottom = bo;
    behind = be;
    right = r;
    left = l;
  }
  public Dice(String t, String f, String r, String l, String be, String bo){
    top = int.Parse(t);
    front = int.Parse(f);
    right = int.Parse(r);
    left = int.Parse(l);
    behind = int.Parse(be);
    bottom = int.Parse(bo);
  }
}



Measured memory_bytes: 15944
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<algorithm>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;
using P = pair<int, int>;
int n, m;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    
    vector<P> revs(0);
    REP(i, m) {
        int aft, pre;
        cin >> aft >> pre;
        revs.emplace_back(aft, pre);
    }
    sort(ALL(revs));

    int pos = 0;
    int ans = 0;
    int k = 0;
    while(k < revs.size()) {
        // DD(k, pos);
        int pre = revs[k].second;
        int aft = revs[k].first;
        // DD(pre, aft);
        while(k+1 < revs.size() && revs[k+1].first < pre) {
            k++;
            pre = max(pre, revs[k].second);
            // DD("contains", k);
        }
        ans += pre - pos + (pre - aft) * 2;
        // D(pre - pos + (pre - aft) * 2);
        pos = pre;
        k++;
    }
    ans += n + 1 - pos;
    cout << ans << endl;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  long long  A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;

  long long kyori=0;
  long long hayasa=0;
  kyori=abs(A-B);
  hayasa=V-W;

  if(kyori<=hayasa*T){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll a, b, c;
	cin >> a >> b >> c;
	ll x = abs(a - b), y = abs(a - c), z = abs(b - c);
	cout << min(x + y, min(y+z, x + z));
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> A, std::vector<long long> B)
{
    ll cnt = 0;
    REP(i, N)
    {
        if (A[i] < B[i])
        {
            cnt += (B[i] - A[i]) / 2;
        }
        else
        {
            cnt -= A[i] - B[i];
        }
    }

    if (cnt < 0)
    {
        cout << NO << endl;
    }
    else
    {
        cout << YES << endl;
    }
    return;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &a[i]);
    }
    std::vector<long long> b(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &b[i]);
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 384
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N, M, K = map(int, readline().split())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

ac = [0]
bc = [0]

for i in range(N):
    ac.append(ac[i] + A[i])
for i in range(M):
    bc.append(bc[i] + B[i])

ans = 0
j = M

for i in range(N+1):
    if ac[i] > K:
        break
    while bc[j] > K - ac[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)


Measured memory_bytes: 48168