akhauriyash/Code-Regression huggingface dataset:
/*
* @author:  codancer
* @createTime:  time
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
string all[4]={"AC","WA","TLE","RE"};
int main(){
	map<string,int> mps;
	int n;
	string s;
	cin>>n;
	rep(i,1,n){
		cin>>s;
		mps[s]++;
	}
	for(int i=0;i<4;i++){
		cout<<all[i]<<" x "<<mps[all[i]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] x = new int[m];
		for (int i = 0; i < m; i++) {
			x[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(x);

		int[] z = new int[m - 1];

		if (n >= m) {
			out.println(0);
			return;
		}

		for (int i = 1; i < x.length; i++) {
			z[i - 1] = (x[i] - x[i - 1]);
		}

		Arrays.sort(z);

		int ans = x[x.length - 1] - x[0];
		for (int i = 0; i < n - 1; i++) {
			ans -= z[z.length - 1 - i];
		}

		out.println(ans);

	}

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

}


Measured memory_bytes: 48520
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N, W = map(int, readline().split())
    wv = map(int, read().split())
    dp = np.zeros(W + 1, np.int64)

    for w, v in zip(wv, wv):
        np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

    print(dp.max())


if __name__ == '__main__':
    main()

Measured memory_bytes: 14604
#include <iostream>
#include <vector>
#include <limits>
#include <queue>
#include <utility>
#include <tuple>

using namespace std;

constexpr int MAX = numeric_limits<int>::max();

struct Compare
{
	bool operator()(const tuple<int, int, int>& t1,
		const tuple<int, int, int>& t2)
	{
		return get<2>(t1) > get<2>(t2);
	}
};

void neighbour(int& h, int& w, int dir)
{
	switch (dir)
	{
	case 0:
		h++;
		break;
	case 1:
		h--;
		break;
	case 2:
		w++;
		break;
	case 3:
		w--;
		break;
	}
}

int main()
{
	int h, w;
	cin >> h >> w;
	int ch, cw;
	cin >> ch >> cw;
	ch -= 1;
	cw -= 1;
	int dh, dw;
	cin >> dh >> dw;
	dh -= 1;
	dw -= 1;
	vector<vector<char>> field(h, vector<char>(w));
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> field[i][j];

	vector<vector<int>> dist(h, vector<int>(w, MAX));
	dist[ch][cw] = 0;
	vector<vector<bool>> visited(h, vector<bool>(w, false));

	Compare comp;
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, Compare> q(comp);
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			q.push({ i, j, dist[i][j] });

	while (!q.empty())
	{
		tuple<int, int, int> min = q.top();
		q.pop();
		int cur_h = get<0>(min);
		int cur_w = get<1>(min);
		int cur_dist = get<2>(min);
		if (visited[cur_h][cur_w])
			continue;
		if (cur_dist == MAX)
		{
			cout << -1 << endl;
			break;
		}

		for (int dir = 0; dir < 4; dir++)
		{
			int new_h = cur_h;
			int new_w = cur_w;
			neighbour(new_h, new_w, dir);
			if (new_h < 0 || new_h >= h || new_w < 0 || new_w >= w ||
				field[new_h][new_w] == '#')
				continue;
			int new_dist = cur_dist;
			if (new_dist < dist[new_h][new_w])
			{
				dist[new_h][new_w] = new_dist;
				q.push({ new_h, new_w, new_dist });
			}
		}
		for (int i = -2; i <= 2; i++)
			for (int j = -2; j <= 2; j++)
			{
				int new_h = cur_h + i;
				int new_w = cur_w + j;
				if (new_h < 0 || new_h >= h || new_w < 0 || new_w >= w ||
					field[new_h][new_w] == '#')
					continue;
				int new_dist = cur_dist + 1;
				if (new_dist < dist[new_h][new_w])
				{
					dist[new_h][new_w] = new_dist;
					q.push({ new_h, new_w, new_dist });
				}
			}

		visited[cur_h][cur_w] = true;
		if (cur_h == dh && cur_w == dw)
		{
			cout << dist[cur_h][cur_w] << endl;
			break;
		}
	}
}

Measured memory_bytes: 20636
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, d): (usize, i64) = read();
    let di: Vec<i64> = readnc();
    let q: usize = read();
    let qi: Vec<usize> = readnc();


    let mut left = vec![0; n+1];
    left[0] = d;
    for i in 0..n {
        left[i+1] = min(left[i], (left[i] - di[i]).abs());
    }

    let mut can_zero = vec![0; n+1];
    for i in (0..n).rev() {
        if di[i] <= can_zero[i+1] + 1 {
            can_zero[i] = can_zero[i+1] + di[i];
        } else if di[i] < (can_zero[i+1] + 1) * 2 {
            can_zero[i] = di[i] + can_zero[i+1];
        } else {
            can_zero[i] = can_zero[i+1];
        }
    }

    for i in 0..q {
        let l = qi[i] - 1;
        if left[l] > can_zero[l+1] {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}

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

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

int arr[n];
for(int index=0;index<n;index++)
cin>>arr[index];

if(k>=n)
cout<<0<<endl;
else
{
    sort(arr,arr+n);
    ll ans=0;
    for(int index=0;index<(n-k);index++)
    ans+=(ll)arr[index];
    cout<<ans<<endl;
}



    return 0;
}


Measured memory_bytes: 1024
s = input()
n = int(input())
methods = {'print': lambda s, b, e: (s, print(s[b:e+1])),
           'reverse': lambda s, b, e: (s[:b] + s[e:b-len(s)-1:-1] + s[e+1:],),
           'replace': lambda s, b, e, r: (s[:b] + r + s[e+1:],)}
for _ in range(n):
    args = input().split(' ')
    method = args[0]
    args[1] = int(args[1])
    args[2] = int(args[2])
    s = methods[method](s, *args[1:])[0]

Measured memory_bytes: 7724
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	scanner.Split(bufio.ScanWords)
	a := make([]int, 8)
	for i := 0; i < 8; i++ {
		a[i] = nextInt()
	}
	s := 0
	for i := 0; i < 4; i++ {
		s += a[i]
	}
	t := 0
	for i := 4; i < 8; i++ {
		t += a[i]
	}
	fmt.Println(max(s, t))
}



Measured memory_bytes: 1060
<?php
// クラス使うならこんな感じで。参考にしてみてください。
// 行列用のMatrixクラス、ベクトル用のVectorクラス、計算するCalculatorをクラスで定義して解いてみました。

class Matrix
{
    private $number_of_row;
    private $number_of_column;
    private $elements = array();
    
    public function __construct($number_of_row, $number_of_column)
    {
        $this->number_of_row = $number_of_row;
        $this->number_of_column = $number_of_column;
        for ($line = 1; $line <= $this->number_of_row; $line++) {
            array_push($this->elements, explode(" ", trim(fgets(STDIN))));
        }
    }

    public function getElements()
    {
        return $this->elements;
    }
}

class Vector
{
    private $length;
    private $elements = array();
    
    public function __construct($length)
    {
        $this->length = $length;
        for ($line = 1; $line <= $this->length; $line++) {
            array_push($this->elements, trim(fgets(STDIN)));
        }
    }

    public function getElements()
    {
        return $this->elements;
    }
}

class Calculator
{
    private $matrix;
    private $vector;
    private $result = array();

    public function __construct()
    {
        list($n, $m) = explode(" ", trim(fgets(STDIN)));
        $this->matrix = new Matrix($n, $m);
        $this->vector = new Vector($m);
    }

    // ベクトルの内積計算するメソッド
    public function statsStatInnerproduct($vector_a, $vector_b)
    {
        $sum = 0;
        foreach ($vector_a as $index => $element) {
            $sum += $element * $vector_b[$index];
        }
        return $sum;
    }

    // 行列とベクトル積を計算するメソッド
    public function calculateProduct()
    {
        foreach ($this->matrix->getElements() as $matrix_elements) {
            print($this->statsStatInnerproduct($matrix_elements, $this->vector->getElements()) . PHP_EOL);
        }
    }
}

$calculator = new Calculator();
$calculator->calculateProduct();



Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,M;
    cin>>N>>M;

    int A[M],B[M];
    Graph G(N);
    rep(i,M){
        cin>>A[i]>>B[i];
        A[i]--;
        B[i]--;
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    queue<int> q;
    vector<int> dist(N,INF);
    vector<int> an(N,-1);
    dist[0]=0;
    q.push(0);
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(auto nv:G[v]){
            if(dist[nv]<=dist[v]+1)continue;
            dist[nv]=dist[v]+1;
            an[nv]=v;
            q.push(nv);
        }
    }
    string ans="Yes";
    rep(i,N){
        if(dist[i]==INF) {
            ans="No";
            break;
        }
    }
    cout << ans << endl;
    if(ans=="Yes"){
        for(int i=1;i<N;i++){
            cout << an[i]+1 << endl;
        }
    }





}


Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5+10;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int n,k;
int dp[N];
int main()
{  fast
dp[0]=1;
cin>>n>>k;
for(int i=0;i<n;i++)
{
	int lim;
	cin>>lim;
	vector<int> v(k+1);
	for(int j=k;j>=0;j--)
	{
		int l=j+1;
		int r=j+min(lim,k-j);
		if(l<=r)
		{

		v[l]+=dp[j];
		if(r+1<=k)
		v[r+1]-=dp[j];if(v[r+1]<0)v[r+1]+=mod;}
	}
	int sum=0;
	for(int j=0;j<=k;j++)
	{
		sum+=v[j];
		if(sum>=mod)sum-=mod;
		dp[j]+=sum;
		if(dp[j]>=mod)
		dp[j]-=mod;
	}
}
	cout<<dp[k];
	


}

Measured memory_bytes: 1024
def solve():
    H,W,K = map(int,input().split())

    for k in range(0,H+1):
        for l in range(0,W+1):
            if k*(W-l)+l*(H-k) == K:
                print('Yes')
                return
    else:
        print('No')
if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
import math
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = 0
t = 0
u = 0
v = []

for i in range(n):
	x = abs(a[i]-b[i])
	s += x
	t += x**2
	u += x**3
	v.append(x)

print("{:.10f}".format(s))
print("{:.10f}".format(math.sqrt(t)))
print("{:.10f}".format(u**(1/3)))
print("{:.10f}".format(max(v)))
	
	



Measured memory_bytes: 5696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(abs(b-a)>abs(c-a))cout<<"B"<<endl;
	else cout<<"A"<<endl;
	return 0;
}


Measured memory_bytes: 256
class QuickSort
  def solve
    n    = gets.chomp.to_i
    a = Array.new
    b = Array.new
    n.times do
      m, i = gets.split(/\s+/)
      a << [m, i.to_i]
      b << [m, i.to_i]
    end

    qsort(a, 0, n-1)

    stable = true
    (0..n-2).each do |i|
      if (a[i][1] == a[i+1][1])
        if b.index(a[i]) > b.index(a[i+1])
          stable = false
          break
        end
      end
    end

    if stable
      puts("Stable")
    else
      puts("Not stable")
    end

    a.each do |x|
      puts x.join(" ")
    end
  end

  def qsort(a, p, r)
    if p < r
      q = partion(a, p, r)
      qsort(a, p, q-1)
      qsort(a, q+1, r)
    end
  end

  def partion(a, p, r)
    x = a[r][1]
    i = p - 1
    (p...r).each do |j|
      if a[j][1] <= x
        i += 1
        a[i], a[j] = a[j], a[i]
      end
    end
    a[i+1], a[r] = a[r] , a[i+1]
    return i+1
  end
end

if $0 == __FILE__
  QuickSort.new.solve
end

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    int sum=0;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    double w;
    w=(double)sum/(4*m);

    sort(a.begin(),a.end(),greater<int>());
    if(a[m-1]>=w){cout<<"Yes";}
    else{cout<<"No";}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b,c; cin >> a >> b >> c;
    rep(i,10) {
        c = a * c - b;
        cout << c << endl;
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); 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 (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    ll ans = -1;
    REP(i,N+1){
        //printf("%d : %lld, %f\n", i, ll(i*1.08), i*1.08);
        if(ll(i*1.08) == N){
            ans = i;
            break;
        }
    }

    if(ans == -1){
        cout << ":(" << endl;
    }
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {

	int A, B, C, D;
	int sum = 0;

	cin >> A >> B >> C >> D;

	if (A > B) {

		sum = sum + B;

	}

	else

		sum = sum + A;

	if (C > D) {

		sum = sum + D;

	}

	else

		sum = sum + C;

	cout << sum << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    int a, b;
    cin >> a >> b;
    if ( a + b == 15 ) {
        cout << "+" << endl;
    }
    else if ( a * b == 15 ) {
        cout << "*" << endl;
    }
    else {
        cout << "x" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

// 標準入力から改行かスペースまで読み取り、数字として返す
int get_num() {
    // 10文字+区切り文字までしか受け付けられない
    char s[11];
    int i, n;
    for (i = 0; i < sizeof(s); i++) {
        s[i] = getchar();
        if (s[i] == ' ' || s[i] == '\n') {
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}

int main(void) {
    int A, B, N, i, minimum = INT_MAX, sum;

    N = get_num();
    
    for (i = 1; i < N; i++) {
        A = i;
        B = N - A;
        sum = 0;
        while(A > 0) {
            sum += A % 10;
            A /= 10;
        }
        while(B > 0) {
            sum += B % 10;
            B /= 10;
        }
        if (minimum > sum) {
            minimum = sum;
        }
    }
    
    printf("%d\n", minimum);
    
    return 0;
}


Measured memory_bytes: 128
A, B, C = map(int,input().split())
co = 0
while True:
    if A%2 == 1 or B%2 == 1 or C%2 == 1:
        print(co)
        break
    elif A == B == C:
        print(-1)
        break
    ca = B/2 + C/2
    cb = A/2 + C/2
    cc = A/2 + B/2
    A = ca
    B = cb
    C = cc
    co = co + 1


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int g[15][15];
 
int main() {
  int n;
  cin >> n;
  rep(i,n)rep(j,n) g[i][j] = -1;
  rep(i,n) {
    int m;
    cin>>m;
    rep(j,m) {
      int a, x;
      cin >> a >> x;
      --a;
      g[i][a] = x;
    }
  }
  int ans = 0;
  rep(i,1<<n) {
    vector<int> d(n);
    rep(j,n) if (i>>j&1) {
      d[j] = 1;
    }
    bool ok = true;
    rep(j,n) {
      if (d[j]) {
        rep(k,n) {
          if (g[j][k] == -1) continue;
          if (g[j][k] != d[k]) ok = false;
        }
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
const int N=100005;
int n, m, T;
int uu[N], dd[N], cc[N];
int dp[N][11];
vector<int> g[N];
void dfs(int u, int d, int c) {
	if(d<0) return;
	if(dp[u][d]) return;
	dp[u][d]=c;
	dfs(u, d-1, c);
	for(int i=0; i<g[u].size(); i++) {
		dfs(g[u][i], d-1, c);
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i=0; i<m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	scanf("%d", &T);
	for(int i=T-1; i>=0; i--) scanf("%d%d%d", &uu[i], &dd[i], &cc[i]);
	for(int i=0; i<T; i++) {
		uu[i]--;
		dfs(uu[i], dd[i], cc[i]);
	}
	for(int i=0; i<n; i++) {
		printf("%d\n", dp[i][0]);
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e7) + 5;
const double EPS = 1e-8;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

vector<bool> isprime;
vector<int> p;

void solve(int x){
    isprime.resize(x+1,true);
    isprime[0] = false;
    isprime[1] = false;
    for(int i=2;i*i<=x;i++){
        if(isprime[i]){
            for(int j=2;i*j<=x;j++){
                isprime[i*j] = false;
            }
        }
    }
}

int main() {
    int n, cnt = 0;
    cin >> n;
    solve(n+5);
    for(int i = 1;i<=n;i++)if(isprime[i])p.push_back(i);
    for(auto i : p){
        if(i>n)break;
        if(isprime[i+2])cnt += 2;
    }
    cout << cnt << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;

const int N = 100100;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i - 1] + a[i] > x) {
            ans += a[i - 1] + a[i] - x;
            a[i] -= min(a[i], a[i - 1] + a[i] - x);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll n, m, k;

int main() {
    cin >> n >> m >> k;
    vector<ll> avec(n, 0);
    vector<ll> bvec(m, 0);
    for(int i = 0; i < n; ++i) cin >> avec.at(i);
    for(int i = 0; i < m; ++i) cin >> bvec.at(i);
    vector<ll> asum(n+1, 0);
    vector<ll> bsum(m+1, 0);
    for(int i = 0; i < n; ++i) {
        asum.at(i+1) = asum.at(i) + avec.at(i);
    }
    for(int i = 0; i < m; ++i) {
        bsum.at(i+1) = bsum.at(i) + bvec.at(i);
    }

    int cnt = 0;
    for(int i = 0; i <= n; ++i) {
        // aはi冊読む
        int now = i;
        ll sum = asum.at(i);
        if(sum > k) continue;
        ll rest = k-sum;
        int bno = upper_bound(bsum.begin(), bsum.end(), rest) - bsum.begin();
        now += (bno-1);
        chmax(cnt, now);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 9592
L = str(input())

n = len(L)
MOD = 10**9+7
 
dp = [[0]*2 for i in range(n+1)]
dp[0][0] = 1

for i in range(n):
  for k in range(2):
    nd = int(L[i])
    for d in range(2):
      ni = i+1
      nk = k
      if k == 0:
        if d > nd:
          continue
        elif d < nd:
          nk = 1
        else:
          pass
      if d == 1:
        dp[ni][nk] += (dp[i][k]*2)%MOD
      else:
        dp[ni][nk] += (dp[i][k])%MOD
        
#print(dp)
print(sum(dp[-1])%MOD)

Measured memory_bytes: 19996
from fractions import *
N, M = map(int, input().split())

l = []
r = []
for i in range(M):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

if min(r)-max(l) < 0:
    print(0)
else:
    print(min(r)-max(l)+1)




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

int main(int argc, char* argv[]){
    string S;
    int ans = 0;
    cin >> S;
    rep(i, 3){
        if(S[i] == 'o') ans++;
    }
    cout << 700 + 100 * ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));


/*	int bfs(int x, int y,vvi &A,vvi flag) {
		queue<pii> que;
		que.push(pii(x, y));
		while (que.size()) {
			pii p = que.front(); que.pop();
			AFOR(i, 4) {
				int nx = p.first + dx[i]; int ny = p.second + dy[i];
				if (0 <= nx && nx < N && 0 <= ny && ny < N) {
					if (A.at(p.first).at(p.second) + flag.at(p.first).at(p.second) < A.at(nx).at(ny)) {
						A.at(nx).at(ny) = A.at(p.first).at(p.second) + flag.at(p.first).at(p.second);
						que.push(pii(nx, ny));
					}
				}
			}
		}
		return 0;
	}
	*/
	/*int gcd(int p, int q){
		while(q != 0){
		int r = p % q;
		p = q;
		q = r;
		}
	return p;
	}*/
