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

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

signed main() {
	int p, m, c;
	cin >> p >> m >> c;
	cout << p + m + c << endl;
	return 0;
}



Measured memory_bytes: 3096
from collections import deque

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    li = [list(map(int, input().split())) for _ in range(2*h-1)]
    
    Map = [['x'] * (w*2+1)]
    Map += [['x'] + ['.'] * (w*2-1) + ['x'] for _ in range(2*h-1)]
    Map += [['x'] * (w*2+1)]
    
    for i in range(2*h+1):
        for j in range(2*w+1):
            if i%2 == 0 and j%2 == 0:
                Map[i][j] = 'x'
    
    for k in range(2*h-1):
        if k%2 == 0:
            for i in range(len(li[k])):
                if li[k][i] == 1:
                    Map[k+1][i*2+2] = 'x'
        else:
            for i in range(len(li[k])):
                if li[k][i] == 1:
                    Map[k+1][i*2+1] = 'x'
    
    moved = [[0, 1], [0, -1], [1, 0], [-1, 0]]
    stack = deque([(1,1)])
    Map[1][1] = 1
    while stack:
        x, y = stack.popleft()
        for s, t in moved:
            if Map[x+s][y+t] == '.':
                stack.append((x+s, y+t))
                if (x+s) % 2 == 0 or (y+t) % 2 == 0:
                    Map[x+s][y+t] = Map[x][y]
                else:
                    Map[x+s][y+t] = Map[x][y] + 1
    
    ans = Map[2*h-1][-2]
    if ans == '.':
        print(0)
    else:
        print(ans)



Measured memory_bytes: 6040
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
#vsInput()


n,k=value()
a=sorted(array())

print(sum(a[0:k]))





Measured memory_bytes: 77468
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(),x.end()

int main(){

    string s;
    cin >> s;

    if(s=="SSS")
        cout << 0 << endl;
        else if(s=="RRR")
        cout << 3 << endl;
    else if(s=="RRS"||s=="SRR")
        cout << 2 << endl;
    else 
        cout << 1 << endl;

    return 0;

}


Measured memory_bytes: 3552
if __name__ == '__main__':

	while True:

		n,m = map(int,input().split())
		if n == 0 and m == 0:
			break

		A = [i for i in range(1,n+1)]

		ind = 0
		for _ in range(n-1):
			x = len(A)
			ind += m - 1
			if ind >= x:
				ind = ind % x
			A.pop(ind)

		print(A[0])



Measured memory_bytes: 5604
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

N=input()
A=map(int, sys.stdin.readline().split())

mod=10**9+7
ans=0
for keta in range(60):
    C=defaultdict(lambda: 0)     #0と1の出現回数をカウント
    temp_ans=0  #2進数での各桁のxorの和
    for i,a in enumerate(A):
        a=a>>keta&1
        if i==0:
            C[a]+=1
        else:
            if a==1:
                temp_ans+=C[0]  #aが1の場合は、xorを取ったら1になるのは0なので0の出現回数をカウント
            elif a==0:
                temp_ans+=C[1]  #aが0の場合は、xorを取ったら1になるのは1なので1の出現回数をカウント
            C[a]+=1
    ans+=pow(2,keta,mod)*temp_ans
    ans%=mod
print ans

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

using namespace std;

int const NMAX = 1e5;
int v[1 + NMAX];

int main() {

  int n, pos = 1, p, ans = 1;
  string GUIDO;
  cin >> n >> p >> ans;
  for(int i =1;i <= 10;i++){
    ans = n * ans - p;
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 3532
#include<cstdio>

int map[12][12];
char c[15];


void f(int x,int y)
{
	map[x][y]=0;
	if(map[x-1][y]==1&&x-1>=0&&12>x-1&&y>=0&&12>y)f(x-1,y);
	if(map[x+1][y]==1&&x+1>=0&&12>x+1&&y>=0&&12>y)f(x+1,y);
	if(map[x][y-1]==1&&x>=0&&12>x&&y-1>=0&&12>y-1)f(x,y-1);
	if(map[x][y+1]==1&&x>=0&&12>x&&y+1>=0&&12>y+1)f(x,y+1);
}


int main()
{
	while(true)
	{
	for(int i=0;i<12;i++)
	{
		if(scanf("%s",c)==EOF)goto end;
		for(int j=0;j<12;j++)
		{
			map[i][j]=c[j]-'0';
		}
	}

	int answer=0;
	for(int i=0;i<12;i++)
	{
		for(int j=0;j<12;j++)
		{
			if(map[i][j]==1)
			{
				answer++;
				f(i,j);
			}
		}
	}
	printf("%d\n",answer);
	}


end:
	return 0;
}

Measured memory_bytes: 976
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int maxn = 1e8 + 8;

int a[10000 + 8];
int n,v,j;

void insertSort(int a[])
{
    for(int i = 1; i < n; ++i){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j+1]  = a[j];
            j--;
        }
        a[j+1] = v;
    }
}
bool  judge(int x)
{
    if(x == 2) return true;
    for(int i = 2; i <= (int)sqrt(x); ++i){
        if(x % i == 0) return false;
    }
    return true;
}
int main()
{
    memset(a,0,sizeof a);

    scanf("%d",&n);
    for(int i = 0; i < n; ++i){
        scanf("%d",&a[i]);
    }
    insertSort(a);//??¶??´?????????O(n^2)

   /* for(int i = 0; i < n; ++i){
        if(i) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");*/

    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(judge(a[i])) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}
