akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e5 * 3 + 10;
vector <ll> vec;
ll q;
set<ll> cords[3];
ll curPos[SIZE], prv[3];

ll nt(char st, char nd) {
	if (st == '0') {
		if (nd == '1') return '2';
		if (nd == '2') return '1';
	}
	if (st == '1') {
		if (nd == '0') return '2';
		if (nd == '2') return '0';
	}
	if (st == '2') {
		if (nd == '1') return '0';
		if (nd == '0') return '1';
	}
}
int main() {
	fastInp;

	ll n;
	cin >> n;
	
	string s;
	cin >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') s[i] = '0';
		else if (s[i] == 'G') s[i] = '1';
		else s[i] = '2';
		cords[s[i] - '0'].insert(i);
		prv[s[i] - '0']++;
		curPos[i] = prv[s[i] - '0'];
	}

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (s[i] != s[j]) {
				ll pos = j + (j - i), pos2 = i - (j - i), pos3 = -1;
				if ((j - i) % 2 == 0) {
					pos3 = (j + i) / 2;
				}
				ll ind = nt(s[i], s[j]) - '0';
				ans += cords[ind].size();
				if (cords[ind].find(pos) != cords[ind].end()) ans--;
				if (cords[ind].find(pos2) != cords[ind].end()) ans--;
				if (cords[ind].find(pos3) != cords[ind].end()) ans--;
			}
		}
	}

	cout << ans / 6;
	return 0;
}

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

int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  if(S.at(K-1)=='A'){
    S.at(K-1)='a';
  }else if(S.at(K-1)=='B'){
    S.at(K-1)='b';
  }else{
    S.at(K-1)='c';
  }
  cout << S << endl;
}

Measured memory_bytes: 256
X, N = map(int,input().split())
if N > 0:
  P = set([int(_) for _ in input().split()])
else:
  P = set()

l_cand = None
r_cand = None
i = 0
while (l_cand is None) and (r_cand is None):
  if X - i not in P and l_cand is None:
    l_cand = X - i
  if X + i not in P and r_cand is None:
    r_cand = X + i
  i += 1
  
if l_cand is not None:
  print(l_cand)
else:
  print(r_cand)

Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

ll N;
vvll AdjList;
ll K = 0;
map<pll, ll> ec;

void dfs(ll node, ll prev, ll parent){
    K = max(K, prev);
    ll k = 1; if(prev == k) ++k;
    for(ll i = 0; i < AdjList[node].size(); ++i){
        ll v = AdjList[node][i];
        if(v == parent) continue;
        if(k == prev) ++k;
        K = max(K, k);
        ec[mp(node, v)] = k;
        ec[mp(v, node)] = k;
        dfs(v, k++, node);
    }
    return;
}

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> N;
    AdjList.resize(N);
    vpll edgelist(N-1);
    for(ll i = 0; i < N-1; ++i){
        ll u, v; cin >> u >> v; u--; v--;
        AdjList[u].pb(v);
        edgelist[i] = mp(u, v);
    }
    dfs(0, 0, -1);
    cout << K << endl;
    for(ll i = 0; i < N-1; ++i){
        cout << ec[edgelist[i]] << endl;
    }

    return 0;
}

//cikisir



Measured memory_bytes: 20864
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

string f(int x) {
  ostringstream s;
  s << setfill('0') << setw(2) << x / 3600 << ':' << setfill('0') << setw(2) << x % 3600 / 60 << ':' << setfill('0') << setw(2) << x % 60;
  return s.str();
}

void solve() {
  int t, h, s;
  while (cin >> t >> h >> s, t != -1) {
    int x = 7200 - (t * 3600 + h * 60 + s);
    cout << f(x) << endl;
    cout << f(x * 3) << endl;
  }
}

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

using namespace std;
typedef long long ll;

int main()
{
    string s;
    int n, k;
    cin >> n >> k;
    cin >> s;
    s[k - 1] = s[k - 1] + 32;
    cout << s << endl;
    return 0;
}	

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

