akhauriyash/Code-Regression huggingface dataset:
def a(xs):
    k = 0
    m = 0
    ops = []
    for i, x in enumerate(xs):
        if x > m:
            k = i
            m = x
    for i, x in enumerate(xs):
        if xs[i] < 0:
            xs[i] += m
            ops.append((k, i))
    for i in range(len(xs) - 1):
        if xs[i] > xs[i + 1]:
            xs[i + 1] += xs[i]
            ops.append((i, i + 1))
    return ops

def b(xs):
    k = 0
    m = 0
    ops = []
    for i, x in enumerate(xs):
        if x < m:
            k = i
            m = x
    for i, x in enumerate(xs):
        if xs[i] > 0:
            xs[i] += m
            ops.append((k, i))
    for i in range(len(xs) - 2, -1, -1):
        if xs[i] > xs[i + 1]:
            xs[i] += xs[i + 1]
            ops.append((i + 1, i))
    return ops
            
n = input()
xs = map(int, raw_input().split())
m = min(xs)
M = max(xs)
if abs(M) >= abs(m):
    ops = a(xs)
else:
    ops = b(xs)
print len(ops)
for a, b in ops:
    print a + 1, b + 1


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

using namespace std; 
int main()
{


int A,B,C,D;
int x;
int y;
cin>>A>>B>>C>>D;




y=max(A,C);
x=min(B,D);

if(x-y>0)
cout<<x-y;
else
cout<<"0";

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int i, j, n, q, count = 0;
    int dataS[10001],dataT[501];
	cin >> n;
        for (i = 0; i < n; i++){
		cin >> dataS[i];
	}

	cin >> q;
	for (i = 0; i < q; i++){
		cin >> dataT[i];
	}
			for (int j = 0; j < q; j++){
				for (int i = 0; i < n; i++){
				if (dataT[j] == dataS[i]){
					count++;
					break;
				}
		}
	}
		cout << count << "\n";

	return 0;
}

Measured memory_bytes: 1204
import java.nio.file.*;
import java.nio.charset.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set s = new HashSet();
        for(int i=0;i<n;i++){
            s.add(sc.next());
        }
        if(s.size()==3){
            System.out.println("Three");
        }
        else{
            System.out.println("Four");
        }
    }
}

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

int main(void){
    
while(true){
    int n,m;
    int kakaku[1000000];
    int i,j;
    cin >> n >> m ;
    if(n==0&&m==0)break;
    
    for(int i=0;i<n;i++){
        cin >> kakaku[i];
    }
        int ans=-1;
        for (i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                 if(kakaku[i]+kakaku[j] <= m)
                     ans=max(ans, kakaku[i]+ kakaku[j]);
            }
        }
        if(ans==-1)
            cout << "NONE" << endl;
        else
            cout << ans << endl;
        
    
    }
    return 0;
}



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

namespace ConsoleApp15
{
    class Class206
    {
        static void Main()
        {
            var xyabc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x = xyabc[0], y = xyabc[1], a = xyabc[2], b = xyabc[3], c = xyabc[4];
            var p = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(z => z).Take(x);
            var q = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(z => z).Take(y);
            var r = Console.ReadLine().Split().Select(long.Parse).ToList();
            r.AddRange(p);
            r.AddRange(q);
            r = r.OrderByDescending(z => z).ToList();
            long ans = r.GetRange(0, x + y).Sum();
            Console.WriteLine(ans);
        }
    }

}


