akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

int main(void){
    int N; cin >> N;
    cout << N*(N+1)/2 << endl;
}

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

int main()
{
	int n, num;
	list<int> l;
	char s[20];
	scanf("%d", &n);
	for(int i = 0; i < n; ++ i)
	{
		scanf("%s", s);
		if(s[0] == 'i')
		{
			scanf("%d", &num);
			l.push_front(num);
		}
		else if(s[6] == 'F')
		{
			l.pop_front();
		}
		else if(s[6] == 'L')
		{
			l.pop_back();
		}
		else if(s[0] == 'd')
		{
			scanf("%d", &num);
			for(list<int>::iterator it = l.begin(); it != l.end(); it ++)
			{
				if(*it == num)
				{
					l.erase(it);
					break;
				}
			}
		}
	}
	
	int i = 0;
	for(list<int>::iterator it = l.begin(); it != l.end(); it ++)
	{
		if(i ++)	printf(" ");
		printf("%d", *it);
	}
	printf("\n");
	
	
	return 0;
}


Measured memory_bytes: 34440
package main

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

var (
	A, B, C int
)

func main() {
	readVariables()
	var answer string
	if A+B+C >= 22 {
		answer = "bust"
	} else {
		answer = "win"
	}
	fmt.Println(answer)
}

func readVariables() {
	A, B, C = nextInt(), nextInt(), nextInt()

}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
module Main where

readL :: Read a => IO [a]
readL = map read . words <$> getLine

main = do
  [k, x] <- readL
  let p = max (-1000000) $ x - k + 1:: Int
  let q = min 1000000 $ x + k - 1:: Int
  mapM_ print [p..q]


Measured memory_bytes: 764
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>

#define div1 1000000007

using namespace std;

