akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int p[1000000];
int main(void){
	int n,i,j,ans;
	rep(i,2,1000000) p[i]=1;

	rep(i,2,1000000){
		if(p[i]==1){
			rep(j,2,1000000){
				if(i*j>=1000000) break;
				p[i*j]=0;
			}
		}

	}
	
	while(scanf("%d",&n)!=EOF){
		ans=0;
		rep(i,0,n+1){
			ans+=p[i];
		}
		printf("%d\n",ans );
	}
	
	return 0;
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, N, ans=0;
    vector<int> v(3);
    vector<char> L(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> N;

    cout << (N>=1000 ? "ABD" : "ABC") << endl;
    // ans = a<=b ? a:a-1;

    
    // ans = min(A, B) + min(C, D);
    // cout << ans<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(abs(a-b) <=d && (b-c) <=d ||abs(c-a)<=d)
    // 	puts("Yes");
    // else
    // 	puts("No");
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

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

ll lcm(ll a, ll b){
  return a/gcd(a, b)*b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll a, b;
  cin>>a>>b;
  cout<<lcm(a, b)<<'\n';
  return 0;
}


Measured memory_bytes: 256
from math import gcd

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

G=gcd(N,M)
L=(N*M)//G

P=L//N
Q=L//M

A=range(0,L,P)
B=range(0,L,Q)

F=True
for k in A:
    if k in B:
        F&=S[k//P]==T[k//Q]
if F:
    print(L)
else:
    print(-1)

Measured memory_bytes: 67764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, x2;
  double x1;
  cin >> a >> b;
  x1 = 0.5 * (a + b);
  x2 = (a + b) / 2;
  if ((x1 - x2) > 0) x2++;
  cout << x2;
}

Measured memory_bytes: 256
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
using namespace std;

int main()
{
    unsigned int n,q,k,all;
    bitset<20> a(0),b(0);
    cin>>n;
    all=1<<n;
    cin>>n;
    while(n--){
        cin>>q;
        b.set(q,1);
    }
    for(int i=0;i<all;i++){
        a=i;
        if((a&b)==b){
            cout<<i<<":";
            for(int i=0;i<18;i++){
                if(a.test(i)){
                    cout<<" "<<i;
                }
            }
            cout<<"\n";
        }
    }

}





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

typedef long long ll;

const int MOD = (int)(1e+9) + 7;
int N;
ll max_A;
int max_bit;
vector<ll> A;
vector<int> pow2;

void input_init(void) {
	cin >> N;
	A.resize(N);
	max_A = -1;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		max_A = max(A[i], max_A);
	}
	ll tmp = 1;
	pow2.push_back((int)tmp);
	while (tmp < max_A) {
		tmp <<= 1;
		pow2.push_back((int)(tmp % MOD));
	}
	max_bit = pow2.size() - 1;
}

ll solve(void) {
	ll sum = 0;
	for (int bit = 0; bit <= max_bit; ++bit) {
		int cnt_1 = 0;
		for (int i = 0; i < N; ++i) {
			if ((A[i] & ((ll)1 << bit)) != 0)
				++cnt_1;
		}
		int cnt_0 = N - cnt_1;
		sum += (((ll)cnt_0 * cnt_1) % MOD) * pow2[bit] % MOD;
		sum %= MOD;
	}
	return sum;
}

int main(void) {
	input_init();
	ll ans = solve();
	cout << ans << '\n';
	return 0;
}


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

int main(){

    long int n, k;
    cin >> n >> k;

    vector<long long int> h(n);

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

    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());

    long long int ans = 0;

    for(long int i = k; i < n; ++i){
        ans += h[i];
    }

    cout << ans << endl;

}

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

int main(){
	int x[301],y[4000];
	int n;
	int num,a,b,c,r;
	while(cin>>a>>b>>c,a||b||c){
		cin>>n;
		num=a+b+c;
		fill(x,x+301,2);
		for(int i=0;i<n;i++){
			cin>>a>>b>>c>>r;
			if(r==1)x[a]=x[b]=x[c]=1;
			y[4*i]=a;
			y[4*i+1]=b;
			y[4*i+2]=c;
			y[4*i+3]=r;
		}
		for(int i=0;i<n;i++){
			int c=0;
			for(int j=0;j<3;j++)if(x[y[4*i+j]]==1)c++;
			if(y[4*i+3]==0 && c==2){
				for(int j=0;j<3;j++)if(x[y[4*i+j]]==2)x[y[4*i+j]]=0;
			}
		}
		for(int i=1;i<=num;i++)cout<<x[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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)*}
    };
}

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input!{
        n: usize,
        x: i64,
        a: [i64; n],
    }
    let mut a = a;
    a.reverse();
    let mut acc = vec![0; n + 1];
    for i in 0 .. n {
        acc[i + 1] = acc[i] + a[i];
    }
    let mut mi: i64 = 1 << 62;
    for k in 1 .. (n + 1) {
        let mut cost = x * k as i64;
        let c = n / k;
        for i in 0 .. c {
            let coef = if i == 0 { 5 } else { 2 * i as i64 + 3 };
            let t = (acc[k * (i + 1)] - acc[k * i]).saturating_mul(coef);
            cost = cost.saturating_add(t);
        }
        cost = cost.saturating_add((acc[n] - acc[c * k]).saturating_mul(2 * c as i64 + 3));
        mi = min(mi, cost);
    }
    puts!("{}\n", mi + n as i64 * x);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 12540
