akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n, m int
	n, m = nextInt(), nextInt()
	Ac, Wa := make(map[int]bool, n+1), make([]int, n+1)
	Acount, Wcount := 0, 0
	for i := 0; i < m; i++ {
		p, s := nextInt(), nextStr()
		if Ac[p] {
			continue
		}
		if s == "AC" {
			Ac[p] = true
			continue
		}
		Wa[p]++
	}
	for i := 1; i <= n; i++ {
		if Ac[i] {
			Acount++
			Wcount += Wa[i]
		}
	}
	fmt.Println(Acount, Wcount)
}

func init() {
	const max = 1024
	var buf = make([]byte, max)
	sc.Buffer(buf, max)
	sc.Split(bufio.ScanWords)
	return
}

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


Measured memory_bytes: 4472
# coding: utf-8
# Your code here!

# ITP1_7_A


def judge(point,re_exam_point):
    if point>=80:
        return "A"
    elif 65 <= point < 80:
        return "B"
    elif 50 <= point < 65:
        return "C"
    elif 30 <= point < 50:
        if re_exam_point >= 50:
            return "C"
        return "D"
    else:
        return "F"
        
while(True):
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    if m==-1 or f==-1:
        print("F")
    else:
        total=m+f
        print(judge(total,r))
    
    
    
    
    


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;

int main() {
    ll n,x,y;
    cin >> n >> x >> y;
    x--; y--;
    vector<ll> data(n,0);
    for(ll i=0; i<n; i++){
        for(ll j=i+1; j<n; j++){
            ll sayuri=min(j-i,abs(x-i)+abs(y-j)+1);
            data.at(sayuri)++;
        }
    }

    rep(i,n){
        if(i==0) continue;
        cout << data.at(i) << endl;
    }
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

bool cmp(string &a,string &b) {return a+b<b+a;}

void solve(int test_case) {//209
	string s;
	int k;
	cin>>s>>k;
	int n = s.length();
	unordered_set<string> arr;
	REP(i,0,n-1) {
		for(int j=1;j<=k&&i+j-1<n;j++) {
			arr.insert(s.substr(i,j));
		}
	}
	vector<string> v;
	for(auto i:arr)v.PUB(i);
	sort(v.begin(),v.end());//, cmp);
	cout<<v[k-1];
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 4964
h1, m1, h2, m2, k = map(int, input().split())
if m2 >= m1:
    print((h2 - h1) * 60 + (m2 - m1) - k)
else:
    print((h2-1 - h1) * 60 + (m2 + 60 - m1) - k)

Measured memory_bytes: 9160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  string a,b ;cin >> a >> b ;

  if(a.size() != b.size()){
    if(a.size() > b.size()) cout << "GREATER" << endl;
    else cout << "LESS" << endl;
  }
  else{
    rep(i,a.size()){
      if(a[i] > b[i]){
	cout << "GREATER" << endl;
	return 0;
      }
      if(a[i] < b[i]){
	cout << "LESS" << endl;
	return 0;
	  
      }
    }
    cout << "EQUAL" << endl;
  }

  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    int n = s.size() + 1;
    vector<int> a(n, 0);
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == '<') {
            a[i + 1] = a[i] + 1;
        } else {
            while (i + 1 < n - 1 && s[i + 1] != '<') {
                i++;
            }

            for (int j = i; j >= 0 && s[j] != '<'; j--) {
                a[j] = max(a[j], i - j + 1);
            }
        }
    }

    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += a[i];
    }

    cout << res << endl;
}


Measured memory_bytes: 2820
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	string s;
	cin >> s;

	int cnt = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s.substr(i, 2) == "OX" || s.substr(i, 2) == "XO")
		{
			cnt++;
			i++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T& x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define pb push_back
#define fs first
#define sc second
#define MOD 1000000007
#define MOD2 998244353
#define INF 1000000000000000000ll
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

void solve()
{
    string s, t;
    cin >> s >> t;
    ll mn = INF;
    rep(i,0,s.size() - t.size()+1)
    {
        ll cnt = 0;
        rep(j,0,t.size())
        {
            if(s[i+j] != t[j])
            {
                cnt++;
            }
        }
        mn = min(mn, cnt);
    }
    cout << mn << endl;
}

int main()
{
    cin.sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	/*ll t;
	cin >> t;
	while(t--)*/
		solve();
}


Measured memory_bytes: 3632
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
static const int COUNTER_CLOCKWISE = 1,CLOCKWISE = -1,ONLINE_BACK = 2,ONLINE_FRONT = -2,ON_SEGMENT = 0;
//???
class Point{
	public:	
		double x,y;
		Point(double x = 0,double y = 0):x(x),y(y){}
		//?????????
		Point operator + (Point p) { return Point(x + p.x,y + p.y);}
		Point operator - (Point p) { return Point(x - p.x,y - p.y);}
		Point operator * (double a) { return Point(x*a,y*a);}
		Point operator / (double a) { return Point(x/a,y/a);}
		//???????????¨??§??????
		double abs() {return sqrt(norm());}
		double norm() {return x*x+y*y;}

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}
		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};