int N;
long long A[200100];
int L[200100];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long  ans = 0;
	long long node = 1;
	long long leaf = 1;
	long long sum = 0;
	cin >> N;
	if (N == 0) { 
		cin >> A[0];
		if (A[0] == 1) { ans = 1; 
		}
		else ans = -1; 
	}
	else {
		AFOR(i, N + 1) {
			cin >> A[i];
			sum += A[i];
		}
		if (A[0] >= 1) { ans = -1; }
		else {
			FOR(i, 1, N - 1) {
				sum -= A[i];
				leaf = min(leaf * 2 - A[i], sum);
				if (leaf < 0) {
					ans = -1;
				}
				node += A[i] + leaf;

				//cout << node << endl;
			}
		}
		//Nの処理
		if (ans >= 0) {
			if (leaf * 2 >= A[N] && leaf <= A[N]) {
				node += A[N];
				ans = node;
			}
			else ans = -1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7576
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using myui = uint64_t;
using myint = int64_t;

template<typename T>
T diff(const T& a, const T& b) {
    return a > b ? a - b : b - a;
}

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

    {
        myui a, b, c;
        cin >> a >> b >> c;
        bool ret;
        if (a > b) {
            ret = a >= c && c >= b;
        } else {
            ret = a < c && c < b;
        }
        cout << (ret ? "Yes" : "No") << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def solve(s):
    d = {}
    for i, c in enumerate(s):
        d.setdefault(c, []).append(i)
    for k in d:
        d[k].sort()
        for i in range(len(d[k]) - 1):
            if d[k][i + 1] - d[k][i] <= 2:
                return (d[k][i] + 1, d[k][i + 1] + 1)
    return (-1, -1)


s = input()
print(*solve(s))

Measured memory_bytes: 43376
package main

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

func main() {
	var X, Y int
	var err error
	var target int

	scanner := bufio.NewScanner(os.Stdin)

	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	X, err = strconv.Atoi(scanner.Text())

	if err != nil {
		panic(err)
	}

	scanner.Scan()
	Y, err = strconv.Atoi(scanner.Text())

	if err != nil {
		panic(err)
	}

	for i := 0; i < X+1; i++ {
		target = i*2 + (X-i)*4
		if Y == target {
			fmt.Println("Yes")
			os.Exit(0)
		}
	}

	fmt.Println("No")
}


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

int main(){
  string a,b;
  cin>>a>>b;
  int num=0;

 for(int i = 0;i<a.size();i++){
  num+=(a.at(i)-'0')*pow(10,a.size()-i-1);
 }
 num*=pow(10,(b.size()));
 for(int i = 0;i<b.size();i++){
  num+=(b.at(i)-'0')*pow(10,b.size()-i-1);
 }
  string ans ="No";
  int tmp = sqrt(num);
  if(tmp*tmp==num)ans = "Yes";
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M;

int main(void){
    
    scanf("%d %d", &N, &M);
    printf("%.0f\n", (1900 * M + 100 * (N - M)) * pow(2, M));
    
    return 0;
}



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

int main(){
    int N, K;
    cin >> N >> K;
    bool num[N + 1];
    for(int i = 1; i< N + 1; i++) num[i] = false;
    for(int i = 0; i < K; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            num[a] = true;
        }
    }

    int count = 0;
    for(int i = 1; i < N + 1; i++){
        if(num[i] == false) count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


signed main(){
  int r, D, x;cin >> r >> D >> x;
  rep(i,10){
    x = x*r-D;
    cout << x << endl;
  }
  return 0;
}






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

int main()
{
    int n, m;
    int a[100][100], b[100];
    int result[100] = {0};

    cin >> n >> m;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            result[i] += a[i][j] * b[j];
        }
    }

    for (int i = 0; i < n; i++) {
        cout << result[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI atan(1)*4
typedef long long int ll;
using namespace std;
int main(){
	io;
	char s[4];
	cin >> s;
	if(s[1] == 'B'){
		cout << "ARC";
	}
	else
		cout << "ABC";
	return 0;
} 

Measured memory_bytes: 3640
#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime> 
#include <stack>

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

const int MAXN = 200001;

int a[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	int n, c, k;
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int p = 0;
	int cur = 0;
	while (p < n)
	{
		cur++;
		p = min(p + c, (int)(upper_bound(a, a + n, a[p] + k) - a));
	}
	cout << cur << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
 
int main() {
ll n,k;
cin>>n;
ll t[n+1]={};
ll x[n+1]={};
ll y[n+1]={};
ll f=0;
for(ll i=1; i<=n; i++){
cin>>t[i]>>x[i]>>y[i];}
for(ll i=1; i<=n; i++){
ll dx=abs(x[i]-x[i-1]);
ll dy=abs(y[i]-y[i-1]);
ll dt=abs(t[i]-t[i-1]);
if(dt<dx+dy){
cout<<"No"<<endl;
f++;
break;}
else if((dt-dx-dy)%2==0){
continue;}
else{
cout<<"No"<<endl;
f++;
break;}}
if(f==0){
cout<<"Yes"<<endl;}}


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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while(a>=b){
        b<<=1;
        k--;
    }
    while(b>=c){
        c <<= 1;
        k--;
    }
    cout << (k>=0 ? "Yes" : "No") << endl;
    return 0;
}

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

void add(vector<vector<int> >& C, vector<vector<int> >& D, vector<bool>& flag, int x, int depth, int K){
  if(flag[x]) return;
  if(depth > K) return;

  D[depth].push_back(x);
  flag[x] = true;

  int num_connect = C[x].size();
  for(int i=0; i<num_connect; ++i){
    add(C, D, flag, C[x][i], depth+1, K);
  }

  return;
};

void add(vector<vector<int> >& C, vector<vector<int> >& D, vector<bool>& flag, int x1, int x2, int depth, int K){
  D[depth].push_back(x1);
  D[depth].push_back(x2);
  flag[x1] = true;
  flag[x2] = true;

  int num_connect = C[x1].size();
  for(int i=0; i<num_connect; ++i){
    add(C, D, flag, C[x1][i], depth+1, K);
  }
  num_connect = C[x2].size();
  for(int i=0; i<num_connect; ++i){
    add(C, D, flag, C[x2][i], depth+1, K);
  }

  return;
};

int main(){
  int N, K;
  vector<int> A, B;
  vector<vector<int> > C;
  cin >> N >> K;
  A.resize(N-1);
  B.resize(N-1);
  C.resize(N);
  for(int i=0; i<N-1; ++i){
    cin >> A[i] >> B[i];
    C[A[i]-1].push_back(B[i]-1);
    C[B[i]-1].push_back(A[i]-1);
  }

  vector<vector<vector<int> > > D;
  D.resize(N);
  for(int i=0; i<N; ++i){
    D[i].resize(N);
  }

  int min=N;
  for(int i=0; i<N; ++i){
    vector<bool> FLAG(N);
    for(int j=0; j<N; ++j){
      FLAG[j]=false;
    }

    if(K%2==0){
      add(C, D[i], FLAG, i, 0, K/2);
    }else{
      if(i==N-1) continue;
      add(C, D[i], FLAG, A[i]-1, B[i]-1, 0, (K-1)/2);
    }

    int count = 0;
    for(int j=0; j<N; ++j){
      if(FLAG[j] == true){
        count++;
      }
    }

    count = N - count;
    if(count < min){
      min = count;
    }

  }

  /*
  for(int i=0; i<N; ++i){
    for(int j=0; j<C[i].size(); ++j){
      cout << C[i][j] << " ";
    }
    cout << "\n";
  }
  cout << endl;
  */

  /*
  for(int i=0; i<N; ++i){
    cout << i << "th initial state" << endl;;
    for(int j=0; j<N; ++j){
      cout << j << " depth " << endl;
      for(int k=0; k<D[i][j].size(); ++k){
        cout << D[i][j][k] << " ";
      }
      cout << endl;
    }
  }
  cout << endl;
  */

  cout << min << endl;

  return 0;
}

Measured memory_bytes: 156800
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int gcd(int a,int b){
  if(a > b){
    if(a % b == 0){
      return b;
    }
    else{
      return gcd(b,a % b);
    }
  }
  else{
    if(b % a == 0){
      return a;
    }
    else{
      return gcd(a,b % a);
    }
  }
}

int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int k;

  cin >> k;
  lll sum = 0;
  int gcd_ab,gcd_abc;
  for(ii=1;ii<=k;ii++){
    for(jj=1;jj<=k;jj++){
      for(kk=1;kk<=k;kk++){
        gcd_ab = gcd(ii,jj);
        gcd_abc = gcd(gcd_ab,kk);
        sum += gcd_abc;
      }
    }
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;

auto main() -> i32 {
	i32 n;
	scanf("%d", &n);
	switch (n % 10) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9: {
			puts("hon");
			break;
		}
		case 0:
		case 1:
		case 6:
		case 8: {
			puts("pon");
			break;
		}
		case 3: {
			puts("bon");
			break;
		}
		default: {
			throw;
		}
	}
	return 0;
}


Measured memory_bytes: 3184
n,m=map(int,input().split())
if 2*n>=m:
    print(m//2)
else:
    k1 = (m-n*2)//4
    k2 = k1+1
    k3 = max(k1-1,0)
    r1 = min(n+k1,(m-k1*2)//2)
    r2 = min(n+k2,(m-k2*2)//2)
    r3 = min(n+k3,(m-k3*2)//2)
    print(max(r1,r2,r3))


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

int main() {
	int n;
	cin >> n;
	vector<int> ans(n,0);
	rep(i,n-1) {
		int a;
		cin >> a;
		ans[a-1]++;
	}
	rep(i,n) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    char c[510][510];
    char a[510][510];
    char b[510][510];

    int H, W;
    cin >> H >> W;

    rep(i,0,H) rep(j,0,W) {
        bool period_a = false, period_b = false;
        if(j == 0) {a[i][j] = '#'; period_a = true;}
        else if(j == W-1) {b[i][j] = '#'; period_b = true;}
        else if(i % 2 == 0) {a[i][j] = '#'; period_a = true;}
        else if(i % 2 == 1) {b[i][j] = '#'; period_b = true;}
        
        if(!period_a) a[i][j] = '.';
        if(!period_b) b[i][j] = '.';
    }

    rep(i,0,H) rep(j,0,W) {
        cin >> c[i][j];
        if(i % 2 == 0 && c[i][j] == '#') b[i][j] = '#';
        else if(i % 2 == 1 && c[i][j] == '#') a[i][j] = '#';
    }

    rep(i,0,H) {
        rep(j,0,W) {
            cout << a[i][j];
        }
        cout << endl;
    }

    cout << endl;

    rep(i,0,H) {
        rep(j,0,W) {
            cout << b[i][j];
        }
        cout << endl;
    }

    /* 確認用
    cout << endl;
    rep(i,0,H) {
        rep(j,0,W) {
            if(a[i][j] == '#' && b[i][j] == '#') cout << "#";
            else cout << ".";
        }
        cout << endl;
    }
    */

    return 0;
}

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

int main(){
  set<int> a;
  int n; cin >> n;
  int d;
  for(int i=0; i<n; ++i){
    cin >> d;
    a.insert(d);
  }
  cout << a.size() << "\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        Integer[] x = new Integer[n];
        Arrays.setAll(x, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int result = 0;
        for (int i = 0; i < n; i++) {
            int a = x[i] * 2;
            int b = Math.abs(k - x[i]) * 2;
            result += Math.min(a, b);
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 26964
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

template <class T> struct Dinic {
    
    struct Edge {
        int to,rev; T cap;
        Edge (int t, int r, T c) : to(t), rev(r), cap(c) {}
    };
    
    vector < vector< Edge > > G;
    vector < int > level, iter;
    const T INF = numeric_limits < T > ::max();
    Dinic (int n) : G(n), level(n, 0), iter(n, 0) {}
    
    void add_edge(int from, int to, T cap) {
        G[from].push_back(Edge(to, (int)(G[to].size()), cap));
        G[to].push_back(Edge(from, (int)(G[from].size()) - 1, 0));
    }
    
    void bfs(int s) {
        fill(level.begin(), level.end(), -1);
        queue < int > que({s});
        level[s] = 0;
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int i = 0; i < G[v].size(); i++) {
                Edge& e = G[v][i];
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    
    T dfs(int cur, int t, T f) {
        if (cur == t) return f;
        for (int &i = iter[cur]; i < G[cur].size(); i++) {
            Edge& e = G[cur][i];
            if (e.cap > 0 && level[e.to] > level[cur]) {
                T d = dfs(e.to, t, min(f, e.cap));
                if (d == 0) continue;
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return 0;
    }
    
    T max_flow(int s, int t) {
        T flow = 0, d;
        while (true) {
            bfs(s);
            if(level[t] < 0) break;
            fill(iter.begin(), iter.end(), 0);
            while ((d = dfs(s, t, INF)) > 0) {
                flow += d;
            }
        }
        return flow;
    }
    
};

int main() {

    ll N; cin >> N;
    vector < ll > a(N + 1);
    REP(i,N) cin >> a[i + 1];

    Dinic < ll > inst(1000);
    const int S = 900;
    const int T = 950;

    ll sum = 0;
    for (int i = 1; i <= N; i++) {
        if (a[i] >= 0) {
            sum += a[i];
            inst.add_edge(T, i, 0);
            inst.add_edge(i, T, a[i]);
        } else {
            inst.add_edge(S, i, -a[i]);
            inst.add_edge(i, T, 0);
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (j % i == 0 && a[i] < 0) {
                inst.add_edge(i, j, 1000000000000);
            }
        }
    }

    ll f = inst.max_flow(S, T);
    cout << sum - f << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


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

  map<int, int> prime;
  for(int x = 2; x <= n; ++x) {
    int _x = x;
    for(int i = 2; i*i <= _x; ++i) {
      while(_x % i == 0) {
        ++prime[i];
        _x /= i;
      }
    }
    if(_x != 1) ++prime[_x];
  }

  vector<int> vec;
  for(auto x : prime) vec.push_back(x.second);
  sort(ALL(vec));

  int ans = 0;

  for(int i = 0; i < vec.size(); ++i) {
    for(int j = 0; j < vec.size(); ++j) {
      for(int k = j+1; k < vec.size(); ++k) {
        if(i == j || i == k) continue;
        if(vec[i] >= 2 && vec[j] >= 4 && vec[k] >= 4) ++ans;
      }
    }
  }

  for(int i = 0; i < vec.size(); ++i) {
    for(int j = 0; j < vec.size(); ++j) {
      if(i == j) continue;
      if(vec[i] >= 2 && vec[j] >= 24) ++ans;
      if(vec[i] >= 4 && vec[j] >= 14) ++ans;
    }
  }

  for(int i = 0; i < vec.size(); ++i) if(vec[i] >= 74) ++ans;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n,first=1,last=1,f=0;
    long long ans=0,c=1,conti=0,k;
    cin>>s>>k;
    n=s.size();
    if(n==1){cout<<k/2; return 0;}
    else if(s[0]!=s[n-1]){
        for(int i=0;i<n-1;i++){
            if(s[i]==s[i+1]){c++;}
            else{conti+=c/2;c=1;}
        }
        ans+=conti*k;
        ans+=c/2*k;
        cout<<ans;
        return 0;
    }
    else{
        int ind=0,IND=n-1;
        while(ind<IND&&s[ind]==s[ind+1]){
            first++;
            ind++;
        }
        while(s[IND]==s[IND-1]&&IND>ind){
            last++;
            IND--;
        }
        if(first==n){cout<<n*k/2;return 0;}
        for(int i=ind;i<IND;i++){
            if(s[i]==s[i+1]){c++;}
            else{conti+=c/2;c=1;}
        }
        ans+=conti*k;
        ans+=first/2+(first+last)/2*(k-1)+last/2;
        cout<<ans;
    }
}

Measured memory_bytes: 256