akhauriyash/Code-Regression huggingface dataset:
let bin_search x (a : int array) n =
  let l = ref 0 in
  let r = ref n in
  try
    while !l < !r do
      let m = (!l + !r) / 2 in
      if x = a.(m) then raise Exit;
      if x < a.(m) then r := m
      else l := m + 1;
    done;
    false
  with Exit -> true

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let read_seq () = read_line () |> split_on_char ' ' |> List.map int_of_string in
  let n = read_int () in
  let s = read_seq () |> Array.of_list in
  let _ = read_int () in
  read_seq ()
  |> List.fold_left (fun acc e -> acc + (if bin_search e s n then 1 else 0)) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 16288
#include <cstdio>
#include <cstdlib>

#define siz 10000000

char buf[siz], *bit = buf;

inline int nextInt(void) {
	register int ret = 0;
	register int neg = false;

	for (; *bit < '0'; ++bit)
		if (*bit == '-')neg ^= true;

	for (; *bit >= '0'; ++bit)
		ret = ret * 10 + *bit - '0';

	return neg ? -ret : ret;
}

int n, m;

int pre[100005];

inline int ask(int p) {
	int ret = 0;
	for (; p; p -= p&-p)
		ret += pre[p];
	return ret;
}

inline void add(int p, int k) {
	for (; p <= n; p += p&-p)
		pre[p] += k;
}

signed main(void) {
	fread(buf, 1, siz, stdin);

	n = nextInt();
	m = nextInt();

	for (int i = 1; i <= m; ++i) {
		int c = nextInt();
		if (c)	// get(i)
			printf("%d\n", ask(nextInt()));
		else	// add(s, t, x)
		{
			int x = nextInt();
			int y = nextInt();
			int k = nextInt();
			add(x, k); add(y + 1, -k);
		}
	}

	//system("pause");
}

Measured memory_bytes: 4304
//
// Created by 徳備彩人 on 2020/02/23.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

const int MOD = 1e9 + 7;

int fact(ll a, ll b){
    ll result = 1;
    for(int i=0;i<b;++i){
        result *= a;
        a--;
        result %= MOD;
    }
    return result;
}

int mpow(ll x, ll n){
    ll result = 1;
    while( n != 0 ) {
        if (n & 1) result = result*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return result % MOD;
}

int combination(ll a, ll b) {
    ll result = fact(a, b) % MOD;
    result *= mpow(fact(b, b), MOD-2) % MOD;
    return result % MOD;
}

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    ll s = mpow(2, n) - 1;
    s = (s - combination(n, a) - combination(n, b)) % MOD;
    cout << (s + MOD) % MOD << endl;
}





Measured memory_bytes: 256
a,b = map(int,input().split())
num_a = ''
num_b = ''
lst = []
for i in range(b):
    num_a += str(a)
for i in range(a):
    num_b += str(b)
lst.append(num_a)
lst.append(num_b)
lst.sort()
print(lst[0])


Measured memory_bytes: 9052
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.printf("%d %d %f\n", a/b, a%b, a/(double)b);
    }
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  for (int i = 1; i + k - 1 <= n; i++){
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
	double max = -1000000000000000;
	double min =  1000000000000000;
	double m;
	while(cin >> m){
		if(max<m) max=m;
		if(min>m) min=m;
	}
	cout << setprecision(20) << max-min << endl;
}

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

int main() {
	int n, q;
	map<int, int> cnt;
	long long total = 0;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		cnt[a] ++;
		total += a;
	}

	cin >> q;

	while (q--)
	{
		int b, c;
		cin >> b >> c;

		// b 개수만큼 뺀 다음 c 개수만큼 더하면 됨.
		int bcnt = cnt[b];

		total -= (long long)(bcnt)*b;
		total += (long long)(bcnt)*c;

		cnt[b] -= bcnt;
		cnt[c] += bcnt;

		cout << total << endl;
	}
}