int main() {
	long long N; cin >> N;
	vector<long long>A(N), sum(N + 1, 0);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
		sum.at(i + 1) = sum.at(i) + A.at(i);
	}
	sort(sum.begin(), sum.end());
	vector<long long>same;
	long long num = 1, to = sum.at(0);
	for (long long i = 1; i <= N; i++) {
		if (sum.at(i) == to) num++;
		else {
			same.push_back(num);
			num = 1;
			to = sum.at(i);
		}
	}
	same.push_back(num);
	long long ans = 0;
	for (long long i = 0; i < same.size(); i++) {
		ans += same.at(i) * (same.at(i) - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8328
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    ll n,k,i,j;
    string s,t;
    cin>>s>>t;

    if(((int)s.length())+1!=(int)t.length()){
        cout<<"No";
        return 0;
    }
    for(i=0;i<(int)s.length();i++){
        if(s[i]!=t[i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

    return 0;
}



Measured memory_bytes: 3620
#include <stdio.h>

int main(void)
{
    int h1, h2;
    int k1, k2;
    int sh, sk;
    int a, b, c, d;

    scanf("%d %d", &h1, &h2);
    scanf("%d %d", &k1, &k2);
    scanf("%d %d %d %d", &a, &b, &c, &d);
    sh = a * h1 + b * h2 + c * (h1 / 10) + d * (h2 / 20);
    sk = a * k1 + b * k2 + c * (k1 / 10) + d * (k2 / 20);

    if (sh > sk){
        puts("hiroshi");
    }
    else if (sh < sk){
        puts("kenjiro");
    }
    else {
        puts("even");
    }

    return 0;
}

Measured memory_bytes: 584
w,h,n=map(int,input().split())
x0=0
x1=w
y0=0
y1=h
for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x0=max(x0,x)
  elif a==2:
    x1=min(x1,x)
  elif a==3:
    y0=max(y0,y)
  elif a==4:
    y1=min(y1,y)
if y1-y0<=0 or x1-x0<=0:
  print(0)
else:
  print((y1-y0)*(x1-x0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,i;
    long sum;
    cin >> N;
    sum = 0;
    for(i=1;i<=N;i++)
    {
        if(i%15!=0 && i%3!=0 && i%5!=0)
        {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

ans = 1
flag = 0
inv = 0
for i in range(1, n):
    if inv == 0:
        if a[i] - a[i-1] > 0:
            if flag == -1:
                inv = 1
            flag = 1
        elif a[i] - a[i-1] < 0:
            if flag == 1:
                inv = 1
            flag = -1
    else:
        if a[i] - a[i-1] > 0:
            ans += 1
            flag = 1
            inv = 0
        elif a[i] - a[i-1] < 0:
            ans += 1
            flag = -1
            inv = 0

if inv == 1:
    ans += 1
    
print(ans)

Measured memory_bytes: 21456
#include <cstdio>
#include <algorithm>
#include <vector>

int main(void){

    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    std::vector<long long> v;
    if(a <= 0 && b >= 0){
        v.push_back(0LL);
    }else if(c <=0 && d >= 0){
        v.push_back(0LL);
    }

    v.push_back(1LL*a*c);
    v.push_back(1LL*a*d);
    v.push_back(1LL*b*c);
    v.push_back(1LL*b*d);

    std::sort(v.begin(),v.end());
    printf("%lld\n",v[v.size()-1]);
    return 0;
}

Measured memory_bytes: 3228
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)	   for(int i = 0; i < (n); ++i)
#define all(c)		   begin(c), end(c)
#define rall(c)		   rbegin(c), rend(c)
#define SZ(a)		   ((ll) a.size())

typedef long long		   ll;
typedef unsigned long long ull;


int main(){
  ll N,C;
  cin >> N >> C;
  vector<ll> x(N+2,0);
  vector<ll> v(N+2,0);
  rep(i,N) scanf("%lld %lld",&x[i+1],&v[i+1]);
  x[N+1]=C;

  vector<ll> A(N+1,0);
  vector<ll> B(N+1,0);
  vector<ll> maA(N+1,0);
  vector<ll> maB(N+1,0);
  vector<ll> X(N+1,0);
  vector<ll> Y(N+1,0);
  rep(i, N) A[i+1] = A[i] + v[i+1] - (x[i+1]-x[i]);
  rep(i, N) B[i+1] = B[i] + v[N-i] - ((C-x[N-i])-(C-x[N-i+1]));

  rep(i,N) maA[i+1] = max(maA[i],A[i+1]);
  rep(i,N) maB[i+1] = max(maB[i],B[i+1]);
  rep(i,N) X[i+1] = A[i+1] - x[i+1] + maB[N-i-1];
  rep(i,N) Y[i+1] = B[i+1] - (C-x[N-i]) + maA[N-i-1];
  cout << max(max(*max_element(all(A)),*max_element(all(B))),max(*max_element(all(X)),*max_element(all(Y))));

}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
long long A[1000000],B[1000000];
int main()
{
  long long i,j,n,c=0;
  scanf("%lld",&n);
  for(i=1;i<=n;i++)
  {
    scanf("%lld",&A[i]);
    B[i]=B[i-1]+A[i];

  }
  for(i=1;i<=n;i++)
  {
    c+=(A[i]*((B[n]-B[i])%1000000007));
    c%=1000000007;
  }
printf("%lld\n",c);
}


Measured memory_bytes: 6840
#include<cstdio>

using namespace std;

int func(int n){
    int sum = 0;
    while (n){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n;
    scanf("%d", &n);
    if (n % func(n) == 0) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
let modulo = 1000000007

let ( +% ) a b = let c = a + b in if c > modulo then c - modulo else c
let ( -% ) a b = if a >= b then a - b else modulo + a - b
let ( *% ) a b = a * b mod modulo


let n = read_int ()

let rec read_ints accu = function
  | 0 -> List.rev accu
  | k -> read_ints ((Scanf.scanf " %d" (fun x -> x)) :: accu) (k-1)

let tl = Array.of_list (read_ints [] n)
let al = Array.of_list (read_ints [] n)


let b = Array.make n 1


let () = match n with
  | 1 -> print_int (if tl.(0) = al.(0) then 1 else 0)
  | _ ->
  for i = 1 to n-2 do
    b.(i) <- if tl.(i-1) < tl.(i) && al.(i) > al.(i+1) then if tl.(i) = al.(i) then 1 else 0
      else if tl.(i-1) < tl.(i) then if al.(i) >= tl.(i) then 1 else 0
      else if al.(i) > al.(i+1) then if tl.(i) >= al.(i) then 1 else 0
      else (min tl.(i) al.(i))
  done;
  if al.(0) > al.(1) && al.(0) != tl.(0) then b.(0) <- 0;
  if tl.(n-1) > tl.(n-2) && al.(n-1) != tl.(n-1) then b.(n-1) <- 0;
  if tl.(n-1) != al.(0) then b.(0) <- 0;

  print_int (Array.fold_left ( *% ) 1 b);

Measured memory_bytes: 8764
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {   
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
}




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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int D = sc.nextInt();
			if (D == 0) break;
			int N = sc.nextInt();
			int M = sc.nextInt();
			int[] p = new int[N + 1];
			for (int i = 0; i < N - 1; ++i) {
				p[i] = sc.nextInt();
			}
			p[N] = D;
			Arrays.sort(p);
			int ans = 0;
			for (int i = 0; i < M; ++i) {
				int k = sc.nextInt();
				int pos = Arrays.binarySearch(p, k);
				if (pos < 0) {
					pos = -pos - 2;
					int d = Math.min(k - p[pos], p[pos + 1] - k);
					ans += d;
				}
			}
			System.out.println(ans);
		}
	}
}

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

import sys
import copy


def main():
    n = int(sys.stdin.readline())
    separator = '####################'

    room, floor = 10, 3;
    building1 = [[0 for col in range(room)] for row in range(floor)]
    building2 = copy.deepcopy(building1)
    building3 = copy.deepcopy(building1)
    building4 = copy.deepcopy(building1)

    buildings = {1 : building1,
                 2 : building2,
                 3 : building3,
                 4 : building4
    }

    for i in range(n):
        lst = [int(num) for num in sys.stdin.readline().split()]
        buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3]

    for idx, (key, value) in enumerate(buildings.items()):
        for floor in value:
            print(' %s %s %s %s %s %s %s %s %s %s' % tuple(floor))
        if idx < 3:
            print(separator)


if __name__ == '__main__':
    main()

Measured memory_bytes: 8212
#include <stdio.h>
#include <math.h>

int
main(void)
{
	char line[80];
	double v0;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%lf", &v0) != 1) {
			return 1;
		}

		int n = 1;
		while (n > 0) {
			double y = 5.0 * n - 5.0;
			double t = sqrt(y/4.9);
			double v = 9.8 * t;
			if (v >= v0) {
				printf("%d\n", n);
				break;
			}
			n++;
		}
	}

	return 0;
}

Measured memory_bytes: 1072
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void){
    long N,K,t,answer;
    cin >> N >> K;
    t = N % K;//tは正の値での最小値,|t-K|に操作をしたらtに戻る
    //tと|t-K|の大小比較
    if(t <= abs(t-K)){
        answer = t;
    }
    else{
        answer = abs(t-K);
    }
    cout << answer;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn volume(a: usize, b: usize) -> f64 {
    (b as f64) / ((a + b) as f64)
}

fn main() {
    let abcdef: Vec<usize> = util::gets();
    let a = abcdef[0];
    let b = abcdef[1];
    let c = abcdef[2];
    let d = abcdef[3];
    let e = abcdef[4];
    let f = abcdef[5];

    let mut pairs: HashSet<(usize, usize)> = HashSet::new();
    pairs.insert((0, 0));
    let mut maximum_pair = (100 * a, 0);

    let mut updated = true;
    while updated {
        updated = false;
        let mut next = HashSet::new();
        for (w, s) in pairs {
            for &(ww, ss) in [(100 * a, 0), (100 * b, 0), (0, c), (0, d)].iter() {
                let (nw, ns) = (w + ww, s + ss);
                if nw + ns <= f && (nw / 100) * e >= ns {
                    if volume(nw, ns) > volume(maximum_pair.0, maximum_pair.1) {
                        maximum_pair = (nw, ns);
                    }
                    next.insert((nw, ns));
                    updated = true;
                }
            }
        }
        pairs = next;
    }
    let (w, s) = maximum_pair;
    println!("{} {}", w + s, s);
}


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


def read():
    N = int(input().strip())
    D, X = map(int, input().strip().split())
    A = []
    for i in range(N):
        a = int(input().strip())
        A.append(a)
    return N, D, X, A


def solve(N, D, X, A):
    count = [0 for i in range(D+1)]
    for a in A:
        i = 0
        while True:
            day = i * a + 1
            if day > D:
                break
            count[day] += 1
            i += 1
    return X + sum(count)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 3188
N, A, B, C, D = map(int, input().split())
S = str(input())
if C < D:
    if '##' in S[min(A, B):D]:
        print('No')
    else:
        print('Yes')
elif C > D:
    if '##' in S[min(A, B):C]:
        print('No')
    else:
        # ここの添字は図を書いて理解してください
        if '...' in S[B - 2:D + 1]:
            print('Yes')
        else:
            print('No')


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] == 'R') cnt += 1;
    else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout << ans << '\n';
}


Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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 Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    Graph G(N), H(N);
    rep(i,N-1+M) {
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        H[b].emplace_back(a);
    }

    vector<int> cnt(N),ans(N,-1);
    int p;
    rep(i,N) {
        cnt[i] = H[i].size();
        if (cnt[i] == 0) p = i;
    }
    queue<int> que;
    que.emplace(p);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            cnt[nv]--;
            if (cnt[nv] == 0) {
                ans[nv] = v;
                que.emplace(nv);
            }
        }
    }

    rep(i,N) cout << ans[i]+1 << endl;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
 