//??????
struct Segment{Point p1,p2;};
//????????????
typedef Point Vector;
//??´???
typedef Segment Line;
//???
class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(),double r = 0.0): c(c),r(r){}
};
//????§???¢
//typedef Vector<Point> Polygon;
//????????¨??????
double dot(Vector a,Vector b){
	return a.x*b.x + a.y*b.y;
}
double cross(Vector a,Vector b){
	return a.x*b.y - a.y*b.x;
}

int check(Point p0,Point p1,Point p2){
	Vector v1 = p1 - p0;
	Vector v2 = p2 - p0;
	if(cross(v1,v2) > EPS){
		return COUNTER_CLOCKWISE;
	}
	if(cross(v1,v2) < -EPS){
		return CLOCKWISE;
	}
	if(dot(v1,v2) < -EPS){
		return ONLINE_BACK;
	}
	if(v1.norm() < v2.norm()){
		return ONLINE_FRONT;
	}

	return ON_SEGMENT;
}

bool intersect(Point p0,Point p1,Point p2,Point p3){
	return (check(p0,p1,p2)*check(p0,p1,p3) <= 0 && check(p3,p2,p0)*check(p3,p2,p1) <= 0);
}



int main(){
	int n;
	cin >> n;
	Point p0,p1,p2,p3;
	for(int i = 0;i < n;i++){
		cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
		if(intersect(p0,p1,p2,p3)){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
num = int(input())

n = 26
nl = [26**i for i in range(1,12)]

for i in range(12):
    if num <= sum(nl[:i]):
        break
maxpower = i
num = num - sum(nl[:i-1])-1

lst = []
for i in range(maxpower-1, 0, -1):
    lst.append(num // (26**i))
    num = num % (26**i)
lst.append(num)

letters = 'abcdefghijklmnopqrstuvwxyz'

result = ''

for i in lst:
    result += letters[i]

print(result)


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

using namespace std;

using int64 = long long;

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector< int > ev[501];
  for(int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    ev[x].push_back(y);
  }
  for(int i = 0; i <= N; i++) {
    sort(begin(ev[i]), end(ev[i]));
  }
  for(int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    int ret = 0;
    for(int j = x; j <= y; j++) {
      ret += upper_bound(begin(ev[j]), end(ev[j]), y) - begin(ev[j]);
    }
    cout << ret << endl;
  }
}







Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}

int main() {
    ll n;
    cin>>n;
    vector<ll> v;
    rep(i, n) {
        ll y;
        cin>>y;
        if(i == 0) v.push_back(y);
        else{
            if(v.back() != y) v.push_back(y);
        }
    }
    unordered_map<ll, ll> m;
    vector<ll> ans(v.size(), 0);
    rep(i, v.size()) {
        auto arg = v[i];
    
        if(i==0) {
            m[arg] = i+1;
            continue;
        }
        ans[i] = ans[i-1];
        if(m[arg] > 0){
            ll y = (ans[m[arg]-1] +1) % 1000000007;
            ans[i] += y;
            ans[i] %= 1000000007;
        }
        m[arg] = i+1;
    }
    pr( (ans[v.size() -1] + 1) % 1000000007 );



    return 0;
}



Measured memory_bytes: 14320
"use strict"
let fs = require('fs');
let input = fs.readFileSync("/dev/stdin", "utf8").split(/\n/);
 
const N = +input[0];
let currentCoordinate = { x: 0, y: 0 };
let currentTime = 0;
let ans = 'Yes';
 
for(let i=1; i<=N; i++ ) {
  const row = input[i].split(' ');
  const t = +row[0] - currentTime;
  let move = Math.abs( +row[1] - currentCoordinate.x) + Math.abs(+row[2] - currentCoordinate.y);
  if( !( t >= move && (t - move) % 2 === 0) ) {
    ans = 'No';
    break;
  }
  currentCoordinate = { x: +row[1], y: +row[2] };
  currentTime += t;
}
 
console.log(ans);

Measured memory_bytes: 28792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if (A + B < 2*C) {
        cout << A * X + B * Y << endl;
    }
    else {
        if (X < Y) {
            int ans1 = 2 * Y*C;
            int ans2 = 2 * X*C + (Y - X)*B;
            cout<<min(ans1, ans2)<<endl;
        }
        else {
            int ans3 = 2 * X*C;
            int ans4 = 2 * Y*C + (X - Y)*A;
            cout<<min(ans3, ans4);
        }
    }
    return 0;
}


Measured memory_bytes: 3524
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;
typedef pair<int, int> P;

int n;
int l[200005], r[200005];
vector<P> vec;
vector<int> lvec, rvec;

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> l[i] >> r[i], r[i]--;
	
	for(int i = 1; i <= n; i++){
		lvec.push_back(l[i]);
		rvec.push_back(r[i]);
	}
	sort(lvec.begin(), lvec.end());
	sort(rvec.begin(), rvec.end());
	
	int ans = 0, tmp;
	for(int i = 1; i <= n; i++){
		tmp = lower_bound(rvec.begin(), rvec.end(), l[i]) - rvec.begin();
		tmp += lvec.end() - upper_bound(lvec.begin(), lvec.end(), r[i]);
		ans = max(ans, n - tmp);
	}
	
	for(int i = 1; i <= n; i++){
		vec.push_back(make_pair(l[i], 1));
		vec.push_back(make_pair(r[i], 2));
	}
	sort(vec.begin(), vec.end());
	
	int ans2 = 0, cnt = 0;
	for(int i = 0; i < vec.size(); i++){
		if(vec[i].second == 1) cnt++;
		if(vec[i].second == 2) cnt--;
		ans2 = max(ans2, cnt);
	}
	
	cout << ans << " " << ans2 << endl;
	return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

int32_t main() {

    int n, m; cin >> n >> m;
    vector<pair<int, int>> keys(m);
    for(int i = 0; i < m; ++i) cin >> keys[i].first >> keys[i].second;

    int maxstart = 0, minend = n;
    for(auto p : keys) {
        maxstart = max(maxstart, p.first);
        minend = min(minend, p.second);
    }

    int ans = max(0, minend-maxstart+1);

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1024
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Mod(I []int, P int) int {
  N := 0
  for _, i := range I {
    N = N * 10 + i
    N %= P
  }
  return N
}

func Solve() {
  var N int
  NextInt(&N)
  T := make([][]int, N)
  for i := range T {
    T[i] = make([]int, 0)
  }
  var a, b int
  for i := 1; i < N; i++ {
    NextInt(&a, &b)
    a, b = a - 1, b - 1
    T[a] = append(T[a], b)
    T[b] = append(T[b], a)
  }
  D := make([]int, N)
  D[0] = 1
  pos := 1
  OE := make([]int, 2)
  Q := make([]int, N)
  for _, q := range Q {
    OE[D[q] % 2]++
    for _, adj := range T[q] {
      if 0 < D[adj] { continue }
      D[adj] = D[q] + 1
      Q[pos] = adj
      pos++
    }
  }
  A := make([]int, N)
  k1, k2, k3 := 0, 0, 0
  for i, d := range D {
    if d % 2 == 1 {
      if OE[1] <= N / 3 {
        A[i] = 3 * k3 + 3
        k3++
      } else if 3 * k1 + 1 <= N {
        A[i] = 3 * k1 + 1
        k1++
      } else if OE[0] <= N / 3 && 3 * k2 + 2 <= N {
        A[i] = 3 * k2 + 2
        k2++
      } else {
        A[i] = 3 * k3 + 3
        k3++
      }
    } else {
      if OE[0] <= N / 3 {
        A[i] = 3 * k3 + 3
        k3++
      } else if OE[1] <= N / 3 && 3 * k1 + 1 <= N {
        A[i] = 3 * k1 + 1
        k1++
      } else if 3 * k2 + 2 <= N {
        A[i] = 3 * k2 + 2
        k2++
      } else {
        A[i] = 3 * k3 + 3
        k3++
      }
    }
  }
  WriteIntVec(A)
}

func main() {
  Solve()
  Output()
}

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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

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<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  while(true){
    int D,E;
    cin>>D>>E;
    if(!(D|E))return;
    double res=1000000;
    rep(i,D+1)
          chmin(res,abs(sqrt(i*i+(D-i)*(D-i))-E));
    cout<<res<<endl;
  }
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


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

ll sum[100050],psum[100050];

ll part(int l, int r){
  return sum[r] - sum[l];
}
ll partp(int l, int r){
  return psum[r] - psum[l];
}

int main(){
  int N,K; cin>>N>>K;
  vector<ll> a(N);
  for(int i=0;i<N;i++) cin>>a[i];
  for(int i=0;i<N;i++)
    sum[i+1] = sum[i] + a[i];
  for(int i=0;i<N;i++){
    if(a[i] > 0) psum[i+1] = psum[i] + a[i];
    else psum[i+1] = psum[i];
  }
  ll ans = 0;
  for(int i=0;i+K<=N;i++){
    ll tmp = partp(0,i) + partp(i+K,N);
    ll b = part(i,i+K);
    if(b > 0) tmp += b;
    if(ans < tmp) ans = tmp;
  }
  cout<<ans<<endl;
  return 0;
}


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

#define int long long int 

int32_t main()
{

    int n,x;
    cin>>n>>x;
    int cor[n];
    for(int i=0;i<n;i++)
    {cin>>cor[i];cor[i]=abs(cor[i]-x);}
    if(n==1)
    {
        cout<<cor[0]<<endl;
        return 0;
    }

    int gcd=__gcd(cor[0],cor[1]);
    for(int i=2;i<n;i++)
    gcd=__gcd(gcd,cor[i]);
    cout<<gcd<<endl;
}

Measured memory_bytes: 4408
#include<stdio.h>

int main(void)
{
	int N;
	scanf("%d", &N);
	int W[N];
	int sum[N];
	int sum2[N];
	int sub[N];
	int min;

	for(int i = 0; i < N; i++){
		W[i] = 0;
		scanf("%d", &W[i]);
	}

	for(int j = 1; j < N; j++){
		sum[j] = 0;
		sum2[j] = 0;
		for(int i = 0; i < j; i++){
			sum[j] += W[i];
		}
		for(int i = N-1; i >= j; i--){
			sum2[j] += W[i];
		}
	}

	for(int i = 1; i < N; i++){
		sub[i] = 0;
		sub[i] = sum[i] - sum2[i];
		if(sub[i] < 0){
			sub[i] = -(sub[i]);
		}
	}

	min = sub[1];
	for(int i = 1; i < N; i++){
		if(sub[i] < min){
			min = sub[i];
		}
	}

	printf("%d\n", min);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


int n,m,cnt,a[N];
int main() {
	scanf("%d%d",&n,&m);
	REP(i,1,m) scanf("%d",a+i);
	int x=0,y=0,z=0;
	REP(i,1,m) if (a[i]&1) {
		if (!x) x=i;
		else if (!y) y=i;
		else if (!z) z=i;
	}
	if (z) return puts("Impossible"),0;
	vector<int> v;
	if (m==1) {
		printf("%d\n",a[1]);
		if (a[1]!=1) v.pb(a[1]-1);
		v.pb(1);
	}
	else if (!x) {
		REP(i,1,m) printf("%d ",a[i]);hr;
		v.pb(a[1]-1);
		REP(i,2,m-1) v.pb(a[i]);
		v.pb(a[m]+1);
	}
	else if (!y) {
		printf("%d ",a[x]),v.pb(a[x]+1);
		REP(i,1,m) if (i!=x) printf("%d ",a[i]),v.pb(a[i]);
		--v.back(),hr;
	}
	else {
		printf("%d ",a[x]),v.pb(a[x]+1);
		REP(i,1,m) if (i!=x&&i!=y) printf("%d ",a[i]),v.pb(a[i]);
		printf("%d\n",a[y]);
		if (a[y]>1) v.pb(a[y]-1);
	}
	printf("%d\n",(int)v.size());
	for (int t:v) printf("%d ",t);hr;
}


Measured memory_bytes: 256
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
S = int(input())

lis = [0,S]

for i in range(2,1000000+1):
    if lis[i-1]%2==0:
        num = lis[i-1]//2
    if not lis[i-1]%2==0:
        num = 3*lis[i-1]+1
    if num in lis:
        ans = i
        break
    lis.append(num)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 3060
N=input()
if int(N[-1])==2 or int(N[-1])==4 or int(N[-1])==5 or int(N[-1])==7 or int(N[-1])==9:
    print('hon')
elif int(N[-1])==0 or int(N[-1])==6 or int(N[-1])==1 or int(N[-1])==8:
    print('pon')
else :
    print('bon')


Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;

typedef pair<int, int> P;
struct edge { int v, w; };

vector<int> dijkstra(int N, vector<vector<edge>>& G, int s) {
	vector<int> d(N, inf);
    d[s] = 0;
	priority_queue<P,vector<P>,greater<P>> Q;
	Q.push(P(0, s));
	while (!Q.empty()){
		P p = Q.top();
        Q.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (edge e: G[u]){
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				Q.push(P(d[e.v], e.v));
			}
        }
	}
	return d;
}

signed main() {
	int N;
    cin >> N;
	vector<vector<edge> > G(N);
	for(int i=0;i<N-1;i++){
		int u,v,w;
        cin>>u>>v>>w;
		u--, v--;
		G[u].push_back(edge{v,w});
		G[v].push_back(edge{u,w});
	}
	int Q,x;
    cin>>Q>>x;
	x--;
	vector<int> d = dijkstra(N, G, x);
	for(int i=0;i<Q;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        cout<<d[u]+d[v]<<endl;
	}
}


Measured memory_bytes: 11120
#include <cstdio>
#include <algorithm>
int main() {
    int a, b, c;
    int cnt = 0;
    scanf("%d %d %d", &a, &b, &c);
	for (int i = a; i <= b; i++) {
        if (c % i == 0) cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 2756
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = map(int, input().split())
a = list(map(int, input().split()))

dp = [0]*(k+1)
cum = [1]*(k+2)
M = 10**9+7
dp[0] = 1
cum[0] = 0
for i in range(1,n+1):
    current = [0]*(k+2)
    for j in range(k+1):
        dp[j] = (cum[j+1] - cum[max(0, j-min(k,a[i-1]))]) % M
        current[j+1] = (current[j] + dp[j])%M
    cum = current
print(dp[k])

Measured memory_bytes: 150484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  string s,t;
  cin>>s>>t;
  ll ans=0;
  rep(i,s.size()){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3920
#include<bits/stdc++.h>
#include <unordered_map>
#define int long long int
#define double long double
#define endl "\n"
#define PI 3.141592653589793238462643383279502884
#define sp(x)   setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define LCM(a,b)    (a*b)/__gcd(a,b)
#define all(v)  v.begin(),v.end()
#define alls(s,v)  s.begin(),s.end(),v
#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)
#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)
#define base ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define exit return 0;
using namespace std;
const int N=1000000;
bool prime[N];
void sieve()
{
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<100000000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<100000; i += p)
                prime[i] = false;
        }
    }
}
int power(int x, int y)
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x*x;
    }
    return res;
}
int nxt()
{
    int x;
    cin >> x;
    return x;
}
int findTileCount(int x, int y, int l, int r)
{
    int lcm = (x * y) / __gcd(x, y);
    int countl = (l - 1) / lcm;
    int countr = r / lcm;
    return countr - countl;
}
int32_t main()
{
    base
    string s;
    cin >> s;
    for (int i = 0; i < s.size()-1; ++i)
    {
        if (s[i] == s[i + 1])
        {
            cout << i + 1 << ' ' << i + 2 <<endl;
            return 0;
        }
    }
    for (int i = 0; i < s.size() - 2; ++i)
    {
        if (s[i] == s[i + 2])
        {
            cout << i + 1 << ' ' << i + 3 <<endl;
            return 0;
        }
    }
    cout << "-1 -1" <<endl;
    exit
}



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll A, B;