Measured memory_bytes: 8088
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		int ans = 0;

		for (int i = 0; i < k; i++) {
			if (!s.substring(i, i+1).equals("1")) {
				ans = Integer.valueOf(s.substring(i, i+1));
				break;
			}
		}
		
		if (ans == 0) {
			System.out.println(1);	
		} else {
			System.out.println(ans);
		}
		
		sc.close();
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
const int INF = 2e9;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> L(n);
  REP(i,n) cin >> L[i];
  sort(ALL(L));
  ll cnt = 0;
  REP(b,n) FOR(c,b+1,n){
    int tmp = lower_bound(ALL(L), L[c]+L[b]) - L.begin();
    cnt += max(tmp-(c+1), 0LL);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3632
def main()->None:
    (N, K) = map(int, input().split())
    l = list(map(int, input().split()))

    sorted_l = sorted(l, reverse=True)
    s = 0
    for i in sorted_l[:K]:
        s += i

    print(s)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

ll lcm(int x, int y)
{
	ll X = x; ll Y = y;
	if (x < y) swap(x, y);
	while (1)
	{
		if (y == 0) break;
		ll tmpy = y;
		y = x%y;
		x = tmpy;
	}
	return X / x*Y;
}

int main()
{
	ll a[3]; ll m[3];
	while (1)
	{
		REP(i, 3) cin >> a[i] >> m[i];
		if (!a[0] && !a[1] && !a[2] && !m[0] && !m[1] && !m[2]) break;
		ll t[3];
		REP(i, 3)
		{
			ll x = 1;
			x = (a[i] * x % m[i]);
			for (t[i] = 1; x != 1; t[i]++)
			{
				x = (a[i] * x % m[i]);
			}
		}
		cout << lcm(t[0], lcm(t[1], t[2])) << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    
    int m = (n-1) / 111;
    string ans = to_string((m+1)*111);
    cout << ans << endl;
}

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

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

    string s;
    cin >> s;

    if(s == "RRR") cout << 3 << endl;
    else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) cout << 2 << endl;
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 3648
A, B = [int(x) for x in input().split()]

def main():
    count = 0
    for num in range(A, B + 1):
        s = str(num)
        pri = s[0:3] # first 3 chars
        sec = s[4:1:-1] # last 3 chars
        if pri == sec:
            count += 1
    print(count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0 ;
int d[55], cnt[30] ;
bool vis[30] ;
vector<int> v ;
void dfs (int cur) {
    if (cur == n) {
        int res = 1e9 ;
        for (int i = 0; i < v.size(); i ++)
            for (int j = i + 1; j < v.size(); j ++)
                res = min (res, min (abs (v[i] - v[j]), 24 - abs (v[i] - v[j]))) ;
        ans = max (ans, res) ;
        return ;
    }
    dfs (cur + 1) ;
    if (!vis[v[cur]]) {
        v[cur] = 24 - v[cur] ;
        dfs (cur + 1) ;
        v[cur] = 24 - v[cur] ;
    }
}
int main() {
    cin >> n ;
    cnt[0] = 1 ;
    for (int i = 1; i <= n; i ++) {
        scanf("%d", &d[i]) ;
        cnt[d[i]] ++ ;
    }
    for (int i = 0; i <= 12; i ++)
        if (cnt[i] >= 3) {
            printf("0\n"); return 0 ;
        }
    for (int i = 0; i <= 12; i ++) {
        if (cnt[i] == 1) v.push_back (i) ;
        if (cnt[i] == 2) {
            v.push_back (i), v.push_back (24 - i) ;
            vis[i] = 1; vis[24 - i] = 1 ;
        }
    }
    dfs (1) ;
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type UnionFindTree struct {
	parent	map[int]int
	size	map[int]int
	rank	map[int]int
}

func NewUnionFindTree() *UnionFindTree {
	u := new(UnionFindTree)
	u.parent = make(map[int]int)
	u.size = make(map[int]int)
	u.rank = make(map[int]int)
	return u
}

func (u UnionFindTree) Add(a int) {
	u.parent[a] = -1
	u.size[a] = 1
	u.rank[a] = 0
}

func (u UnionFindTree) Root(a int) int {
	if u.parent[a] == -1 {
		return a
	} else {

		u.parent[a] = u.Root(u.parent[a])
		return u.parent[a]
	}
}

func (u UnionFindTree) Unite(a, b int) {
	a, b = u.Root(a), u.Root(b)
	if a == b {
		return
	}
	if u.rank[a] == u.rank[b] {
		u.rank[a] += 1
	} else if u.rank[a] < u.rank[b] {
		a, b = b, a
	}
	u.parent[b] = a
	u.size[a] += u.size[b]
}

func (u UnionFindTree) IsSame(a, b int) bool {
	return u.Root(a) == u.Root(b)
}

func (u UnionFindTree) Size(a int) int {
	return u.size[u.Root(a)]
}

func (u UnionFindTree) Groups() map[int][]int {
	ret := make(map[int][]int)
	for k := range u.parent {
		r := u.Root(k)
		if len(ret[r]) == 0 {
			ret[r] = []int{}
		}
		ret[r] = append(ret[r], k)
	}
	return ret
}

type Point struct {
	pos int
	idx int
}

type ByPos []Point
func (a ByPos) Len() int { 
	return len(a)
}
func (a ByPos) Less(i, j int) bool {
	return a[i].pos < a[j].pos
}
func (a ByPos) Swap(i, j int) { 
	a[i], a[j] = a[j], a[i]
}

type Adjacent struct {
	distance int
	a int
	b int
}

type ByDistance []Adjacent
func (a ByDistance) Len() int { 
	return len(a)
}
func (a ByDistance) Less(i, j int) bool {
	return a[i].distance < a[j].distance
}
func (a ByDistance) Swap(i, j int) { 
	a[i], a[j] = a[j], a[i]
}

func main() {
	var N int
	fmt.Scan(&N)
	uft := NewUnionFindTree()
	xPoint := make([]Point, N)
	yPoint := make([]Point, N)
	for i := 0; i < N; i++ {
		uft.Add(i)
		var x, y int
		fmt.Scan(&x, &y)
		xPoint[i] = Point{pos: x, idx: i}
		yPoint[i] = Point{pos: y, idx: i}
	}
	sort.Sort(ByPos(xPoint))
	sort.Sort(ByPos(yPoint))
	adj := make([]Adjacent, (N-1)*2)
	for i := 0; i < N-1; i++ {
		adj[2*i] = Adjacent{
			distance: xPoint[i+1].pos - xPoint[i].pos, 
			a: xPoint[i].idx, 
			b: xPoint[i+1].idx,
		}
		adj[2*i+1] = Adjacent{
			distance: yPoint[i+1].pos - yPoint[i].pos, 
			a: yPoint[i].idx, 
			b: yPoint[i+1].idx,
		}
	}
	sort.Sort(ByDistance(adj))
	ans := 0
	for i := 0; i < (N-1)*2; i++ {
		if !uft.IsSame(adj[i].a, adj[i].b) {
			ans += adj[i].distance
			uft.Unite(adj[i].a, adj[i].b)
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b; 
int d = a / b; 
int r = a % b;
double f = (double) a / b; 
  cout << d << " " << r << " "; 
  printf("%.8lf\n", f); 
  cout << endl; 
}


Measured memory_bytes: 3228
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

MOD = 10**9+7

def calc(x, y):
    return int((x + y) / 3), int((2*x - y) / 3)

def mod_cmb(n, r, mod):
    if r == 0:
        return 1
    x = 1
    y = n
    for i in range(2,r+1):
        x *= i
        x %= mod
        y *= n-i+1
        y %= mod
    return y * pow(x, mod-2, mod) % mod


def main():
    x, y = input_nums()
    if (x+y) % 3 != 0:
        print(0)
        exit(0)
    n, m = calc(x, y)
    if n < 0 or m < 0:
        print(0)
        exit(0)
    ans = mod_cmb(n, m, MOD)
    print(ans % MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
# include<iostream>
# include<vector>
#include <algorithm>
#include <math.h>
# include<map>
typedef long long ll;
using namespace std;
int main() {
    multimap<int, int, greater<int> > m;
    int n;
    scanf("%d", &n);
    int t;
    int arr[n];
    for (int i=0; i<n; i++) {
        cin >> t;
        arr[i] = t;
        m.insert(make_pair(t, i));
    }
    for (int i=0; i<n; i++) {
        if (m.begin()->second != i)
            cout << m.begin()->first << endl;
        else {
            auto it = m.begin();
            ++it;
            cout << it->first << endl;
        }
    }
}

Measured memory_bytes: 13184
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    int L, R, d;
    cin >> L >> R >> d;

    int count;
    count = 0;
    for(int i=L; i<=R; i++){
        if(i % d == 0){count += 1;}
    }
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string.h>
using namespace std;
int n,q,len;
char s[100005];
int c[100005];
void add1(int x)
{
    for(int i=x;i<=n;i+=i&(-i))
    {
        c[i]++;
    }
}
int q1(int x)
{
    int ans=0;
    for(int i=x;i>0;i-=i&(-i))
    {
        ans+=c[i];
    }
    return ans;
}
int main()
{
    scanf("%d%d",&n,&q);
    getchar();
    for(int i=1;i<=n;i++)
    {
        scanf("%c",&s[i]);
    }
    for(int i=2;i<=n;i++)
    {
        if(s[i]=='C'&&s[i-1]=='A')
            add1(i);
    }
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        int a=q1(r)-q1(l);
        //if(s[l]=='C'&&s[l-1]=='A') a--;
        printf("%d\n",a>=0?a:0);
    }
    return 0;
}


Measured memory_bytes: 1280
l = input()[::-1]

mod = 10 ** 9 + 7

pows = [1]
for i in range(10 ** 5 + 10):
    pows.append((pows[-1] * 3) % mod)

dp = 1
for i in range(len(l)):
    if l[i] == '1':
        dp = (pows[i] + dp * 2) % mod
print(dp)


Measured memory_bytes: 45460
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    println!("ABC{}",a);
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,c;int sum1,sum2,sum3,sum;
    scanf("%d%d%d",&a,&b,&c);
    sum1=abs(a-b)+abs(a-c);	
    sum2=abs(b-a)+abs(b-c);
    sum3=abs(c-a)+abs(c-b);
	sum=sum1;
	if(sum2<sum1)
		sum=sum2;
	if(sum3<sum1&&sum3<sum2)
		sum=sum3;
	printf("%d\n",sum);
		
		
}	

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

const int maxn = 1000002;
int n, a[maxn+4], b[maxn];
int cnt[maxn+4];
vector<int> p;

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> b[i];
	}
	fill(a, a+maxn, 1);
	
	for(int i = 2; i*i <= maxn; i++) {
		if(a[i] == 0) continue;
		for(int j = i*i; j <= maxn; j += i)
			a[j] = 0;
	}
	for(int i = 2; i <= maxn; i++) {
		if(a[i] == 1)
			p.push_back(i);
	}

	bool pairwise_coprime = true;
	
	for(int i = 0; i < n; i++) {
		int num = b[i];
		for(int j = 0; p[j]*p[j] <= num; j++) {
			if(num % p[j] == 0) {
				cnt[p[j]]++;
			} else continue;
			if(cnt[p[j]] > 1) {
				pairwise_coprime = false;
				break;
			}
			while(num % p[j] == 0) {
				num /= p[j];
			}
		}
		if(num > 1) cnt[num]++;
		if(cnt[num] > 1) pairwise_coprime = false;
		if(!pairwise_coprime) break;
	}
	if(pairwise_coprime) {
		cout << "pairwise coprime";
		return 0;
	}
	
	int g = 0;
	for(int i = 0; i < n; i++) {
		g = __gcd(g, b[i]);
		if(g == 1) break;
	}
	if(g == 1) {
		cout << "setwise coprime";
	} else {
		cout << "not coprime";
	}
}


Measured memory_bytes: 11884
n, q = gets.chomp.split.map(&:to_i)

edge = Hash.new{ |h, k| h[k] = [] }
(n-1).times do
  a, b = gets.chomp.split.map(&:to_i)
  edge[a] << b
  edge[b] << a
end

val = Array.new(n+1, 0)
q.times do
  p, x = gets.chomp.split.map(&:to_i)
  val[p] += x
end

done = []
queue = [[1, 0]]
while elem = queue.shift do
  node, p_val = elem
  done[node] = true
  val[node] += p_val
  edge[node].each do |nextnode|
    next if done[nextnode]
    queue.push([nextnode,val[node]])
  end
end

puts(val[1..n].join(" "))

Measured memory_bytes: 49020
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    ll ans = 0;
    for (int i = 0; i <= min(n, k); ++i) {
        for (int j = 0; j <= i; ++j) {
            vector<int> get;
            for (int l = 0; l < j; ++l) {
                get.push_back(v[l]);
            }
            for (int l = 0; l < i-j; ++l) {
                get.push_back(v[n-l-1]);
            }
            ll tmp=0;
            SORT(get);
            for (int l = 0; l < k - i; ++l) {
                if (l < (int)get.size() && get[l]>0) tmp += get[l];
            }
            for (int l = k-i; l < i; ++l) {
                tmp += get[l];
            }
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        Map<Integer, Integer> map = new HashMap<>();
        long ans = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if(map.containsKey(i-A[i])) {
                ans += map.get(i-A[i]);
            }
            int c = A[i] + i;
            int count = map.getOrDefault(c, 0) + 1;
            map.put(c, count);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 69276
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

ll f(ll b, ll n) {
  ll res = 0;
  for (ll i = n; i > 0; i /= b) {
    res += i % b;
  }
  return res;
}

int main() {
  ll n, s;
  cin >> n >> s;

  if (s > n) {
    cout << -1 << endl;
    return 0;
  }
  else if (s == n) {
    cout << n + 1 << endl;
    return 0;
  }

  int rn = sqrt(n);
  for (ll b = 2; b < rn; b++) {
    if (s == f(b, n)) {
      cout << b << endl;
      return 0;
    }
  }
  for (ll p = rn; p > 0; p--) {
    ll b = (n - s) / p + 1;
    if (b < rn) continue;
    if (s == f(b, n)) {
      cout << b << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

#define MAX 110
int N,M;
ll fw[MAX][MAX];

void compute() {

}

int main() {
  cin >> N >> M;
  rep(i,N) rep(j,N) {
    if( i == j ) fw[i][j] = 0;
    else fw[i][j] = LLONG_MAX;
  }
  vector<int> a(M), b(M), c(M);
  rep(i,M) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i], --b[i];
    fw[a[i]][b[i]] = c[i];
    fw[b[i]][a[i]] = c[i];
  }
  rep(k,N) rep(i,N) rep(j,N) {
    if( !( fw[i][k] == LLONG_MAX  || fw[k][j] == LLONG_MAX ) ) {
      fw[i][j] = min(fw[i][j],fw[i][k]+fw[k][j]);
    }
  }
  set<int> S;
  rep(i,N) {
    rep(j,N) {
      if( i == j ) continue;
      rep(k,M) {
	int s = a[k], t = b[k];
	ll u = c[k];
	if( ( fw[i][s] + u + fw[t][j] == fw[i][j] ) ||
	    ( fw[i][t] + u + fw[s][j] == fw[i][j] ) 
	    )   {
	  S.insert(k);
	}
      }
    }
  }
  cout << M - (int)S.size() << endl;
  compute();
  return 0;
}


Measured memory_bytes: 384
#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>;

int main() {
   int h1, m1, h2, m2, k;
   int time;
   cin >> h1 >> m1 >> h2 >> m2 >> k;
   time = ((h2 - h1) -1)*60;
   time += 60 - m1;
   time += m2;
   cout << time - k << endl;
   return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	int a[3], k, ans = 0;
	cin >> a[0] >> a[1] >> a[2];
	cin >> k;
	
	sort(a,a+3);
	
	ans += a[0]+a[1];
	ans += pow(2, k) * a[2];
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import accumulate
from collections import Counter

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

def main():
    cumsum = accumulate(A)
    counter = Counter(cumsum)
    yield counter[0]
    for v in counter.values():
        if v > 1:
            yield v*(v-1)//2


print(sum(main()))

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

int main(){
  int n;
  cin>>n;
  int num[n];
  for(int i=0;i<n;i++)cin>>num[i];
  for(int i=n-1;i>=0;i--){
    cout<<num[i];
    if(i) cout<<" ";
  }
  cout<<"\n";

}

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


int main(){
  long long int n,m;cin>>n>>m;

  if(abs(m-n)>1){cout<<'0'<<endl;}
  else if(abs(m-n)==1){
    long long int ans=1;
    for(int i=n;i>0;i--){
      ans*=i;
      ans=ans%1000000007;
    }
    for(int i=m;i>0;i--){
      ans*=i;
      ans=ans%1000000007;
    }
    cout<<ans<<endl;
  }
  else{
    long long int ans=1;
    for(int i=n;i>0;i--){
      ans*=i;
      ans=ans%1000000007;
    }
    for(int i=m;i>0;i--){
      ans*=i;
      ans=ans%1000000007;
    }
    cout<<2*ans%1000000007<<endl;    
  }
  
  return 0;
}


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

using namespace std;

int main(){
  string t, w;
  int count = 0;
  bool flag = false;
  cin >> w;
  while (cin >> t) {
    if (t == "END_OF_TEXT") break;
    for (int i = 0; i < t.length(); i++)
      if (isupper(t[i])) t[i] = (char)(t[i]-'A'+'a');
    if (w == t) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1188
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	long long tcount = 1, acount = 1;
	int t, a;
	for (int i = 0; i < n; i++) {
		cin >> t >> a;
		tcount = max((tcount + t - 1) / t, (acount + a - 1) / a)*t;
		acount = max((tcount + t - 1) / t, (acount + a - 1) / a)*a;
	}
	cout << tcount + acount << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string number_max(string S, string T){
  if (S.size() > T.size() || S.size() == T.size() && S > T){
    return S;
  } else {
    return T;
  }
}
int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<vector<string>> dp(N + 1, vector<string>(N + 1));
  for (int d = 0; d <= N; d++){
    for (int i = 0; i <= N - d; i++){
      int j = i + d;
      bool ok = true;
      string tmp;
      for (int k = i; k < j; k++){
        if ('0' <= S[k] && S[k] <= '9'){
          tmp += S[k];
        } else if (S[k] == '?'){
          tmp += '9';
        } else {
          ok = false;
        }
      }
      if (S[i] == '0' && d > 1){
        ok = false;
      }
      if (ok){
        dp[i][j] = tmp;
      }
      if (d >= 6){
        if (S[i + 1] == '(' || S[i + 1] == '?'){
          if (S[j - 1] == ')' || S[j - 1] == '?'){
            if (S[i] == 'L' || S[i] == '?'){
              for (int k = i + 3; k < j - 2; k++){
                if (S[k] == ',' || S[k] == '?'){
                  if (dp[k + 1][j - 1] != ""){
                    dp[i][j] = number_max(dp[i][j], dp[i + 2][k]);
                  }
                }
              }
            }
            if (S[i] == 'R' || S[i] == '?'){
              for (int k = i + 3; k < j - 2; k++){
                if (S[k] == ',' || S[k] == '?'){
                  if (dp[i + 2][k] != ""){
                    dp[i][j] = number_max(dp[i][j], dp[k + 1][j - 1]);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (dp[0][N] == ""){
    cout << "invalid" << endl;
  } else {
    cout << dp[0][N] << endl;
  }
}


Measured memory_bytes: 3288
n, m = list(map(int, input().split()))
s = {e for e in list(map(int, input().split()))}
d = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
dp = [-1 for i in range(n+1)]
dp[0] = 0
for i in range(1, n+1):
  for e in s:
    if i-d[e]>=0 and dp[i-d[e]]>=0:
      dp[i] = max(dp[i], dp[i-d[e]]+1)

ans = ""
j = n
for i in range(dp[n]):
  for e in sorted(s, reverse=True):
    if j-d[e]>=0 and dp[j]-1==dp[j-d[e]]:
      ans += str(e)
      j -= d[e]
      break
print(ans)

Measured memory_bytes: 3348
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//よくわかんないけど通った？

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


	int N, K;
	scanf("%d", &N);
	scanf("%d", &K);
	int H[302] = {};
	rep1(i, N) scanf("%d", H + i);
	ll hutuu = 0;
	rep(i, N + 1) {
		if (H[i + 1] > H[i]) hutuu += H[i + 1] - H[i];
	}

	if (N == K) {
		printf("0");
		return 0;
	}

	ll dp[302][301] = {};
	rep(i, N + 1) {
		auto dpi = dp[i];
		ll tmp1 = max(0, H[i + 1] - H[i]);
		ll tmp2 = max(0, H[i] - H[i + 1]);
		ll tmp3 = min(tmp1, tmp2);
		int mae = H[i + 1];
		ll maetmp = tmp3;
		for (int j = i + 2; j <= min(N + 1, K + i + 1); j++) {
			if (mae < H[j]) tmp1 += H[j] - mae;
			if (mae > H[j]) tmp2 += mae - H[j];
			tmp3 = min(tmp1, tmp2);
			if (maetmp < tmp3) {
				int k = j - i - 1;
				auto dpj = dp[j] + k;
				rep(p, K - k + 1) if (dpj[p] < dpi[p] + tmp3) dpj[p] = dpi[p] + tmp3;
			}
			mae = H[j];
			maetmp = tmp3;
		}
		auto dpi2 = dp[i + 1];
		rep(p, K + 1) chmax(dpi2[p], dpi[p]);
	}
	printf("%lld", hutuu - dp[N + 1][K]);


	Would you please return 0;
}

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

int main(){
  string s;
  
  cin >> s;
  
  int sum = 700;
  for(int i = 0; i < 3; i++){
    if(s[i] == 'o'){
      sum += 100;
    }
  }
  
  cout << sum << endl;
  
  return 0;
}

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

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

fn main() {
    let r: f32 = read();

    println!("{}", r * std::f32::consts::PI * 2.0);
}


Measured memory_bytes: 2188
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
using namespace std;

int a[100005];
int flag[100005]; 

int main(){
	int n,sum = 1,ans;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
	int m = a[1];
	flag[1] = 0;
	flag[m] = 1;
	while(1){
		if(flag[2] == 1){
			printf("%d",sum);
			return 0;
		}
		if(flag[m] == 0){
			printf("-1");
			return 0;
		}
		ans = a[m];
		flag[m] = 0;
		flag[ans] = 1;
		m = ans;
		sum++;
		if(sum > 100005) break;
	}
	printf("-1");
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)


int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	REP(i, n - 1) {
		ll z, x;
		cin >> z >> x;
		ll n = max((a + z - 1) / z, (b + x - 1) / x);
		a = z * n;
		b = x * n;
	}
	cout << a + b << endl;
}	


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> p;
  int a;
  rep(i,n) {
    cin >> a;
    p.push_back(a);
  }
  sor(p);
  ll ans = 0;
  rep(i,k) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    ll ans = 0, amin = INF, cnt_minus = 0;
    rep(i, 0, n) {
        if (a[i] < 0) cnt_minus++;
        chmin(amin, abs(a[i]));
        ans += abs(a[i]);
    }
    if (cnt_minus % 2 == 0) cout << ans << endl;
    else cout << ans - 2 * amin << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000
#define ll long long int

using namespace std;

int main(){
 char c; cin>>c;
 if(c=='A') cout<<'T'<<endl;
 if(c=='T') cout<<'A'<<endl;
 if(c=='G') cout<<'C'<<endl;
 if(c=='C') cout<<'G'<<endl;


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define resett(arr,val,N) for(int ii=0;ii<(N);ii++) arr[ii]=val;
#define PI 2*acos(0.0)
int n,x,ar[100007];

int main(){
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) ;
    while(cin>>n){

        for(int i=0;i<n;i++){
            scanf("%d",ar+i);
        }

        LL low=0,high=1e18+1;
        LL ans1,ans2;

        while(high-low>1){
          LL mid=(low+high)>>1;
          LL temp=mid;
          int i;

          for(i=0;i<n;i++){
            temp=temp-temp%ar[i];
            if(temp<2)
                goto jump;
          }

          if(temp>=2){
            high=mid;
          }
          else{
           jump:;
           low=mid;
          }

        }

        ans1=high;
//        printf("%lld ",high);
        low=0,high=1e18+1;

        while(high-low>1){
          LL mid=(low+high)>>1;
          LL temp=mid;
          int i;

          for(i=0;i<n;i++){
            temp=temp-temp%ar[i];
            if(temp<2)
                goto jump2;
          }

          if(temp<=2){
            jump2:;
            low=mid;
          }
          else{
           high=mid;
          }

        }

        if(ans1>low)
            printf("-1\n");
        else
           printf("%lld %lld\n",ans1,low);



    }

    return 0;
}





Measured memory_bytes: 640
# https://atcoder.jp/contests/abc058/tasks/arc071_b
# 定式化してみると、独立に計算できる部分と、
# 前処理で累積和を求めておけばループ内でO(1)に減る部分と、
# 愚直に計算する部分に減る

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


class ModInt:
    def __init__(self, x, MOD=10 ** 9 + 7):
        '''
        pypyじゃないと地獄みたいな遅さなので注意
        '''
        self.mod = MOD
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x, self.mod)
        else:
            return ModInt(self.x + other, self.mod)

    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x, self.mod)
        else:
            return ModInt(self.x - other, self.mod)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x, self.mod)
        else:
            return ModInt(self.x * other, self.mod)

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(self.x * pow(other, self.mod - 2, self.mod), self.mod)

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, self.mod), self.mod)
        else:
            return ModInt(pow(self.x, other, self.mod), self.mod)

    __radd__ = __add__

    def __rsub__(self, other):  # 演算の順序が逆
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.mod)
        else:
            return ModInt(other - self.x, self.mod)

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x * pow(self.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(other * pow(self.x, self.mod - 2, self.mod), self.mod)

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, self.mod), self.mod)
        else:
            return ModInt(pow(other, self.x, self.mod), self.mod)


def read_ints():
    return list(map(int, read().split()))


from itertools import accumulate

n, m = read_ints()
X = read_ints()
Y = read_ints()
MOD = 10 ** 9 + 7


def mul_term(X: list, n):
    S = list(accumulate(reversed(X)))
    S.reverse()
    ret = ModInt(0)
    for i in range(n - 1):
        ret += S[i + 1] - (n - i - 1) * X[i]
    return ret


# print(mul_term(X, n), mul_term(Y, m))
print(mul_term(X, n) * mul_term(Y, m))


Measured memory_bytes: 79060
dic={}
max1=0
ans=[]
n=int(input())
for i in range(n):
    word=input()
    if word in dic:
        dic[word]+=1
    else:
        dic[word]=1

for k in dic.values():
    if k>max1:
        max1=k

for n,b in dic.items():
    if b==max1:
        ans.append(n)


for i in sorted(ans):
    print(i)

Measured memory_bytes: 32988
#include<iostream>
#include<queue>
#include<tuple>
using namespace std;

char T[22]="0123456789^>v<?_|.+-@";
int x[25][25],h,w;char c;
int dp[25][25][16][4];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
int ab,a1,a2,a3,a4,X;
tuple<int,int,int,int>tup;
queue<tuple<int,int,int,int>>Q;

int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>c;
			for(int k=0;k<21;k++){
				if(T[k]==c){
					x[i][j]=k;
				}
			}
		}
	}
	dp[0][0][0][1]=1;
	Q.push(make_tuple(0,0,0,1));
	while(!Q.empty()){
		tup=Q.front();
		Q.pop();
		a1=get<0>(tup);
		a2=get<1>(tup);
		a3=get<2>(tup);
		a4=get<3>(tup);
		X=x[a1][a2];
		if(X>=0 && X<=9){
			a3=X;
			if(dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]==0){
				dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]=1;
				Q.push(make_tuple((a1+dy[a4]+h)%h,(a2+dx[a4]+w)%w,a3,a4));
			}
		}
		if(X>=10 && X<=13){
			a4=X-10;
			if(dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]==0){
				dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]=1;
				Q.push(make_tuple((a1+dy[a4]+h)%h,(a2+dx[a4]+w)%w,a3,a4));
			}
		}
		if(X==14){
			for(int n=0;n<4;n++){
				a4=n;
				if(dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]==0){
					dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]=1;
					Q.push(make_tuple((a1+dy[a4]+h)%h,(a2+dx[a4]+w)%w,a3,a4));
				}
			}
		}
		if(X==15){
			if(a3==0){
				a4=1;
			}
			else{
				a4=3;
			}
			if(dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]==0){
				dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]=1;
				Q.push(make_tuple((a1+dy[a4]+h)%h,(a2+dx[a4]+w)%w,a3,a4));
			}
		}
		if(X==16){
			if(a3==0){
				a4=2;
			}
			else{
				a4=0;
			}
			if(dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]==0){
				dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]=1;
				Q.push(make_tuple((a1+dy[a4]+h)%h,(a2+dx[a4]+w)%w,a3,a4));
			}
		}
		if(X==17){
			if(dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]==0){
				dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]=1;
				Q.push(make_tuple((a1+dy[a4]+h)%h,(a2+dx[a4]+w)%w,a3,a4));
			}
		}
		ab=1;
		if(X==18 || X==19){
			if(X==19){ab=-1;}
			a3=(a3+ab+16)%16;
			if(dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]==0){
				dp[(a1+dy[a4]+h)%h][(a2+dx[a4]+w)%w][a3][a4]=1;
				Q.push(make_tuple((a1+dy[a4]+h)%h,(a2+dx[a4]+w)%w,a3,a4));
			}
		}
		if(X==20){
			cout<<"YES"<<endl;
			goto E;
		}
	}
	cout<<"NO"<<endl;