ld pi = 3.141592653589793;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  ll r;
  cin >> r;
 
  cout << fixed << setprecision(10) << 2 * pi * r << en;
 
  return 0;
}

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

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

	int n;
	bool isq = false;
	if (b == 100) {
		n = 10 * a + 1;
		for (int i = 1;i <= 40;i++) {
			if (n == i * i) { isq = true; }
		}
	}
	else if (b<10) {
		n = 10 * a + b;
		for (int i = 1;i <= 40;i++) {
			if (n == i * i) { isq = true; }
		}
	}
	else {
		n = 100 * a + b;
		for (int i = 10;i <= 101;i++) {
			if (n == i * i) { isq = true; }
		}
	}

	if (isq) { cout << "Yes"; }
	else { cout << "No"; }
}


Measured memory_bytes: 256
// Shift-JIS（シフトジス）

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

int main()
{
    string S;
    cin >> S;
    bool flag = false;
    char s1 = S[0];
    int ns1 = 0;
    for (int i = 1; i < 4; i++)
    {
        if (S[i] == s1)
        {
            ns1++;
            S[i] = ' ';
        }
    }
    if (ns1 == 1)
    {
        char s2 = ' ';
        for (int i = 0; i < 4; i++)
        {
            if (S[i] == s2)
            {
                flag = true;
                break;
            }
            if (S[i] != ' ')
            {
                s2 = S[i];
            }
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int A,B,C,K;cin>>A>>B>>C>>K;
	int res=0;
	if (K>0){
		res+=min(A,K);
		K-=min(A,K);
	}
	if (K>0){
		K-=min(B,K);
	}
	if (K>0){
		res-=min(C,K);
		K-=min(C,K);
	}
	cout<<res;
}


Measured memory_bytes: 3648
N, K = input().split(" ")
N, K = int(N), int(K)
d = []
A = []
for k in range(K):
    d.append(int(input()))
    A += [int(a) for a in input().split(" ")]

ans = 0
for n in range(N):
    if A.count(n+1) == 0:
        ans += 1
print(ans)

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == 7){
        if(b == c && b == 5)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(b == 7){
        if(a == c && a == 5)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(c == 7){
        if(a == b && a == 5)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else cout << "NO" << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i].first;
    v[i].second = i;
  }

  sort(v.begin(), v.end());
  for(int i = 0; i < n; i++){
    if(i == v[n - 1].second){
      cout << v[n - 2].first << endl;
    }
    else{
      cout << v[n - 1].first << endl;
    }
  }


}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

int buka[2 * pow10(5)];

void solve()
{
    int N;
    cin >> N;

    FOR (i, 2, N + 1)
    {
        int a;
        cin >> a;
        buka[a]++;
    }

    REP1 (i, N)
    {
        std::cout << buka[i] << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 4324
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class349
    {
        static void Main()
        {
            var XY = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = XY[0], Y = XY[1];
            if ((X + Y) % 3 != 0)
            {
                Console.WriteLine(0);return;
            }
            int b = (X + Y) / 3;
            int num = X - b;
            if (num < 0 || b < num)
            {
                Console.WriteLine(0);return;
            }
            int ans = (int)Modular.Ncr(b, num);
            Console.WriteLine(ans);
        }
    }
    class Modular  //Modしながら計算するクラス
    {
        private const int M = 1000000007;
        private long value;
        public Modular(long value) { this.value = value; }
        public static implicit operator Modular(long a)
        {
            var m = a % M;
            return new Modular((m < 0) ? m + M : m);
        }
        public static Modular operator +(Modular a, Modular b)
        {
            return a.value + b.value;
        }
        public static Modular operator -(Modular a, Modular b)
        {
            return a.value - b.value;
        }
        public static Modular operator *(Modular a, Modular b)
        {
            return a.value * b.value;
        }
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
                case 0:
                    return 1;
                case 1:
                    return a;
                default:
                    var p = Pow(a, n / 2);
                    return p * p * Pow(a, n % 2);
            }
        }
        public static Modular operator /(Modular a, Modular b)
        {
            return a * Pow(b, M - 2);
        }
        private static readonly List<int> facs = new List<int> { 1 };
        public static Modular Fac(int n)   //階乗
        {
            for (int i = facs.Count; i <= n; ++i)
            {
                facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
            }
            return facs[n];
        }
        public static Modular Fac(int r, int n)
        {
            int temp = 1;
            for (int i = r; i <= n; i++)
            {
                temp = (int)(Math.BigMul(temp, i) % M);
            }
            return temp;
        }
        public static Modular Ncr(int n, int r) //nCr
        {
            return (n < r) ? 0
                 : (n == r) ? 1
                            : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r))
                                : Fac(n - r + 1, n) / Fac(r);
        }
        public static explicit operator int(Modular a)
        {
            return (int)a.value;
        }
    }
}


