akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int arra[200007];

ll combination(ll n){
    return (n*(n-1))/2;
}

int main(){
    ll n, x, i, sum=0, temp;
    cin >> n;
    map<int, int>m;
    map<int, int>::iterator it;
    vector<int>v;
    for(i=0; i<n; i++){
        cin >> x;
        arra[x]++;
        m[x] = arra[x];
        v.push_back(x);
    }
    for(it=m.begin(); it!=m.end(); it++){
        temp = it->second;
        sum += combination(temp);
    }
    for(i=0; i<v.size(); i++){
        temp = m[v[i]];
        cout << sum - combination(temp) + combination(temp-1) << endl;
    }
    return 0;
}

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

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

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	vector<pair<int, int>> pos;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				pos.emplace_back(i, j);
			}
		}
	}
	int cnt = -1;
	while (!pos.empty()) {
		vector<pair<int, int>> tmp;
		for (auto p : pos) {
			int x, y; tie(x, y) = p;
			for (int i = 0; i < 4; i++) {
				int tx = x + dx[i], ty = y + dy[i];
				if (0 <= tx && tx < H && 0 <= ty && ty < W && S[tx][ty] != '#') {
					S[tx][ty] = '#';
					tmp.emplace_back(tx, ty);
				}
			}
		}
		pos = move(tmp);
		++cnt;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 14468
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

int n;

double d(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}

int fact(int i)
{
    if(i==1)return 1;
    return i*fact(i-1);
}

main()
{
    vi v(81);

    rep2(i,1,10)
    {
        rep2(j,1,10)
        {
            v.push_back(i*j);
        }
    }

    int a;
    cin>>a;
    each(it,v)
    {
        if(it==a)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long
int inf = (1LL <<  62);
using namespace std;

signed main(){
    string s;
    cin >> s;
    int n = s.size() - 1;
    int ans = 0;
    for(int i = 0; i < (1 << n); i++){
        int start = 0;
        int sum = 0;
        for(int j = 0; j < n; j++){
            if(i & (1 << j)){
                sum += stoll(s.substr(start, j - start + 1));
                start = j + 1;
            }
        }
        sum += stoll(s.substr(start, n + 1 - start));
        ans += sum;
    }
    cout << ans;
}

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

const int N = 1e6 + 5;

#define st first
#define nd second
#define make(a,b) make_pair(a,b)

typedef pair<int,int> pun;
typedef long long ll;

long long tab[N];
long long res[N];
long long MAX = 10000LL * 10000LL * 10000LL * 10000LL + 1000;

int main()
{
	long long k = 0;
	scanf("%lld", &k);
	if (k == 0) {
		printf("2\n0 0\n");
		return 0;
	}
	int n = max(2LL, (k + MAX - 1) / MAX);
	for (int i = 0; i < n; i ++) {
		tab[i] = MAX;
	}
	long long wynik = 0;
	while (true) {
		long long ile = 0;
		long long wklad = 0;
		for (int i = 0; i < n && wynik + ile < k; i ++) {
			wklad = min(tab[i] / n, k - wynik - ile);
			tab[i] -= wklad * n;
			tab[i] -= wklad;
			ile += wklad;
		}
		wynik += ile;
		for (int i = 0; i < n; i ++) {
			tab[i] += ile;
		}
		if (wynik == k) {
			bool OK = true;
			for (int i = 0; i < n; i ++) {
				res[i] = MAX - (tab[i] - n + 1);
				if (res[i] < 0) {
					OK = false;
					wynik = 0;
					MAX /= 2;
					for (int i = 0; i < n; i ++) {
						tab[i] = MAX;
					}
				}
			}
			if (OK) break;
		}
		if (ile == 0) {
			wynik = 0;
			n ++;
			for (int i = 0; i < n; i ++) {
				tab[i] = MAX;
			}
		}
	}
	printf("%d\n", n);
	for (int i = 0; i < n; i ++)
	printf("%lld ", res[i]);
	printf("\n");
}


Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,int> table;

#if 0
所用時間:

感想:

#endif

void solve(){
  // typedef set<int> size_t;
  string word, frequent, longest;
  int N = 0;
  while(cin >> word){
    table[word] += 1;
    if(table[word] > N){
      frequent = word; N = table[word];
    }
    if(word.size() > longest.size()){
       longest = word;
    }
  }
  cout << frequent << " " << longest << endl;
}

int main(){
  solve();
}



Measured memory_bytes: 2992
from itertools import permutations, product

N,C = map(int,input().split())
DM = [list(map(int, input().split())) for i in range(C)]

CM = [list(map(int, input().split())) for i in range(N)]

MODN = 3
# http://sonickun.hatenablog.com/entry/2014/06/13/132821
Cnum =  [[0 for i in range(C)] for j in range(MODN)]

# mod3に応じて、各色の個数をカウント
for i,j in product(range(N), range(N)):
  Cnum[(i+j)%MODN][CM[i][j] - 1] += 1

# mod3ごとの色番号をpermutationで全通り洗い出して、コスト全計算
ans = 1e9
for p,q,r in permutations(range(C), 3):
  cost = 0
  #print(p,q,r)
  for i in range(C):
    cost += Cnum[0][i] * DM[i][p] + Cnum[1][i] * DM[i][q] + Cnum[2][i] * DM[i][r]
  ans = min(ans, cost)
  
print(ans)


Measured memory_bytes: 5620
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

	int W, D;
	int[] ws, ds;

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			W = in.nextInt();
			D = in.nextInt();
			if(W==0 && D==0) return ;
			ws = new int[W];
			ds = new int[D];
			for(int i=0; i<W; i++){
				ws[i] = in.nextInt();
			}
			for(int i=0; i<D; i++){
				ds[i] = in.nextInt();
			}
			System.out.println(solve());
		}
	}

	int solve(){
		int[][] board = new int[W][D];
		sort(ws);
		sort(ds);
		board[W-1][D-1] = ws[W-1];

		for(int p=W-2, q=D-2;p>=0 || q>=0;){
			int nw = p>=0?ws[p]:ds[q], nd = q>=0?ds[q]:ws[p];
			if(nw == nd){
				board[max(p,0)][max(q,0)] = nw;
				p--; q--;
			}
			else if(nw > nd){
				board[p][D-1] = nw;
				p--;
			}
			else if(nd > nw	){
				board[W-1][q] = nd;
				q--;
			}
		}

		int ret = 0;
		for(int i=0; i<W; i++){
			for(int j=0; j<D; j++){
				ret += board[i][j];
			}
		}

		return ret;
	}

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

Measured memory_bytes: 12000
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define cdbg cerr << "Debug in " << __func__ << ", " << __LINE__ << ": "

#define q <<  '\n'
#define sp << ' '
#define pb emplace_back
#define ft first
#define sd second
#define ld long double
#define ll long long
#define ull unsigned long long
#define lll __int128
#define pii pair<int , int>
#define vi vector<ll>
using namespace std;
const ll INF = 1e8;
const ll N = 1000;

ll n,m,c,ans,res,brr[1000001], arr[1000001];
main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m >> c;
    for (int i = 0 ; i < m; i++)
    {
        cin >> brr[i];
    }

    for (int i = 0 ; i < n; i++)
    {
        for  (int j = 0; j < m; j++)
        {
            cin >> arr[j];
            res += arr[j] * brr[j];
        }
        if (res + c > 0) ans++;
        res = 0;
    }
    cout << ans q;





















































}