#[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 ) * } } ; }
#[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 , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules! chmin {
    ( $ x : expr , $ y : expr ) => {
        if $x > $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n]
    }

    let mut ret = 1i64 << 60;
    for i in -100..101 {
        let mut c = 0;
        for j in 0..n {
            c += (a[j] - i).pow(2);
        }
        chmin!(ret, c);
    }
    println!("{}", ret);
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct cnt_t
{
	map<int,int> c;
};


struct segtree_t
{
	int n;
	int base;
	std::vector<int> t;
	segtree_t(int n) : n(n)
	{
		for(base=1;base<n;base*=2)
			;

		t.resize(base*2);
	}

	void set_i(int x)
	{
		if(x==0) return;
		t[x]=t[x*2]+t[x*2+1];
		set_i(x/2);
	}

	void set(int x, int v)
	{
		int y=base+x;
		t[y]=(v!=0);
		set_i(y/2);
	}

	int get_i(int x)
	{
		if(x==0) return 0;
		int add=0;
		if(x&1) add=t[x-1];
		return add+get_i(x/2);
	}

	int get(int x)
	{
		int y=base+x;
		return t[y]+get_i(y);
	}

void dump(void)
{
	for(auto&m:t) cout << m << " ";
	cout << "\n";
}

};


struct solve
{
	int n;
	vi c;
	segtree_t t;
	map<pii,int> ans;
	solve(int n, vi&c, vi&l, vi&r) : n(n), c(c), t(n+1) {
		vvi x(n+1);
		for(int i=1;i<=n;i++)
		{
			x[c[i]].push_back(i);
		}

		for(int i=1;i<=n;i++)
		{
			if(x[i].empty()) continue;
			t.set(x[i].back(), 1);
		}
//t.dump();
		int q=l.size();
		vpii rl;
		for(int i=0;i<q;i++)
		{
			rl.push_back(make_pair(r[i], l[i]));
		}
		sort(rl.rbegin(), rl.rend());

		int xr=n;
		for(int i=0;i<q;i++)
		{
			for(;xr>rl[i].first;xr--)
			{
				auto&tv=x[c[xr]];
				t.set(tv.back(), 0);
				tv.pop_back();
				if(tv.empty()) continue;
				t.set(tv.back(), 1);
			}
			ans[rl[i]]=t.get(rl[i].first)-t.get(rl[i].second-1);
//cout << "ans " << rl[i].first << " " << rl[i].second << " " << ans[rl[i]] << "\n";
		}
	}
	ll operator()(int l, int r) {
		auto it=ans.find(make_pair(r, l));
		return it->second;
	}
};

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

	for(;;)
	{
		int n, q;
		cin >> n >> q;
		if(cin.fail()) break;
		vi c(n+1);
		for(int i=1;i<=n;i++) cin >> c[i];

		vi l(q), r(q);
		for(int i=0;i<q;i++) cin >> l[i] >> r[i];

		solve solver(n, c, l, r);
		for(int i=0;i<q;i++)
		{
			cout << solver(l[i], r[i]) << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 77336
private const val MOD:Long=1e9.toLong()+7

private class Comb(){
    val n=2e6.toInt()+2
    var fact=LongArray(n+1)
    var factinv=LongArray(n+1)
    init {
        fact[0]=1L
        for(i in 1 until n+1){
            fact[i]=fact[i-1]*i%MOD
        }
        factinv[n]=pow(fact[n], MOD-2)
        for(i in n downTo 1){
            factinv[i-1]=factinv[i]*i%MOD
        }
    }
    private fun pow(base:Long, exp:Long):Long{
        if(exp==0L) return 1L
        var ans=pow(base, exp shr 1)
        ans=ans*ans%MOD
        if (exp and 1L==0L) return ans
        return ans*base%MOD
    }
    fun comb(n:Int, k:Int):Long{
        return fact[n] * factinv[n-k]%MOD * factinv[k]%MOD
    }
}

fun main(args: Array<String>) {
    var (r1, c1, r2, c2)= readLine()!!.split(" ").map { it.toInt() }
    var ans:Long=0L
    var cb=Comb()
    ans+=cb.comb(r2+1+c2+1, r2+1)
    ans=ans%MOD
    ans-=cb.comb(r2+1+c1, r2+1)
    ans=(ans+MOD)%MOD
    ans-=cb.comb(r1+c2+1, c2+1)
    ans=(ans+MOD)%MOD
    ans+=cb.comb(r1+c1, r1)
    ans=ans%MOD
    println(ans)
}


Measured memory_bytes: 70796
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 310;
const int MAX_M = 310;
int N, M;
int A[MAX_N][MAX_M];

std::pair<int, int> count(std::bitset<MAX_M> bs) {
    int cnt[MAX_M] = {};
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (bs.test(A[i][j])) {
                cnt[A[i][j]]++;
                break;
            }
        }
    }

    int s = 0;
    int max = 0;
    for (int j = 1; j <= M; j++) {
        if (max < cnt[j]) {
            s = j;
            max = cnt[j];
        }
    }
    return std::pair<int, int>({s, max});
}

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= N; i++) {
        A[i][0] = MAX_M;
        for (int j = 1; j <= M; j++) {
            std::cin >> A[i][j];
        }
    }

    std::bitset<MAX_M> bs;

    for (int i = 1; i <= M; i++) {
        bs.set(i);
    }

    int ret = N;
    while (0 < bs.count()) {
        std::pair<int, int> cnt = count(bs);
        ret = std::min(ret, cnt.second);
        bs.reset(cnt.first);
    }

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