Measured memory_bytes: 53108
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int n, ans = 0;
	cin >> n;
	rep(i,n){
		int l, r;
		cin >> l >> r;
		ans+=(r-l+1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	
	Vec< int > a(N), b(N);
	for_(i,0,N) cin >> a[i];
	for_(i,0,N) cin >> b[i];
	
	lint sum = 0;
	for_(i,0,N) sum += (b[i] - a[i]);
	
	if (sum < 0) {
		puts("No");
	} else {
		lint cnt_a = 0, cnt_b = 0;
		for_(i,0,N) {
			if (a[i] < b[i]) cnt_a += (b[i] - a[i]) / 2 + (b[i] - a[i]) % 2;
			else cnt_b += a[i] - b[i];
		}
		puts(max(cnt_a, cnt_b) > sum ? "No" : "Yes");
	}
}
//--------------8---------------->> coding space <<-----------------8-------------//


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<ll,ll> g(ll x, ll y) {
	ll z = x / 2;
	return {z * y, (x-z) * y};
}
ll f(ll x, ll y) {
	if (x % 3 == 0 || y % 3 == 0) return 0;
	ll r = 1LL<<60;
	for (ll i = x/3 - 2; i <= x/3 + 2; ++ i) if (1 <= i && i < x) {
		ll a1 = i * y;
		{
			auto p = g(x-i, y);
			r = min(r, max(p.second, a1) - min(p.first, a1));
		}
		{
			auto p = g(y, x-i);
			r = min(r, max(p.second, a1) - min(p.first, a1));
		}
	}
	return r;
}

int main() {
	ll H, W;
	cin >> H >> W;
	cout << min(f(H, W), f(W, H)) << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

type Otoshidama struct {
	X float64
	U string
}

func main() {
	var n int
	fmt.Scan(&n)

	o := make([]Otoshidama, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&o[i].X, &o[i].U)
	}

	var answer float64
	for i := 0; i < len(o); i++ {
		if o[i].U == "BTC" {
			o[i].U = "JPY"
			o[i].X = o[i].X * 380000.0
		}
		answer += o[i].X
	}

	fmt.Println(answer)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(){
  int n;
  vector<int> a(3);
  cin >> n;

  while(n--){
    int MAX;
    
    cin >> a[0] >> a[1] >> a[2];
    a[0] *= a[0];
    a[1] *= a[1];
    a[2] *= a[2];
    MAX = max(a[0], max(a[1], a[2]));
        
    if(MAX == accumulate(a.begin(), a.end(), 0) - MAX){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 2992
function getChangeIndex(input, containText) {
  var index = -1;

  for (var i = input.length - containText.length; i >= 0; i--) {
    if (input[i] !== containText[0] && input[i] !== '?') {
      continue;
    }
    var slicedInput = input.slice(i, i + containText.length);

    var result = true;
    for (var j = 0; j < containText.length; j++) {
      if (slicedInput[j] !== containText[j] && slicedInput[j] !== '?') {
        result = false;
        break;
      }
    }

    if (result) {
      index = i;
      break;
    }
  }
  return index;
}

function solve(inputRaw) {
  var row = inputRaw.trim().split('\n');
  var input = row[0];
  var containText = row[1];

  var index = getChangeIndex(input, containText, 0);

  if (index >= 0) {
    var result = input.substr(0, index) + containText + input.substr(index + containText.length, input.length);
    result = result.split('?').join('a');
    return result;
  }

  return 'UNRESTORABLE';
}

console.log(solve(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 21444
N = int(input())

class Node():
    def __init__(self, parent=-1, left=-1, right=-1):
        self.parent = parent
        self.left = left
        self.right = right

T = [Node() for _ in range(N)]

for _ in range(N):
    id, left, right = map(int, input().split())

    T[id].left = left
    T[id].right = right

    if left != -1:
        T[left].parent = id
    if right != -1:
        T[right].parent = id


def preorder(id):
    if id == -1:
        return

    preorder_list.append(id)

    preorder(T[id].left)
    preorder(T[id].right)

def inorder(id):
    if id == -1:
        return

    inorder(T[id].left)
    inorder_list.append(id)
    inorder(T[id].right)

def postorder(id):
    if id == -1:
        return

    postorder(T[id].left)
    postorder(T[id].right)
    postorder_list.append(id)

preorder_list = []
inorder_list = []
postorder_list = []
for id in range(N):
    if T[id].parent == -1:
        preorder(id)
        inorder(id)
        postorder(id)
        break


print("Preorder")
print(" "+" ".join(map(str, preorder_list)))
print("Inorder")
print(" "+" ".join(map(str, inorder_list)))
print("Postorder")
print(" "+" ".join(map(str, postorder_list)))


Measured memory_bytes: 5616
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> abc = new ArrayList<>();
        abc.add(sc.nextInt());
        abc.add(sc.nextInt());
        abc.add(sc.nextInt());
        Collections.sort(abc);
        int k = sc.nextInt();
        System.out.println((int) (abc.get(0) + abc.get(1) + abc.get(2) * Math.pow(2, k)));
    }

}


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

using namespace std;

using ll = long long;

ll solve(const ll capacity, const vector<pair<ll, ll>> &items) {
    const int sz = items.size();
    
    const ll max_value = accumulate(items.cbegin(), items.cend(), 0, [](const ll agg, const auto item) { 
        return agg + item.second; 
    });
    
    // dp -- min weight [up to item index i][with total value exactly j]
    vector<vector<ll>> dp(sz, vector<ll>(max_value + 1, LLONG_MAX));
    ll ans = LLONG_MIN;
    
    for (int i = 0; i != sz; ++i) {
        for (ll j = 1; j <= max_value; ++j) {
            const ll w = items[i].first;
            const ll v = items[i].second;
            
            if (!i) {
                if (v == j) dp[i][j] = w;
            } else {
                if (v == j) {
                    dp[i][j] = min(dp[i - 1][j], w);
                } else if (v < j) {
                    if (dp[i - 1][j - v] != LLONG_MAX) dp[i][j] = min(dp[i - 1][j - v] + w, dp[i - 1][j]);
                    else dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }

            if (dp[i][j] <= capacity) {
                ans = max(ans, j);
            }
        }
    }
    
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    
    ll N, W;
    cin >> N >> W;
    vector<pair<ll, ll>> items(N);
    
    for (auto &item : items) {
        ll w, v;
        cin >> w >> v;
        item = {w, v};
    }
    
    cout << solve(W, items) << endl;
    
    return 0;
}


Measured memory_bytes: 79488
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

// swap(a,b);
// abs(a,b); a,bの型は問わない
// reverse(a+I,a+r); aは配列,a[i]からa[r-1]までを逆順にする.計算量はN. reverse(str.begin(),str.end());
// sortも上とあまり変わらない.
// ただし,sort(a,a+N,greater<int>());で大きい順にならべかえる.
// stack<int> a; 宣言 上に積み上げたものをとったり、一番上に積み上げる.
// a.push(x); aに要素xをつむ a.pop(); a.size(); a.empty(); これはtrue or false
// a.top;で一番上の要素を返す
// queue<int> a; a.front();
// priority_queue<int,vector<int>,greater<int>> Q1; 最も小さい奴を取り出す
// priority_queue<double,vector<double>,less<double>> Q2;最も大きい値を取り出す
// Q1.top();ができる
// count(a+l,a+r,x);
// find(a+l,a+r,x);
// 文字変換
//char a='a';
//a=a+1;
//cout<<a<<endl;


int main(){
  int N,K;cin>>N>>K;
  priority_queue<int,vector<int>,less<int>> Q1;
  ll tmp;
  REP(i,N){
    cin>>tmp;
    Q1.push(tmp);
  }
  if(K>=N){
    cout<<0<<endl;
    return 0;
  }
  REP(i,K){
    Q1.pop();
  }
  ll ans=0;
  REP(i,N-K){
    tmp=Q1.top();
    Q1.pop();
    ans=ans+tmp;
  }
  cout<<ans<<endl;

}

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

int main(){
    char s[3300];
    char t[3300];
    char res[3300] = {};
    char ans[3300] = {};
    int slen, tlen;
    int i, j, k;
    int tmp;
    int dp[3300][3300];

    for(i=0; i<3300; i++){
        for(j=0; j<3300; j++){
            dp[i][j] = 0;
        }
    }

    scanf("%s", &s);
    scanf("%s", &t);
    slen = strlen(s);
    tlen = strlen(t);

    for(i=0; i<slen; i++){
        for(j=0; j<tlen; j++){
            if(s[i]==t[j]){
                tmp = dp[i][j] +1;
                if(dp[i+1][j+1] < tmp){
                    dp[i+1][j+1] = tmp;
                }
            }
            tmp = dp[i+1][j];
            if(dp[i+1][j+1] < tmp){
                dp[i+1][j+1] = tmp;
            }
            tmp = dp[i][j+1];
            if(dp[i+1][j+1] < tmp){
                dp[i+1][j+1] = tmp;
            }
        }
    }
    i = slen;
    j = tlen;
    k = 0;

    while(i>0 && j>0){
        if(dp[i][j] == dp[i-1][j]){
            i--;
        }else if(dp[i][j] == dp[i][j-1]){
            j--;
        }else{
            res[k] = s[i-1];
            i--, j--, k++;
        }
    }
    for(i=0; i<k; i++){
        ans[i] = res[k-i-1]; 
    }

    printf("%s", ans);


    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans1 = 0, ans2 = 0, ans3 = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[0] == 'R') ans1++;
    if(s[1] == 'R') ans2++;
    if(s[2] == 'R') ans3++;
  }
  if((ans1 && ans2) && ans3) cout << 3 << endl;
  else if((ans1 && ans2) || (ans2 && ans3)) cout << 2 << endl;
  else if(ans1 || ans2 || ans3) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3616
m = int(input())
P = [list(map(int, input().split())) for i in range(m)]
s = set()
for i in range(m):
    xi, yi = P[i]
    for j in range(i+1, m):
        xj, yj = P[j]
        u = xj - xi; v = yj - yi
        for x, y in s:
            if x * v == y * u:
                break
        else:
            s.add((u, v))
memo = {}
def dfs(state, dx, dy):
    if (state, dx, dy) in memo:
        return memo[state, dx, dy]
    pstate = state
    update = 1
    cnt = -1
    while update:
        update = 0; cnt += 1
        for i in range(m):
            if (state >> i) & 1:
                continue
            xi, yi = P[i]
            for j in range(i+1, m):
                if (state >> j) & 1:
                    continue
                xj, yj = P[j]
                u = xj - xi; v = yj - yi
                if dx * v == dy * u:
                    update = 1
                    state |= (1 << i) | (1 << j)
                    break
            if update: break
    if cnt <= 1:
        res = 0
    else:
        res = cnt*(cnt-1)//2 + max(dfs(state, *e) for e in s)
    memo[pstate, dx, dy] = res
    return res
print(max(dfs(0, *e) for e in s))

Measured memory_bytes: 6672
import java.util.Scanner;

/**
 * B - Battle
 * 高橋君と青木君がモンスターを闘わせます。
 * 高橋君のモンスターは体力が A で攻撃力が B です。
 * 青木君のモンスターは体力が C で攻撃力が D です。
 * 高橋君→青木君→高橋君→青木君→... の順に攻撃を行います。
 * 攻撃とは、相手のモンスターの体力の値を自分のモンスターの攻撃力のぶんだけ減らすことをいいます。
 * このことをどちらかのモンスターの体力が 0 以下になるまで続けたとき、 先に自分のモンスターの体力が 0 以下になった方の負け、そうでない方の勝ちです。
 * 高橋君が勝つなら Yes、負けるなら No を出力してください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 高橋くんのモンスターの体力
        double a = sc.nextDouble();
        // 高橋くんのモンスターの攻撃力
        double b = sc.nextDouble();
        // 青木くんのモンスターの体力
        double c = sc.nextDouble();
        // 青木くんのモンスターの攻撃力
        double d = sc.nextDouble();

        double takahashi = Math.ceil( a / d );
        double aoki = Math.ceil( c / b );

        System.out.println( takahashi >= aoki ? "Yes" : "No" );

        sc.close();
    }
}

Measured memory_bytes: 37420
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  int v[n],c[n];
  ll ans=0;
  rep(i,0,n) cin>>v[i];
  rep(i,0,n) cin>>c[i];
  rep(i,0,n) if(v[i]>c[i]) ans+= v[i]-c[i];
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3588
use std::io::*;

fn main() {
  let input = {
    let mut buf = vec![];
    stdin().read_to_end(&mut buf);
    unsafe { String::from_utf8_unchecked(buf) }
  };
  let mut lines = input.split('\n');

  let (n, m) = {
    let line = lines.next().unwrap();
    let mut iter = line.split(' ').map(|s| s.parse::<usize>().unwrap());

    (iter.next().unwrap(), iter.next().unwrap())
  };

  let mut cost = lines.next().unwrap()
    .bytes().filter(|&ch| ch != b'W').count();

  let mut wr = Vec::with_capacity(n - 2);
  wr.extend(lines.by_ref().take(n - 2).map(|l| {
    l.bytes().fold((0, 0), |(w, r), ch| match ch {
      b'W' => (w + 1, r),
      b'R' => (w, r + 1),
      _    => (w, r)
    })
  }));

  let mut min = usize::max_value();

  for i in 0..(n - 2) {
    let w: usize = wr[..i].iter().map(|&(w, _)| m - w).sum();

    for j in (i + 1)..(n - 1) {
      let b: usize = wr[i..j].iter().map(|&(w, r)| w + r).sum();
      let r: usize = wr[j.. ].iter().map(|&(_, r)| m - r).sum();

      let cost = w + b + r;
      if min > cost { min = cost; }
    }
  }
  cost += min;

  cost += lines.next().unwrap()
    .bytes().filter(|&ch| ch != b'R').count();

  println!("{}", cost);
}



Measured memory_bytes: 5024
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<i64>();
    let mut ans = 1;
    for i in 1..n + 1 {
        if i * i <= n {
            ans = i * i;
        } else {
            break;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>a(N+1);

	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	int tmp = 1, ans = 0;
	while(1) {
		ans++;
		if (a[tmp] == 2) {
			cout << ans << endl;
			break;
		}
		tmp = a[tmp];
		if (ans > N) {
			cout << -1 << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 768
/*
    And I know I may end up failing too
*/




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

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

#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF          0x3f3f3f3f

struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);auto hash2 = hash<T2> {}(p.second);return hash1 ^ hash2;
    }
};

ll t;
ll mod=N;
ll BigMod(ll base,ll pow,ll mod)
{
    if(pow==0||base==1)return 1;
    else if(pow==1)return base;
    else if(pow%2)return BigMod(base,pow-1,mod)*base%mod;
    else {ll x=(BigMod(base,pow/2,mod)%mod);x=(x*x)%mod;return x;}
}

vector<ll>v;

int main()
{
    fast;
    ll a,b,c,d,e,f,g,i,j;
    ll n,m,k;
    f=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        f^=a;
        v.pb(a);
    }
    for(i=0;i<n;i++)
    {
        if(i)cout<<' ';
        b=f^v[i];
        cout<<b;
    }
    cout<<endl;
    return 0;
}


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

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

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    ll X[N];
    X[0] = 0;
    rep(i, N) {
        if (i % 2 == 0) X[0] += A[i];
        else X[0] -= A[i];
    }
    rep(i, N - 1) X[i + 1] = (A[i] - X[i] / 2) * 2;

    rep(i, N) {
        cout << X[i];
        if (i != N - 1) cout << " ";
        else cout << endl;
    }


    return 0;
}


