akhauriyash/Code-Regression huggingface dataset:
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[] rev = new int[n+1];
        for(int i=0; i<n; i++){
            int idx = Integer.parseInt(sc.next());
            rev[idx] = i;
        }
        
        TreeSet<Integer> ts = new TreeSet<>();
        ts.add(-1);
        ts.add(n);
        
        long ans = 0L;
        for(int i=1; i<=n; i++){
            int ridx = rev[i];
            ts.add(ridx);
            int l = ridx - ts.lower(ridx);
            int r = ts.higher(ridx) - ridx;
            ans += (long)l*r*i;
        }
        
        System.out.println(ans);
    }
}



Measured memory_bytes: 52888
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int k;
  cin>>k;
  if(k%2==1){
  cout<<(k/2)*(k+1)/2  <<endl;
  }
  else{
  cout<<k*k/2/2<<endl;
  }
}

Measured memory_bytes: 3600
# include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int c=0;
		for(int j=1;j<int(sqrt(i));j++)
		{
			for(int k=1;k<=j;k++)
			{
				for(int p=1;p<=k;p++)
				{
					int a=j+k;
					int b=k+p;
					int d=j+p;
					if((pow(a,2)+pow(b,2)+pow(d,2))==2*i)
					{
						if(j==p&&k==p)
						{
							c++;
						}
						else if((j==p&&k!=p)||(j==k&&j!=p)||(p==k&&p!=j))
						{
							c+=3;
						}
						else c+=6;
					}
					if((pow(a,2)+pow(b,2)+pow(d,2))>2*i) break;
				}
			}
		}
		cout<<c<<endl;
	}
	return 0;
}


Measured memory_bytes: 3576
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


bool f[111111];

