akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)
using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

// b^e (mod m) を求める
ULONG modpow(ULONG b, ULONG e, ULONG m) {
  ULONG result = 1;
  while (e > 0) {
    if ((e & 1) == 1) result = (result * b) % m;
    e >>= 1;
    b = (b * b) % m;
  }
  return result;
}

const ULONG MOD = 1'000'000'000 + 7;
int main(void) {
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  REP(i, N) cin >> T[i];
  REP(i, N) cin >> A[i];
  vector<bool> exact(N);
  vector<int> maxes(N);
  int prev = 0;
  REP(i, N) {
    if (prev < T[i]) {
      exact[i] = true;
    }
    prev = T[i];
    maxes[i] = T[i];
  }
  prev = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (prev < A[i]) {
      if (exact[i] && A[i] != T[i] || A[i] > maxes[i]) {
          cout << 0 << endl;
          return 0;
      }
      exact[i] = true;
    }
    prev = A[i];
    maxes[i] = min(A[i], T[i]);
  }
  ULONG cnt = 1;
  for (int i = 0; i < N; i++) {
    if (!exact[i]) {
      for (int j = i + 1; j < N; j++) {
        if (exact[j]) {
          int width = j - i;
          int m = maxes[i];
          cnt = (cnt * modpow(m, width, MOD)) % MOD;
          i = j;
          break;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main(){
  int N; cin >> N;
  string s,t; cin >> s>> t;
  int i = 0;
  while(i<N){
    if(s.substr(i,N-i)==t.substr(0,N-i) ){
      break;
    }else{
	  i++;
    }
  }
  int r = N + i;
  cout << r << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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

  int t=1;
//  cin>>t;
  int tt=1;
  while(t--){
    ll n;
    cin>>n;
    ll ans=1e17;
    for(ll i=1;i*i<=n;i++)
    {
      if(n%i==0)
      {
        ll b=n/i;
        ans=min(ans,i+b-2);
      }
      
   // cout<<"Case #"<<tt<<": ";
   // tt++;
    }
    cout<<ans;
    }
  return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int a[21][21],d,m,n,x,y,vx,vy;
  char c;
  while(cin>>n&&n){
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      int p,q;
      cin>>p>>q;
      a[p][q]=1;
    }
    cin>>m;
    x=y=10;
    k=0;
    if(a[x][y]){
      a[x][y]=0;
      k++;
    }
    for(i=0;i<m;i++){
      cin>>c>>d;
      if(0){
      }else if(c=='N'){
	vx=0;
	vy=1;
      }else if(c=='E'){
	vx=1;
	vy=0;
      }else if(c=='S'){
	vx=0;
	vy=-1;
      }else if(c=='W'){
	vx=-1;
	vy=0;
      }
      for(j=0;j<d;j++){
	x+=vx;
	y+=vy;
	if(a[x][y]){
	  a[x][y]=0;
	  k++;
	}
      }
    }
    if(k==n)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	string S; cin >> S;

	set<char>st;
	vector<int>a(N);
	vector<vector<int>>d(N, vector<int>(10, -1));
	rep(i, 0, N) {
		st.insert(S[i]);
		a[i] = st.size();
	}
	rep(i, 0, N) {
		if (i >= 1) {
			d[i] = d[i - 1];
		}
		d[i][S[i] - '0'] = i;
	}
	int ans = 0;
	rep(i, 0, 10) {
		int x = d[N - 1][i];
		if (d[N - 1][i] == -1 or x < 2)continue;
		rep(j, 0, 10) {
			int y = d[x - 1][j];
			if (y == -1 or y < 1)continue;
			ans += a[y - 1];
		}
	}
	cout << ans << endl;


	return 0;
}


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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using Double = long double;
template<typename T>
using Vector = vector<vector<T>>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

void solve() {
	int n, x;
	cin >> n >> x;

	lli ans = 0, tmp, lst = 0;
	for (int i = 0; i < n; ++i) {
		cin >> tmp;
		if (tmp + lst > x) {
			ans += tmp + lst - x;
			tmp = x - lst;
		}
		lst = tmp;
	}

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

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int  H, W;
	
	while(1)
	{
		cin >> H;
		cin >> W;
		
		if( (0 == H) && (0 == W) )
		{
			break;
		}
		
		for(int i = 0; i < H; i++)
		{
			for(int j = 0; j < W; j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3108
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

import static java.lang.System.in;
import static java.lang.System.out;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(in);
        PrintWriter w = new PrintWriter(out);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int t1 = (n-m) * 100;
        int t2 = m * 1900;

        int chance = (int) Math.pow(2, m);
        
        w.println((t1+t2)*chance);

        w.close();
    }

}


Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
using namespace std;


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

    int ans = 0;
    for (int i = 1; i < S.length() - 1; i++)
    {
        /* code */
        if(S[i-1] == 'A' && S[i] == 'B' && S[i + 1] == 'C'){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    last = A[0]
    direction = 0
    ans = 1
    for i in range(1,N):
        if direction == 0:
            if last< A[i]:
                direction = 1
            elif last>A[i]:
                direction = -1
            last = A[i]
            continue
        if direction == 1:
            if last<=A[i]:
                last = A[i]
                continue
            else:
                last = A[i]
                direction = 0
                ans += 1
                continue
        if direction == -1:
            if last >= A[i]:
                last = A[i]
                continue
            else:
                last = A[i]
                direction = 0
                ans += 1
                continue
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC113
{
    class ProblemB
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] TA = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int T = TA[0];
            int A = TA[1];
            int[] H = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int id = 0;
            for(int i = 0; i < N; i++)
            {
                double dti = Math.Abs(A - (T - H[i] * 0.006));
                double dt = Math.Abs(A - (T - H[id] * 0.006));

                if (dti < dt) id = i;
            }

            Console.WriteLine(id + 1);
        }
    }
}


Measured memory_bytes: 28664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long llong;
#define sum(N) ((N) * (N + 1) / 2)

int main() {
    llong n;
    llong v;
    llong ans = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v;
        ans += v;
    }

    ans -= sum(n);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3096
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
P, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

prefs = defaultdict(list)
for p, y in zip(P, Y):
    prefs[p].append(y)

for ys in prefs.values():
    ys.sort()

for p, y in zip(P, Y):
    idx = bisect.bisect_left(prefs[p], y) + 1
    print('{:06d}{:06d}'.format(p, idx))


Measured memory_bytes: 77252
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#define _USE_MATH_DEFINENS
#include <cmath>
using namespace std;

#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

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

    ll d, n;
    cin >> d >> n;

    int num = 1;

    for(int i = 0; i < d; i++){
        num *= 100;
    }
    if(n <= 99){
        cout << n * num << endl;
    }else{
        cout << 101 * num << endl;
    }

    return 0;
}


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

int main(void) {
    long long N;
    cin >> N;
    vector<pair <long long, long long>> records(N);
    for (long long i = 0; i < N; i++) {
        long long record;
        cin >> record;
        records[i] = make_pair(record, i);
    }

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

    for(int j = 0; j < N; j++) {
        cout << records[j].second + 1;
        if (j == N-1) cout << endl;
        else cout << " ";
    }

    return 0;
}

Measured memory_bytes: 2432
n = int(input())
a = list(map(int, input().split()))
a_index = []
for i in range(n):
    a_index.append((i, a[i]))
dic1 = {}
dic2 = {}
for i in range(n):
    one = a_index[i][0] + a_index[i][1]
    two = a_index[i][0] - a_index[i][1]
    if one not in dic1:
        dic1[one] = 1
    else:
        dic1[one] += 1
    if two not in dic2:
        dic2[two] = 1
    else:
        dic2[two] += 1
ans = 0
for i in dic1.keys():
    if i in dic2:
        ans += dic2[i] * dic1[i]
for i in dic2.keys():
    if i in dic1:
        ans += dic1[i] * dic2[i]
        #print(i)
print(ans // 2)

Measured memory_bytes: 163624
#include<iostream>
using namespace std;
int main()
{
   long long m,n,k,a;
    cin>>m>>n>>k;
    a=min(k,m);
    m-=a;
    k-=a;
    a=min(k,n);
    n-=a;
    cout<<m<<" "<<n;
    return 0;
}


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

using namespace std;

const int N = 1e5 + 7;

int stk[N], top(0);
int leftovers[N], ltop(0);

int p[N];
int unust[N], doist[N], unudr[N], doidr[N], aux[N];
int n;

int plimba(int val) {
    int st = 1, dr = ltop;
    while (st != dr) {
        int mij = ((st + dr)>>1);
        if (p[leftovers[mij + 1]] < val)
            dr = mij;
        else
            st = mij + 1;
    }
    if (p[leftovers[st]] >= val)
        return st;
    return 0;
}

void baga(int *first, int *second) {
    top = ltop = 0;
    for (int i = 1; i <= n; ++i) {
        int pt = top;
        while (top && p[stk[top]] < p[i])
            --top;
        for (int j = top + 1; j <= pt; ++j) {
            while (ltop && p[leftovers[ltop]] <= p[stk[j]])
                --ltop;
            leftovers[++ltop] = stk[j];
        }
        if (top) {
            first[i] = stk[top];
            if (top - 1)
                second[i] = stk[top - 1];
            if (ltop) {
                int x = plimba(p[i]);
                if (x) {
                    if (second[i])
                        second[i] = max(leftovers[x], second[i]);
                    else
                        second[i] = leftovers[x];
                }
            }
        }
        stk[++top] = i;
    }
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> p[i];

    baga(unust, doist);
    reverse(p + 1, p + n + 1);
    baga(unudr, doidr);
    reverse(p + 1, p + n + 1);
    for (int i = 1; i <= n; ++i) {
        unudr[i] = n + 1 - unudr[i];
        doidr[i] = n + 1 - doidr[i];
    }
    reverse(unudr + 1, unudr + n + 1);
    reverse(doidr + 1, doidr + n + 1);

    long long ans(0);
    for (int i = 1; i <= n; ++i) {
        ans += 1LL * (unust[i] - doist[i]) * (unudr[i] - i) * p[i];
        ans += 1LL * (doidr[i] - unudr[i]) * (i - unust[i]) * p[i];
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
def main():
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        X.append(list(map(int, input().split())))
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            v = 0
            for a, b in zip(X[i], X[j]):
                v += abs((a - b) ** 2)
            if int(v ** 0.5) == v ** 0.5:
                ans += 1
    print(ans)


main()


Measured memory_bytes: 3188
from itertools import permutations

N, M = list(map(int, input().split()))
G = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
    ai, bi = list(map(int, input().split()))
    G[ai][bi] = 1
    G[bi][ai] = 1

count = 0
for idx, perm in enumerate(permutations(range(1, N+1))):
    if perm[0] != 1:
        continue

    flag = True
    for i in range(len(perm) - 1):
        if G[perm[i]][perm[i + 1]] == 0:
            flag = False
            break
    if flag:
        count += 1

print(count)

Measured memory_bytes: 40176
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#include <random>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 1000005;
const int MAXM = 50005;
const double EPS = 1e-8;
const ll MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}
template <typename T, typename T1> inline T qpower(T x, T p, T1 mod) { T re = 1; x %= mod; while (p) { if (p & 1)re = (re * x) % mod; x = (x * x) % mod; p >>= 1; }return re; }


void solve()
{
    ll n;
    cin >> n;
    ll ans = 0;
    if (n!=1)
        ans =  ( ( qpower(10LL,n,MOD) - 2 * qpower(9LL,n,MOD) % MOD + MOD ) % MOD  + qpower(8LL,n,MOD) % MOD + MOD ) %MOD;
    cout << ans % MOD << endl;

}


int main()
{closeSync;
#ifdef DEBUG
	//freopen("C:/Users/86159/Desktop/a2.in.txt", "r", stdin);
	//freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
	//clock_t c1 = clock();

    // int T;
    // cin >> T;
    // while (T--)
        solve();

    //cerr << "Time:" << clock() - c1 << "ms" <<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int X, Y;
    cin >> X >> Y;
    int a[4] = {1, 0, 1, 0};
    int b[4] = {1, 1, 0, 0};

    int mini = INF;
    for (int i = 0; i < 4; i++)
    {
        int x = X, y = Y;
        if (a[i])
            x *= -1;
        if (b[i])
            y *= -1;
        int tmp = y - x;
        if (tmp >= 0)
        {
            mini = min(tmp + a[i] + b[i], mini);
        }
    }
    cout << mini << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int Partition(int* A,int p,int r);
 
main(){
  int n,i,p,A[100000];
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  p = Partition(A,0,n-1);
 
  for(i=0;i<n;i++){
    if(p==i)printf("[%d]",A[i]);
    else printf("%d",A[i]);
if(i!=n-1) printf(" ");
  }
  printf("\n");
 
  return 0;
}
 
int Partition(int* A,int p, int r){
 
  int x, i,j, tmp;
 
  x = A[r];
  i = p-1;
  for(j=p; j<=r-1; j++){
 
    if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
 
  }
      tmp = A[i+1];
      A[i+1] = A[r];
      A[r] = tmp;
 
  return i+1;
 
}

Measured memory_bytes: 804
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
if A[0] != 0:
    print(-1)
else:
    count = 0
    prev = 0
    for i in range(1, N):
        temp = A[i] - prev
        if 0 < temp:
            if 2 <= temp:
                print(-1)
                break
            if A[i] == prev + 1:
                count += 1
            else:
                count += A[i]
            prev = A[i]
        else:
            count += A[i]
            prev = A[i]
    else:
        print(count)


Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll n, x, t; cin >> n >> x >> t;
  if (n%x) cout << (n/x+1) * t << endl;
  else cout << (n/x) * t << endl;
}

Measured memory_bytes: 3604
S = input()

S_New_STR = list(S)

S_New_INT = [int(s) for s in S_New_STR]


S_New_SUM = sum(S_New_INT)

S_N = int(S)

if S_N % S_New_SUM == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n,m;
  vector<string> s(100),t(100);
  cin>>n;
  for(int i=0;i<n;i++) cin>>s[i];
  cin>>m;
  for(int i=0;i<m;i++) cin>>t[i];

  int point=0,place=0;
  for(int i=0;i<n;i++)
   {
     //i番目の文字を言ったら何点もらえるかを計算する．
     int cnt=1;
     for(int j=i+1;j<n;j++)
     {
       if(s[i]==s[j]) cnt++;
     }
     for(int j=0;j<m;j++)
     {
       if(s[i]==t[j]) cnt--;
     }
     if(cnt>point)
     {
       point=cnt;
       place=i;
     }
   }
   int ans;
   (point>=0) ? ans=point : ans=0;
   cout<<ans<<endl;


}

Measured memory_bytes: 256
def main():

  n = int(input())

  a = list(map(int, input().split()))
  b = list(map(int, input().split()))

  d = 0
  for i in range(n):
    if a[i] >= b[i]:
      d += b[i]

    else:
      d += a[i]
      b[i] = b[i] - a[i]

      if a[i+1] - b[i] >= 0:
        d += b[i]
        a[i+1] = a[i+1] - b[i]

      else:
        d += a[i+1]
        a[i+1] = 0


  print(d)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int main(){
    LL s,c;
    cin >> s >> c;
    if(s>=c/2){
        cout << c/2 << endl;
        return 0;
    }
    LL t=(c-2*s)/4;
    cout << t+s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
//typedef pair<int,int> P;

//少数点表示
//cout << std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = 0;
    if(a>b){
        cout << ans << endl;
        return 0;
    }
    if(a!=b && n == 1){
        cout << ans << endl;
        return 0;
    }
    ll min_ = a*(n-1)+b;
    ll max_ = b*(n-1)+a;

    ans = max_ - min_ +1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll D[55];
    cin >> N;
    rep(i,0,N) cin >> D[i];
    sort(D, D+N);
    ll lv = 0, rv = 0;
    ll pos[25] = {};
    pos[0] = 1;
    rep(i,0,N){
        if(D[i] - lv > D[i] - rv){
            pos[24-D[i]]++;
            lv = D[i];
        }else{
            pos[D[i]]++;
            rv = D[i];
        }
    }
    rep(i,0,24){
        if(pos[i] >= 2){
            print(0);
            return 0;
        }
    }
    vector<ll> tt;
    rep(i,0,24){
        if(pos[i] == 1){
            tt.push_back(i);
        }
    }
    ll ans = INF;
    ll n = tt.size();
    rep(i,0,n){
        ans = min(ans, abs(tt[(i+1)%n] - tt[i]));
    }
    print(ans);


    
}


Measured memory_bytes: 256
n,k = map(int,input().split())
w = [int(input()) for i in range(n)]

def check(p):
    i = 0
    for j in range(k):
        s = 0
        while s + w[i] <= p:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i

left = 0
right = (10**5)*(10**4)
while right - left > 1:
    mid = (left+right)//2
    v = check(mid)
    if v >= n:
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 9564
#include <iostream>
#include <vector>
#include <stdio.h>

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

int main() {
  int a,b;
  cin >> a >> b;
  cout << a/b << " " << a%b << " ";
  printf("%.10f", double(a)/ double(b));
}



Measured memory_bytes: 3244
#include<stdio.h>

int bubblesort(int *a, int length)
{
  int i, j, tmp, cnt=0;

for(i=0; i<length; i++)
  {
    for(j=length-1; j>i; j--)
      {
	if(a[j] < a[j-1])
	  {
	    tmp = a[j];
	    a[j] = a[j-1];
	    a[j-1]  = tmp;
	    cnt++;
	  }
      }
  }
 return cnt;
}

main()
{
  int i, n, Array[100], cnt=0;

  scanf("%d", &n);

  for(i=0; i<n; i++)
    {
      scanf("%d", &Array[i]);
    }

  cnt = bubblesort(Array, n);

  printf("%d", Array[0]);

  for(i=1; i<n; i++)
    {
      printf(" %d", Array[i]);
    }

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

  return 0;
}

Measured memory_bytes: 600
from collections import deque
n,m=map(int,input().split())
f=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  f[a].append(b)
  f[b].append(a)
q=deque()

for i in range(n):
  for j in f[i]:
    q.append(j)
  while q:
    p=q.popleft()
    if i!=p:
      f[i]+=f[p]
      for k in f[p]:
        q.append(k)
      f[p]=[]
ans=1
for i in f:
  cnt=len(list(set(i)))
  ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 154304
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 100010;
const int MOD = 1000000007;
const int INF = (int)1e9;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define dbg(msg, var) cout << msg << " " << var << endl;
#define ti tuple<int,int,int>
//

int main() {
    int s = 3;

    vector<vi> mat(3, vi(3, 0));
    forn(i, s) {
        forn(j, s) {
            cin >> mat[i][j];
        }
    }

    int n;
    cin >> n;

    forn(i, n) {
        int val;
        cin >> val;

        forn(i, s) {
            forn(j, s) {
                if(mat[i][j] == val)
                    mat[i][j] = -1;
            }
        }
    }

    bool win = false;
    forn(i, s) {
        int qt = 0;
        forn(j, s) {
            if(mat[i][j] == -1)
                qt++;
        }
        if(qt == s) {
            win = true;
        }
    }

    forn(j, s) {
        int qt = 0;
        forn(i, s) {
            if(mat[i][j] == -1)
                qt++;
        }
        if(qt == s) {
            win = true;
        }
    }

    {
        int qt = 0;
        forn(i, s) {
            if(mat[i][i] == -1)
                qt++;
        }
        if(qt == s)
            win = true;
    }

    {
        int qt = 0;
        forn(i, s) {
            if(mat[i][s-i-1] == -1)
                qt++;
        }
        if(qt == s)
            win = true;
    }

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

    return 0;
}


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

int main(void) {
  int animal;
  int leg;

  cin >> animal >> leg;

  //2x + 4y = leg, x+y = animal
  //かいが存在
  //x>0 && y > 0

  bool ans = false;
  for (int i = 0; i <= animal; i++) {
    int j = animal - i;
    if (2 * i + 4 * j == leg) {ans = true; break;}
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
 char str;
 cin >> str;
   if(str == 'A'||str == 'B'||str == 'C'||str == 'D'||str == 'E'||str == 'F'||str == 'G'||str == 'H'||str == 'I'||str == 'J'||str == 'K'||str == 'L'||str == 'M'||str == 'N'||str == 'O'||str == 'P'||str == 'Q'||str == 'R'||str == 'S'||str == 'T'||str == 'U'||str == 'V'||str == 'W'||str == 'X'||str == 'Y'||str == 'Z')
   {
     cout << "A" << endl;
   }
   else{
     cout << "a" << endl;
   }
}
 

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K;
  cin >> N >> K;

  cout << min(N%K, K-N%K) << "\n";

  return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    ll ans = 0;
    if (p == 2 | p == 5) {
        rep(i, n) {
            ll num = s[i] - '0';
            if (num % p == 0) {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    ll memo[p] = {};
    ll base = 1;
    memo[0] = 1;
    ll hash = 0;
    rep(i, n) {
        ll index = n - i - 1;
        ll num = s[index] - '0';
        hash = (hash + num * base) % p;
        memo[hash]++;
        base *= 10;
        base %= p;
    }

    rep(i, p) { ans += (memo[i] * (memo[i] - 1)) / 2; }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 644
n = int(input())
a = []
b = []

for i in range(n):
    t = int(input())
    a.append(t)
    b.append(t)

b.sort()

for i in range(n):
    if a[i] != b[-1]:
        print(b[-1])
        continue
    else:
        print(b[-2])

Measured memory_bytes: 14120
m=[4,1,4,1,2,1,2,1]
l=[]
while 1:
    try:
        c=map(int,raw_input().split())
        cnt=[0]*8
        for i in range(8):
            chk=[m[(i+x)%8] for x in range(8)]
            l.append(chk)
            for j in range(8):
                if c[j]>chk[j]:
                    cnt[i]+=c[j]-chk[j]
        ans=[]
        for i in range(8):
            if cnt[i]==min(cnt):
                ans.append(int(''.join(map(str,l[i]))))
        ans.sort()
        for i in str(ans[0]):
            print i,
        print
    except:
        break

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

int main(){
  int n;cin>>n;
  long long ttl=0,ans=100100100100100100;
  vector<long long> a(n+1,0);

  REP(i,n){
    long long t;cin>>t;
    a.at(i+1)=a.at(i)+t;
    ttl+=(long long)t;
  }
  
  REP(i,n-1){
    //cout<<abs(ttl-2*a.at(i+1))<<" "<<ans<<endl;
    ans=min(ans,abs(ttl-2*a.at(i+1)));
  }

  cout<<ans;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in);) {
			
			int r = sc.nextInt();
			int c = sc.nextInt();
			
			StringBuilder sb = new StringBuilder();
			
			int colSum[] = new int[c];
			int total = 0;
			
			for(int i = 0; i < r; i++) {
				int rowSum = 0;
				for(int j = 0; j < c; j++) {
					int num = sc.nextInt();
					rowSum += num;
					colSum[j] += num;
					total += num;
					
					sb.append(num);
					sb.append(" ");
				}
				sb.append(rowSum);
				sb.append("\n");
			}
			
			for(int i = 0; i < c; i++) {
				sb.append(colSum[i]);
				sb.append(" ");
			}
			
			sb.append(total);
			
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 40160
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		int n = in.nextInt();
		for (int i=0; i<n; i++) {
			BigInteger x = (new BigInteger(in.next())).add(new BigInteger(in.next()));
			out.println(x.toString().length() <= 80 ? x : "overflow");
		}
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

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

int main(void){
  int n;
  vector<int> v;
  cin >> n;
  for(int i = 0;i < n;++i){
    int a;
    cin >> a;
    --a;
    v.push_back(a);
  }
  int res = 0;
  for(int i = 0;i < n;++i){
    if(v[v[i]] == i)++res;
  }
  cout << res/2 << endl;
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll fact[200005];
ll bigmod(ll a,ll n,ll mod)
{
    ll res=1;
    ll x=a%mod;
    while(n>0)
    {
        if(n%2==1)res=(res*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return res;
}

void cal()
{
    ll mod=1e9+7;
    fact[0]=1;
    for(ll i=1;i<=102003;i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
    }
    return;
}
ll M=1e9+7;
ll ncr(ll n,ll r)
{
    if(r>n)return 0;
    ll a=bigmod(fact[n-r],M-2,M);
    ll b=bigmod(fact[r],M-2,M);
//    ll mod=(M*a*b);
    ll res=(((fact[n]*a)%M)*b)%M;
    return res%M;
}
ll ara[100005];
bool vis[100005];
int main()
{
    cal();
//    cout<<ncr(100001,3300)<<endl;
    ll n;cin>>n;
    ll st=0,ed=0;
    for(ll i=0;i<n+1;i++)
    {
        cin>>ara[i];
    }
    for(int i=0;i<=n;i++)
    {
        ll val=ara[i];
        if(vis[val]==0)vis[val]=1;
        else
        {
            ed=i;
            break;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(ara[i]==ara[ed])
        {
            st=i;
            break;
        }
    }
    int d=n-ed+st;
//    cout<<"d = "<<d<<endl;
    ll val = ara[ed];
    ll last = (n-ed);
    for(ll i=0;i<n;i++)
    {
        if(ara[i]==val){
            st=i;
            break;
        }
    }
    for(int i=1;i<=n+1;i++)
    {
        ll inc=ncr(n+1,i)%M;
        ll exc=ncr(d,i-1)%M;
        ll ans=(inc-exc);
        if(ans<0)ans+=M;
        cout<<ans<<endl;
    }
//    cout<<(4-5)%3<<endl;
//    cout<<st<<" "<<ed<<endl;
}
/*
8
7 8 5 4 3 3 1 2 6

8
1 4 2 5 6 8 3 2 7
*/


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
   int N, K;
   std::cin >> N >> K;
   std::vector<int> p(N);
   for(int i=0; i<N; ++i) std::cin >> p[i];

   std::sort(p.begin(), p.end());

   int ans = 0;
   for(int i=0; i<K; ++i) ans += p[i];

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


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int cnt_A = 0, cnt_C = 0;
  for (char c : s) {
    cnt_A += c == 'A';
    cnt_C += c == 'C';
  } 
  if (s[0] != 'A' || cnt_A != 1 || cnt_C != 1) {
    cout << "WA" << '\n';
    return 0;
  }
  bool ok = false;
  for (int i = 2; i <= (int) s.size() - 2; ++i) {
    if (s[i] == 'C') {
      ok = true;
    }
  }
  for (char c : s) {
    if (c != 'A' && c != 'C') {
      ok &= (c < 'A' || c > 'Z');
    }
  }
  cout << (ok ? "AC" : "WA") << '\n';
  return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

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

    if(n & 1)
        cout << "0";
    else
    {
        n /= 10;
        ll cnt = n;
        while(n > 4)
        {
            n /= 5;
            cnt += n;
        }

        cout << cnt;
    }

    return 0;
}


Measured memory_bytes: 256
N = int( input() )
p_list = list( map( int, input().split() ) )
t_list = p_list[:]
p_list.sort()
c = 0
for i in range(N):
    if p_list[i] != t_list[i]:
        c += 1
if c == 0 or c == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

// 二乗を計算する。
int sq(int x) { return x * x; }

// 領域内にいるか。
bool within(int x, int min, int max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T &container, typename T::key_type &key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T &container, typename T::key_type &key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
LONG modpow(LONG b, LONG e, LONG m) {
	LONG result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}

int main(void) {
	int N, A, B;
	cin >> N >> A >> B;
	if (N == 1 && A != B || A > B) {
		cout << 0 << endl;
	}
	else if(N == 1) {
		cout << 1 << endl;
	}
	else {
		LONG sum = (LONG)(N - 2) * (LONG)(B - A) + 1;
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
const int N=2e5+10;
const int M=1e7;
typedef long long ll;
struct edge{
	int u,v;ll val;
	inline bool operator <(const edge B)const{
		return val<B.val;
	}
}E[M];int cur=0;
int fa[N];
ll w[N];
int n,m;
struct Edge{
	int to,next;ll w;
}a[N<<1];
int head[N],cnt=0;
inline void add(int x,int y,ll w){a[++cnt]=(Edge){y,head[x],w};head[x]=cnt;}
int size[N],f[N];
bool vis[N];
int RT,SZ;
void Find(int u,int fa){
	size[u]=1,f[u]=0;
	for(int v,i=head[u];i;i=a[i].next){
		v=a[i].to;if(v==fa||vis[v]) continue;
		Find(v,u);
		f[u]=max(f[u],size[v]);size[u]+=size[v];
	}
	f[u]=max(f[u],SZ-size[u]);
	if((!RT)||f[RT]>f[u]) RT=u;
	return;
}
typedef pair<ll,int> PA;
PA Dis[N];int top=0;
PA Mi;
void Dfs(int u,int fa,ll dis){
	Dis[++top]=PA(dis+w[u],u);
	if(Mi>Dis[top]) Mi=Dis[top];
	for(int v,i=head[u];i;i=a[i].next){
		v=a[i].to;if(vis[v]||v==fa) continue;
		Dfs(v,u,dis+a[i].w);
	}
	return;
}
int dep=0,mx=0;
void Divide(int u){
	vis[u]=1;top=0;Mi=PA(w[u],u);
	++dep;mx=max(dep,mx);
	int L=0,R=0;
	for(int v,i=head[u];i;i=a[i].next){
		v=a[i].to;if(vis[v]) continue;
		L=top;PA now=Mi;
		Dfs(v,u,a[i].w);if(now!=Mi) R=top;
	}
	if(!R) {
		int U=Mi.second;ll val=Mi.first;
		for(int i=1;i<=top;++i) {
			int V=Dis[i].second;
			E[++cur]=(edge){U,V,val+Dis[i].first};
		}
	}
	else {
		E[++cur]=(edge){u,Mi.second,Mi.first+w[u]};
		int U=Mi.second;ll val=Mi.first;
		for(int i=1;i<=top;++i) {
			if(i>L&&i<=R) continue;
			int V=Dis[i].second;
			E[++cur]=(edge){U,V,val+Dis[i].first};
		}
	}
	for(int v,i=head[u];i;i=a[i].next){
		v=a[i].to;if(vis[v]) continue;
		RT=0;SZ=size[v];Find(v,u);
		Divide(RT);
	}
	--dep;
	return;
}
int find(int x){return fa[x]==x? x:fa[x]=find(fa[x]);}
int main()
{
	init(n);
	for(int i=1;i<=n;++i) init(w[i]);
	int u,v;ll val;
	for(int i=1;i<n;++i) {
		init(u),init(v),init(val);
		add(u,v,val),add(v,u,val);
	}
	SZ=n;Find(1,0);
	Divide(RT);
	sort(E+1,E+1+cur);
	for(int i=1;i<=n;++i) fa[i]=i;
	ll ans=0;
	for(int i=1;i<=cur;++i) {
		int u=E[i].u,v=E[i].v;
		ll Val=E[i].val;
		int fx=find(u),fy=find(v);
		if(fx==fy) continue;
		fa[fx]=fy;ans+=Val;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 71040
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int l, r, d, ans = 0;
	cin >> l >> r >> d;
	for (int i = 1; i <= 1000; i++){
		if (l <= i * d && i * d <= r) 
			ans ++;
	}
	cout << ans;
}


Measured memory_bytes: 3628
A, B, m = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)

for i in range(m):
    x, y, c = map(int, input().split())

    price = a[x-1] + b[y-1] - c

    ans = min(price, ans)

print(ans)


Measured memory_bytes: 18736
def solve(x: int, y: int) -> int:
    if abs(x) > abs(y):
        return solve(-y, -x)
    m = 0
    if x < 0:
        m += 1
    if y < 0:
        m += 1
    return abs(y) - abs(x) + m


def test():
    assert solve(1, 10) == 9
    assert solve(-1, 10) == 10
    assert solve(1, -10) == 10
    assert solve(-1, -10) == 11

    assert solve(10, 1) == 11
    assert solve(-10, 1) == 10
    assert solve(-10, -1) == 9
    assert solve(10, -1) == 10

    assert solve(10, 20) == 10
    assert solve(10, -10) == 1
    assert solve(-10, -20) == 12
    assert solve(-10, 10) == 1


if __name__ == "__main__":

    x, y = [int(x) for x in input().split(" ")]

    print(solve(x, y))

Measured memory_bytes: 62020
from collections import deque


def bfs():
  d = [[float('inf')]* w for i in range(h)]
  
  dx = [1, 0, -1, 0]
  dy = [0, 1, 0, -1]
  
  que = deque([])
  que.append((sx, sy))
  d[sx][sy] = 0
  
  while que:
    p = que.popleft()
    if p[0] == gx and p[1] == gy:
      break
    for i in range(4):
      nx = p[0] + dx[i]
      ny = p[1] + dy[i]
      
      if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != '#' and d[nx][ny] == float('inf'):
        que.append((nx, ny))
        d[nx][ny] = d[p[0]][p[1]] + 1
        
  return d[gx][gy]
  
  
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
sx, sy = 0, 0
gx, gy = h-1, w-1

white = 0
for i in range(h):
  for j in range(w):
    if maze[i][j] == '.':
      white += 1
      
res = bfs()
if 0 < res < float('inf'):
  print(white - res - 1)
else:
  print(-1)

Measured memory_bytes: 9364
from collections import deque
import sys
sys.setrecursionlimit(1000000000)
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
que = deque([0])
parent = [-1]*N
parent[0] = 0
while que:
    cur = que.pop()
    for nxt in edges[cur]:
        if parent[nxt] < 0:
            parent[nxt] = cur
            que.append(nxt)
cur = N-1
route = [N-1]
while cur:
    cur = parent[cur]
    route.append(cur)
i = len(route)//2
a, b = route[i-1:i+1]
edges[a].remove(b)
edges[b].remove(a)
que = deque([0])
flag = [True]*N
score = 0
flag[0] = False
while que:
    v0 = que.pop()
    score+=1
    for v in edges[v0]:
        if flag[v]:
            que.append(v)
            flag[v] = False
if score>N//2:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 23928
#include <bits/stdc++.h>
using namespace std;
inline int rf()
{
	int r;int s=0,c;
	for(;!isdigit(c=getchar());s=c);
	for(r=c^48;isdigit(c=getchar());
	(r*=10)+=c^48);
	return s^45?r:-r;
}
//#define int long long
#define N
int n;
//int head[N<<1],nxt[N<<1],ver[N<<1],top=0;
//int val[N<<1];
/*
void add(int x,int y)
{
	 nxt[++top]=head[x];
	 head[x]=top;
	 ver[top]=y;
	 //val[top]=v;
}
*/
char c[100010];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=rf();
  	int ans=0;
  	scanf("%s",c+1);
  	for(int i=2;i<=n;i++)
		if(c[i]!=c[i-1])
          	ans++;
 	cout<<ans+1;
    return 0;
}


Measured memory_bytes: 384
# your code goes here
h, w, d = gets.split(' ').map {|s| s.to_i}
x = Array.new(h*w+1)
y = Array.new(h*w+1)
h.times do |i|
  t = gets.split.map {|s| s.to_i}
  w.times do |j|
    x[t[j]] = j
    y[t[j]] = i
  end
end
sum = Array.new(h*w+1, 0)
(h*w+1).times do |i|
  if i > d then
    cost = (x[i]-x[i-d]).abs + (y[i]-y[i-d]).abs
    sum[i] = sum[i-d] + cost
  end
end
q = gets.to_i
q.times do |i|
  l, r = gets.split.map {|s| s.to_i}
  puts (sum[r]-sum[l]).to_s
end

Measured memory_bytes: 5372
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    vector<int> a(n);
    char c; int sum=0;
    for(int i=0; i<n; i++){
        cin>>c;
        if(c=='E')
            a.at(i)=1;
        else
            a.at(i)=0;
        if(i>=1) sum+=a.at(i);
    }
    int ans=sum;
    for(int i=1; i<n; i++){
        sum-=a.at(i);
        if(a.at(i-1)==0) sum+=1;
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define CLEAR(d) memset((d), 0, (sizeof((d))))
#define ALL(c) (c).begin(), (c).end()
#define ABS(x) ((x < 0) ? -(x) : (x))
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define SIZE(a) ((int)((a).size()))
#define MOD 1000000007
#define EPS 1e-7
#define PI  3.14159265358979323846
#define INF 100000000
struct edge { int to; int cost; };
//===================================================

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k, x, sum = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> x;
		if(2 * x < 2 * (k - x))
			sum += 2 * x;
		else
			sum += 2 * (k - x);
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256