akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    ll res=0;
    res+=(a+9)/10*10;
    res+=(b+9)/10*10;
    res+=(c+9)/10*10;
    res+=(d+9)/10*10;
    res+=(e+9)/10*10;
    int in[5]={a%10,b%10,c%10,d%10,e%10};
    sort(in,in+4);
    int mi = 10;
    rep0(i,5){
        if(in[i]!=0){
            mi=in[i];
            break;
        }
    }
    cout << res-10+mi << endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define MAXN 100001
int a[MAXN],b[MAXN];
ll N,K;
typedef pair<ll,ll> P;
int main(){
    P par[MAXN];
    cin >> N >> K;
    rep(i,N){
        ll A,B;cin >> A >> B;
        par[i].first = A;
        par[i].second = B;
    }   
    sort(par,par+N);
    ll count = 0;
    rep(i,N){
        if(count+par[i].second<K)count += par[i].second;
        else {
            cout << par[i].first << endl;
            break;
        }
    }
    return 0;

}

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

int main(){
	int h,w,a[2550],b[2550],cnt=0;
	fill(a,a+2500,100);
	cin>>h>>w;
	string s[h+2];
s[0]=s[h+1]="###############################################################################################################################################################################################################################################";
	for(int i=0; i<h; i++){
s[i+1]="###############################################################################################################################################################################################################################################";
		for(int j=0; j<w; j++){
			cin>>s[i+1][j+1];
			if(s[i+1][j+1]=='#')a[cnt]=i+1,b[cnt]=j+1,cnt++;
		}
	}
	
	for(int i=0; i<2550; i++){
		if(a[i]==100){
			break;
		}
		if(s[a[i]-1][b[i]]!='#' and s[a[i]+1][b[i]]!='#' and s[a[i]][b[i]-1]!='#' and s[a[i]][b[i]+1]!='#'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
 
typedef vector<int> vi;
typedef vector<ui> vui;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
 
typedef vector<vi> vvi;
typedef vector<vui> vvui;
typedef vector<vll> vvll;
typedef vector<vull> vvull;
typedef vector<vs> vvs;
 
typedef string ss;
#define forr(i,b) for(int i = 0; i < b; i++)
#define ford(i,b) for(int i = b; i >= 0; i--)
#define ff for(;;)
 
template<typename T> int sgn(T val) { return (T(0) < val) - (val < T(0)); }
int gcd(int a, int b) { if(a == 0) return b; return gcd(b % a, a); }
int ncr(int n, int k) { int r = 1; if(k > n - k) k = n - k; for(int i=0;i<k;i++) { r *= n - i; r /= i + 1; } return r; }
template<typename T> void printa(vector<T> arr) { for(ui i = 0; i < arr.size(); i++) if(i != arr.size() - 1) cout << arr[i] << ' '; else cout << arr[i] << '\n'; }
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n,k;
    cin >> n >> k;

    vi mask(n,0);
    forr(i,k) {
        int d;
        cin >> d;

        vi z(d);
        forr(j,d) {
            cin >> z[j];
            mask[z[j] - 1]++;
        }
    }

    int s = 0;
    for(int m:mask)
        if(m == 0)
            s++;

    cout << s << '\n';

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

string S;
int N, M;

const int MAXN = 300000;

vector<int> G[MAXN];

queue<int> myremove;
int degA[MAXN], degB[MAXN];
bool added[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> N >> M;
	cin >> S;
	
	FOR (i, MAXN)
		G[i].clear();
	SET(degA, 0);
	SET(degB, 0);
	
	int a, b;
	FOR (i, M) {
		cin >> a >> b;
		a--;
		b--;
		G[a].pb(b);
		if (S[b] == 'A')
			degA[a]++;
		else
			degB[a]++;

		
		G[b].pb(a);
		if (S[a] == 'A')
			degA[b]++;
		else
			degB[b]++;
	}

	SET(added, 0);
	while (!myremove.empty())
		myremove.pop();
		
	FOR (i, N)
		if (degA[i] == 0 || degB[i] == 0) {
			added[i] = true;
			myremove.push(i);
		}
		
	int removed = 0;
	while (!myremove.empty()) {
		removed++;
		int v = myremove.front();
		myremove.pop();
		FOR (i, G[v].sz) {
			int w = G[v][i];
			if (added[w])
				continue;
			if (S[v] == 'A')
				degA[w]--;
			else
				degB[w]--;
			if (degA[w] == 0 || degB[w] == 0) {
				myremove.push(w);
				added[w] = true;
			}
		}
	}
	if (removed == N)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 15952
n, m = map(int, input().split())
a = []
for i in range(m):
	s,c = map(int, input().split())
	a.append([s,c])

for i in range(10**(n-1)-1,10**n):
	if len(str(i)) != n:
		continue
	if all(str(i)[s-1] == str(c) for s,c in a):
		print (i)
		exit()
print (-1)

Measured memory_bytes: 3064
def main():
    n, m, c = map(int, input().split())
    blis = list(map(int, input().split()))
    alis = []
    for i in range(n):
        ilis = list(map(int, input().split()))
        alis.append(ilis)
    ans = 0
    for i in range(n):
        tmp = c
        for k in range(m):
            #print(alis, alis[i], alis[i][k], blis, blis[k])
            tmp += alis[i][k] * blis[k]
        if tmp > 0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 62192
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, K) = Read2Longs();
            var A = ReadLongs();

            if (A[0] == 1) return 1;

            if (K <= N)
            {
                var cur = 1L;
                for (long i = 0; i < K; i++)
                {
                    cur = A[(int)cur - 1];
                }
                return cur;
            }

            var visitedTable = new long[N];
            visitedTable[0] = -1;
            var current = 1L;
            var innerMember = 0L;
            var outerMember = 0L;
            while(true)
            {
                var nextIndex = A[(int)current - 1] - 1;
                // きれいに一周したケース
                if (visitedTable[nextIndex] == -1)
                {
                    outerMember = 0;
                    innerMember = visitedTable.Count(x => x != 0);
                    break;
                }
                if (visitedTable[nextIndex] > 0)
                {
                    outerMember = visitedTable[nextIndex];
                    innerMember = visitedTable.Count(x => x != 0) - outerMember;
                    break;
                }

                var pre = visitedTable[current - 1];
                visitedTable[nextIndex] = pre == -1 ? 1 : (pre + 1);
                current = A[(int)current - 1];
            }

            current = 1;
            var smallCount = (K - outerMember) % innerMember + outerMember;
            for (long i = 0; i < smallCount; i++)
            {
                current = A[(int)current - 1];
            }

            return current;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 44996
#include<stdio.h>

int main(){
  int N,K;
  int snuke[101]={0};
  scanf("%d%d",&N,&K);
  for(int i=0;i<K;i++){
    int d;
    scanf("%d",&d);
    for(int j=0;j<d;j++){
      int A;
      scanf("%d",&A);
      snuke[A]++; //A番目のsnukeが持ってるお菓子を増やす
    }
  }
  int ans=0;
  for(int i=1;i<=N;i++){ //snukeは1からN
    if(snuke[i]==0){
      ans++;
    }
  }
  printf("%d\n",ans);
}


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


int n;


int main(){
  cin >> n;
  const int N = n;
  int arr[N];
  int matrix[N][2];
  for(int i = 0; i < n; i++){
    cin >> arr[i];
  }
  matrix[n-1][0] = 0;
  matrix[n-1][1] = 0;
  matrix[n-2][0] = abs(arr[n-1]-arr[n-2]);
  matrix[n-2][1] = 22222222;

  for(int j = n-3; j >= 0; j--){
    for(int h = 0; h < 2; h++){
      matrix[j][h] = abs(arr[j] - arr[j+h+1]) + min(matrix[j+1+h][0],matrix[j+1+h][1]);
    }
  }

  cout << min(matrix[0][0], matrix[0][1]);

}


Measured memory_bytes: 1408
using System;

public class Hello
{
    public static void Main()
    {
		string[] line = Console.ReadLine().Trim().Split(' ');
		var n = int.Parse(line[0]);
		var k = int.Parse(line[1]);
		var s = Console.ReadLine().Trim();
		var s2 = s.ToCharArray();
		var cc = s2[k - 1].ToString().ToLower();
		s2[k - 1] = cc[0];
		var ans = new string(s2);
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
b = sum(a)
count = 0
ans = False
for i in range(n):
    if a[i]/b >= 1/(4*m):
        count += 1
    if count == m:
        ans = True
        break
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  int n;
  string s;
  cin >> n >> s;
  vector<int> v(n+1,0);
  rep1(i,n){
    int x;
    if(s[i-1] == 'I') x = 1;
    if(s[i-1] == 'D') x = -1;
    v[i] = v[i-1] + x;
  }
  cout << vecmax(v) << endl;
}

Measured memory_bytes: 256
import math

line = input().split(" ")
capture = int(line[0])
blue = int(line[1])
red = int(line[2])

amari = capture % (blue + red)
waru = math.floor(capture / (blue + red))

if amari > blue:
	print(blue * waru + blue)
else:
    print(blue * waru + amari)

Measured memory_bytes: 3060
m=[0]*5
for i in range(int(input())):
        try: m["MARCH".index(input()[0])]+=1
        except: continue
ans = 0
for i in range(5):
        for j in range(i+1,5):
                for k in range(j+1, 5):
                        ans += m[i]*m[j]*m[k]
print(ans)

Measured memory_bytes: 3060
n, k = gets.split(" ").map(&:to_i)

divided_numbers = []
0.upto(18) do |num|
  divided_numbers.push(k / (2 ** num).to_f)
end
divided_numbers.each_with_index do |num, index|
  divided_numbers[index] = num.ceil
end
# puts divided_numbers
chances = []
0.upto(18) do |num|
  chances.push(1 / (2 ** num).to_f)
end
# puts chances
multiply_times = []
last_number = false
18.times do |num|
  if last_number == false
  multiply_times[num] = n - divided_numbers[num] + 1
    if multiply_times[num] < 0
      multiply_times[num] = 0
    end
    if multiply_times[num] > 0
      last_number = true
    end
  elsif last_number == true
    multiply_times[num] = divided_numbers[num - 1] - divided_numbers[num]
  end
end
# puts multiply_times
sum = 0.0

18.times do |num|
  sum += chances[num] * multiply_times[num]
end
sum /= n

puts sum

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, c;

	cin >> n;

	ll ans = 0;

	vector<ll> v(n);

	REP(i, n) {
		cin >> v[i];
	}

	REP(i, n) {
		cin >> c;
		ans += max((ll)0, v[i] - c);
	}

	cout << ans << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll f(ll in) {
    if(in < 10) {
        ll ans = 0;
        for(ll i = 0; i <= in; i++) ans = ans ^ i;
        return ans;
    }
    ll beki = 1;
    while(beki * 2 < in) beki *= 2;
    if((in - beki) % 2 == 0) return beki + (f(in - beki));
    return f(in - beki);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    cout <<(f(B) ^ f(A - 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
public static void main(String[]args){
	Scanner sc = new Scanner(System.in);
	
	int a = sc.nextInt();
	int b = sc.nextInt();
	int area = a*b;
	int length = 2*a +2*b;
	System.out.println(area + " " + length);
}
}

Measured memory_bytes: 26088
H, W = map(int, input().split())
board = []
black = "#"
white = "."
for _ in range(H):
    board.append(input())

flags = [[False for _ in range(W)] for _ in range(H)]
has_alternative_around = [[False for _ in range(W)] for _ in range(H)]

deltas = [(1, 0), (-1, 0), (0, 1), (0, -1)]

for i in range(H):
    for j in range(W):
        for dx, dy in deltas:
            ni = i + dx
            nj = j + dy
            if \
            ni >= 0 \
            and ni < H \
            and nj >= 0 \
            and nj < W \
            and board[i][j] != board[ni][nj]:
                has_alternative_around[i][j] = True
                has_alternative_around[ni][nj] = True

ans = 0

for i in range(H):
    for j in range(W):
        if flags[i][j] is True \
        or has_alternative_around[i][j] is False:
            continue
        else:
            flags[i][j] = True
            reachable = 1
            n_black = 0
            n_white = 0
            if board[i][j] == black:
                n_black = 1
            else:
                n_white = 1
            visit = []
            for dx, dy in deltas:
                ni = i + dx
                nj = j + dy
                if \
                ni >= 0 \
                and ni < H \
                and nj >= 0 \
                and nj < W \
                and has_alternative_around[ni][nj] is True \
                and board[i][j] != board[ni][nj] \
                and flags[ni][nj] is False:
                    visit.append( (ni, nj) )
                    flags[ni][nj] = True
                    reachable += 1
                    if board[ni][nj] == black:
                        n_black += 1
                    else:
                        n_white += 1
            while len(visit) != 0:
                visit_info = visit.pop()
                prev_i = visit_info[0]
                prev_j = visit_info[1]
                for dx, dy in deltas:
                    ni = prev_i + dx
                    nj = prev_j + dy
                    if \
                    ni >= 0 \
                    and ni < H \
                    and nj >= 0 \
                    and nj < W \
                    and has_alternative_around[ni][nj] is True \
                    and board[prev_i][prev_j] != board[ni][nj] \
                    and flags[ni][nj] is False:
                        visit.append( (ni, nj) )
                        flags[ni][nj] = True
                        reachable += 1
                        if board[ni][nj] == black:
                            n_black += 1
                        else:
                            n_white += 1
            if reachable >= 2:
                ans += n_black * n_white

print(ans)

Measured memory_bytes: 13388
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;


int main() {
    
    int n;
    cin>>n;
    int k;
    cin>>k;
    rep(i,1LL<<n){
        int co=0;
        rep(j, 19) {
            co+=(i&(1LL<<j))>0;
        }
        if(co!=k)continue;
        
        cout<<i<<":";
        rep(j, 29) {
            if(i&(1LL<<j)){
                cout<<" "<<j;
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3116
#include <stdio.h>

void insertionSort(int targetArray[], int size)
{
        for (int i = 1; i < size; i++)
        {
                int currentNumber = targetArray[i];

                int j = i - 1;
                int foreNumber = targetArray[j];

                while (j >= 0 && targetArray[j] > currentNumber)
                {
                        targetArray[j + 1] = targetArray[j];
                        j--;
                        targetArray[j + 1] = currentNumber;
                }

                for (int j = 0; j < size; ++j)
                {
                        if (j == 0)
                                printf("%d", targetArray[j]);
                        else
                                printf(" %d", targetArray[j]);
                }
                putchar('\n');
        }
}

int main()
{
        int size;

        scanf("%d", &size);

        int targetArray[size];

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

        for (int j = 0; j < size; ++j)
                {
                        if (j == 0)
                                printf("%d", targetArray[j]);
                        else
                                printf(" %d", targetArray[j]);
                }
                putchar('\n');

        insertionSort(targetArray, size);

        return 0;
}


Measured memory_bytes: 2132
import java.util.Scanner;

public class Main {

	int min = Integer.MAX_VALUE;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long sum =0;
		for (long i=K;i<=N+1;i++) {
			long min = (i-1)*i/2;
			long max = (N+N-i+1)*i/2;
			long temp = (max-min+1)%1000000007l;
			sum = (sum+temp)%1000000007l;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 35836
#include <iostream>
#include <queue>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

const int MAX_N = 100000;
const int MAX_M = 100000;
const long long FIRST_YEN = 1000000000000000;

void dijkstra(int n, vector<pair<int, int>> G[MAX_N + 1], int start, long long dist[MAX_N + 1]);

int main() {
    int n, m, s, t, u[MAX_M], v[MAX_M], a[MAX_M], b[MAX_M];
    cin >> n >> m >> s >> t;
    for (int i = 0; i < m; i++) cin >> u[i] >> v[i] >> a[i] >> b[i];

    vector<pair<int, int>> yen[MAX_N + 1], snuuk[MAX_N + 1];
    for (int i = 0; i < m; i++) {
        yen[u[i]].push_back(make_pair(v[i], a[i]));
        yen[v[i]].push_back(make_pair(u[i], a[i]));
        snuuk[u[i]].push_back(make_pair(v[i], b[i]));
        snuuk[v[i]].push_back(make_pair(u[i], b[i]));
    }

    long long dist_s2i[MAX_N + 1];
    long long dist_i2t[MAX_N + 1];
    dijkstra(n, yen, s, dist_s2i);
    dijkstra(n, snuuk, t, dist_i2t);

    pair<long long, int> dist_s2t[MAX_N + 1];
    for (int i = 1; i <= n; i++) {
        dist_s2t[i] = make_pair(dist_s2i[i] + dist_i2t[i], i);
    }
    sort(dist_s2t + 1, dist_s2t + n + 1);

    long long max_snuuk[MAX_N];
    int ms_i = 0;
    int d_i = 1;
    while (ms_i < n) {
        bool hoge = false;
        for (int i = ms_i; i < dist_s2t[d_i].second; i++) {
            max_snuuk[i] = FIRST_YEN - dist_s2t[d_i].first;
            hoge = true;
        }
        if (hoge) ms_i = dist_s2t[d_i].second;
        d_i++;
    }

    for (int i = 0; i < n; i++) {
        cout << max_snuuk[i] << endl;
    }
    return 0;
}

void dijkstra(int n, vector<pair<int, int>> G[MAX_N + 1], int start, long long dist[MAX_N + 1]) {
    // initialize distance
    for (int i = 1; i <= n; i++) dist[i] = FIRST_YEN;

    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> Q;
    Q.push(make_pair(0, start));
    dist[start] = 0;
    while (!Q.empty()) {
        int pos = Q.top().second; Q.pop();
        for (int i = 0; i < G[pos].size(); i++) {
            int to = G[pos][i].first, cost = G[pos][i].second;
            if (dist[to] > dist[pos] + cost) {
                dist[to] = dist[pos] + cost;
                Q.push(make_pair(dist[to], to));
            }
        }
    }

    return;
}

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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define insert ins
#define ers erase
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

int main() {
	
	fastio;

    rd2(ll, n, m);
    vc(string, str);
    
    string s1 = "", s2 = "";
    
    FOR(i, 0, n) 
        s1 += to_string(m);

    FOR(i, 0, m) 
        s2 += to_string(n);
    
    str.pb(s1);
    str.pb(s2);
    
    for(int i = 0; i < 1; ++i)
       for( int j = i + 1; j < 2; ++j)
       {
          if(str[i] > str[j])
          {
            string temp = str[i];
            str[i] = str[j];
            str[j] = temp;
          }
    }
    
    cout << str[0] << endl;
    
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    X, Y = map(int, input().split())

    ans = 0

    while X <= Y:
        X *= 2
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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


long long int  func(long long int n, long long int r) 
{ 

 
  long long int p = 1, k = 1; 

  
  if (n - r < r) 
    r = n - r; 

  if (r != 0) { 
    while (r) { 
      p = 1LL*p*n; 
      k = 1LL*k*r; 

      // gcd of p, k 
      long long int m = __gcd(p, k); 

      // dividing by gcd, to simplify product 
      // division by their gcd saves from the overflow 
      p /= m; 
      k /= m; 

      n--; 
      r--; 
    } 
  } 

  else
    p = 1; 

   return p;
} 


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
          int count;
      cin>>count;
      vector<long long int>nish1,nish2;
      for(int i=0;i<count;i++)
      {
        long long int a,b;
        cin>>a>>b;
        nish1.push_back(a);
        nish2.push_back(b);
      }

      sort(nish1.begin(),nish1.end());
      sort(nish2.begin(),nish2.end());

      long long int x,y;
      if(count%2==1)
      {
        x=nish1[count/2];
        y=nish2[count/2];
      }
      else
      {
        x=nish1[(count/2)-1]+nish1[count/2];
        y=nish2[(count/2)-1]+nish2[count/2];
      }

      cout<<y-x+1<<endl;
    return 0;
}


Measured memory_bytes: 6688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll LCM(ll a , ll b){
	return ((a * b) /__gcd(a , b));
}
int main()
{
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	ll R = B - A + 1;
	ll divC = B / C - (A - 1) / C;
	ll divD = B / D - (A - 1) / D;
	ll ans = R - (divC + divD - (B / LCM(C, D) - (A - 1) / LCM(C, D)));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<stdlib.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)

#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
//#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
typedef pair<int,int> pii;
ll INF=1<<28;
//typedef long long lld;
const double PI=acos(-1.0);
//int fx[]={1,-1,0,0}; //direction array
//int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000

struct compare
{
  bool operator()(const pair<int,pii>& l, const pair<int,pii>& r)
  {
      if(l.ff==r.ff)
      {
          return l.sn.ff>r.sn.ff;
      }
      return l.ff<r.ff;
  }
};
// bool operator<(pair<int,pii> l, pair<int,pii> r)
//  {
//      if(l.ff==r.ff)
//      {
//          cout<<"ok "<<endl;
//          return l.sn.ff<r.sn.ff;
//      }
//      return l.ff>r.ff;
//  }

/////////////////////////////////////template sesh/////////////////////////////////////////////////////

///code goes from here
const int mx=1000150;
///
ll mod=1e9+7;
ll arr[mx];

int main()
{
//    SPEED;
    int t,tc=1;
//    sf(t);
    t=1;
    while(t--)
    {
        ll x,k,d;
        sl3(x,k,d);
        if(x<0)
            x*=-1LL;
        ll lagbe=x/d;
        if(lagbe>=k)
        {
            x-=(k*d);
            cout<<x<<endl;
        }
        else
        {
            x-=(lagbe*d);
            k-=lagbe;
            k%=2;
            if(k)
            {
                x-=d;
            }
            if(x<0)
                x*=-1LL;
            cout<<x<<endl;
        }
    }


    return 0;
}



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

using namespace std;

int main() {
  string str;

  cin >> str;

  int res = 1;
  string prev(str.begin(), str.begin() + 1);
  for (int i = 1; i < str.length();) {
    bool brk = true;

    for (int j = i + 1; j <= str.length(); j++) {
      string tmp(str.begin() + i, str.begin() + j);

      if (prev != tmp) {
        res++;
        prev = tmp;
        i = j;
        brk = false;
        break;
      }
    }

    if (brk) {
      break;
    }
  }

  cout << res << endl;
}

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

using namespace std;

#define mp make_pair
#define all(x) x.begin(), x.end()
#define up(x, v) upper_bound(all(x), v)
#define low(x, v) lower_bound(all(x), v)
#define bin(x, v) binary_search(all(x), v)
#define FOR(k, a, b) for(int k = (a); k < (b); ++k)
#define ROF(k, a, b) for(int k = (a); k > (b); --k)
#define pq priority_queue

#define EPS 1.0e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

int main() {

	int n;
	bool approved = true;

	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n;

	FOR(k, 0, n) {

		int x;

		cin >> x;

		if(x % 2 == 0 && x % 3 && x % 5)
			approved = false;
	}

	if(approved)
		cout << "APPROVED\n";

	else
		cout << "DENIED\n";


    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := ReadInt()
	A1 := ReadInts(N)
	A2 := ReadInts(N)
	s1 := make([]int, N+1)
	s2 := make([]int, N+1)
	for i := 0; i < N; i++ {
		s1[i+1] = s1[i] + A1[i]
		s2[i+1] = s2[i] + A2[i]
	}
	max := -1
	for i := 0; i < N; i++ {
		max = Max(max, s1[i+1]+s2[N]-s2[i])
	}
	fmt.Println(max)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

const int inf = 1e9+7;
int a[100007];
int main(){
	int n,t;
	long long ans = 1;
	
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> t;
		a[t]++;
	}
	
	if(n&1){
		for(int i = n-1;i>=0;i-=2){
			if(i&&a[i]==2){
				ans*=2;
				ans%=inf;
			}
			else if(i){
				cout << 0;
				return 0;
			}
			else if(!i&&a[i]==1){
				cout << ans;
				return 0;
			}
		}
	}
	else{
		for(int i = n-1;i>=1;i-=2){
			if(a[i]==2){
				ans*=2;
				ans%=inf;
			}
			else{
				cout << 0;
				return 0;
			}
		}
		cout << ans;
	}
}

Measured memory_bytes: 640
from collections import Counter

def choose(n):
    return n * (n - 1) // 2


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    cnt = 0
    for c in C.values():
        cnt += choose(c)

    for a in A:
        ans = cnt
        ans -= choose(C[a])
        ans += choose(C[a] - 1)
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26780
import heapq


def main():
    V, E, r = map(int, input().split())
    G = [[] for _ in range(V)]
    P = [1e10]*V
    for _ in range(E):
        s, t, d = map(int, input().split())
        G[s].append((d, t))

    q = []
    heapq.heapify(q)
    heapq.heappush(q, (0, r))
    fixed = [0]*V
    while q:
        v = heapq.heappop(q)
        if P[v[1]] > v[0]:
            P[v[1]] = v[0]
        fixed[v[1]] += 1
        for g in G[v[1]]:
            if not fixed[g[1]]:
                dist = g[0] + P[v[1]]
                P[g[1]] = dist
                heapq.heappush(q, (dist, g[1]))

    for p in P:
        if p == 1e10:
            print("INF")
        else:
            print(p)


if __name__ == '__main__':
    main()



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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ld n, m, d;

	cin >> n >> m >> d;

	cout << fixed << setprecision(10) << 2 * (n - d) * (m - 1) / (n * n) / (d ? 1 : 2 ) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    char s[10];
    int ac=0, wa=0, tle=0, re=0;

    for(int i=0;i<n;i++){
        scanf("%s", s);
        if('A' == s[0]){
            ac++;
        }else if('W' == s[0]){
            wa++;
        }else if('T' == s[0]){
            tle++;
        }else{
            re++;
        }
    }

    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", ac, wa, tle, re);

    return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

const int INF = 1 << 30;

typedef long long ll;
struct Rosen{
	string from;
	string to;
	int d, t;
};
int tbl[505][505];

int stoi (string name, map<string, int> taio )
{
	map<string, int>::iterator it = taio.begin();
	for (; it != taio.end(); it++ ){
		if ((*it).first == name ){
			return (*it).second;
		} // end if
	} // end for

	return -1;
}

int dijkstra (int from, int to, int n )
{
	vector <int> len (n, INF );
	vector <bool> v (n, false );
	len[from] = 0;
	int minlen = 0;

	do{
		minlen = INF;
		int p;

		for (int i = 0; i < n; i++){
			if (!v[i] && len[i] < minlen ){
				minlen = len[i];
				p = i;			
			} // end if
		} // end for
		
		v[p] = true;	// ツつアツつアツづ慊づづ債づ慊づつスツつュツ督ッツつカ

		for (int i = 0; i < n; i++){
			if (len[p] + tbl[p][i] < len[i] ){
				len[i] = len[p] + tbl[p][i];
			} // end if
		} // end for
	} while (minlen != INF);// end while

	int res = len[to];

	return res;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.s18k", "r", stdin );
	int n, m;
	while (cin >> n >> m && n && m ){
//		memset (tbl, INF, sizeof (tbl ) );
		for (int i = 0; i <= 501; i++ )
			for (int j = 0; j <= 501; j++ )
				tbl[i][j] = INF;

		string start, tochu, end;
		cin >> start >> tochu >> end;

		vector <Rosen> r(m );
		set <string> name;
		for (int i = 0; i < m; i++ ){
			cin >> r[i].from >> r[i].to >> r[i].d >> r[i].t;
			name.insert (r[i].from );
			name.insert (r[i].to );
		} // end for
		map <string, int> taio;
		set <string>::iterator it = name.begin();
		for (int i = 0; it != name.end(); it++, i++ ){
			taio[(*it)] = i;
		} // end for
			
		for (int i = 0; i < m; i++ ){		
			int from = stoi(r[i].from, taio );
			int to = stoi (r[i].to, taio );
			int d = r[i].d/40 + r[i].t;
			tbl[from][to] = d;
			tbl[to][from] = d;
		} // end for
		int res = dijkstra (stoi (start, taio ), stoi (tochu, taio ), n );
		res += dijkstra (stoi (tochu, taio ), stoi (end, taio ), n );
		cout << res << endl;
	} // end loop

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

Measured memory_bytes: 2372
object Main {
    def queens(n: Int, list: List[(Int, Int)]): List[List[(Int, Int)]] = {
        def placeQueens(k: Int): List[List[(Int, Int)]] = {
            if(k == -1) List(List())
            else
                for {
                    queens <- placeQueens(k - 1)
                    col <- 0 to n - 1
                    queen = (k, col)
                    if isSafe(queen, queens)
                } yield queen :: queens
        }
         placeQueens(n - 1).filter(qs => check(list, qs))
    }

    def isSafe(queen: (Int, Int), queens: List[(Int, Int)]) = {
        queens.forall(q => !inCheck(queen, q))
    }

    def inCheck(q1: (Int, Int), q2: (Int, Int)) = {
        q1._1 == q2._1 ||
        q1._2 == q2._2 ||
        (q1._1 - q2._1).abs == (q1._2 - q2._2).abs
    }

    def check(list: List[(Int, Int)], queens: List[(Int, Int)]): Boolean = list.forall(q => queens.contains(q))

    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val list = List.fill(n)(sc.nextInt, sc.nextInt)
        for(qs <- queens(8, list)) {
            for(y <- 0 to 7) {
                for(x <- 0 to 7) {
                    print(if(qs.contains((y, x))) "Q" else ".")
                }
                println
            }
        }
    }
}

Measured memory_bytes: 50876
#include <stdio.h>
long bucket[200000] = {0};
long A[200000] = {0};

long nC2(long n){
    return n*(n-1)/2;
}

long main(){
    long N;
    long i, k;
    long buf;
    scanf("%ld", &N);
    for(i=0; i<N; i++){
        scanf("%ld", &buf);
        bucket[(A[i] = buf-1)]++;
    }
    long ans=0;
    for(i=0; i<N; i++){
        if(bucket[i]){
            ans += nC2(bucket[i]);
        }
    }
    for(k=0; k<N; k++){
        printf("%ld\n", ans-(bucket[A[k]]-1));
    }
    return 0;
}

Measured memory_bytes: 4608
import math
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

Measured memory_bytes: 67804
#include<bits/stdc++.h>
#define ll  long long int
#define db long double 
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005
 
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // compute();
    int tests=1;
    // cin>>tests;    
    while(tests--)
    {
    	ll i,j,n,m,x;
    	cin>>n>>x>>m;
    	x%=m;
    	map<ll,ll>mpp;
    	mpp[x]=1;
    	vector<ll>v;
    	v.pb(0);
    	v.pb(x);
    	ll period=-1;
    	ll cnt=1;
    	while(true)
    	{
    		x*=x;
    		x%=m;
    		// cout<<"-->"<<x<<"\n";
    		if(mpp.find(x)!=mpp.end())
    		{
    			period=v.size()-mpp[x];
    			break;
    		}
    		else
    		{
    			mpp[x]=v.size();
    			v.pb(x);
    		}
    		cnt++;
    		if(cnt==n) break;
    	}

    	// cout<<period<<"\n";

    	if(period==-1)
    	{
    		ll ans=0;
    		for(auto x:v) {ans+=x;}
    		cout<<ans;
    		return 0;
    	}

    	vector<ll>c;

    	cnt=0;
    	ll persum=0;
    	while(cnt<period)
    	{
    		c.pb(v.back());
    		persum+=v.back();
    		// persum%=m;
    		v.pop_back();
    		cnt++;
    	}
    	ll ans=0;
    	n-=v.size()-1;
    	for(auto x:v) {ans+=x;}

    	ans+=((n/period)*(persum));
    	// ans%=m;
    	n%=period;
    	reverse(all(c));
    	rep(i,0,n-1)
    	{
    		ans+=c[i];
    		// ans%=m;
    	}

    	cout<<ans;

    }

    return 0;
}
    

Measured memory_bytes: 7384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
typedef long long ll;
using namespace std;

ll co = 0;
ll ten = 10;

ll getfive(ll N)
{
    while(N >= ten)
    {
        co += N/ten;
        ten *= 5;
    }
    return (co);
}


int main()
{
    ll N;
    cin >> N;
    if (N % 2 != 0)
    {
        cout << 0 << endl;
        return(0);
    }

    cout <<getfive(N) << endl;
}

Measured memory_bytes: 380
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

ll n;

char f() {
	int x = n % 26;
	n -= x;
	n /= 26;
	if (x == 0) {
		n--;
		return 'z';
	}
	return 'a' + x - 1;
}

int main() {
	cin >> n;
	string s;
	while (n != 0) {
		s.push_back(f());
	}
	REVERSE(s);
	cout << s << endl;
}






Measured memory_bytes: 3720
#include <iostream>

int main()
{
    int A, B;
    std::cin >> A >> B;
    if (A > 8 || B > 8) {
        std::cout << ":(" << std::endl;
    }
    else {
        std::cout << "Yay!" << std::endl;
    }
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  rep(i, n) cin >>h.at(i);
  rep(i, m){
    int a, b;
    cin >>  a >> b;
    a--; b--;
    if(h.at(a)<=h.at(b))  ok.at(a) = false;
     if(h.at(b)<=h.at(a))  ok.at(b) = false;
  }
  int ans = 0;
  rep(i,n){
    if(ok.at(i) == true) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3788
import java.util.Scanner;

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

        while(sc.hasNext()) {
            long a = Long.parseLong(sc.next());
            long b = Long.parseLong(sc.next());
            long g = gcd(a, b);

            System.out.println(g + " " + (a / g * b));
        }
    }

    private static long gcd(long a, long b) {
        if (a < b) {
            a ^= b;
            b ^= a;
            a ^= b;
        }
        
        while (b != 0) {
            long r = a % b;
            a = b;
            b = r;
        }
        
        return a;
    }
}

Measured memory_bytes: 25628
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

ull gcd(ull a, ull b){
    if(b == 0){ return a;}
    else {
        return gcd(b, a % b);
    }
}

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

    ull all = B - A + 1;

    ull divC = B / C - (A-1) / C;
    ull divD = B / D - (A-1) / D;
    ull CD = C*D/gcd(max(C,D) , min(C,D));
    ull divCD = B/CD - (A-1)/CD;

    cout << all - (divC + divD - divCD) << endl;
}


Measured memory_bytes: 3624
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N);
    for(int i=0; i<N; i++) cin >> H[i];
    vector< vector<int> > G(N);
    for(int i=0; i<M; i++) {
        int u, v; scanf("%d%d", &u, &v);
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    int ans = 0;
    for(int i=0; i<N; i++) {
        bool highest = true;
        for(auto j : G[i]) {
            highest &= (H[i] > H[j]);
        }
        ans += highest;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8868