/*
11
12
13
14
15
16
17
7
8
9
10
11
*/

Measured memory_bytes: 3232
text = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
        1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]


print(text[int(input()) - 1])


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

int main(){
  string s;
  cin >> s;
  int ans = 700;
  for(auto i = 0;i<3;i++){
    if(s.at(i) == 'o'){
      ans += 100;
    }
  }
  cout <<ans << endl;
}

Measured memory_bytes: 256
def main():
    import numpy as numpy
    import sys
    from collections import deque

    S=sys.stdin.readline().strip()
    Q=int(sys.stdin.readline())
    rv=False
    S=deque(S)
    for i in range(Q):
        qs=sys.stdin.readline().split()
        if int(qs[0])==1:
            rv=(rv+1)%2
        elif int(qs[0])==2:
            if (int(qs[1])-1+rv)%2==0:
                S.appendleft(qs[2])
            elif (int(qs[1])-1+rv)%2==1:
                S.append(qs[2])
            else:
                print('error')
                return
        else:
            print('error')
            return
    
    if rv:
        S=reversed(list(S))
    else:
        S=list(S)

    S="".join(S)
    
    return S

print(main())

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


int main() {
  string s;
  cin >> s;
  if (s[0]==s[1]||s[1]==s[2]||s[2]==s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
ll extended_gcd(ll a, ll b, ll &x, ll &y) {
    if (b == 0) { x = 1; y = 0; return a; }
    ll xx, yy;
    ll res = extended_gcd(b, a%b, xx, yy); x = yy; y = xx - yy * (a / b);
    return res;
}

const ll sz = 1e4 + 5;
vector<ll> fac(sz, 1);

// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }

// * ALways PASS arrays, strings etc to functions BY REFERENCE

// const ll sz = 1e6 + 6;
// vector<bool> p(sz, true);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    // p[0] = p[1] = false;
    // for (ll i = 2; i*i <= sz; i++) if (p[i]) {
    //     for (ll j = i*i; j <= sz; j += i)
    //         p[j] = false;
    // }
    
    int t = 1;
    // cin >> t;

    while(t--) {
        ll sm;
        cin >> sm;
        
        if (sm <= 2) {
            cout << 0 << endl;
            return 0;
        }
        
        vector<ll> dp(sm+1, 0);
        dp[0] = 1;
        
        for (int i = 3; i <= sm; i++) {
            //for (int j = i-3; j >= 0; j--)
            dp[i] = (dp[i-1] + dp[i-3]) % mod;
        }
        
        cout << dp[sm] << endl;
    }
    
	return 0;
}


Measured memory_bytes: 3724
#include <stdio.h>

int gcd(int a, int b) {
	while (b > 0) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(void) {
	int x, y;
	if (scanf("%d%d", &x, &y) != 2) return 1;
	printf("%d\n", (x + 1) + (y + 1) - (gcd(x, y) + 1));
	return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 0; i < n; i++)
		if(s[i] == ',')
			s[i] = ' ';
	cout << s << endl;
    return 0;
}



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

int main(){
  int n;
  cin>>n;
  int tarous=0,hanakos=0;
  for(int i=0;i<n;i++){
    string tarou,hanako;
    cin>>tarou>>hanako;
    if(tarou>hanako){
      tarous+=3;
    }else if(tarou<hanako){
      hanakos+=3;
    }else{
      tarous++;
      hanakos++;
    }
  }
  cout<<tarous<<' '<<hanakos<<endl;
  return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>;

signed main() {
    string s;
    cin>>s;
    rep(i, s.size()) if(s[i] == '7') {
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3588
import math
import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    ts = np.zeros(n+1,dtype=int)
    for _ in range(m):
        a,b = map(int,ipt().split())
        ts[a] += 1
        ts[b] += 1
    if np.count_nonzero(ts%2) == 0:
        print("YES")
    else:
        print("NO")
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 14028
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

typedef pair<int, int> P;
int main() {
  int n; cin >> n;
  string s; cin >> s;
  list<char> C;
  for (auto &&c: s) C.push_back(c);
  int depth = 0;
  int min_ = 1000000;
  for (auto &&c: s) {
    if (c == '(') depth++;
    else depth--;
    min_ = min(min_, depth);
  }
  while (min_++ < 0) C.push_front('(');
  depth = 0;
  for (auto &&c: C) {
    if (c == '(') depth++;
    else depth--;
  }
  while (depth-- > 0) C.push_back(')');
  for (auto&&c: C) cout << c;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3588
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CraneAndTurtle solver = new CraneAndTurtle();
        solver.solve(1, in, out);
        out.close();
    }

    static class CraneAndTurtle {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();

            if (y < 2 * x || 4 * x < y || y % 2 == 1) {
                out.append("No\n");
                return;
            }

            for (int i = 0; i <= x; i++) {
                if ((2 * i + 4 * (x - i)) == y) {
                    out.append("Yes\n");
                    return;
                }

            }
            out.append("No\n");
        }

    }
}



Measured memory_bytes: 35700
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := intSliceScanner(n + 1)
	us := make([]int, n+1)
	us[n] = a[n]
	for i := n - 1; i >= 0; i-- {
		us[i] = us[i+1] + a[i]
	}
	ds := make([]int, n+1)
	ds[0] = 1
	f := true
	for i := 1; i < n+1; i++ {
		if ds[i-1]-a[i-1] >= 0 {
			ds[i] = smaller((ds[i-1]-a[i-1])*2, us[i])
		} else {
			f = false
		}
	}
	f = true
	if ds[n] != a[n] {
		f = false
	}
	if f {
		ans := 0
		for i := 0; i < n+1; i++ {
			ans += ds[i]
		}
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}
func smaller(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}


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

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> cs(m);
	for(int i=0; i<m; ++i){
		cin >> cs[i];
	}
	sort(cs.begin(), cs.end());
	vector<vector<int>> cache(n+1, vector<int>(m));
	for(int i=0; i<m; ++i) cache[0][i]=0;
	for(int i=0; i<=n; ++i) cache[i][0]=i;
	for(int ni=1; ni<=n; ++ni){
		for(int mi=1; mi<m; ++mi){
			int t;
			if(cs[mi]>ni) t=min(cache[ni][mi-1], cache[ni-1][mi]+1);
			else {
				t=min(cache[ni][mi-1], cache[ni-1][mi]+1);
				t=min(t, cache[ni-cs[mi]][mi]+1);
			}
			cache[ni][mi]=t;
		}
	}
	cout << cache[n][m-1] << endl;
	return 0;
}



Measured memory_bytes: 8644
def p(i: int) -> int:
    """レベルiバーガーのパティの数
    p[i] = 2*p[i-1] + 1
    p[i] + 1 = 2*(p[i-1] + 1)
    p[i] + 1 = (2**i)*(p[0] + 1)
    p[i] + 1 = (2**i)*2
    p[i] = 2**(i+1) - 1
    """
    return 2**(i+1) - 1


def a(i: int) -> int:
    """レベルiバーガーの層の数(パティとパンの数)
    a[i] = 2*a[i-1] + 3
    a[i] + 3 = 2 * (a[i-1] + 3)
    a[i] + 3 = (2**i) * (a[0] + 3)
    a[i] + 3 = (2**i) * 4
    a[i] = (2**(i+2)) - 3
    """
    return 2**(i+2) - 3


def f(N: int, X: int) -> int:
    """レベルNバーガーの下からX層の中に含まれるパティの数
    :param N: バーガーのレベル
    :param X: パティの数を調べたい層の数
    :return: パティの数
    """
    if N == 0:
        return 1 if X > 0 else 0

    an = a(N)
    if X < an // 2 + 1:
        # レベルN-1バーガーに含まれる。
        return f(N-1, X-1)
    if X == an // 2 + 1:
        # 中央のパティ + レベルN-1バーガーに含まれる全てのパティ
        return 1 + p(N-1)
    # レベルN-1バーガの全てのパティ + 中央のパティ
    # + レベルN-1バーガの下から(X-(ai+2))そうに含まれるパティ
    return 1 + p(N-1) + f(N-1, X-(an // 2 + 1))


if __name__ == "__main__":
    N, X = map(int, input().split())
    ans = f(N, X)
    print(ans)


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

int main()
{
  int  n, m, a[50], b[50], c[50], d[50], i, j, min, dst, cp;

  scanf("%d %d", &n, &m);
  for( i = 0; i < n; i++){
    scanf("%d %d", &a[ i ], &b[ i ]);
  }
  for( j = 0; j < m; j++){
    scanf("%d %d", &c[ j ], &d[ j ]);
  }

  for( i = 0; i < n; i++){
    min = 1000000000;
    for( j = 0; j < m; j++){
      dst = abs( a[ i ] - c[ j ]) + abs( b[ i ] - d[ j ]);
      if( dst < min){
        min = dst;
         cp = j;
      }
    }
    printf("%d\n", cp+1);
  }

  return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/05/02.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC167
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const int MOD = 1000000007;
//#define __DBG__



void solve(void){
  
  ll A, B, C, K;
  
  cin >> A >> B >> C >> K;
  
  if(K<=A){
    cout << K << endl;
  }
   else if(K <= A+B){
    cout << A << endl;
  }
  else
  {
    cout << 2*A+B-K << endl;
  }
  return;
}



#define TESTCASES 1

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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}




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

int h, w, k;
char s[300][300];
int a[300][300];

bool check(int l, int r, int y) {
    for (int j = l; j <= r; j++) {
        if (s[y][j] == '#' || a[y][j] > 0) return false;
    }
    return true;
}
void fillrange(int l, int r, int y, int i) {
    for (int j = l; j <= r; j++) {
        a[y][j] = i;
    }
}

int main() {
    cin >> h >> w >> k;
    vector<pair<int, int>> p;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s[i][j];
            if (s[i][j] == '#') p.push_back(make_pair(i, j));
        }
    }
    for (int i = 0; i < k; i++) {
        int x = p[i].second, y = p[i].first;
        a[y][x] = i + 1;
        int l = x, r = x;
        while (l > 0 && s[y][l - 1] != '#' && a[y][l - 1] == 0) {
            l--;
            a[y][l] = i + 1;
        }
        while (r < w - 1 && s[y][r + 1] != '#' && a[y][r + 1] == 0) {
            r++;
            a[y][r] = i + 1;
        }
        int t = y, b = y;
        while (t > 0 && check(l, r, t - 1)) {
            t--;
            fillrange(l, r, t, i + 1);
        }
        while (b < h - 1 && check(l, r, b + 1)) {
            b++;
            fillrange(l, r, b, i + 1);
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std; 
typedef long long lli;
#define mod 1000000007
const int INF = 1e6;
const int MAX = 1e5+10;
#define fori(n) for(int i=0;i<n;i++)
#define forj(n) for(int j=0;j<n;j++)
#define forli(n) for(lli i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define print(a) cout<<a<<endl
#define print2(a,b) cout<<a<<" "<<b<<endl
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define sortvec(a) sort(a.begin(),a.end())
 
//FUNCTONS
lli llipower(lli x, lli y){lli res = 1;x = x % mod; while (y > 0){if (y & 1) res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
lli llipowerp(lli x, lli y,lli p){lli res = 1;x = x % p; while (y > 0){if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}
lli gcd(lli a, lli b){ if (!a) return b; return gcd(b%a,a);}
lli binarySearch(vector<int> arr, int l, int r, int x){ 
	if (r >= l) { 
		lli mid = l + (r - l) / 2; 
		if (arr[mid] == x) return mid; 
		if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); 
		return binarySearch(arr, mid + 1, r, x); 
	} 
	return -1;
}

template <typename T>
void printvec(vector<T> inp){
	for(int i=0;i<inp.size();i++){
		cout<<inp[i]<<" ";
	}
	cout<<endl;
}
template <typename T>
T ceildiv(T x, T y){
	return 1 + ((x - 1) / y);
}
lli modInverse(lli a, lli m){//m is PRIME 
    lli g = gcd(a, m); 
    if (g != 1) return -1;
    else return llipowerp(a, m-2, m);
} 
vector<int> addvec(vector<int> a, vector<int> b){
	vector<int> c;
	fori(a.size()){
		c.pb(a[i]+b[i]);
	}
	return c;
}
const int MAXN=5e5;
int n;
vector<int> t[4*MAXN+3];

void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
    	vector<int> tmp(26,0);
    	tmp[a[tl]]=1;
        t[v] = tmp;
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = addvec(t[v*2],t[v*2+1]);
    }
}
vector<int> sum(int v, int tl, int tr, int l, int r) {
    if (l > r){
    	vector<int> temp(26,0);
        return temp;
    }
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return addvec(sum(v*2, tl, tm, l, min(r, tm)),sum(v*2+1, tm+1, tr, max(l, tm+1), r));
}
void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
    	vector<int> temp(26,0);
    	temp[new_val]=1;
        t[v]=temp;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = addvec(t[v*2],t[v*2+1]);
    }
}
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int nums[n];
	fori(n) nums[i]=(s[i]-'a');
	build(nums,1,0,n-1);
	int q;
	cin>>q;
	int temp1,temp2,temp4;
	char temp3;
	fori(q){
		cin>>temp1;
		if(temp1==1){
			cin>>temp2>>temp3;
			update(1,0,n-1,temp2-1,temp3-'a');
		}
		else{
			cin>>temp2>>temp4;
			vector<int> temp;
			temp=sum(1,0,n-1,temp2-1,temp4-1);
			int ans=0;
			fori(26) ans+=min(1,temp[i]);
			cout<<ans<<endl;
		}
	}

}
 
 

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

int main() {
	int n; cin >> n;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		ans += i; 
	}
	cout << ans;
}