signed main()
{
    cin >> A >> B;
    ll ans = A;
    if(B < A) { ans--; }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
from collections import deque

def main():
    K = int(input())
    
    # bfs
    count = 0
    q = deque(range(1, 10))
    while count < K-1:
        now = q.popleft()
        count += 1

        d1 = now % 10
        base = 10 * now
        for suffix in [d1 - 1, d1, d1 + 1]:
            if suffix not in [-1, 10]:
                new = base + suffix
                q.append(new)

    ans = q.popleft()
    print(ans)
    

if __name__ == "__main__":
    main()

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

int main(){

    int n;
    cin >> n;

    int L[n];
    int l;
    int i=0;
    int max_l = 0;
    int total = 0;

    while(cin >> l){
        L[i] = l;
        i++;
        if(l > max_l){
            max_l = l;
        }
        total = total + l;
    }

    if(max_l < (total - max_l)){
        cout <<"Yes"<<endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
    int main(){
     long int X,z;
      z=100;
      int i;
      scanf("%ld",&X);
      for(i=1;i<4000;i++){
        z= z+ z/100;
        if(z>=X){
          printf("%d",i);
        	break;
        }
      }
       
       
      return 0;
    }

Measured memory_bytes: 1736
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
double eps=1e-12;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

void nckinit(ll n,ll md){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=md;
  }
  gya[n]=gyaku(kai[n],md);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=md;
  }
  gya[0]=1;
}
ll nck(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  ret*=gya[k];
  ret%=md;
  return ret;
}
ll npk(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int ma=1000000000;
    int ans=0;
    rep(i,0,n){
        int p;cin>>p;
        if(p<=ma){
            ans++;
        }
        ma=min(ma,p);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 384
#include <iostream>

int main() {
  int x, y;
  while (true) {
    std::cin >> x >> y;
    if (x == 0 && y == 0) break;
    
    if (x > y) std::cout << y << " " << x << std::endl;
    else std::cout << x << " " << y << std::endl;

  }
  return 0;
}


Measured memory_bytes: 2988
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	let c = v[2];
	if a+b < c {
		println!("No");
	}else{
		println!("Yes");
	}
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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; }

double p[1010],maxi=0,now=0;
int N,K,cnt=0;

int main(){
    cin>>N>>K;
    int A[N];
    p[0]=0;
    rep(i,N)cin>>A[i];
    repi(i,1,1005)p[i]=p[i-1]+i;
    repi(i,1,1005)p[i]/=i;
    rep(i,N){
        if(i<K){
            now+=p[A[i]];
        }
        else{
           now-=p[A[i-K]]; 
           now+=p[A[i]];
        }
        maxi=max(maxi,now);
    }
    printf("%.12f\n",maxi);

    
    
}

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

int main(){
	int N;
	cin>>N;
	int p[5000];
	for(int i=0;i<N;i++){
		cin>>p[i];
	}
	int min_sum=20000;
	for(int I=0;I<=p[0];I++){
		int q[5000];
		for(int i=0;i<N;i++){
			q[i]=p[i];
		}
		int sum=I;
		q[0]-=I;
		for(int i=0;i<=N-2;i++){
			if(q[i]<=0){
				continue;
			}
			sum+=q[i]*2;
			q[i+1]-=q[i];
		}
		if(q[N-1]>0){
			sum+=q[N-1];
		}
		min_sum=min(min_sum,sum);
	}
	cout<<min_sum<<endl;

	return 0;
}

Measured memory_bytes: 3140
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())

flag = [[False] * 3 for i in range(3)]
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                flag[j][k] = True

ans = False
for i in range(3):
    if sum(flag[i]) == 3:
        ans = True

flag_t = [list(x) for x in zip(*flag)]
for i in range(3):
    if sum(flag_t[i]) == 3:
        ans = True

if flag[0][0] and flag[1][1] and flag[2][2]:
    ans = True
if flag[0][2] and flag[1][1] and flag[2][0]:
    ans = True

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


// a,bの最小公倍数
ll lcm(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll gcd(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}
// MOD
ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}


int main(){


    int n;
    cin >> n;
    int t[n], x[n], y[n];
    rep(i,n) cin >> t[i] >> x[i] >> y[i];

    bool flag = true;
    rep(i,n) {
        if (x[i] + y[i] <= t[i] && (t[i] - x[i] - y[i]) % 2 == 0) {
            ;
        }
        else flag = false;
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;



}



//              g++ -std=c++1z


Measured memory_bytes: 1408
import java.util.*;

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

    int sumMin = N ;
    int[] digitA = new int[5];
    int[] digitB = new int[5];

    for(int A = 1 ; A < N ;A ++){
      int sum = 0;
      int B = N - A ;

      digitA[ 4 ] = A / 10000 ;
      digitA[ 3 ] = ( A % 10000 ) / 1000 ;
      digitA[ 2 ] = ( A %  1000 ) / 100  ;
      digitA[ 1 ] = ( A %  100  ) / 10   ;
      digitA[ 0 ] =   A %  10  ;

      digitB[ 4 ] = B / 10000 ;
      digitB[ 3 ] = ( B % 10000 ) / 1000 ;
      digitB[ 2 ] = ( B %  1000 ) / 100  ;
      digitB[ 1 ] = ( B %  100  ) / 10   ;
      digitB[ 0 ] =   B %  10  ;

      for(int i = 0 ; i < 5 ; i ++){
        sum = sum + digitA[i] + digitB[i] ;
      }
      if(sum < sumMin ){
        sumMin = sum ;
      }
    }
    System.out.println(sumMin);
  }
}


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

