akhauriyash/Code-Regression huggingface dataset:
from collections import deque
import copy


def bfs(start, s):
    h = len(s)
    w = len(s[0])
    distance = 0
    maze = [[-1] * w for _ in range(h)]
    maze[start[0]][start[1]] = 0
    s[start[0]][start[1]] = "#"
    drcs = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    q = deque()
    q.append(start)
    while(q):
        cr, cc = q.popleft()
        for dr, dc in drcs:
            nr, nc = cr + dr, cc + dc
            if nr < 0 or nc < 0 or nr >= h or nc >= w:
                continue
            if s[nr][nc] == ".":
                q.append([nr, nc])
                s[nr][nc] = "#"
                maze[nr][nc] = maze[cr][cc] + 1
                if maze[nr][nc] > distance:
                    distance = maze[nr][nc]
                    goal = [nr, nc]
    return goal, distance


def main():
    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    for r in range(h):
        if "." in s[r]:
            start = [r, s[r].index(".")]
    goal, distance = bfs(start, copy.deepcopy(s))
    _, res = bfs(goal, s)
    print(res)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3436
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int A, B, C;
    std::cin >> A >> B >> C;

    if (A <= C && C <= B) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No"  << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  if(n%2==1){
    for(int i=0;i<(n+1)/2;i++){
      cout << a[n-1-(i*2)] << " ";
    }
    for(int i=0;i<(n-1)/2;i++){
      cout << a[i*2+1] << " ";
    }
  }else if(n%2==0){
    for(int i=0;i<n/2;i++){
      cout << a[n-1-(i*2)] << " ";
    }
    for(int i=0;i<n/2;i++){
      cout << a[i*2] << " ";
    }
  }
  cout << endl;
  return 0;
}
  


Measured memory_bytes: 2944
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int C[50][26];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) {
    string s;
    cin >> s;
    for (char c : s) {
      C[i][(int)(c-'a')]++;
    }
  }
  string o = "";
  rep(c, 26) {
    int m = INF;
    rep(i, N) {
      m = min(m, C[i][c]);
    }
    rep(i, m) o += (char)('a'+c);
  }
  cout << o << "\n";
  return 0;
}


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