inline bool is_squared(int x)
{
  return f[x];
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  memset(f, 0, sizeof(f));

  for (int i = 0; i * i < 111111; i ++)
    f[i * i] = true;

  int N, D, c = 0;

  std::cin >> N >> D;

  std::vector<std::vector<int>> p(N, std::vector<int>(D));

  for (int i = 0; i < N; i ++)
    for (int j = 0; j < D; j ++)
      std::cin >> p[i][j];

  for (int i = 0; i < N; i ++)
    for (int j = i + 1; j < N; j ++) {
      int d2 = 0;

      for (int k = 0; k < D; k ++) {
        int dx = p[i][k] - p[j][k];
        
        d2 += dx * dx;
      }

      if (is_squared(d2))
        c ++;
    }

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 384
<?php
$L=trim(fgets(STDIN));

$p0=0;
$p1=0;

for($i=0;$i<$L;$i++){
  $C=explode(' ',trim(fgets(STDIN)));
  $c=strcmp($C[0],$C[1]);

  if($c<0){$p1+=3;continue;}
  if($c>0){$p0+=3;continue;}
  ++$p0;
  ++$p1;
}

echo $p0,' ',$p1;
?>

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

using namespace std;

typedef long long ll;

int main(){
  ll money = 1000;
  ll kabu = 0;
  ll N,i;
  ll A[222222];
  cin >> N;
  for(i=1;i<=N;i++)
    cin >> A[i];

  A[0] = 111111;
  A[N+1] = 0;
  for(i=1;i<=N;i++){ 
    if(A[i-1] > A[i] && A[i] < A[i+1]) {
      kabu += money / A[i];
      money %= A[i];
      }//極小値で買う
    else if(A[i-1] < A[i] && A[i] > A[i+1]){
      money += kabu * A[i];
      kabu = 0;
      }//極大値で売る
    else if(A[i-1] == A[i] && A[i] > A[i+1]){
    money += kabu * A[i];
    kabu = 0;
    }//売る
    else if(A[i-1] == A[i] && A[i] < A[i+1]){
    kabu += money / A[i];
    money %= A[i];
    }//買う
    }
  cout << money << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void){
    int h,a;
    scanf("%d %d",&h,&a);
    int ans;
    if(a>=h){
        ans=1;
    }else{
        if(h%a==0){
            ans=h/a;
        }else{
            ans=h/a+1;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  long long int a,b;
  long long int temp,con;
  long long int hk1,hk2;
  while(scanf("%lld %lld",&a,&b)!=EOF){
    if(a>b){
      if(a%b==0){
	hk1=b;
      }else{
	long long int bit=b/2;
	for(long long int i=bit;i>0;i--){
	  if(a%i==0 && b%i==0){
	    hk1=i;
	    break;
	  }
	}
      }
    }else{
      if(b%a==0){
	hk1=a;
      }else{
	long long int dot=a/2;
	for(long long int i=dot;i>0;i--){
	  if(a%i==0 && b%i==0){
	    hk1=i;
	    break;
	  }
	}
      }
    }
    temp=a*b;
    con=temp/hk1;
    hk2=con;
    printf("%lld %lld\n",hk1,hk2);
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
      int B=sc.nextInt();
      if(1 <= A && A <= 9 && 1 <= B && B <= 9){
        System.out.println(A*B);
      }else{
        System.out.println(-1);
      }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    n--;
    int b[n];
    rep(i,n) cin >> b[i];
    int ans = b[0];
    rep(i,n){
        if(i == n - 1){
            ans += b[i];
        }else if(b[i] <= b[i+1]){
            ans += b[i];
        }else if(b[i] > b[i+1]){
            ans += b[i+1];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> len(100002, -1);
vector<vector<int> > path(100002, vector<int>());

int dfs(int current)
{
    if(len[current] != -1){
        return len[current];
    }
    int maxlen = 0;
    for(int i = 0; i < path[current].size(); i++){
        int len = dfs(path[current][i]);
        maxlen = max(maxlen, len);
    }
    len[current] = maxlen + 1;

    return len[current];
}

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

    for(int i = 0; i < m; i++){
        int xi, yi;
        cin >>xi >>yi;
        path[xi-1].push_back(yi-1);
    }
    int maxlen = 0;
    for(int i = 0; i < n; i++){
        maxlen = max(maxlen, dfs(i));
    }

    printf("%d\n", maxlen - 1);

    return 0;
}

Measured memory_bytes: 8192
""" tutorial06
    https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
"""
import sys
import math
from functools import reduce

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def main(N, S):
    """ main
    """
    count = 0
    skip1 = []
    skip2 = []
    skip3 = []

    for i in range(0, N):
        if S[i] in skip1:
            continue
        skip1.append(S[i])
        for j in range(i+1, N):
            if S[j] in skip2:
                continue
            skip2.append(S[j])
            for k in range(j+1, N):
                if S[k] in skip3:
                    continue
                skip3.append(S[k])
                count += 1
            skip3 = []
        skip2 = []

    return count

if __name__ == "__main__":
    _N = readInteger()
    _S = readString()

    print(main(_N, _S))

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

int main() {
  string s;
  cin >> s;
  int N = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '1') {
      N++;
    }
  }
    cout << N << endl;
}

Measured memory_bytes: 256
N = gets.to_i
as = gets.split.map(&:to_i)

def finish(first_win)
    puts first_win ? 'First' : 'Second'
    exit
end

first = true
loop do
    odd = 0
    odd_i = nil
    has_one = false
    N.times do |i|
        if as[i] % 2 == 1
            odd += 1
            odd_i = i
        end
        has_one = true if as[i] == 1
    end

    if odd == 0
        N.times do |i|
            as[i] /= 2
        end
    elsif (odd - N) % 2 == 1
        finish(first)
    elsif has_one || odd >= 2
        finish(!first)
    else
        first = !first
        as[odd_i] -= 1
        g = as.inject{|memo, e| memo.gcd(e)}
        N.times do |i|
            as[i] /= g
        end
    end
end


Measured memory_bytes: 10516
fn main() {
    let x: i32 = read();
    let t: i32 = read();
    let ans = if x >= t {
        x - t
    } else {
        0
    };
    println!("{}", ans);
}

// 以下関数

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

pub const MOD: u64 = 10e9 as u64 + 7;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}


Measured memory_bytes: 4352
// AGC040B.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5 + 200, INF = 0x3f3f3f3f;

struct segment
{
    int l, r;
    bool operator<(const segment &nd) const { return r < nd.r; }
} segs[MAX_N];

int n;
multiset<int> ms;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &segs[i].l, &segs[i].r);
    sort(segs + 1, segs + 1 + n);
    int lft = segs[1].l, rig = segs[1].r, gans = 0;
    for (int i = 2; i <= n; i++)
        ms.insert(segs[i].l);
    for (int i = 2; i <= n - 1; i++)
    {
        int grig = segs[i].r;
        ms.erase(ms.find(segs[i].l));
        // calc;
        int L1 = *ms.begin(), L2 = *ms.rbegin();
        int pans = max(grig - max(L1, segs[i].l) + 1, 0) + max(rig - max(lft, L2) + 1, 0);
        pans = max(pans, max(grig - max(L2, segs[i].l) + 1, 0) + max(rig - max(lft, L1) + 1, 0));
        pans = max(pans, max(grig - max(L2, segs[i].l) + 1, 0) + max(rig - lft + 1, 0));
        pans = max(pans, max(grig - segs[i].l + 1, 0) + max(rig - max(lft, L2) + 1, 0));
        gans = max(gans, pans);
        // merge;
        lft = max(lft, segs[i].l), rig = min(rig, segs[i].r);
    }
    gans = max(gans, max(rig - lft + 1, 0) + max(segs[n].r - segs[n].l + 1, 0));
    printf("%d", gans);
    return 0;
}

Measured memory_bytes: 5760
H, W = map(int, input().split())
C = list(map(lambda x: int(x)-1, input().split()))
D = list(map(lambda x: int(x)-1, input().split()))

Ss = [str(input()) for _ in range(H)]
group = [[-1 for _ in range(W)] for _ in range(H)]

moves = [[-1,0], [1,0], [0,-1], [0,1]]

from collections import deque
todo = deque()
now_group = -1
for i in range(H):
    for j in range(W):
        if group[i][j] == -1 and Ss[i][j]==".":
            todo.append([i,j])
            now_group += 1
            group[i][j] = now_group
        while len(todo) > 0:
            checking = todo.pop()
            for move in moves:
                now = [checking[0]+move[0],checking[1]+move[1]]
                if not (0 <= now[0] <H and 0 <= now[1] <W):
                    continue
                if group[now[0]][now[1]] == -1 and Ss[now[0]][now[1]]==".":
                    todo.append(now)
                    group[now[0]][now[1]] = now_group

can_waap = [set() for _ in range(now_group+1)]

for i in range(H):
    for j in range(W):
        if group[i][j] ==-1:
            continue
        for yoko in range(-2,3):
            for tate in range(-2,3):
                now = [tate+i, yoko+j]
                if not (0<=now[0]<H and 0<=now[1]<W):
                    continue
                if group[now[0]][now[1]] == -1:
                    continue
                
                if group[i][j] != group[now[0]][now[1]]:
                    can_waap[group[i][j]].add(group[now[0]][now[1]])
                    can_waap[group[now[0]][now[1]]].add(group[i][j])

start = group[C[0]][C[1]]
goal = group[D[0]][D[1]]
import sys
import copy
seen = set([start])
nows = [start]

if start==goal:
    print(0)
    sys.exit()
for step in range(now_group+1):
    pre_nows = copy.deepcopy(nows)
    nows = []
    for pre_now in pre_nows:
        for j in can_waap[pre_now]:
            if j not in seen:
                seen.add(j)
                nows.append(j)
                if j == goal:
                    print(step+1)
                    sys.exit()

print(-1)


Measured memory_bytes: 165212
/******

AUTHOR : RUDRANSH TRIPATHI, IIIT NAGPUR, CCID(rt24) & CFID(rsgt24)

MOTTO : Use criticism as fuel and you will never run out of energy.
        AIM : TO BECOME A BETTER CODER
        INTROSPECT + COURSE CORRECTIONS = CATALYST FOR SUCCESS
        Every moment is an opportunity to better yourself

*******/

#include<bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MAX = 2e6 + 10;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define pb push_back
#define d(x) cout<<x<<"\n"
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

//basic mathematics
int gcd(int a, int b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

//modular arithmetic
int powermod(int x, int y, int p = M)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;

	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res % p;
}

//Prime numbers till n precomputation - range query
int prefix[MAX + 1];

void buildPrefix()
{
	bool prime[MAX + 1];
	memset(prime, true, sizeof(prime));

	for (int p = 2; p * p <= MAX; p++) {
		if (prime[p] == true) {
			for (int i = p * 2; i <= MAX; i += p)
				prime[i] = false;
		}
	}
	prefix[0] = prefix[1] = 0;
	for (int p = 2; p <= MAX; p++) {
		prefix[p] = prefix[p - 1];
		if (prime[p])
			prefix[p]++;
	}
}

int query(int L, int R)
{
	return prefix[R] - prefix[L - 1];
}


//Find all paths from a to b in an undirected graph
vector<int> g[MAX];
int visited[MAX];
//count of all the paths from 1 to n;

void dfs(int visited[MAX], int u, int v, vector<int> path)
{
	visited[u] = 1;
	if (u == v)
	{
		for (int i = 0; i < path.size(); i++)
		{
			cout << path[i] << " ";
		}
		cout << "\n";
	}
	else
	{
		for (int i = 0; i < g[u].size(); i++)
		{
			int y = g[u][i];

			if (visited[y] == 0)
			{
				visited[y] = 1;
				path.pb(y);
				dfs(visited, y, v, path);
				path.pop_back();
			}

		}
	}

	visited[u] = 0;

}

vector<int> graph[MAX];
int vis[MAX];

void dfs(int v)
{
	vis[v] = 1;

	for (auto x : graph[v]) {

		if (vis[x] == 0)
		{
			dfs(x);
		}

	}
}

void solve()
{ 
    int a,b,c,d;
    
    cin >> a >> b >> c >> d;
    
    int a1 = a*c;
    int a2 = a*d;
    int a3 = b*c;
    int a4 = b*d;
    
    cout << max({a1,a2,a3,a4}) << "\n";

}

int32_t main(void)
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	//cerr << "\n" << "Time elapsed : " << time_passed << "\n";
	return 0;
}