string LCS(vector <vector <int>>&dp,string s,string t,int n,int m)
{
	if(n==0 || m==0)
		return "";
	if(s[n-1]==t[m-1])
		return  LCS(dp,s,t,n-1,m-1)+s[n-1];
	else
	{
		if(dp[n-1][m]>dp[n][m-1])
			return LCS(dp,s,t,n-1,m);
		else
			return LCS(dp,s,t,n,m-1);
	}
}
void solve()
{
	string s;
	string t;
	cin>>s;
	cin>>t;
	int i,j,n=s.length(),m=t.length();
	vector <vector <int>>dp(n+1,vector <int>(m+1,0));
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	cout<<LCS(dp,s,t,n,m);

}
int main()
{

	solve();
}

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

int main() {
  ios::sync_with_stdio(false);
  int N, a;
  cin >> N;
  map<int, int> MA;
  while (cin >> a) MA[a]++;

  int ans = 0;

  for (auto ma : MA) {
    if (ma.first > ma.second) ans += ma.second;
    else ans += ma.second - ma.first;
  }

  cout << ans << "\n";
}

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

typedef pair< int , int > P;
struct Edge {
  int to,cost;
  Edge(){}
  Edge(int to,int cost):to(to),cost(cost){};
};
vector< vector< Edge > > Graph;
int V,E;
int prim(){
  int total = 0;
  vector< bool > used(Graph.size(),false);
  priority_queue< P,vector< P >,greater< P > > que;
  que.push(P(0,0));
  while(!que.empty()){
    int cost = que.top().first;
    int now = que.top().second;
    que.pop();
    if(used[now]) continue;
    used[now] = true;
    total += cost;
    for(int i=0;i<Graph[now].size();i++){
      que.push(P(Graph[now][i].cost,Graph[now][i].to));
    }
  }
  return total;
}

