akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
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; }
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N;
vector<int> A;

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

  cin >> N;
  int a;
  rep(i, N){
    cin >> a;
    A.push_back(a);
  }
  
  sort(A.begin(), A.end());
  int ans1 = A[N-1];
  int medi = A[N-1]/2;
  auto po = lower_bound(A.begin(), A.end(), medi);
  int s = po-A.begin();

  if (A[s] == medi){
    cout << ans1 << ' ' << medi << endl;
    return 0;
  }

  if (A[s] - medi > medi - A[s-1]){
    cout << ans1 << ' ' << A[s-1] << endl;
  } else {
    if (A[s] == ans1){
      cout << ans1 << ' ' << A[s-1] << endl;
    }else{
      cout << ans1 << ' ' << A[s] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 892
n = int(input())
a = [int(i) for i in input().split()]
ans = 0

dp = dict()
dm = dict()

for i,ai in enumerate(a):
    dp[i+ai] = dp.get(i+ai,0)+1
    dm[i-ai] = dm.get(i-ai,0)+1

for wa,i in dm.items():
    ans += i*dp.get(wa,0)

print(ans)


Measured memory_bytes: 56728
use v5.18;
use warnings;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

my @coins = split / /, read_line;

my $num = 0;
for my $i (0, 1) {
  my $b = do {
    if ( $coins[0] < $coins[1] ) {
      my $orig = $coins[1];
      $coins[1] -= 1;
      $orig;
    }
    else {
      my $orig = $coins[0];
      $coins[0] -= 1;
      $orig;
    }
  };
  $num += $b;
}
say $num;


Measured memory_bytes: 640
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	if parseProblem() {
		fmt.Println("POSSIBLE")
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}

func parseProblem() bool {
	n, m := scanInt(sc), scanInt(sc)
	g := nextLinkedList(n, m, 1, sc)

	// BFS
	q := []int{0}
	visited := make([]bool, n)
	steps := make([]int, n)
	visited[0] = true
	var cur int
	for len(q) > 0 {
		cur, q = q[0], q[1:]
		if steps[cur] > 2 {
			return false
		}
		if cur == n-1 {
			return true
		}
		for next := range g.edges[cur].members() {
			if visited[next] {
				continue
			}
			steps[next] = steps[cur] + 1
			visited[next] = true
			q = append(q, next)
		}
	}
	return false
}

type basicLinkedList struct {
	size, deg int
	edges     []intSet
}

func newLinkedList(size int) *basicLinkedList {
	ll := &basicLinkedList{size: size, edges: make([]intSet, size)}
	for i := 0; i < size; i++ {
		ll.edges[i] = newIntSet()
	}
	return ll
}

func (ll *basicLinkedList) addEdge(a, b int) {
	ll.addDirectedEdge(a, b)
	ll.addDirectedEdge(b, a)
}

func (ll *basicLinkedList) addDirectedEdge(a, b int) {
	if ll.edges[a].add(b) {
		ll.deg++
	}
}

func (ll *basicLinkedList) exists(a, b int) bool {
	return ll.edges[a].doesContain(b)
}

func nextLinkedList(n, m, offset int, sc *bufio.Scanner) *basicLinkedList {
	ll := newLinkedList(n)
	for i := 0; i < m; i++ {
		x, y := nextInt(sc), nextInt(sc)

		x -= offset
		y -= offset
		ll.addEdge(x, y)
	}
	return ll
}

func nextDirectedLinkedList(n, m, offset int, sc *bufio.Scanner) *basicLinkedList {
	ll := newLinkedList(n)
	for i := 0; i < m; i++ {
		x, y := nextInt(sc), nextInt(sc)

		x -= offset
		y -= offset
		ll.addDirectedEdge(x, y)
	}
	return ll
}

type intSet map[int]none

func newIntSet() intSet {
	return map[int]none{}
}

func (s intSet) add(i int) (added bool) {
	_, ok := s[i]
	added = !ok
	s[i] = mark
	return
}

func (s intSet) remove(i int) (removed bool) {
	_, removed = s[i]
	delete(s, i)
	return
}

func (s intSet) doesContain(i int) bool {
	_, ok := s[i]
	return ok
}

func (s intSet) size() int {
	return len(s)
}

func (s intSet) members() chan int {
	ch := make(chan int)
	go func() {
		defer close(ch)
		for k := range s {
			ch <- k
		}
	}()
	return ch
}

type none struct{}

var mark none

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 57064
from itertools import *
from bisect import *
from math import *
from collections import *
from heapq import *
from random import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    input()
    aa=LI()
    ans=0
    for a0,a1 in zip(aa,aa[1:]):
        if a0<a1:ans+=1
    print(ans)

main()



Measured memory_bytes: 20164
n = gets.to_i
b = gets.split.map(&:to_i)

sum = b[0]
for i in 1.upto(n - 2)
    if b[i - 1] < b[i] then
        sum += b[i - 1]
    else
        sum += b[i]
    end
end
sum += b[n - 2]

puts sum


Measured memory_bytes: 1788
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

ans = 0
for i in range(N):
    ans += A[i] // 2
    if A[i] % 2 == 1:
        if i + 1 < N:
            if A[i + 1] > 0:
                ans += 1
                A[i + 1] -= 1

print(ans)


Measured memory_bytes: 44888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf INT_MAX
#define mod 1000000009
using namespace std;
 
int main() {
	speed;
	int n, k;
	cin >> n >> k;
	double ans = 0, v = 1.0/n;
	for (int i = 1; i <= n; ++i) {
		int mn = 0, j = i;
		while (j < k)
			j *= 2, ++mn;
		ans += v * 1/pow(2, mn);
	}
	cout.precision(12);
	cout << fixed << ans << '\n';
	return 0;
}

Measured memory_bytes: 384
loop do
    w, h = gets.split.map(&:to_i)
    break if w == 0 && h == 0
    c = h.times.map{gets.strip}
    dp = Array.new(h).map{Array.new(w,0)}
    max = 0
    c.each_with_index do |r,i|
        r.each_char.with_index do |ch, j|
            next if ch.to_s.match(/[A-Z]/)
            if i == 0
                if j == 0
                    dp[i][j] = ch.to_i
                else
                    dp[i][j] = (dp[i][j-1].to_s + ch).to_i
                end
            else
                if j == 0
                    dp[i][j] = (dp[i-1][j].to_s + ch).to_i
                else
                    dp[i][j] = ([dp[i-1][j], dp[i][j-1]].max.to_s + ch).to_i
                end
            end
        end
        max = [max, dp[i].max].max
    end
    puts max
end

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

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    int b[m], a[n][m];
    int ans = 0;
    for (int i = 0; i < m; i++) cin >> b[i];
    for (int i = 0; i < n; i++) {
        int t = 0;
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            t += a[i][j] * b[j];
        }
        if (t + c > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

class RMQ
{
	int n;
	vector<int> dat;
public:
	RMQ(int n_)
	{
		n = 1;
		while (n < n_)
		{
			n *= 2;
		}
		dat.resize(2 * n - 1);
		for (int i = 0; i < 2 * n - 1; ++i)
		{
			dat[i] = INT_MAX;
		}
	}
	void update(int k, int a)
	{
		k += n - 1;
		dat[k] = a;
		while (k > 0)
		{
			k = (k - 1) / 2;
			dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}
	int query(int a, int b, int k = 0, int l = 0, int r = 0)
	{
		if (r <= l)
		{
			r = n;
		}
		if (r <= a || b <= l)
		{
			return(INT_MAX);
		}
		if (a <= l && r <= b)
		{
			return(dat[k]);
		}
		int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return(min(vl, vr));
	}
};

void solve()
{
	int n, q;
	cin >> n >> q;
	RMQ r(n);
	for (int i = 0; i < q; ++i)
	{
		int com, x, y;
		scanf("%d%d%d", &com, &x, &y);
//		cin >> com >> x >> y;
		if (com == 0)
		{
			r.update(x, y);
		}
		else
		{
			printf("%d\n", r.query(x, y + 1));
//			cout << r.query(x, y + 1) << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 2060
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios	      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main() {
   
    ios
    int n;
    cin >> n;
    if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)cout <<"hon\n";
    else if(n%10==3)cout <<"bon\n";
    else cout << "pon\n";
    return 0;
  
}

Measured memory_bytes: 3652
#include<bits/stdc++.h> 
#define int long long
using namespace std;
int absc(int a){
	if(a<0){
		return -a;
	}
}
int f(int a){
	return (a*(a-1))/2;
}
vector<int> a;
int maxc(int a,int b){
	if(a>b){
		return a;
	}
	else{
		return b;
	}
}
signed main(){
	string s;
	int m=0;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(m<=0&&s[i]=='<'){
			m--;
		}
		else if(m>0&&s[i]=='<'){
			a.push_back(m);
			m=-1;
		}
		else if(m>=0&&s[i]=='>'){
			m++;
		}
		else if(m<0&&s[i]=='>'){
			a.push_back(m);
			m=1;
		}
	}
	a.push_back(m);
	if(a[0]>0){
		a.insert(a.begin(),-1);
	}
	if(a.back()<0){
		a.push_back(1);
	}
	
	long long ans=0;
	for(int i=0;i<a.size();i+=2){
		ans+=f(-a[i])+f(a[i+1])+maxc(-a[i],a[i+1]);
	}	
	cout<<ans;	
}

Measured memory_bytes: 3068
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N, A[Nmax];

ll dfs(int p, int n, bool flip, int n_neg){
	if(p==1&&n==1){
		int x=A[n_neg+p-1], y=A[n-1];
		if(flip) swap(x, y);
		cout << x << " " << y << endl;
		return x-y;
	}
	if(p<n){
		if(!flip){
			ll m = dfs(p, n-1, flip, n_neg);
			cout << m << " " << A[n-1] << endl;
			return m-A[n-1];
		} else {
			ll m = dfs(p, n-1, !flip, n_neg);
			cout << A[n-1] << " " << m << endl;
			return A[n-1]-m;
		}
	} else{
		if(!flip){
			ll m = dfs(p-1, n, !flip, n_neg);
			cout << A[n_neg+p-1] << " " << m << endl;
			return A[n_neg+p-1]-m;
		} else {
			ll m = dfs(p-1, n, flip, n_neg);
			cout << m << " " << A[n_neg+p-1] << endl;
			return m-A[n_neg+p-1];
		}
	}
}

int main(){
	cin >> N;
	for(int i=0; i<N; i++) cin >> A[i];
	sort(A, A+N);

	int neg = 1;
	if(A[0]>0) neg = 1;
	else if(A[N-1]<0) neg = N-1;
	else while(neg+1<N && A[neg]<=0) neg++;

	ll m = 0;
	for(int i=0; i<neg; i++) m -= A[i];
	for(int i=neg; i<N; i++) m += A[i];

	cout << m << endl;

	vector<pair<ll, ll>> ans;

	int p=N-neg;
	int n=neg;
	dfs(p, n, false, neg);

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int n,m;
	ll d[200][200] = {};
	int a[2000],b[2000],c[2000];
	cin >> n >> m;
	rep(i,0,n)rep(j,0,n)if(i != j)d[i][j] = linf;
	
	rep(i,0,m){
        cin >> a[i] >>b[i]>> c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
	}

	rep(k,0,n){
	    rep(i,0,n){
	        rep(j,0,n){
	            d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
	        }
	    }
	}
    
    int ans = m;

    rep(i,0,m){
        bool f = 0;
        rep(j,0,n)if(d[j][a[i]]+c[i] == d[j][b[i]])f = 1;
        if(f == 1)ans --;
    }
	
	P(ans);
	
	return  0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	cout<<(h2*60+m2)-(h1*60+m1)-k<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>

#define TEST 1

using namespace std;
int parse(string str){
    if(str.length()==0)return 0;
    switch(str[0]){
        case '(':{
            
            int sub=parse(str.substr(1));
            if(sub==-1)return -1;
            int p1=1+sub;
            if(str[p1]==')'){
                int sub2=parse(str.substr(p1+1));
                return p1+sub2+1;
            }
            return -1;
        }
        case '[':{
            int sub=parse(str.substr(1));
            if(sub==-1)return -1;
            int p1=1+sub;
            if(str[p1]==']'){
                int sub2=parse(str.substr(p1+1));
                return p1+sub2+1;
            }
            return -1;
        }
        case ')':
        case ']':
            return 0;
        default:
            int res=parse(str.substr(1));
            return res==-1?-1:res+1;
    }
}

int main(){
    string line;
    while (getline(cin,line)&&line!=".") {
        int len=parse(line);
        cout<<(len==line.length()?"yes":"no")<<endl;
    }
}

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

using namespace std;

int main()
{
	int A, B, C;
	cin>>A>>B>>C;

	int K;
	cin>>K;

	while(K>0 && A>=B)
	{
		B *= 2;
		K--;
	}

	while(K>0 && B>=C)
	{
		C *= 2;
		K--;
	}

	if(C>B && B>A)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int h,H[251];
int right(int);
int left(int);
int parent(int);

int main(){
  int i;
  scanf("%d",&h);

  for(i=1;i<=h;i++){
    scanf("%d",&H[i]);
  }
  for(i = 1;i<=h;i++){
    printf("node %d: key = %d, ",i,H[i]);
    if(parent(i)>=1) printf("parent key = %d, ",H[parent(i)]);
    if(left(i)<=h) printf("left key = %d, ",H[left(i)]);
    if(right(i)<=h) printf("right key = %d, ",H[right(i)]);
    printf("\n");
  }
  return 0;
}


int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

static vector<int> G;
static int cnt = 0;

void insert_sort(vector<int> &A, int g) {
  FOR(i, g, A.size()) {
    auto v = A[i];
    auto j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      ++cnt;
    }
    A[j + g] = v;
  }
}

void shell_sort(vector<int> &A) {
  for(int h = 1;;) {
    if (h > A.size()) break;
    G.push_back(h);
    h = 3*h + 1;
  }
  reverse(ALL(G));
  REP(i, G.size()) insert_sort(A, G[i]);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  shell_sort(A);
  cout << G.size() << endl;
  REP(i, G.size()) {
    if (i) cout << " ";
    cout << G[i];
  }
  cout << endl << cnt << endl;
  for (auto a : A) cout << a << endl;
}



Measured memory_bytes: 6760
#include <cstdio>

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

char s[N];
int a[N], n, f[N], nxt[3];

int main() {
	scanf("%s", s);
	for (; s[n]; ++n) a[n+1] = (a[n] + s[n] - 'a' + 1) % 3;
	int flag = 0;
	for (int i = 1; i < n; ++i) {
		if (s[i] == s[i-1]) flag = 1;
		// printf("%d\n", a[i]);
	}
	if (!flag) {
		puts("1");
		return 0;
	}
	f[n] = 1;
	for (int i = 0; i < 3; ++i) nxt[i] = i == a[n] ? n : n + 1;
	for (int i = n-1; i >= 0; --i) {
		f[i] = i && a[i] == a[n];
		for (int c = 1; c <= 2; ++c) {
			(f[i] += f[nxt[(a[i]+c)%3]]) %= MOD;
		}
		nxt[a[i]] = i;
 	}
 	printf("%d\n", f[0]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

const ll MAXN = 2000;
string M[MAXN];

ll dp[MAXN][MAXN];

ll W, H;

int main()
{
    cin >> H >> W;
    rep (i, H) { cin >> M[i]; }

    rep (y, H)
    rep (x, W)
    {
        if (M[y][x] == '#') { continue; }

        ll n = 0;

        for (ll i=x;i<W;++i)
        {
            if (M[y][i] == '#') { break; }
            ++n;
        }

        while (x < W)
        {
            if (M[y][x] == '#') { break; }

            dp[y][x] += n;
            ++x;
        }
    }

    rep (x, W)
    rep (y, H)
    {
        if (M[y][x] == '#') { continue; }

        ll n = 0;

        for (ll i=y;i<H;++i)
        {
            if (M[i][x] == '#') { break; }
            ++n;
        }

        while (y < H)
        {
            if (M[y][x] == '#') { break; }
            dp[y][x] += n;
            ++y;
        }
    }

    ll ans = 0;

    rep (y, H)
    rep (x, W)
    {
        ans = max(ans, dp[y][x] - 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35584
fun main(args: Array<String>) {
    val (N, M, X, Y) = readLine()!!.split(' ').map(String::toInt)
    val xs = readLine()!!.split(' ').map(String::toInt)
    val ys = readLine()!!.split(' ').map(String::toInt)
    if(listOf(xs.max()!!, X).max()!! < listOf(ys.min()!!, Y).min()!!) {"No War"} else {"War"}.run(::println)
}

Measured memory_bytes: 38180
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int N;
int d[100000];
int main(void){
    cin >> N;
    REP(i,N) cin >> d[i];
    sort(d, d+N);
    cout << d[N/2] - d[N/2 - 1] << endl;
    return 0;
}



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

int main() {
    int n;cin>>n;
    ll a[n];
    for (int i=0;i<n;i++) {
        cin>>a[i];
        if (a[i]==0) {
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=1;
    ll mx=1e18;
    for (int i=0;i<n;i++) {
        if (ans>mx/a[i]) {
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int threecolor[3][35];

int main() {
  int n,C; cin >> n >> C;
  int d[C][C];
  FOR(i,0,C-1){
    FOR(j,0,C-1){
      cin >> d[i][j];
    }
  }
  int c[n][n];
  FOR(i,0,n-1){
    FOR(j,0,n-1){
      cin >> c[i][j];
      ++threecolor[(i+j)%3][c[i][j]];
    }
  }

  int ans = 1000000000;
  FOR(i,1,C){
    FOR(j,1,C){
      FOR(k,1,C){
        if(i==j || j==k || k==i) continue;
        int tmp = 0;
        FOR(l,1,C){
          tmp += threecolor[0][l] * d[l-1][i-1];
          tmp += threecolor[1][l] * d[l-1][j-1];
          tmp += threecolor[2][l] * d[l-1][k-1];
        }
        chmin(ans,tmp);
      }
    }
  }

  cout << ans << endl;


}

Measured memory_bytes: 1280
#include<iostream>
#include<stack>
#include<cstdlib>
#include<string>

using namespace std;
int main() {
	string s,sub;
	stack<int> st;
	int a, b;
	getline(cin, s);
	bool flag=true;
	while (flag) {
		flag = false;
		for (int i = 0;i < s.length();i++) {
			if (s[i] == ' ') {
				sub = s.substr(0, i);
				s = s.substr(i+1);
				flag = true;
				break;
			}
		}
		if (!flag)sub = s;
		if (sub == "+") {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(a + b);
		}
		else if (sub == "*") {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(a * b);
		}
		else if (sub == "-") {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(b-a);
		}
		else {
			st.push(atoi(sub.c_str()));
		}
	}
	cout << st.top() << endl;
}


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

class Program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int t = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        List<int> list = new List<int>();
        for(int i = 0; i < n; i++){
            list.Add(int.Parse(str[i]));
        }
        long sum = 0;
        for(int i = 1; i < n; i++){
            if(t <= list[i] - list[i - 1]){
                sum += t;
            }else{
                sum += list[i] - list[i - 1];
            }
        }
        sum += t;

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 28512
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
X = [int(x) for x in input().strip().split()]

def f(p):
    ret = 0
    for x in X:
        ret += (x - p) ** 2
    return ret

ans = float('inf')
for i in range(1, 101):
    ans = min(ans, f(i))

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
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; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

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

int main ()
{
  ll N,K;cin>>N>>K;
  string S; cin>>S;
  vector<int> pos;
  vector<int> num;
  int postmp = 0;
  char tmp = S[0];
  for(int i=1;i<N;i++){
    if(S[i]!=tmp){
      pos.push_back(i-postmp);
      num.push_back(tmp-'0');
      postmp = i;
      tmp = S[i];
    }
  }
  pos.push_back(N-postmp);
  num.push_back(S[N-1]-'0');
  ll ans = 0;
  //print(pos);
  //print(num);
  for (int i = 0; i < pos.size(); i++)
  {
    if(num[i] == 0){
      ll length;
      if (i==0){
          length = 2 * K;
           if (i+length>pos.size()){
          ll tmp = accumulate(pos.begin()+i, pos.end(), 0);
          ans = max(ans,tmp);
            }else{
            ll tmp = accumulate(pos.begin()+i, pos.begin()+i+length, 0);
            ans = max(ans,tmp);
            }
      }else{
        length = 2 * K;
      
        if (i+length>pos.size()){
          ll tmp = accumulate(pos.begin()+i-1, pos.end(), 0);
          ans = max(ans,tmp);
        }else{
            ll tmp = accumulate(pos.begin()+i-1, pos.begin()+i+length, 0);
            ans = max(ans,tmp);
        }
      }
    }
    if(num[i] == 1){
      ll length = 2 * K + 1;
        if (i+length>pos.size()){
          ll tmp = accumulate(pos.begin()+i, pos.end(), 0);
          ans = max(ans,tmp);

        }else{
            ll tmp = accumulate(pos.begin()+i, pos.begin()+i+length, 0);
            ans = max(ans,tmp);
        }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int N,ans=0; cin >> N;
  v<int> a(N+1);
  for(int i=1;i<=N;i++){
    cin >> a[i];
  }
  int x1=0;
  for(int i=1;i<=N;i++){
    if(i%2==1) x1+=a[i];
    else x1-=a[i];
  }
  cout << x1 << endl;
  x1/=2;
  int x=x1;
  for(int i=1;i<=N-1;i++){
    x=2*(a[i]-x);
    cout << x << endl;
    x/=2;
  }
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, K; cin >> N >> K;
    vector<int> P(N), C(N);
    rep(i,N) {
        int j; cin >> j; j--;
        P[i] = j;
    }
    rep(i,N) {
        cin >> C.at(i);
    }
    vector<vector<int>> G;
    vector<ll> MON;

    ll max = -9999999999;
    rep(i,N) {
        int cur = P[i];
        bool found = false;
        rep(j, G.size()) {
            vector<int>& H = G[j];
            auto x = find(H.begin(), H.end(), cur);
            if (x != H.end()) {
                found = true;
                break;
            }
        }
        if (found) continue;
        vector<int> L;
        L.push_back(cur);
        ll money = 0;
        while (1) {
            money += C[cur];
            cur = P[cur];
            if (cur == P[i]) break;
            L.push_back(cur);
        }
        G.push_back(L);
        MON.push_back(money);
    }

    rep(i,N) {
        rep(j, G.size()) {
            vector<int>& H = G[j];
            auto x = find(H.begin(), H.end(), P[i]);
            if (x != H.end()) {
                ll score = 0;
                ll ma = -9999999999;
                if (MON[j] < 0) {
                    rep(k, H.size()) {
                        score += C[*x];
                        if (ma < score) ma = score;
                        x = next(x);
                        if (x == H.end()) x = H.begin();
                    }
                } else {
                    ll s1 = MON[j] * (K / H.size() - 1);
                    rep(k, H.size() + K % H.size()) {
                        s1 += C[*x];
                        if (ma < s1) ma = s1;
                        x = next(x);
                        if (x == H.end()) x = H.begin();
                    }
                }
                if (max < ma) max = ma;
                break;
            }
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 3736
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    def f(a, b):
        ret = 0
        while a > b:
            ret += 2
            b *= 4
        return ret

    N = int(input())
    A = list(map(int, input().split()))

    right = [0] * (N+1)
    st = [(1, A[-1], A[-1])]
    for i in range(N-2, -1, -1):
        a = A[i]
        st.append((1, a, a))
        right[i] = right[i+1]
        while True:
            if len(st) == 1:
                break
            if st[-1][2] > st[-2][1]:
                na, amin, amax = st.pop()
                nb, bmin, bmax = st.pop()
                k = f(amax, bmin)
                right[i] += nb * k
                if st:
                    st.append((na+nb, amin, bmax << k))
                else:
                    st.append((na+nb, amin, float("inf")))
            else:
                break
    left = [0] * (N+1)
    left[1] = 1
    st = [(1, A[0], A[0])]
    for i in range(2, N+1):
        a = A[i-1]
        st.append((1, a, a))
        left[i] = left[i-1] + 1
        while True:
            if len(st) == 1:
                break
            if st[-1][2] > st[-2][1]:
                na, amin, amax = st.pop()
                nb, bmin, bmax = st.pop()
                k = f(amax, bmin)
                left[i] += nb * k
                if st:
                    st.append((na + nb, amin, bmax << k))
                else:
                    st.append((na+nb, amin, float("inf")))
            else:
                break
    ans = float("inf")
    for i in range(N+1):
        ans = min(ans, left[i] + right[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103888
/* This code is written by Nemlit */
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define ls k * 2
#define rs k * 2 + 1
#define maxn 2333
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next; }e[maxn << 1];
	il void add(int u, int v) { e[++ cnt] = (edge){v, head[u]}, head[u] = cnt; }
}
//using namespace Graph;
int n, m;
char c[maxn];
signed main() {
	scanf("%s", c);
	if(c[1] == 'R') puts("ABC");
	else puts("ARC");
	return 0;
}


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

int main(){
  int n;
    cin >> n;
  int H[n];
  for(int i = 0; i < n; i++){
    cin >> H[i];
  }
int mx = 0 , ans = 0;
for(int i = 0; i < n; i++){
  if(H[i] >= mx){
    ans++;
    mx = H[i];
  }
}
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
typedef long long ll;
const int mod=1e9+7;
ll n,cnt[65];
void via(ll x){
	int p=0;
	while(x){
		if(x%2)cnt[p]++;
		x>>=1;p++;
	}
}
ll C(ll x){
	return x*(x-1)/2;
}
int main(){
	cin>>n;ll sum=0;
	for(ll i=1;i<=n;i++){
		ll x;cin>>x;
		via(x);sum+=x;sum%=mod;
	}
	ll tmp=0,j=2;
	for(ll i=0;i<=62;i++){
		if(cnt[i]>1){
			tmp+=(C(cnt[i])%mod*(j%mod))%mod;
			tmp%=mod;
		}j*=2;
	}
	ll ans=((n-1)*sum%mod-tmp+mod)%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int i,j,k;
int n;
int height[int(1e6)];
int cache[int(1e6)];


int dp(int x){
    if(x==0){
        return 0;
    }
    else if(x == 1){
        return abs(height[x]-height[x-1]); 
    }
    else if(cache[x] != -1){
        return cache[x];
    }

    else{
        return cache[x] = min(dp(x-1) + abs(height[x]-height[x-1]) ,dp(x-2)+ abs(height[x]-height[x-2]));
        }

}

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

    cin >> n;
    for(i = 0 ; i < n ; i++){
        cin >> height[i];
        cache[i] = -1; 
    }
    cout << dp(n-1) << endl;
}

Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a, ans[200020];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		if (n % 2) {
			if (i % 2) ans[n / 2 + 1 - i / 2] = a;
			else ans[n / 2 + 1 + i / 2] = a;
		}
		else {
			if (i % 2) ans[n / 2 + 1 + i / 2] = a;
			else  ans[n / 2 + 1 - i / 2] = a;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (i != n)cout << ans[i] << " ";
		else cout << ans[i] << endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int b[n-1];
  for(int s=0; s<n-1; s++){
    cin >> b[s];
  }
  
  int ans=b[0];
  
  for(int s=0; s<n-1; s++){
    
    if(s==n-2){
      ans+=b[s];
      break;
    }
    if(b[s]<=b[s+1]) ans+=b[s];
    else ans+=b[s+1];
  }
  
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <iostream>

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

  char s;

  std::cout << N-1 << std::endl;
  std::cin >> s;
  std::cin.ignore(16, '\n');
  if (s == 'V') return 0;

  std::cout << 0 << std::endl;
  std::cin >> s;
  std::cin.ignore(16, '\n');
  if (s == 'V') return 0;  

  int lb=0, ub=N-1;
  while (ub-lb > 1) {
    int mid=(lb+ub)>>1;
    std::cout << mid << std::endl;

    char t;
    std::cin >> t;
    std::cin.ignore(16, '\n');
    if (t == 'V') return 0;
    ((mid&1)^(s==t)? lb:ub) = mid;
  }
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans;
  for (int i=1;;i++){
    if(i*i<=n&&(i+1)*(i+1)>n){
      ans=i*i;
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{

  long long  N;
  cin >> N;

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end() );

  //cerr << A[(N / 2) - 1] << endl;
  //cerr << A[(N / 2)    ] << endl;
  cout << A[(N / 2)] - A[(N / 2) - 1];

  return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

def MII_split(): return map(int, input().split())

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

def LII_split(): return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

K = input_int()
S = input()

if len(S) > K:
    S = S[:K]
    S += '...'
print(S)

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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

const long INF = 1e18;

struct segtree
{
	int sz;
	long tree[400003], lazy[400003];
	segtree()
	{
		for(int i = 0; i <= 400000; i++)
		{
			lazy[i] = INF;
			tree[i] = INF;
		}
	}
	void cek_lazy(int pos, int kir, int kan)
	{
		if(lazy[pos] != INF)
		{
			tree[pos] = min(tree[pos], lazy[pos]);
			if(kan-kir) lazy[pos*2] = min(lazy[pos*2], lazy[pos]);
			if(kan-kir) lazy[pos*2+1] = min(lazy[pos*2+1], lazy[pos]);
			lazy[pos] = INF;

		}
	}
	void update(int pos, int kir, int kan, int qkir, int qkan, long val)
	{
		// printf("%d %d %d %d %d %d\n", pos, kir, kan, qkir, qkan, val);
		cek_lazy(pos, kir, kan);
		if(qkan < kir || kan < qkir) return;
		else if(qkir <= kir && kan <= qkan) lazy[pos] = min(lazy[pos], val), cek_lazy(pos, kir, kan);
		else
		{
			int mid = (kir+kan)/2;
			update(pos*2, kir, mid, qkir, qkan, val);
			update(pos*2+1, mid+1, kan, qkir, qkan, val);
			tree[pos] = min(tree[pos*2], tree[pos*2+1]);
		}
	}
	void update(int kir, int kan, long val)
	{
		update(1, 1, sz, kir, kan, val);
	}
	long query(int pos, int kir, int kan, int qkir, int qkan)
	{
		cek_lazy(pos, kir, kan);
		if(qkan < kir || kan < qkir) return INF;
		else if(qkir <= kir && kan <= qkan) return tree[pos];
		else
		{
			int mid = (kir+kan)/2;
			long a = query(pos*2, kir, mid, qkir, qkan);
			long b = query(pos*2+1, mid+1, kan, qkir, qkan);
			return min(a,b);
		}
	}
	long query(int kir, int kan)
	{
		return query(1, 1, sz, kir, kan);
	}
};

int n, m;
segtree tree;
vector<iii> vec;

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d %d", &n, &m);
	tree.sz = n;	
	for(int i = 0; i < m; i++)
	{
		int u, v, c;
		scanf("%d %d %d", &u, &v, &c);
		vec.push_back({{u,v},c});
	}
	sort(vec.begin(), vec.end());

	tree.update(1, 1, 0);
	for(auto edg : vec)
	{
		int u = edg.fi.fi, v = edg.fi.se;
		long w = edg.se;
		tree.update(u, v, tree.query(u, v)+w);
		// for(int i = 1; i <= n; i++)
		// 	printf("%lld ", tree.query(i,i));
		// printf("\n");
	}
		// for(int i = 1; i <= n; i++)
		// 	printf("%lld ", tree.query(i,i));
		// printf("\n");
	long res = (tree.query(n,n));
	printf("%lld\n", (res == INF)? -1 : res);
}

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

int main(){
  int h, w;
  cin>>h>>w;
  
  string board[50];
  for(int i=0; i<h ; i++)cin>>board[i];
  
  int dx[8] = {  1,  1,  1,  0,  0,  -1,  -1,  -1};
  int dy[8] = {  1, -1,  0,  1,  -1,  1,  -1,   0};
  
  for(int i=0; i<h; i++){
    
    for(int j=0; j<w; j++){
      if(board[i][j] == '#') continue;
      
      int num = 0;
      for(int d=0; d<8; d++){
        int ni = i + dy[d];
        int nj = j + dx[d];
        
        if(0 > ni or h <= ni) continue;
        if(0 > nj or w <= nj) continue;
        if(board[ni][nj] == '#') num++;
      }
    
      board[i][j] = char(num + '0');
    }
  }
  
  for(int i=0; i<h; i++)cout<<board[i]<<endl;
}

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

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 400;
char s[N][N];

int main() {
  int n, m, x;
  scanf("%d%d%d", &n, &m, &x);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  vector<vector<int>> a(n, vector<int>(m));
  int h = 1, u = 1;
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    for (int j = 0; j < m; ++j) cnt += s[i][j] == '#';
    if (cnt == 0) {
      ++h;
      continue;
    }
    for (int j = 0, k; j < m; j = k) {
      for (k = j; k < m && s[i][k] == '.'; ++k) {
        for (int v = 0; v < h; ++v) {
          a[i - v][k] = u;
        }
      }
      if (k < m) {
        for (int v = 0; v < h; ++v) {
          a[i - v][k] = u;
        }
        ++u;
      } else {
        for (k = j; k < m; ++k) {
          for (int v = 0; v < h; ++v) {
            a[i - v][k]--;
          }
        }
      }
      ++k;
    }
    h = 1;
  }
  if (h > 1) {
    for (int i = n - h + 1; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        a[i][j] = a[i - 1][j];
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%d%c", a[i][j], " \n"[j + 1 == m]);
    }
  }
  return 0;
}


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


void solve(long long A, long long B, long long K){
  for(int i = A; i <= B; i++) {
    if((A+K) > i || (B-K) < i) cout << i << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long K;
  scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


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

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

    long long n;
    cin >> n;
    vector<long long> A(n);
    for(long long i = 0; i < n; i++){
        cin >> A[i];
        A[i] -= (i + 1);
    }

    sort(A.begin(), A.end());
    long long h = 0;
    if(n % 2){
        h = A[n / 2];
    }else{
        h = (A[n / 2] + A[n / 2 - 1]) / 2;
    }

    long long ans = 0;
    for(long long i = 0; i < n; i++){
        ans += abs(A[i] - h);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

const int N = 100005;

int f[N];

int main() {
	int n;
	scanf("%d", &n);
	vector <int> a;
	a.push_back(1);
	for (int i = 1; i <= 5; i++) {
		a.push_back(pow(9, i));
	}
	for (int i = 1; i <= 6; i++) {
		a.push_back(pow(6, i));
	}
	int m = a.size();
	for (int i = 1; i <= 100002; i++) {
		f[i] = 1e9;
	}
	f[0] = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 1; j <= n; j++) {
			if (j - a[i] >= 0) {
				f[j] = min(f[j], 1 + f[j - a[i]]);
			}
		}
	}
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
 
int n,m;
int i,j;
int x,y;
int a[256][256];
int b[256];
int sum;
 
main(){
    scanf("%d %d",&n,&m);
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d",&x);
            a[i][j]=x;
        }
    }
    for(i=0; i<m; i++){
        scanf("%d",&y);
        b[i]=y;
    }
     
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            sum += a[i][j]*b[j];
        }
                printf("%d\n",sum);
                sum=0;
    }
return 0;   
}

Measured memory_bytes: 704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    vector<int> a(n);rep(i,n)cin>>a[i];
    vector<int> b(n);
    int ans = 0;
    for(int i=n-1; i>=0; i--){
        int sum = 0;
        for(int j=2; (i+1)*j<=n; j++){
            sum ^= b[(i+1)*j-1];
        }
        if(b[i]=(a[i]^sum))ans++;
    }
    cout<<ans<<endl;
    rep(i,n)if(b[i])cout<<i+1<<" ";

    return 0;
}

Measured memory_bytes: 2560
use std::io::*;
use std::str::FromStr;

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

use std::collections::VecDeque;

fn main() {
    let mut vd: VecDeque<i64> = VecDeque::new();
    let n: usize = read();
    for i in 0..n {
        let ai: i64 = read();
        if i % 2 == 0 {
            vd.push_back(ai);
        } else {
            vd.push_front(ai);
        }
    }
    if n % 2 == 0 {
        for i in vd.into_iter() {
            print!("{} ", i)
        }
    } else {
        for i in vd.into_iter().rev() {
            print!("{} ", i)
        }
    }
}


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

int main() {
    int K; cin >> K;
    int A; cin >> A;
    int B; cin >> B;
    string ans = "NG";

    for(int i = A; i <= B; i++){
        int tmp = i % K;
        if(tmp == 0){
            ans = "OK";
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += b[i]
for i in range(n-1):
  if(a[i+1]-a[i] == 1):
    j = a[i]-1
    ans += c[j]

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
    char str[5];
    scanf("%s",str);
    int num = 0;
    for(int i = 0;i < 4;i++){
        if(str[i] == '+'){
            num++;
        } else {
            num--;
        }
    }
    printf("%d",num);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        System.out.println(-1);

    }
}


Measured memory_bytes: 52452
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    while(n>0)
    {
        int temp = n%10;
        if(temp==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        n/=10;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3596