Measured memory_bytes: 97416
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  ll c=0,d=0,x,y,z;
  scanf("%lld %lld\n",&x,&y);
  COMinit();
  if((x%3==0 && y%3==0)||(x%3==1 && y%3==2)||(x%3==2 && y%3==1)){
    z=x-y;
    if(z>0){
      d=z;
      c+=(y-d)/3;
      d+=(y-d)/3;
    }
    else{
      z=abs(z);
      c=z;
      d+=(x-c)/3;
      c+=(x-c)/3;
    }
    if(c<0 || d<0){
      printf("0\n");
      return 0;
    }
    printf("%lld\n",COM(c+d,c));
  }
  else{
    printf("0\n");
    return 0;
  }
  return 0;
}

Measured memory_bytes: 47232
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const ll INF = std::numeric_limits<long long>::max();
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define sz size
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n, m;
string s;
vector<int>ints;
vector<string>strings;
int main() {
	ll n;
	cin >> n;
	cout << (n / 11) * 2 + (n % 11 > 6 ? 2 : (n % 11 == 0) ? 0 : 1) << endl;
	return 0;
}


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

#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
	int n;
	int ans=0;
	
	cin >> n;
	
	int p[n];
	
	for(int i=0; i<n; i++)	cin >> p[i];
	
	for(int i=1; i<n-1; i++){
		if(p[i-1]<p[i] && p[i]<p[i+1])	ans++;
		if(p[i+1]<p[i] && p[i]<p[i-1])	ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import itertools
def resolve():
    n,m = map(int,input().split()) #スイッチ､電球
    ss = []
    for i in range(m):
        k, *s = map(int, input().split())
        ss.append(s)
    p = list(map(int,input().split()))
    #print()
    #print(n,m)
    #print(ss)
    #print(p)

    #print()
#    for i in range(m):
#        print(len(ss_on[i])%2 == p[i])

#    for i in range():
#        for m in range 
    ans = 0
    # スイッチパターンfor
    for s_pattern in itertools.product(range(0,2),repeat=n):
       # 各ライトfor 番号､構成スイッチ
        light_bool = []
        for light_num, each_s in enumerate(ss):
            ssum = 0
            for num in each_s: ssum += s_pattern[num-1]
            light_bool.append(ssum % 2 == p[light_num])
            #print(s_pattern)
            #print(each_s,ssum)
            #print(p)
        #print(light_bool)
        if all(light_bool):
            ans+=1
    print(ans)
            #if sum(l)%2 == 
    

resolve()


Measured memory_bytes: 14532
#include<bits/stdc++.h>
#define ll long long 
#define inf 0x3f
#define INF 0x3f3f3f3f
#define fi first
#define se second 
#define pa pair<int,int>

using namespace std;

inline ll read()
{
	ll sum=0,f=1;char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();}
	while (isdigit(c)) {sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
const int MAXN=200010;
ll f[MAXN][5];
int n,A[MAXN],B[MAXN];
int mp[5][5];
inline void init()
{
	mp[1][0]=2;mp[1][1]=1;mp[1][2]=0;
	mp[3][0]=2;mp[3][1]=1;mp[3][2]=0;
	mp[2][0]=1;mp[2][2]=1;mp[2][1]=0;
}
int main()
{
	int n=read();
	init();
	for(int i=1;i<=n;i++)
		A[i]=read(),B[i]=A[i];
	for(int i=1;i<=n;i++) 
	{
		if(A[i]==0)
			continue;
		if(A[i]%2==1) A[i]=1;
		else A[i]=2;
	}
	memset(f,inf,sizeof(f));
	memset(f[0],0,sizeof(f[0]));
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<5;j++)
		{
			int tmp=mp[j][A[i]];
			if(j==0 || j==4)
				tmp=B[i];
			ll mn=1e18;
			for(int k=0;k<=j;k++)
				mn=min(mn,f[i-1][k]);
			f[i][j]=mn+tmp;
		}
	} 
	ll ans=1e18;
	for(int j=0;j<5;j++)
		ans=min(1ll*ans,f[n][j]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9600
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        LinkedList<Double> v = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            v.add(sc.nextDouble());
        }

        Collections.sort(v);

        while (v.size() >= 2) {
            double v1 = v.poll();
            double v2 = v.poll();
            v.offerFirst((v1 + v2) / 2);
        }

        System.out.print(v.get(0));
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<n; i++)
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int N, S1=0, S2=0;
	cin>>N;
	vector<int> A(N);
	rep(i, 0, N) cin>>A[i], S1+=A[i];
	int M=S1;
	rep(i, 0, N) S2+=A[i], M=min(M, abs(S1-2*S2));
	cout<<M;
}

