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

using namespace std;

#define N 1600000
#define ls (x<<1)
#define rs (x<<1|1)

int n,p,t1,t2,a[N],seg[N],fst[N],mn[N],pos[N],c[N];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d",a+i);
		if ((a[i]&1)!=(i&1)){puts("No"); return 0;}
		pos[a[i]]=i;
	}
	for (int i=1;i<=n-2;++i)
		if (a[i]!=i&&a[i+1]!=i+1&&a[i+2]!=i+2){puts("No"); return 0;}
	p=t1=t2=0;
	for (int i=1;i<=n;i+=2) c[++p]=a[i];
	for (int i=1;i<=p;++i)
		if (c[i]>t2) t2=c[i];
		else{
			if (c[i]>t1) t1=c[i];
			else{puts("No"); return 0;}
		}
	p=t1=t2=0;
	for (int i=2;i<=n;i+=2) c[++p]=a[i];
	for (int i=1;i<=p;++i)
		if (c[i]>t2) t2=c[i];
		else{
			if (c[i]>t1) t1=c[i];
			else{puts("No"); return 0;}
		}
	puts("Yes");
	
	return 0;
}
			

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)


void solve(){
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long h[100009];
long long sz[100009];
long long f[100009];
long long D[100009];
vector<long long> v[100009];
map<long long,long long> M;
void dfs(long long x, long long de){
    f[x] = 1;
    h[x] = de;
    for(long long i = 0; i < v[x].size(); i++){
        if(!f[v[x][i]]) dfs(v[x][i], de + 1);
    }
}
main(){
    long long n;
    cin >> n;
    for(long long i = 1; i <= n; i++){
        cin >> D[i];
        M[D[i]] = i;
        sz[i] = 1;
    }
    long long t = D[1];
    sort(D + 1, D + n + 1);
    for(long long i= n; i >= 2; i--){
        long long k = M[D[i]];
        long long diff = n - 2 * sz[k];
        if(diff <= 0 || !M[D[i] - diff]){
            cout << -1 << endl;
            return 0;
        }
 
        v[k].push_back(M[D[i]-diff]);
        v[M[D[i] - diff]].push_back(k);
        sz[M[D[i] - diff]] += sz[k];
 
    }
 
    dfs(1,0);
    long long S = 0;
    for(long long i = 1; i <= n; i++){
        S += h[i];
    }
    if(S == t){
        for(long long i = 1; i <= n; i++){
            for(long long j = 0; j < v[i].size(); j++){
                if(i < v[i][j]){
                    cout<<i<<" "<<v[i][j]<<endl;
                }
            }
        }
    }
    else{
        cout<< -1 << endl;
        return 0;
    }
}

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

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

    map<char, int> s_map;
    map<char, int> t_map;
    ll size = S.size();
    // cout << size << endl;
    for(ll i=0; i<size; ++i) {
        if(s_map.find(S[i])==s_map.end()) {
            s_map[S[i]] = 1;
        }
        else s_map[S[i]] += 1;
        if(t_map.find(T[i])==t_map.end()) {
            t_map[T[i]] = 1;
        }
        else t_map[T[i]] += 1;
    }

    vector<int> s_vec;
    vector<int> t_vec;
    for(auto kv : s_map) s_vec.push_back(kv.second);
    sort(s_vec.begin(), s_vec.end());
    for(auto kv : t_map) t_vec.push_back(kv.second);
    sort(t_vec.begin(), t_vec.end());

    bool flag = true;
    if(s_vec.size()==t_vec.size()) {
        for(int i=0; i<s_vec.size(); ++i) {
            if(s_vec[i]!=t_vec[i]) flag = false;
        }
    }
    else flag = false;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

constexpr int N = 5000;
constexpr int K = 5000;

bool Solve(const std::vector<int> &arr, const int skip_index, const int k)
{
    std::vector<bool> current(k + 1), next(k + 1);
    current[0] = true;
    for (int i = 0; i < arr.size(); ++i)
    {
        if (i == skip_index)
        {
            continue;
        }

        const int a = arr[i];
        for (int j = 0; j <= k; ++j)
        {
            // 使わない場合
            next[j] = next[j] || current[j];
            // 使う場合
            next[std::min(k, j + a)] = next[std::min(k, j + a)] || current[j];
        }

        current.swap(next);
    }

    const int a = arr[skip_index];
    for (int i = std::max(k - a, 0); i < k; ++i)
    {
        if (current[i])
        {
            // 必要
            return true;
        }
    }
    // 不要
    return false;
}

int main()
{
    int n, k;
    std::cin >> n >> k;
    std::vector<int> arr(n);
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        std::cin >> tmp;
        arr[i] = tmp;
    }
    std::sort(arr.begin(), arr.end());

    int first = 0;
    int last = n;
    do
    {
        int i = (first + last) / 2;
        if (Solve(arr, i, k))
        {
            // 必要なので[first, i)の範囲
            last = i;
        }
        else
        {
            // 不要なので[i + 1, last)の範囲
            first = i + 1;
        }
    } while (first != last);
    std::cout << last << std::endl;
    return 0;
}


Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N):

    for h in range(1, 3501):
        for n in range(1, 3501):
            a = N*h*n
            b = 4*h*n - N*h - N*n
            if b != 0 and a % b == 0 and a // b > 0:
                z = a // b
                return "%d %d %d" % (h, n, z)