int main(void)
{
    long long N, H, W, A[1001], B[1001], i, ans=0;

    cin >> N >> H >> W;

    for(i=1; i<=N; i++){
        cin >> A[i] >> B[i];

        if(A[i]>=H && B[i]>=W){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
"""
dp[i] := 足場iまでにかかるコストの最小値
"""
N = int(input())
*h, = map(int, input().split())
dp = [0 for _ in range(N)]
dp[1] = abs(h[0] - h[1])  # initialize dp

for i in range(2, N):
    case1 = dp[i-1] + abs(h[i-1] - h[i])
    case2 = dp[i-2] + abs(h[i-2] - h[i])
    dp[i] = min(case1, case2)

print(dp[-1])

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

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    const double pi = acos(-1.0);
    double alpha = (h*60+m)*2*pi/720;
    double beta = m*pi*2/60;
    double gamma = alpha - beta;
    double ans = sqrt(a*a + b*b - 2*a*b*cos(gamma));
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4204
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
//// NG!!
int main() {
  int H,B,N,M,K,X,Y,Z;
  cin >> N;

  vector<int> A(N);

  for(int i=0 ; i < N ; i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  for(int i=1 ; i < N ; i++){
    if(A[i-1] == A[i]){
      cout << "NO" << endl;
      return(0);
    }
  }
  cout << "YES" << endl;
  return(0);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

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

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

    int n;
    cin>>n;
    vector<int> w(n);
    for(int i=0; i<n; i++){
        cin>>w[i];
        if(i>0) w[i]+=w[i-1];
    }
    int answer=INT_MAX;
    for(int i=0; i<n; i++){
        if(answer>abs(w[n-1]-w[i]-w[i])){
            answer=abs(w[n-1]-w[i]-w[i]);
        }
    }
    cout<<answer;

    return 0;
}


Measured memory_bytes: 256
import heapq

N = int(input())
A = sorted(list(map(int, input().split())),reverse=True)
B = [0]
heapq.heapify(B)
conf = 0
ans = 0
for i, a in enumerate(A):
    conf = heapq.heappop(B)
    if i == 0:
        heapq.heappush(B, -a)
    else:
        for _ in range(2):
            heapq.heappush(B, -a)
    ans += (-1) * conf
print(ans)

Measured memory_bytes: 31636
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var [h,w]=arr.shift().split(" ").map(Number);
var b=[];
for(var i=0;i<h;i++){
   arr.shift().split("").forEach((v,j)=>{
      if(v=="B")b.push([i,j]);
   });
}
var max=0;
for(var i=0;i<b.length;i++){
   for(var j=i+1;j<b.length;j++){
      var d=Math.abs(b[i][0]-b[j][0])+Math.abs(b[i][1]-b[j][1]);
      max=Math.max(max,d);
   }
}
console.log(max);


Measured memory_bytes: 16344
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int a,b,c,d;
int main(){
	while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
		if ((abs(c-a) <= d) || (abs(c-b) <= d && abs(b - a)<= d)  )puts("Yes");
			else puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	int n;
	cin >> n;
	map<ll, int> m;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		m[x]++;
	}
	int cnt = 0;
	for(auto i : m){
		if(i.first != i.second){
			if(i.first > i.second)
				cnt += i.second;
			else
				cnt += i.second - i.first;
		}
	}
	cout << cnt << endl;
	return 0;
}






Measured memory_bytes: 6272
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut t = Tree::new(n);
    for _ in 0..n - 1 {
        let i: usize = scan(tokens);
        let j: usize = scan(tokens);
        t.add_edge(i - 1, j - 1);
    }
    println!("{}", t.solve());
}

struct Tree {
    n: usize,
    neighbors: Vec<Vec<usize>>,
    visited: Vec<bool>,
    counts: Vec<Vec<usize>>,
}

impl Tree {
    fn new(n: usize) -> Self {
        Tree {
            n: n,
            neighbors: vec![Vec::new(); n],
            visited: vec![false; n],
            counts: vec![Vec::new(); n],
        }
    }
    fn add_edge(&mut self, i: usize, j: usize) {
        self.neighbors[i].push(j);
        self.neighbors[j].push(i);
    }
    fn visit(&mut self, i: usize) -> usize {
        if self.visited[i] {
            return 0;
        }
        self.visited[i] = true;
        let mut ans = 1;
        for j in 0..self.neighbors[i].len() {
            let i1 = self.neighbors[i][j];
            let k = self.visit(i1);
            if k > 0 {
                self.counts[i].push(k);
                ans += k;
            }
        }
        self.counts[i].push(self.n - ans);
        ans
    }
    fn solve(&mut self) -> usize {
        self.visit(0);
        let power_of_two: Vec<usize> = {
            let mut power_of_two = vec![0; self.n + 1];
            power_of_two[0] = 1;
            for i in 0..self.n {
                power_of_two[i + 1] = power_of_two[i] * 2 % MODULO;
            }
            power_of_two
        };
        let mut ans = 0;
        for i in 0..self.n {
            let l = self.counts[i].len();
            if l == 1 {
                continue;
            }
            ans = (ans + power_of_two[self.n - 1]) % MODULO;
            for j in 0..l {
                let k = self.counts[i][j];
                ans = (ans + neg(power_of_two[k])) % MODULO;
            }
            ans = (ans + l - 1) % MODULO;
        }
        ans * inverse(power_of_two[self.n]) % MODULO
    }
}

const MODULO: usize = 1_000_000_007;

fn power(mut base: usize, mut exponent: usize) -> usize {
    let mut prod = 1;
    while exponent != 0 {
        if exponent & 1 == 1 {
            prod = prod * base % MODULO;
        }
        base = base * base % MODULO;
        exponent >>= 1;
    }
    prod
}

fn inverse(x: usize) -> usize {
    power(x, MODULO - 2)
}

fn neg(x: usize) -> usize {
    if x == 0 {
        0
    } else {
        MODULO - x
    }
}


Measured memory_bytes: 46068
#include <stdio.h>
 
 
 
int main(void){
  char N[4];
  scanf("%s", N);
 
  
  if(N[0]=='7'||N[1]=='7'||N[2]=='7'){
      printf("Yes\n");
        
      }
  else{
        printf("No\n");
  }
 
  return 0;
}
 
 
 

Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

ll power(ll i, ll num)
{
    ll s = 1;
    repi(j, num, 0)
    {
        s *= i;
    }
    return s;
}
int main()
{
    ll N;
    cin >> N;
    cout << power(N,3) << endl;
    return 0;
}


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

int main() {
    int l, r, d;
    int cnt = 0;
    cin >> l >> r >> d;
    for (int i=l; i<=r; i++) {
        if (i % d == 0) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3592
def f(a, b, pb):
    return min(a, b + pb), max(0, b - max(a - pb, 0))

def g(A, B):
    ans, pb = 0, 0
    for a, b in zip(A, B):
        k, pb = f(a, b, pb)
        ans += k
    return ans

N = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split())) + (0,)
print(g(A, B))


Measured memory_bytes: 18624
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int MAX = 510000;
const int MOD = 1000000007;
int main() {
  int h,n;
  cin >> h>>n;
  vector<pair<int,int>>a;
  
  int ta,tb;
  for(int i = 0;i<n;i++){
    cin >> ta >> tb;
    a.push_back(make_pair(ta,tb));
  }
  
  int dp[10001];
  for(int i = 0;i<10001;i++){
    dp[i] = 1000000000;
  }
  
  dp[0] = 0;
  int tmp_a,tmp_b;
  for(int i =1;i<h+1;i++){
    for(int j = 0;j<n;j++){
      tmp_a = a[j].first;
      tmp_b = a[j].second;
      if(i-tmp_a >=0){
        dp[i] = min(dp[i],dp[i-tmp_a]+tmp_b);
      }else{
        dp[i] = min(dp[i],dp[0] + tmp_b);
      }
    }
  }
  cout << dp[h];             
                  
}


Measured memory_bytes: 3672
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
// vector : vector <int> vector;
// array : int array[size];
// set : set<int>set;
// map : map<init , int> map;

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        arr[i] = x;
    }
    int size = sizeof(arr) / sizeof(arr[0]);
    sort(arr, arr + size);
    int sum = 0;
    for (int i = 0; i < k; ++i)
    {
        sum += arr[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
    int K,A,B;
    scanf("%d %d %d",&K,&A,&B);
    if(B/K-A/K >= 1 || B%K == 0 || A%K == 0){
        printf("OK");
    }else{
        printf("NG");
    }
}

Measured memory_bytes: 1732
from collections import deque
from itertools import product
h, w = list(map(int,input().split()))
sy, sx = list(map(int,input().split()))
gy, gx = list(map(int,input().split()))
sx, sy, gx, gy = sx-1, sy-1, gx-1, gy-1
 
G = [list(input()) for _ in range(h)]
D = [[10**6]*w for _ in range(h)]
D[sy][sx] = 0
Q = deque([(sy, sx)])
while Q:
    y, x = Q.pop()
    for dy, dx in product(range(-2, 3), repeat=2):
        ny, nx = y+dy, x+dx
        if dx==dy==0:
            G[y][x] = '#'
        elif (0<=ny<h and 0<=nx<w) and G[ny][nx] != '#':
            if abs(dy)+abs(dx)<=1:
                G[ny][nx] = '#'
                D[ny][nx] = D[y][x]
                Q.append((ny, nx))
            elif D[ny][nx] == 10**6:
                D[ny][nx] = D[y][x]+1
                Q.appendleft((ny, nx))
            
if D[gy][gx] == 10**6:
    print(-1)
else:
    print(D[gy][gx])


Measured memory_bytes: 136828
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//const ll MOD  = 998244353;
//ll MOD;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


struct edge{ll from, to, cost;};
edge es[3000];

ll d[3000];
ll V, E, P;

ll shortest_path(ll s){
  for(ll i = 0; i < V; i++) d[i] = INFL;
  d[s] = 0;
  ll cnt = 0;
  ll ans1, ans2;
  ll res;
  while(true){
    cnt++;
    bool update = 0;
    for(ll i = 0; i < E; i++){
      edge e = es[i];
      if(d[e.from] != INFL && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if(cnt == E* 2) ans1 = d[V-1];
    if(cnt == E * 4){
      ans2 = d[V-1];
      break;
    }
  }
  if(ans1 == ans2 && ans1 < 0) return -d[V-1];
  else if(ans1 == ans2 && ans1 >= 0) return 0;
  return -1;

}

int main(void){
  cin >> V >> E >> P;
  rep(i, E){
    ll A, B, C;
    cin >> A >> B >> C;
    es[i].from = A-1;
    es[i].to = B-1;
    es[i].cost = P - C;
  }
  cout << shortest_path(0) << endl;


}


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

using namespace std;

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

  vector<queue<uint16_t>> A(N+1);
  vector<uint32_t> last_played(N+1,0);

  for (int n1=1; n1<=N; ++n1) {
    for (int n2=1; n2<=N-1; ++n2) {
      short a;
      cin >> a;
      A[n1].push(a);
    }
  }

  uint32_t day = 0;
  bool complete = false;
  bool no_games_prev = false;
  while(!complete) {
    ++day;
    bool no_games = true;
    complete = true;
    for (int player = 1; player < N; ++player) {
      if (A[player].empty())
	continue;
      else
	complete = false;

      if (last_played[player] == day)
	continue;
      
      auto possible_opponent = A[player].front();
      if ( last_played[possible_opponent] < day && A[possible_opponent].front() == player) {
	A[player].pop(); A[possible_opponent].pop();
	last_played[player] = last_played[possible_opponent] = day;
	no_games = false;
      }
    }
    if (complete)
      break;

    if (no_games_prev && no_games) {
      cout << -1 << endl;
      return 0;
    }

    no_games_prev = no_games;
    if (no_games) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << day-1 << endl;

  return 0;
}


Measured memory_bytes: 2432
#134c tle
n=int(input())
s=[int(input()) for i in range(n)]
a=sorted(s)
max_=a[-1]
max_2=a[-2]
#print(s)
for i in range(n):
    if s[i]==max_:
        print(max_2)
    else:
        print(max_)

Measured memory_bytes: 14084
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N=int(input())
number=list(map(int,input().split()))
number1=[i for i in number if i%2==0]
S=len(number1)
ans=0
for j in number1:
    if j%3==0 or j%5==0:
        ans += 1
if S==ans:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 27168
#include<iostream>
#include<string.h>
using namespace std;

int n,c,as[30],bs[30];
int memo[31][1<<16];

int f(int i,int p){
    if(i==n)
        return 0;
    p |= as[i];
    int m = 0;
    for(int j=0;j<c;j++){
        int q = p&~bs[j];
        int v = __builtin_popcount(p&bs[j]);
        int w = memo[i+1][q];
        if(w==-1){
            w = f(i+1,q);
            memo[i+1][q] = w;
        }
        if(m<v+w)
            m = v+w;
    }
    return m;
}
int main(){
    while(true){
        memset(memo,255,sizeof(memo));
        cin >> n >> c;
        if(n==0 && c==0)
            break;
        for(int i=0,v;i<n;i++){
            as[i] = 0;
            for(int j=0;j<16;j++){
                cin >> v;
                as[i] <<= 1;
                as[i] += v;
            }
        }
        for(int i=0,v;i<c;i++){
            bs[i] = 0;
            for(int j=0,v;j<16;j++){
                cin >> v;
                bs[i] <<= 1;
                bs[i] += v;
            }
        }
        cout << f(0,0) << endl;
    }
    return 0;
}

Measured memory_bytes: 9108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 100010


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

int main(){
	ios::sync_with_stdio(false);
	ll n,k,A[SIZE],g=0,mx=0;
	cin>>n>>k;
	rep(i,n){
		cin>>A[i];
		mx= max(mx,A[i]);
		g = gcd(A[i],g);
	}
	if(k%g==0 && k<=mx){
		cout<<"POSSIBLE"<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}

	return 0;
}


Measured memory_bytes: 1024
s = input()

for i in range(2**3):
    b = bin(i)[2:].zfill(3)
    op = ["+" if int(b[j]) else "-" for j in range(3)]
    f = "".join([s[j//2] if j%2==0 else op[(j-1)//2] for j in range(7)])
    if eval(f) == 7:
        print("%s=7" % f)
        quit()

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<numeric>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int n,l;
    int ans=0;
    cin>>n>>l;
    vector<int> a(n),b(n);
    rep(i,n)
    {
        a[i]=l+i;
        b[i]=abs(a[i]);
    }
    ans=accumulate(a.begin(),a.end(),0);
    std::vector<int>::iterator minIt = min_element(b.begin(), b.end());
    int minIndex=distance(b.begin(),minIt);
    cout<<ans-a[minIndex]<<endl;

    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    vector<string> vec;
    cin >> H >> W;
    vec.resize(H);

    for (int i = 0; i < H; ++i) {
        cin >> vec[i];
    }

    for (int i = 0; i < W + 2; ++i) {
        cout << "#";
    }

    cout << endl;


    for (int i = 0; i < H; ++i) {
        cout << "#";
        cout << vec[i];
        cout << "#" << endl;
    }

    for (int i = 0; i < W + 2; ++i) {
        cout << "#";
    }
        cout << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int x;
  double ans = 0;
  cin >> x;
  for (int b = 1; b < 1000; b++) {
    for (int p = 2; p < 1000; p++) {
      if (pow(b, p) <= x) ans = max(ans, pow(b, p));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    string s = "ACL";
    int k;
    cin>>k;
    while(k--) {
      cout << s;
    }
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    // cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n;
    cin >> n;
    int l = 0;
    int k = n;
    while (k > 0){
        k /= 10;
        l++;
    }

    int ans = 0;
    for (int i = 1; i < l; i+=2){
        ans += (pow(10, i) - pow(10, i-1));
    }

    if (l & 1) ans += (n - pow(10, l-1) + 1);
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

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

namespace ConsoleApp15
{
    class Class397
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            Dictionary<int, long> dic = new Dictionary<int, long>();
            for (int i = 0; i < N; i++)
            {
                if (dic.ContainsKey((int)A[i]))
                    dic[(int)A[i]]++;
                else
                    dic[(int)A[i]] = 1;
            }
            long sum = A.Sum();
            var Q = int.Parse(Console.ReadLine());
            for (int i = 0; i < Q; i++)
            {
                var bc = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (dic.ContainsKey(bc[0]))
                {
                    if (dic.ContainsKey(bc[1]))
                    {
                        dic[bc[1]] += dic[bc[0]];
                    }
                    else
                    {
                        dic[bc[1]] = dic[bc[0]];
                    }
                    sum += bc[1] * dic[bc[0]] - bc[0] * dic[bc[0]];
                    dic[bc[0]] = 0;

                }
                Console.WriteLine(sum);
            }
        }
    }
}


Measured memory_bytes: 49608
n = int(input())

import bisect
l = []
def dfs(num, index):
    if index == 9:
        if (num.find("3") != -1) and (num.find("5") != -1) and (num.find("7") != -1):
            l.append(int(num))
        return 0
        
    if num == "":
        ret0 = dfs(num + "" , index+1)
    ret1 = dfs(num + "3", index+1)
    ret2 = dfs(num + "5", index+1)
    ret3 = dfs(num + "7", index+1)

    return 0

dfs("", 0)

print (bisect.bisect_right(l,n))

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define bits(n) __builtin_popcount(n)

void solve()
{
   int x;
   cin>>x;
   if(x>=400&&x<=599)
   cout<<"8";
   else if(x>=600&&x<=799)
   cout<<"7";
   else if(x>=800&&x<=999)
   cout<<"6";
   else if (x >= 1000 && x <=1199)
       cout << "5";
   else if (x >= 1200 && x <= 1399)
       cout << "4";
   else if (x >= 1400 && x <= 1599)
       cout << "3";
   else if (x >= 1600 && x <= 1799)
       cout << "2";
   else if (x >= 1800 && x <= 1999)
       cout << "1";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.length(), m = t.length();
  vector< vector< pair<int,int> > > dp(n+1, vector< pair<int,int> >(m+1,{-1,-1}));
  dp[0][0] = {0,0};
  int di[] = {0,1,1}, dj[] = {1,0,1};
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= m; ++j){
      if(j < m and dp[i][j+1] < dp[i][j]){
        dp[i][j+1].first = dp[i][j].first;
        dp[i][j+1].second = 0;
      }
      if(i < n and dp[i+1][j] < dp[i][j]){
        dp[i+1][j].first = dp[i][j].first;
        dp[i+1][j].second = 1;
      }
      if(i < n and j < m and s[i] == t[j] and dp[i+1][j+1].first < dp[i][j].first+1){
        dp[i+1][j+1].first = dp[i][j].first+1;
        dp[i+1][j+1].second = 2;
      }
    }
  }
  string ans;
  int i = n, j = m;
  while(i > 0 or j > 0){
    //cerr << i << " " << j << " " << dp[i][j].first << " " << dp[i][j].second << endl;
    int k = dp[i][j].second;
    int i_ = i - di[k], j_ = j - dj[k];
    if(dp[i][j].first == dp[i_][j_].first+1) ans += s[i-1];
    i = i_;
    j = j_;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 70784
import datetime

def main():
    H1, M1, H2, M2, K = map(int,input().split())
    start = H1 * 60 + M1
    end = H2 * 60 + M2
    
    ans = end - start - K
    print(ans)
    


if __name__ == "__main__":
    main()

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

int main()
{
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
  cin >> vec[i];
  }
  int sum = 0;
  for(int i=0;i<n-2;i++){
    for(int j = i+1;j<n-1;j++){
      for(int k = j+1;k<n;k++){
      int a,b,c;
        a = vec[i];
        b = vec[j];
        c = vec[k];
        if(a+b>c&&a+c>b&&c+b>a&&a!=b&&b!=c&&c!=a){
          sum++;
          //cout << a << " " << b << " " << c << endl;
        }
      }
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3628
N = int(input())
XYH = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[2], reverse=True)


for cx in range(0, 101):
    for cy in range(0, 101):
        flag = 1
        x, y, h = XYH[0]
        H = h + abs(x - cx) + abs(y - cy)
        for n in range(1, N):
            xn, yn, hn = XYH[n]
            if hn != max(H-abs(xn-cx)-abs(yn-cy), 0):
                flag = 0
        if flag == 1:
            print(cx, cy, H)
            quit()

Measured memory_bytes: 3064
n = gets.chomp.to_i
vlist = gets.chomp.split.collect{ |item| item.to_i}
clist = gets.chomp.split.collect{ |item| item.to_i}

result = 0
n.times do |num|
  if vlist[num] > clist[num]
    result += vlist[num] - clist[num]
  end
end
puts result

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

// n進数 bit 列加算
void add(vector <int> &bits, int x){
    const int n = 2; 
    bits[bits.size()-1] += x;
    for(int i = bits.size() -1 ; i >= 0; i--){
        while(bits[i] >= n){
            bits[i] -= n;
            if(i != 0) bits[i-1] += 1;
        }
    }
}

void printBits(vector <int> &bits){
    for(int i = 0; i < bits.size(); i++){
        cout << bits[i];
    }
    cout << endl;
}

void bit_to_ope(int bit){
    if(bit == 0){
        cout << "+";
    }
    if(bit == 1){
        cout << "-";
    }
}

int calc(vector <int> &bits, vector <int> &num){

    int ans = num[0];
    for(int i = 0; i < bits.size(); i++){
        if(bits[i] == 0){
            ans += num[i+1];
        }
        if(bits[i] == 1){
            ans -= num[i+1];
        }
    }
    return ans;
}

int main(){
    
    vector <int> num(4);
    string s;
    cin >> s;
    for(int i = 0; i < 4; i++){
        num[i] = stoi(s.substr(i,1));
    }
    vector <int> bits(3);
    int bmax = 1;
    for(int i = 0; i < bits.size(); i++){
        bmax = bmax * 2;
    }

    int ans;
    for(int i = 0; i < bmax; i++){
        ans = calc(bits, num);
        if(ans == 7){
            for(int i = 0; i < 3; i++){
                cout << num[i];
                bit_to_ope(bits[i]);
            }
            cout << num[3] << "=7" << endl;
            return 0;
        }
        add(bits, 1);
    }

}



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

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

const int MAXN = (int)2e3;
int n, a[MAXN + 5];
ll f[2 * MAXN + 5];

void update(int x, int y){
	for(int i = x ; i <= 2 * MAXN + 2 ; i += (i & -i)){
		f[i] += y;
	}
}

ll query(int x){
	ll ret = 0;
	for( ; x > 0 ; x -= (x & -x)){
		ret += f[x];
	}
	return ret;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; ++i){
	cin >> a[i];
}
sort(a, a + n);
ll sol = 0;
for(int i = 0 ; i < n ; ++i){
	sol += query(a[i]);
	//cout << sol << endl;
	for(int j = 0 ; j < i ; ++j){
		update(1, 1);
		update(a[i] + a[j], -1);
		//cout << a[i] + a[j] << ' ';
	}
}
cout << sol << endl;

return 0;
}



Measured memory_bytes: 256
$history = {}

class Goal < Exception; end
class Loop < Exception; end

$count = 0

def dummy(id)
	raise Goal if $x == $gx && $y == $gy
	a = [$x, $y, $dx, $dy, id]
	raise Loop if $history[a]
	$history[a] = 1
end

def check(id)
	raise Goal if $x == $gx && $y == $gy
	a = [$x, $y, $dx, $dy, id]
	raise Loop if $history[a]
	$history[a] = 1
	$count += 1
end 

def wall
	$a[$y + $dy][$x + $dx] == ?#
end

def north
	$dx == 0 && $dy == -1
end

def south
	$dx == 0 && $dy == 1
end

def east
	$dx == 1 && $dy == 0
end

def west
	$dx == -1 && $dy == 0
end

def right(id)
	check(id)
	$dx, $dy = -$dy, $dx
end

def left(id)
	check(id)
	$dx, $dy = $dy, -$dx
end

def forward(id)
	check(id)
	unless wall 
		$x += $dx
		$y += $dy
	end
end

def backward(id)
	check(id)
	unless $a[$y - $dy][$x - $dx] == ?#
		$x -= $dx
		$y -= $dy
	end
end

m, n = gets.split.map &:to_i
$a = (1..m).map { gets.chomp.scan /./ }

$dx = 0
$dy = -1
(0..m-1).each do |i|
	(0..n-1).each do |j|
		if $a[i][j] == ?s
			$y, $x = i, j
		end
		if $a[i][j] == ?g
			$gy, $gx = i, j
		end
	end
end

s = gets.chomp

cond = /~*[NESWCT]/
non_par = /[^{}\[\]]/

action_id = 0
0 while
	s.gsub!(/\[(#{cond})(#{non_par}*)\]/, 'if \1;\2;end;') ||
	s.gsub!(/{(#{cond})(#{non_par}*)}/){"while #{$1};dummy(#{action_id += 1});#{$2};end;"}

s.gsub!(?T, "true")
s.gsub!(?~, ?!)
s.gsub!(?C, "wall")
s.gsub!(?N, "north")
s.gsub!(?E, "east")
s.gsub!(?W, "west")
s.gsub!(?S, "south")

s.gsub!(?^) {"forward(#{action_id += 1});"}
s.gsub!(?v) {"backward(#{action_id += 1});"}
s.gsub!(?<) {"left(#{action_id += 1});"}
s.gsub!(?>) {"right(#{action_id += 1});"}

s.gsub!(?;, "\n")

terminate = true

begin
	eval s
rescue Goal
	terminate = false
	p $count
rescue Loop
	terminate = false
	p -1
end

if terminate
	p ($x == $gx && $y == $gy ? $count : -1)
end

Measured memory_bytes: 207240
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}
 
template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

i64 calc_1(i64 len1, i64 len2) {
  i64 ret = LINF;
  i64 side1 = len1 / 2;
  i64 side2 = len1 - side1;

  if (side2 > side1) {
    rep(i, len2) {
      i64 V1 = len1 * i;
      i64 V2 = (len2 - i) * side2;
      i64 V3 = (len2 - i) * side1;

      i64 norm = (V1 > V2 ? V1 - V3 : max(V2 - V3, V2 - V1));
      chmin(ret, norm);
    }
  }

  else {
    rep(i, len2) {
      chmin(ret, abs(i*len1 - side1*(len2 - i)));
    }
  }

  return ret;
}

i64 calc_2(i64 len1, i64 len2) {
  i64 ret = LINF;
  for (i64 i = 1; i*2 < len1; ++i) {
    chmin(ret, abs(i - (len1 - 2*i)) * len2);
  }
  return ret;
}

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

  VAR(i64, H, W);

  if (H % 3 == 0 || W % 3 == 0) {
    OUTL(0);
    return 0;
  }

  i64 res = LINF;
  chmin(res, calc_1(H, W));
  chmin(res, calc_1(W, H));
  chmin(res, calc_2(H, W));
  chmin(res, calc_2(W, H));

  OUTL(res);

  return 0;
}


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

int main(){
    long N;
    cin >> N;
    long max_i = floor(sqrt(N));
    long selected_i, selected_j;
    for(int i=1; i<=max_i; i++){
        if(N % i == 0){
            selected_i = i;
            selected_j = N / i;
        }
    }
    long res = selected_i + selected_j - 2;
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int n;
    cin >> n;
    VI p(n);
    REP(i,n)cin >> p[i];
    int r=-1,l=-1;
    int flag=0;
    REP(i,n-1){
        if(p[i]>p[i+1]&&flag==1){
            l=i+1;
            flag++;
            //cout << l << endl;
        }
        if(p[i]>p[i+1]&&flag==0){
            r=i;
            flag++;
            //cout << r << endl;
        }
        if(flag>2)break;
    }
    if(l==-1){
        if(r!=-1){
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        return 0;
    }
    // if(r==-1){
    //     cout << "NO" << endl;
    //     return 0;
    // }
    swap(p[r],p[l]);
    int re=1;
    REP(i,n-1){
        if(re>=n-1){
            cout << "YES" << endl;
            return 0;
        }
        if(p[i]<p[i+1]){
            re++;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

int main() {
  int n, l;
  cin >> n >> l;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  sort(s, s + n);

  string ans;
  for (int i = 0; i < n; i++) {
    ans += s[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 2e5 + 10;
const int M = (int) 18;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;
int n;

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    multiset<int> st;
    for (int i = 1, a; i <= 3 * n; i++) {
        cin >> a;
        st.insert(a);
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        st.erase(st.begin());
        st.erase(--st.end());
        ans += *st.rbegin();
        st.erase(--st.end());
    } 
    cout << ans;
    return 0;
}   

Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e6 + 10, Mod = 1e9 + 7;
int ch[N][26], cnt[N][26], tot, tim;
LL ans;
string s[N];
bool flg[26];
void insert(int k, int x) {
	if (k == -1) return ;
	if (!ch[x][s[tim][k] - 'a']) ch[x][s[tim][k] - 'a'] = ++tot;
	insert(k - 1, ch[x][s[tim][k] - 'a']);
	flg[s[tim][k] - 'a'] = 1;	
	for (int j = 0; j < 26; j++)
		if (flg[j]) cnt[x][j]++;
}
int main() {
	int n = gi<int>();
	for (int i = 1; i <= n; i++) {
		cin >> s[i]; tim = i;
		for (int j = 0; j < 26; j++) flg[j] = 0;
		insert(s[i].length() - 1, 0);
	}
	for (int i = 1; i <= n; i++) {
		int now = 0, len = s[i].length();		
		for (int j = len - 1; j; j--) 
			now = ch[now][s[i][j] - 'a'];
		ans += cnt[now][s[i][0] - 'a'];
	}
	printf("%lld\n", ans - n);
	return 0;
}


Measured memory_bytes: 297748
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)
 
typedef vector<int> vi;
 
int main()
{
    int w, n;
    scanf("%d%d", &w, &n);
 
    vi line(w);
    rep(i, w) line[i] = i+1;
    rep(i, n){
        int a, b;
        scanf("%d,%d", &a, &b);
        swap(line[a-1], line[b-1]);
    }
 
    rep(i, w) printf("%d\n", line[i]);
 
    return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>
char s[25];
int stack=0;
void push(char c)
{
	s[stack++]=c;
}
char pop(void)
{
	return s[--stack];
}
int main (void)
{
	int n;
	char c;
	for(;;)
	{
		c=getchar();
		if(c=='\n'||c==EOF)
	    {
	    	while(stack)
	           putchar(pop());
			if(c=='\n') putchar(c);	
	    }
	    else 
	        push(c);
		if(c==EOF) break;
		 
	}
    return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <vector>

std::size_t solve(const std::vector<std::vector<std::size_t>>& schedule,
                  std::vector<std::size_t>& finished,
                  std::vector<std::size_t>& update_before) {
  auto people = finished.size();
  std::vector<std::size_t> update(people, 0);
  for (const auto& n : update_before) {
    if (finished[n] == people - 1) continue;
    auto enemy = schedule[n][finished[n]];
    if (finished[enemy] == people - 1) continue;
    if (n == schedule[enemy][finished[enemy]]) {
      update[n] += 1;
      update[enemy] += 1;
    }
  }
  auto res = 0;
  update_before.clear();
  for (std::size_t n = 0; n < people; ++n) {
    if (update[n] != 0) {
      res++;
      finished[n]++;
      update_before.emplace_back(n);
    }
  }
  return res;
}

int main() {
  std::size_t people;
  std::cin >> people;
  std::vector<std::vector<std::size_t>> schedule(people, std::vector<std::size_t>(people - 1));
  for (std::size_t n = 0; n < people; ++n) {
    for (std::size_t m = 0; m < people - 1; ++m) {
      std::cin >> schedule[n][m];
      schedule[n][m]--;
    }
  }

  std::vector<std::size_t> finished(people, 0);
  std::size_t ans = 0;
  std::size_t finish = 0;
  auto mx = people * (people - 1);
  std::vector<std::size_t> buffer(people);
  for (std::size_t n = 0; n < people; ++n) {
    buffer[n] = n;
  }
  while (finish < mx) {
    auto tmp = solve(schedule, finished, buffer);
    if (tmp == 0) {
      std::cout << -1 << std::endl;
      return 0;
    }
    finish += tmp;
    ans += 1;
  }
  std::cout << ans << std::endl;
}

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

using namespace std;

typedef long long LL;

const int nmax = 1000005;

LL N,M,w,e,r;
LL n1,n2,sol;

int main()
{
    int i,j,x;
//    #ifndef ONLINE_JUDGE
//        freopen ("txt.in","r",stdin);
//        freopen ("txt.out","w",stdout);
//    #endif
   ios::sync_with_stdio(false);
   LL sum = 0;
    cin>>N >> M;
    w = M/2;
    sol = min(N,w);
    N-=sol;
    M-=sol*2;
//   cout << M << '\n';
    if(M <= 1){
      cout << sol << '\n';
      return 0;
    }

    sol+=M/4;
    cout << sol << '\n';

    return 0;
}


Measured memory_bytes: 256