Measured memory_bytes: 2816
<?php
    fscanf(STDIN, "%s", $s);
    $result = '';
    switch($s){
        case 'Sunny':
        $result =  'Cloudy';
        break;
        case 'Cloudy';
        $result =  'Rainy';
        break;
        case 'Rainy';
        $result = 'Sunny';
        break;
    }
    echo $result;
  ?>

Measured memory_bytes: 3828
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define N 25
#define mo 1000000007
using namespace std;
int n,m,h,a[N][N],f[N][1048577],e[N],nxt[1048577][N],ans=0;
int main()
{
	scanf("%d%d%d",&n,&m,&h);
	fo(i,1,h)
	{
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		a[x][y]=z+1;
	}
	e[0]=1;fo(i,1,n) e[i]=e[i-1]*2;
	fo(s,0,e[n]-1)
	{
		int y=-1;
		fd(j,n,1)
		{
			nxt[s][j]=y;
			if(s&e[j-1]) y=j;
		}
	}
	f[n][0]=1;
	fo(i,1,m)
	{
		fo(s,0,e[n]-1) f[1][s]=f[n][s];
		fo(j,2,n) fo(s,0,e[n]-1) f[j][s]=0;
		fo(j,1,n-1)
		{
			fo(s,0,e[n]-1)
			if(f[j][s])
			{
				if(s&e[j-1])
				{
					if(a[i][j]!=1) (f[j+1][s]+=f[j][s])%=mo;
				}
				else
				{
					if(a[i][j]!=2) (f[j+1][s]+=f[j][s])%=mo;
					if(a[i][j]!=1)
					{
						int s1=s;
						if(nxt[s][j]!=-1) s1-=e[nxt[s][j]-1];
						s1+=e[j-1];
						(f[j+1][s1]+=f[j][s])%=mo;
					}
				}
			}
		}
	}
	fo(s,0,e[n]-1) (ans+=f[n][s])%=mo;
	printf("%d\n",ans);
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int H, W, N;
char B[111][111];

signed main() {
  cin >> H >> W;
  rep (i, H) {
    cin >> B[i];
  }

  int y = 0, x = 0;
  while (1) {
    B[y][x] = '.';
    // dbg2(y, x)
    if (y == H-1 and x == W-1) break;

    if (y + 1 < H and B[y+1][x] == '#') {
      y++;
      continue;
    }
    if (x + 1 < W and B[y][x+1] == '#') {
      x++;
      continue;
    }
    puts("Impossible");
    return 0;
  }

  // print2(B, H, W);

  rep (i, H) {
    rep (j, W) {
      if (B[i][j] == '#') {
        puts("Impossible");
        return 0;
      }
    }
  }
  puts("Possible");

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
int v[110000];
long long ijk[110000];
long long ijk2[110000];
int ans[110000];
vector<pair<int,int> > g[110000];
long long z[110000];
int bit[110000];
int n;
pair<long long,long long>pt[110000];
pair<long long,pair<int,long long > >ev[110000];
void add(int a,int b){
	for(;a<110000;a|=a+1)bit[a]+=b;
}
int sum(int a,int b){
	if(a>b)return 0;
	if(a)return sum(0,b)-sum(0,a-1);
	int ret=0;
	for(;b>=0;b=(b&(b+1))-1)ret+=bit[b];
	return ret;
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	n=a;
	for(int i=0;i<b;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);
		g[p].push_back(make_pair(q,r));
		g[q].push_back(make_pair(p,r));
	}
	for(int i=0;i<a;i++)ijk[i]=99999999999999LL;
	ijk[0]=0;
	priority_queue<pair<long long,int> > Q;
	Q.push(make_pair(0,0));
	while(Q.size()){
		long long cost=-Q.top().first;
		int at=Q.top().second;
		Q.pop();
		if(v[at])continue;
		v[at]=1;
		for(int i=0;i<g[at].size();i++){
			if(!v[g[at][i].first]&&ijk[g[at][i].first]>cost+g[at][i].second){
				ijk[g[at][i].first]=cost+g[at][i].second;
				Q.push(make_pair(-cost-g[at][i].second,g[at][i].first));
			}
		}
	}
	for(int i=0;i<a;i++)v[i]=0;
	for(int i=0;i<a;i++)ijk2[i]=999999999999999LL;
	ijk2[a-1]=0;
	Q.push(make_pair(0,a-1));
	while(Q.size()){
		long long cost=-Q.top().first;
		int at=Q.top().second;
		Q.pop();
		if(v[at])continue;
		v[at]=1;
		for(int i=0;i<g[at].size();i++){
			if(!v[g[at][i].first]&&ijk2[g[at][i].first]>cost+g[at][i].second){
				ijk2[g[at][i].first]=cost+g[at][i].second;
				Q.push(make_pair(-cost-g[at][i].second,g[at][i].first));
			}
		}
	}
	for(int i=0;i<a;i++){
		if(ijk[i]>10000000000LL||ijk2[i]>10000000000LL){
			while(1);
		}
	}
	for(int i=0;i<a;i++)z[i]=ijk2[i];
	std::sort(z,z+a);
	int c;scanf("%d",&c);
	for(int i=0;i<c;i++){
		long long p,q;scanf("%lld%lld",&p,&q);
		ev[i]=make_pair(p,make_pair(i,q));
	}
	std::sort(ev,ev+c);
	for(int i=0;i<a;i++)pt[i]=make_pair(ijk[i],ijk2[i]);
	std::sort(pt,pt+a);
	int at=0;
	for(int i=0;i<c;i++){
		while(at<a&&pt[at].first<=ev[i].first){
			add(lower_bound(z,z+a,pt[at].second)-z,1);
			at++;
		}
		if(ev[i].second.second>z[a-1])continue;
		ans[ev[i].second.first]=sum(lower_bound(z,z+a,ev[i].second.second)-z,a-1);
	}
	for(int i=0;i<c;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 15852
#include <stdio.h>

int main(void)
{
    int N, M, P;
    int X;
    int sum, win;
    int i;
    int devident;
    
    while (1){
        scanf("%d%d%d", &N, &M, &P);
        if ((N | M | P) == 0){
            break;
        }
        
        sum = 0;
        for (i = 1; i <= N; i++){
            scanf("%d", &X);
            sum += X;
            if (i == M){
                win = X;
            }
        }
        
        if (win == 0){
            devident = 0;
        }
        else {
            devident = sum * (100 - P) / win;
        }
        
        printf("%d\n", devident);
        
    }
    
    return (0);
}

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

typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, K, H[200000];
ll res;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	sort(H, H + N);
	for (int i = 0; i < N - K; i++) {
		res += H[i];
	}
	cout << res << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  string s;
  cin>>s;
  int ans = 0;
  int buf = 0;
  for(c:s){
    if(c=='A'||c=='T'||c=='C'||c=='G') buf++;
    else{
      ans = max(buf,ans);
      buf = 0;
    }
  }
  ans = max(ans,buf);
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int road[n + 1] = {};
  for(int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    road[a]++;
    road[b]++;
  }

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

Measured memory_bytes: 256
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table



N = int(input())
ans = []

list_divisor = divisor(N)

for a in list_divisor:
    b = N // a
    len_a = len(str(a))
    len_b = len(str(b))
    ans.append(max(len_a,len_b))

print(min(ans))

Measured memory_bytes: 3188
/*
  AOJ 2609
  Title:Wave Attack
  @kankichi573
*/
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <limits.h>
typedef long long ll;
int w,h,v,t,x,y,p,q;

main()
{
  int i,j,total;
  int xmin,xmax,xpos,ypos,xlim,ylower,yupper;
  ll total2,ret,ypos2,xpos2;

  scanf("%d %d %d %d %d %d %d %d",&w,&h,&v,&t,&x,&y,&p,&q);
  total = v*t;
  total2=(ll)total*total;
  yupper=  total/h+1;
  ylower= -total/h-1;
  ret=0;

  for(i=ylower;i<=yupper;i++)
    {
      ypos=h*i+((i&1)?(h-q):q);
      ypos2=(ll)(ypos-y)*(ypos-y);
      if(total2 < ypos2)
	continue;
      xlim=(int)sqrt(total2-ypos2)/w;

      for(j=-xlim-1;j<=0;j++)
	{
	  xpos=w*j+((j&1)?(w-p):p);
	  xpos2 = (ll)(xpos-x)*(xpos-x);
	  if(total2 >= ypos2+xpos2)
	    {
		    xmin=j;
		    goto NEXT;
	    }
	}
      continue;
    NEXT:
      for(j=xlim+1;j>=0;j--)
	{
	  xpos=w*j+((j&1)?(w-p):p);
	  xpos2 = (ll)(xpos-x)*(xpos-x);
	  if(total2 >= ypos2+xpos2)
	    {
		    xmax=j;
		    goto NEXT2;
	    }
	}
      continue;
    NEXT2:
      ret += (ll)(xmax - xmin + 1);
    }
  printf("%lld\n",ret);
  return(0);
}

Measured memory_bytes: 596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi p(n);
    rep(i, n) cin >> p[i];

    vi a(n, 1), b(n, 1);
    int h = n-1;
    rep(i, n) {
        int now = p[i];
        now--;
        if(now != n-1) a[now+1] += h;
        if(now) b[now-1] += h;
        h--;
    }
    rep(i, n-1) {
        a[i+1] += a[i];
        b[n-i-2] += b[n-i-1];
    }

    rep(i, n) {
        cout << a[i] << (i == n-1?'\n':' ');
    }
    rep(i, n) {
        cout << b[i] << (i == n-1?'\n':' ');
    }
}

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

int culc(int x,int y,int z){
  int ans=0;
  
  if(z==0){
    ans=x+y;
  }else{
    ans=x-y;
  }
  //cout<<x<<" "<<z<<" "<<y<<"="<<ans<<endl;
  return ans;
}

int main(){
  int A,B,C,D;
  string tmp;
  cin>>tmp;
  A=(int)(tmp.at(0)-'0');
  B=(int)(tmp.at(1)-'0');
  C=(int)(tmp.at(2)-'0');
  D=(int)(tmp.at(3)-'0');
  
  //cout<<A<<" "<<B<<" "<<C<<" "<<D<<endl;
  
  int ans=0;
  string pm;
  for(int i=0;i<(1<<3);i++){
    bitset<3> s(i);
    //cout<<s<<endl;
    ans=culc(A,B,s[0]);
    ans=culc(ans,C,s[1]);
    ans=culc(ans,D,s[2]);
    if(ans==7){
      for(int x=0;x<3;x++){
        if(s[x]==0){
          pm+="+";
        }else{
          pm+="-";
        }
      }
      break;
    }
  }
  
  cout<<A<<pm[0]<<B<<pm[1]<<C<<pm[2]<<D<<"="<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
using console = System.Console;

public class App
{
    public static void Main(string[] args)
    {
        console.WriteLine(Max(readarr.Max()*2-1,preadarr.Sum()));
    }
}
public class Exter
{
    public static int Max(params int[] p)=>p.Max();
    public static short Max(params short[] p)=>p.Max();
    public static long Max(params long[] p)=>p.Max();
    public static string read
    {
        get
        {
            char c;
            string s = "";
            while(true)
            {
                c = console.ReadKey().KeyChar;
                if(c == ' '||c=='\n')
                    break;
                s += c;
            }
            return s;
        }
    }
    public static int readi
    {
        get
        {
            char c;
            string s = "";
            while(true)
            {
                c = console.ReadKey().KeyChar;
                if(c == ' '||c=='\n')
                    break;
                s += c;
            }
            return int.Parse(s);
        }
    }
    public static int[] preadarr;
    public static int[] readarr
    {
        get
        {
            preadarr = console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            return preadarr;
        }
    }
    public static long readl
    {
        get
        {
            char c;
            string s = "";
            while(true)
            {
                c = console.ReadKey().KeyChar;
                if(c == ' '||c=='\n')
                    break;
                s += c;
            }
            return long.Parse(s);
        }
    }
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s,w = LI()
if s <= w:
    print('unsafe')
else:
    print('safe')

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

class Dice{
	int top, n, s, e, w;
public:
	Dice();
	void roll(char dir);
	void turn(char dir);
	int getNum(char dir);
};

Dice::Dice(){
	top = 1;
	n = 5;
	s = 2;
	e = 3;
	w = 4;
}

void Dice::roll(char dir){
	switch (dir){
	case 'N':
		n = top;
		top = s;
		s = 7 - n;
		break;
	case 'S':
		s = top;
		top = n;
		n = 7 - s;
		break;
	case 'E':
		e = top;
		top = w;
		w = 7 - e;
		break;
	case 'W':
		w = top;
		top = e;
		e = 7 - w;
		break;
	}
}

void Dice::turn(char dir){
	switch (dir){
	case 'R':
		n = w;
		w = s;
		s = e;
		e = 7 - w;
		break;
	case 'L':
		n = e;
		e = s;
		s = w;
		w = 7 - e;
		break;
	}
}

int Dice::getNum(char dir){
	switch (dir){
	case 'T':return top;
	case 'N':return n;
	case 'E':return e;
	case 'W':return w;
	case 'S':return s;
	case 'B':return 7-top;
	default: return -1;
	}
}

int main(void){
	int d[6], d2[6], c=0;
	Dice dice, dice2;

	for (int i = 0; i < 6; i++){
		cin >> d[i];
	}
	for (int i = 0; i < 6; i++){
		cin >> d2[i];
	}

	while (d[dice.getNum('T') - 1] != d2[dice2.getNum('T') - 1]){
		if (c < 4)	dice2.roll('S');
		else dice2.roll('E');
		c++;
	}

	while (d[dice.getNum('S') - 1] != d2[dice2.getNum('S') - 1]){
		dice2.turn('R');
	}

	if (d[dice.getNum('E') - 1] == d2[dice2.getNum('E') - 1]){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 1124
# 入力
N = int(input())

# 処理
exist = False           # 条件を満たす買い方が存在する
for i in range(100):    # ケーキを買う個数
  for j in range(100):  # ドーナツを買う個数
    s = i*4 + j*7       # 合計金額
    if s == N:          
      exist = True      # 条件を満たす買い方を見つけた

# 出力
if exist:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn=2*1e5+5;
long long a[maxn];
int main()
{
    int n;
    long long sum1=0,sum2=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]),sum2+=a[i];
    sum1=a[0],sum2-=a[0];
    long long Min=abs(sum1-sum2);
    for(int i=1;i<n-1;i++)
    {
        Min=min(Min,abs(sum1-sum2));
        sum1+=a[i];sum2-=a[i];
    }
    cout<<Min<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int Prime(int);
int main(){
    int i,n,x,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(Prime(x) == 1) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}
int Prime(int n){
    int i;
    if(n < 2) return 0;
    else if(n == 2) return 1;
    if(n % 2 == 0) return 0;
    for(i = 3;i*i <= n;i+=2){
        if(n%i == 0) return 0; 
    }
    return 1;
}



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

#define INF INT_MAX

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;



int main(void){
 	cin.tie(0);
    ios::sync_with_stdio(false);
	
	int N,L;
	cin >> N >> L;

	int sum = 0;
	for(int i = 1;i <= N;i++){
		sum += L + i -1;		
	}

	if(L <= 0 && 0 <= L + N - 1 ){
		cout << sum << endl;
	}else{
		if(L <= 0){
			cout << sum - (L+N-1) << endl;
		}else{
			cout << sum - (L) << endl;
		}
	}	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    ll n, W;
    cin >> n >> W;
    vector<ll> w(n);
    vector<ll> v(n);

    REP(i,n){
        cin >> w[i] >> v[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, 0));

    FOR(i,0,n){
        FOR(j,0,W+1){
            if(j - w[i] >= 0){
                dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
            else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}

Measured memory_bytes: 80256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};


int H,W;
int a[505][505];
vector<pair<int,int>> be,af;

int main(){
      cin>>H>>W;
      int cnt=0;
      rep0(i,H){
            rep0(j,W){
                  cin>>a[i][j];
                  a[i][j]=a[i][j]%2;
            }
      }
      rep0(i,H){
            rep0(j,W){
                  if(i==(H-1)&&j==(W-1)) break;
                  if(a[i][j]%2==1){
                        be.push_back({i+1,j+1});
                  
                  if(j==(W-1)){
                        a[i+1][j]=(a[i+1][j]+1)%2;
                        af.push_back({i+2,j+1});
                  }
                  else{
                        a[i][j+1]=(a[i][j+1]+1)%2;
                        af.push_back({i+1,j+2});
                  
                  }
                  cnt++;
                  }
            }
      }
      cout<<cnt<<endl;
      rep0(i,cnt){
            cout<<be[i].first<<" "<<be[i].second<<" "<<af[i].first<<" "<<af[i].second<<endl;
      }

      return 0;
}

Measured memory_bytes: 5228
N = int(input())
A = list(map(int, input().split()))
B = list(A[i] - (i + 1) for i in range(N))
B.sort()
if (N % 2 == 1):
  b = B[N // 2]
else:
  b = (B[N // 2 - 1] + B[N // 2]) // 2
ans = sum(abs(B[i] - b) for i in range(N))
print(ans)


Measured memory_bytes: 25196
#include<bits/stdc++.h>
using namespace std;
int main()
{
	priority_queue<int>q;
	int n,m,a,ans=0,t;scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%d",&a),q.push(a);
	while(m--){
		t=q.top();q.pop();
		ans+=t;
	} 
	cout<<ans<<endl;
 } 

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

int main(){
    int n,l;
    cin >> n >> l;
    int all=0,res=0;
    int tas=300;
    for (int i = 1; i <= n; i++)
    {
        all+=l+i-1;
    }
  	for(int i=1;i<=n;i++){
      	if(abs(all-(all-(l+i-1)))<tas){
          res=all-(l+i-1);
        }
      	tas=min(abs(all-(all-(l+i-1))),tas);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
 
def print_arr(arr):
    for i in range(len(arr)):
        sys.stdout.write(str(arr[i]))
        if i != len(arr) - 1:
            sys.stdout.write(' ')
    print()
 
def insertion_sort(arr, n, g):
    cnt = 0
    for i in range(g, n):
        v = arr[i]
        j = i - g
        while j >= 0 and arr[j] > v:
            arr[j + g] = arr[j]
            j = j - g
            cnt += 1
        arr[j + g] = v
    return cnt
 
def shell_sort(arr, g):
    cnt = 0
    for i in range(len(g)):
        cnt += insertion_sort(arr, len(arr), g[i])
    return cnt
 
def get_gap(n):
    lst = []
    v = 1
    cnt = 1
    while v <= n:
        lst.append(v)
        v += 3**cnt
        cnt += 1
    if len(lst) == 0: lst.append(1)
    return list(reversed(lst))
 
n = int(input())
arr = [0] * n
for i in range(n):
    arr[i] = int(input())
 
g = get_gap(n)
m = len(g)
cnt = shell_sort(arr, g)
 
print(m)
print_arr(g)
print(cnt)
for i in range(n):
    print(arr[i])


Measured memory_bytes: 45480
//#pragma GCC optimize(2)


#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#include<ext/rope>*/
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
//void err(istream_iterator<string> it){cerr<<endl;}
//template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args){cerr << *it << " = " << a << " , ";err(++it, args...);}
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mem(a,b) memset((a),b,sizeof((a)))
#define fpre(x) cout<<fixed<<setprecision(x)
#define clr(v) (v).clear()
#define pii pair<int,int>
#define pdd pair<double,double>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp make_pair
#define eb emplace_back
#define pb emplace_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define uint unsigned int
#define ushort unsigned short
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define lowbit(i) (i&(-i))
#define lson rt<<1
#define rson lson|1
#define fi first
#define se second
const double eps=1e-7;
const double pi=acos(-1);
inline int dcmp(double x)
{
    if(x<-eps)
        return -1;
    if(x>eps)
        return 1;
    return 0;
}
//-----------------------------------------------head

const int maxn=2e5+5;
char s[maxn];
int main()
{
    while(~scanf("%s",s+1))
    {
        int n=strlen(s+1);
        int l=-1,r=-1;
        for(int i=1;i<n;++i)
            if(s[i]==s[i+1])
                l=i,r=i+1;
            else if(s[i]==s[i+2])
                l=i,r=i+2;
        printf("%d %d\n",l,r);
    }
}

/*
6
0 0 -1 3
-2 -1
2 3
3 -1
-1 2
-3 2
-4 0
6
3 10 3 2
2 1
4 1
0 3
6 3
4 4
2 4
6
3 2 3 10
2 1
4 1
0 3
6 3
4 4
2 4
*/









Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int Fennec[N],Snuke[N];
vector<int>g[N];
queue<int>q;
const int INF=1e6+1000;
int main()
{
	int n,a,b,black=0,white=0;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(Fennec,INF,sizeof(Fennec));
	Fennec[1]=0;
	q.push(1);
	while(!q.empty())
	{
		int k=q.front();
		q.pop();
		for(int i=0;i<g[k].size();i++)
		{
			if(Fennec[g[k][i]]>Fennec[k]+1)
			{
				Fennec[g[k][i]]=Fennec[k]+1;
				q.push(g[k][i]);
			}
		}
	}
	memset(Snuke,INF,sizeof(Snuke));
	Snuke[n]=0;
	q.push(n);
	while(!q.empty())
	{
		int k=q.front();
		q.pop();
		for(int i=0;i<g[k].size();i++)
		{
			if(Snuke[g[k][i]]>Snuke[k]+1)
			{
				Snuke[g[k][i]]=Snuke[k]+1;
				q.push(g[k][i]);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
  		if(Fennec[i]<=Snuke[i])
			black++;
		else
			white++;
	}
	if(black>white)
		puts("Fennec");
	else
		puts("Snuke");
	return 0;
}

Measured memory_bytes: 6656