akhauriyash/Code-Regression huggingface dataset:
from collections import deque
import copy

S = list(input())
Q = int(input())
Q_list = [input().split() for i in range(Q)]

sn = 0
s = 0

Ans_list1 = deque([])

for k in range(len(S)):
    Ans_list1.append(S[k])

for j in range(Q):
    if Q_list[j][0] == "1":
        s += 1

if s % 2 == 1:
    Ans_list1.reverse()

Ans_list2 = copy.deepcopy(Ans_list1)

for i in range(Q):
    if Q_list[i][0] == "1":
        sn += 1
    else:
        if (sn % 2 == 0 and Q_list[i][1] == "1") or (sn % 2 == 1 and Q_list[i][1] == "2"):
            Ans_list1.appendleft(Q_list[i][2])
            Ans_list2.append(Q_list[i][2])
        else:
            Ans_list1.append(Q_list[i][2])
            Ans_list2.appendleft(Q_list[i][2])


if sn % 2 == 0:
    print(''.join(Ans_list1))
else:
    print(''.join(Ans_list2))


Measured memory_bytes: 48048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a;
    vector<long long>tap;
    for(int i=0;i<a;i++)
    {
        cin>>b;
        tap.push_back(b);

    }
    sort(tap.begin(),tap.end());
    long long dif,sz;
    sz=tap.size()-1;
    cout<<tap[sz]-tap[0];
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import exp, ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, e
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
import random
import time
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

start = time.time()

D = INT()
C = LIST()
s = [LIST() for _ in range(D)]

def decrease(d, j):  # d:日にち, j:開催するコンテスト
    tmp = 0
    for i in range(26):
        if i == j: continue
        tmp += C[i]*(d-last[i])
    return tmp 

def init():  # 貪欲でとった解を1度保存する
    global now
    for i in range(D):  # i+1日目
        ma = -INF
        ma_idx = None
        for j in range(26):  # 開催するコンテスト
            tmp = now
            tmp += s[i][j]
            tmp -= decrease(i+1, j)
            if tmp > ma:
                ma = tmp
                ma_idx = j
        now = ma
        last[ma_idx] = i+1
        score[ma_idx] += s[i][ma_idx]
        for j in range(26):
            score[j] -= C[j]*(i+1-last[j])
        last[ma_idx] = i+1
        ans[i] = ma_idx+1

def update(d, q):  # d日目のところをqに変更する
    d -= 1
    q -= 1
    c = ans[d]-1  # c:更新前
    ans[d] = q+1
    last_c = 0
    last_q = 0
    score_c = 0
    score_q = 0
    for j in range(D):
        if ans[j]-1 == c:
            last_c = j+1
            score_c += s[j][c]
        elif ans[j]-1 == q:
            last_q = j+1
            score_q += s[j][q]
        score_c -= C[c] * (j+1 - last_c)
        score_q -= C[q] * (j+1 - last_q)
    score[c] = score_c
    score[q] = score_q

def swap(d):  # d日目とd+1日目の開催を入れ替える
    update(d, ans[d])
    update(d+1, ans[d-1])

ans = [0]*D
last = [0]*26
score = [0]*26
now = 0

init()

TL = 1.8 - (time.time()-start)
start = time.time()
T0 = 2e3
T1 = 6e2
T = T0
randint = random.randint
rand = random.random
while 1:
    t = (time.time()-start)/TL
    if t >= 1:
        break
    T = pow(T0, 1-t)*pow(T1, t)
    if rand() < 0.5:  # 1点変更
        d = randint(1, D)
        q = randint(1, 26)
        old = ans[d-1]
        old_score = score.copy()
        s_old = sum(score)
        update(d, q)
        s_new = sum(score)
        if s_new <= s_old and exp((s_new-s_old)/T) <= rand():  # 戻す確率
            score = old_score
            ans[d-1] = old
    else:  # 2点入れ替え
        d = randint(1, D-1)
        old = ans[d-1]
        old_score = score.copy()
        s_old = sum(score)
        swap(d)
        s_new = sum(score)
        if s_new <= s_old and exp((s_new-s_old)/T) <= rand():
            score = old_score
            ans[d-1] = old

print(*ans, sep="\n")


Measured memory_bytes: 90884
#coding:utf-8

a = list(map(int,input().split()))
w = a[0]
h = a[1]
x = a[2]
y = a[3]

