akhauriyash/Code-Regression huggingface dataset:
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    use std::collections::{BinaryHeap, VecDeque};
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let mut ab: Vec<(usize, usize)> = vec(n, |_| {
        let a: usize = scan(tokens);
        let b: usize = scan(tokens);
        (a, b)
    });
    ab.sort();
    let mut ab = VecDeque::from(ab);
    let mut heap = BinaryHeap::new();
    let mut ans = 0;
    for i in 0..m + 1 {
        while ab.front().map_or(false, |&(a, _)| a <= i) {
            let (_, b) = ab.pop_front().unwrap();
            heap.push(b);
        }
        if let Some(b) = heap.pop() {
            ans += b;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
template <class T> ostream& operator<<(ostream& s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }

int eval(char c, int a, int b) {
    if (c == '&') return a & b;
    if (c == '|') return a | b;
    if (c == '^') return a ^ b;
    assert(0);
}
signed main() {
    int n, m; cin >> n >> m;
    vector<char> op(n);
    vector<int> var(n);
    REP (i, n - 1) {
        string s; cin >> s;
        op[i + 1] = s[3];
        var[i + 1] = s[4] - 'X';
    }
    vector<vector<int>> g(n);
    REP (i, n - 1) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> weighted_acc(n);
    function<int(int, int, int, const vector<int>&)> dfs = [&](int v, int prev, int sign, const vector<int>& perm) -> int {
        if (prev != -1 && g[v].size() == 1) return sign * weighted_acc[v];
        int ma = -1e9;
        for (int s : g[v]) if (s != prev) {
            assert(weighted_acc[s] == 0);
            REP (i, 4) {
                int tmp = weighted_acc[v] >> i & 1;
                int x = perm[i] >> 1 & 1;
                int y = perm[i] & 1;
                if (var[s] == 0) tmp = eval(op[s], tmp, x);
                else if (var[s] == 1) tmp = eval(op[s], tmp, y);
                else assert(0);
                weighted_acc[s] |= tmp << i;
            }
            ma = max(ma, - dfs(s, v, -sign, perm));
            assert(abs(ma) < 16);
        }
        return ma;
    };
    map<vector<int>, int> tbl;
    {
        vector<int> perm = {0, 1, 2, 3};
        do {
            tbl[perm] = dfs(0, -1, 1, perm);
            fill(weighted_acc.begin(), weighted_acc.end(), 0);
        } while (next_permutation(perm.begin(), perm.end()));
    }
    REP (_, m) {
        int x, y; cin >> x >> y;
        vector<int> perm, idxs(16);
        for (int k = 15; k >= 0; k--) {
            int idx = (x >> k & 1) << 1 | (y >> k & 1) << 0;
            if (find(perm.begin(), perm.end(), idx) == perm.end()) perm.push_back(idx);
            idxs[k] = idx;
        }
        REP (idx, 4) {
            if (find(perm.begin(), perm.end(), idx) == perm.end()) perm.push_back(idx);
        }
        reverse(perm.begin(), perm.end());
        int tmp = tbl.at(perm);
        int ans = 0;
        REP (k, 16) {
            int shift = find(perm.begin(), perm.end(), idxs[k]) - perm.begin();
            assert(shift < 4);
            ans |= (tmp >> shift & 1) << k;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 22472
#include <cstdio>

using namespace std;

int main()
{
    int h,r;
    scanf( "%d %d\n", &h, &r );
    if( -r < h )
    {
        printf( "%d\n", 1 );
    }
    else if( h == -r )
    {
        printf( "%d\n", 0 );
    }
    else
    {
        printf( "%d\n", -1 );
    }
    return 0;
}


Measured memory_bytes: 2724
from collections import defaultdict
from heapq import heappush, heappop, heapify
from sys import stdin
#import time

def sp(G,R,V):
    d = {}
    INF = float('inf')
    for i in range(V):
        d[i] = INF
    q = [(0, R)]
    d[R] = 0
    heapify(q)
    while q:
        (cost, v) = heappop(q)
        for (next, c) in G[v].items():
            if d[next] > d[v] + c:
                d[next] = d[v] + c
                heappush(q, (d[next], next))
    return d

#start = time.clock()

V, E, R = [int(x) for x in stdin.readline().split()]
G = defaultdict(dict)
for case in range(E):
    s, t, w = [int(x) for x in stdin
    .readline().split()]
    G[s][t] = w
d = sp(G, R, V)
for k in range(V):
    if d[k] == float('inf'):
            print("INF")
    else:
        print(d[k])
#print('Computation time : {}'.format(time.clock()-start))

Measured memory_bytes: 102404
#include <iostream>
#include <string>
#include <locale>
using namespace std;

int main() {
  int s; cin >> s;
  int l = s / 100;
  int r = s % 100;
  int pattern = 0;
  
  if (1 <= l && l <= 12) {
    if (1 <= r && r <= 12) pattern = 3;
    else pattern = 2;
  } else if (1 <= r && r <= 12) {
    if (1 <= l && l <= 12) pattern = 3;
    else pattern = 1;
  }
  
  switch (pattern) {
    case 1: cout << "YYMM" << endl; break;
    case 2: cout << "MMYY" << endl; break;
    case 3: cout << "AMBIGUOUS" << endl; break;
    default: cout << "NA" << endl;
  }
  
  return 0;
}

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

long long dp[3100][3100];

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;++i) cin >> a[i];

  for(int i=0;i<n;++i) dp[i][i]=0;

  for(int len=1;len<=n;++len){
    for(int i=0;i+len<=n;++i){
      int j=i+len;

      if((n-len)%2==0){
        dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1]);
      }else{
        dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1]);
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}


Measured memory_bytes: 73984
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;//for StringBuilder
class c
{
    static void Main()
    {
        var l = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = l[0], b = l[1], c = l[2];
        int k = int.Parse(Console.ReadLine());
        var ans = 0;
        while (a >= b)
        {
            ans++;
            b *= 2;
        }
        while (b >= c)
        {
            ans++;
            c *= 2;
        }
        if (ans <= k) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 27524
import java.util.*;
import java.io.*;

public class Main {
 
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
	    char s[] = in.readString().toCharArray(); 
	    boolean isgood = true; 
	    if(s[0] == s[1])isgood = false; 
	    if(s[1] == s[2])isgood = false; 
	    if(s[2] == s[3])isgood = false; 
	    System.out.println(isgood ? "Good":"Bad") ;
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int m,n;
	cin>>m>>n;
	int ans=0;
	int count=1;
	while(count<n){
		count--;
		count+=m;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int d1,d2,n,f[2001][2001],a=0,now=0;
void color(int x){
	if (x % 2==1){
		for (int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if (((i>>now)+(j>>now)) %2) f[i][j]=1;
	}
	else if (x % 4==2){
		for (int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if ((i>>now) % 2) f[i][j]=1;
	}
	else{ 
		now++;
		color(x/4);
	} 
}


int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	color(d1);
	now=0;
	color(d2);
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
			if (f[i][j]==0){
				a++;
				printf("%d %d\n",i,j);
				if (a==n*n) return 0;
			} 
} 

Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    cout<<"A"<<b[0]<<"C"<<endl;
}


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

using namespace std;

using ll = unsigned long long;

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

ll count(ll X, ll C, ll D) {
    ll LCM = C * D / gcd(C,D);
    ll N_C = X/C;
    ll N_D = X/D;
    ll N_LCM = X/LCM;

    return X - (N_C + N_D - N_LCM);
}

int main() {
    ll A,B,C,D;
    cin >> A >> B >> C >> D;

    cout << count(B, C, D) - count(A-1, C, D) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void bubbleSort(int[],int);

int main()
{
  int i,N,A[100];

  scanf("%d",&N);
  for(i = 0;i < N;i++)
    {
      scanf("%d",&A[i]);
    }
  bubbleSort(A,N);
  return 0;
}
void bubbleSort(int A[],int N)
{
  int a,i = 0,j,flag = 1,count = 0;
  while(flag == 1)
    {
      flag = 0;
      for(j = N-1;j >= 1;j--)
	{
	  if(A[j] < A[j-1])
	    {
	      a = A[j];
	      A[j] = A[j-1];
	      A[j-1] = a;
	      flag = 1;
	      count++;
	    }
	 
	}
    }
  for(i = 0;i < N;i++)
    {
      if(i > 0) printf(" ");
      printf("%d",A[i]);
    }
  printf("\n%d\n",count);
  
}
  



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

int a[4];

long long read(){
	long long x, f = 1;
	char c = getchar();
	while (c < '0' || c > '9'){
		if (c == '-') f = -1;
		c = getchar();
	}
	x = c ^ '0';
	c = getchar();
	while (c >= '0' && c <= '9'){
		x = (x << 1) + (x << 3) + (c ^ '0');
		c = getchar();
	}
	return f == 1 ? x : -x;
}

void print(long long x){
	if (x < 0){
		putchar('-');
		print(-x);
		return ;
	}
	if (x >= 10) print(x / 10);
	putchar(char(x % 10 + '0'));
}

int main(){
	a[1] = read(), a[2] = read(), a[3] = read();
	sort(a + 1, a + 4);
	print(a[1] + a[3] * 10 + a[2]);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

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

    vector<long long> B(N+1, 0);
    for(int i=0; i<N; i++)
        B[i+1] = B[i] + A[i];

    long long ans = 1LL<<60;
    for(int i=2; i<=N-2; i++){
        long long x = (B[i]+1)/2;
        long long y = B[i]+(B[N]-B[i]+1)/2;
        int id0 = lower_bound(B.begin(), B.end(), x) - B.begin();
        int id1 = lower_bound(B.begin(), B.end(), y) - B.begin();
        long long mx0 = 1LL<<60, mx1 = 1LL<<60;
        long long mn0 = 0, mn1 = 0;
        for(int j=0; j<4; j++){
            int xx = id0 - j;
            if(0 < xx && xx < i){
                long long a = B[xx] - B[0];
                long long b = B[i] - B[xx];
                mx0 = min(mx0, max(a, b));
                mn0 = max(mn0, min(a, b));
            }
        }
        for(int j=0; j<4; j++){
            int yy = id1 - j;
            if(i < yy && yy < N){
                long long a = B[yy] - B[i];
                long long b = B[N] - B[yy];
                mx1 = min(mx1, max(a, b));
                mn1 = max(mn1, min(a, b));
            }
        }
        ans = min(ans, max(mx0, mx1) - min(mn0, mn1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
N,M=map(int,input().split())
MAX=0
MIN=N
for i in range(M):
  L,R=map(int,input().split())
  MAX=max(MAX,L)
  MIN=min(MIN,R)
A=MIN-MAX+1
if A<=0:
  print(0)
else:
  print(A)

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

  int N, i;
  cin >> N;
  
  int sum=0;
    
  for(i=0;i<N;i++){
    int l, r;
    cin >> l >> r;
    sum += r-l+1;
  }
  
  cout << sum << endl;
}  

Measured memory_bytes: 256
N = int(input())
X = []
Y = []
D = 0
F = [1]
for i in range(N):
    F.append(F[i]*(i+1))
E = F[N-2]*(N-1)
E = E/F[N]
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
for i in range(N):
    xi,yi = X[i],Y[i]
    for j in range(i,N):
        xj,yj = X[j],Y[j]
        d=((xj-xi)**2+(yj-yi)**2)**0.5
        D+= d
print(D*E*2)

Measured memory_bytes: 3188
import bisect

N = int(input())

A = []

for i in range(N):

    a = int(input())
    A.append(a)

A.reverse()

seq = [float("-inf")]

for i in A:

    ind = bisect.bisect_right(seq,i)

    if ind == len(seq):
        seq.append(i)
    else:
        seq[ind] = i

print (len(seq)-1)



Measured memory_bytes: 57048
main = do
    [n, m] <- map read . words <$> getLine
    xs <- solve m n
    print . length . filter (==n) $ xs

solve :: Int -> Int -> IO [Int]
solve m 0 = return $ replicate m 0
solve m n = do
    k:as <- map read . words <$> getLine
    let xs = map (\i -> if i `elem` as then 1 else 0) [1..m]
    ys <- solve m (n - 1)
    let zs = zipWith (+) xs ys
    return zs


Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

// 
// Union Find Data Structure
// 
// Description:
//   An union-find data structure (aka. disjoint set data structure) 
//   maintains a disjoint sets and supports the following operations.
//   - unite(u, v): merge sets containing u and v.
//   - find(u, v) : return true if u and v are in the same set
//   - size(u)    : size of the set containing u.
//
//   The weighted version additionally maintains the values for the
//   elements and supports the following operations:
//   - add(u, a)   : value[u] += a
//   - addSet(u, a): value[v] += a for v in set(u)
//   - get(u)      : return value[u]
//   - getSet(u)   : return sum(value[v] for v in set(u))
//
// Complexity:
//   Amortized O(a(n)) for all operations.
//   Here, a(n) is the inverse Ackermann function, which is
//   less than five for a realistic size input.
//
// Verified:
//   AOJ1330 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1330
//   and other many problems.
//


#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())

struct UnionFind {
  vector<int> parent; // parent[root] is the negative of the size.
  UnionFind(int n) : parent(n, -1) { };
  bool unite(int u, int v) { 
    u = root(u); v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v]; parent[v] = u;
    return true;
  }
  bool find(int u, int v) { return root(u) == root(v); }
  int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
  int size(int u) { return -parent[root(u)]; }
};

int main() {
    ll n, m;
    cin >> n >> m;
    
    vector<int> a(m), b(m);
    
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    
    vector<ll> ans(m);
    
    UnionFind uf(n);
    
    ll x = n * (n - 1) / 2;
    
    for (int i = m - 1; i >= 0; i--) {
        ans[i] = x;
        
        ll sa = uf.size(a[i]);
        ll sb = uf.size(b[i]);
        
        if (uf.unite(a[i], b[i])) {
            x -= sa * sb;
        }
    }
    
    for (int i = 0; i < m; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3328
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let a_line = lines.next().unwrap().unwrap();
    let mut splited = a_line.trim().split_whitespace();
    let a: i32 = splited.next().unwrap().parse().unwrap();
    let b: i32 = splited.next().unwrap().parse().unwrap();
    let ans = if a < 10 && b < 10 { a * b } else { -1 };

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2 5", br"10
",
        ),
        (
            br"5 10", br"-1
",
        ),
        (
            br"9 9", br"81
",
        ),
    ];

    #[test]
    fn test_a() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define fastt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define enl "\n"
#define ll long long
#define pb push_back
#define fi first
#define se second
#define vvl vector<vector<ll>> 
#define vl vector<ll> 
#define vpll vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(ll i = 0; i < n; ++i)
#define PI 3.14159265 
ll mod=1e9+7;

 int main(){
     fastt;
     ll i,j,k;
   cin>>j;
   cout<<2*PI*j<<enl;
 }


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,l,best=INT_MAX,sum=0,minus;
    scanf ("%d %d",&n,&l);
    for (int x = 1; x <= n; x++) {
      if (abs(l+x-1) < best) {
        best = abs(l+x-1);
        minus = l+x-1;
      }
      sum += (l+x-1);
    }
    printf ("%d\n",sum-minus);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

ull gcd(ull a, ull b) {
  if(a<b) swap(a,b);
  ull c = -1;
  while(c != 0){
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}

ull lcm(ull a,ull b) {
    return a / gcd(a,b) * b;
}
  
int main() {
  int N;
  cin >> N;
  v(ull) t(N);
  rep(i,N) {
    cin >> t[i];
  }
  ull ans = 1;
  rep(i,N) {
    ans = lcm(ans,t[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int A[N],B[N];
  int a;
  for(int i=0;i<N;i++){
    cin >> A[i];
    a = A[i];
    B[i] = a;
  }
  sort(A,A+N);
  int cnt = 0;
  for(int i=0;i<N;i++){
    if(A[i] != B[i]){
      cnt++;
    }
  }
  if(cnt < 3){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int[] a=new int[n];
		for (int i=0;i<n;++i) a[i]=in.nextInt();
		int fromPrevious = Math.abs(a[1] - a[0]);
        int fromBeforePrevious = 0;
		for (int i=2;i<n;++i) {
          int temp = fromPrevious;
          fromPrevious = Math.min(fromPrevious + Math.abs(a[i] - a[i-1]), 
                                  fromBeforePrevious + Math.abs(a[i]-a[i-2]));
          fromBeforePrevious = temp;
		}
		System.out.println(fromPrevious);
	}
}

Measured memory_bytes: 50956
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
        
int main(){
	int n,q; cin >> n >> q;
	string s; cin >>s;
	vector<int> ans(n+1,0);

	for(int i=0;i<n;i++){
		if(i+1 < n && s[i]=='A' && s[i+1]=='C') ans[i+1]=ans[i]+1;
		else ans[i+1]=ans[i];
	}


	for(int p=0;p<q;p++){
		int l,r;cin >> l >> r;
		--r;
		--l;
		cout << ans[r] - ans[l] << endl;
	}
}


Measured memory_bytes: 3800
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

int r[20010];

int f(int s,int a,int b){
	if(a>=b-1)return a;
	int m=(a+b)/2;
	if(r[m]<=s)return f(s,a,m);
	return f(s,m,b);
}

int main() {
	int n,s,res;
	IL{
		res=0;
		cin>>n>>s;
		if(n==0&&s==0)break;
		rep(i,n)r[i]=-in();
		sort(r,r+n);
		rep(i,n)r[i]=-r[i];
//rep(i,n)debug<<r[i]<<" ";
//debug<<endl;
		rep(i,n){
			if(r[0]+r[i]<=s)continue;
			res+=f(s-r[i],0,n)+1;
			if(r[i]+r[i]>s)--res;
//debug<<i<<" "<<res<<endl;
		}
		cout<<res/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	string a;
	cin>>a;
	for(int j=0;j<26;j++){
			int y=1;
 
	for(int i=0;i<a.size();i++){
		if(a[i]=='a'+j)y=0;
	}
	if(y==1){
	cout<<char('a'+j)<<endl;
	return 0;
	}if(j==26-1)cout<<"None"<<endl;
		
	}
return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int i,j,k,n,v;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  
  for(k=0;k<n;k++){
    printf("%d",A[k]);
    if(k<n-1){
      printf(" ");
    }else{
      printf("\n");
    }
  }
  
  for(i=1;i<=n-1;i++){
    v=A[i];
    
    for(j=i-1;j>=0&&A[j]>v;j--){
      A[j+1]=A[j];
    }
    A[j+1]=v;
    for(k=0;k<n;k++){
      printf("%d",A[k]);
      if(k<n-1){
	printf(" ");
      }else{
	printf("\n");
      }
    }
  }
  return 0;
}




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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

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

    char a, b;
    cin >> a >> b;

    if (a == 'H')
        cout << b << '\n';
    else
        cout << ((b == 'H') ? 'D' : 'H') << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    int in[n];
    for(int i = 0; i < n; i++){
        cin >> in[i];
    }
    int maxv = -2000000000;
    int minv = in[0];
    for(int i = 1; i < n; i++){
        maxv = max(maxv, in[i] - minv);
        minv = min(minv, in[i]);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3872
/*input
1 3
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int a,b;
  cin >> a >> b;
  if(a <= 0 && b >= 0)cout << "Zero";
  else if(a > 0 || (! ((b-a+1)%2) ) )cout << "Positive";
  else cout << "Negative";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MN = 2e5+5;
ll A[MN],X[MN],ans;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    int N;
    cin >> N;
    for(int i=1; i<=N; i++){
        cin >> A[i];
        X[A[i]]++;
    }
    for(int i=1; i<=N; i++) ans += X[i]*(X[i]-1)/2;
    for(int i=1; i<=N; i++){
        int t = A[i];
        cout << ans-(X[t]-1) << '\n';
    }
}


Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int MM = 2e5 + 4;
ll mod;
ll dp[MM], ans[MM];
vector <ll> T[MM], suf[MM], pref[MM];
ll dfs(int u, int p) {
	ll ans = 1;
	for(int i = 0; i < T[u].size(); i++) {
		int v = T[u][i];
		if(v != p) {
			ans = (ans * (1 + dfs(v, u))) % mod;
		}
	}
	ll k = 1;
	pref[u].push_back(1);
	for(int i = 0; i < T[u].size(); i++) {
		int v = T[u][i];
		if(v != p) {
			k = (k * (1 + dp[v])) % mod;
		}
		pref[u].push_back(k);
	}
	k = 1;
	for(int i = (int)T[u].size() - 1; i >= 0; i--) {
		int v = T[u][i];
		if(v != p) {
			k = (k * (1 + dp[v])) % mod;
		}
		suf[u].push_back(k);
	}
	reverse(suf[u].begin(), suf[u].end());
	suf[u].push_back(1);
	return dp[u] = ans;
}
void dfs2(int u, int p, int ind, ll tp) {
	ans[u] = 1;
	if(p != -1) {
		ans[u] = (pref[p][ind] * suf[p][ind + 1]) % mod;
		ans[u] = (ans[u] * tp) % mod;
		ans[u]++;
	}
	for(int i = 0; i < T[u].size(); i++) {
		int v = T[u][i];
		if(v != p) {
			dfs2(v, u, i, ans[u]);
		}
	}
	for(int v : T[u]) {
		if(v != p) {
			ans[u] = (ans[u] * (1 + dp[v])) % mod;
		}
	}
}
int main() {
	int n;
	cin >> n >> mod;
	for(int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		T[x].push_back(y);
		T[y].push_back(x);
	}
	dfs(0, -1);
	dfs2(0, -1, 0, 1);
	for(int i = 0; i < n; i++) {
		cout << ans[i] % mod << endl;
	}
	return 0;
}

Measured memory_bytes: 37632
#include<iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX

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

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

int main() {
	ll n;
	cin >> n;
	if (n % 2 != 0) {
		cout << 0 << endl;
		return 0;
	}
	n /= 2;
	ll five = 5;
	ll num = 5;
	ll ans = 0;

	while (n / five >= 1) {
		ll tmp = n / five;
		ans += tmp;
		five *= 5;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
(n,m,),*b=[[*map(int,i.split())]for i in open(0)]
b=sorted(b,key=lambda x:x[1])
p=0
c=0
for i in b:
    if i[0]>=p:
        c+=1
        p=i[1]
    if p == n:
        break
print(c)


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

int main() {
int n;
cin >> n;
int mxn = -1, mx = -1;
for (int i = 1; i <= n; i++) {
int tmp = 0;
int aa = i;
   while (aa % 2 == 0) {
   tmp++;
   aa/=2;
}
if (tmp > mx) {
 mx = tmp;
 mxn = i; 
}
}
cout << mxn << endl;
return 0;
}

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

using namespace std;

typedef long long LL;
typedef long double LD;



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

  LL cnt0 = 0;
  LL cnt1 = 0;
  for (int i = 0; i < S.length(); ++i) {
    if (i % 2 == 0) {
      if (S[i] != '0') {
        cnt0++;
      }
      else {
        cnt1++;
      }
    }
    else {
      if (S[i] != '1') {
        cnt0++;
      }
      else {
        cnt1++;
      }

    }
  }
  cout << min(cnt0, cnt1);
   

  return 0;
}






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

#define EPS 1e-5

int main() {
  
  double q;
  while( cin >> q, q >= 0 ) {
    double x = q/2;
    while( fabs( x*x*x - q ) >= EPS * q ) {
      x = x - ( x*x*x - q ) / ( 3*x*x );
    }
    printf("%f\n", x);
  }
  
  return 0;
}

Measured memory_bytes: 1228
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by hikigineer on 2017/03/04.
 */
public class Main {
    static Scanner in;
    static PrintWriter out;
    static String INPUT = "";

    public static void main(String[] args) throws Exception
    {
        in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
        out = new PrintWriter(System.out);
        int N = ni();
        int[] a = new int[3 * N];
        int i;
        long result = 0L;
        for(i = 0; i < 3 * N; i++) a[i] = ni();
        Arrays.sort(a);
        for(i = 3 * N - 2; i >= N; i -= 2) result += a[i];

        out.println(result);
        out.flush();
    }

    static int ni() {
        return Integer.parseInt(in.next());
    }
}

Measured memory_bytes: 62612
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a*n,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int n, k; cin>>n>>k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<vector<ll>> dp(n+1, vector<ll>(k+1, 0));
    dp[0][0] = 1;

    for(int i=0; i<n; i++){
        vector<ll> dpsum(k+2, 0);
        for(int j=0; j<=k; j++){
            dpsum[j+1] = dpsum[j] + dp[i][j];
            dpsum[j+1] %= MOD;
        }

        for(int cur=0; cur<=k; cur++){
            dp[i+1][cur] += dpsum[cur+1] - dpsum[max(0, cur - a[i])] + MOD;
            dp[i+1][cur] %= MOD;
        }
    }

    cout << dp[n][k] << endl;

    return 0;
}

Measured memory_bytes: 80256
from collections import deque

mae = deque()
usiro=deque()

s=input()
kai=int(input())

siji=[]*kai

for i in range(kai):
    siji.append(input())


state=1
for i in range(kai):
    si=siji[i]
    if(si[0]=='1'):
        state*=-1
    else:
        _,f,c=si.split()
        f=int(f)
        if(state==-1):
            f=3-f
        if(f==1):
            mae. appendleft(c)
        else:
            usiro.append(c)

ans=deque()
for m in mae:
    if(state==1):
        ans.append(m)
    else:
        ans.appendleft(m)
for smoji in s:
    if(state==1):
        ans.append(smoji)
    else:
        ans.appendleft(smoji)
for u in usiro:
    if(state==1):
        ans.append(u)
    else:
        ans.appendleft(u)

kotae="".join(ans)
print(kotae)

Measured memory_bytes: 101464
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000000;
#define MOD 1000000007LL;
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef int64_t i64;

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

int N; cin >> N;
VVI F(N, VI(10)), P(N, VI(11));
rep(i, 0, N) rep(j, 0, 10) cin >> F[i][j];
rep(i, 0, N) rep(j, 0, 11) cin >> P[i][j];
VI p(11, 0);

int64_t maxi = -INF;
rep(bit, 1, 1<<10){
    VI bothcnt(N+1, 0); // 店iと重複する回数
    rep(i, 0, 10) // period
        if (bit & (1<<i))
            rep(j, 0, N) if (F[j][i]) ++bothcnt[j];
    int64_t profit = 0;
    rep(j, 0, N) profit += P[j][bothcnt[j]];
    maxi = max(maxi, profit);
}

cout << maxi << endl;

}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> count(100001);
    lint sum = 0;
    rep(i, n)
    {
        cin >> a.at(i);
        sum += a.at(i);
        count.at(a.at(i))++;
    }
    int q;
    cin >> q;
    rep(i, q)
    {
        int a, b;
        cin >> a >> b;
        sum = sum + (b - a) * count.at(a);
        count.at(b) += count.at(a);
        count.at(a) = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 4036
#include<bits/stdc++.h>
using namespace std;
bool isvalid(int i,int j,int n,int m)
{
    return i>=0&&j>=0&&i<n&&j<m;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int x1,y1;
    cin>>x1>>y1;
    int x2,y2;
    cin>>x2>>y2;
    x1--;
    y1--;
    x2--;
    y2--;
    vector<vector<char> > adj(n,vector<char>(m));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            char c;
            cin>>c;
            adj[i][j]=c;
            
        }
    }
    vector<vector<int> > dp(n,vector<int>(m,1e9));
    deque<pair<int,pair<int,int> > > q;
    q.push_front({0,{x1,y1}});
    dp[x1][y1]=0;
    while(!q.empty())
    {
        int dist=q.front().first;
        int x=q.front().second.first;
        int y=q.front().second.second;
        q.pop_front();
        for(int i=-2;i<=2;i++)
        {
            for(int j=-2;j<=2;j++)
            {
                int newx=x+i;
                int newy=y+j;
                if(isvalid(newx,newy,n,m)&&adj[newx][newy]=='.')
                {
                    if(abs(i)+abs(j)==1)
                    {
                        if(dp[newx][newy]>dp[x][y])
                        {
                            dp[newx][newy]=dp[x][y];
                            q.push_front({dist,{newx,newy}});
                        }
                        
                    }
                    else
                    {
                        if(dp[newx][newy]>dp[x][y]+1)
                        {
                            dp[newx][newy]=dp[x][y]+1;
                            q.push_back({dist+1,{newx,newy}});
                        }
                    }
                    
                }
            }
        }
    }
    if(dp[x2][y2]==1e9)
    cout<<-1<<endl;
    else
    {
        cout<<dp[x2][y2]<<endl;
    }
    
    
}

Measured memory_bytes: 8684
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	public static void main(String[]args){
		String a=scan.next();
		boolean bool=false;
		if(a.charAt(0)!='k'||a.charAt(a.length()-1)!='e') {
			if(a.indexOf("keyence")!=-1) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
			return;
		}
		
		for(int i=0;i<a.length();i++) {//一つ目の最初の場所
			for(int j=i+1;j<=a.length();j++) {//一つ目の最後
				String str1=a.substring(i,j);
				for(int k=j;k<a.length();k++) {
					for(int l=k+1;l<=a.length();l++)	{
						String str2=a.substring(k,l);
						String str=str1+str2;
						if(str.equals("keyence"))bool=true;
					}
				}
			}
		}
		System.out.println(bool?"YES":"NO");
	}
}

Measured memory_bytes: 92424
#include<bits/stdc++.h>
using namespace std;
bool p(int a){
    if(0 < a && a < 13) return true;
    else return false;
}
int main(){
    int s;
    cin >> s;
    int a = s/100;
    int b = s%100;
    if(!p(a) && p(b)) cout << "YYMM" << endl;
    if(p(a) && !p(b)) cout << "MMYY" << endl;
    if(!p(a) && !p(b)) cout << "NA" << endl;
    if(p(a) && p(b)) cout << "AMBIGUOUS" << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>
  
int main()
{
  int N,i,j,a[10000],x,count,count1=0;
    
  scanf("%d",&N);
    
  for(i=0; i<N; i++){
    scanf("%d",&a[i]);
  }
  for(i=0; i<N; i++){
    count=0;
    x=a[i];
    if(x==2)count1++;
    if(x%2!=0){
      for(j=3;j<=sqrt(x); j++){
    if(x%j==0)count++;
      }
      if(count==0)count1++;
    }
  }
  printf("%d\n",count1);
  return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;



int MOD=1000000007;
int main(){
	int a,b;
	cin >> a >> b;
	if(a>b)
	for(int i=0; i<a; i++) cout << b;
	else
	for(int i=0; i<b; i++) cout << a;
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  string s;
  cin>>s;
  vector<int> f(26);
  trav(x,s) f[x-'a']++;
  frn(i,26) {
    if(f[i]==0) {cout<<(char)(i+'a'); return 0;}
  }
  cout<<"None";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
const ll INF = 1e10;

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i ++) cin >> a[i];

    vector<ll> b = a;
    ll ans1 = 0;
    ll ans2 = 0;
    
    if (a[0] <= 0) {
        ans1 += 1 - a[0];
        a[0] = 1;
    }

    for (ll i = 1; i < n ; i ++) {
        a[i] += a[i - 1];
        if (a[i - 1] < 0 && a[i] <= 0) {
            ans1 += 1 - a[i];
            a[i] = 1;
        }
        if (a[i - 1] > 0 && a[i] >= 0) {
            ans1 += a[i] + 1;
            a[i] = -1;
        }
    }

    if (b[0] >= 0) {
        ans2 += b[0] + 1;
        b[0] = -1;
    }

    for (ll i = 1; i < n ; i ++) {
        b[i] += b[i - 1];
        if (b[i - 1] < 0 && b[i] <= 0) {
            ans2 += 1 - b[i];
            b[i] = 1;
        }
        if (b[i - 1] > 0 && b[i] >= 0) {
            ans2 += b[i] + 1;
            b[i] = -1;
        }
    }

    ll ans = min(ans1,ans2);
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
 
        String str = scanner.next();
        String order,change;
        int Q = scanner.nextInt();
        int a,b;
 
        for(int loop = 0; loop < Q; loop++){
            order = scanner.next();
 
            if(order.equals("print")){
 
                a = scanner.nextInt();
                b = scanner.nextInt();
 
                print(str,a,b);
 
            }else if(order.equals("reverse")){
 
                a = scanner.nextInt();
                b = scanner.nextInt();
 
                str = reverse(str,a,b);
 
            }else{
 
                a = scanner.nextInt();
                b = scanner.nextInt();
                change = scanner.next();
 
                str = replaceStr(str,a,b,change);
            }
        }
    }
 
    private static void print(String str,int a,int b){
        String output = str.substring(a, b+1);
        System.out.println(output);
    }
 
    private static String reverse(String str,int a,int b){
 
        char work[] = str.toCharArray();
 
        int num = b-a+1;
        char tmp;
 
        for(int i = 0; i < num/2; i++){
 
            tmp = work[a+i];
            work[a+i] = work[b-i];
            work[b-i] = tmp;
        }
 
        return String.valueOf(work).substring(0, str.length());
    }
 
    private static String replaceStr(String str,int a,int b,String change){
 
        char ch[] = change.toCharArray();
        char work[] = str.toCharArray();
 
        for(int i = a; i <= b; i++){
            work[i] = ch[i-a];
        }
 
        return String.valueOf(work).substring(0,str.length());
    }
}


Measured memory_bytes: 29704