def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 60780
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main(){
    long long H, W;
    cin >> H >> W;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;
    vector<vector<char>> S(H, vector<char>(W));
    for(int i =0 ; i < H; i++){
        for(int j = 0; j < W; j++) cin >> S[i][j];
    }
    vector<vector<int>> syu(H, vector<int> (W, -1));
    int cnt = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '.'){
                queue<P> q;
                q.push(P(i, j));
                syu[i][j] = cnt;
                S[i][j] = '#';
                while(!q.empty()){
                    P v = q.front();
                    q.pop();
                    int x = v.first, y = v.second;
                    for(int k = 0; k < 4; k++){
                        int nx = x + dx[k], ny = y + dy[k];
                        if(0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] == '.'){
                            q.push(P(nx, ny));
                            syu[nx][ny] = syu[x][y];
                            S[nx][ny] = '#';
                        }
                    }
                }
                cnt++;
            }
        }
    }
    vector<int> G[cnt];
    int ind = 0, goal =  0;
    for(int i = 0; i< H; i++){
        for(int j = 0; j < W; j++){
            if(i == ch && j == cw){
                ind = syu[i][j];
            }
            if(i == dh && j == dw){
                goal = syu[i][j];
            }
            if(syu[i][j] != -1){
                for(int k = -2; k <= 2; k++){
                    for(int l = -2; l<=2; l++){
                        int x = i + k, y = j + l;
                        if(0 <= x && x < H && 0<= y && y < W && syu[x][y] != -1 && syu[x][y] != syu[i][j]){
                            G[syu[i][j]].push_back(syu[x][y]);
                            G[syu[x][y]].push_back(syu[i][j]);
                        } 
                    }
                }
            }
        }
    }
    queue<P> q;
    q.push(P(ind, 0));
    vector<int> used(cnt, -1);
    used[ind] = 0;
    while(!q.empty()){
        P s = q.front();
        q.pop();
        for(int k: G[s.first]){
            if(used[k] == -1){
                q.push(P(k, s.second + 1));
                used[k] = s.second + 1;
            }
        }
    }
    cout << used[goal] << endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
        }
        int s1 = 0;
        int s2 = Arrays.stream(w).sum();
        int min = Integer.MAX_VALUE;
        min = Math.min(min, Math.abs(s1 - s2));
        for (int i = 0; i < n; i++) {
            s1 += w[i];
            s2 -= w[i];
            min = Math.min(min, Math.abs(s1 - s2));
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 27988
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let xls = Array.init (n + 1) @@ function
    | 0 -> (-100000000, 0)
    | _ -> Scanf.scanf "%d %d\n" @@ fun x l -> x, l in
  Array.sort (fun (x, l) (x', l') -> compare (x + l) (x' + l')) xls;
  let dp = Array.make (n + 1) 0 in
  for i = 1 to n do
    dp.(i) <- max (dp.(i - 1)) @@
      1 + dp.(upper_bound 0 i (fun j ->
        fst (xls.(j)) + snd (xls.(j)) <= fst (xls.(i)) - snd (xls.(i))))
  done;
  Printf.printf "%d\n" dp.(n)

Measured memory_bytes: 7552
#include<stdio.h>
  
int main(){
  int N, M, K, A, Fm[30] = {0}, i, j, ans = 0;
  
  scanf("%d %d", &N, &M);
  
  for (i = 0; i < N; i++){
    scanf("%d", &K);
    for (j = 0; j < K; j++){
      scanf("%d", &A);
      Fm[A - 1]++;
    }
  }
  for (i = 0; i < M; i++){
    if(Fm[i] == N){
      ans++;
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
n = int(input())
s = [input() for _ in range(n)]
l = "abcdefghijklmnopqrstuvwxyz"
ans = ""
for i in l:
    tnp = 100
    for j in range(n):
        tnp = min(tnp,s[j].count(i))
    ans += i*tnp
print(ans)
    

Measured memory_bytes: 9028
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;


int main(void){
        long long a,b;
        long long n;
        cin >> n;
        long long ans = 0;
        for(a=1;a<n;a++){
            ans += ((n-1)/a);
        } 
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a,b,c,n;
    cin>>a>>b>>c;
    n=a*c;
    if(n<=b)
    {
        cout<<c;
    }
    else if(n>=b)
    {
        int d;
        d=b/a;
        cout<<d;
    }



    return 0;
}


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

int bs(long long A, int x){
	int b = -(A+1e3);
	int e = 1e3;
	while(e-b > 1){
		int mid = (b+e)/2;
		int a = (A+mid);
		if(pow(a,5) - pow(mid, 5) > x) e=mid;
		else if(pow(a,5) - pow(mid, 5) < x)b=mid;
		else if(pow(a,5) - pow(mid, 5) == x)return mid;
	}
	return b;
}

int main() {
	int x; cin>>x;
	for(long long i=1; i*i<=x; i++){
		if(x%i==0){
			int b = bs(i , x);
			int a = i+b;
			if(pow(a,5) - pow(b,5) == x){
				cout<<a<<" "<<b<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 4052
package main

import (
        "fmt"
        "sort"
        "sync"
)

func main() {
        var n int
        var c int64
        fmt.Scan(&n, &c)
        s := make([]sushi, n)
        for i := range s {
                fmt.Scan(&s[i].x, &s[i].v)
        }
        sort.Sort(counter(s))
        s = append([]sushi{sushi{0, 0}}, s...)
        s = append(s, sushi{c, 0})

        var eatr, eatl, maxr, maxr2 []int64
        wg := &sync.WaitGroup{}
        wg.Add(2)
        go func() {
                eatr = make([]int64, len(s))
                eatr[0] = s[0].v
                for i := 1; i < len(s); i++ {
                        eatr[i] = eatr[i-1] + s[i].v
                }

                wg.Add(2)
                go func() {
                        maxr = make([]int64, len(s))
                        maxr[0] = eatr[0] - s[0].x
                        for i := 1; i < len(s); i++ {
                                maxr[i] = eatr[i] - s[i].x
                                if maxr[i-1] > maxr[i] {
                                        maxr[i] = maxr[i-1]
                                }
                        }
                        wg.Done()
                }()
                go func() {
                        maxr2 = make([]int64, len(s))
                        maxr2[0] = eatr[0] - 2*s[0].x
                        for i := 1; i < len(s); i++ {
                                maxr2[i] = eatr[i] - 2*s[i].x
                                if maxr2[i-1] > maxr2[i] {
                                        maxr2[i] = maxr2[i-1]
                                }
                        }
                        wg.Done()
                }()
                wg.Done()
        }()
        go func() {
                eatl = make([]int64, len(s))
                eatl[len(s)-1] = s[len(s)-1].v
                for i := len(s) - 2; i >= 0; i-- {
                        eatl[i] = eatl[i+1] + s[i].v
                }
                wg.Done()
        }()
        wg.Wait()

        var max int64
        for i := 1; i < len(s); i++ {
                call := eatl[i] - c + s[i].x
                cal := maxr2[i-1] + call
                if cal > max {
                        max = cal
                }
                call = eatl[i] - 2*c + 2*s[i].x
                cal = maxr[i-1] + call
                if cal > max {
                        max = cal
                }
        }
        fmt.Println(max)
}

type sushi struct {
        x, v int64
}

type counter []sushi

func (c counter) Len() int           { return len(c) }
func (c counter) Less(i, j int) bool { return c[i].x < c[j].x }
func (c counter) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>


int main()

{
	long double r;
	cin>>r;
	long double k = 3.1415926;
	k = (long double)2*r*k;
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            for (int k = 0; k <= 9; k++) {
                int p1 = -1, p2 = -1, p3 = -1;
                for (int l = 0; l < n; l++) {
                    if (s[l] - '0' == i) {
                        p1 = l;
                        break;
                    }
                }
                if (p1 == -1) {
                    // cout << i << j << k << " " << 1 << endl;
                    continue;
                }
                if (n - 1 - p1 <= 1) {
                    continue;
                }
                for (int l = n - 1; l >= p1 + 1; l--) {
                    if (s[l] - '0' == k) {
                        p3 = l;
                        break;
                    }
                }
                if (p3 == -1) {
                    // cout << i << j << k << " " << 2 << endl;
                    continue;
                }
                if (p3 - p1 <= 1) {
                    continue;
                }
                for (int l = p1 + 1; l <= p3 - 1; l++) {
                    if (s[l] - '0' == j) {
                        p2 = l;
                        break;
                    }
                }
                if (p2 == -1) {
                    // cout << i << j << k << " " << 3 << endl;
                    continue;
                }
                ans++;
                // cout << i << j << k << endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,r,a[10],w[300][300];
int main()
{
    scanf("%d%d%d",&n,&m,&r);
    for(int i=0;i<r;i++)scanf("%d",a+i);
    sort(a,a+r);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)w[i][j]=1<<25;
    while(m--)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        w[x][y]=w[y][x]=z;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)w[i][j]=min(w[i][j],w[i][k]+w[k][j]);
    int ans=1<<30;
    do
    {
        int buf=0;
        for(int i=1;i<r;i++)buf+=w[a[i-1]][a[i]];
        ans=min(ans,buf);
    }while(next_permutation(a,a+r));
    printf("%d\n",ans);
}

Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        b: chars,
    }

    let ans = match b[0] {
        'A' => 'T',
        'T' => 'A',
        'C' => 'G',
        'G' => 'C',
        _ => unreachable!(),
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define eb emplace_back
using namespace std;
string s;
ll ans=1,cnt=0,n;
const int mod=1e9+7;
int main(){
    cin>>n>>s;
    for(auto x:s){
        if(x=='W'&&(cnt&1)){
            cnt++;
        }else if(x=='B'&&!(cnt&1)){
            cnt++;
        }else{
            (ans*=cnt)%=mod;
            cnt--;
        }
    }
    for(ll i=1;i<=n;i++){
        (ans*=i)%=mod;
    }
    if(cnt){
        ans=0;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    if (2 * C >= A + B) {
        cout << X * A + Y * B << endl;
        return 0;
    }
    
    int Z = max(X, Y);
    int tmp = 2 * C * Z;
    int ans = tmp;
    int X_count = Z;
    int Y_count = Z;
    for (int i = Z - 1; i >= 0; i--) {
        tmp -= 2 * C;
        X_count -= 1;
        Y_count -= 1;
        if (X_count < X) {
            X_count += 1;
            tmp += A;
        }
        if (Y_count < Y) {
            Y_count += 1;
            tmp += B;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
N, Y = map(int,input().split())
A=-1
B=-1
C=-1

for i in range(N+1):
    for j in range(N+1-i):
        if (10000*i + 5000*j + 1000*(N-i-j)) == Y:
            A,B,C=i,j,(N-i-j)
print(A,B,C)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  bool find = false;
  cin >> s;
  for (int i = 0; i < 3; i++)
    if (s[i] == '7')
      find = true;
  cout << (find? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
int N=1e5+9;
ll power(ll x,ll y){
    ll prod=1;
    while(y){
        if(y&1){
            prod=(prod*x)%mod;
        }
        x=(x*x)%mod;
        y/=2;
    }
    return prod;
}
ll modinverse(ll x){
    return power(x,mod-2);
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int n,k;
	cin>>n>>k;
	ll a[n+1];
	a[0]=0;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=k+1,j=1;i<=n;i++,j++){
	    if(a[i]>a[j]) cout<<"Yes\n";
	    else cout<<"No\n";
	}
	return 0; 
	
}


Measured memory_bytes: 5176
import os, sys, re, math

L,R = map(int, input().split(' '))

base = 2019
temp = L
mod = []
while (temp <= R) and (temp-L <= base):
    mod.append(temp % base)
    temp += 1

mod = list(set(mod))

ret = base
for i in range(len(mod)-1):
    for j in range(i+1,len(mod)):
        ret = min(ret, (mod[i]*mod[j])%base)

print(ret)


Measured memory_bytes: 3444
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    S = str(input())
    return (S,)


def solve(S):
    before_dict = collections.defaultdict(list)
    before_ind_dict = collections.defaultdict(int)
    for ind, char in enumerate(S):
        if char not in before_ind_dict:
            before_ind_dict[char] = ind
            before_dict[char].append(ind)
        else:
            before = before_ind_dict[char]
            before_dict[char].append(ind - before - 1)
            before_ind_dict[char] = ind

    len_s = len(S)
    for key, val in before_ind_dict.items():
        before_dict[key].append(len_s - val - 1)

    l_max = [max(v) for v in before_dict.values()]
    ans = min(l_max)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


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

struct Card {
    char suit;
    int value;
};

void bubble(vector<struct Card> &A, int N);
void selection(vector<struct Card> &A, int N);
void print(vector<struct Card> A, int N);
int isStable(vector<struct Card> C1, vector<struct Card> C2, int N);

int main() {
    int N;
    cin >> N;
    
    vector<Card> C1(N), C2(N);
    for (int i=0; i<N; i++) {
        cin >> C1.at(i).suit >> C1.at(i).value;
    }
    for (int i=0; i<N; i++) {
        C2.at(i) = C1.at(i);
    }
    
    
    bubble(C1, N);
    selection(C2, N);
    
    print(C1, N);
    cout << "Stable" << endl;
    
    print(C2, N);
    if (isStable(C1, C2, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    
}

void bubble (vector<struct Card> &A, int N) {
    for (int i=0; i<N; i++) {
        for (int j=N-1; j>=i+1; j--) {
            if (A.at(j-1).value > A.at(j).value) {
                Card tmp = A.at(j);
                A.at(j) = A.at(j-1);
                A.at(j-1) = tmp;
            }
        }
    }
}

void selection (vector<struct Card> &A, int N) {
    for (int i=0; i<N; i++) {
        int minj = i;
        for (int j=i; j<N; j++) {
            if ( A.at(j).value < A.at(minj).value ) {
                minj = j;
            }
        }
        Card tmp = A.at(i);
        A.at(i) = A.at(minj);
        A.at(minj) = tmp;
    }
}

void print(vector<struct Card> A, int N) {
    for (int i=0; i<N; i++) {
        cout << A.at(i).suit << A.at(i).value;
        if (i == N-1) {
            cout << endl;
        } else {
            cout << ' ';
        }
    }
}

int isStable(vector<struct Card> C1, vector<struct Card> C2, int N) {
    for(int i=0; i<N; i++) {
        if (C1.at(i).suit != C2.at(i).suit) {
            return 0;
        }
    }
    return 1;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

void max_search(int pos, const int last, const vll& a, const vll& b, const vll& c, vll& dpA, vll& dpB, vll& dpC){
  if(pos>=last) return;
  if(dpA[pos]>=0 && dpB[pos]>=0 && dpC[pos]>=0) return;
  max_search(pos+1, last, a, b, c, dpA, dpB, dpC);
  dpA[pos] = a[pos] + max(dpB[pos+1], dpC[pos+1]);
  dpB[pos] = b[pos] + max(dpC[pos+1], dpA[pos+1]);
  dpC[pos] = c[pos] + max(dpA[pos+1], dpB[pos+1]);
  return;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vector<ll> a(N), b(N), c(N);
  rep(i, 0, N){
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<ll> dpA(N, -1), dpB(N, -1), dpC(N, -1);

  dpA[N-1] = a[N-1];
  dpB[N-1] = b[N-1];
  dpC[N-1] = c[N-1];

  max_search(0, N-1, a, b, c, dpA, dpB, dpC);

  ll ans = max(dpA[0], max(dpB[0], dpC[0]));

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX =2000007;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
     signed main(){
     COMinit();
int k;string s;
cin>>k>>s;
int ans=0;
for(int i=0;i<=k;i++){
   ans=(ans+modpow(25,i,MOD)*COM(i+s.size()-1,s.size()-1)%MOD*modpow(26,k-i,MOD)%MOD)%MOD;
}
cout<<ans<<endl;

     }


 


 






    





      

        


Measured memory_bytes: 52140
N = int(input())

s_list = []
for i in range(N):
	s_list.append(input().strip())

ss_list = sorted(["".join(sorted(s)) for s in s_list])

total = 0
count = 1
start = 0
prev = None
for i in range(N):
	s = ss_list[i]
	if prev == s:
		count += 1
	else:
		if count > 1:
			total += count * (count - 1) // 2
		count = 1
	prev = s

if count > 1:
	total += count * (count - 1) // 2

print(total)


Measured memory_bytes: 18520
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
std::vector<std::vector<long long>> combTableByPascalsTriangle(
    int n) { /*パスカルの三角形を利用した組合せの前計算。O(N^2)。 * arg... *
int n: 組合せ計算したい要素の個数。nCrで指定しうる最大のn *
return... *  vector<vector<long long>> c :
組合せ計算nCrの結果がc[n][r]に入っている。 */
  auto c = std::vector<std::vector<long long>>(
      n + 1, std::vector<long long>(n + 1, 0));
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0 or j == i) {
        c[i][j] = 1LL;
      } else {
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]);
      }
    }
  }
  return c;
}

int main() {
  int n, p;
  cin >> n >> p;
  VEC<int> b(n);
  int n0 = 0, n1 = 0;
  REP(i, 0, n) {
    int a;
    cin >> a;
    b[i] = a % 2;
    b[i] ? ++n1 : ++n0;
  }
  auto comb = combTableByPascalsTriangle(n);
  auto f = [&](int p) -> LL {
    LL ans = 0;
    for (int k = p; k <= n1; k += 2) {
      // ans += comb[n0][n - k] * comb[n1][k];
      ans += (LL)pow(2, n0) * comb[n1][k];
    }
    return ans;
  };
  LL ans = f(p);

  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);
        String s = sc.next();
        System.out.print(s.charAt(0));
        System.out.print(s.length() - 2);
        System.out.println(s.charAt(s.length() - 1));
    }
}


Measured memory_bytes: 21716
#include <stdio.h>
#include <string.h>
int main(void){
  int A,B;
  char S[11],T[11],U[11];
  
  scanf("%s %s",S,T);
  scanf("%d %d",&A,&B);
  scanf("%s",U);
  
  if(strcmp(S,U) == 0){
    A = A - 1;
  }
  if(strcmp(T,U) == 0){
    B = B - 1;
  }
  printf("%d %d",A,B);
  return 0;
  }

Measured memory_bytes: 128
a = Array.new(4).map { Array.new(3).map { Array.new(10, 0) } }
n = gets.to_i
n.times do
  info = gets.split.map(&:to_i)
  b, f, r, v = info.map {|x| x - 1 }
  v += 1
  a[b][f][r] += v
end
(0..3).each do |b|
  (0..2).each do |f|
    puts " " + a[b][f] * " "
  end
  puts ?# * 20 if b < 3
end



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

using namespace std;

const int maxn=50001;

int prime[maxn],cnt,res;
bool isprime[maxn];

void maketable()
{
    int base=(int)sqrt((double)maxn);
    isprime[0]=isprime[1]=1;
    for(int i=2;i<maxn;i++){
        if(!isprime[i]){
            prime[cnt++]=i;
            for(int j=i+i;j<maxn;j+=i){
                isprime[j]=1;
            }
        }
    }
}

void solve(int n)
{
    int k=(int)sqrt((double)n);
    for(int i=0;prime[i]<=k;i++){
        if(n%prime[i]==0){
            return ;
        }
    }
    res++;
}

int main()
{
    maketable();
    int n,s;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s);
        solve(s);
    }
    printf("%d\n",res);
    return 0;
}



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

int main()
{
    int i = 0, j = 0, n = 0, x = 0;
    cin >> n;
    for(i = 0; i <= 25; i++)
    {
        for(j = 0; j <= 14; j++)
        {
            if(i * 4 + j * 7 == n)
            {
                cout << "Yes";
                x = 1;
                break;
            }
        }
        if(x == 1)
        {
            break;
        }
    }
    if(x == 0)
    {
    cout << "No";
    }





return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n),b(n),c(n);
rep(i,n)cin>>a[i];
rep(i,n)cin>>b[i];
rep(i,n)cin>>c[i];
sort(a.begin(),a.end());
sort(b.begin(),b.end());
sort(c.begin(),c.end());
ll ans=0;
rep(i,n){
    int _b=b[i];
    auto iter_a = lower_bound(a.begin(),a.end(),_b);
    auto iter_c = upper_bound(c.begin(),c.end(),_b);
    int dist=a.end()-iter_a;
    dist=c.end()-iter_c;
    ans+=(n-int(a.end()-iter_a))*(c.end()-iter_c);
}
cout<<ans<<endl;
return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    int ans=0;
    while(!s.empty()){
        n = s.size();
        vi A(n); A[0]=n;
        int i=1,j=0;
        while(i<n){
            while(i+j<n && s[i+j]==s[j]) j++;
            A[i] = j;
            if (j==0){ i++; continue; }
            int k = 1;
            while(i+k<n && k+A[k]<j) A[i+k]=A[k], k++;
            i+=k; j-=k;
        }
        rep(i,n) chmax(ans,min(A[i],i));
        s=s.substr(1);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define ss second
#define pp pop_back
#define in insert
#define ld long double
#define sz(v) (int)v.size()
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define sp cout << " "
#define endl '\n'
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';              
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define lmax 9223372036854775807
#define v3(type, v, x, y, z) vector<vector<vector<type>>> v(x, vector<vector<type>>(y, vector<type>(z)))
#define v2(type, v, n, m) vector<vector<type>> v(n, vector<type>(m))

const ll MOD=1e9+7;
typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vpii;
typedef vector<pll > vpll;


inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = (n%p) * (n%p) % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}


int main()
{
	ll i,j,n,m,k,ans,t=1;
	// cin>>t;
	while(t--)
	{
		cin>>n>>m;
		n=n%m;
		n=min(n,m-n);
		cout<<n<<endl;	
	}
	
}

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

int main(){
    int cnt = 0;
    string V;
    cin >> V;
    
    while(true){
        string S;
        cin >> S;
        if(S == "END_OF_TEXT") break;
        
        for(int i = 0; i < S.size(); i++){
            if(isupper(S[i])) S[i] = tolower(S[i]);
        }
        
        if(S == V)cnt++;
        
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3160
N, K = map(int, input().split())
* P, = map(int, input().split())
P = [(1+p)/2 for p in P]
M1 = sum(P[:K])
M0 = M1
for i in range(K, N):
    M0 += P[i]
    M0 -= P[i - K]
    if M0 > M1:
        M1 = M0
print(M1)


Measured memory_bytes: 24804
#include <iostream>
#include<string>
#include<fstream>
#include<vector>
#include <algorithm>
#include <set>
#include <math.h>
using namespace ::std;
vector<int> v, a;
 
signed  main()
{
	int n;
	cin >> n;
	v.resize(n);
	a.resize(n,1000000000);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	a[0] = 0;
	a[1] = abs(v[0] - v[1]);
	for(int i=2;i<n;i++)
	{ 
		a[i] = min(a[i], a[i - 1] + abs(v[i - 1] - v[i]));
		a[i] = min(a[i], a[i -2] + abs(v[i - 2] - v[i]));
	}
	cout << a[n - 1];
	cin >>n;
}
 //   aaaddda

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

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

    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int M;
	cin >> M;
	cout << 24 + (24 - M) << endl;

	return 0;
}


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

int main(){
  int a,b,c,d,k,n,m,i;
  cin >> a >> b >> k;
  n=k/2; m=k%2;
  for(i=0; i<n; i++){
    a=(a/2)*2;
    b+=a/2; a/=2;

    b=(b/2)*2;
    a+=b/2; b/=2;
  }

  if(m==1){
    a=(a/2)*2;
    b+=a/2; a/=2;
  }
  cout<<a<<' '<<b;
}

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

using namespace std;

typedef long long ll;

ll n, x;

ll gcd(ll n, ll x)
{
	if (!x) return n;
	return gcd(x, n % x);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> x;
	cout << ((n / gcd(n, x)) - 1ll) * 3ll * gcd(n, x) << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N = int(input())
    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        temp = sum(A1[0:i + 1]) + sum(A2[i:N])
        ans = max(ans, temp)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n,d;
  cin>>n>>d;
  vector<vector<int>>data(n,vector<int>(d));
  rep(i,n){
    rep(j,d){
      cin>>data[i][j];
    }
  }
  int ans=0;
  rep(i,n) rep(k,i){
      int sq=0;
      rep(j,d){
        int dif=data[i][j]-data[k][j];
        sq+=dif*dif;
      }
    int s=sqrt(sq)+0.5; //intは切り捨てなので、四捨五入になるように0.5を足す
    if(s*s==sq) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>

#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))

int main(int argc, char *argv[])
{
    int a, b, c, d, e, k;
    int min, max;

    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);

    min = min(a, min(b, min(c, min(d, e))));
    max = max(a, max(b, max(c, max(d, e))));
    
    if (max - min > k) {
        printf(":(\n");
    } else {
        printf("Yay!\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int CYCLE = 2 * 2 * 2 * 2 * 3 * 3 * 5 * 7 * 11;

int main(){
  int N;
  while(cin>>N && N){
    int access[25][25] = {};
    REP(i, N){
      int cycle, offset; cin>>cycle>>offset;
      REP(j, cycle){
        int volume; cin>>volume;
        access[cycle][(j - offset + cycle) % cycle] += volume;
      }
    }
    vector<int> access_sum(CYCLE);
    for(int cycle = 1; cycle <= 24; cycle++){
      if(cycle == 13 || cycle == 17 || cycle == 19 || cycle == 23){
        int max_a = 0;
        REP(i, cycle) max_a = max(max_a, access[cycle][i]);
        REP(i, CYCLE) access_sum[i] += max_a;
      }else{
        int idx = 0;
        REP(i, CYCLE){
          access_sum[i] += access[cycle][idx];
          idx = (idx + 1) % cycle;
        }
      }
    }
    cout<<*max_element(access_sum.begin(), access_sum.end())<<endl;
  }
  return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf ((ll)1e18)

int sz[2], q;
set<ll> items[2];

ll next_pos(ll x, int pos, int side) {
    if (side == 0) {
        auto it = items[pos].lower_bound(x);
        return it == items[pos].begin() ? -inf : *(--it);
    } else {
        auto it = items[pos].upper_bound(x);
        return it == items[pos].end() ? inf : *it;
    }
}

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

    cin >> sz[0] >> sz[1] >> q;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < sz[i]; ++j) {
            ll x; cin >> x;
            items[i].insert(x);
        }
    }
    while (q--) {
        ll x, ans = inf; cin >> x;
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                for (int k = 0; k < 2; ++k) {
                    ll v1 = next_pos(x, i, j);
                    ll v2 = abs(x-v1) + abs(v1-next_pos(v1, 1-i, k));
                    ans = min(ans, v2);
                }
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 10752
from itertools import combinations
import sys

# dp[n][使った数字(bit)][合計] = count
dp = [[[0]*331 for _ in [0]*2048] for _ in [0]*11]
for i in range(11):
    dp[1][2**i][i] = 1

for i in range(2, 11):
    for used in (sum(comb) for comb in combinations([2**n for n in range(10)], i-1)):
        for j in filter(lambda x: used & 2**x == 0, range(10)):
            for total, count in filter(lambda p: p[1]>0, enumerate(dp[i-1][used])):
                dp[i][used|2**j][total+j*i] += count

for n, s in (map(int, l.rstrip().split()) for l in sys.stdin):
    print(sum(a[s] for a in dp[n] if a[s]) if s<331 else 0)


Measured memory_bytes: 66028
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    int ans = 0;
    rep(i, N - 2) {
        if ('A' == S.at(i) && 'B' == S.at(i + 1) && 'C' == S.at(i + 2)) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import math

h = int(readline())
w = int(readline())
n = int(readline())
ans = min(math.ceil(n / h), math.ceil(n / w))
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll ans=0;
    vector<ll> a(6);
    for (int i=0;i<6;++i){
            cin >> a[i];
    }
    for(ll i=0;i<4;++i){
        for (ll j=i+1;j<5;++j){
            if (abs(a[i]-a[j])<=a[5]){
                ++ans;
            }
        }
    }
    if (ans<10){
        cout << ":(" << endl;
        return 0;
    }
    cout << "Yay!" << endl;
    return 0;
}


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

using namespace std;

int main(){
   int a,b;
   cin>>a>>b;
   int ans=0;
   for(int i=a;i<b+1;i++){
      string s=to_string(i);
      if(s[0]==s[4] && s[1]==s[3])ans++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 384