akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

const int INF = 1e9;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> list(N);
  for (int i = 0; i < N; i++) {
    cin >> list[i];
  }
  
  ll dp[N + 1];
  for (int i = 0; i <= N; i++) {
    dp[i] = INF;
  }
  
  dp[0] = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = 1; j <= K; j++) {
      if (i + j <= N - 1) {
        dp[i + j] = min(dp[i + j], dp[i] + abs(list[i + j] - list[i]));
      }
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1408
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = 1001001001001001

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	node := make([][]int, N)
	for i := 0; i < M; i++ {
		f, t := getInt()-1, getInt()-1
		node[f] = append(node[f], t)
		node[t] = append(node[t], f)
	}

	ans := make([]int, N)
	// cnt := make([]int, N)
	used := make([]bool, N)
	// for i := 0; i < N; i++ {
	// 	cnt[i] = inf
	// }
	s := make([]int, 0)
	s = append(s, 0)
	// cnt[0] = 0
	used[0] = true
	for len(s) > 0 {
		x := s[0]
		s = s[1:]
		for _, v := range node[x] {
			// if cnt[v] > cnt[x]+1 {
			// 	cnt[v] = cnt[x] + 1
			// }
			if used[v] == true {
				continue
			}
			used[v] = true
			ans[v] = x
			s = append(s, v)
		}
	}

	out("Yes")
	for i := 1; i < N; i++ {
		out(ans[i] + 1)
	}
}


Measured memory_bytes: 18488
from collections import deque
S = input().split()
stack = deque([])
for s in S:
    if s == "+":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1+s2)
    elif s == "-":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s2-s1)
    elif s == "*":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1*s2)
    elif s == "/":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1/s2)
    else:
        stack.append(int(s))
print(stack[0])


Measured memory_bytes: 6004
#include <iostream>

    using namespace std;

    int main()
    {
       int A,B;
       cin>>A>>B;
       if(A>13||A<1){
        return 0;
       }
       if(B>13||B<1){
        return 0;
       }
       if(A==1&&B>1){cout<<"Alice";
       return 0 ;}
       if(B==1&&A>1) {cout<<"Bob";
       return 0;}
       if(A==B) {cout<<"Draw";
       return 0 ;}
       if(A>B){ cout<<"Alice";
       return 0;}
       if(A<B) {cout<<"Bob";
       return 0;}


    }



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;