Measured memory_bytes: 256
import sys

def solve(N, S, K):
    char = S[K-1]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans

Measured memory_bytes: 2568
#pragma GCC diagnostic ignored "-Wunused-result"

#include <stdio.h>

int main(void) {
  int x1,y1,x2,y2,x3,y3,x4,y4;
  int ret;
  
  scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

  y3 = y2+(x2-x1);
  y4 = y1+(x2-x1);
  x3 = x2-(y2-y1);
  x4 = x1-(y2-y1);

  printf("%d %d %d %d\n",x3,y3,x4,y4);
  return 0;

}


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

constexpr int MOD = 998244353;

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

using mint = ModInt<MOD>;
mint dp[3010][3010];
bool visited[3010][3010];

mint dfs(int y, int x) {
	if(visited[y][x]) return dp[y][x];
	visited[y][x] = true;
	dp[y][x] += dfs(y, x - 1) * y;
	dp[y][x] += dfs(y - 1, x) * x;
	dp[y][x] -= dfs(y - 1, x - 1) * (x - 1) * (y - 1);
	return dp[y][x];
}

int main() {
	int a, b; cin >> a >> b;
	int c, d; cin >> c >> d;
	dp[a][b] = 1;
	visited[a][b] = true;
	for(int y = a + 1; y <= c; ++y) {
		dp[y][b] = dp[y - 1][b] * b;
		visited[y][b] = true;
	}
	for(int x = b + 1; x <= d; ++x) {
		dp[a][x] = dp[a][x - 1] * a;
		visited[a][x] = true;
	}
	cout << dfs(c, d) << '\n';
	return 0;
}

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