int main()
{
	int a,b,n,s;
	while(cin >> a >> b >> n)
	{
		a%=b; s=0;
		for(int i=0; i<n; i++)
		{
			a*=10;
			s+=(a/b);
			a%=b;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;



public class Main {
	
	InputUtil in = new InputUtil();

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

	public void exec() throws IOException {
		PrintWriter out = new PrintWriter(System.out);
		int H = in.nextInt();
		int[] heapData = in.nextInt(new int[H+1],1,H);
		MaximumHeap mh = new MaximumHeap(heapData);
		out.print(' ');
		OutputUtil.output(out, mh.getAll(), 1, H, " ");
		out.flush();
	}

	
}

class BinaryHeap {
	protected int[] data = null;
	
	public BinaryHeap(int[] data) {
		this.data = data;
	}
	
	public int[] getAll() {
		return data;
	}

	public int getParent(int i){
		if(i<=1 || data.length<i) return -1;
		return i/2;
	}

	public int getLeft(int i){
		if(i<=0 || (data.length-1)/2<i) return -1;
		return i*2;
	}

	public int getRight(int i){
		if(i<=0 || (data.length)/2-1<i) return -1;
		return i*2 + 1;
	}
}

class MaximumHeap extends BinaryHeap {	
	
	public MaximumHeap(int[] data) {
		super(data);
		this.buildMaxHeap();
	}
	
	protected void maxHeapify(int i) {
		int leftId = getLeft(i);
		int rightId = getRight(i);
		int largest = i;
		if(leftId != -1 && data[largest] < data[leftId]) largest = leftId;
		if(rightId != -1 && data[largest] < data[rightId]) largest = rightId;
		if(largest != i){
			data[0] = data[i]; data[i] = data[largest]; data[largest] = data[0];
			maxHeapify(largest);
		}
	}
	
	public void buildMaxHeap() {
		for(int i=(data.length-1)/2; i>=1; i--)
			maxHeapify(i);
			
	}
	
}


class OutputUtil {
	public static final String EOF = System.lineSeparator();

	public static void output(PrintWriter out, int[] a, int off, int len, String delim) {
		out.print(a[off]);
		for(int i=off+1; i<off+len; i++){
			out.print(delim);
			out.print(a[i]);
		}
		out.println("");
		out.flush();
	}
}


class InputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int nextInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    
    public int[] nextInt(int[] a, int off, int num) throws NumberFormatException, IOException{
        int i=off;
        while(i<off+num) {
            for(String s: br.readLine().split(" ")){
            	if(i<off+num) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    }
}

Measured memory_bytes: 75180
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    long long Rnum = 0, Gnum = 0, Bnum = 0;
    for (int i = 0; i < N; ++i)
    {
        if (S[i] == 'R') ++Rnum;
        else if (S[i] == 'G') ++Gnum;
        else ++Bnum;
    }

    // 条件1 を満たす組の総数
    long long sum = Rnum * Gnum * Bnum;
    if (sum == 0)
    {
        cout << sum << endl;
        return 0;
    }
    // 条件2 を満たさない組を引く
    for(int i = 0; i < N - 2; ++i)
    {
        for (int j = i + 1; 2 * j - i < N; ++j)
        {
            // d = j - i なので k = j + d = 2 * j - i
            int k = 2 * j - i;
            if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) --sum;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3576
S = list(input())
len(S)

count=1
for k in S:
    if count%2 != 0:
        if k != "R" and k != "U" and k != "D":
            break
    elif count%2 == 0:
        if k != "L" and k != "U" and k != "D":
            break
    count += 1

if count-1 == len(S):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
import math

def combination_count(n,r):
    return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))

N,M =map(int,input().split())

if N <= 1:
    L = 0
else:
    L = combination_count(N,2)

if M <= 1:
    O = 0
else:
    O = combination_count(M,2) 
    
num = L + O 

print(num)

Measured memory_bytes: 3060
mod=10**9+7
n,k=map(int,input().split())

def calc(a):
    smallest=a*(a-1)//2
    largest=smallest+a*(n-a+1)
    return largest-smallest+1

ans=0

for a in range(k,n+2):
    ans+=calc(a)
    ans%=mod

print(ans)

Measured memory_bytes: 9036
INF = float('inf')

def solve():
    N, Ma, Mb = map(int, input().split())
    l = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        l.append((a, b, c))
 
    dp = [[[INF] * 401 for _ in range(401)] for _ in range(N + 1)]
    dp[0][0][0] = 0
    for i in range(len(l)):
        for a in range(401):
            for b in range(401):
                if dp[i][a][b] != INF:
                    dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
                    dp[i + 1][a + l[i][0]][b + l[i][1]] = min(dp[i + 1][a + l[i][0]][b + l[i][1]], dp[i][a][b] + l[i][2])
 
    ans = INF
    for i in range(len(dp)):
        for a in range(1, 401):
            for b in range(1, 401):
                if dp[i][a][b] != INF:
                    if Ma * b == Mb * a:
                        ans = min(ans, dp[i][a][b])
 
    print(-1 if ans == INF else ans)
 
 
if __name__ == '__main__':
    solve()

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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    string ans = "Yes";
    if (N%2!=0) {
        cout << "No" << endl;
        exit(0);
    }
    vector<char> T(N/2);
    for (int i=0; i<N/2; i++) {
        T[i] = S[i];
    }
    ans = "Yes";
    for (int i=N/2; i<N; i++) {
        if (T[i-N/2]!=S[i]) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

ull getMinK(const vector<ull>& A, const vector<ull>& F, ull thr){
    ull res = 0;
    for(int i=0; i<A.size(); i++){
        if(A[i] * F[i] > thr) res += (A[i] * F[i] - thr + F[i] - 1)/F[i];
    }
    return res;
}

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

    ull thr_min = 0;
    ull thr_max = 1e+13;
    while(thr_max-thr_min>1){
        auto thr = (thr_max + thr_min)/2;
        auto res = getMinK(A, F, thr);
        if(res <= K) thr_max = thr;
        else         thr_min = thr;
    }
    auto res1 = getMinK(A, F, thr_min);
    if(res1 <= K) cout << thr_min << endl;
    else          cout << thr_max << endl;

    return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;
int a[MAXX];

int main()
{
    _FastIO;
    cout.precision(10);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a , a + n);
    double ans = (a[0] + a[1]) * 1.0 / 2.0;
    for(int i = 2; i < n; i++){
        ans = ans + a[i];
        ans = ans * 1.0 / 2.0;
    }
    cout << fixed << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define LLREP(i,n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define SORT(x) sort(ALL(x))
#define REVE(x) reverse(ALL(x))
#define MP make_pair
#define PB push_back
#define INF INT_MAX

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef queue<int> QI;
typedef long long LL;

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	VI x(n), y(n), a(n);
	REP(i, n)cin >> x[i] >> y[i] >> a[i];

	VVB z(h, vector<bool>(w, false));
	REP(i, n) {

		if (a[i] == 1) {
			REP(j, h)REP(k, w) {
				if (k < x[i])z[j][k] = true;
			}
		}

		if (a[i] == 2) {
			REP(j, h)REP(k, w) {
				if (k >= x[i])z[j][k] = true;
			}
		}

		if (a[i] == 3) {
			REP(j, h)REP(k, w) {
				if (j < y[i])z[j][k] = true;
			}
		}

		if (a[i] == 4) {
			REP(j, h)REP(k, w) {
				if (j >= y[i])z[j][k] = true;
			}
		}

	}
	int ans = 0;
	REP(i, h)REP(j, w)if (!z[i][j])ans++;
	cout << ans << endl;
}

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

long long dp[310][610];

int main() {
    int n, k; cin >> n >> k;
    vector<long long> h(n+1, 0);
    for (int i = 0; i <= n+1; i++) {
        for (int j = 0; j <= 2*n; j++) dp[i][j] = 1e16;
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) cin >> h[i+1];
    for (int i = 0; i <= n; i++) {
        for (int z = 0; z <= n; z++) {
            for (int j = i+1; j <= n; j++) {
                dp[j][z+1] = min(dp[j][z+1], dp[i][z] + max(0LL, h[j]-h[i]));
            }
            dp[n+1][z] = min(dp[n+1][z], dp[i][z]);
        }
    }
    long long ans = 1e18;
    for (int i = 0; i <= k; i++) ans = min(ans, dp[n+1][n-i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int shurui,max=0;
int N=Integer.parseInt(sc.next());
String S=sc.next();
    for(int I=0;I<N;I++){
    String SS=S.substring(0,I+1);
    String SSS=S.substring(I+1,N);
    shurui=0;
    if(SSS.contains("a")&&SS.contains("a"))shurui++;
    if(SSS.contains("b")&&SS.contains("b"))shurui++;
    if(SSS.contains("c")&&SS.contains("c"))shurui++;
    if(SSS.contains("d")&&SS.contains("d"))shurui++;
    if(SSS.contains("e")&&SS.contains("e"))shurui++;
    if(SSS.contains("f")&&SS.contains("f"))shurui++;
    if(SSS.contains("g")&&SS.contains("g"))shurui++;
    if(SSS.contains("h")&&SS.contains("h"))shurui++;
    if(SSS.contains("i")&&SS.contains("i"))shurui++;
    if(SSS.contains("j")&&SS.contains("j"))shurui++;
    if(SSS.contains("k")&&SS.contains("k"))shurui++;
    if(SSS.contains("l")&&SS.contains("l"))shurui++;
    if(SSS.contains("m")&&SS.contains("m"))shurui++;
    if(SSS.contains("n")&&SS.contains("n"))shurui++;
    if(SSS.contains("o")&&SS.contains("o"))shurui++;
    if(SSS.contains("p")&&SS.contains("p"))shurui++;
    if(SSS.contains("q")&&SS.contains("q"))shurui++;
    if(SSS.contains("r")&&SS.contains("r"))shurui++;
    if(SSS.contains("s")&&SS.contains("s"))shurui++;
    if(SSS.contains("t")&&SS.contains("t"))shurui++;
    if(SSS.contains("u")&&SS.contains("u"))shurui++;
    if(SSS.contains("v")&&SS.contains("v"))shurui++;
    if(SSS.contains("w")&&SS.contains("w"))shurui++;
    if(SSS.contains("x")&&SS.contains("x"))shurui++;
    if(SSS.contains("y")&&SS.contains("y"))shurui++;
    if(SSS.contains("z")&&SS.contains("z"))shurui++;
    max=Math.max(shurui, max);
    }
System.out.println(max);
}
}

Measured memory_bytes: 21716
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		long k = sc.nextLong();

		long[] a = new long[50];
		Arrays.fill(a, 49 + (k / 50));

		int r = (int) (k % 50);
		for (int i = 0; i < r; i++) {
			a[i] += 50 - r;
		}
		for (int i = r; i < 50; i++) {
			a[i] -= r;
		}

		out.println(50);
		out.print(a[0]);
		for (int i = 1; i < 50; i++) {
			out.print(" " + a[i]);
		}
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) return true;
		else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) return buffer[ptr++];
		return -1;
	}

	private boolean isPrintableChar(byte c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) throw new NoSuchElementException();
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll a; string b;
	cin >> a >> b;
	
	ll llb = 0;
	llb += b[0]-'0';
	llb *= 10;
	if(b.size() >= 3)llb += b[2]-'0';
	llb *= 10;
	
	if(b.size() >= 4)llb += b[3]-'0';

	//print(llb)
	ll ans = a * llb;
	ans /= 100;
	
	print(ans)
	
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int colors[10];
int main() {
	int n;
	cin >> n;
	rep(i, n) {
		int a; cin >> a;
		a /= 400;
		if (a>=8) colors[8]++;
		else colors[a] = 1;
	}
	int ans = 0;
	rep(i, 8) ans += colors[i];
	if (ans == 0) cout << 1 << ' ' << colors[8] << endl;
	else cout << ans << " " << ans + colors[8] << endl;
	return 0;
}

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

int main(void)
{
	char ip=' ';
	int i=0;
	for(int k=0;k<3;k++)
	{
		ip=getchar();
		if(ip=='o')
			i+=100;
	}
	cout<<i+700<<endl;
	return 0;
}

 

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

#define MX 100050
int x[MX];
int f[18][MX];

int main() {
	int n, L, q;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", x + i);
	scanf("%d%d", &L, &q);
	for(int i = 0; i < n; i++) {
		int p = upper_bound(x, x + n, x[i] + L) - x; p--;
		f[0][i] = p;
	}
	for(int i = 1; i < 18; i++)
		for(int j = 0; j < n; j++) f[i][j] = f[i - 1][f[i - 1][j]];
	while(q--) {
		int s, t; scanf("%d%d", &s, &t); s--; t--;
		if(s > t) swap(s, t);
		int res = 0;
		for(int i = 17; i >= 0; i--) {
			if(f[i][s] < t) s = f[i][s], res ^= 1 << i;
		}
		printf("%d\n", res + 1);
	}
	return 0;
}

Measured memory_bytes: 8192
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int A, B; cin >> A >> B;

    string ans = "No";
    if ((A % 2 == 1) && (B % 2 == 1)) ans = "Yes";

    cout << ans << endl;

    return 0;
}

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

void LCS_bottomup(string x,string y,int n,int m)
{
    int a[n+1][m+1]={0};
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0||j==0) a[i][j]=0;
            else if(x[i-1]==y[j-1]) a[i][j]=a[i-1][j-1]+1;
            else a[i][j]=max(a[i-1][j],a[i][j-1]);
        }
    }
    int idx=a[n][m];
    char ans[idx+1];
    ans[idx]='\0';
    int i=n,j=m;
    while(i>0&&j>0)
    {
        if(x[i-1]==y[j-1])
        {
            ans[idx-1]=x[i-1];
            idx--;
            i--;
            j--;
        }
        else if(a[i-1][j]>a[i][j-1])i--;
        else j--;
    }
    cout<<ans;
}