Measured memory_bytes: 2304
# -*- coding: utf-8 -*-
from math import sin, cos, pi



def koch(d, p1, p2):
    if d == 0:
        return

    s = [None, None]
    u = [None, None]
    t = [None, None]
    
    s[0] = (2*p1[0] + p2[0])/3
    s[1] = (2*p1[1] + p2[1])/3
    t[0] = (p1[0] + 2*p2[0])/3
    t[1] = (p1[1] + 2*p2[1])/3
    u[0] = (t[0] - s[0])*cos(1/3*pi) - (t[1] - s[1])*sin(1/3*pi) + s[0]
    u[1] = (t[0] - s[0])*sin(1/3*pi) + (t[1] - s[1])*cos(1/3*pi) + s[1]

    koch(d-1, p1, s)
    print(s[0], s[1])
    koch(d-1, s, u)
    print(u[0], u[1])
    koch(d-1, u, t)
    print(t[0], t[1])
    koch(d-1, t, p2)

if __name__ == '__main__':

    n = int(input())
    a = [0, 0]
    b = [100, 0]

    print(a[0], a[1])
    koch(n ,a ,b)
    print(b[0] ,b[1])

    


Measured memory_bytes: 5784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int n, int m, long[] X, long[] Y)
        {
            long x = 0;
            long y = 0;
            for (int i = 0, k = -n + 1; i < n; ++i, k += 2)
            {
                x += X[i] * k;
                x %= MODULO;
            }
            for (int i = 0, k = -m + 1; i < m; ++i, k += 2)
            {
                y += Y[i] * k;
                y %= MODULO;
            }
            return ((x * y) % MODULO + MODULO) % MODULO;
        }
        static void Main(string[] args)
        {
            int[] values = ReadInts();
            long[] X = ReadLongs();
            long[] Y = ReadLongs();
            Console.WriteLine(Solve(values[0], values[1], X, Y));
        }
    }
}