int main() {
 int a,b,c,d,x,y;
cin>>a;
  x=a/100;
  y=a%100;
  //cout<<x<<"  "<<y<<endl;
  
  
  
  

 // cout<<x<<endl;
  if(x==0) {
    if(y<13 && y>0) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
  }
  
  if(x>0 && x<13){
    if(y>0 && y<13) cout<<"AMBIGUOUS"<<endl;
    else cout<<"MMYY"<<endl;
  }
  
  if(x>12){
    if(y>0 && y<13) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
  }
    
    
   
}


Measured memory_bytes: 256
S = input()
P =2019
ans = 0

count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
print(ans)

Measured memory_bytes: 9196
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    ll k, x, b;
    set<ll> s;
    bool as = true;
    cin >> k >> x;
    while(k--){
        ll c , cc;
        c = x -k;
        cc = x + k;
        if( c >= -1000000){
            s.insert(c);
        }
        if( cc <= 1000000){
            s.insert(cc);
        }
    }
    for(auto i : s) cout << i << " ";
    return 0;
}
/*
         ,--"""",--.__,---[],-------._
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________

*/


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

class Program
{
    struct Interval
    {
        public int b;
        public int e;
        public Interval(int _b,int _e)
        {
            b = _b;
            e = _e;
        }
    }

    public static void Main()
    {
        int K;
        K = int.Parse(Console.ReadLine().Split(' ')[1]);
        string S = Console.ReadLine();

        List<Interval> IL = new List<Interval>();
        IL.Add(new Interval(-1, 0));
        for (int i = 0; i < S.Length;)
        {
            if (S[i] == '0')
            {
                Interval v = new Interval();
                v.b = i;
                while (i<S.Length&&S[i] == '0')
                    i++;
                v.e = i;
                IL.Add(v);
            }
            else
                i++;
        }
        IL.Add(new Interval(S.Length, S.Length+1));
        
        if (IL.Count - 2 <= K)
            Console.WriteLine(S.Length);
        else
        {
            int m = 0;
            for (int i = 1; i + K < IL.Count; i++)
                m = Math.Max(m, IL[i + K].b - IL[i - 1].e);
            Console.WriteLine(m);
        }
    }
}

Measured memory_bytes: 12384
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

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

  N %= 10;
  if(N == 3){
    cout << "bon\n";
  }
  else if(!N or N == 1 or N == 8 or N == 6){
    cout << "pon\n";
  }
  else cout << "hon\n";

  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.);