int main()
{
    string x,y;
    cin>>x>>y;
    int i=x.size();
    int j=y.size();
    LCS_bottomup(x,y,i,j);
    //for(int i=0;i<ans.size();i++)cout<<ans[i];
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;


int main(){

  int n;cin>>n;

  out(n*n*n);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	ll n;
	cin>>n; 
	ll a[n][3],i,j;
	for(i=0;i<n;i++) {
		for(j=0;j<3;j++) cin>>a[i][j];
	}
	ll dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(i=1;i<n;i++) {
		for(j=0;j<3;j++) {
			if(j==0) {
				dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
			}
			else if(j==1) {
				dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
			}
			else {
				dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
			}
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
}

Measured memory_bytes: 4992
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    x = N % K
    if abs(x-K) < x:
        cnt = abs(x-K)
    else:
        cnt = x
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

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

void input(int& rnBgn, vector<int>& rvnCoord)
{
  int nCoordSiz;
  cin >> nCoordSiz >> rnBgn;
  rvnCoord.resize(nCoordSiz);

  for (int& rnCoord : rvnCoord)
    cin >> rnCoord;
}

int gcd(int nOne, int nOtr)
{
  if ( !nOtr )
    return nOne;
  else
    return gcd(nOtr, nOne % nOtr);
}

int calcMaxMovemnt(int nBgn, const vector<int>& cnrvnCoord)
{
  vector<int> vnDiff(cnrvnCoord.size());

  for (int i = 0; i < cnrvnCoord.size(); ++i)
    vnDiff[i] = abs(nBgn - cnrvnCoord[i]);

  int nGcd = vnDiff[0];

  for (int i = 1; i < vnDiff.size(); ++i)
    nGcd = gcd(nGcd, vnDiff[i]);

  return nGcd;
}
  
int main()
{
  int nBgn;
  vector<int> vnCoord;
  
  input(nBgn, vnCoord);
  cout << calcMaxMovemnt(nBgn, vnCoord) << endl;

  return 0;
}

Measured memory_bytes: 3948
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/union_find.hpp
#ifndef UNION_FIND_HPP
#define UNION_FIND_HPP


/*
usage:

tools::union_find<std::int_fast64_t> uf(10);
uf.unite(1, 3);
uf.is_same(1, 3);
*/

namespace tools {
  template <typename T>
  class union_find {
  private:
    std::vector<T> parents;
    std::vector<T> sizes;
    T component_count;

  public:
    union_find(const T n) :
      parents(n),
      sizes(n, 1),
      component_count(n) {
      for (T i = 0; i < n; ++i) {
        parents[i] = i;
      }
    }

    T root(const T x) {
      return this->parents[x] == x ? x : (this->parents[x] = this->root(this->parents[x]));
    }

    bool is_same(const T x, const T y) {
      return this->root(x) == this->root(y);
    }

    void unite(T x, T y) {
      x = this->root(x);
      y = this->root(y);
      if (x == y) return;

      if (this->sizes[x] < this->sizes[y]) std::swap(x, y);
      this->parents[y] = x;
      this->sizes[x] += this->sizes[y];
      --this->component_count;
    }

    T size() const {
      return this->component_count;
    }

    T size(const T x) {
      return this->sizes[this->root(x)];
    }
  };
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  tools::union_find<i64> uf(N);
  for (i64 i = 0; i < M; ++i) {
    i64 A_i, B_i;
    std::cin >> A_i >> B_i;
    uf.unite(A_i - 1, B_i - 1);
  }

  i64 answer = std::numeric_limits<i64>::min();
  for (i64 i = 0; i < N; ++i) {
    answer = std::max(answer, uf.size(i));
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 6436
def dfs(L):
    global N, ans
    ret = 0
    if all([L.count(i) for i in ["3", "5", "7"]]):
        ret += 1
    for j in ["3", "5", "7"]:
        if int(L + j) <= int(N):
            ret += dfs(L + j)
    return ret

N = input()
print(dfs(''))

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=3e3+10, mod=1e9+7;
ll dp[N][N],a[N];

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	memset(dp,0,sizeof dp);
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	
	for(int len=1;len<=n ;len++){
		for(int l=0;l+len-1<n;l++){
			int r=l+len-1;
			if( (n-len)%2==0 ){ // if even number of turns have been occured
				dp[l][r]=max(a[l]+dp[l+1][r] ,a[r]+dp[l][r-1] );
			}else dp[l][r]=min(-a[l]+dp[l+1][r] ,-a[r]+dp[l][r-1] );
		}
	}
	cout<<dp[0][n-1];
}

// check for any potential overflow before submitting


Measured memory_bytes: 71040
#include <stdio.h>
int map[10]={1,2,4,8,16,32,64,128,256,512};
int main(void){
    int num,i,o,line[10];
    for(;o=0,scanf("%d",&num)!=EOF;){
        for(i=9;i>=0;i--){
            if(num/map[i]){
                line[o++]=map[i];
                num-=map[i];
            }
        }
        for(i=o-1;i>=0;i--)
            printf("%d%s",line[i],i==0?"\n":" ");
    }
    return 0;
}

Measured memory_bytes: 596
/* "miles to go before I sleep." */


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

typedef long long ll;
#define mod 1000000007
#define pi  3.14159265358979323846
#define pb push_back
#define mk make_pair
#define popcnt(a) _Generic((a), int: __builtin_popcount(a), \  long long: __builtin_popcountll(a))  
#define precise(x) cout<<fixed<<setprecision(10)<<x
#define test cout<<"#";
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout) 

const ll inf = 1e18L + 2;

double dp[3001][3001];

// double solve(vector<double> &v, ll n, ll x)
// {
//     if(x == 0)
//         return 1;
//     if(n == 0)
//         return 0;
//     if(dp[n][x] >= -0.9)
//         return dp[n][x];
//     return dp[n][x] = solve(v, n-1, x-1)*v[n-1] + solve(v, n-1, x)*(1 - v[n-1]);
// }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<double> v(n);
    for(ll x = 0; x < n; x++)
        cin>>v[x];
    dp[0][0] = 1;
    for(ll x = 1; x <= n; x++)
    {
        dp[0][x] = 0;
    }
    for(ll x = 1; x <= n; x++)
    {
        dp[x][0] = 1;
    }
    for(ll x = 1; x <= n; x++)
    {
        for(ll y = 1; y <= n; y++)
        {
            dp[x][y] = v[x-1]*dp[x-1][y-1] + (1 - v[x-1])*dp[x-1][y];
        }
    }
    precise(dp[n][(n+2)/2]);
}

Measured memory_bytes: 74104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P; 
typedef pair<P, P> L; 
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define EQ(n,m) (abs((n)-(m)) < EPS)
 
D dot(P a, P b) {return (conj(a)*b).X; }
 
D cross(P a, P b) {  return (conj(a)*b).Y;}
 
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

P crosspointLL(P a1, P a2, P b1, P b2) {
  D d1 = cross(b2-b1, b1-a1);
  D d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;  // same line
  if (EQ(d2, 0)) throw "kouten ga nai";   // 交点がない
  return a1 + d1/d2 * (a2-a1);
}

int inPolygon(const VP& ps, P p) {
  int n = ps.size();
  bool in = false;
  rep (i, n) {
    P a = ps[i] - p;
    P b = ps[(i + 1) % n] - p;
    if (EQ(cross(a,b), 0) && LE(dot(a,b), 0)) return 2;
    if (a.Y > b.Y) swap(a,b);
    if ((a.Y*b.Y < 0 || (a.Y*b.Y < EPS && b.Y > EPS)) && LE(cross(a, b), 0)) in = !in;
  }
  return in;
}

VP convexCut(const VP& ps, P a1, P a2) {
  int n = ps.size();
  VP ret;
  rep(i,n) {
    int ccwc = ccw(a1, a2, ps[i]);
    if (ccwc != -1) ret.push_back(ps[i]);
    int ccwn = ccw(a1, a2, ps[(i + 1) % n]);
    if (ccwc * ccwn == -1) ret.push_back(crosspointLL(a1, a2, ps[i], ps[(i + 1) % n]));
  }
  return ret;
}

VP voronoiCell(P p, const VP& ps, const VP& outer) {
  VP cl = outer;
  rep (i, ps.size()) {
    if (EQ(norm(ps[i]-p), 0)) continue;
    P h = (p+ps[i])*0.5;
    cl = convexCut(cl, h, h + (ps[i]-h)*P(0,1) );
  }
  return cl;
}

int n,m;
double x,y,ans;
VP v,cir,out;

int main(){

  out.push_back(P(-1e9,-1e9));
  out.push_back(P(1e9,-1e9));
  out.push_back(P(1e9,1e9));
  out.push_back(P(-1e9,1e9));

  cin>>n;
  rep(i,n){
    scanf("%lf%lf",&x,&y);
    v.push_back(P(x,y));
  }

  cin>>m;
  rep(i,m){
    scanf("%lf%lf",&x,&y);
    cir.push_back(P(x,y));
  }

  vector<VP>V;
  rep(i,m) V.push_back( voronoiCell(cir[i],cir,out) );

  rep(i,m){
    rep(j,n){
      if( inPolygon(V[i],v[j]) ) ans=max(ans,abs(cir[i]-v[j]));
      rep(k,V[i].size()){
        if( isecSS( V[i][k] , V[i][(k+1)%V[i].size()] , v[j],v[(j+1)%v.size()])){
          ans=max(ans,abs(cir[i]-crosspointLL(V[i][k] , V[i][(k+1)%V[i].size()] , v[j],v[(j+1)%v.size()])));
        }
      }
    }
    rep(j,V[i].size()){
      if( inPolygon(v,V[i][j]) ) ans=max(ans,abs(V[i][j]-cir[i]));
    }
  }

  printf("%.11f\n",ans);
}


Measured memory_bytes: 3336
S=input()
N=len(S)
S1=S[0:int((N-1)/2)]
S2=S[int((N+3)/2)-1:len(S)]
if S==S[::-1] and S1==S1[::-1] and S1==S1[::-1]:
  print("Yes")
else :
  print("No")

Measured memory_bytes: 38256
#include <iostream>

#define MAX 1000000001

using namespace std;


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

  int a_min = MAX, b_min = MAX;
  int a, b;

  for(int i = 0; i < n; i++){
    cin >> a >> b;
    if(b < b_min){
      b_min = b;
      a_min = a;
    }
  }
  cout << a_min+b_min << endl;
  

}


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

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

template <int M> class ModInt {
    int x;

  public:
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    constexpr ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % M);
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-() const { return ModInt(-x); }
    constexpr ModInt operator+(const ModInt &p) const {
        return ModInt(*this) += p;
    }
    constexpr ModInt operator-(const ModInt &p) const {
        return ModInt(*this) -= p;
    }
    constexpr ModInt operator*(const ModInt &p) const {
        return ModInt(*this) *= p;
    }
    constexpr ModInt operator/(const ModInt &p) const {
        return ModInt(*this) /= p;
    }
    constexpr bool operator==(const ModInt &p) const { return x == p.x; }
    constexpr bool operator!=(const ModInt &p) const { return x != p.x; }
    constexpr ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t = 0;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(const int64_t &n) const {
        ModInt ret(1), mul(x);
        int64_t k = n % (M - 1);
        while(k > 0) {
            if(k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    constexpr friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    constexpr friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t = 0;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};
using modint = ModInt<mod>;

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

    ll n;
    cin >> n;
    modint ans(1);
    ll robot = 0;
    rep(i, n) {
        int x;
        cin >> x;
        robot++;
        if(x < robot * 2 - 1) ans *= robot--;
    }
    while(robot)
        ans *= robot--;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

string S,T,U;
int main(){
    ll a,b;
    cin>>S>>T;
    cin>>a>>b;
    cin>>U;
    if(U==S){
        cout<<a-1<<" "<<b<<endl;
    }else{
        cout<<a<<" "<<b-1<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<string> vs;

/*
struct node {
	int key;
	node* parent;
	node* left;
	node* right;
};
typedef vector<node> vn;
void pre(int u, vn& A) {
	if (u == -1) return;
	cout <<" "<<u ;
	pre(A[u].left,A);
	pre(A[u].right,A);
}
void in(int u, vn& A) {
	if (u == -1)return;
	in(A[u].left, A);
	cout <<" "<< u ;
	in(A[u].right, A);
}
void post(int u, vn& A) {
	if (u == -1)return;
	post(A[u].left, A);
	post(A[u].right, A);
	cout<<" " << u ;
}
void print(int root) {
	in(root);
	pre(root);
}
void insert() {

}
int main() {
	int N;
	cin >> N;
	vector<node> A(N);
	for (int i = 0; i < N; i++)A[i].parent = A[i].left = A[i].right = -1;
	for (int i = 0; i < N; i++)
	{
		int id;
		cin >> id;
		cin >> A[id].left;
		cin >> A[id].right;
		if (A[id].left != -1)A[A[id].left].parent = id;
		if (A[id].right != -1)A[A[id].right].parent = id;
	}
	int root = 0;
	for (int i = 0; i < N; i++)
	{
		if (A[i].parent == -1)root = i;
	}

};

*/
int main() {
	int N, K;
	cin >> N >> K;
	int num = 1;
	for (int i = 0; i < N; i++)
	{
		num = min(num*2,num+K);
	}
	cout << num << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
x, y = 0, 0
count = 1
ops = []
while True:
    if count == H * W:
        break
    if x % 2 == 0:
        if y == W - 1:
            nx, ny = x + 1, y
        else:
            nx, ny = x, y + 1
    else:
        if y == 0:
            nx, ny = x + 1, y
        else:
            nx, ny = x, y - 1
    if a[x][y] % 2 == 1:
        a[x][y] -= 1
        a[nx][ny] += 1
        ops.append((x + 1, y + 1, nx + 1, ny + 1)) # 1-based indexing
    x, y = nx, ny
    count += 1
print(len(ops))
for op in ops:
    print(*op)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, ll>> v;
  for (int i = 0; i < n; i++) {
    ll x, l;
    cin >> x >> l;
    v.push_back(make_pair(x + l, x - l));
  }
  sort(v.begin(), v.end());

  ll ans = 0, now = 0;
  for (int i = 0; i < n; i++) {
    if (ans != 0 && v[i].second < now) continue;  // 1つめは必ず可能なので
    now = v[i].first;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    while(cin >> n, n)
    {
        ll cnt = 0;
        while(n != 1)
        {
            if(n % 2 == 0) n /= 2LL;
            else n = 3LL * n + 1LL;
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}




Measured memory_bytes: 3136
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int A[3];
	for_(i,0,3) cin >> A[i];
	sort(A, A + 3);
	
	int maxi = A[2], med = A[1];
	
	int ans = maxi - med;
	A[0] += ans;
	
	int rem = A[2] - A[0];
	if (rem % 2) {
		ans += 1 + (rem + 1) / 2;
	}
	else {
		ans += rem / 2;
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	int A[N];
	rep(i,0,N) cin>>A[i];
	int B[N],C[N];
	rep(i,0,N){ B[i] = A[i] + i + 1; C[i] = i + 1 - A[i]; }
	sort(B, B+N); sort(C, C+N);
	long ans = 0;
	rep(i,0,N){
		ans += upper_bound(C, C+N, B[i]) - lower_bound(C, C+N, B[i]);
	}cout<<ans<<endl;
}

Measured memory_bytes: 5984
#include <bits/stdc++.h>
using namespace std;
int main(){
  int rf,wf,c,r;
  double a;
  int ans;
  while(1){
    cin>>rf>>wf>>c>>r;
    if(rf==0 && wf==0 && c==0 && r==0) break;
    ans=0;
    a=(double)rf/(double)wf;
    while(1){
      if(a<c){
	rf+=r;
	ans++;
	a=(double)rf/(double)wf;
      }
      else break;
    }
    cout<<ans<<endl;
  }
  return 0;
}
    



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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n; cin >> n;
    vector<ll> p(n);
    rep(i, n) {
        ll tmp; cin >> tmp;
        tmp--;
        p[i] = tmp;
    }
    vector<ll> x(n, 0);
    ll ans = 0;
    rep(i, n) {
        if(p[i] == 0) x[p[i]] = 1;
        else x[p[i]] = x[p[i]-1]+1;
        
        if(ans < x[p[i]]) ans = x[p[i]];
    }
    cout << n - ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 6344
n = int(input())
s = list(input())
ans = 0
r = []
g = []
b = []
for i in range(n):
    if s[i]=='R':r.append(i)
    elif s[i]=='G':g.append(i)
    else:b.append(i)
ans = len(r)*len(g)*len(b)
d = 0
for i in range(n-2):
    for j in range(i,n-1):
        k = j+j-i
        if k < n and s[i] != s[j] and s[k] != s[i] and s[k]!=s[j]:
            d+=1
print(ans-d)

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;
    string ss;
    cin >> ss;
    string tt;
    cin >> tt;
    
    cout << (char)(st[0] - ('a' - 'A'))
        << (char)(ss[0] - ('a' - 'A'))
        << (char)(tt[0] - ('a' - 'A')) << endl;

    return 0;
}


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

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

template<class T>
istream &operator>>(istream &ist, vector<T> &vec)
{
	for (auto i = vec.begin(); i != vec.end(); ++i)
	{ ist >> vec[i]; }
	return ist;
}

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//



int main()
{
	IOS

	int n;
	cin >> n;
	if (n % 2 == 0)
	{
		cout << n * (n - 2) / 2 << '\n';
		for (int i = 1; i <= n; ++i)
		{
			for (int j = i + 1; j <= n; ++j)
			{
				if (i + j != n + 1)
				{
					cout << i << ' ' << j _;
				}
			}
		}
	} else
	{
		cout << n - 1 + (n - 1) * (n - 3) / 2 << '\n';
		for (int i = 1; i < n; ++i)
		{
			cout << n << ' ' << i _;
		}

		for (int i = 1; i < n; ++i)
		{
			for (int j = i + 1; j < n; ++j)
			{
				if (i + j != n)
				{
					cout << i << ' ' << j << '\n';
				}
			}
		}
	}

	return 0;
}
/*
 5 3
 100 1
 3 5
 2 5
 2 7
 1 8
 */

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

int data[100];

int main() {
  
  int n; cin >> n;
  for ( int i = 0; i < n; i++ ) cin >> data[i];
  
  int cnt = 0;
  
  for ( int i = 0; i < n; i++ ) {
    int minj = i;
    for ( int j = i; j < n; j++ ) {
      if ( data[j] < data[minj] ) minj = j;
    }      
      swap( data[i], data[minj] );
      if ( i != minj ) cnt++;
  }

  for ( int i = 0; i < n-1; i++ ) cout << data[i] << " ";
  cout << data[n-1] << endl;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	long w=sc.nextLong();
	long h=sc.nextLong();
	long x=sc.nextLong();
	long y=sc.nextLong();
	int ans=0;
	if(2*x==w&&2*y==h){
		ans=1;
	}
	System.out.println((double)(w*h)/2+" "+ans);

	}}

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

int main(){
  int n;
  int a[100000];
  int b[100000];
  int c[100000];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  for(int i = 0; i < n; i++) cin >> c[i];
  sort(a, a+n);
  sort(b, b+n);
  sort(c, c+n);
  ll cnt = 0;
  for(int i = 0; i < n; i++){
    auto ita = lower_bound(a, a+n, b[i]);
    auto itc = upper_bound(c, c+n, b[i]);
    cnt += (ita - a) * ((c+n) - itc);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1408