int main(){
  cin >> V >> E;
  Graph.resize(V+1);
  for(int i=0;i<E;i++){
    int s,t,d;
    cin >> s >> t >> d;
    Graph[s].push_back(Edge(t,d));
    Graph[t].push_back(Edge(s,d));
  }
  cout << prim() << endl;
}

Measured memory_bytes: 6048
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

void chmin(int &a, int b) { a = min(a, b); }

int n;
char c[4000]; int a[4000];
int posW[2001];
int posB[2001];
int cntW[4001][2001];	//cntW[i][j] = 先頭i文字を取り除いたとき、j以下の白いボールはいくつあるか？
int cntB[4001][2001];
int dp[2001][2001];		//dp[白][黒] = 反転数の最小値
int INF = 1e+7;

int main() {
	int i, j;
	
	cin >> n;
	rep(i, 2 * n) {
		cin >> c[i] >> a[i];
		if (c[i] == 'W') { posW[a[i]] = i; cntW[i][a[i]]++; }
		if (c[i] == 'B') { posB[a[i]] = i; cntB[i][a[i]]++; }
	}
	
	rep(i, 2 * n + 1) {
		rep(j, n) cntW[i][j + 1] += cntW[i][j];
		rep(j, n) cntB[i][j + 1] += cntB[i][j];
	}
	
	rep(j, n + 1) {
		rrep(i, 2 * n) cntW[i][j] += cntW[i + 1][j];
		rrep(i, 2 * n) cntB[i][j] += cntB[i + 1][j];
	}

	rep(i, n + 1) rep(j, n + 1) dp[i][j] = INF;
	dp[0][0] = 0;
	
	rep(i, n + 1) {
		rep(j, n + 1) {
			if (i < n) {
				chmin(dp[i + 1][j], dp[i][j] + cntW[posW[i + 1] + 1][i] + cntB[posW[i + 1] + 1][j]);
			}
			if (j < n) {
				chmin(dp[i][j + 1], dp[i][j] + cntW[posB[j + 1] + 1][i] + cntB[posB[j + 1] + 1][j]);
			}
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 78464
#include<bits/stdc++.h>
using namespace std;
const int N=200006;
int T,a,b,c,d,n;
char s[N];
bool fl;
int main(){
	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s+1);
	s[n+1]=s[n+2]=s[n+3]='#';
	s[b]='#',fl=1;
	for (;(a<c || b<d) && fl;){
		while (a<c && a<b-1){
			if (a+2<b && a+2<=c && s[a+1]=='#' && s[a+2]!='#') a+=2;
			else if (a+1<b && a+1<=c && s[a+1]!='#') a++;
			else break;
		}
		if (c>d && a==b-1 && a+2<=c && s[a+2]!='#') a+=2,swap(a,b),swap(c,d);
		if (a==c && b==d) break;
		s[b]='.';
		if (b+2<=d && s[b+1]=='#' && s[b+2]!='#') b+=2,s[b]='#';
		else if (b+1<=d && s[b+1]!='#') b++,s[b]='#';
		else fl=0;
	}
	if (a!=c || b!=d) fl=0;
	puts(fl?"Yes":"No");
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int main(){
  string s;
  int cnt = 0,ma=0;
  cin >> s;
  int n = s.size();
  for(int i=0; i<n; i++){//開始地点
    for(int j=1; j<=n-i; j++){//文字数
      if(s[i+j-1]=='A'||s[i+j-1]=='C'||s[i+j-1]=='G'||s[i+j-1]=='T'){
        ma = max(ma,j);
      }else{
        break;
      }
    }
  }
  cout << ma << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,j,k,h;
    cin>>n;
    vector<int>dp(3);
    vector<int>c(3);
    int i;
    for(i=0;i<n;i++)
    {
        vector<int>new_dp(3,0);
        for(j=0;j<3;j++)
        cin>>c[j];
        for(k=0;k<3;k++)
          for(h=0;h<3;h++)
            if(h!=k)
              new_dp[h]=max(new_dp[h],dp[k]+c[h]);
    
        dp=new_dp;
    }
    cout<<max(dp[0],max(dp[1],dp[2]))<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    int n,x;
    cin>>n;
    int cnt=0;

    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x&1 and i&1) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

int main(void){
    ll N; cin >> N;
    vector<ll> a(N,0); for(int i = 0; i < N; i++) cin >> a.at(i);
    
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(a[i] % 2 == 0){
            while(a[i] %2 == 0){
                a[i] /= 2;
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    long t;
    int[] as;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        t = sc.nextLong();
        as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        int max = as[n - 1];
        int maxProfit = 0;
        int maxProfitCount = 0;
        for (int i = n - 2; i >= 0; i--) {
            int tempMaxProfit = max - as[i];
            if (tempMaxProfit > maxProfit) {
                maxProfit = tempMaxProfit;
                maxProfitCount = 1;
            } else if (tempMaxProfit == maxProfit) {
                maxProfitCount++;
            }
            if (max < as[i]) {
                max = as[i];
            }
        }
        System.out.println(maxProfitCount);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
    if(A.size() == n+1){
        int now = 0;
        rep(i,q){
            if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    ans = 0;
    vector<int> A(1,1);
    dfs(A);
    cout << ans << endl;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    ll n,c=0;
    cin >> n;
    for(ll i=1;i<=n;i++){
        if(n%i!=0){
            c+=n/i;
        }else{
            c+=n/i-1;
        }
    }
    /*
}    
    if(n%2==1){
        for(ll i=1;i<=n/2+1;i++){
        rep1(j,n/2+1){
            if(i*j<n) c++;
            }
        }      
    }else{    
        for(ll i=1;i<=n/2;i++){
        rep1(j,n/2){
                if(i*j<n) c++;
        }
    }
}*/
    //for(ll i=n/2;i<n;i++) c++;
    cout << c << endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}
int main() {
  int n;
  int a, b;
  cin >> n;
  int ans;
  cin >> a >> b;
  ans = gcd(a, b);
  for (int i = 2; i < n; i++) {
    if (ans == 1) {
      break;
    }
    cin >> b;
    ans = gcd(ans, b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String line = in.readLine();
      int k = Integer.parseInt(in.readLine());

      int n = line.length();
      Set<String> set = new TreeSet<>();

      for(int i=0; i <= n; i++) {
        String s = "";
        for(int j=i; j<=n && j<=i+k; j++) {
          // if( (1&i>>j) == 1 )
            s = line.substring(i, j);
            set.add(s);
        }
      }

      // for(String s: set)
      //   System.out.println(s);

      Iterator<String> ite = set.iterator();
      String[] str = new String[k+1];
      for(int i=0; i<=k; i++)
        str[i] = ite.next();

      System.out.println(str[k]);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 24148