Measured memory_bytes: 19808
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N; //奇数
    vector<unsigned long long> A(N);
    vector<unsigned long long> X(N, INF);
    REP(i, N) { cin >> A[i]; }
    // M[0]をもとめる
    unsigned long long S = accumulate(A.begin(), A.end(), 0LL);
    REP(i, N) { A[i] = 2LL * A[i]; }
    X[0] = S;
    for(int i = 1; i < N - 1; i += 2) {
        X[0] -= A[i];
    }
    for(int i = 0; i < N - 1; i++) {
        X[i + 1] = A[i] - X[i];
    }
    REP(i, N) { cout << X[i] << " "; }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var str = "";
            for (int i = 0; i < s.Length; i++)
            {
                var x = s[i].ToString();
                if(x== "A"|| x == "C"|| x == "G"|| x == "T")
                {
                    str += "1";
                }
                else
                {
                    str += "0";
                }
            }
            //Console.WriteLine(str);

            if (str.Contains("1111111111"))
            {
                Console.WriteLine("10");
            }
            else if (str.Contains("111111111"))
            {
                Console.WriteLine("9");
            }
            else if (str.Contains("11111111"))
            {
                Console.WriteLine("8");
            }
            else if (str.Contains("1111111"))
            {
                Console.WriteLine("7");
            }
            else if (str.Contains("111111"))
            {
                Console.WriteLine("6");
            }
            else if (str.Contains("11111"))
            {
                Console.WriteLine("5");
            }
            else if (str.Contains("1111"))
            {
                Console.WriteLine("4");
            }
            else if (str.Contains("111"))
            {
                Console.WriteLine("3");
            }
            else if (str.Contains("11"))
            {
                Console.WriteLine("2");
            }
            else if (str.Contains("1"))
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine("0");
            }

        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
 
 