const int N=105;
int n,x[N],y[N];
double p[N+N];
signed main()
{
    cin>>n;
    for(int i=0; i<n; i++)cin>>x[i]>>y[i];
    for(int i=0; i<n; i++)
    {
        int tot=0;
        for(int j=0; j<n; j++)
            if(i!=j)p[tot++]=atan2(y[j]-y[i],x[j]-x[i]);
        sort(p,p+tot);
        for(int j=0; j<tot; j++)p[j+tot]=p[j]+2*pi;
        double ans=0;
        for(int j=0; j<tot; j++)ans=max(ans,pi-p[j+tot-1]+p[j]);
        printf("%.8f\n",ans/2/pi);
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

int main()
{
  int N, K, Q;
  cin >> N >> K >> Q;

  vector<int> X(N,0);
  
  for (int q=0; q<Q; ++q) {
    int A;
    cin >> A;
    X[--A]++;
  }

  int count=0;
  for (int n=0; n<N; ++n) {
    if (X[n]+K>Q)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 110000;
vi e[3][maxn];
int gr[3][maxn];

const i64 P = 998244353, Q = 716070898;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    vvi64 cnt(3, vi64(500));
    forn(i, 3) {
        int m;
        cin >> m;
        forn(j, m) {
            int u, v;
            cin >> u >> v;
            --u; --v;
            if (u > v) swap(u, v);
            e[i][u].pb(v);
        }

        ford(j, n) {
            vi used(e[i][j].size() + 1);
            for (int k: e[i][j]) {
                int x = gr[i][k];
                if (x >= used.size()) continue;
                used[x] = 1;
            }
            while (used[gr[i][j]]) ++gr[i][j];
//            cerr << i << ' ' << j << ' ' << gr[i][j] << '\n';
        }
        i64 z = Q;
        forn(j, n) {
            (cnt[i][gr[i][j]] += z) %= P;
            (z *= Q) %= P;
        }
    }

    i64 ans = 0;
    forn(i, 500) forn(j, 500) {
        if ((i ^ j) >= 500) continue;
        ans += cnt[0][i] * cnt[1][j] % P * cnt[2][i ^ j];
        ans %= P;
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 14592
program name
    implicit none
    integer(4):: n,k
    character(:),allocatable:: s
    integer(4):: cnt,i,ni,ans,l
    integer(4),allocatable:: si(:)

    read*, n,k
    allocate(character(n):: s)
    read*, s

    cnt=2
    do i=2,n
        if (s(i-1:i-1) /= s(i:i)) cnt=cnt+1
    end do

    allocate(si(cnt))

    ni=1
    si(:) = 0
    si(1) = 1
    do i=2,n
        if (s(i-1:i-1) /= s(i:i))then
            ni=ni+1
            si(ni) = i
        end if
    end do
    si(cnt) = n+1

    ans = 0
    do i=1,cnt-1
        if (s(si(i):si(i)) == '0') then
            l = (2*k)
        else
            l = 2*k+1
        end if
        ans = max(ans, si(min(cnt,l+i))-si(i))
    end do
    print*, ans
end program name

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

using Graph = vector<vector<ll>>;

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

#define MAX_N 2010

const long long INF = 1LL << 60;

//境界値に注意！！！

int main() {
    ll n,x=0,y=0;
    cin >> n;
    ll z[n];
    for (ll i=0;i<n;i++)cin >> z[i];
    sort(z,z+n);
    for (ll i=0;i<n;i++){
        if (i%2){
            y+=z[n-i-1];
        }else{
            x+=z[n-i-1];
        }
    }
    cout << x-y << endl;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

#define N 12                     //未知数の数
/*計算結果を表示する際に、三角行列になったか
確認したいときは1を、解のみ表示した場合は0にしておく*/
#define CHECK 1 

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

const ll mod=1000000000+7;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)cout<<c;
	else if(b==c)cout<<a;
	else cout<<b;
	cout<<endl;
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if(0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int,int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

lli C(lli n, lli r){
	lli f[n+1];
	f[0] = 1;

	for(int i=1;i<=n;i++){
		f[i] = i*f[i-1];
	}
	return f[n]/f[r]/f[n-r];
}

lli powMod(lli a, lli b, lli MOD2){
	lli x=1, y = a;
	while(b > 0){
		if(b%2==1){
			x = (x*y);
			if(x > MOD2) x%=MOD2;
		}
		y = (y*y);
		if(y > MOD2) y%=MOD2;
		b/=2;
	}
	return x;
}


lli inverseEuler(lli n, lli MOD2){
	return powMod(n, MOD2-2, MOD2);
}

/*
	Coeficiente Binomial com Modulo
*/

lli C(lli n, lli r, lli MOD2){
	vector<lli> f(n+1, 1);
	// Dá pra otimizar o calculo do fatorial
	// Deixando todos pre calculados
	for(lli i = 2;i<=n;i++){
		f[i] = (f[i-1]*i)%MOD2;
	}

	return (f[n]*((inverseEuler(f[r], MOD2) * inverseEuler(f[n-r], MOD2))%MOD2))%MOD2;
}

void no(){
  cout << 0 << endl;
  exit(0);
}

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

  lli n, m;
  cin >> n >> m;
  if(n < m) swap(n, m);
  if((n+m)%3 != 0){
    no();
  }
  
  lli h = (n+m)/3;
  n -= h, m -= h;
  if(n < 0 or m < 0) no();
  cout << C(h, n, MOD) << endl;

  return 0;
}

Measured memory_bytes: 5504
if __name__=="__main__":
    N, A, B = list(map(int,input().strip().split()))
    X = list(map(int,input().strip().split()))

    result = 0
    for i in range(1,N):
        walk =  A*(X[i] - X[i-1]) 
        if walk < B:
            result += walk
        else:
            result += B
    print(result)




Measured memory_bytes: 14224
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
#include <math.h>
using namespace std;
#define MAXSIZE 100005
#define PI 3.141592653589793
#define MOD_CONST 1000000007
typedef long long int lli;

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

    double w = x / a / a;

    double ans_radian;
    if(w == 0.5 * b){
        ans_radian = atan(b / a);
    }else if(w > 0.5 * b){
        double tmpl = 2 * x / a / a - b;
        ans_radian = atan((b - tmpl) / a);
    }else{
        double tmpl = 2 * x / a / b;
        ans_radian = atan(b / tmpl);
    }

    double ans_degree = ans_radian * 180 / PI;
    printf("%.15f", ans_degree);
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
	int i = 0;
	int r, D, x_2000;
	cin >> r >> D >> x_2000;
	int output[100];
	int sum = 0;

	for (i = 0; i < 10; ++i) {
		if (i == 0) {
			sum += r * x_2000-D;
			output[0] = sum;
		}
		else {
			sum = r * output[i-1]-D;
			output[i] = sum;
		}
	}

	for (i = 0; i < 10; ++i) {
		cout << output[i] << endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/ruby
#encoding: utf-8

# 配るDPで書く
# a3.rb の 「if i != n-2」の条件分岐を無くしたver
# dpについて、最初からに要素数の大きい配列を
# hについては、+[0]して１つだけ大きい要素とする。
# 作ってしまえばよい。

n = gets.to_i
h = gets.split.map(&:to_i)+[0]

dp = Array.new(10010000,1e9.to_i)

#p h

dp[0] = 0

(0..n-2).each do |i|
  dp[i+1] = [dp[i+1] , dp[i] + (h[i+1] - h[i]).abs].min
  dp[i+2] = [dp[i+2] , dp[i] + (h[i+2] - h[i]).abs].min
end

puts dp[n-1]

Measured memory_bytes: 86916
#include <stdio.h>
int main(void){
    int a,b,c;
    
    while(scanf("%d %d",&a,&b)!=EOF){
    c=a+b;
    int keta=0;
    while(c!=0){
                c=c/10;
                keta++;
    }
    printf("%d\n",keta);
    }
    return 0;
}



Measured memory_bytes: 1980
#include <stdio.h>

int main(){
  int a, b, n, ans;
  while(~scanf("%d%d%d", &a, &b, &n)){
    ans =  0;
    while(n--){
      a *= 10;
      ans += a / b % 10;
      a = a % b;
      if(!a) break;
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 596
// 問題の URL を書いておく
// 

#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int n;
    cin >> n;
//    vector<int64_t> as(n);

    map<int64_t, int64_t> t;
    int64_t total = 0;
    rep(i, n)
    {
        int a;
        cin >> a;
        total += a;
        if(t.find(a) == t.end())
        {
            t[a] = 0;
        }
        t[a]++;
    }
    int q;
    cin >> q;
    rep(i, q)
    {
        int64_t b, c;
        cin >> b >> c;
        auto bc = t[b];
        t[b] = 0;
        total -= b * bc;
        t[c] += bc;
        total += c * bc;
        cout << total << endl;
    }

    return 0;
}


Measured memory_bytes: 9440
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;


int main(){
    int N,K; cin >> N >> K;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    ll ng = 0;
    ll ok = 1e9;
    
    while(abs(ok-ng)>1){
        ll mid = (ok+ng) / 2;
        auto f = [&](int mid){
            ll now = 0;
            rep(i,N) now += (A[i]-1)/mid;
            return now <= K;
        };
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int b[n-1];
    for(int i=0; i<n-1; i++)
        cin>>b[i];
    int a[n];
    a[0]=b[0];
    int sum=a[0];
    for(int i=1; i<n-1; i++)
    {
        a[i]=min(b[i-1],b[i]);
        sum=sum+a[i];
    }
    a[n-1]=b[n-2];
    sum=sum+a[n-1];
    cout<<sum<<endl;



}


Measured memory_bytes: 256
s = str(input())
n = len(s)
D = [0]*3
for i in range(n):
    D[ord(s[i])-ord('a')] += 1
#print(D)

D.sort(reverse=True)

if D[0]-1 <= D[1] <= D[0] and D[2] >= D[0]-1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 39280
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
#define rep(i,l,r) for(ll i=l;i<=r;i++)

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    string a,b,c;
    ll n;cin>>n;
    cin>>a>>b>>c;
    ll ans=0;
    ll coun;
    rep(i,0,n-1){
        coun=0;
        if(a[i]==b[i]){
            coun++;
        }
        if(c[i]==b[i]){
            coun++;
        }
        if(a[i]==c[i]){
            coun++;
        }
        if(coun==3){
            ans+=0;
        }else{
            ans+=(2-coun);
        }
        
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <random>
/* All our base are belong to AC */
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
ll adad(ll x) {return x*(x+1)/2;} // 1～xの総和

namespace r {
    random_device rd;
    mt19937 mt(rd());
    //mt19937 mt(time(NULL));
    int nd(int max) {return mt() % max + 1;}
    int nd2(int min, int max) {return mt() % (max - min + 1) + min;}
}

int d;
ll c[26], s[365][26], t[365];
set<int> v[26];
ll an;

void solve0() {
  an=0;
  for(int i=0;i<d;i++) {
    an+=s[i][t[i]];
  }
  for(int i=0;i<26;i++) {
    int bf = -2;
    ll su = 0;
    for(int x : v[i]) {
      su+=adad(x-bf-1);
      bf=x;
    }
    an-=su*c[i];
  }
}

void solve1(int h, int k) {
  int bf = t[h];
  an-=s[h][bf];
  an+=s[h][k];

  auto s1 = v[bf].lower_bound(h);
  auto s2 = v[bf].upper_bound(h);
  s1--;
  //cout<<*s1<<" "<<h<<" "<<*s2<<endl;

  an+=adad((*s2) - h - 1) * c[bf];
  an+=adad(h - (*s1) - 1) * c[bf];
  an-=adad((*s2) - (*s1) - 1) * c[bf];
  v[bf].erase(h);
  
  auto t1 = v[k].lower_bound(h);
  auto t2 = v[k].upper_bound(h);
  t1--;
  //cout<<*t1<<" "<<h<<" "<<*t2<<endl;

  an-=adad((*t2) - h - 1) * c[k];
  an-=adad(h - (*t1) - 1) * c[k];
  an+=adad((*t2) - (*t1) - 1) * c[k];
  v[k].insert(h);
  t[h]=k;
}

int main() {
  cin>>d;
  for(int i=0;i<26;i++) {
    cin>>c[i];
  }
  for(int i=0;i<d;i++) {
    for(int j=0;j<26;j++) {
      cin>>s[i][j];
    }
  }
  for(int i=0;i<26;i++) {
    v[i].insert(-1);
    v[i].insert(d);
  }
  for(int i=0;i<d;i++) {
    t[i] = i%26;//r::nd(26)-1;
    v[t[i]].insert(i);
  }
  solve0();
  for(int i=0;i<7000000;i++) {
    if (i%1000==0) {
      ll ba = an;
      int f[3], g[3], undo[3];
      for(int j=0;j<3;j++) {
        f[j] = r::nd(d)-1; g[j] = r::nd(26)-1;
      }
      for(int j=0;j<3;j++) {
        undo[j]=t[f[j]];
      }
      for(int j=0;j<3;j++) {
        solve1(f[j],g[j]);
      }
      if (ba > an) {
        for(int j=0;j<3;j++) {
          solve1(f[j],undo[j]);
        }
      }
    } else {
      int f = i%d, g = i%26;
      ll ba = an;
      int undo = t[f];
      solve1(f,g);
      if (ba > an) solve1(f,undo);
    }
    //if(i%650000==0)cout<<an<<" ";
  } //cout<<endl;
  for(int i=0;i<d;i++) {
    cout<<t[i]+1<<endl;
  }
}

Measured memory_bytes: 3736
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let s = iter.next().unwrap().to_owned();
    let t = iter.next().unwrap().to_owned();
    println!("{}", t + &s);
}


Measured memory_bytes: 4352
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A = LI()
print(sum(A)-N)

Measured memory_bytes: 39152
# listじゃなくてdict使いたい
n = int(input())
j = [0] * 4
moji = ["AC", "WA", "TLE", "RE"]
for i in range(n):
    s=input()
    if s == "AC":
        j[0] += 1
    elif s=="WA":
        j[1] += 1
    elif s=="TLE":
        j[2] += 1
    elif s == "RE":
        j[3] += 1
for k in range(4):
    print(f"{moji[k]} x {j[k]}")


Measured memory_bytes: 9124