Measured memory_bytes: 3600
// https://atcoder.jp/contests/abc084/tasks/abc084_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// constexprな素数列挙(エラトステネスの篩)
// https://259-momone.hatenablog.com/entry/2018/05/06/015026
template <int_fast64_t max_N> struct Prime {
    bool sieve[max_N];
    constexpr Prime() : sieve() {
        for (int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for (int_fast64_t i = 2; i < max_N; ++i) {
            for (int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
};

// BIT(Binary-Indexed-Tree) 別名：Fenwick Tree
template <typename T> struct BIT {
    int n;
    vector<T> d;
    BIT(int n = 0) : n(n), d(n + 1) {}
    // 要素iにxを加算
    void add(int i, T x = 1) {
        for (i++; i <= n; i += i & -i) {
            d[i] += x;
        }
    }
    // 区間[0, i]の合計を求める（閉区間）
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i & -i) {
            x += d[i];
        }
        return x;
    }
    // 区間[l, r]の合計を求める（閉区間）
    T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

const int SZ = 1e5 + 1;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    constexpr auto p = Prime<SZ>();
    BIT<int> bit(SZ);
    for (int i = 1; i < SZ; i += 2) {
        if (p.sieve[i] && p.sieve[(i + 1) / 2]) {
            bit.add(i, 1);
        }
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << bit.sum(l, r + 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 4328
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

A,B=LI()

print(math.ceil((B-1)/(A-1)))

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    ll cnt = 0;
    // 1桁
    for (int x=1; x<=9; ++x) {
        if (x <= N) cnt ++;
        for (int i=10; ; i*=10) {
            if (x*i+x > N) break;
            ll t = (max(0, min(i, N-(x*i+x)+1)) + 9) / 10;
            cnt += t*2;
        }   
    }
    // 2桁~
    for (int x=1; x<=9; ++x) {
        for (int y=1; y<=9; ++y) {
            // y...x
            ll ca = 0;
            for (int i=10; ; i*=10) {
                if (y*i+x > N) break;
                ca += (max(0, min(i, N-(y*i+x)+1)) + 9) / 10;
            }
            // x...y
            ll cb = 0;
            for (int i=10; ; i*=10) {
                if (x*i+y > N) break;
                cb += (max(0, min(i, N-(x*i+y)+1)) + 9) / 10;
            }
            cnt += ca * cb;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
hs = list(map(int, input().split()))

dp = [0]*N

dp[0] = 0
dp[1] = abs(hs[1] - hs[0])
for i in range(2, N):
    dp[i] = min(dp[i-2]+abs(hs[i]-hs[i-2]), dp[i-1]+abs(hs[i]-hs[i-1]))
    #print(dp)
print(dp[N-1])


Measured memory_bytes: 52208
/**
 *	author:		Yoseph Weissman
 *	created:	27.06.2020 20:02:28
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s(1,'\0'),t(1,'\0');
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < (int)s.length(); ++i) {
		if (s[i] != t[i])
			++cnt;
	}
	cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 3792
[L,R] = list(map(int,input().split()))

flag=0
for i in range(L,R+1):
    if i%2019 == 0:
        flag=1
        break

LL = L%2019
RR = R%2019
dammy=[]
for i in range(LL,RR):
    for j in range(i+1,RR+1):
        dammy.append((i*j)%2019)

if flag==0:
    print(min(dammy))
else:
    print(0)

Measured memory_bytes: 107148
#include<stdio.h>
int main()
{
	unsigned long long A,B;
	char s;
	scanf("%llu %c %llu",&A,&s,&B);
	long long c;
	if(s=='+')
	{
		c=A+B;
		printf("%lld\n",c);
	}
	if(s=='-')
	{
		c=A-B;
		printf("%lld\n",c);
	}
	return 0;
}

Measured memory_bytes: 128
import math
n = sorted(list(int(i) for i in input().split()),reverse=True)
mod = 10**9+7
if n[0]-n[1] >= 2:
 #並べない
 ans = 0
elif n[0]-n[1] ==1:
 ans = ((math.factorial(n[0])%mod)*(math.factorial(n[1])%mod)%mod)
else:
 ans = (2*(math.factorial(n[0])%mod)*(math.factorial(n[1])%mod)%mod)    
print(ans)
  


Measured memory_bytes: 4100
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

int main(){
  long K,sum=0;
  cin>>K;
  for(int c=1;c<=K;c++){
    for(int b=1;b<=K;b++){
      for(int a=1;a<=K;a++){
        sum+=gcd(gcd(a,b),c);
      }
    }
  }
    cout<<sum;
}


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

#define MAX_N 100000

priority_queue<pair<int, bool> > q;

int main(void)
{
    int n, h;
    scanf("%d%d", &n, &h);
    for (int i = 0; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        q.push(make_pair(a, 1));
        q.push(make_pair(b, 0));
    }
    int ans = 0;
    while (h > 0) {
        int dis = q.top().first;
        bool flag = q.top().second;
        q.pop();
        if (flag) {
            int cnt = h / dis;
            if (h % dis) cnt++;
            h -= dis * cnt;
            ans += cnt;
        }
        else {
            h -= dis;
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#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()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;

  if(k%2) {
    cout << b-a << endl;
  } else {
    cout << a-b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    string s;
    cin>>s;
    ll l = s.length();
    ll x,mn=1000000;
    for(ll i=0;i<l-2;i++)
    {
        x = ((((s[i]-'0')*10)+(s[i+1]-'0'))*10)+(s[i+2]-'0');
        //cout<<x<<endl;
        if(abs(x-753)<mn)
            mn = abs(x-753);
    }
    cout<<mn<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    long N,H,W;
    std::cin >> H;
    std::cin >> W;
    std::cin >> N;
    std::cout << std::ceil((double)N/std::max(H,W)) << std::endl;
    return 0;
}

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

class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		int n = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => -x).ToArray();

		var aSum = 0;
		var bSum = 0;

		for (int i = 0; i < n; i++)
		{
			if (i % 2 == 0)
				aSum += input[i];
			else
				bSum += input[i];
		}
		Console.WriteLine(aSum - bSum);
	}

}

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

const int INF = 1001001001;

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

  if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)){
    cout<<"Yes"<<endl;
  }else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


vector<int> primes(1001, 1);

void calcPrimes() {
    primes[0] = 0;
    primes[1] = 0;
    for (int i = 2; i <= sqrt(1000); i++) {
        if ( primes[i] != 0 ) {
            for (int j = 2; i*j < 1001; j++) {
                primes[i*j] = 0;
            }
        }
    }
}


int main() {

    CIN(int, N);
    calcPrimes();
    int MOD = 1e9+7;

    if ( N==1 ) {
        cout << 1 << "\n";
        return 0;
    }

    ll ans = 1;

    for (int i = 2; i <= N; i++) {

        if ( primes[i] == 0 ) continue;

        int count = 0;
        int temp = N;

        for (int j = 0; j < N; j++) {
            if (temp == 0) break;
            count += temp / i;
            temp = temp / i;
        }
        ans = (ans * (count+1)) % MOD;
    }


    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 100005;

ll n, mod = 1e9 + 7, dp[MAXN][2];
vector<ll>adj[MAXN];

void dfs(ll node, ll par)
{
	for(auto it : adj[node])
	{
		if(it == par) continue;
		dfs(it, node);
	}
	if(sz(adj[node]) == 1 && node > 0)
		dp[node][0] = dp[node][1] = 1;
	else
	{
		ll temp1 = 1, temp2 = 1;
		for(auto it : adj[node])
		{
			if(it == par) continue;
			temp1 = (temp1 * ((dp[it][0] + dp[it][1]) % mod)) % mod;
			temp2 = (temp2 * dp[it][1]) % mod;
		}
		dp[node][1] = temp1;
		dp[node][0] = temp2;
	}
}

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

 	cin >> n;
 	for(int i=0;i<n-1;i++)
 	{
 		ll a, b;
 		cin >> a >> b;
 		adj[a - 1].pb(b - 1);
 		adj[b - 1].pb(a - 1);
 	}   
 	dfs(0, -1);
 	cout << (dp[0][0] + dp[0][1]) % mod << endl;
    return 0;
}

Measured memory_bytes: 11264
#include<iostream>

using namespace std;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  while(a!=-1 || b!=-1 || c!=-1){
    if(a==-1 || b==-1)cout << 'F';
    else if(a+b>=80)cout << 'A';
    else if(a+b>=65)cout << 'B';
    else if(a+b>=50)cout << 'C';
    else if(a+b>=30){
      if(c>=50)cout << 'C';
      else cout << 'D';
    }else cout << 'F';
    cout << endl;
    cin>> a >> b >> c;
  }
  return 0;
}



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

int main()
{
  int N;
  cin >> N;
  vector<int> n(N);
  for (int i = 0; i < N; ++i)
    n[i] = i + 1;
  vector<int> P(N);
  for (int i = 0; i < N; ++i)
    cin >> P[i];
  vector<int> Q(N);
  for (int i = 0; i < N; ++i)
    cin >> Q[i];
  bool _p = true;
  bool _q = true;
  int cnt = 0;
  int cnt_p, cnt_q;
  do
  {
    int i;
    if (_p)
    {
      for (i = 0; i < N; ++i)
        if (P[i] != n[i])
          break;
      if (N == i)
      {
        _p = false;
        cnt_p = cnt;
      }
    }
    if (_q)
    {
      for (i = 0; i < N; ++i)
        if (Q[i] != n[i])
          break;
      if (N == i)
      {
        _q = false;
        cnt_q = cnt;
      }
    }
    ++cnt;
  }
  while ((_p || _q) && std::next_permutation(n.begin(), n.end()));
  cout << ((cnt_p < cnt_q) ? cnt_q - cnt_p : cnt_p - cnt_q);
  return 0;
}


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

int main()
{
  string S, T;
  cin >> S >> T;
  vector<vector<int>> V(30);
  for (int i = 0; i < S.size(); i++)
  {
    int ic = S.at(i) - 'a';
    V.at(ic).push_back(i);
  }
  int64_t ans = 0, pos = -1;
  for (int i = 0; i < T.size(); i++)
  {
    int a = T.at(i) - 'a';
    if (V.at(a).size() == 0)
    {
      cout << -1 << endl;
      return 0;
    }
    auto itr = upper_bound(V.at(a).begin(), V.at(a).end(), pos);
    if (itr == V.at(a).end())
    {
      ans += (S.size() - 1 - pos) + (V.at(a)[0] + 1);
      pos = V.at(a)[0];
    }
    else
    {
      ans += *itr - pos;
      pos = *itr;
    }
  }
  cout << ans << endl;
}


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


int main() {
    int N;
    cin >> N;
    ll a = 1, b = 1;
    ll T, A;
    ll q_a, q_b, q;
    for (int i = 0; i < N; i++) {
        cin >> T >> A;
        q_a = (a + T - 1) / T;
        q_b = (b + A - 1) / A;
        q = max(q_a, q_b);
        a = T * q;
        b = A * q;
    }
    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 3640
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int q; cin >> q;
	vector<bool> prime(1001001, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i < 100001; ++i)
	{
		if (!prime[i])continue;
		for (int j = i + i; j < 100001; j += i)prime[j] = false;
	}
	vector<int> sum(100002, 0);
	rep(i, 100001)
	{
		sum[i + 1] = sum[i];
		if (i % 2 == 0)continue;
		if (prime[i] && prime[(i + 1) / 2])++sum[i + 1];
	}
	while (q--)
	{
		int l, r; cin >> l >> r;
		cout << sum[r + 1] - sum[l] << endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main(){
	int day[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
	int mon,d;
	while(cin>>mon>>d){
		int sum =0;
		if(mon == 0) break;
		for(int i=0;i<mon-1;i++){
			sum += day[i];
		}
		sum += d;
		int a = sum%7;
		if(a==1) cout<<"Thursday"<<endl;
		else if(a==2) cout<<"Friday"<<endl;
		else if(a==3) cout<<"Saturday"<<endl;
		else if(a==4) cout<<"Sunday"<<endl;
		else if(a==5) cout<<"Monday"<<endl;
		else if(a==6) cout<<"Tuesday"<<endl;
		else if(a==0) cout<<"Wednesday"<<endl;
	}
	return 0;
}

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

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

using namespace std;

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

	int ans=0;
	rep(i,n){
		int a; cin>>a;
		while(a%2==0) ans++, a>>=1;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int MOD = (int) (Math.pow(10, 9) + 7);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(ary);
        long ans = 1;
        if (n % 2 == 0) {
            long even = -1;
            for (int i = 0; i < n; i += 2) {
                even += 2;
                int temp1 = ary[i];
                int temp2 = ary[i + 1];
                if (temp1 != even || temp2 != even) {
                    System.out.println(0);
                    return;
                }
            }
        } else {
            if (ary[0] != 0) {
                System.out.println(0);
                return;
            }
            long odd = 0;
            for (int i = 1; i < n; i += 2) {
                odd += 2;
                int temp1 = ary[i];
                int temp2 = ary[i + 1];
                if (temp1 != odd || temp2 != odd) {
                    System.out.println(0);
                    return;
                }
            }
        }
        for (int i = 0; i < (n / 2); i++) {
            ans = (2 * ans) % MOD;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 46160
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X,Y,Z,a,b = 0;
    cin >> X >> Y >> Z;
    for(int i = 1; i < X; i++){
        a = i*Y +(i + 1)*Z;
        if(a > X)
        {
            break;
        }
        b++;
    }
    cout << b << endl;
}

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

const int MAX_HW = 505;
int A[MAX_HW][MAX_HW];
int H, W;

int res[MAX_HW*MAX_HW][4];

int main()
{
    scanf("%d %d", &H, &W);
    for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) scanf("%d", &A[i][j]);

    int N = 0;
    for(int i = 0; i < H-1; ++i) for(int j = 0; j < W; ++j) {
        if(A[i][j]%2) {
            ++A[i+1][j]; --A[i][j];
            res[N][0] = i+1, res[N][1] = j+1, res[N][2] = i+2, res[N][3] = j+1;
            ++N;
        }
    }
    for(int j = 0; j < W-1; ++j) {
        if(A[H-1][j]%2) {
            ++A[H-1][j+1]; --A[H-1][j];
            res[N][0] = H, res[N][1] = j+1, res[N][2] = H, res[N][3] = j+2;
            ++N;
        }
    }
    printf("%d\n", N);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 3; ++j) printf("%d ", res[i][j]);
        printf("%d\n" ,res[i][3]);
    }
    /*
    printf("\n");
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) printf("%d ", A[i][j]);
        printf("\n");
    }
    */
    return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

int main(){
    int N, M;
    cin >> N >> M;

    vector<int>X(M);
    vector<long long>kyori(M-1);
    rep(i,M)cin>> X[i] ;
    sort(X.begin(),X.end());
    rep(i,M-1)kyori[i] = X[i+1]-X[i];
    sort(kyori.begin(),kyori.end(),greater<int>());

    long long ans = 0;
    for(int i = N-1; i<M-1; i++){
        ans += kyori[i];
    }

    cout << ans << endl;

}



Measured memory_bytes: 4208
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int N,K,X,Y;

	cin >> N >> K >> X >> Y;

	int ans = 0;

	if (N <= K) {
		for (int i = 0; i < N; i++) {
			ans += X;
		}

		cout << ans << endl;
	}
	else {
		for (int i = 0; i < K; i++) {
			ans += X;
		}
		for (int i = K; i < N; i++) {
			ans += Y;
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <iterator>
#include <algorithm>
#include <queue>

typedef std::pair<int, int> P;

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
std::string move[] = {"R", "U", "L", "D"};

inline P key(int i, int j) {return std::make_pair(i, j);}
inline int getx(P pair) {return pair.first;}
inline int gety(P pair) {return pair.second;}

struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator() (const std::pair<T1, T2> &pair) const
	{
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};

std::unordered_map<P, P, pair_hash> d;
std::unordered_map<P, bool, pair_hash> visits;

std::string bfs(int sx, int sy, int tx, int ty);
void solve();
/*
void solve(int sx, int sy, int tx, int ty)
{
  std::string ans;
  ans += bfs(sx, sy, tx, ty);
  ans += bfs(tx, ty, sx, sy);
  ans += bfs(sx, sy, tx, ty);
  ans += bfs(tx, ty, sx, sy);
  std::cout << ans << std::endl;
}
*/

void solve(int sx, int sy, int tx, int ty)
{
  std::string ans;

  for (int i=0; i< tx-sx; i++) ans += "R";
  for (int i=0; i< ty-sy; i++) ans += "U";

  for (int i=0; i< tx-sx; i++) ans += "L";
  for (int i=0; i< ty-sy; i++) ans += "D";

  ans += "L";
  for (int i=0; i<= ty-sy; i++) ans += "U";
  for (int i=0; i<= tx-sx; i++) ans += "R";
  ans += "D";

  ans += "R";
  for (int i=0; i<= ty-sy; i++) ans += "D";
  for (int i=0; i<= tx-sx; i++) ans += "L";
  ans += "U";

  std::cout << ans << std::endl;
}

int main()
{
  int sx, sy, tx, ty;
  std::cin >> sx >> sy >> tx >> ty;
  solve(sx, sy, tx, ty);
  return 0;
}

std::string bfs(int sx, int sy, int tx, int ty)
{
  std::string ret;
  std::queue<P> que;

  // init
  que.push(key(sx, sy));
  d.insert({key(sx, sy), key(0, -1)});

  while (!que.empty()) {
    P p = que.front(); que.pop();
    int x = getx(p), y = gety(p);
    //std::cout << x << ", " << y << '\n';
    if (x==tx && y==ty) break;
    for (int i=0; i<4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      auto search = d.find(key(nx, ny));
      auto visited = visits.find(key(nx, ny));
      if (search == d.end() && visited == visits.end()) {
        // if not found and not visited before, then push it to queue
        que.push(key(nx, ny));
        int dist = (d.find(key(x, y))->second).first + 1;
        d.insert({key(nx, ny), key(dist, i)});
      }
      //else std::cout << "Already visited: " << nx << ", " << ny << '\n';
    }
  }

  // back trace
  P p = key(tx, ty);
  while (1) {
    P srch = d.find(p)->second;
    int m = srch.second;
    if (m==-1) break;
    ret += move[m];
    visits.insert({p, true});
    p = key(getx(p) - dx[m], gety(p) - dy[m]);
  }
  visits.erase(visits.find(key(tx, ty)));
  std::reverse(ret.begin(), ret.end());

  //std::cout << ret << std::endl;

  d.clear();

  return ret;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
		//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int N;
		cin>>N;
		long double a,s=0;
		for(int i=0;i<N;i++){
      cin>>a;
      s+=1/a;
		}
		cout<<1/s;
		return 0;
}


Measured memory_bytes: 256