int main(void) {
 
	char s[1001], t[1001];
	int count, k, ans, s_len, t_len;
 
	scanf("%s %s", s,t);
 
 
	s_len = strlen(s);
	t_len = strlen(t);
	ans = t_len;
 
	for (int i = 0; i < (s_len - t_len + 1); i++) {
 
		count = 0;
		for (int j = 0, k = i; j < t_len; j++, k++) {
			if (s[k] != t[j]) count++;
		}
		if (ans > count) {
			ans = count;
		}
	}
 
	printf("%d\n", ans);
 
	return 0;
}

Measured memory_bytes: 1712
def insertion_sort(num_list,gap):
    global cnt 

    for i in range(gap,len(num_list)):
        evc = num_list[i]
        j   = i-gap
        while j >= 0 and num_list[j] > evc:
            num_list[j+gap] = num_list[j]
            j = j-gap
            cnt += 1
            num_list[j+gap] = evc

def shell_sort(num_list):
    global cnt
    cnt = 0
    m_list = []
    h = 1
    while h <= len(num_list):
        m_list.append(h)
        h = 3*h+1
    m_list.reverse()
    m = len(m_list)

    print(m)
    print(' '.join([str(i) for i in m_list]))
    for i in range(m):
        insertion_sort(num_list,m_list[i])