#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
vector<int>has;
map<int, bool>vis;
void work() {
    int x;
    scanf("%d", &x);
    LL now = 0, to = 1;
    while (now < x) {
        now += to;
        if (now >= x) {
            cout << to << endl;
            return;
        }
        to++;
    }
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


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

int compare_char(char *a,char *b){
	return strcmp(a,b);
}

int intsort(const void *a, const void *b){
	return *(int*)b - *(int*)a;
	/*qsort(a,aの配列数,sizeof(int),intsort);*/
}

int longsort(const void *a, const void *b){
	long *A=(long *)a;
	long *B=(long *)b;
	if(*A>*B) return -1;
	if(*A<*B) return 1;
	return 0;
}

int main(){
  int i,j,k,N,a[3],b[3],cnt=0;
  scanf("%d",&a[0]);
  scanf("%d",&a[1]);
  scanf("%d",&a[2]);
  qsort(a,3,sizeof(int),intsort);
  scanf("%d",&N);
  b[0]=N/a[0];
  N+=a[0];
  for(i=0;i<=b[0];i++){
    N-=a[0];
    b[1]=N/a[1];
    for(j=0;j<=b[1];j++){
      if((N-a[1]*j)%a[2]==0)cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	string a,b;
	cin>>a>>b;
	int x=stoi(a+b);
	bool flg=false;
	//cout<<x<<endl;
	for(int i=0;i<x;i++){
		if(i*i==x){
			flg=true;
			break;
		}
	}
	cout<<((flg)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 384
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int K = 8;
const int M = 2;
const int st = 0;
int go[K][M] = {{1,2},{3,0},{4,5},{1,1},{6,2},{7,7},{4,4},{5,5}};
bool ac[K] = {0,0,1,0,0,0,0,1};
int dp[K], ndp[K];
void upd(int &x, int v) {x=x+v>=mod?x+v-mod:x+v;}
int main()
{
	dp[st] = 1;
	while (_buff.notend())
	{
		char c = getreal();
		memset(ndp, 0, sizeof(ndp));
		for (int i=0; i<K; i++)
		{
			for (int j=0; j<M; j++)
			{
				if (c!='?'&&c-'0'!=j) continue;
				upd(ndp[go[i][j]], dp[i]);
			}
		}
		swap(dp, ndp);
	}
	int ans = 0;
	for (int i=0; i<K; i++) if (ac[i]) upd(ans, dp[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int main(){
  string s;
  cin >> s;
  ll n = s.size();
  char r[n],t[n];
  rep(i,n){
    if(i%2==0){
      r[i] = '0';
      t[i] = '1';
    }else{
      r[i] = '1';
      t[i] = '0';
    }
  }
  ll a=0,b=0;
  rep(i,n){
    if(s[i]!=r[i]) a++;
    if(s[i]!=t[i]) b++;
  }
  cout << min(a,b) << endl;
}


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

int main(){
    string S; cin >> S;
    int count = 0, ans = 0;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' ||S[i] == 'T'){
            count++;
            ans = max(ans, count);
        }else{
            count = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
times = 0

for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        A[i], A[minj] = A[minj], A[i]
        times += 1

print(" ".join(map(str, A)))
print(times)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int xs,ys,n,m;
ll a[2003];
ll b[2003];
bool vis[1009][1009];
int ans[1000004];
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    cin>>m;
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        int sum=0;
        for(int i=1;i<=n;i++)
        {
           if(i==x)
           {
               sum+=y;
               continue;
           }
           sum+=a[i];
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3652
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*ab = map(int,read().split())

m = iter(ab)
g = [[] for _ in range(n)]
for a,b in zip(m,m):
    g[a-1].append(b-1)
    g[b-1].append(a-1)

def dist(g,start):
    n = len(g)
    dist = [-1]*n
    q = [start]
    dist[start] = 0
    while q:
        v = q.pop()
        for c in g[v]:
            if dist[c] == -1:
                dist[c] = dist[v]+1
                q.append(c)
    return dist        

df = dist(g,0)
ds = dist(g,n-1)


cnt = 0
for i,j in zip(df,ds):
    if i <= j:
        cnt += 1
    else:
        cnt -= 1

#print(cnt)
if cnt >= 1:
    print("Fennec")
else:
    print("Snuke")







Measured memory_bytes: 41316
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


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

	if (a == b) {
		ANS(a + b);
	}
	else {
		int m = max(a, b);
		ANS(m + m - 1);
	}
	

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int k = Integer.parseInt(sa[2]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] b = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int ans = 0;
		int sum = 0;
		int j = -1;
		for (int i = 0; i < m; i++) {
			if (sum + b[i] <= k) {
				sum += b[i];
				j = i;
			} else {
				break;
			}
		}
		ans = j + 1;

		for (int i = 0; i < n; i++) {
			sum += a[i];
			while (j >= 0 && sum > k) {
				sum -= b[j];
				j--;
			}
			if (sum <= k) {
				ans = Math.max(ans, i + j + 2);
			} else {
				break;
			}
		}
		System.out.println(ans);
	}
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> s(H);
  for(int i=0;i<H;i++){
    cin >> s.at(i);
  }
  vector< vector<int> > dp(H,vector<int>(W,0));
  if(s.at(0).at(0)=='#'){
    dp.at(0).at(0)=1;
  }else{
    dp.at(0).at(0)=0;
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if((i==0)&&(j==0)){
        continue;
      }
      if(i==0){
        dp.at(i).at(j)=dp.at(i).at(j-1);
        if(s.at(i).at(j)=='#'){
          dp.at(i).at(j)++;
          if(s.at(i).at(j-1)=='#'){
            dp.at(i).at(j)--;
          }
        }
      }else if(j==0){
        dp.at(i).at(j)=dp.at(i-1).at(j);
        if(s.at(i).at(j)=='#'){
          dp.at(i).at(j)++;
          if(s.at(i-1).at(j)=='#'){
            dp.at(i).at(j)--;
          }
        }
      }else{
        if(dp.at(i).at(j-1)<dp.at(i-1).at(j)){
          dp.at(i).at(j)=dp.at(i).at(j-1);
          if(s.at(i).at(j)=='#'){
            dp.at(i).at(j)++;
            if(s.at(i).at(j-1)=='#'){
              dp.at(i).at(j)--;
            }
          }
        }else if(dp.at(i).at(j-1)>dp.at(i-1).at(j)){
          dp.at(i).at(j)=dp.at(i-1).at(j);
          if(s.at(i).at(j)=='#'){
            dp.at(i).at(j)++;
            if(s.at(i-1).at(j)=='#'){
              dp.at(i).at(j)--;
            }
          }
        }else{
          dp.at(i).at(j)=dp.at(i-1).at(j);
          if(s.at(i).at(j)=='#'){
            dp.at(i).at(j)++;
            if((s.at(i-1).at(j)=='#')||(s.at(i).at(j-1)=='#')){
              dp.at(i).at(j)--;
            }
          }
        }
      }
    }
  }
  cout << dp.at(H-1).at(W-1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

void solve(){
	int n;
	cin>>n;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	map<ll,ll>mp;
	vector<ll>sum(n+1);
	rep(i,n)sum[i+1]=sum[i]+a[i];
	rep(i,n+1){
		mp[sum[i]]++;
	}
	ll ans=0;
	rep(i,n+1){
		mp[sum[i]]--;
		ans+=mp[sum[i]];
	}
	cout<<ans<<"\n";
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 18724
# UnionFind: https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        
    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.root[x] > self.root[y]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x
        
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.root[self.find(x)]

n, m = map(int, input().split())
cards = UnionFind(n)
for i in range(m):
    x, y, z = map(int, input().split())
    cards.unite(x, y)
print(sum(cards.find(i) == i for i in range(1, n + 1)))

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

static void SolveA()
{
	int n, k;
	std::string s;
	std::cin >> n >> k;
	std::cin >> s;

	s[k - 1] = std::tolower(s[k - 1]);

	std::cout << s;
}

enum Format
{
	None,
	YYMM,
	MMYY,
};

static void SolveB()
{
	std::string s;
	std::cin >> s;

	const int upper = std::stoi(s.substr(0, 2));
	const int lower = std::stoi(s.substr(2, 2));

	int format{};
	// YYMM
	if (1 <= lower && lower <= 12)
	{
		format |= Format::YYMM;
	}

	// MMYY
	if (1 <= upper && upper <= 12)
	{
		format |= Format::MMYY;
	}

	if ((format & Format::YYMM) && (format & Format::MMYY))
	{
		std::cout << "AMBIGUOUS\n";
		return;
	}

	if (format & Format::YYMM)
	{
		std::cout << "YYMM\n";
		return;
	}

	if (format & Format::MMYY)
	{
		std::cout << "MMYY\n";
		return;
	}

	std::cout << "NA\n";
}

static void SolveC()
{
	int n;
	double k;
	std::cin >> n >> k;

	double sum = 0;
	for (int i = 1; i <= n; i++)
	{
		const double numFlips = std::ceil(log2(k / i));
		if (numFlips < 1e-5)
		{
			sum += (1.0 / n);
			continue;
		}
		sum += (1.0 / n) * std::pow(0.5, numFlips);
	}


	std::cout << std::setprecision(10) << sum << "\n";
}

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

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define int ll
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;;
signed  main(){
    int n; cin>>n;
    vi v(3*n);rep(i,3*n)cin>>v[i];
    sort(all(v),greater<int>());
    int ans=0;
    int cnt=0;
    rep(i,n)ans+=v[i*2+1];
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n;
    cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{	
		if(s[i]+n>'Z')
		s[i]-=(26-n);
		else s[i]+=n;
	}
	for(int i=0;i<s.size();i++)
		cout<<s[i];
	return 0;
}

Measured memory_bytes: 256
// atcoder/abc049/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  int h, w;
  while (cin >> h >> w) {
    char g[h][w];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> g[i][j];
      }
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cout << g[i][j];
      }
      cout << endl;
      for (int j = 0; j < w; ++j) {
        cout << g[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    int k=0;
    while(1){
        cin>>H>>W;
        if(k>0)cout<<endl;
        if(H==0&&W==0)break;
        k++;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i==0||i==H-1||j==0||j==W-1)cout<<"#";
                else cout<<".";
            }cout<<endl;
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 3088
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
I = A[0]
ans = 0
for i in range(N):
    if B[i] <= I:
        ans += B[i]
        I = A[i+1]
    elif I + A[i+1] >= B[i] > I:
        ans += B[i]
        I = I + A[i+1] - B[i]
        
    elif B[i] > I + A[i+1]:
        ans += I + A[i+1]
        I = 0
print(ans)

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

class CumulativeSum1D {

private:
    //入力データa[0]～a[n-1]に対し、
    // source[0] = 0
    // source[i] = a[0] + … + a[i-1]
    //とする。
    std::vector<long long> data;

public:
    CumulativeSum1D(std::vector<int> source) {
        int n = source.size();
        data = std::vector<long long>(n + 1);
        data[0] = 0;
        long long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += source[i];
            data[i + 1] = sum;
        }
    }
    // 終点は含まれないため注意。
    long long query(int start, int end) {
        return data[end] - data[start];
    }

};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> r(n), g(n), b(n);
    for (int i = 0; i < n; i++) {
        char c = s[i];
        if (c == 'R') {
            r[i]++;
        }
        else if (c == 'G') {
            g[i]++;
        }
        else {
            b[i]++;
        }
    }
    auto rc = CumulativeSum1D(r);
    auto gc = CumulativeSum1D(g);
    auto bc = CumulativeSum1D(b);

    ll result = 0;
    //1個目・2個目は素直にループ
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (s[i] == s[j]) continue;
            int exclusion = 2 * j - i;
            //どれを使うかのロジック…
            if (r[i]) {
                if (g[j]) {
                    result += bc.query(j + 1, n);
                    if (exclusion < n) result -= b[exclusion];
                }
                else if (b[j]) {
                    result += gc.query(j + 1, n);
                    if (exclusion < n) result -= g[exclusion];
                }
            }
            else if (g[i]) {
                if (r[j]) {
                    result += bc.query(j + 1, n);
                    if (exclusion < n) result -= b[exclusion];
                }
                else if (b[j]) {
                    result += rc.query(j + 1, n);
                    if (exclusion < n) result -= r[exclusion];
                }
            }
            else if (b[i]) {
                if (r[j]) {
                    result += gc.query(j + 1, n);
                    if (exclusion < n) result -= g[exclusion];
                }
                else if (g[j]) {
                    result += rc.query(j + 1, n);
                    if (exclusion < n) result -= r[exclusion];
                }
            }
        }
    }
    cout << result << endl;

    return 0;

}


Measured memory_bytes: 3732
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
struct edge {int from,to;};
int V,E;
vector<int> e[100];
int used[100];
int checked[100];
int dfs(int v){
  if(used[v]==1)return 1;
  used[v]=1;
  for(int j=0;j<e[v].size();j++){
    int u=e[v][j];
    if(!checked[u])
      if(dfs(u)) return 1;
  }
  used[v]=0;
  checked[v]=1;
  return 0;
}
int main(){
  scanf("%d %d",&V,&E);
  for(int i=0;i<E;i++){
    int x,y;
    scanf("%d %d",&x,&y);
    e[x].push_back(y);
  }
  int f;
  for(int i=0;i<V;i++){
    f=0;
    memset(used,0,sizeof(used));
    if(!checked[i]){
      f=dfs(i);
    }
    if(f)break;
  }
  printf("%d\n",f);
  return 0;
}

Measured memory_bytes: 3260
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		boolean is_prime = true;
		Integer[] prime_10 = {2, 3, 5, 7};
		ArrayList<Integer> prime_100 = new ArrayList<Integer>(Arrays.asList(prime_10));
		for(int i = 10; i < 100; i++){
			is_prime = true;
			for(int j = 0; j < prime_10.length; j++){
				if(i %  prime_10[j] == 0){
					is_prime = false;
					break;
				}
			}
			if(is_prime){
				prime_100.add(i);
			}
		}

		ArrayList<Integer> prime_10000 = new ArrayList<Integer>();
		for(int i = 2; i < 10000; i++){
			is_prime = true;
			for(int j = 0; j < prime_100.size(); j++){
				Integer prime = prime_100.get(j);
				if(i != prime&& i % prime == 0){
					is_prime = false;
					break;
				}
			}
			if(is_prime){
				prime_10000.add(i);
			}
		}

		ArrayList<Integer> result = new ArrayList<Integer>();
		while(s.hasNext()){
			Integer number = Integer.parseInt(s.next());
			is_prime = true;
			if(result.contains(number)){
				continue;
			}
			for(int j = 0; j < prime_10000.size(); j++){
				Integer prime = prime_10000.get(j);
				if(!number.equals(prime) && number % prime == 0){
					is_prime = false;
					break;
				}
			}
			if(is_prime){
				result.add(number);
			}
		}
		System.out.println(result.size());
		s.close();
	}
}

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


int main(void){
	int N;
	cin >> N;
	unordered_map<string, int> u_m;
	const int one = 1;
	string s;
	for(int i = 0; i < N; ++i){
		cin >> s;
		if(u_m.find(s) == u_m.end()){
			u_m.insert({s, one});
		}else{
			++u_m[s];
		}
	}
	int max = 0;
	vector<string> max_s;
	for(auto& k_v : u_m){
		if(max < k_v.second){
			max = k_v.second;
			vector<string>().swap(max_s);
			max_s.push_back(k_v.first);
		}else if(max == k_v.second){
			max_s.push_back(k_v.first);	
		}
	}
	sort(max_s.begin(), max_s.end());
	for(auto& v : max_s){
		cout << v << endl;
	}

}


Measured memory_bytes: 26692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4]==s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll atcoder = int(1e9 + 7);

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


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

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

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

	int cs, ct, m;
	cs = ct = m=0;

	rep(i, s.length()) {
		if (s[i] == 'S')cs++;
		else ct++;

		if (ct - cs > m)m = (ct - cs);
	}
	pr(2 * m);
	
	return 0;

}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

char buf[16];

void selectionsort(int *a, int n)
{
  int i, j, mini, t, nswap = 0;
  for (i=0; i<n; i++) {
    mini = i;
    for (j=i; j<n; j++)
      if (a[j]<a[mini]) mini=j;
    if (i!=mini) {
      t = a[i];
      a[i] = a[mini];
      a[mini] = t;
      nswap++;
    }
  }
  buf[15]=0;
  buf[14] = ' ';
  for (i=0; i<n-1; i++) {
    if (a[i]==0)  putc_unlocked('0', stdout);
    for (j=13; a[i]>0; j--, a[i]/=10) buf[j]='0' + (a[i]%10);
    fputs(buf+j+1, stdout);
  }
  buf[14] = '\n';
  for (j=13; a[i]>0; j--, a[i]/=10) buf[j]='0' + (a[i]%10);
  fputs(buf+j+1, stdout);

  if (nswap==0)  putc_unlocked('0', stdout);
  for (j=13; nswap>0; j--, nswap/=10) buf[j]='0' + (nswap%10);
  fputs(buf+j+1, stdout);
}

int main()
{
  char *p = NULL;
  size_t linecap = 0;
  fgets(buf, 12, stdin);
  int n = atoi(buf);
  int *a = (int*)malloc(sizeof(int)*n);
  getline(&p, &linecap, stdin);
  a[0] = 0;
  int i=0;
  for (; *p!='\n'; p++) {
    if (*p == ' ') {
      a[++i] = *(++p)-'0';
    } else {
      a[i] = a[i] * 10 + *p - '0';
    }
  }
  selectionsort(a, n);

  return 0;
}



Measured memory_bytes: 2104
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,0,-1};
const static int ty[] = {-1,0,1,0};

const static double EPS = 1e-8;

int main(){
  string cypher;
  while(cin >> cypher){
    if(cypher == "#END") break;

    string res = "";
    string dp_str[301][301];

    for(int split_i = 1; split_i < cypher.size(); split_i++){
      //[0,split_i),[split_i,cypher.size())
      if(res.size() >= min(split_i,(int)cypher.size() - split_i)){
        continue;
      }
      string A = cypher.substr(0, split_i - 0);
      string B = cypher.substr(split_i, cypher.size() - split_i);

      dp_str[0][0] = "";
      for(int y = 0; y < A.size(); y++){
        for(int x = 0; x < B.size(); x++){
          if(A[y] == B[x]){
            dp_str[y+1][x+1] = dp_str[y][x] + A[y];
          }
          else {
            if(dp_str[y][x+1].size() > dp_str[y+1][x].size()){
              dp_str[y+1][x+1] = dp_str[y][x+1];
            }
            else{
              dp_str[y+1][x+1] = dp_str[y+1][x];
            }
          }
        }
      }
      if(res.size() < dp_str[A.size()][B.size()].size()){
        res = dp_str[A.size()][B.size()];
      }
    }
    printf("%s\n",res.c_str());
  }
}

Measured memory_bytes: 5712
#include<iostream>
#include<string>

using namespace std;

int main(){
	int n;
	int m;
	char data[5000][2];
	string s;
	while(true){
		cin>>n;
		if(n==0)break;
		string str;
		for(int i=0;i<n;i++){
			cin>>data[i][0]>>data[i][1];
		}
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>s;
			str=str+s;
		}
		for(int i=0;i<str.size();i++){
			for(int j=0;j<n;j++){
				if(data[j][0]==str[i]){
					str[i]=data[j][1];
					break;
				}
			}
		}
		cout<<str<<endl;
	}
	return 0;
}