s = w*h

print(s/2,end='')

if min(x/w,1-x/w)==0.5 and min(y/h, 1-y/h)==0.5:
    print(" 1")
else:
    print(" 0")


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

#define xx first
#define yy second

const int N = 1e2 + 1;
const int W = 1e5 + 1;

int wt[N], v[N];
ll dp[W];

void solve() {
    int n, w; cin >> n >> w;
    for (int i = 0; i < n; i++)
        cin >> wt[i] >> v[i];
    fill(dp, dp + W, 0);
    for (int i = 0; i < n; i++)
        for (int j = w - wt[i]; j >= 0; j--)
            dp[j + wt[i]] = max(dp[j + wt[i]], dp[j] + v[i]);
    cout << dp[w] << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

#define EPS (1e-7)
#define PI (acos(-1))
//const ll mod = 1000000007;
template< typename T >
struct LiChaoTree {
  struct Line {
    T a, b;

    Line(T a, T b) : a(a), b(b) {}

    inline T get(T x) const { return a * x + b; }

    inline bool over(const Line &b, const T &x) const {
      return get(x) < b.get(x);
    }
  };

  vector< T > xs;
  vector< Line > seg;
  int sz;

  LiChaoTree(const vector< T > &x, T INF) : xs(x) {
    sz = 1;
    while(sz < xs.size()) sz <<= 1;
    while(xs.size() < sz) xs.push_back(xs.back() + 1);
    seg.assign(2 * sz - 1, Line(0, INF));
  }

  void update(Line &x, int k, int l, int r) {
    int mid = (l + r) >> 1;
    auto latte = x.over(seg[k], xs[l]), malta = x.over(seg[k], xs[mid]);
    if(malta) swap(seg[k], x);
    if(l + 1 >= r) return;
    else if(latte != malta) update(x, 2 * k + 1, l, mid);
    else update(x, 2 * k + 2, mid, r);
  }

  void update(T a, T b) { // ax+b
    Line l(a, b);
    update(l, 0, 0, sz);
  }

  T query(int k) { // xs[k]
    const T x = xs[k];
    k += sz - 1;
    T ret = seg[k].get(x);
    while(k > 0) {
      k = (k - 1) >> 1;
      ret = min(ret, seg[k].get(x));
    }
    return ret;
  }
};
ll dp[200050];


int main() {
    //cout.precision(10);
    ll N, C;
    cin >> N >> C;
    vector<ll> h(N + 1);
    h[0] = 1;
    for(int i = 1; i <= N; i++) {
      cin >> h[i];
    }
    LiChaoTree<ll> CHT(h,1e18);
    for(ll i = 2; i <= N; i++) {
      CHT.update(-2*h[i-1], h[i-1]*h[i-1] + dp[i-1]);
      dp[i] = h[i]*h[i] + C + CHT.query(i);
    }
    cout << dp[N] << endl;
    //cout << CHT.query(4) << endl;
    return 0;
}

Measured memory_bytes: 14576
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		string s = getString();
		Console.WriteLine(s[0] + (s.Length-2).ToString() + s[s.Length-1]);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int getInt(){ return int.Parse(getArg()); }
	public static long getLong(){ return long.Parse(getArg()); }
	public static double getDouble(){ return double.Parse(getArg()); }
	public static string getString(){ return getArg(); }
}


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

int main() {
  int n,m;
  cin >> n >> m;
  
  vector<long long> a1,a2,a3,a4;
  
  for(int i=0; i<n; i++){
    long long p,q,r;
    cin >> p >> q >> r;
    
    a1.push_back(p + q + r);
    a2.push_back(p + q - r);
    a3.push_back(p - q + r);
    a4.push_back(p - q - r);
  }
  
  sort(a1.begin(), a1.end(),greater<long long>());
  sort(a2.begin(), a2.end(),greater<long long>());
  sort(a3.begin(), a3.end(),greater<long long>());
  sort(a4.begin(), a4.end(),greater<long long>());
  
  long long ans1 = 0;
  long long ans2 = 0;
  long long ans3 = 0;
  long long ans4 = 0;
  long long ans5 = 0;
  long long ans6 = 0;
  long long ans7 = 0;
  long long ans8 = 0;
  
  for(int i=0; i<m; i++){
    ans1 += a1[i];
    ans2 += a2[i];
    ans3 += a3[i];
    ans4 += a4[i];
    ans5 += a1[n-1-i];
    ans6 += a2[n-1-i];
    ans7 += a3[n-1-i];
    ans8 += a4[n-1-i];
  }
  
  long long ans = ans1;
  ans = ans > ans2 ? ans : ans2;
  ans = ans > ans3 ? ans : ans3;
  ans = ans > ans4 ? ans : ans4;
  ans = ans > -ans5 ? ans : -ans5;
  ans = ans > -ans6 ? ans : -ans6;
  ans = ans > -ans7 ? ans : -ans7;
  ans = ans > -ans8 ? ans : -ans8;
  cout << ans << endl;
}