Measured memory_bytes: 640
def main():
    n,c,k = map(int,input().split())
    t = [int(input()) for _ in range(n)]
    t = sorted(t)
    left = 0
    right = 0
    ans = 0
    while 1:
        if right == n-1:
            if t[right]-t[right-1]>k:
                ans +=2
                break
            else:
                ans +=1
                break
        if t[right]-t[left]<=k and right-left+1<=c:
            right +=1
        else:
            ans +=1
            left = right
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 51032
from math import gcd
from functools import reduce

def gcd_list(lis):
  return reduce(gcd, lis)

K = int(input())

ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += gcd_list([i,j,k])
      
print(ans)

Measured memory_bytes: 74876
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;

int main(){
	string str;
	int array[8];
	int max, min;
	int n;
	getline(cin, str);
	n = atoi(str.c_str());
	for (int i = 0; i < n; i++) {
		getline(cin, str);
		for (int j = 0; j < 8; j++) {
			array[j] = (int)(str[j] - '0');
		}
		sort(array, array+8, greater<int>());
		for (int j = 0; j < 8; j++) {
			str[j] = (char)array[j] + '0';
		}
		max = atoi(str.c_str());

		sort(array, array+8);
		for (int j = 0; j < 8; j++) {
			str[j] = (char)array[j] + '0';
		}
		min = atoi(str.c_str());
		cout << max-min << endl;
	}
	return 0;
}

Measured memory_bytes: 0
def main():
    N, M = map(int, input().split())
    digits = ["empty"] * N

    for _ in range(M):
        s, c = map(int, input().split())
        if digits[s-1] != "empty" and digits[s-1] != str(c):
            print(-1)
            return

        digits[s-1] = str(c)

    if N == 1:
        print(digits[0].replace("empty", "0"))
        return

    if digits[0] == str(0):
        print(-1)
        return
    elif digits[0] == "empty":
        digits[0] = "1"

    print("".join(digits).replace("empty", "0"))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
N, K = [int(x) for x in input().split()]

# sushi
s = {}
for i in range(N):
    t, d = [int(x) for x in input().split()]
    if not t in s:
        s[t] = [d]
    else:
        s[t].append(d)

# 各スシのMax
m = [max(v) for k, v in s.items()]
m.sort(reverse=True)

s2 = {}
all2 = []
for k in s.keys():
    s2[k] = sorted(s[k])
    s2[k].pop()
    all2 += s2[k]
all2.sort(reverse=True)

# スシ種類
# kinds = len(set([k for k in s.keys()]))
kinds = len(m)

import itertools

acM = list(itertools.accumulate(m))
acAll2 = list(itertools.accumulate(all2))

ans = 0
# for i in range(1, min(K, kinds) + 1):
for i in range(0, min(K, kinds)):
    # addM = m[:i]
    # addAll2 = all2[:K - i]
    # newAns = sum(addM) + sum(addAll2) + i ** 2
    t1 = acM[i]
    idx = K - i - 2
    t2 = acAll2[idx] if idx >= 0 and idx < len(acAll2)  else 0
    newAns = t1 + t2 + (i + 1) ** 2
    ans = max(ans, newAns)

print(ans)

pass


Measured memory_bytes: 49328
import java.util.*;
public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    int[] arr = new int[N+1];
    sc.close();

    arr[0] = 0;
    int all = 0;

    for (int i = 1; i < N+1; i++) {
      arr[i] = L + i - 1;
      all += arr[i];
    }

    int d = 200;
    int r = 200;

    for (int i = 1; i < N+1; i++) {
      if (Math.abs(arr[i]) < d){
        d = Math.abs(arr[i]);
        r = arr[i];
      }
    }

    System.out.println(all - r);

  }
  
}

Measured memory_bytes: 21716
#include <algorithm>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>

using namespace std;

int field_B[1002][1002] = {0};
int field_W[1002][1002] = {0};
int ruiseki_B[1002][1002] = {0};
int ruiseki_W[1002][1002] = {0};

