akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

int main()
{
    string s;
    cin >> s;

    int L = s.size();

    stack<char> st;

    int S = 0, ans = 0;
    for(int i = 0; i < L; i++){
        if(st.size() == 0){
            st.push(s[i]);
            S++;
            continue;
        }

        char c = st.top();
        if((c == '0' && s[i] == '1') || (c == '1' && s[i] == '0'))
            st.pop(), ans += 2, S--;
        else
            st.push(s[i]), S++;
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, M; cin >> N >> M;
	ll ans = (100 * (N - M) + 1900 * M) * pow(2LL, M);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#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.at(i);
    }
    
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());

    int alice=0,bob=0;
    for (int i=0;i<N;++i){
        if (i%2==0){
            alice += vec.at(i);
        }
        else{
            bob += vec.at(i);
        }
    }

    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;



int main()
{
    int n;
    int arr[8];
    for(int i=0;i<5;i++)
    {
        cin>>arr[i];
    }
    cin>>n;
    int flag=0;
    for(int i=0;i<5;i++)
    {
        for(int j=i+1;j<5;j++)
        {
            if(arr[j]-arr[i]>n)
            {
                flag=1;
                break;
            }
        }
        if(flag==1)
        {
            break;
        }
    }
    if(flag==0)
    {
        cout<<"Yay!";
    }
    else
    {
        cout<<":(";
    }
   
    return 0;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int N;
long long W,weight[110],value[110];
long long dp[110][100100];

int main(){
  cin >> N >> W;
	for(int i=0;i<N;i++) cin >> weight[i] >> value[i];

	// ループ
	for (int i = 0; i < N; ++i) {
		for(int sum_w=0;sum_w<=W;++sum_w){
      if(sum_w-weight[i]>=0){
        chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
      }
      chmax(dp[i+1][sum_w], dp[i][sum_w]);
    }
	}

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

	}


Measured memory_bytes: 79488
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var a,b,c int
    fmt.Scan(&a,&b,&c)
    ans := min32(a,min32(b,c))*(a+b+c-min32(a,min32(b,c))-max32(a,max32(b,c)))/2
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


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

int n,a[200005];
int p[1000005];

int main(){

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

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        p[a[i]]++;
    }
    for(int i=1;i<=1e6;i++){
        if(p[i]&&p[i]<1e9){
            for(int j=i+i;j<=1e6;j+=i)p[j]=1e9;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=p[a[i]]==1;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 8256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String value = sc.next();
		Integer N = Integer.valueOf(value);
		int[] nums = new int[N];
		for(int i=0;i<N;i++) nums[i]=Integer.parseInt(sc.next());
		int max = Integer.MIN_VALUE;
		int sum = 0;
		for(int i=0; i<nums.length; i++) {
			sum += nums[i];
			max = Math.max(max, nums[i]);
		}
		sum -= max/2;
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 22868
use std::io::*;
use std::str::FromStr;
use std::clone::Clone;

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

struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,  
    size: Vec<usize>
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0; n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            par: vec, 
            rank: vec![0; n], 
            size: vec![1; n]
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            let p = self.par[x];
            let pp = self.find(p);
            self.size[x] = self.size[pp];
            self.par[x] = pp;
            pp
        }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let p_x = self.find(x);
        let p_y = self.find(y);
        if p_x != p_y {
            self.size[p_x] += self.size[p_y];
            self.size[p_y] = self.size[p_x];
            if self.rank[p_x] < self.rank[p_y] {
                self.par[p_x] = p_y;
            } else {
                self.par[p_y] = p_x;
                if self.rank[p_x] == self.rank[p_y] {
                    self.rank[p_x] += 1;
                }
            }
        }
    }

    fn are_same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}

#[derive(Clone)]
struct Edge {
    from: usize, 
    to: usize, 
    cost: u64
}

#[derive(Clone)]
struct Node {
    pos: u64, 
    idx: usize
}