Measured memory_bytes: 1596
N, M = map(int,input().split())
DP = [0 for i in range(N+1)]
DP[0]=1
for i in range(M):
    DP[int(input())] = None
for i in range(N):
    if 0<i and DP[i+1]!=None and DP[i-1]!=None:
        DP[i+1]+=DP[i-1]
    if DP[i+1]!=None and DP[i]!=None:
        DP[i+1]+=DP[i]
print(DP[N]%1000000007)

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::set<int64_t> s;
  for (int64_t i = 0; i < n; i++) {
    int64_t a;
    std::cin >> a;
    s.insert(a);
  }

  if (s.size() == n) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
    return 0;
  }
  else{
    cout << "No" << endl;
    return 0;
  }
}

Measured memory_bytes: 3548
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
using namespace std;


int main(void) {
	int x;
	cin >> x;
	int s = 0;
	int count = 0;

	while (x > s) {
		s += 105;
		++count;
	}
	if (x >= s - 5 * count) {
		cout << 1;
	}
	else {
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = [0] * N
for i in range(N):
    A.append(int(input()))
max = max(A)
B = sorted(A, reverse = True)
count = A.count(max)
if count > 1:
    for i in range(N):
        print(max)
else:
    for i in range(N):
        if A[i] != max:
            print(max)
        else:
            print(B[1])


Measured memory_bytes: 14856
n,m = map(int,input().split())
if n % 2 == 1:ans = [[1+i,n-i] for i in range(n//2)]
else:ans = [[1+i,n-i] for i in range(n//4)]+[[n//2+1+i,n//2-1-i] for i in range(n//2-n//4-1)]
for i in range(m):print(ans[i][0],ans[i][1])

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

using namespace std;

long long n, a[105], k;

int main() {

cin >> n;

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


for (int i = 1; i < n; ++i){
    if (a[i] == a[i + 1]){
        if (a[i + 1] == a[i + 2]) {a[i + 1] = k * -1; k++;}
        else {k++;}
    }
}

cout << k;

return 0;

}


Measured memory_bytes: 256
def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

n=int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
ll wei[105],val[105];
ll dp[105][100005];
int main()
{
  int n,w;

  for(int i=0; i<101; i++){
    for(int j=0; j<100001; j++){
      dp[i][j] = 0;
    }
  }

  cin >> n >> w;

  for(int i=0; i<n; i++) cin >> wei[i] >> val[i];

  for(int i=0; i<n; i++){
    for(int x=0; x<=w; x++){
      if(wei[i] <= x){
	dp[i + 1][x] = max(dp[i][x], dp[i][x - wei[i]] + val[i]);
      } else {
	dp[i + 1][x] = dp[i][x];
      }
    }
  }

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

  return 0;
}
    


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

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

  int sum = 0;
  for (int i = 1; i < (N + 1); i++) {  // Nまで
    // cout << i << endl;

    int t = i, c = 0;
    for (int j = 0; j < 5; j++) {
      c += t % 10; t /= 10;
      // cout << c << endl;
    }
    if (A <= c && c <= B) {
      sum += i;
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
//--
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<complex>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef complex<double> pt;
double dot(pt a,pt b){return (conj(a)*b).real();}
double cros(pt a,pt b){return (conj(a)*b).imag();}
pt proj(pt a,pt to){
  return dot(a,to)/norm(to)*to;
}

pt refle(pt a,pt mirror){
  return pt(2)*proj(a,mirror)-a;
}

pt pt3(pt a,pt b,pt c){
  pt p=b-a,q=c-a,tmp;
  tmp=cros(p,q);
  cout<<tmp<<endl;
  return p;
}

int main(){
  int i,j,k,n;
  pt o,p,q;
 // cout<<cros(pt(1,0),pt(0,-1))<<endl;
  cin>>o.real()>>o.imag()>>p.real()>>p.imag();
  cin>>n;
  rep(i,n){
    cin>>q.real()>>q.imag();
    q=refle(q-o,p-o)+o;
    printf("%.9f %.9f\n",q.real(),q.imag());
  }
  return 0;
}

Measured memory_bytes: 1268
import java.util.*;

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

        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        boolean flip = false;

        for(int i=0 ;i<n; i++) {
            int t = sc.nextInt();
            if(t == 1) {
                flip = !flip;
            } else {
                int f = sc.nextInt();
                String c = sc.next();
                if(!flip && f==1 || flip && f==2) {
                    sb1.append(c);
                } else {
                    sb2.append(c);
                }
            }
        }

        if(flip) {
            System.out.print(sb2.reverse().toString());
            System.out.print(new StringBuilder(s).reverse().toString());
            System.out.println(sb1.toString());
        } else {
            System.out.print(sb1.reverse().toString());
            System.out.print(s);
            System.out.println(sb2.toString());
        }
    }
}

Measured memory_bytes: 120212
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define int long long
const int N = 4400000;
const int M = 21000000;
const int inf = 1e18;
int read() {
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + ch - '0'; ch = getchar();}
    return x * f;
}
int pre[N], to[M], nxt[M], w[M], ls[N], rs[N], pos[N], dis[N], sz, top, ra, rb, n, m;
bool vis[N];
void add(int u, int v, int ww = 0) {to[++top] = v; nxt[top] = pre[u]; pre[u] = top; w[top] = ww;}
struct data
{
    int a, b;
    data(int aa = 0, int bb = 0) : a(aa), b(bb) {}
    bool operator < (data a) const {return b > a.b;}
};

void Build(int &p, int L, int R, bool flag) {
    if(!p) p = ++sz;
    if(L == R) {if(flag) pos[L] = sz; return;}
    int mid = L + R >> 1;
    Build(ls[p], L, mid, flag); Build(rs[p], mid + 1, R, flag);
    if(flag) add(ls[p], p), add(rs[p], p);
    else add(p, ls[p]), add(p, rs[p]);
} 
void Add(int pa, int pb, int L, int R) {
    if(L == R) {add(pb, pa); return;}
    int mid = L + R >> 1;
    Add(ls[pa], ls[pb], L, mid); Add(rs[pa], rs[pb], mid + 1, R);
}
void Update(int p, int L, int R, int st, int ed, int c, bool flag) {
    if(L == st && ed == R) {
        if(flag) add(p, c, 0);
        else add(c, p, 0);
        return ;
    }
    int mid = L + R >> 1;
    if(st <= mid) Update(ls[p], L, mid, st, min(mid, ed), c, flag);
    if(ed > mid) Update(rs[p], mid + 1, R, max(st, mid + 1), ed, c, flag);
}
void Link(int a, int b, int c, int d,int ww)
{
    Update(ra, 1, n, a, b, ++sz,ww);
	add(sz, sz + 1,ww); 
    Update(rb, 1, n, c, d, ++sz, 0);
}

void Dij() {
    for(int i = 1;i <= sz; ++i) dis[i] = inf;
    priority_queue<data>q;
    dis[pos[1]] = 0; q.push(data(pos[1], 0));
    while(!q.empty()) {
        int u = q.top().a; q.pop();
        if(vis[u]) continue;
        vis[u] = true;
        for(int i = pre[u]; i; i = nxt[i]) 
        if(!vis[to[i]] && dis[to[i]] > dis[u] + w[i]) {
            dis[to[i]] = dis[u] + w[i];
            q.push(data(to[i], dis[to[i]]));
        }
    }
}
signed main()
{
    scanf("%lld%lld",&n,&m);
    Build(ra, 1, n, 1); Build(rb, 1, n, 0); Add(ra, rb, 1, n);
    for(int i = 1;i <= m; ++i)
	{
       int a,b;
		int ww;
		scanf("%lld%lld%lld",&a,&b,&ww);
        Link(a, b, a, b,ww);
    }
    Dij();
	if(dis[pos[n]]>=inf)
		printf("-1");
	else
		printf("%lld\n", dis[pos[n]]);
    return 0;
}


Measured memory_bytes: 115444
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

ll AN (ll A, ll N){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0){
      return AN(A * A % nmax, N / 2) % nmax;
    }else{ 
      return AN(A * A % nmax, N / 2) % nmax * A % nmax;
    }
  }
}

int main(){
  ll N; cin >> N;
  vector <ll> C(N);
  for (int i = 0; i < N; i++) cin >> C[i];
  sort(C.begin(), C.end());

  ll ans = 0;
  for (ll i = 0; i < N; i++){
    ll now = AN(2, N - 1);
    now *= (N + 1 - i); now %= nmax;
    now *= AN(2, N - 1); now %= nmax;
    now *= C[i]; now %= nmax;
    ans += now; ans %= nmax;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;
long long int n,k,p[5002];
long long int ans=-1000000000000,c[5002];
int main()
{
 scanf("%lld %lld",&n,&k);
 for(long long int i=1;i<=n;i++)
 {
	scanf("%lld",&p[i]);
 }
 for(long long int i=1;i<=n;i++)
 {
	scanf("%lld",&c[i]);
 }
 for(long long int i=1;i<=n;i++)
 {
	long long int nw=i;
	long long int lpt=0;
	long long int lpsx=0;//lpt:ループを回すのに必要な回数 lpsx:ループを回したときのスコア
	for(;;)
	{
		lpt++;
		nw=p[nw];lpsx+=c[nw];
		if(nw==i){break;}
	}
	long long int lpc;//ループを回す回数
	if(lpsx>=0){lpc=k/lpt;}
	else{lpc=0;}
	long long int scr=0;
	scr=lpc*lpsx; //ループ部分でのスコア
	long long int kz=k-lpc*lpt; //kzは残り動ける回数、この中で得点を最大化する。
	long long int zw=-100000000000,zn=0;
	long long int mv=0;
	if(lpc==0)
	{
	for(long long int l=1;l<=min(kz,lpt);l++)
	{
		nw=p[nw];zn+=c[nw];
		if(zw<zn){mv=l; zw=zn;}
	}
	}
	else
	{
	scr-=lpsx; kz+=lpt;
	for(long long int l=1;l<=kz;l++)
	{	
		nw=p[nw];zn+=c[nw];
		if(zw<zn){mv=l; zw=zn;}
	}
	zw=max(zw,0LL);
	}
	scr+=zw;
	ans=max(ans,scr);
 }
 printf("%lld",ans);
}



Measured memory_bytes: 3916
a,b,m=map(int,input().split())

A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[list(map(int,input().split())) for i in range(m)]

lis=[min(A)+min(B)]

for i in range(m):
    lis.append(A[C[i][0]-1]+B[C[i][1]-1]-C[i][2])

print(min(lis))


Measured memory_bytes: 42528
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  string s; cin >> s;
  vector<ll> cntr(n+1), cntg(n+1), cntb(n+1);
  for (int i = n-1; i >= 0; i--) {
    cntr[i] = cntr[i+1];
    cntg[i] = cntg[i+1];
    cntb[i] = cntb[i+1];
    if (s[i] == 'R') cntr[i]++;
    if (s[i] == 'G') cntg[i]++;
    if (s[i] == 'B') cntb[i]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) continue;
      ll v;
      char c;
      if (s[i] == 'R' && s[j] == 'G') {v = cntb[j+1];c='B';}
      if (s[i] == 'G' && s[j] == 'R') {v = cntb[j+1];c='B';}
      if (s[i] == 'R' && s[j] == 'B') {v = cntg[j+1];c='G';}
      if (s[i] == 'B' && s[j] == 'R') {v = cntg[j+1];c='G';}
      if (s[i] == 'B' && s[j] == 'G') {v = cntr[j+1];c='R';}
      if (s[i] == 'G' && s[j] == 'B') {v = cntr[j+1];c='R';}
      ans += v;
      if (2 * j - i < n && s[2 * j - i] == c) ans--;
    }
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 3268
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

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

    int n; cin>>n;
    vector<vector<int>> a(n, vector<int>(n));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++) cin>>a[i][j];
    }

    vector<ll> score((1<<n), 0);
    for(int bit=0; bit<(1<<n); bit++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if((bit & (1 << i)) && (bit & (1 << j))){
                    score[bit] += a[i][j];
                }
            }
        }
        score[bit] /= 2;
    }

    vector<ll> dp((1<<n), 0);
    for(int bit=0; bit<(1<<n); bit++){
        int unused = bit ^ ((1 << n) - 1);
        for(int cur=unused; cur>0; cur=(cur-1)&unused){
            chmax(dp[bit | cur], dp[bit] + score[cur]);
        }
    }

    cout << dp[(1<<n)-1] << endl;

    return 0;
}

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

int main(void) {
    int N,M;cin>>N>>M;
    int target[M];
    vector<int> score(N+1,0);
    for (int i = 0; i < M; i++) cin>>target[i];
    for (int i = 0; i < M; i++) {
        int tmp = 0;
        for (int j = 1; j <= N; j++) {
            int B;cin>>B;
            if (j == target[i]) score[j] += 1;
            else {
                if (B == target[i]) score[j] += 1;
                else tmp++;
            }
        }
        score[target[i]] += tmp;
    }
    for (int i = 1; i <= N; i++) cout << score[i] << endl;
    return 0;
}


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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  string result;
  if((abs(a - b) <= d && abs(b - c) <= d) ||
    abs(a - c) <= d) {
    result = "Yes";
  } else {
    result = "No";
  }

  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 384