Measured memory_bytes: 33372
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  string S;cin>>S;
  
  for(int i=0;i<S.size();i++){
    S.at(i)='x';
    cout<<S.at(i);
  }
  cout<<endl;
}
  

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d", &n);
    
    if(n == 1){
        printf("%d\n", 2);
    }else{
        if(n % 2 == 0){
            printf("%d\n", n);
        }else{
            printf("%d", n * 2);
        }
    }
}

Measured memory_bytes: 128
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func getStirlingType2(n, k, p int) [][]int {
	table := make([][]int, n+1)
	table[1] = make([]int, k+1)
	table[1][1] = 1
	for i := 2; i <= n; i++ {
		table[i] = make([]int, k+1)
		for j := 1; j <= k; j++ {
			table[i][j] = (table[i-1][j-1] + j*table[i-1][j]) % p
		}
	}
	return table
}

func main() {
	scanner.Split(bufio.ScanWords)

	prime := 1000000000 + 7

	nBalls := nextInt()
	nBoxes := nextInt()

	table := getStirlingType2(nBalls, nBoxes, prime)
	// fmt.Println(table)

	nCombinations := 0
	for k := 1; k <= nBoxes; k++ {
		nCombinations = (nCombinations + table[nBalls][k]) % prime
	}
	fmt.Println(nCombinations)
}



Measured memory_bytes: 9776
#include <iostream>

using namespace std;
int main(void){
    // Here your code !
int n;

while(cin>>n){
bool flag=false;

for(int i=1;i<=512;i=i*2){

if(n%(i*2)!=0){
    if(flag) cout<<" ";
    flag=true;
    cout<<i;
    n=n-i;
}
}

cout<<endl;
}
return 0;
}

Measured memory_bytes: 1160
import itertools

def test():
    n = int(input())
    ans = 0
    name = [0] * 5
    for i in range(n):
        s = input()
        if s[0] == "M":
            name[0] += 1
        elif s[0] == "A":
            name[1] += 1
        elif s[0] == "R":
            name[2] += 1
        elif s[0] == "C":
            name[3] += 1
        elif s[0] == "H":
            name[4] += 1

    for x,y,z in itertools.combinations(name,3):
        ans += x*y*z
    print(ans)


if __name__ == "__main__":
    test()


Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
t = (a+9)//10*10+(b+9)//10*10+(c+9)//10*10+(d+9)//10*10+(e+9)//10*10
if a%10 == 0:
    aa = 10
else:
    aa = a%10
if b%10 == 0:
    bb = 10
else:
    bb = b%10
if c%10 == 0:
    cc = 10
else:
    cc = c%10
if d%10 == 0:
    dd = 10
else:
    dd = d%10
if e%10 == 0:
    ee = 10
else:
    ee = e%10
m = min(aa,min(bb,min(cc,min(dd,ee))))
print(t+m-10)

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

signed main(){
    string S;
    cin >>S;
    sort(S.begin(),S.end());
    if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[3]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
    string S;
    cin >> S;
    stack <char> s;
    for (char c : S){
        if (c == 'S') s.push(c);
        else {
            if (!s.empty() && s.top() == 'S') s.pop();
            else s.push('T');
        }
    }
    cout << (int)s.size() << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 644
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>

#define long long long int

using std::vector;
using std::map;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

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

    vector<vector<bool>> b(n - 1, vector<bool>(m - 1));
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < m - 1; j++) {
            b[i][j] = !(a[i][j] ^ a[i + 1][j] ^ a[i][j + 1] ^ a[i + 1][j + 1]);
        }
    }

    vector<int> h(m - 1);
    int res = std::max(n, m);
    for (int i = 0; i < n - 1; i++) {
        vector<pair<int, int>> st;
        st.push_back({0, -1});
        for (int j = 0; j < m; j++) {
            int x;
            if (j < m - 1) {
                if (b[i][j]) {
                    h[j]++;
                } else {
                    h[j] = 0;
                }
                x = h[j];
            } else {
                x = 0;
            }
            int y = j;
            while (st[st.size() - 1].first > x) {
                res = std::max(res, (st[st.size() - 1].first + 1) * (j - st[st.size() - 1].second + 1));
                y = st[st.size() - 1].second;
                st.pop_back();
            }
            if (st[st.size() - 1].first < x) {
                st.push_back({x, y});
            }
        }
    }

    cout << res;

    return 0;
}