fn main() {
    let N: usize = read();
    let mut edges: Vec<Edge> = vec![
        Edge{ from: 0, to: 0, cost: 0 }; N*2
    ];
    let mut x: Vec<Node> = vec![Node{ pos: 0, idx: 0}; N];
    let mut y: Vec<Node> = vec![Node{ pos: 0, idx: 0 }; N];

    for i in 0..N {
        x[i].pos = read();
        x[i].idx = i;
        y[i].pos = read();
        y[i].idx = i;
    }

    x.sort_by(
        |x1, x2| { x1.pos.cmp(&x2.pos) }
    );
    y.sort_by(
        |y1, y2| { y1.pos.cmp(&y2.pos) }
    );


    for i in 0..N-1 {
        edges[2*i].from = x[i].idx;
        edges[2*i].to = x[i+1].idx;
        edges[2*i].cost = x[i+1].pos - x[i].pos;
        edges[2*i+1].from = y[i].idx;
        edges[2*i+1].to = y[i+1].idx;
        edges[2*i+1].cost = y[i+1].pos - y[i].pos;
    }

    edges.sort_by(
        |e1, e2| { e1.cost.cmp(&e2.cost) }
    );

    let mut uf = UnionFind::new(N);
    let mut ans = 0;
    for edge in &edges {
        if !uf.are_same(edge.from, edge.to) {
            uf.unite(edge.from, edge.to);
            ans += edge.cost;
        }
    }

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

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

int main(){
  int strs, strp;
  int a,b,c;
  char s[100],p[100];
  scanf("%[^\n]%*c",s);
  scanf("%[^\n]%*c",p);
  strs=strlen(s);
  strp=strlen(p);

  
  for(a=0;a<strs;a++){
    for(b=0;b<strp;b++){
      if(strs<=b+a){
	c=a+b-strs;
      }else{
	c=a+b;
      }
      if(s[c]!=p[b]){
	break;
      }else if(b+1==strp){
	printf("Yes\n");
	return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}
      


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

int main() {
    long long n, w;
    cin >> n >> w;
    vector<pair<long long, long long> >v;
    for(long long i = 1; i <= n; i++) {
        long long val, wt;
        cin >> wt >> val;
        v.push_back(make_pair(val, wt));
    }
    sort(v.begin(), v.end());
    long long dp[w + 1];
    for(long long i = 0; i <= w; i++) {
        dp[i] = 0;
    }
    for(long long i = 0; i < n; i++) {
        for(long long j = w; j > 0; j--) {
            if(j - v[i].second < 0)
                break;
            dp[j] = max(dp[j], dp[j - v[i].second] + v[i].first);
        }
    }
    cout << dp[w] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<tgmath.h>
using namespace std;

#define lld long long

int main(){
    string str1,str2;
    cin >> str1;
    str2 = str1;
    reverse(str2.begin(),str2.end());
    if(str1 == str2){
        string str3 = str1.substr(0,(str1.size()-1)/2);
        string str4 = str3;
        reverse(str4.begin(),str4.end());
        if(str3 == str4){
            string str5 = str1.substr((str1.size()+2)/2,str1.size()-1);
            string str6 = str5;
            reverse(str6.begin(),str6.end());
            if(str5 == str6){
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
import fractions
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]

n,q=map(int,input().split())
s=list(input())[:-1]
lr = [list(map(int,input().split())) for _ in range(q)]
l=[0]*(n)
for i in range(1,n):
    if s[i]=='C' and s[i-1]=='A':
        l[i]=1
    else:
        l[i]=0
wa=[0]*(n)
for i in range(n):
    if i==0:
        wa[i]=0
    else:
        wa[i]=wa[i-1]+l[i]

for i in range(q):
    print(wa[lr[i][1]-1]-wa[lr[i][0]-1])


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

typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int BIG = 1e9 + 555;
const int maxN = 100 * 1000 + 9;

ll a[maxN], b[maxN];
int n;

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

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

	for(int i = 1; i <= n; i++){
		cin >> b[i];
	}
	
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ll delta = min(a[i], b[i]);
		a[i] -= delta;
		b[i] -= delta;
		ans += delta;

		delta = min(a[i + 1], b[i]);
		a[i + 1] -= delta;
		b[i] -= delta;
		ans += delta;
	}
	
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define un unsigned
#define de double
#define pi acos(-1.0)
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
#define mem(ae, value) memset(ae, value, sizeof(ae))
#define all(x) x.begin( ), x.end( )
#define UNIQUE(x) x.resize(unique(all(x)) - x.begin())
#define FASTER ios_base::sync_with_stdio(0)
#define loop(begin, end) for(u int i=begin; i<=end; i++)
#define Read freopen("in.txt", "r", stdin)
#define Write freopen("out.txt", "w", stdout)
#define nl '\n'

using namespace std;

template<class T> inline T sq(T x) { return x*x; }
template <class T> inline T gcd(T a, T b) { if(b == 0) return a; return gcd(b, a%b); }
template <class T> inline T lcm(T a, T b) { return ( a/gcd(a, b) ) * b; }
template <class T> inline T power(T b, T p)
{
    if(p == 0) return 1;
    if(p == 1) return b;
    if(p&1) return b*power(b, p-1);
    else return sq(power(b, p>>1));
}

int main(int argc, char **argv)
{
    vector<int> v;
    int i=0;
    while(i<10)
    {
        int n; cin >> n;
        v.pb(n);
        i ++;
    }
    sort(all(v), greater<int>());
    cout << v[0] << nl << v[1] << nl << v[2] << nl;
    v.clear( );
    
    return 0;
}

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

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

    if ((N[0]==N[1]&&N[1]==N[2])||(N[1]==N[2]&&N[2]==N[3])){
        cout << "Yes" << endl;
    }else{
    cout << "No" <<endl;
    }
}


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

using namespace std;

int main () {
    cin.tie(0);
    int D, G;
    cin >> D >> G;
    int p[D], c[D];
    for (int i = 0; i < D; i++) cin >> p[i] >> c[i];
    
    int min_num = 100000;
    for (int bit = 0; bit < (1<<D); bit++) {
        int left = G;
        int num = 0;
        int choice[D] = {};
        for (int i = D-1; i >= 0; --i) {
            if (left <= 0) break;
            if (bit & (1<<i)) {
                choice[i] = 1;
                left -= p[i]*(i+1)*100 + c[i];
                num += p[i];
            }
        }
        
        for (int i = D - 1; i >= 0; --i) {
            if (left <= 0) break;
            if (choice[i] == 0) {
                int div = left / ((i+1)*100);
                left -= min(div, p[i]-1)*(i+1)*100;
                num += min(div, p[i]-1);
            }
        }

        if (left <= 0) {
            min_num = min(min_num, num);
        }
    }
    cout << min_num << "\n";
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll n,k;cin>>n>>k;
  ll x[100005];
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  ll res=1000LL*1000LL*1000LL;
  for(int i=0;i<n;i++){
    if(i+k-1>=n)break;
    if(x[i]>=0){
      res=min(res, x[i+k-1]);
    }else if (x[i+k-1]<=0){
      res=min(res, abs(x[i]));
    }else {
      res = min(res, abs(x[i])*2+abs(x[i+k-1]));
      res = min(res, abs(x[i])+abs(x[i+k-1])*2);
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

string a;
//vector<vector<string>> block;
int block_size = 0;
vector<vector<int>> pos(26);
int block_pos[200000 + 5];
bool used[26];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a;
    int n = a.size();
    int cnt = 0;
    string tmp;
    rrep2(i, n - 1, -1) {
        pos[a[i] - 'a'].pb(i);
        block_pos[i] = block_size;
        tmp = tmp + a[i];
        if (!used[a[i] - 'a']) {
            used[a[i] - 'a'] = true;
            cnt++;
            if (cnt == 26) {
                //block.push_back(tmp);
                block_size++;
                rep(j, 26) used[j] = false;
                cnt = 0;
                tmp = "";
            }
        }
    }
    if (cnt != 0) {
        //block.push_back(tmp);
        block_size++;
    }

    rep(i, 26) sort(all(pos[i]));
    //reverse(all(block));

    int now = -1;
    string ans = "";
    int now_block = block_size;
    if (cnt != 0) now_block--;
    while (now_block >= 0) {
        rep(i, 26) {
            char c = char('a' + i);
            if (now_block == 0) {
                auto itr = lower_bound(all(pos[i]), now + 1);
                int di = distance(pos[i].begin(), itr);
                if (di == pos[i].size()) {
                    ans += c;
                    now_block--;
                    break;
                }
            }
            else {
                int idx = *lower_bound(all(pos[i]), now + 1);
                if (now_block - block_pos[idx] == 1) {
                    now_block--;
                    now = idx;
                    ans += c;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)
int main()
{
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s,t;cin>>s>>t;
ll n=s.length(),m=t.length(),i,j;
ll dp[n+1][m+1];
//vector<vector<ll>>dp(n+1,vector<ll>(m+1,0));
for(i=0;i<=n;i++)
{
  for(j=0;j<=m;j++)
  {
       if(i==0 || j==0)
          dp[i][j]=0;
      else if(s[i-1]==t[j-1])
      dp[i][j]=dp[i-1][j-1]+1;
      else
      dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      //cout<<dp[i][j]<<" ";
  }}
  //cout<<"\n";
  i=n,j=m;
  string ans="";
  while(i>0 && j>0)
  {
      if(dp[i][j]==dp[i-1][j])
      i-=1;
      else if(dp[i][j]==dp[i][j-1])
      j-=1;
      else
      {
          ans+=s[i-1];i-=1;j-=1;
      }
  }
  reverse(ans.begin(),ans.end());
  cout<<ans;
  
}
  

Measured memory_bytes: 73976
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m,k;
vvp g;
vl dp;

int main(){
	cin>>n>>m>>k;
	g=vvp(n);
	dp=vl(n,-INF);
	dp[0]=0;
	for(int i=0;i<m;i++){
		int u,v,c;
		cin>>u>>v>>c;
		u--;v--;c-=k;
		g[u].push_back({v,c});
	}
	ll tmp;
	for(int i=0;i<3*n;i++){
		vl DP=dp;
		for(int u=0;u<n;u++) for(auto p:g[u]){
			int v=p.first,c=p.second;
			DP[v]=max(DP[v],dp[u]+c);
		}
		if(i>n-1&&tmp!=DP[n-1]){
			cout<<-1<<endl;
			return 0;
		}
		dp=DP;
		if(i==n-1) tmp=dp[n-1];
	}
	cout<<max(dp[n-1],0ll)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int cur=0;
  rep(i,1,n){
    if(s[i]=='E'){
      cur++;
    }
  }
  int ans=cur;
  rep(i,1,n){
    if(s[i-1]=='W'){
      cur++;
    }
    if(s[i]=='E'){
      cur--;
    }
    ans=min(ans,cur);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 900
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
using namespace std;

typedef struct{
	int num;
	int pr[11]; //waの数，acしたら-1
	int ac;
	long time;
}team;

int main(){
	while(1){
		int T, P, R;
		team a[51];
		
		scanf(" %d %d %d", &T, &P, &R);
		if(T==0) break;
		
		//初期化
		for(int i=1; i<=50; ++i){
			a[i].num=i;	
			for(int j=1; j<=10; ++j) a[i].pr[j]=0;
			a[i].ac=0;
			a[i].time=0;
		}
		
		
		for(int i=0; i<R; ++i){
			int t, p, m;
			string j;
			scanf(" %d %d %d", &t, &p, &m);
			cin >> j;
			if(j=="WRONG"){ //不正解
				a[t].pr[p]++;
			}
			else{ //正解
				if(a[t].pr[p]==-1) continue;
				
				a[t].ac++;
				a[t].time+=m+1200*a[t].pr[p];	
				a[t].pr[p]=-1;
			}
		}	
		
		//sort
		for(int i=1; i<=T; ++i){
			for(int j=i; j<=T; ++j){
				if(a[i].ac < a[j].ac) swap(a[i], a[j]);
				else if(a[i].ac == a[j].ac){
					
					if(a[i].time > a[j].time) swap(a[i], a[j]);
					else if(a[i].time == a[j].time){
						
						if(a[i].num > a[j].num) swap(a[i], a[j]);
					}					
				}
				
			}
		}
			
		for(int i=1; i<=T; ++i) printf("%d %d %ld\n", a[i].num, a[i].ac, a[i].time);
		
	}
	return 0;
}

Measured memory_bytes: 1256
'''input
2 5
1 WA
1 AC
2 WA
2 AC
2 WA
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline



# main starts
n, m = list(map(int, input().split()))
ac = dict()
wa = dict()
w = 0
for _ in range(m):
	a, t = list(input().split())
	a = int(a)
	if t == 'AC':
		if a in ac:
			pass
		else:
			if a in wa:
				w += wa[a]
			ac[a] = 1

	else:
		if a in ac:
			pass
		else:
			if a in wa:
				wa[a] += 1
			else:
				wa[a] = 1
print(len(ac), w)

Measured memory_bytes: 50140
#include<iostream>
#include<string>
#include<algorithm>
#define N 50
 
using namespace std;

int main(){
  int n, m, dp[N][N];
  string s;
  cin >> n >> m;
  for(int i=0; i<n; ++i){
    cin >> s;
    for(int j=0; j<m; ++j) dp[i][j]=s[j]-'0';
  }
  for(int j=1; j<m; ++j) dp[0][j]+=dp[0][j-1];
  for(int i=1; i<n; ++i){
    dp[i][0]+=dp[i-1][0];
    for(int j=1; j<m; ++j)
      dp[i][j] += min(dp[i-1][j], dp[i][j-1]);
  }
  cout << dp[n-1][m-1] << endl;
  return 0;
}

Measured memory_bytes: 1208
let kFMax = 3000 in
let kWMax = 30 in
Scanf.scanf " %d %d %d %d %d %d" @@ fun a b c d e f ->
  let ans = ref (0., 0, 0) in
  let water = Array.make (kWMax + 1) false in
  for i = 0 to kWMax do
    for j = 0 to kWMax do
      let w = a * i + b * j in
      if w <= kWMax then water.(w) <- true
    done
  done;
  let sugar = Array.make (kFMax + 1) false in
  for i = 0 to kFMax do
    for j = 0 to kFMax do
      let s = c * i + d * j in
      if s <= kFMax then sugar.(s) <- true
    done
  done;
  for w = 1 to kWMax do
    if water.(w) then
      for s = 0 to kFMax do
        if sugar.(s) then
          let w_s = w * 100 + s in
          if w_s <= f && w * e >= s then
            let c = 100. *. float s /. (float w +. float s) in
            ans := max !ans (c, w_s, s)
      done
  done;
  let _, w_s, s = !ans in
  Printf.printf "%d %d\n" w_s s

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

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

  if(n==0) break;

  int len[n];
  for(int i=0; i<n; i++){
   string w;
   cin >> w;
   len[i] = w.size();
  }

  for(int i=0; i<n; i++){
   bool flag = false;
   int sta = 0; //区切り
   int sum = 0; //文字数の合計

   for(int j=i; j<n; j++){
    sum = sum + len[j];
    
    if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
     sta++;
    }

    if(sta==5){
     flag = true;
     break;
    }else if(sum>=31){
     break;
    }
   }

   if(flag){
    cout << i+1 << endl;
    break;
   }
  }
 }

 return 0;
}


Measured memory_bytes: 3188
import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val tree = new TreeWalk(n);
        for (i <- (0 until n)) {
            val line = readLine.split(" ").map(_.toInt);
            tree.add(line(0), line(1), line(2));
        }
        println("Preorder");
        println(" " + tree.preorder.mkString(" "));
        println("Inorder");
        println(" " + tree.inorder.mkString(" "));
        println("Postorder");
        println(" " + tree.postorder.mkString(" "));
    }
}
class TreeWalk(size: Int) {
    case class Node(id: Int, var parent: Node, var left: Node, var right: Node);
    val tree = new Array[Node](size);
    lazy val root: Option[Node] = tree.find(a => a != null && a.parent == null);
    def add(id: Int, left: Int, right: Int): Unit = {
        if (tree(id) == null) tree(id) = Node(id, null, null, null);
        if (left != -1) {
            if (tree(left) == null) tree(left) = Node(left, null, null, null);
            tree(left).parent = tree(id);
            tree(id).left = tree(left);
        }
        if (right != -1) {
            if (tree(right) == null) tree(right) = Node(right, null, null, null);
            tree(right).parent = tree(id);
            tree(id).right = tree(right);
        }
    }
    def preorder: List[Int] = {
        def go(curr: Node, ret: List[Int]): List[Int] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = curr.id :: ret;
                val ret2 = go(curr.left, ret1);
                val ret3 = go(curr.right, ret2);
                ret3;
            }
        }
        root match {
            case None => Nil;
            case Some(r) => go(r, Nil).reverse;
        }
    }
    def inorder: List[Int] = {
        def go(curr: Node, ret: List[Int]): List[Int] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = go(curr.left, ret);
                val ret2 = curr.id :: ret1;
                val ret3 = go(curr.right, ret2);
                ret3;
            }
        }
        root match {
            case None => Nil;
            case Some(r) => go(r, Nil).reverse;
        }
    }
    def postorder: List[Int] = {
        def go(curr: Node, ret: List[Int]): List[Int] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = go(curr.left, ret);
                val ret2 = go(curr.right, ret1);
                val ret3 = curr.id :: ret2;
                ret3;
            }
        }
        root match {
            case None => Nil;
            case Some(r) => go(r, Nil).reverse;
        }
    }
}


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

using namespace std;

typedef pair<int,int> pii;

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

    int n;
    cin>>n;

    vector<pii> arr(n);

    for(int i=0;i<n;i++) cin>>arr[i].first>>arr[i].second;

    sort(arr.begin(),arr.end());

    for(int i=0;i<n;i++) cout<<arr[i].first<<" "<<arr[i].second<<endl;

    return 0;
}



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

typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for (int i = b; i <= e; i++)
#define FORD(i, b, e) for (int i = b; i >= e; i--)
#define SIZE(x) ((int)(x).size())
#define pb push_back
#define st first
#define nd second
#define all(a) begin(a), end(a)
#define watch(x) cerr << (#x) << " is " << (x) << '\n';

const int N = 22;

int a[N], b[N], c[N];

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

    int n;
    cin >> n;

    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];
    FOR(i, 1, n - 1) cin >> c[i];

    int res = 0;

    int last = -10;
    FOR(i, 1, n) {
        res += b[a[i]];
        if (last == a[i] - 1) res += c[a[i] - 1];
        last = a[i];
    }
    cout << res << '\n';

    return 0;
}


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


int main(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    int dp[n];
    if(k>=n){
        k=n-1;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int ans=INT_MAX;
    for(int i=1;i<n;i++){
        ans=INT_MAX;
        if(i<=k){
            for(int j=i-1;j>=0;j--){
               ans= min(ans, dp[j]+abs(arr[i]-arr[j]));
            }
            dp[i]=ans;

        }else{
            for(int j=i-1;j>=(i-k);j--){
                ans= min(ans, dp[j]+abs(arr[i]-arr[j]));
            }
            dp[i]=ans;
        }

    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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


using namespace std;

string let = "RYGB";

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int x = ((i + j) % (2 * d) + (2 * d)) % (2 * d) / d;
      int y = ((i - j) % (2 * d) + (2 * d)) % (2 * d) / d;
      
      putchar(let[2 * x + y]);
    }
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
using namespace std;
int N, M;
pair<int,int> PD[10010];
int main() {
    while (cin >> N >> M && N) {
        int d, p;
        int sum;
        for (int i=0; i<N; i++) {
            cin >> d >> p;
            PD[i] = make_pair(p, d);
        }
        
        sort(PD, PD+N);
        sum = 0;
        for (int i=N-1; i >=0; i--) {
            for (int l=0; l < PD[i].second; ++l) {
                if (M > 0) {
                    M -= 1;
                } else {
                    sum += PD[i].first;
                }
                
            }
        }
        cout << sum << endl;
    }
    
}


Measured memory_bytes: 3080
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] L = new int[N];
        for(int i=0;i<N;i++) L[i] = sc.nextInt();
        int m=0,cnt =0;
        int g = 1,g2=1;
        while(g2<=N){
            g*=3;
            g2+=g;
            m++;
        }
        int G [] = new int [m];
        G[m-1]=1;
        g = 1;
        for(int i=1;i<m;i++){
            g*=3;
            G[m-i-1]=G[m-i]+g;
        }
        for(int i=0;i<m;i++) cnt = insertion_sort(L,N,G[i],cnt);
        System.out.println(m);
        for(int i=0;i<m;i++){
            if(i!=m-1) System.out.print(G[i]+" ");
            else  System.out.println(G[i]);
        }
        System.out.println(cnt);
        for(int i:L) System.out.println(i);
    }
    public static int insertion_sort(int [] L,int N,int g,int cnt){
        for(int i=g;i<N;i++){
            int v = L[i];
            int j = i-g;
            while(j>=0&&L[j]>v){
                L[j+g]=L[j];
                j = j-g;
                cnt++;
            }
            L[j+g]=v;
        }
        return cnt;
    }
}


Measured memory_bytes: 299240
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;

int l,r;
int min=INT_MIN,max=INT_MAX;
while(m--)
{
cin>>l>>r;
 
if(min<=l)
min=l;
if(max>=r)
max=r;
if(max<min)
break;
}
if(max-min<0)
cout<<0;
else
cout<<max-min+1;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {

	/*
	 * https://onlinejudge.u-aizu.ac.jp/problems/0079
	 */

	public static void main(String[] args) throws IOException {
		//入力
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<double[]> points = new ArrayList<>();
		String str = br.readLine();
		for(; str!=null; str=br.readLine()) {
			String s[] = str.trim().split(",");
			double p[] = {Double.parseDouble(s[0]), Double.parseDouble(s[1])};
			points.add(p);
		}

		//0番目の点が原点になるように平行移動
		double originX = points.get(0)[0],
		       originY = points.get(0)[1];
		for(int i=0; i<points.size(); i++) {
			double p1[] = points.get(i);
			p1[0] -= originX;
			p1[1] -= originY;
		}
		//外積の半分を計算して足す
		double area = 0;
		for(int i=1; i+1<points.size(); i++) {
			area += crossProduct(points.get(i), points.get(i+1))/2;
			//System.out.println(area);
		}
		//area += crossProduct(points.get(points.size()-1), points.get(1)); <- これは要らない

		//出力
		System.out.println(Math.abs(area));
	}

	//外積を計算
	private static double crossProduct(double[] v1, double[] v2) {
		return v1[0]*v2[1]-v1[1]*v2[0];
	}

}



Measured memory_bytes: 24348
#include <stdio.h>

int main()
{
	int i, j, H, W;
	char A[10][10] = {};
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(A[i][1]));

	int count = 0;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) if (A[i][j] == '#') count++;
	}
	
	if (count == W + H - 1) printf("Possible\n");
	else printf("Impossible\n");
	fflush(stdout);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	int ans = 0;
	for (int tot = 0; tot < n; tot++) {
		int prev = 0;
		int m = a[prev];
		for (int i = 0; i < n; i++) {
			if (a[i] == 0) {
				ans += m;
				for (int j = prev; j < i; j++) 
					a[j] -= m;
				prev = i+1;
				m = a[prev];
			} else {
				m = min(m, a[i]);
			}
		}
		if (prev != n) {
			ans += m;
			for (int i = prev; i < n; i++)
				a[i] -= m;
		}
	}
	cout << ans << endl;
	return 0;
}

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

class Treap {
public:
  Treap *left = nullptr;
  Treap *right = nullptr;
  int key;
  int pri;
  Treap(int k, int p) : key(k), pri(p) {}
  Treap *Insert(int k, int p) {
    if (k < key) {
      if (!left) {
        left = new Treap(k, p);
      } else {
        left = left->Insert(k, p);
      }
      if (left->pri > pri) {
        //        cout << "Debug: At " << key << ", left node " << left->key
        //             << " has lower priority " << left->pri << " (vs. " << pri
        //             << "); rotating right\n";
        return RotateRight();
      }
    } else if (k > key) {
      if (!right) {
        right = new Treap(k, p);
      } else {
        right = right->Insert(k, p);
      }
      if (right->pri > pri) {
        //        cout << "Debug: At " << key << ", right node " << right->key
        //             << " has lower priority " << right->pri << " (vs. " <<
        //             pri
        //             << "); rotating left\n";
        return RotateLeft();
      }
    }
    return this;
  }
  // pre: right != null
  Treap *RotateLeft() {
    Treap *s = right;
    right = s->left;
    s->left = this;
    return s;
  }
  // pre: left != null
  Treap *RotateRight() {
    Treap *s = left;
    left = s->right;
    s->right = this;
    return s;
  }
  bool Find(int k) {
    if (k == key) {
      return true;
    } else if (k > key) {
      return (right and right->Find(k));
    } else if (k < key) {
      return (left and left->Find(k));
    }
  }
  // pre: k is in the treap
  Treap *Remove(int k) {
    if (k == key) {
      if (not left and not right) {
        delete this;
        return nullptr;
      } else if (left and not right) {
        return RotateRight()->Remove(k);
      } else if (right and not left) {
        return RotateLeft()->Remove(k);
      } else {
        if (right->pri > left->pri) {
          return RotateLeft()->Remove(k);
        } else {
          return RotateRight()->Remove(k);
        }
      }
    } else {
      if (k > key and right) {
        right = right->Remove(k);
      } else if (k < key and left) {
        left = left->Remove(k);
      }
      return this;
    }
  }
};

void PrintInorder(Treap *t) {
  if (!t)
    return;
  PrintInorder(t->left);
  cout << ' ' << t->key;
  PrintInorder(t->right);
}

void PrintPreorder(Treap *t) {
  if (!t)
    return;
  cout << ' ' << t->key;
  PrintPreorder(t->left);
  PrintPreorder(t->right);
}

int main() {
  int n;
  cin >> n;
  string cmd;
  Treap *root = nullptr;
  int k, p;
  while (cin >> cmd) {
    if (cmd == "insert") {
      cin >> k >> p;
      if (!root) {
        root = new Treap(k, p);
      } else {
        root = root->Insert(k, p);
      }
    } else if (cmd == "find") {
      cin >> k;
      if (root and root->Find(k)) {
        cout << "yes\n";
      } else {
        cout << "no\n";
      }
    } else if (cmd == "print") {
      PrintInorder(root);
      cout << endl;
      PrintPreorder(root);
      cout << endl;
    } else if (cmd == "delete") {
      cin >> k;
      // root will always be non-null when deleting
      root = root->Remove(k);
    }
  }
}


Measured memory_bytes: 9448
function wa(x)
    res = 0
    while x > 0
        res += x % 10
        x = div(x, 10)
    end
    return res
end

function main()
    n, a, b = map(x -> parse(Int64, x), split(readline()))

    ans = 0
    for x in 1:n
        if a <= wa(x) <= b
            ans += x
        end
    end
    println(ans)
end

main()


Measured memory_bytes: 112024
n = gets.to_i
ws = gets.split.map(&:to_i)

min = 1_000_000_000
1.upto(n - 1) do |i|
  l = 0
  0.upto(i) do |k|
    l += ws[k]
  end
  r = 0
  (i+1).upto(n-1) do |k|
    r += ws[k]
  end

  min = [min, (l - r).abs].min
end

p min


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<int> a(n);
  for (int &i : a) in >> i;
  int p = -1, val = -1;
  for (int i = 0; i < n; ++i) {
    if (p == -1 || abs(val) < abs(a[i])) {
      p = i;
      val = a[i];
    }
  }
  vector<pair<int, int>> ops;
  ops.emplace_back(p, p);
  for (int i = 0; i < n; ++i) {
    if (i != p) {
      ops.emplace_back(p, i);
    }
  }
  if (a[p] < 0) {
    for (int i = n - 1; i > 0; --i) {
      ops.emplace_back(i, i - 1);
    }
  } else {
    for (int i = 0; i < n - 1; ++i) {
      ops.emplace_back(i, i + 1);
    }
  }
  out << ops.size() << '\n';
  for (pair<int, int> pr : ops) {
    out << pr.first + 1 << ' ' << pr.second + 1 << '\n';
  }
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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 nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(void){
  int n;
  scanf("%d",&n);
  for(int i=n;;i++){
    int flg=1;
    for(int j=2;j<=sqrt(i);j++){
      if(i%j<1){
        flg=0;
        break;
      }
    }
    if(flg){
      PRN(i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() 
{ 
	int n,m;
	cin>>n>>m;
	int A[m];
	for(int i=0;i<m;i++)cin>>A[i];
	int sum=0;
	for(int i=0;i<m;i++)sum+=A[i];
	if(sum>n)cout<<-1;
	else cout<<n-sum;
	return 0; 
}

Measured memory_bytes: 3704
n = int(input())
v = list(map(int, input().split()))

while len(v) > 1:
    min1 = min(v)
    v.remove(min(v))
    min2 = min(v)
    v.remove(min(v))
    avg = (min1 + min2) / 2
    v.append(avg)

print(sum(v))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 366666;
int n,k;
struct node{int x,y,z;}ans[N];int len;
void solve(int A, int B, int C, int n){//A..A+n-1
	for(int j=(n+1)/2,i=1;j>=1;j--,i+=2){
		ans[++len]=(node){A+i-1,B+j-1,C++};
	}
	for(int i=2,j=n;i<=n;i+=2,j--){
		ans[++len]=(node){A+i-1,B+j-1,C++};
	}
}
int main() {
	read(n);read(k);
	if(!(2*k<=n+1)){puts("-1");return 0;}
	if(n&1)solve(k,k+n,k+2*n,n);
	else ans[++len]=(node){k,k+n,k+2*n},solve(k+1,k+1+n,k+1+2*n,n-1);
	assert(len==n);
	rep(i,1,n)assert(ans[i].x+ans[i].y<=ans[i].z);
	rep(i,1,len)printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].z);
	return 0;
}


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

using namespace std;

int main(void) {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> cnts(N, 0);
  for (int i = 0; i < Q; ++i) {
    int A;
    cin >> A;
    cnts[A - 1]++;
  }
  for (const int v : cnts) {
    if (K - (Q - v) <= 0) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector <int> v(n);
    for (int i=0; i<n; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    int x = v.size() / 2;
    cout << v[x]-v[x-1];
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();
        string t = sc.Next();

        long answer = long.MaxValue;

        int length = t.Length;
        for (int i = 0; i < s.Length - length + 1; i++)
        {
            string s2 = s.Substring(i, length);
            if (s2.Length < length)
            {
                return;
            }
            long tmpAnswer = 0;
            for (int j = 0; j < length; j++)
            {
                if (s2[j] != t[j])
                {
                    tmpAnswer++;
                }
            }
            answer = Math.Min(answer, tmpAnswer);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

long long P = 1000000007;

ll dp[404][404] = {0};
ll memo[404][404] = {0};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, c;
  cin >> n >> c;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++)cin >> a[i];
  for (int i = 0; i < n; i++)cin >> b[i];

  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j <= b[i]; j++) {
      ll tmp = 1;
      for (int k = 0; k <= c; k++) {
        memo[i][k] += tmp;
        memo[i][k] %= P;
        tmp *= j;
        tmp %= P;
      }
    }
  }

  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= c; j++) {
      dp[i + 1][j] = 0;
      for (int k = 0; k <= c; k++) {
        if (j - k < 0) continue;
        dp[i + 1][j] += (dp[i][j - k] * memo[i][k]) % P;
        dp[i + 1][j] %= P;
      }
    }
  }
  cout << dp[n][c] << endl;
  return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

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

    long double sum = 0;
    long double a[n];
    for(long long i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    long double average = sum/((long double) n);

    long double minv = 1e9;
    for(long long i = 0; i < n; i++){
        a[i] = abs(a[i]-average);
        minv = min(minv, a[i]);
    }

    for(long long i = 0; i < n; i++){
        if(minv == a[i]){
            printf("%lld\n", i);
            return 0;
        }
    }
}

Measured memory_bytes: 3768