E:;
	return 0;
}

Measured memory_bytes: 3264
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int[] A = new int[N + 10];
    A[0] = 0;
    A[N + 1] = 0;
    long sum = 0;
    long ans = 0;
    for (int i = 1; i <= N; i++){
      A[i] = scanner.nextInt();
    }
    for (int i = 0; i <= N; i++){
      sum += Math.abs(A[i+1] - A[i]);
    }
    for (int i = 0; i < N; i++){
      ans = sum + Math.abs(A[i + 2] - A[i]) - Math.abs(A[i + 2] - A[i + 1])
      - Math.abs(A[i + 1] - A[i]);
      System.out.println(ans);
      ans = 0;
    }
  }
}


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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main(){
    int temp;
    cin >> temp;
    if(temp>=30) cout << "Yes";
    else cout << "No";
    
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff(i,n) for(i=0;i<n;i++)
#define pb push_back
ll bg =  998244353;
ll fac[300000];
ll power(ll x,ll y)
{
    if(y==0)
	    return 1;
	ll d = power(x,y/2)%bg;
	ll f = (d*d)%bg;
	if(y%2==0)
	  return f;
	else
	  return (f*x)%bg;	 	
}
ll modinv(ll m)
{
	return power(m,bg-2);	
}
ll ncr(ll n,ll r)
{
	ll s1 = fac[n],s2 = fac[r],s3 = fac[n-r];
	ll d1 = (s1*modinv(((s2*s3)%bg)))%bg;
	return d1;
}
int main()
{
	fac[0]=1;
	for(ll j=1;j<300000;j++)
	  fac[j] = (j*fac[j-1])%bg;
	ll t;
	t=1;
	while(t--)
	{
		ll i,n,m,k;
		cin>>n>>m>>k;
		ll ans = 0 ;
		for(i=0;i<=k;i++)
		{
			ans += (power(m-1,n-i-1)*ncr(n-1,i))%bg;
			ans %= bg;
		}
		ans = (ans*m)%bg;
		if(m==1 && k+1 == n)
		  ans = 1;
		else if(m==1 && k+1!= n)
		  ans = 0;  
		cout<<ans;
	}
	 return 0;
}

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

using namespace std;

int main()
{
    int n,m;
    int sum=0,ans = 0;
    cin >> n >> m;
    vector<int> a(n);

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

    sort(a.begin(), a.end());

    if(a[n-m]<(double)sum/(4*m)){
        ans = 1;
    }



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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(x,n) for(int i=x;i<n;i++)
#define REP(y,n) for(int j=y;j<n;j++)
#define vi vector<int>
#define vvi vector<vector<int>>
signed main(){
  string W,T;
  int c=0;
  cin>>W;
  while(true){
    cin>>T;
    if(T=="END_OF_TEXT")break;
    rep(0,T.size()){
      if(65<=T[i]&&T[i]<=90)T[i]+=32;
    }
    if(W==T)c++;
  }
  cout<<c<<endl;
}



Measured memory_bytes: 3156
#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>;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--, y--;

  vector<int> freq(n);
  rep(i, n) rep(j, n) {
    if (i < j) {
      int dist =
          min(j - i, min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)));
      freq[dist]++;
    }
  }
  for (int i = 1; i < n; i++) cout << freq[i] << endl;

  return 0;
}

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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	int b[n];
	int c[n-1];
	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-1); i++)
		cin>>c[i];
	int w = 0;
	int ost = -1;
	for(int i=0; i<n; i++) {
		w+=b[a[i]-1];
		if(a[i] == (ost+1))
			w+=c[a[i]-2];
		ost = a[i];
	}
	cout<<w;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