Measured memory_bytes: 5120
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func readInt() int {
	i, _ := strconv.Atoi(read())
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Split(bufio.ScanLines)
	n := readInt()
	Card := make(map[string]int)
	for i := 0; i < n; i++ {
		s := read()
		if _, ok := Card[s]; !ok {
			Card[s] = 1
		} else {
			Card[s]++
		}
	}
	m := readInt()
	for i := 0; i < m; i++ {
		s := read()
		if _, ok := Card[s]; !ok {
			Card[s] = -1
		} else {
			Card[s]--
		}
	}
	maxNum := 0
	for _, val := range Card {
		maxNum = max(maxNum, val)
	}
	fmt.Println(maxNum)
}


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

int main(){

        int a[3],N;
        int i;

        cin >> N;

        for(i=0;i<3;i++){
        a[i]=N%10;
        N=N/10;
        }

/*      for(i=0;i<3;i++){
        cout << a[i]<< endl;
        }
*/

        N=100*a[2]+10*a[1]+a[0];

        if(N<=a[2]*100+10*a[2]+a[2]){
        N=100*a[2]+10*a[2]+a[2];
        }else{
        N=100*(a[2]+1)+10*(a[2]+1)+(a[2]+1);
        }

        cout << N <<endl;





        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810364364
#define PI 3.14159265358979
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL i,j,a=0,N,X,Y;
  scanf("%lld%lld%lld",&N,&X,&Y);
  LL ans[2005]={0};
  rep(i,N)FOR(j,i+1,N){
    a=MIN(MIN(j-i,abs(i-X+1)+abs(Y-1-j)+1),abs(i-Y+1)+abs(X-1-j)+1);
    ans[a]++;
  }
  FOR(i,1,N)printf("%lld\n",ans[i]);

  //printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int A[1010][1010];
int B[1000010];
char c;
int H,W;
int D[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int ans = 0;


int main() {
	cin >> H >> W;
	int p = 0;
	int q = 0;
	int t = 0;
	int cnt = H * W;
	for (int h = 0; h <= H + 1; h++) {
		for (int w = 0; w <= W + 1;w++) {
			if (h == 0 or h == H + 1 or w == 0 or w == W + 1) A[h][w] = 10000001;
			else {
				cin >> c;
				if (c == '#') {
					A[h][w] = 0;
					B[p] = h * W + (w - 1);
					p++;
					cnt --;
				} else { A[h][w] = -1;}
			}
		}
	}
	
	while(cnt > 0) {
		int h = B[q] / W;
		int w = B[q] % W + 1;
		t = A[h][w];
		for (int i = 0; i < 4; i++) {
			int dh = D[i][0];
			int dw = D[i][1];
			if (A[h + dh][w + dw] == -1) {
				A[h + dh][w + dw] = t + 1;
				B[p] = (h + dh) * W + (w + dw - 1);
				p++;
				cnt --;
				ans = t + 1;
			}
		}
		q ++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int cnt[maxn];

int32_t main(){
	fastio();
	int n,x,m;
	cin >> n >>  x >> m;
	int done = 1;
	int ans = 0;

	memset(cnt,-1,sizeof(cnt));
	int turn  = 1;
	int left = n;
	int prev = x;
	vector<int>v;
	ans += x;
	v.push_back(x);
	cnt[prev] = 1;
	prev = x * x;
	prev %= m;
	left = n - 1;
	while(left > 0  and cnt[prev] == -1){
			ans += prev;
			cnt[prev] = turn;
			v.push_back(prev);
			prev = (prev % m) * (prev % m);
			prev %= m;
		
		turn++;
		left--;
		 
	}
	//cout << left << " " << turn << "\n";
	if(left == 0){
		cout << ans;
		return 0;
	}
	int l = 1;
	int sum = 0;
	vector<int>c;
	while(v.size() > 0 and v.back() != prev){
		sum += v.back();
		c.push_back(v.back());
		v.pop_back();
		l++;
	}
	sum += v.back();
	c.push_back(v.back());
	ans += ((left) / l) * sum;
	left %= l;
	reverse(all(c));
	//for(auto i:c) cout << i << "\n";
	for(int i = 0; i < left; i++){
		ans += c[i];
	}
	cout << ans;
}

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

#define int ll
#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp);
	if(y%2 == 1)
		temp *= x;
	return temp;
}


int32_t main() {
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 1; i <= n; i++) {
		if(i%3 > 0 && i%5 > 0) {
			//mainspring;
			sum += i;
		}
	}
	cout << sum;
}


Measured memory_bytes: 3636
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 c = sc.nextInt();
		String ans = "NO";
		switch(a + b) {
		case 10 :
			if(a == 5 && b == 5 && c == 7) {
				ans = "YES";
			}
			break;
		case 12 :
			if(a == 5) {
				ans = (b == 7 && c == 5 ? "YES" : "NO");
			} else if(b == 5) {
				ans = (a == 7 && c == 5 ? "YES" : "NO");
			}
			break;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
long ans;
long A[1<<17],B[1<<17];
main()
{
	int N;cin>>N;
	for(int i=0;i<N;i++)cin>>A[i]>>B[i];
	for(int i=N;i--;)
	{
		long T=(-A[i]-ans)%B[i];
		if(T<0)T+=B[i];
		ans+=T;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
n = int(input())
s =[]
for i in range(n):
    s.append(int(input()))
s.sort()
if sum(s) % 10 != 0:
    print(sum(s))
else:
    a = sum(s)
    for i in range(n):
        if s[i] % 10 != 0:
            a = s[i]
            break
    print(sum(s) - a)

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

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    double a,b,n;
    cin>>a>>b>>n;
    ll ans=0;
    ll i=min(b-1,n);
    ll num=floor(a*i/b)-a*floor(i/b);
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 3636
def seg_tree_update(n,x):
    ind=2**m-1+n
    tree[ind]=x
    ind=(ind-1)//2
    while ind>=0:
        tree[ind]=max(tree[2*ind+1],tree[2*ind+2])
        ind=(ind-1)//2

def seg_tree_find_max(L,R):
    L,R=2**m-1+L,2**m-1+R
    qqq=0
    while L<R:
        if L%2==0:
            qqq=max(qqq,tree[L])
        if R%2==1:
            qqq=max(qqq,tree[R])
        L//=2
        R=R//2-1
        
    if L==R:
        qqq=max(qqq,tree[L])
    return qqq

N=int(input())
h=list(map(int,input().split()))
a=list(map(int,input().split()))

m=0
while pow(2,m)<N+1:
    m+=1
tree=[0]*(pow(2,m+1)-1)

for i in range(N):
    M=seg_tree_find_max(0,h[i])
    if tree[2**m-1+h[i]]<a[i]+M:
        seg_tree_update(h[i],a[i]+M)

ans=0
for i in range(N+1):
    ans=max(ans,tree[2**m-1+i])

print(ans)

Measured memory_bytes: 123984
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<math.h>
using namespace std;

int main(){
    int N, Y;
    cin >> N >> Y;
    int x=0, y=0, z=0, S=0;
    bool frag=false;
    
    for(x=0; x<=N; x++){
        for(y=0; y<=N-x; y++){
            z=N-x-y;
            S=10000*x+5000*y+1000*z;
            if(S==Y){
                frag=true;
                cout << x << " " << y << " " << z << endl;
                break;
            }
        }
        if(frag==true){
            break;
        }
    }
    if(frag==false){
        frag=true;
        cout << "-1 -1 -1" << endl;
    }

    return 0;
}

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

int main(){
    int m,d;
    cin>>m>>d;
    int cnt = 0;
    int decs,ones;
    for(int i = 1 ; i <= m ; i++){
        for(int j = 1 ; j <= d ; j++){
            if(j >= 10){
                ones = j % 10;
                decs = j / 10;
                if(ones >= 2 && decs >= 2 && ones * decs == i){
                    cnt++;
                }
            }                
        }
    }
    cout<<cnt<<endl;
	return 0;
}

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

#index,h
pp =[]
pm = []
all_set = set()
for i in range(N):

    pp.append(i + A[i])
    pm.append( i - A[i])

count = 0
c = collections.Counter(pp)
#print(c)
for i in range(N):
    count += c[pm[i]] 
    #print(c[pm[i]])

    #count += pp.count(pm[i])
    #count += pm.count(pp[i])

print(count)

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

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	int l = 0;
	for(int i = 0;i<n;i++)
	{
		if(s[i]=='R')l++;
		else l = 0;
		ans = max(ans,l);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var H = ReadLine().Split().Select(int.Parse).ToArray();
        var c = 0;
        var m = 0;
        for (int i = 0; i < N; i++)
        {
            if (m <= H[i])
            {
                c++;
                m = H[i];
            }
        }

        WriteLine(c);
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define rrep(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}

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


//////////////////////////////////////////////////



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

    if ((b-a)%2 == 0) {
        cout << (b-a)/2 << endl;
        return 0;
    }
    ll tmpa = a, tmpb = b;

    ll ans = (a-1)+1;
    b -= ans;
    ans += (b-1)/2;

    a = tmpa;
    b = tmpb;

    ll tmp = (n-b) + 1;
    a += tmp;
    tmp += (n-a)/2;

    cout << min(ans, tmp) << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string s; cin >> s;
  s = "zzz" + s + "zzz";
  ll l = s.size();
  ll pos = l-1, bc = 0, result = 0;
  while (pos>0) {
    if (pos>=1&&s.substr(pos-1,2)=="BC") { bc++; pos-=2; }
    else if (s[pos]=='A') { result += bc; pos--; }
    else { bc = 0; pos--; }
  } 
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 772
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    long long n,m;
    cin>>n>>m;
    long long ans;
    if(2*n<=m)ans=n+(m-2*n)/4;
    else ans=m/2;

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;
signed main(){
    int n;
    cin>>n;
    int l[10000];
    for(int i=0;i<n;i++)cin>>l[i];
    sort(l,l+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            int b,c;
            b=l[i];
            c=l[j];
            ans+=lower_bound(l,l+n,b+c)-upper_bound(l,l+n,abs(b-c));
            //cout<<lower_bound(l,l+n,b+c)-l<<" "<<upper_bound(l,l+n,abs(b-c))
            if(lower_bound(l,l+n,b+c)-l>i&&upper_bound(l,l+n,abs(b-c))-l<=i)ans--;
            if(lower_bound(l,l+n,b+c)-l>j&&upper_bound(l,l+n,abs(b-c))-l<=j)ans--;
        }
    }
    cout<<ans/6<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  string s,t;
  cin >> s >> t;
  bool ans = false;
  REP(i,(int)s.size()){
    if(s==t){
      ans = true;
      break;
    }
    s = s.back() + s.substr(0,s.size()-1);
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
ll a[100];
ll n;
ll dp[100];
int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n;

    FOR(i,1,n) cin >> a[i];

    // pair<int, int> dp[100][2];
    // dp[0][0] = {1000, 0};
    // dp[0][1] = {1000, 0};

    // FOR(i,1,n){
    //     dp[i][0] = dp[i-1][0].first > dp[i-1][1].first + dp[i-1][1].second * a[i] ? dp[i-1][0]: make_pair(dp[i-1][1].first + dp[i-1][1].second * a[i], 0);
    //     dp[i][1] = dp[i-1][1].second > dp[i-1][0].first / a[i]? dp[i-1][1] : make_pair(dp[i-1][0].first - (dp[i-1][0].first/a[i]) *a[i], dp[i-1][0].first/a[i]);
    // }

    // cout << dp[n][0].first << endl;

    dp[0] = 1000;
    FOR(i,1,n) {
        chmax(dp[i], dp[i-1]);
        FOR(j, 0, i-2) {
            ll cnt = dp[j] / a[j+1];
            chmax(dp[i], dp[j] - cnt * a[j+1] + cnt * a[i]);
        }
    } 

    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_V 20

int V;
int G[MAX_V][MAX_V];
bool visited[MAX_V];
int out[MAX_V];
int ix;

void
visit(int v)
{
	visited[v] = true;
	for (int u = 0; u < V; ++u)
	{
		if (G[v][u] && !visited[u])
			visit(u);
	}

	out[--ix] = v + 1;
}

void
solve()
{
	for (int u = 0; u < V; ++u)
		visited[u] = false;

	for (int u = 0; u < V; ++u)
		if (!visited[u])
			visit(u);
}

int
main(int argc, char **argv)
{
	scanf("%d", &V);
	for (int v = 0; v < V; ++v)
	{
		for (int u = 0; u < V; ++u)
			G[v][u] = false;
	}

	int E;
	scanf("%d", &E);
	for (int i = 0; i < E; ++i)
	{
		int s, t;
		scanf("%d%d", &s, &t);
		G[s - 1][t - 1] = true;
	}

	ix = V;
	solve();

	for (; ix < V; ++ix)
		printf("%d\n", out[ix]);

	return 0;
}

Measured memory_bytes: 1836
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  if(A==B && B==C) cout << "No";
  else if (A!=B && A!=C && B!=C) cout << "No";
  else cout << "Yes";
  return 0;
      
}

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

int main()
{
  int N,K;
  cin >> N >> K;
  int res = 1;
  for(int i = 0; i < N; i++)
  {
    if(res < K)
      res *= 2;
    else
      res += K;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
using System;

namespace ForAizuSol
{
    class Program
    {
        static void Main(string[] args)
        {
            var First = Console.ReadLine(); 
            var Next = Console.ReadLine();
            bool res = false;

            res = First.Equals(Next.Remove(Next.Length - 1));

            Console.WriteLine(res ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 25692
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

long long int lcm(long long int a, long long int b, long long int hoge)
{
    long long int tmp;
    long long int foo, bar;
    foo = max(a, b);
    bar = min(a, b);
    foo = foo / hoge;
    return foo * bar;
}

long long int gcd(long long int a, long long int b)
{
    long long int tmp;
    if (a < b)
    {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    long long int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main()
{
    int n;
    cin >> n;
    vector<long long int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    long long int ans = 1;
    rep(i, a.size())
    {
        //cout << ans<<endl;
        auto temp = gcd(ans, a[i]);
       // cout<<temp<<endl;
        ans = lcm(ans, a[i], temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    ArrayList<Integer> even = new ArrayList<>();
    ArrayList<Integer> odd = new ArrayList<>();
    if (K % 2 == 1) { // Kが奇数
      for (int i = 1; i <= N; i++) {
        if (i % K == 0) {
          odd.add(i);
        }
      }
    } else { // Kが偶数
      for (int i = 1; i <= N; i++) {
        if (i % K == 0) {
          odd.add(i);
        } else if (i % K == K / 2) {
          even.add(i);
        }
      }
    }
    System.out.println((long) Math.pow((double) odd.size(), 3.0) + (long) Math.pow((double) even.size(), 3.0));
  }
}


Measured memory_bytes: 28500
a,b,k=map(int,input().split())
for i in range(k):
  if(i%2==0):
    if(a%2==1):
      a -= 1
    a /= 2
    b += a
  else:
    if(b%2==1):
      b -= 1
    b /= 2
    a += b
print(int(a),int(b))

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

using namespace std;
using ll=long long;

bool is_satisfied(string s) {
    string t(s.rbegin(), s.rend());
    return t == s;
}

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

    ll N = S.length();
    if (is_satisfied(S) &&
        is_satisfied(S.substr(0, (N - 1) / 2)) &&
        is_satisfied(S.substr((N + 1) / 2))) {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <cassert>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, s;
};
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}

signed main() {
	ll  n, m;
	cin >> n >> m;

	string s, t;
	cin >> s >> t;

	ll lc = lcm(n,m);

	ll dn = lc / n, dm = lc/m;

	set<ll> us;

	for (ll i = 1; i <= lc; i += dn) {
		us.insert(i);
	}

	for (ll i = 1; i <= lc; i += dm) {
		auto itr = us.find(i);
		if (itr != us.end()) {
			ll sn = (*itr - 1) / dn;
			ll sm = (i - 1) / dm;

			if (s[sn] != t[sm]) {
				cout << -1 << endl;
				return 0;
			}

		}
	}

	cout << lc << endl;
	return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
 
long long mg(int A[],int l,int m,int r){
  long long cnt=0;
  int n1=m-l,n2=r-m;
  int L[n1+1],R[n2+1];
  for(int i=0;i<n1;i++)L[i]=A[l+i];
  for(int i=0;i<n2;i++)R[i]=A[m+i];
  L[n1]=1000000001,R[n2]=1000000001;
  int i=0,j=0;
  for(int k=l;k<r;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      j++;
      cnt+= (long long)n1- (long long)i;
    }
  }
  return cnt;
}
 
long long mgs(int A[],int l,int r){
  long long cnt=0;
  if(l+1<r){
    int m=(l+r)/2;
    cnt+=mgs(A,l,m);
    cnt+=mgs(A,m,r);
    cnt+=mg(A,l,m,r);
  }
  return cnt;
}
 
int main(){
  int n,A[200000];
  long long cnt;
  cin>>n;
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  cnt=mgs(A,0,n);
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4780
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		//		 new Main().solveC2();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);
			int[] wk = new int[3];

			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
			}

			Arrays.sort(wk);
			int res = Math.abs(wk[0] - wk[1]) + Math.abs(wk[1] - wk[2]);

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		String s;
		String t;

		try {
			scanner = new Scanner(System.in);
			s = scanner.next();
			t = scanner.next();

			s = s + s;

			System.out.println(s.contains(t) ? "Yes" : "No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	//	private long saikiSolveC() {
	//
	//	}

	/**
	 * m = a1 × a2 × · · · × aN とすると、各 i について m mod ai = 0 なので、(m − 1) mod ai = ai − 1
	 *  f(m − 1) = (a1 − 1) + (a2 − 1) + · · · + (an − 1) となり、各項が最大値を取っている
	 */
	private void solveC() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			int[] wk = new int[numN];

			int res = 0;
			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
				res += wk[i] - 1;
			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b;
	cin >> a >> b;
	int cnt = 0;
	for (int i = 0;i < a.length();++i) {
		if (a[i] != b[i]) {
			++cnt;
		}
	}
	cout << cnt << '\n';
	return 0;
}



Measured memory_bytes: 3788
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  int now = 0;
  rep(i, n) {
    cin >> a[i];
  }
  vector<int> dist(n);
  for(int i = 1; i < n; i++) {
    dist[i - 1] = a[i] - a[i - 1];
  }
  dist[n - 1] = k - a[n - 1] + a[0];
  sort(all(dist));
  int ans = 0;
  for(int i = 0; i < n-1; i++) {
    ans += dist[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
U,D,R,L='UDRL';x,y,a,b=map(int,input().split());x,y=a-x,b-y;a,b=x+1,y+1;print(U*y+R*x+D*y+L*a+U*b+R*a+D+R+D*b+L*a+U)

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

bool isPrime(int x){
    if(x==2){
        return true;
    }

    if(x<2 || x%2==0){
        return false;
    }

    int i=3;
    while(i<=sqrt((double)x)){
        if(x%i==0){
            return false;
        }
        i+=2;
    }

    return true;
}

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

    vector<int> a(n);
    REP(i,n){
        cin>>a[i];
    }

    int count=0;
    REP(i,n){
        if(isPrime(a[i])){
            count++;
        }
    }

    cout<<count<<endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<int>> tree;
vector<ll> num;

void dfs(int t,int v,int parent){
    num[t] +=v;
    for(int child:tree[t]){
        if(child==parent){
            continue;
        }
        dfs(child,num[t],t);
    }
}

int main(){
    int N,Q;
    cin >> N>>Q;
    tree.resize(N);
    num.resize(N,0);
    for(int i=0;i<N-1;i++ ){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    for(int i=0;i<Q;i++){
        int p,x;
        cin >> p >> x;
        p--;
        num[p] += x;
    }
    dfs(0,0,-1);
    for(int i=0;i<N;i++){
        cout << num[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 24320
import copy

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

neighbor = [[0]*N for _ in range(N)]
edge = []

for _ in range(M):
    a, b = map(int, input().split())
    neighbor[a-1][b-1] = 1
    neighbor[b-1][a-1] = 1
    edge.append([a-1,b-1])

# visitリストを更新する関数。初期化したvisitedを用意した上で呼び出す
def visit_points(current_point):
    visited[current_point] = 1
    neighbor_point = [x for x in range(len(tmp_neighbor[current_point])) if tmp_neighbor[current_point][x] > 0]
    for np in neighbor_point:
        if visited[np] == 0:
            visit_points(np)

# 辺を1つ削除した後に、DFSで連結かどうか調べる
n_bridge = 0

for idx in range(M):
    tmp_neighbor = copy.deepcopy(neighbor)
    tmp_neighbor[edge[idx][0]][edge[idx][1]] = 0
    tmp_neighbor[edge[idx][1]][edge[idx][0]] = 0

    visited = [0]*N
    visit_points(0)
    if sum(visited) < N:
        n_bridge += 1

print(n_bridge)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
 int N, K, SUM=0;
  cin >> N >> K;
  vector<int> S(N);
  
  for(int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  
  for(int i = 0; i < K; i++) {
    SUM += S.at(i);
  }
  cout << SUM << endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
  int n;
  double a;
  cin >> n;
  double ans = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    ans += 1.0 / a;
  }
    
    ans = 1.0 / ans;
    cout << ans << endl;
}

Measured memory_bytes: 256