int main() {
    int N, K;

    cin >> N >> K;

    int x, y;
    char c;

    for (int i = 1; i <= N; i++) {
        cin >> x >> y >> c;
        int pos = (x / K + y / K) % 2;
        if ((c == 'B' && pos == 0) || (c == 'W' && pos == 1)) {
            field_B[x % K][y % K]++;
        } else {
            field_W[x % K][y % K]++;
        }
    }

    for (int i = 0; i < K; i++) {
        for (int j = 0; j < K; j++) {
            ruiseki_B[i][j] = field_B[i][j];
            ruiseki_W[i][j] = field_W[i][j];
        }
    }

    for (int i = 1; i < K; i++) {
        for (int j = 0; j < K; j++) {
            ruiseki_B[i][j] += ruiseki_B[i - 1][j];
            ruiseki_W[i][j] += ruiseki_W[i - 1][j];
        }
    }

    for (int i = 0; i < K; i++) {
        for (int j = 1; j < K; j++) {
            ruiseki_B[i][j] += ruiseki_B[i][j - 1];
            ruiseki_W[i][j] += ruiseki_W[i][j - 1];
        }
    }

    int ans = 0;
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < K; j++) {
            ans = max(ans, ruiseki_B[i][j] +
                               (ruiseki_B[K - 1][K - 1] - ruiseki_B[i][K - 1] -
                                ruiseki_B[K - 1][j] + ruiseki_B[i][j]) +
                               (ruiseki_W[i][K - 1] - ruiseki_W[i][j]) +
                               (ruiseki_W[K - 1][j] - ruiseki_W[i][j]));
            ans = max(ans, ruiseki_W[i][j] +
                               (ruiseki_W[K - 1][K - 1] - ruiseki_W[i][K - 1] -
                                ruiseki_W[K - 1][j] + ruiseki_W[i][j]) +
                               (ruiseki_B[i][K - 1] - ruiseki_B[i][j]) +
                               (ruiseki_B[K - 1][j] - ruiseki_B[i][j]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> mp(1e6 + 1, 0);
    rep(i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll g = a[0];
    for(ll i = 1; i < n; i++){
        g = gcd(g, a[i]);
    }

    if(g != 1){
        cout << "not coprime" << endl;
        return 0;
    }
    bool f = true;
    for(ll i = 2; i <= 1e6; i++){
        ll cnt = 0;
        for(ll j = 0; j <= 1e6; j += i){
            cnt += mp[j];
        }
        if(cnt >= 2){
            f = false;
        }
    }

    if(f){
        cout << "pairwise coprime" << endl;
    } else {
        cout << "setwise coprime" << endl;
    }


}   

Measured memory_bytes: 18820
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define N 1010
vector <int> nxt[N]; bool arr[N][N],arr2[N][N],vis[N]; int vis2[N],vis1[N],num[N][N],n,m,fr[N*300],to[N*300],idx;
void init() {for(int i=1;i<=n;i++) vis[i]=false;}
void dfs(int p,int from)
{
	vis[p]=true,arr[from][p]=true;
	for(int i=0;i<(int)nxt[p].size();i++) if(!vis[nxt[p][i]]) dfs(nxt[p][i],from);
}
void dfs2(int p)
{
	vis[p]=true;
	for(int i=0;i<(int)nxt[p].size();i++) if(!vis[nxt[p][i]])
		vis1[nxt[p][i]]=num[p][nxt[p][i]],dfs2(nxt[p][i]);	
}
void dfs3(int p)
{
	vis[p]=true;
	for(int i=(int)nxt[p].size()-1;~i;i--) if(!vis[nxt[p][i]])
		vis2[nxt[p][i]]=num[p][nxt[p][i]],dfs3(nxt[p][i]);	
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,a,b;i<=m;i++)
	{
		scanf("%d%d",&a,&b),nxt[a].push_back(b);
		num[a][b]=++idx,fr[idx]=a,to[idx]=b;
	}
	for(int i=1;i<=n;i++) dfs(i,i),init();
	for(int i=1;i<=n;i++)
	{
		dfs2(i),init(),dfs3(i),init();
		for(int j=0;j<(int)nxt[i].size();j++)
			if(vis1[nxt[i][j]]!=num[i][nxt[i][j]]||vis2[nxt[i][j]]!=num[i][nxt[i][j]])
				arr2[i][nxt[i][j]]=true;
		for(int j=1;j<=n;j++) vis1[i]=vis2[i]=0;
	}
	for(int i=1;i<=idx;i++) printf(arr[to[i]][fr[i]]^arr2[fr[i]][to[i]]?"diff\n":"same\n");
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=105;
vector<int>e[Maxn],path;
pair<int,int>dfs(int x,int fa,int dis){
    pair<int,int>ret=make_pair(dis,x);
    for(int y:e[x]){
        if(y==fa)continue;
        pair<int,int>tmp=dfs(y,x,dis+1);
        ret=max(ret,tmp);
    }
    return ret;
}
int dfs1(int x,int fa,int dis=0){
    int ret=dis;
    for(int y:e[x]){
        if(y==fa)continue;
        ret=max(ret,dfs1(y,x,dis+1));
    }
    return ret;
}
bool dfs2(int x,int fa,int t){
    if(x==t)return path.push_back(x),true;
    for(int y:e[x]){
        if(y==fa)continue;
        if(dfs2(y,x,t))
            return path.push_back(x),true;
    }
    return false;
}
void dfs3(int x,int fa,int dis,int*f){
    int sz=0;
    for(int y:e[x]){
        if(y==fa)continue;
        sz++;
        dfs3(y,x,dis+1,f);
    }
    f[dis]=max(f[dis],sz);
}
ll solve(int ans,int x,int y,ll ret){
    static int f[Maxn];
    fill(f,f+Maxn,1);
    dfs3(x,y,0,f);
    dfs3(y,x,0,f);
    for(int i=0;i<=ans;i++)ret*=f[i];
    return ret;
}
int main(){
    int n;cin>>n;
    for(int i=1;i<n;i++){
        int x,y;cin>>x>>y;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    int a=dfs(1,0,0).second;
    int b=dfs(a,0,0).second;
    dfs2(a,0,b);
    ll cnt=(path.size()+1)/2,ans;
    if(path.size()&1){
        int x=path[path.size()/2];
        ans=solve(cnt,x,0,1);
        for(int y:e[x])
            if(dfs1(y,x)+dfs1(x,y)<=path.size()-1)
                ans=min(ans,solve(cnt,x,y,2));
    }else{
        for(int x=1;x<=n;x++)
            for(int y:e[x]){
                int a=dfs1(y,x),b=dfs1(x,y);
                if(a+b+2!=path.size())continue;
                if(abs(a-b)>1)continue;
                ans=min(ans,solve(cnt,x,y,2));
            }
    }
    cout<<cnt<<" "<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int n, m, x, tmp, ans;
  ans = 0;
  vector<long long int> v, w;
  cin >> n >> m;

  for(int i=0;i<m;i++){
    cin >> x;
    v.push_back(x);
  }
  
  if(n > m){
    cout << 0 << endl;
    return 0;
  }

  sort(v.begin(), v.end());
  for(int i=0;i<m-1;i++){
    w.push_back(v[i+1]-v[i]);
  }
  sort(w.begin(), w.end());
  for(int i=0;i<m-n;i++){
    ans += w[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2548
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
string input;
string list[1024 / 6];
int idx = 0;

bool w_space(char a) {
    return(a == ' ' || a == '.' || a == ',');
}

bool legal(string str) {
    if(str.length() <= 2 || str.length() >= 7) return(false);
    return(true);
}

void solve() {
    string check = "";
    for(int r = 0; r < input.length(); r++) {
        if(w_space(input[r])) {
            if(legal(check)) {
                list[idx++] = check;
            }
            check = "";
        } else {
            check += input[r];
        }
    }
}

int main(void) {
    getline(cin, input);
    
    solve();
    /*
    set<string>::iterator ite = list.begin();
    for(int r = 0; r < list.size(); r++, ite++) {
        cout << (*ite);
        if(r == list.size() - 1) putchar('\n');
        else putchar(' ');
    }
     */
    
    for(int r = 0; r < idx; r++) {
        cout << list[r];
        if(r == idx - 1) putchar('\n');
        else putchar(' ');
    }
    return(0);
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N,A;cin>>N>>A;
    int b=N%500;
    if(b<=A){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <tuple>

using namespace std;

long long MOD = 1000000007;

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

    vector<pair<int, int> > AB(0);
    for(int i=0; i<N; i++){
        int A, B;
        cin >> A >> B;
        AB.push_back(make_pair(A,B));
    }
    sort(AB.begin(), AB.end());

    vector<vector<int > > dp(N+1, vector<int>(6001,0));
    for(int n=0; n<N; n++){
        for(int t=0; t<6001; t++){
            int A=AB[n].first;
            int B=AB[n].second;
            if(t<T){
                dp[n+1][t+A]=max(dp[n+1][t+A], dp[n][t]+B);
            }
            dp[n+1][t]=max(dp[n+1][t],dp[n][t]);
        }
    }

    int ans =0;
    for(int t=0; t<6001; t++){
        ans=max(ans, dp[N][t]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 70784
class ModeValue
  def mode(array)
    result = array.each_with_object(Hash.new(0)) { |i, h| h[i] += 1 }
    max = result.values.max
    result.select { |_, v| v == max }.keys.sort
  end
end

array = STDIN.read.split("\n").map(&:to_i)
puts ModeValue.new.mode(array)

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

int main() {
    int n; cin >> n;
    vector<int> a(n), ca(n);
    for (int i=0; i<n; i++) cin >> a[i];
    ca = a;
    sort(ca.begin(), ca.end());
    int maxn = ca[n-1], second = ca[n-2];
    for (int i=0; i<n; i++) {
        if (a[i]==maxn) cout << second << endl;
        else cout << maxn << endl;
    }
}

Measured memory_bytes: 3200
while 1:
    n,m=map(int,raw_input().split())
    if n==0:
        break
    l=range(1,n+1)
    tmp=[]
    cnt=0
    while 1:
        if len(l)==1 and len(tmp)==0:
            print l.pop()
            break
        cnt+=1
        if cnt%m:
            tmp.append(l.pop(0))
        else:
            l.pop(0)
        if len(l)==0:
            l=tmp
            tmp=[]
exit()

Measured memory_bytes: 6480
/**
 * Problem:	C. 
 * Author:	hkxadpall. 
 * Date:	2018-08-25. 
 * Upload:	AtCoder. 
 */
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue> 
#include <map>
#include <set>
using namespace std;

namespace AuthorName { 
    template <typename _TpInt> inline _TpInt read();
    template <typename _TpRealnumber> inline double readr();
    template <typename _TpInt> inline void write(_TpInt x);
//	template <typename _TpSwap> inline void swap(_TpSwap &x, _TpSwap &y);
	
#	define Max_N 1007
	
	int n, i;
	
	int main() 
	{
		n = read<int>();
		i = read<int>();
		write(n - i + 1);
	    return 0;
	}

#	define Getchar() getchar()

    template <typename _TpInt>
    inline _TpInt read()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpInt init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = (init << 3) + (init << 1) + (c & 15);
        return init * flag;
    }

    template <typename _TpRealnumber>
    inline double readr()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpRealnumber init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init * 10 + (c & 15);
        if (c != '.') return init * flag;
        register _TpRealnumber l = 0.1;
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init + (c & 15) * l, l *= 0.1;
        return init * flag;
    }

    template <typename _TpInt>
    inline void write(_TpInt x)
    {
        if (x < 0) {
            putchar('-');
            write<_TpInt>(~x + 1);
        }
        else {
            if (x > 9) write<_TpInt>(x / 10);   
            putchar(x % 10 + '0');
        }
    }

//	template <typename _TpSwap>
//	inline void swap(_TpSwap &x, _TpSwap &y)
//	{
//	    _TpSwap t = x;
//	    x = y;
//	    y = t;
//	}
}

int main()
{
    AuthorName::main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
#define An setprecision(16) 
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    int flag = -1;
    int count;
    if(A<B){
        for(int i=1;i<=K;i++)C=C*2;
        if(B<C)flag = 1;
    }else{
        for(int i=1;i<=K;i++){
            B=B*2;
            count = i;
            if(A<B)break;
        }
        for(int j=1;j<=K-count;j++){
            C=C*2;
        }
        if(B<C)flag=1;
    }
    if(flag==1)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
from math import gcd, ceil
a, b, c, d = map(int, input().split())

def f(s, x, y):
    lcm = x * y // gcd(x, y)
    ret = s // x + s // y - s // lcm
    return ret

print(b-a+1-f(b, c, d)+f(a-1, c, d))

Measured memory_bytes: 9112
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
typedef long long int lli;

using namespace std;

int main() {
   
   int N;
   cin >> N;
    cout << N+N*N+N*N*N << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define filein freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);


void fun1(int* a,int* b){
    int sum=*a+*b;
    int dif=abs(*a-*b);
    //cout<<sum<<dif<<"\n";
    *a=sum;
    *b=dif;
}


int main() {
    int k;
    cin>>k;
    long long a[100005]={0,1,2,3,4,5,6,7,8,9};
    int count=10;
    int index=1;
    while (count<100001){
        long long t=a[index]%10;
        for (long long i = t-1; i <=t+1 ; ++i) {
            if (i>-1 && i<10)
                a[count++]=a[index]*10+i;
        }

        index++;
    }


    //for (int j = 0; j <10000 ; ++j) {
    //    cout<<a[j]<<" ";

   // }
   cout<<a[k];





}


Measured memory_bytes: 4372
import sys
input = sys.stdin.readline

def dijkstra(edge_adj: list, node: int, start: int) -> list:
    # graph[node] = [(cost, to)]
    inf = 3 * 10 ** 9
    dist = [inf] * node
    used = [False] * node

    dist[start] = 0
    while True:
        v = -1
        for i in range(node):
            if not used[i] and (v == -1 or dist[v] > dist[i]):
                v = i

        if v == -1:
            break

        used[v] = True
        for i in range(node):
            if dist[i] > dist[v] + edge_adj[v][i]:
                dist[i] = dist[v] + edge_adj[v][i]

    return dist
    # dist = [costs to nodes]

xs, ys, xt, yt = map(int, input().split())
n = int(input())
circles = [(xs, ys, 0), (xt, yt, 0)]
for i in range(n):
    circles.append(tuple(map(int, input().split())))
n += 2

edges = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        dist = ((circles[i][0] - circles[j][0]) ** 2 + (circles[i][1] - circles[j][1]) ** 2) ** 0.5
        cost = max(0, dist - circles[i][2] - circles[j][2])
        edges[i][j] = cost
        edges[j][i] = cost


dist = dijkstra(edges, n, 0)

print(dist[1])


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

int main(){
    int ans = 0;
    string s;
    cin >> s;
    for(int i=0; i<4; ++i){
        if(s[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func gcd(a int, b int)int{
	if b == 0{
		return a
	}

	return gcd(b, a % b)
}

func lcm(a int, b int)int{
	return (a*b) / gcd(a, b)
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	fmt.Println(lcm(a, b))
}

Measured memory_bytes: 1768
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
ll gcd(ll a,ll b){
if(a==0||b==0)return max(a,b);
if(b>a)swap(a,b);
 while(1){
        if(a%b!=0){
            ll tmp=b;b=a%b;
            a=tmp;
        }else{
            return b;
        }
    }
}
int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    ll cd=gcd(c,d);
    cd=c*d/cd;
   // cout<<cd<<endl;
    ll t1=b/cd;
    ll a1=b/c;
    ll a2=b/d;
    t1=b-a1-a2+t1;



    ll t2=(a-1)/cd;
    ll b1=(a-1)/c;
    ll b2=(a-1)/d;
    t2=(a-1)-b1-b2+t2;


    //cout<<t1<<t2<<endl;
    cout<<t1-t2<<endl;


    return 0;
}


Measured memory_bytes: 256
n, k = input().split()
d = input().split()
valid = [i for i in range(10) if str(i) not in d]
ans = ''

if valid[-1] < int(n[0]):
    if valid[0] == 0:
        ans += str(valid[1])
    else:
        ans += str(valid[0])
    ans += str(valid[0]) * len(n)
elif valid[-1] == int(n[0]):
    for s in n:
        if s > str(valid[-1]):
            ans = str(valid[-1])
            ans += str(valid[0]) * len(n)
            break
        ans += str(valid[-1])
else:
    for i, s in enumerate(n):
        if i > 0 and ans[i-1] > n[i-1]:
            ans += str(valid[0]) * (len(n)-i)
            break

        for k in valid:
            if k >= int(s):
                ans += str(k)
                break
print(ans)

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

int main(){
  int sum=0;
  int n,a;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%2==1)sum++;
  }
  if(sum%2==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e5+10;
const ll mod=1e9+7;
int bit[MAX][33],res[MAX];
int main()
{
	int n,x,i,j,a,b,c,ans,flag;
	while(~scanf("%d%d",&n,&x))
	{
		mem(bit,0);
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			bit[a][c]++;
			bit[b+1][c]--;
		}
		mem(res,0);
		for(i=1;i<=x;i++)
		{
			flag=0;
			for(j=1;j<=100000;j++)
			{
				bit[j][i]+=bit[j-1][i];
				if(bit[j][i])
				{
					if(!flag) res[j]++;
					flag=1;
				}
				else
				{
					if(flag) res[j]--;
					flag=0;
				}
			}
		}
		ans=0;
		for(i=1;i<=(int)1e5;i++)
		{
			res[i]+=res[i-1];
			ans=max(ans,res[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 13568
#include <stdio.h>
#include <string.h>

int main(void)
{
    char S[1001], T[1001];
    scanf("%s %s", &S, &T);

    int ans = 0;

    for(int i=0; i < strlen(S)-strlen(T)+1; i++){
        int tmp = 0;
        for(int j=0; j<strlen(T); j++){
            if(S[i+j] == T[j]){
                tmp++;
            }
        }
        if(ans < tmp) ans = tmp;
    }
    printf("%d", strlen(T)-ans);
}

Measured memory_bytes: 1704
<?php
  $N = trim(fgets(STDIN));
  $town = [];
  for($i=0; $i<$N; $i++){
    fscanf(STDIN,"%d %d", $x, $y);
    $town[$i] = [$x,$y];
  }
  //print_r($town);

  function dis($t1, $t2){
    $a = ($t1[0]-$t2[0])**2;
    $b = ($t1[1]-$t2[1])**2;
    return pow($a+$b,1/2);
  }
  
  function createPermutation($n, $r){
    if (!$r || $n < $r) {
      return array();
    }

    $return = array();
    $n2 = $n - 1;

    if ($r == 1) {
      for ($i=0; $i < $n ; $i++) { 
        $return[] = array($i);
      }
      return $return;
    }
    //(n-1)Prは、ほしい順列の一部
    foreach (createPermutation($n2, $r) as $row) {
      $return[] = $row;
    }
    //(n-1)P(r-1)各行の左端から右端まで、n-1を挿入したものを追加。
    foreach (createPermutation($n2, $r-1) as $row) {
      for ($i=0; $i < $r; $i++) { 
        $return[] = array_merge(array_slice($row, 0, $i), array($n2), array_slice($row, $i));
      }
    }
    return $return;
  }

  $ret = createPermutation($N,$N);
  //print_r($ret);
  $dist = 0;
  foreach($ret as $rr){
    for($j=0; $j<$N-1; $j++){
      $dist += dis($town[$rr[$j]],$town[$rr[$j+1]]);
    }
  }
  echo ($dist/count($ret))."\n";


Measured memory_bytes: 23544
def main():
    a = raw_input().strip()
    l = len(a)
    if l < 6:
        s = set()
        s.add(a)
        q = [a]
        oa = ord('a')
        while q:
            a = q.pop()
            for i in xrange(l - 1):
                if a[i] != a[i+1]:
                    t = chr(oa + 3 - (ord(a[i]) - oa) - (ord(a[i+1]) - oa))
                    na = a[:i] + t * 2 + a[i+2:]
                    if na not in s:
                        s.add(na)
                        q.append(na)
        print len(s)
        return
    t = a[0] * l
    if t == a:
        print 1
        return
    x = 0
    for c in a:
        if c == 'b':
            x += 1
        elif c == 'c':
            x += 2
    ans = 0
    if all(a[i] != a[i+1] for i in xrange(l - 1)):
        ans += 1
    mod = 998244353
    dp = (1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
    for i in xrange(l - 1):
        s = (dp[-1] + dp[-2] + dp[-3]) % mod
        dp = ((dp[3]+dp[6])%mod,(dp[4]+dp[7])%mod,(dp[5]+dp[8])%mod,(dp[2]+dp[8])%mod,(dp[0]+dp[6])%mod,(dp[1]+dp[7])%mod,(dp[1]+dp[4])%mod,(dp[2]+dp[5])%mod,(dp[0]+dp[3])%mod,(dp[0]+dp[5]+dp[7]+s)%mod,(dp[1]+dp[3]+dp[8]+s)%mod,(dp[2]+dp[4]+dp[6]+s)%mod)
    print (ans + dp[9+x%3]) % mod
main()


Measured memory_bytes: 3204
# 入力
a, b = map(str, input().split())

# 処理&出力
if a == 'H' and b == 'H':
    print('H')
elif a == 'H' and b == 'D':
    print('D')
elif a == 'D' and b == 'H':
    print('D')
elif a == 'D' and b == 'D':
    print('H')

Measured memory_bytes: 8856
#include<bits/stdc++.h>
 using namespace std;
 #define rep(i, c) for(int i = 0; i < (int)c; i++)
 const int inf = 1000000000; // 10^9

 int main() {
 int N;
 cin >> N;
 vector<int> X(N);
 rep(i, N) cin >> X[i];
 int ans = inf;
 for(int i = 1; i <= 100; i++) { // L やR の計算が不要
     int cost = 0;
 rep(j, N) cost += (X[j] - i) * (X[j] - i);
 ans = min(ans, cost);
 }
 cout << ans << endl;
 return 0; }


Measured memory_bytes: 3580
function Main(s){
  s = s.split("\n");
  var n = +s[0];
  var t = s[1].split(" ").map(a=>+a);
  var v = s[2].split(" ").map(a=>+a);
  var l = Array(n*400+2).fill(0);
  var k = 0;
  for(var i = 0; i < n; i++){
    for(var j = 0; j < t[i]*2; j++){
      k++;
      if(l[k-1] < v[i])l[k] = l[k-1] + 0.5;
      else if(l[k-1] > v[i])l[k] = v[i];
      else l[k] = l[k-1];
    }
  }
  l[k] = 0;
  for(i = n-1; i >= 0; i--){
    for(j = 0; j < t[i]*2; j++){
      k--;
      if(l[k+1] < v[i])l[k] = Math.min(l[k+1] + 0.5, l[k]);
      else if(l[k+1] > v[i])l[k] = Math.min(v[i], l[k]);
      else l[k] = Math.min(l[k+1], l[k]);
    }
  }
  var ans = 0.125;
  for(i = 1; l[i]; i++)ans += (l[i] + l[i+1]) * 0.25;
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 10316
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

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

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::map<int,int> map1,map2;
	rep(i,n) {
		map1[i+a[i]]++;
		map2[i-a[i]]++;
	}
	int ans=0;
	for(auto x:map1) {
		ans+=map2[x.first]*x.second;
	}
	print(ans);
	return 0;
}


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

import math

def C(n1, n2):
    ans = 1
    for i in range(n1, n1-n2, -1):
        ans *= i
    for j in range(1, n2+1):
        ans //= j
    return ans

N, A, B = map(int, input().split())
Vs = list(map(int, input().split()))
Vs.sort()
Vs.reverse()

avg = 0.0
way = 0
for num_of_choice in range(A, B + 1):
    choiced = []
    for n in range(num_of_choice):
        choiced.append(Vs[n])
    if choiced[0] == choiced[-1]:
        avg = choiced[0]
        way += C(Vs.count(choiced[0]), num_of_choice)
    else:
        if way != 0:
            break
        border = choiced[-1]
        n1 = Vs.count(border)
        n2 = choiced.count(border)
        avg = sum(choiced) / num_of_choice
        way = C(n1, n2)
        break

print("{:.12f}".format(avg))
print(way)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
const int max = 100004;
std::vector<bool> prime;

bool chack(int n){
    if(n %2 == 0)return false;
    return (prime[(n + 1) / 2] && prime[n]);
}


int main()
{
    prime.resize(max,true);
    prime[0] = false;
    prime[1] = false;
    for(int i = 2; i < max; i++){
        if(prime[i]){
            for(int j = i + i; j < max; j += i)prime[j] = false;
        }
    }
    //累積和
    std::vector<int> sum(100001);
    for(int i = 1; i < 100001; i++){
        sum[i] = sum[i-1] + chack(i-1);
    }
    int q;
    std::cin >> q;
    std::vector<std::pair<int,int>> query(q);
    for(int i = 0; i < q; i++)std::cin >> query[i].first >> query[i].second; 
    for(int i = 0; i < q; i++){
        int l = query[i].first,r = query[i].second;
        r++;
        std::cout << sum[r] - sum[l] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int k[101]={};
  k[a]++;
  k[b]++;
  k[c]++;
  int ans=0;
  rep(i,101){
    if(k[i]>=1)ans++;
  }
  cout << ans << endl;
}

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

int main() {
        int t[10] = {};
        int a;
        for (int i = 0; i < 3; ++i) {
                cin >> a;
                t[a]++;
        }

        for (int i = 0; i < 10; ++i) {
                if (t[i] == 2) {
                        cout << "Yes" << endl;
                        return 0;
                }
        }
        cout << "No" << 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[] data = new String[2];

    data[0] = "2019/04/30";
    data[1] = sc.nextLine();

    Arrays.sort(data);

    if (data[1].equals("2019/04/30")) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }
  }
}


Measured memory_bytes: 21716