N,M=MAP()
nodes=[[] for i in range(N)]
for i in range(M):
    s,t=MAP()
    nodes[s].append(t)
    nodes[t].append(s)

group=[-1]*N
def rec(u, root):
    if group[u]!=-1:
        return
    group[u]=root
    for v in nodes[u]:
        rec(v, root)

for i in range(N):
    rec(i, i)

Q=INT()
for _ in range(Q):
    s,t=MAP()
    if group[s]==group[t]:
        print('yes')
    else:
        print('no')



Measured memory_bytes: 126976
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B, C = sorted(list(map(int, input().split())))

print("YES" if A == B == 5 and C == 7 else "NO")

Measured memory_bytes: 3572
def solve():
    N = int(input())
    Ss = input().rstrip()

    dp = [[0]*(N+1) for _ in range(N+1)]
    for i in reversed(range(N)):
        for j in reversed(range(N)):
            if Ss[i] == Ss[j]:
                dp[i][j] = dp[i+1][j+1] + 1
            else:
                dp[i][j] = 0

    ans = 0
    for i in range(N):
        for j in range(N):
            L = j-i if j-i <= dp[i][j] else dp[i][j]
            if L > ans:
                ans = L

    print(ans)


solve()


Measured memory_bytes: 230408
n=int(input())