Measured memory_bytes: 256
import math


def F(A, B):
    return max(len(str(A)), len(str(B)))


N = int(input())
answer = len(str(N))
for A in range(1, int(math.sqrt(N)) + 1):
    if N % A == 0:
        B = N // A
        answer = min(answer, F(A, B))
print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    string s, t;
    rep(i, b) s += to_string(a);
    rep(j, a) t += to_string(b);
    cout << min(s, t) << endl;
}

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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION


void solve() {
    ll n; cin >> n;
    vll a; read(a, n, 1);
    vll pre(n + 1, 0);
    repi(i, 1, n) {
        pre[i] = pre[i - 1] + a[i];
        pre[i] = pre[i] % mod;
    }
    ll ans = 0;
    repi(i, 1, n) {
        ans += pre[i - 1] * a[i];
        ans = ans % mod;
    }

    cout << ans << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 6432
/*                          The four Truths of Life

                                    CKMKB
                                    PKMKB

                                    CKMKC
                                    PKMKC
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
	return (x % m + m) % m;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

	//cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

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

		for (i = 1; i <= n; i++)
		{
			if (i % 2 != 0 && arr[i] % 2 != 0)
				cnt++;
		}

		cout << cnt;




		ln
	}
	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll Sn;
char S[101010];
ll i,j,k,ans;
int main(){
    scanf("%s", S);
    for (Sn = 0; S[Sn];Sn++)
        ;
    ll l, r;
    while(i<Sn){
        while(S[j]=='R'){
            
            j++;
        }
        fornum(k,i+1,j){
            printf("0 ");
        }
        l = (j - i + 1) / 2;
        r = (j - i) / 2;
        i = j;
        while(j<Sn&&S[j]=='L'){
            j++;
        }
        l += (j - i) / 2;
        r += (j - i+1) / 2;
        printf("%lld %lld ", l, r);
        fornum(k,i+1,j){
            printf("0 ");
        }
        i = j;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int n,a;
LL d;
struct data{
	LL h,x;
}w[200005];
LL ans;
queue<data>Q;
bool cmp(data a,data b){
	return a.x<b.x;
}
int main(){
	scanf("%d%lld%d",&n,&d,&a);
	for(int i=1;i<=n;++i){
		scanf("%lld%lld",&w[i].x,&w[i].h);
	}
	sort(w+1,w+1+n,cmp);
	LL now=0;
	for(int i=1;i<=n;++i){
		while(!Q.empty()&&Q.front().x<w[i].x){now-=Q.front().h;Q.pop();}
		data e;
		e.x=w[i].x+d*2ll;
		w[i].h-=now;
		if(w[i].h<=0)continue;
		e.h=(w[i].h/a+(w[i].h%a!=0))*a;
		now+=e.h;
		ans+=e.h/a;
		Q.push(e);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992
import math
N=int(input())

count=4

S=[]
S.append(2)
S.append(3)

while count<110000:
    ser=int(math.sqrt(count))+1
    flag=True
    for i in range(2,ser+2):
        if count%i==0:
            flag=False
            break

    if flag==True:        
        S.append(count)
    count+=1
nagasa=len(S)
for i in range(nagasa):
    if N<=S[i]:
        print(S[i])
        exit()

Measured memory_bytes: 3424
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

N, K = map(int, input().split())

print(min(N % K, K - N % K))

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

int main()
{
    long long n,m,i,j,k,x=0,y,z;
    cin>>n>>m;
    if(n*500>=m){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static int gcd(int a,int b){
	if(b==0){return a;}
	return gcd(b,a%b);
}

public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt(),k=s.nextInt();
       boolean[][] dp=new boolean[k+1][n+1];
       int[] arr=new int[n+1];
       for(int i=1;i<=n;i++){arr[i]=s.nextInt();}
       for(int i=1;i<=k;i++){
       	for(int j=1;j<=n;j++){
       		if(i<arr[j]){
       			dp[i][j]=dp[i][j-1];
       		}
       		else{
       			dp[i][j]=(dp[i][j-1]||!dp[i-arr[j]][n]);
       		}
       	}
       }
       if(dp[k][n]){out.write("First\n");}
       else{out.write("Second\n");}
        
        out.flush();
  }
}


Measured memory_bytes: 35152
n = int(input())
h = list(map(int, input().split()))
ans = 0
cnt = 0

for i in range(n-1):
    if h[i] < h[i+1]:
        #print(cnt)
        ans = max(ans, cnt)
        cnt = -1
    cnt += 1

#print(cnt)
ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 14224
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    h,w = map(int,input().split())
    s = []
    for i in range(h):
        x = [y for y in input().split()]
        s.append(x)
    for i in range(h):
        for j in range(w):
            if s[i][j] == 'snuke':
                ans = [chr(j + 65),str(i + 1)]
                print(''.join(ans))
                return
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38892
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n = int(input()) - 1
    ans = 0

    if n % 2:
        print((1 + n) * (n // 2) + (n // 2 + 1))

    else:
        print((1 + n) * (n // 2))


if __name__ == '__main__':
    main()


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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool flag=false;
    if(a==5 and b==7 and c==5){
        flag=true;
    }else if(a==5 and b==5 and c==7){
        flag=true;
    }else if(a==7 and b==5 and c==5){
        flag=true;
    }
    if(flag)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t MAXA = 100000;
vector<int64_t> Count(MAXA + 1, 0);

int main()
{
  int64_t N, a, ans = 0, maxa = 0;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    Count.at(a)++;
    maxa = max(a, maxa);
  }
  int64_t l = 0, r = maxa;
  while (l < r)
  {
    for (int i = l; i <= r; i++) // 左から重複している数字を探す
    {
      if (Count.at(i) >= 2)
      {
        l = i;
        break;
      }
    }
    for (int i = r; i >= l; i--)
    {
      if (Count.at(i) >= 2)
      {
        r = i;
        break;
      }
    }
    int64_t m = min(Count.at(l), Count.at(r)) - 1;
    Count.at(l) -= m;
    Count.at(r) -= m;
  }
  if (l == r)
  {
    if (Count.at(l) % 2 == 0) // 別のカードも一枚減らす必要がある
      Count.at(l) = 0;
    else
      Count.at(l) = 1;
  }
  for (int i = 0; i <= maxa; i++)
    ans += Count.at(i);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007ll
#define rep(i,L,R) for(ll i=L;i<R;i++)
#define f(n) rep(i,0,n)
#define pll pair<ll,ll>
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
#define sq(X) ((X)*(X))
#define PI 3.141592653589
const ll INF = 1e18l+10,N = 1e5+10,MAX = 2e5+10;

// A B C D H F E I G K L M N P S O Q R J U Z Y X T V W
int main()
{
    SPEED
    int n,i,j;
    cin>>n;
    int a[n],dp[n];
    f(n)cin>>a[i];
    dp[1] = abs(a[0]-a[1]),dp[0]=0;
    for(i=2;i<n;i++) {
        dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1];

}

Measured memory_bytes: 1024
H, W, A, B = map(int, open(0).read().split())

S = [["0"] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if (i < B) ^ (j < A):
            S[i][j] = "1"

print("\n".join("".join(s) for s in S))


Measured memory_bytes: 13952
#include <bits/stdc++.h>
    #define Mod 1000000007
    #define INF 1e9
    #define INFL 9e18
    #define EPS 1e-9
    #define pb push_back
    #define mp make_pair
    #define SET(a) memset(a,-1,sizeof(a))
    #define CLR(a) memset(a,0,sizeof(a))
    #define CPY(a,b) memcpy(a,b,sizeof(a))
    #define all(a) (a).begin(),(a).end()
    #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define N 200005
    #define fs first
    #define sc second
    using namespace std;

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

   
    int main()
    {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios;
 string str;  
cin>>str;
str[3]='8';
cout<<str;















    return 0;


    }

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main() { 
   string s; cin >> s;
   map<char, vector<int>> mp;
   rep(i, s.size()) mp[s[i]].push_back(i);

   int a = -1, b = -1;
   for(auto m: mp){
       vector<int> v = m.second;
       rep(i, v.size()-1){
           if(v[i+1]-v[i]<=2){
               a=v[i]+1, b=v[i+1]+1;
           }
       }
    }
    cout << a << " " << b << ln;
}








Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

struct Sum
{
	ll x = 0;
	ll y = 0;
	ll z = 0;
};

using namespace std;

Sum xyz[1005];

Sum dp[1005][1005];

int N, M;

ll SumLL(Sum s)
{
	return std::abs(s.x) + std::abs(s.y) + std::abs(s.z);
}

int main()
{

	cin >> N >> M;

	REP(i, N)
	{
		cin >> xyz[i].x >> xyz[i].y >> xyz[i].z;
	}

	ll max = 0;
	REP(i, pow(2, 3))
	{
		int m[3] = { 1,1,1 };
		REP(j, 3)
		{
			m[j] = m[j] - 2 * ((i >> j) & 1);
		}
		sort(xyz, xyz + N, [m](Sum a, Sum b) {return m[0] * a.x + m[1] * a.y + m[2] * a.z > m[0] * b.x + m[1] * b.y + m[2] * b.z; });
		Sum s;
		REP(j, M)
		{
			s.x += xyz[j].x; s.y += xyz[j].y; s.z += xyz[j].z;
		}
		max = std::max(max, SumLL(s));
	}

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  long long h;
  cin >> h;
  int cnt = 0;
  while(h>1){
    h /= 2;
    cnt++;
  }
  long long s = 0;
  int i;
  for(i=0;i<=cnt;i++){
    s += pow(2,i);
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())

ret = 0
for i in range(1, N + 1) :
  l = str(i)[0]
  r = str(i)[-1]
  
  if r == '0' :
    continue
    
  if l == r and int(l) <= N :
    ret += 1
    
  for j in range(0, len(str(N)) - 2) :
    ret += pow(10, j)
  
  if str(N)[0] == r :
    if len(str(N)) >= 2 :
      ret += int(str(N)[1:]) // 10
      if int(str(N)[-1]) >= int(l) :
        ret += 1
  elif str(N)[0] > r :
    ret += pow(10, len(str(N)) - 2)
    
print(ret)

Measured memory_bytes: 43756
//Created by Aminul on 3/28/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        int x = in.nextInt(), y = in.nextInt();
        int from[] = new int[n], to[] = new int[n];
        int idx = 0;
        for (int i = 2; i <= n; i++) {
            from[idx] = i - 1;
            to[idx++] = i;
        }
        from[idx] = x;
        to[idx++] = y;

        int[][] g = packU(n + 1, from, to);
        int f[] = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            int vis[] = bfs(i, g, n);
            for (int k = 1; k <= n; k++) {
                f[vis[k]]++;
            }
        }

        for (int i = 1; i <= n - 1; i++) {
            pw.println(f[i] / 2);
        }

        pw.close();
    }

    static int[] bfs(int source, int[][] g, int n) {
        int vis[] = new int[n + 1];
        Arrays.fill(vis, -1);
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(source);
        vis[source] = 0;
        while (!queue.isEmpty()) {
            int p = queue.poll();
            for (int v : g[p]) {
                if (vis[v] == -1) {
                    vis[v] = vis[p] + 1;
                    queue.add(v);
                }
            }
        }
        return vis;
    }

    static int[][] packU(int n, int[] from, int[] to) {
        int[][] g = new int[n][];
        int[] p = new int[n];
        for (int f : from)
            p[f]++;
        for (int t : to)
            p[t]++;
        for (int i = 0; i < n; i++)
            g[i] = new int[p[i]];
        for (int i = 0; i < from.length; i++) {
            g[from[i]][--p[from[i]]] = to[i];
            g[to[i]][--p[to[i]]] = from[i];
        }
        return g;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 47768
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  string s;
  cin>>s;
  rep(i,s.size()){
    char c=s[i];
    rep(i,n){
      c++;
      if(c>'Z') c='A';
    }
    s[i]=c;
  }

  cout<<s<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll t1, t2;
    ll a1, a2;
    ll b1, b2;
    cin >> t1 >> t2;
    cin >> a1 >> a2;
    cin >> b1 >> b2;
    ll dif1 = t1 * a1 - t1 * b1;
    ll dif2 = t2 * a2 - t2 * b2;
    if (dif1 == (0-dif2)) {
        // 1サイクルで元に戻る
       cout << "infinity" << endl;
        return 0;
    } else if ((dif1 < 0 && dif1 + dif2 < 0) || (dif1 > 0 && dif1 + dif2 > 0)){
        // 距離は離れるばかり
        cout << 0 << endl;
        return 0;       
    }
    else {
        ll dif = dif1 + dif2;
        ll conf = floor(abs(dif1) / (double)abs(dif));
        if(conf * abs(dif) == abs(dif1))
            cout << conf * 2 << endl;
        else 
            cout << 1 + conf * 2 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[2000005];
int main()
{
   //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
   //ios::sync_with_stdio(false);
   //cin.tie(0); cout.tie(0);
    int i,j,n,m;
    scanf("%d%d",&m,&n);
    int maxn=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    a[n+1]=m+a[1];
    for(i=1;i<=n;i++)maxn=max(a[i+1]-a[i],maxn);
    cout<<m-maxn<<endl;
    return 0;
}


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

struct Card{char suit, value; };

void bubble(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        for(int j = N -1; j >= (i + 1); j--){
            if(A[j].value < A[j - 1].value){
                Card t = A[j];
                A[j] = A[j - 1];
                A[j - 1] = t;
            }
        }
    }
}

void selection(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j].value < A[minj].value){
                minj = j;
            }
        }
        
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

void print(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        if(i > 0){
            cout << " ";
        }
        
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
    for(int i = 0; i < N; i++){
        if(C1[i].suit != C2[i].suit){
            return false;
        }
    }
    
    return true;
}

int main(){
    Card C1[100], C2[100];
    int N;
    char ch;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    
    for(int i = 0; i < N; i++){
        C2[i] = C1[i];
    }
    
    bubble(C1,N);
    selection(C2,N);
    
    print(C1,N);
    cout << "Stable" << endl;
    print(C2, N);
    if(isStable(C1, C2, N)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}



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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll inf = 2e9+7;
const int MAX_N = 5e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = int> T in(){T x;cin >> x;return (x);}
inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
	int par[MAX_N];
	int rank[MAX_N];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};

void UnionFind::init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int UnionFind::find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
	x = find(x);
	y = find(y);
	if (rank[x] < rank[y]) par[x] = y;
	else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

bool UnionFind::same(int x,int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

int main() {
	string s;
	cin >> s;
	int hira = 1;
	int hirahira = 0;
	int ans = 0;
	int ansans = 0;
	char last = s[0];
	FOR (i,1,s.size()) {
		if (s[i] != last) {
			ans++;
			hira--;
			if (!hira && i != s.size()-1) last = s[i+1]; 
		} else {
			hira++;
		}
	}
	cout << ans * 2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using LL = long long;
using namespace std;
const LL mod = 1e9 + 7;
int main() {
	LL n, k; cin >> n >> k;
	LL pre_sum[n + 1] = {};
	for (LL i = 1; i <= n; i++) {
		pre_sum[i] = pre_sum[i - 1] + i;
	}
	LL ans = 1;
	for (LL i = k; i <= n; i++) {
		ans = (ans + pre_sum[n] - pre_sum[n - i] - pre_sum[i - 1] + 1) % mod;
	}
	cout << ans;
}

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

int main(){
  int N, A, B;
  int x;
  
  cin >> N >> A >> B;
  
  if(N*A > B){
    x = B;
  } else {
    x = A*N;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
using namespace std;
 
int main() {
	// your code goes here
	ll a,b,c,d,p=-1000000000,i,j;
	cin>>a>>b>>c>>d;
	cout<<max(max(a*c,a*d),max(b*c,b*d))<<endl;
	return 0;
}

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

using namespace std;

int main() {
int a=0;
for(int i=0;i<5;i++){
int n;
cin>>n;
if(n<40) {
n=40;
}

a=a+n;

}
cout<<a/5<<endl;;
	return 0;
}

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





signed main() {
   
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
 int a,b,c;
 cin>>a>>b>>c;
 a=abs(a);
 int total=a/c;
 int mini=a-(1LL*c*min(total,b));
 b-=total;
 if(b>0)
 {
    int first=mini;
    int second=abs(mini-c);
    b-=1;
    if(b%2)
      cout<<first<<endl;
    else
      cout<<second<<endl;
 }
 else
  cout<<mini<<endl;

//cout<<count1<<endl;
  return 0;
  }

Measured memory_bytes: 3644
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=200;
const int INF=0x3f3f3f3f;
int n,m,r;
int q[MAXN+10];
int G[MAXN+10][MAXN+10];
int main()
{
	scanf("%d%d%d",&n,&m,&r);
	for(int i=1;i<=r;++i)scanf("%d",q+i);
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)G[i][j]=((i==j)?0:INF);
	for(int i=1,a,b,c;i<=m;++i)scanf("%d%d%d",&a,&b,&c),G[a][b]=G[b][a]=min(G[a][b],c);
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
	sort(q+1,q+1+r);
	int ans=INF;
	do{
		int res=0;
		for(int i=1;i<r;++i)res+=G[q[i]][q[i+1]];
		ans=min(ans,res);
	}while(next_permutation(q+1,q+1+r));
	printf("%d",ans);
	return 0;
}

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

int n,m;
int a[8],b[8];
int dp[8][1001];

void solve(void){
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=1000;j++) if(dp[i][j]>0) {
			for(int k=0;k<=b[i] && j+k*a[i]<=1000;k++){
				dp[i+1][j+a[i]*k] += dp[i][j];
			}
		}
	}
}

int main(void){
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i];
		}

		solve(); //DPツ表ツ青カツ青ャ

		cin>>m;
		for(int i=0;i<m;i++){
			int g;
			cin>>g;
			cout<<dp[n][g]<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <list>
#include <algorithm>

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

using namespace std;

int n;
list<int> x;

int main(){
	ios_base::sync_with_stdio(false);
	cin >> n;
	rep(i, n){
		string a;
		cin >> a;
		if(a == "deleteFirst"){
			x.pop_front();
		}
		else if(a == "deleteLast"){
			x.pop_back();
		}
		else{
			int b;
			cin >> b;
			if(a == "insert"){
				x.push_front(b);
			}
			else{
				list<int>::iterator it = find(x.begin(), x.end(), b);
				if(it != x.end()){
					x.erase(it);
				}
			}
		}
	}
	for(list<int>::iterator it = x.begin(); it != x.end(); ++it){
		if(it != x.begin()){
			cout << ' ';
		}
		cout << *it;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 32480
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
long double cuadratic(ll x) {
    return (-1 + sqrt(1 + 8 * x)) / 2.0;
}
int main() {
#ifdef LOCALe
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    ll x;
    cin >> x;

    cout << ceil(cuadratic(x)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 100000 + 100;
const int maxm = 200000 + 100;
const LL MOD = 1000000000 + 7;
const LL INF = 1LL << 60;
struct Node {
    int pos;
    LL dis;
    Node() {}
    Node(int p, LL d) {
        pos = p;
        dis = d;
    }
};
bool operator<(const Node &a, const Node &b) {
    return a.dis > b.dis;
}
struct Edge {
    int u, v;
    LL dis;
};
int n, m, s, t, u, v;
LL d, min_dis, ans;
Edge edge[maxm];
priority_queue<Node> que;
vector<Node> G[maxn];
LL dp_t[maxn], dp_s[maxn];
LL dis_t[maxn], dis_s[maxn];

void bfs(int s, LL *dis, LL *dp) {
    memset(dis, 0x3f, sizeof(LL) * (n + 10));
    dis[s] = 0;
    dp[s] = 1;
    que.push(Node(s, 0));
    while(!que.empty()) {
        Node tmp = que.top();
        que.pop();
        int len = G[tmp.pos].size();
        for(int i = 0; i < len; ++i) {
            int pos = G[tmp.pos][i].pos;
            LL d = G[tmp.pos][i].dis;
            if(dis[pos] > tmp.dis + d) {
                dis[pos] = tmp.dis + d;
                dp[pos] = dp[tmp.pos];
                que.push(Node(pos, dis[pos]));
            } else if(dis[pos] == tmp.dis + d) {
                dp[pos] += dp[tmp.pos];
            }
            dp[pos] %= MOD;
        }
    }
}

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    #endif // LOCAL
    ios::sync_with_stdio(false);

    while(scanf("%d%d", &n, &m) != EOF) {
        for(int i = 1; i <= n; ++i) {
            G[i].clear();
        }
        scanf("%d%d", &s, &t);
        for(int i = 0; i < m; ++i) {
            scanf("%d%d%lld", &u, &v, &d);
            edge[i].u = u;
            edge[i].v = v;
            edge[i].dis = d;
            G[u].push_back(Node(v, d));
            G[v].push_back(Node(u, d));
        }
        bfs(s, dis_s, dp_s);
        bfs(t, dis_t, dp_t);
        min_dis = dis_s[t];
        ans = (dp_s[t] * dp_s[t]) % MOD;
        for(int i = 1; i <= n; ++i) {
            if(dis_s[i] == dis_t[i] && dis_s[i] == min_dis / 2) {
                LL tmp = (dp_s[i] * dp_t[i]) % MOD;
                tmp = (tmp * tmp) % MOD;
                ans = (ans - tmp + MOD) % MOD;
            }
        }
        for(int i = 0; i < m; ++i) {
            int u = edge[i].u;
            int v = edge[i].v;
            if(dis_s[u] > dis_s[v]) {
                swap(u, v);
            }
            if(dis_s[u] + edge[i].dis + dis_t[v] == min_dis && dis_s[u] < min_dis / 2 && dis_s[v] > min_dis / 2) {
                LL tmp = (dp_s[u] * dp_t[v]) % MOD;
                tmp = (tmp * tmp) % MOD;
                ans = (ans - tmp + MOD) % MOD;
            }
        }
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 20592
import java.util.Scanner

fun main(args:Array<String>){
    val cin = Scanner(System.`in`)
    val a = cin.nextInt()
    val b = cin.nextInt()

    val d = a / b
    val r = a % b
    val f = a.toDouble() / b.toDouble()

    println("%d %d %5f".format(d,r,f))
}



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

int main() {
  int k;
  string s;
  cin >> k;
  cin >> s;
  
  if(s.size()<=k) cout << s << endl;
  if(s.size()>k){
    s.erase(k);
    cout << s << "..." << endl;
  }
}


Measured memory_bytes: 3580
#include <iostream>
#include <bits/stdc++.h>
#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 Si(x) scanf("%d",&x)

#define pb push_back
/*
*
* Author : SIZ
*/
typedef long long ll;
const int maxn = 1e5+100;

using namespace std;

vector<int> Ve[maxn];

int col[maxn];
int cnt[4];

int main()
{
    int n,x,y;
    memset(cnt,0,sizeof(cnt));
    memset(col,0,sizeof(col));
    Si(n);

    rep(i,1,n-1)
    {
        Si(x),Si(y);
        Ve[x].pb(y);
        Ve[y].pb(x);
    }
    col[1] = 1; col[n] = 2;
    queue<int> Q;
    Q.push(1); Q.push(n);
    while(!Q.empty() )
    {
        int u = Q.front();
        Q.pop();
        cnt[ col[u] ]++;
        int len = Ve[u].size();
        for(int i = 0 ;i < len ; i++)
        {
            int vv = Ve[u][i];
            if( col[vv] != 0 ) continue;
            col[vv] = col[u];
            Q.push(vv);
        }
    }
    if( cnt[1] > cnt[2])
        printf("Fennec\n");
    else
        printf("Snuke\n");
    return 0;
}


Measured memory_bytes: 6272
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ABichromeCells {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n, a;
	    in >> n >> a;
	    out << n*n - a << endl;
	}
};


int main() {
	ABichromeCells solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX 510000
#define MOD 1000000007

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(){
  init_io();
  ll n,k,ans=1;
  cin >> n >> k;
  if(n>k) cout << "0\n";
  else{
    for(int i=0;i<n;i++){
      ans *= k;
      k--;
      ans%= MOD;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 550;
const ll INF = 1LL << 60;

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



// Main Code

int main()
{
string s;
cin>>s;
string t = s;
reverse(t.begin(), t.end());
int cnt = 0;
rep(i, 0, s.length())
{
  if(s[i] != t[i]) cnt++;
}
cout<<cnt/2<<endl;
}


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

int main() {
  int X, K, lcm, a = 360, b, a2;
  cin >> X;
  b = X;
  while(b != 0) {
    a2= a;
    a = b;
    b = a2 % a;
  }
  cout << 360 / a << endl;
}

Measured memory_bytes: 3628