n = int(input())
num_list = [int(input()) for _ in range(n)]

shell_sort(num_list)
print(cnt)
for num in num_list:
    print(num)


Measured memory_bytes: 45528
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int tall[] = new int[N];
        int count = 0;
        for(int i = 0; i < N; ++i){
            tall[i] = sc.nextInt();
        }
        for(int i = 0; i < N; ++i){
            if(tall[i] >= K){
                count += 1;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 59452
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#define fi first
#define se second
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	int d;
	while(cin>>d){
		int S=0;
		for(int i=1;i*d<=600-d;i++){
			int x=i*d;
			x=x*x;
			x*=d;
			S+=x;
		}
		cout<<S<<endl;
		S=0;
	}
}

Measured memory_bytes: 1160
H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
  print(0)
  exit(0)

if H > W:
  H, W = W, H

ans = 1e10
for i in range(1,W):
  blk1 = i * H
  # vertical cut
  if W-i >1:
    blk2 = (W-i)//2 * H
    blk3 = (W-i- (W-i)//2) * H
    #print(blk1, blk2, blk3)
    ans = min(ans, max(blk1, blk2, blk3) - min(blk1, blk2, blk3))
  # horizontal cut
  if H>1:
    blk2 = (W-i) * (H//2)
    blk3 = (W-i) * (H - (H//2))
    #print(blk1, blk2, blk3)
    ans = min(ans, max(blk1, blk2, blk3) - min(blk1, blk2, blk3))

H, W = W, H

for i in range(1,W):
  blk1 = i * H
  # vertical cut
  if W-i >1:
    blk2 = (W-i)//2 * H
    blk3 = (W-i- (W-i)//2) * H
    #print(blk1, blk2, blk3)
    ans = min(ans, max(blk1, blk2, blk3) - min(blk1, blk2, blk3))
  # horizontal cut
  if H>1:
    blk2 = (W-i) * (H//2)
    blk3 = (W-i) * (H - (H//2))
    #print(blk1, blk2, blk3)
    ans = min(ans, max(blk1, blk2, blk3) - min(blk1, blk2, blk3))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;


int rick[256];

int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	
	
	
	ini(n);
	vpii morty;
	FOR(i,0,n){
		ini(x);
		ini(x1);
		morty.push_back(make_pair(x,x1));
	}
	map<pair<int,int>,int>map1;
	FOR(i,0,n){
		pair<int,int> tmp;
		FOR(i1,0,n){
			if(i1 == i)continue;
			map1[make_pair(morty[i].first-morty[i1].first,morty[i].second-morty[i1].second)]++;
		}
	}
	int rick = 0;
	pair<int,int> rick1;
	for(auto x:map1){if(x.second>rick){rick = x.second;rick1 = x.first;}}
	out(n-rick);










	return 0;
}


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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=b))
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}

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

int main(){
    int r,D,x0;
    cin >> r >> D >> x0;
    for(int i = 0;i < 10;i++){
        x0 = r * x0 - D;
        printf("%d\n",x0);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string adj[n];
    int ans=0;
    for(int i=0;i<n;i++)cin>>adj[i];
    for(int q=0;q<n;q++){
        queue<ii>bfs;
        vector<int>depth(n,-1);
        depth[q]=1;
        bfs.push(mp(q,1));
        bool yes=true;
        int mxd=0;
        while(!bfs.empty()&&yes){
            int x=bfs.front().first,d=bfs.front().second;
            bfs.pop();
            depth[x]=d;
            mxd=max(mxd,d);
            for(int y=0;y<n;y++){
                if(adj[x][y]=='1'){
                    if(depth[y]==-1){
                        depth[y]=d+1;
                        bfs.push(mp(y,d+1));
                    }
                    else if(depth[y]==d){
                        yes=false;
                        break;
                    }
                }
            }
        }
        if(yes){
            ans=max(ans,mxd);
        }
    }
    if(ans==0)cout<<-1;
    else cout<<ans;
}


Measured memory_bytes: 256
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
P = [1 for _ in range(10**6)]
P[0]=0
P[1]=0
for i in range(2,10**3):
    for j in range(i*i,10**6,i):
        P[j] = 0
Q = []
for i in range(2,10**6):
    if P[i]==1:
        Q.append(i)
A,B = map(int,input().split())
N = gcd(A,B)
R = [1]
for p in Q:
    if N%p==0:
        R.append(p)
        while N%p==0:
            N = N//p
if N>1:
    R.append(N)
print(len(R))

Measured memory_bytes: 114544
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;

class UnionFind {
  public:
    vector<int> rank, p;
    UnionFind(){}
    UnionFind(int size){
      rank.resize(size, 0); p.resize(size, 0);
      rep(i,size) makeSet(i);
    }
    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }
    bool same(int x, int y){
      return findSet(x) == findSet(y);
    }
    void unite(int x, int y){
      link(findSet(x), findSet(y));
    }
    void link(int x, int y){
      if(rank[x] > rank[y]) p[y] = x;
      else{
        p[x] = y;
        if(rank[x] == rank[y]) rank[y]++; //同じランクはxORyに統一して併合
      }
    }
    int findSet(int x){
      if(x != p[x]) p[x] = findSet(p[x]);
      return p[x];
    }
};
int main(){
  int n,a,b,q,t;
  cin >> n >> q;
  UnionFind uf = UnionFind(n);
  vector<int> ans;
  rep(i,q){
    cin >> t >> a >> b;
    if(t == 0) uf.unite(a, b);
    else if(t == 1){
      if(uf.same(a,b)) ans.push_back(1);
      else ans.push_back(0);
    }
  }
  rep(i,ans.size()) cout << ans[i] << "\n";
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1000000000000000007
#define pb emplace_back
typedef vector<ll> vi;

void solve(){
int w=0,l=0,k=0,q=0,m=0,r=0,p=0,x=0,y=0,n=0;
cin>>n>>m>>k;
vi a(n+1),b(m+1);
for(int i=0;i<n;i++){
	cin>>a[i+1];
	a[i+1]+=a[i];
}
for(int i=0;i<m;i++){
	cin>>b[i+1];
	b[i+1]+=b[i];
}
int ans=0;
for(int i=0,j=m;i<=n;i++){
//	int j=m;
	if(a[i]>k)
	break;
	while(a[i]+b[j]>k){
		j--;
	}
	ans=max(i+j,ans);
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
  int t=1;
  //cin>>t;
  while(t--){
  	solve();
  }
  return 0;
} 	

Measured memory_bytes: 6308
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V, Mod;
	List<int>[] es;
	void Solve()
	{
		var I = G;
		V = I[0];
		Mod = I[1];
		es = new List<int>[V];
		for (var u = 0; u < V; u++) es[u] = new List<int>();
		for (var e = 0; e < V - 1; e++)
		{
			I = G;
			es[I[0] - 1].Add(I[1] - 1);
			es[I[1] - 1].Add(I[0] - 1);
		}
		// var par = DFS1Exe(0, -1);
		var dp0 = DFS2Exe(0, -1);
		var dp1 = DFS3Exe(0, dp0);
		for (var u = 0; u < V; u++) WriteLine(dp0[u] * (dp1[u] + 1) % Mod);
	}
	int[] DFS1Exe(int u, int p)
	{
		var par = new int[V];
		var st = new Stack<object>();
		st.Push(new A0 { u = u, p = p });
		while (st.Count > 0)
		{
			var f = st.Pop();
			if (f is A0)
			{
				var g = (A0)f;
				es[g.u].Remove(par[g.u] = g.p);
				st.Push(new A1 { u = g.u, p = g.p, i = 0 });
			}
			else
			{
				var g = (A1)f;
				if (g.i < es[g.u].Count)
				{
					st.Push(new A1 { u = g.u, p = g.p, i = g.i + 1 });
					st.Push(new A0 { u = es[g.u][g.i], p = g.u });
				}
			}
		}
		return par;
	}
	long[] DFS2Exe(int u, int p)
	{
		var dp0 = new long[V];
		var st = new Stack<object>();
		st.Push(new B0 { u = u, p = p });
		while (st.Count > 0)
		{
			var f = st.Pop();
			if (f is B0)
			{
				var g = (B0)f;
				dp0[g.u] = 1L;
				es[g.u].Remove(g.p);
				st.Push(new B1 { u = g.u, i = 0 });
			}
			else if (f is B1)
			{
				var g = (B1)f;
				if (g.i < es[g.u].Count)
				{
					st.Push(new B2 { u = g.u, p = g.p, i = g.i });
					st.Push(new B0 { u = es[g.u][g.i], p = g.u });
				}
			}
			else
			{
				var g = (B2)f;
				dp0[g.u] = dp0[g.u] * (dp0[es[g.u][g.i]] + 1) % Mod;
				st.Push(new B1 { u = g.u, p = g.p, i = g.i + 1 });
			}
		}
		return dp0;
	}
	long[] DFS3Exe(int u, long[] dp0)
	{
		var dp1 = new long[V];
		var st = new Stack<object>();
		st.Push(new C0 { u = u });
		while (st.Count > 0)
		{
			var f = st.Pop();
			if (f is C0)
			{
				var g = (C0)f;
				var W = es[g.u].Count;
				var x = new long[W + 1];
				var y = new long[W + 1];
				x[0] = y[W] = 1;
				for (var i = 0; i < W; i++) x[i + 1] = x[i] * (dp0[es[g.u][i]] + 1) % Mod;
				for (var i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[g.u][i]] + 1) % Mod;
				for (var i = 0; i < W; i++) dp1[es[g.u][i]] = (dp1[g.u] + 1) * x[i] % Mod * y[i + 1] % Mod;
				x = y = null;
				st.Push(new C1 { u = g.u, i = 0 });
			}
			else
			{
				var g = (C1)f;
				if (g.i < es[g.u].Count)
				{
					st.Push(new C1 { u = g.u, i = g.i + 1 });
					st.Push(new C0 { u = es[g.u][g.i] });
				}
			}
		}
		return dp1;
	}
}
struct A0 { public int u, p; }
struct A1 { public int u, p, i; }
struct B0 { public int u, p; }
struct B1 { public int u, p, i; }
struct B2 { public int u, p, i; }
struct C0 { public int u; }
struct C1 { public int u, i; }


Measured memory_bytes: 36080
#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
template<class T,class C> T max(T a,C b){ return ((a)>(T)(b) ? (a) : (T)(b)); }
template<class T,class C> T min(T a,C b){ return ((a)<(T)(b) ? (a) : (T)(b)); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
ll n,a,b,c;
ll l[LIMIT1]={0};
ll dfs(ll i,ll al,ll bl,ll cl,ll mp){
  if(i>=n){
    if(al==0 || bl==0 || cl==0) return LLINF;
    else return llabs(a-al)+llabs(b-bl)+llabs(c-cl)+mp;
  }
  ll res = dfs(i+1,al+l[i],bl,cl,mp+(al==0 ? 0 : 10));
  res = min(res,dfs(i+1,al,bl+l[i],cl,mp+(bl==0 ? 0 : 10)));
  res = min(res,dfs(i+1,al,bl,cl+l[i],mp+(cl==0 ? 0 : 10)));
  res = min(res,dfs(i+1,al,bl,cl,mp));
  return res;
}
int main(void){
  initialize();
  ll m,i,j,k,result=0;
  string s;
  
  cin >> n >> a >> b >> c;
  rep(i,n) cin >> l[i];
  
  result = dfs(0,0,0,0,0);
  
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

template <typename T> void read(T& x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

typedef long long ll;

pair<ll, ll> seq[100005];
int n, m;

int main()
{
	read(n); read(m);
	for(int i=1; i<=n; i++)
	{
		read(seq[i].first);
		read(seq[i].second);
	}
	sort(seq+1, seq+n+1);
	ll sum = 0;
	for(int i=1; i<=n; i++)
	{
		int cnt = min((ll)m, seq[i].second);
		sum += seq[i].first * cnt;
		m -= cnt;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=1<<18;


int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> c(0);
    if(s[0]=='0') c.push_back(0);
    if(n==1) c.push_back(1); 
    for(int i=1;i<n;i++){
        int seq=1;
        while(i<n && s[i]==s[i-1]){
            i++;
            seq++;
        }
        c.push_back(seq);
    }
    if(n>1 && s[n-1]!=s[n-2]) c.push_back(1);

    int sum=0;
    int m=c.size();
    for(int i=0;i<=min(2*k,m-1);i++){
        sum+=c[i]; 
    }
    int ans=sum;
    for(int i=2*k+1;i<m;i+=2){
        sum-=c[i-2*k-1];
        sum-=c[i-2*k];
        sum+=c[i];
        if(i+1<m) sum+=c[i+1];
        ans=max(ans,sum);
        //cout<<sum<<endl;
    }
    cout<<ans<<endl;
 
}

Measured memory_bytes: 4032
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int a, b;
    cin >> a >> b;
    int s[1000];

    int count=0;
    for(int i=1; i<=999; i++){
        count+=i;
        s[i-1] = count;
    }
    
    out(s[b-a-1]-b);
}

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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り　0:ON　1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if(system==0) param.add(sc.next());
				if(system==1) param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		
		String number = num.get(0) + "" + num.get(1) + "" +  num.get(2);
		if(Integer.parseInt(number) % 4 == 0){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

int main() {
  int N;
  cin >> N ;
  vector <int> L(N);
  for (int i=0 ; i<N ; i++) cin >> L.at(i) ;
  sort (L.begin(), L.end());
  int count = 0;
  for (int i=0 ; i<N ; i++) {
    for (int j=i+1 ; j<N ; j++) {
      for (int k=j+1 ; k < N ; k++) {
        if (L.at(i)!=L.at(j)&&L.at(j)!=L.at(k)&&L.at(i)!=L.at(k)&&L.at(i)+L.at(j)>L.at(k)) count ++;
      }
    }
  }
  cout << count << endl;       
}


Measured memory_bytes: 3600