print(0)
lowg = input()
print(n-1)
highg = input()

if lowg=="Vacant":
  quit()
if highg=="Vacant":
  quit()

low =0 
high=n-1
mid = (n-1)//2
for i in range(20):
  print(mid)
  temp=input()
  if temp=="Vacant":
    quit()
  if (mid-low)%2==0:
    if lowg==temp:
      lowg=temp
      low=mid
    else:
      high=mid
  else:
    if lowg==temp:
      high=mid
    else:
      lowg=temp
      low=mid
  #print("high " + str(high) + " low "+str(low))
  mid=(high+low)//2

Measured memory_bytes: 74776
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    E = [[] for _ in range(N)]
    for _ in range(M):
        l, r, d = map(int, input().split())
        E[l-1].append((r - 1, d))
        E[r-1].append((l - 1, -d))
    Pos = [10 ** 20] * N
    q = deque()
    flag = True
    for i in range(N):
        if Pos[i] == 10 ** 20:
            q.append((i, 0))
            minX, maxX = 0, 0
            while q:
                x, p = q.popleft()
                if Pos[x] == 10 ** 20:
                    minX = min(minX, p)
                    maxX = max(maxX, p)
                    Pos[x] = p
                    for ne, d in E[x]: q.append((ne, p + d))
                elif Pos[x] == p: continue
                else:
                    flag = False
                    break
            else:
                if maxX - minX <= 10 ** 9: continue
                else: flag = False
            if not flag:
                print("No")
                break
    else: print("Yes")
    #print(Pos)
            
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 86304
using System;
class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            string[] data = Console.ReadLine().Split(' ');
            int H = int.Parse(data[0]);
            int W = int.Parse(data[1]);
            if (H == 0 && W == 0)
            {
                return;
            }

            string line = "";
            string line2 = "";
            for (int i = 0,count = W -1; i < W; i++)
            {
                line = line + "#";
                if (i == 0 || i == count)
                {
                    line2 = line2 + "#";
                }
                else
                {
                    line2 = line2 + ".";
                }
            }

            for (int i = 0,count = H - 1; i < H; i++)
            {
                if (i == 0 || i == count)
                {
                    Console.WriteLine(line);
                }
                else
                {
                    Console.WriteLine(line2);
                }
            }
            Console.WriteLine();
        }
    }
}

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

int main() {
 string s ;
 cin >>s;
 string ans = "Yes";
 sort(s.begin(),s.end());
 if (s.at(0) != s.at(1)){
   ans = "No";
 }
  if (s.at(2) != s.at(3)){
   ans = "No";
 }
   if (s.at(0) == s.at(3)){
   ans = "No";
 }
  cout <<ans ;
}


Measured memory_bytes: 256