akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        }
        private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        }
        private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        }

        static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 54132
#include <iostream>
using namespace std;
int main()
{
	int n,ans;
	cin >> n;
	if(n == 1 || n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7 || n == 8 || n == 9 || n == 10 || n == 12 || n == 14 || n == 15 || n == 16 || n == 18 || n == 20 || n == 21 || n == 24 || n == 25 || n == 28 || n == 30 || n == 32 || n == 35 || n == 36 || n == 40 || n == 42 || n == 45 || n == 48 || n == 49 || n == 54 || n == 56 || n == 63 || n == 64 || n == 72 || n == 81){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 20010;
int p[MAXN], pinv[MAXN], a[MAXN], b[MAXN];

int n;

int main() {
    GI(n);

    FOR1(i, n) {
        GI(p[i]); pinv[p[i]] = i;
    }

    FOR1(i, n) {
        printf("%d ", i * MAXN + pinv[i]);
    }
    printf("\n");

    FOR1(i, n) {
        printf("%d ", (MAXN - i) * MAXN + pinv[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  V<> a{10, 50, 100, 500};
  bool f = true;
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    V<> c(4); for (int i = 0; i < 4; ++i) cin >> c[i];
    int m = inner_product(begin(a), end(a), begin(c), 0) - n;
    V<> d(4);
    for (int i = 3; i >= 0; --i) {
      d[i] = m / a[i];
      m -= a[i] * d[i];
    }
    if (!f) cout << '\n';
    f = false;
    for (int i = 0; i < 4; ++i) if (c[i] - d[i] > 0) {
      cout << a[i] << ' ' << c[i] - d[i] << '\n';
    }
  }
}


Measured memory_bytes: 3024
#include "bits/stdc++.h"
using namespace std;
long long d[100010];
#define endl '\n'
typedef pair <long long, int> pii;

int sub[100010];
int par[100010];

int dis[100010];
vector <int> g[100010]; 

void dfs(int x, int par) {
	for(auto i : g[x]) {
		if(i - par) {
			dis[i] = 1 + dis[x];
			dfs(i, x);
		}
	}
}


int main(int argc, char const *argv[])
{
	ios_base :: sync_with_stdio (false);
	cin.tie(0);

	int n;
	cin >> n;

	map <long long, int> mp;
	vector <pii> v;
	for(int i = 1; i <= n; i++) {
		cin >> d[i];
		v.emplace_back(d[i], i);
		mp[d[i]] = i;
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	for(int i = 1; i <= n; i++) {
		sub[i] = 1;
		par[i] = i;
	}
	for(int i = 0; i < n-1; i++) {
		int node = v[i].second;
		int diff = n - 2 * sub[node];
		long long par_d = v[i].first - diff;
		if(diff == 0 || mp.find(par_d) == mp.end()) {
			cout << -1 << endl;
			exit(0);
		}
		par[node] = mp[par_d];
		sub[par[node]] += sub[node];
		g[par[node]].push_back(node);
		g[node].push_back(par[node]);
	}
	memset(dis, -1, sizeof dis);
	dis[1] = 0;
	dfs(1, 0);

	long long tot = 0;
	for(int i = 1; i <= n; i++) {
		if(dis[i] == -1) {
			cout << -1 << endl;
			exit(0);
		}
		tot += dis[i];
	}
	if(tot != d[1]) {
		cout << -1 << endl;
		exit(0);
	}
	for(int i = 0; i < n-1; i++) {
		int node = v[i].second;
		cout << node << " " << par[node] << endl;
	}
	return 0;
}

Measured memory_bytes: 21232
solve :: Int -> Int -> String
solve a b =
    min (rp a b) (rp b a)
    where 
        rp :: Int -> Int -> String
        rp n c = concat $ replicate n $ show c

main = do
    [a, b] <- map read . words <$> getLine :: IO [Int]
    putStrLn $ solve a b

Measured memory_bytes: 508
#abc128c
n,m=map(int,raw_input().split())
s=[map(int,raw_input().split()) for i in range(m)]
p=map(int,raw_input().split())
res=0
for i in range(2**n):
 res+=1
 for j in range(len(s)):
  on=0
  for k in range(s[j][0]):
   on+=((i>>(s[j][k+1]-1))%2)
  if on%2!=p[j]:
   res-=1
   break
print res


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

int main() {
  vector<vector<char>> a(3,vector<char>(3));
  rep(i,3)rep(j,3)cin >> a.at(i).at(j);
  cout << a.at(0).at(0) <<a.at(1).at(1)<<a.at(2).at(2)<< endl;
}

Measured memory_bytes: 3596
import sys


def main() -> None:
    way = 0
    pre = 0
    ans = 1

    n = next_int()

    for i in range(n):
        now = next_int()
        if i == 0 or now - pre == 0:
            pass
        elif way == 0:
            way = sgn(now - pre)
        elif sgn(now - pre) != way:
            ans += 1
            way = 0

        pre = now

    print(ans)


def sgn(x: int) -> int:
    if x == 0:
        return 0
    if x > 0:
        return 1
    return -1

def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int leftCount = 0, rightCount = 0;
	for (int i = 0; i < N; ++i){
		if (S[i] == '('){
			int leftNum = 1, rightNum = 0;
			for (int j = i + 1; j < N; ++j){
				if (S[j] == '('){
					leftNum++;
				}
				else{
					rightNum++;
				}
				if (leftNum == rightNum){
					break;
				}
			}
			if (leftNum != rightNum){
				rightCount++;
			}
		}
		else{
			int leftNum = 0, rightNum = 1;
			for (int j = i - 1; j >=0; --j){
				if (S[j] == '('){
					leftNum++;
				}
				else{
					rightNum++;
				}
				if (leftNum == rightNum){
					break;
				}
			}
			if (leftNum != rightNum){
				leftCount++;
			}
		}
	}
	string leftS, rightS;
	for (int i = 0; i < leftCount; ++i){
		leftS += '(';
	}
	for (int i = 0; i < rightCount; ++i){
		rightS += ')';
	}
	cout << leftS + S + rightS << endl;
	return 0;
}

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

int main(){
	int A1, A2, A3; cin >> A1 >> A2 >> A3;

	int maxAbs = abs(A1 - A2);
	if(maxAbs < abs(A1 - A3)) maxAbs = abs(A1 - A3);
	if(maxAbs < abs(A2 - A3)) maxAbs = abs(A2 - A3);

	int ans = 0;
	if(maxAbs == abs(A1 - A2)){
		ans = abs(A1 - A3) + abs(A2 - A3);
	}
	if(maxAbs == abs(A1 - A3)){
		ans = abs(A1 - A2) + abs(A2 - A3);
	}
	if(maxAbs == abs(A2 - A3)){
		ans = abs(A1 - A2) + abs(A1 - A3);
	}

	cout << ans;
	return 0;
}

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

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

int h,w;
char s[15][25];
string ans;

void dfs(int py,int px, int y, int x,int k,string cur,set<string> &dic){
    if(dic.count(cur)){
        if(cur.size() > ans.size()) ans = cur;
        if(cur.size() == ans.size()){
            if(cur < ans) ans = cur;
        }
    }
    else dic.insert(cur);

    if(px == x && py == y) return;

    int vx = (x+dx[k]+w) % w;
    int vy = (y+dy[k]+h) % h;

    dfs(py,px,vy,vx,k,cur+s[y][x],dic);
    return;
}

int main(){

    while(1){
        set<string> dic;
        cin>>h>>w;
        if(h == 0 && w == 0) break;

        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                cin>>s[i][j];
            }
        }

        ans = "";

        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                string cur = "";
                for(int k=0; k<8; k++){
                    int vx = (j+dx[k]+w) % w;
                    int vy = (i+dy[k]+h) % h;
                    dfs(i,j,vy,vx,k,cur+s[i][j],dic);
                }
            }
        }

        if(ans.size() <= 1) cout<<"0"<<endl;
        else cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 35700
def main():
    x,y,a,b,c = map(int,input().split())
    p = sorted(list(map(int,input().split())),reverse=True)
    q = sorted(list(map(int,input().split())),reverse=True)
    r = sorted(list(map(int,input().split())),reverse=True)

    ans = sum(p[:x])+sum(q[:y])
    p.insert(0,float("INF"))
    q.insert(0,float("INF"))
    x1 = x
    y1 = y
    for i in r:
        if i > p[x1] and i > q[y1]:
            if p[x1] > q[y1]:
                ans += i-q[y1]
                y1 -= 1
            else:
                ans += i-p[x1]
                x1 -= 1
        elif i > p[x1]:
            ans += i-p[x1]
            x1 -= 1
        elif i > q[y1]:
            ans += i-q[y1]
            y1 -= 1
        else:
            print(ans)
            exit()

    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 111588
// https://atcoder.jp/contests/abc073/tasks/abc073_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, M, R;
  cin >> N >> M >> R;

  VL rs(R);
  rep(i, R) {
    ll r;
    cin >> r;
    r--;
    rs[i] = r;
  }

  VVL ds(N, VL(N, INF));
  rep(i, N) ds[i][i] = 0;

  rep(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    ds[a][b] = c;
    ds[b][a] = c;
  }

  // ワーシャルフロイド
  rep(k, N) rep(i, N) rep(j, N) {
    ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
  }

  ll res = INF;

  sort(all(rs));

  do {
    ll sum = 0;
    rep(i, R - 1) sum += ds[rs[i]][rs[i + 1]];
    chmin(res, sum);
  } while (next_permutation(all(rs)));

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
	int i,j;
	
	for(i=0; i<9; i++){
		for(j=0; j<9; j++){
			printf("%dx%d=%d\n",i+1 ,j+1 ,(i+1)*(j+1));
		}
	}
	
	return 0;
}

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

using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;

int h, w;
int n;

lli ans[20];

map< pii , int > squares;

int main()
{
	scanf("%d %d %d",&h,&w,&n);

	for(int i = 1 ; i <= n ; i++)
	{
		int x, y;
		scanf("%d %d",&x,&y);

		for(int dx = -2 ; dx <= 0 ; dx++)
		{
			for(int dy = -2 ; dy <= 0 ; dy++)
			{
				int curX = x + dx;
				int curY = y + dy;

				if( curX <= 0 || curY <= 0 ) continue;
				if( curX + 2 > h || curY + 2 > w ) continue;

				squares[ { curX , curY } ]++;
			}
		}

		printf("\n\n");
	}

	for(auto it = squares.begin() ; it != squares.end() ; it++)
		ans[ it->second ]++;

	ans[0] = h - 2;
	ans[0] *= w - 2;

	for(int i = 1 ; i <= 9 ; i++)
		ans[0] -= ans[i];

	for(int i = 0 ; i <= 9 ; i++)
		printf("%lld\n",ans[i]);
}

Measured memory_bytes: 56704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	ll N;
	cin >> N;
	ll temp = sqrt(N);
	ll t;
	for(ll i = 1;  i <= temp; ++i) {
		if(N % i == 0) {
			t = i;
		}
	}
	ll ans = t + N / t - 2;
	cout << ans << endl;
}

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

#define int long long

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

int H, W;
string S[50];

signed main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                cout << '#';
                continue;
            }
            int cur = 0;
            for (int y = -1; y <= 1; y++) {
                for (int x = -1; x <= 1; x++) {
                    if (i + y < 0 || i + y > H - 1 || j + x < 0 || j + x > W - 1) {
                        continue;
                    }
                    if (S[i + y][j + x] == '#') {
                        cur++;
                    }
                }
            }
            cout << cur;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

east = [0]*(N+1)
west = [0]*(N+1)


count = 0
for i, s in enumerate(S):
    if s == 'E':
        count+=1
    east[i+1] = count

count = 0
for i, s in enumerate(S):
    if s == 'W':
        count+=1
    west[i+1] = count

minimum = 10**6

for i in range(N):
    tmp = (west[i]-west[0]) + (east[N]-east[i+1])
    #print(tmp)
    if tmp < minimum:
        minimum = tmp

print(minimum)

Measured memory_bytes: 17612
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 18 21:04:22 2020
1h 28min WA
@author: masat

"""

N, K, S = map(int, input().split())
"""
N = 100
K = 10
S = 10
"""
not_S = None
if S == 10**9:
    not_S = 1
else:
    not_S = S+1

answer = []

for i in range(K):
    answer.append(S)
for i in range(N-K):
    answer.append(not_S)

print(" ".join(map(str, answer)))


Measured memory_bytes: 12056
import java.util.*;

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

    String s = sc.next();
    char[] c = s.toCharArray();
    String ans = "Good";
    
    for(int i = 1; i < 4; i++){
      if(c[i - 1] == c[i]){
        ans = "Bad";
        break;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

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

long long lcm(long long a, long long b)
{
    long long d = gcd(a, b);
    return a / d * b;
}

int main()
{
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
if a > 0:
    ans = "Positive"
elif (a <= 0) & (b >= 0):
    ans = "Zero"
else:
    if (b - a + 1) % 2 == 0:
        ans = "Positive"
    else:
        ans = "Negative"
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define L long long
using namespace std;
const int q=1000000007;
int n,m,f[3010][3010][2],p;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d%d",&n,&m);
	n--;
	m--;
	for(i=1;i<=n;i++)
	  f[0][i][0]=1;
	f[0][0][1]=1;
	for(i=1;i<=m;i++)
	  {
	   for(j=0;j<=n;j++)
	     for(k=0;k<=1;k++)
	       f[i][j][k]=(f[i-1][j][k]*2ll+f[i-1][j+1][k]+(j?f[i-1][j-1][k]:0))%q;
	   f[i][0][1]=(f[i][0][1]+f[i][0][0])%q;
	   f[i][0][0]=0;
      }
	for(i=0;i<=n;i++)
	  p=(p+f[m][i][1])%q;
	p=p*4ll%q;
	printf("%d\n",p);
	return 0;
}


Measured memory_bytes: 70784
import Control.Monad
import Data.Char

main = (sub =<< get) >>= put

get = fmap read . words <$> getLine

put = mapM_ putStrLn

sub [h,w] = sol w . fmap (filter isLetter) <$> replicateM h getLine

sol w ss = let l = replicate (w+2) '#' in
  l:fmap (\s -> "#"++s++"#") ss ++ [l]


Measured memory_bytes: 1404
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int N;
    cin >> N;

    int D, X;
    cin >> D >> X;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    int count = 0;
    FOR(i, 0, N){
        int num = (D - 1) / A[i] + 1;
        count += num;
    }

    p(count+X);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long n,x,y,z,i,f[100005],g[100005],sum,ans;
set<pair<long long,long long> > s;
set<pair<long long,long long> > :: iterator it;
struct nyh{
	long long x,y,z;
}o[100005];
bool cmp(nyh u,nyh v){
	return u.x-u.y>v.x-v.y;
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	x=read();y=read();z=read();
   	n=x+y+z;
   	for(i=1;i<=n;i++){
		o[i].x=read();
		o[i].y=read();
		o[i].z=read();
		o[i].x-=o[i].z;
		o[i].y-=o[i].z;
		sum+=o[i].z;
	}
	sort(o+1,o+n+1,cmp);
	for(i=1;i<=n;i++){
		s.insert(make_pair(o[i].x,i));
		f[i]=f[i-1]+o[i].x;
		if(s.size()>x){
			it=s.begin();
			f[i]-=(it->first);
			s.erase(it);
		}
	}
	s.clear();
	for(i=n;i>=1;i--){
		s.insert(make_pair(o[i].y,i));
		g[i]=g[i+1]+o[i].y;
		if(s.size()>y){
			it=s.begin();
			g[i]-=(it->first);
			s.erase(it);
		}
	}
	ans=-2000000000000000000LL;
	for(i=x;i<=n-y;i++)
		ans=max(ans,f[i]+g[i+1]);
	ans+=sum;
	pus(ans,2);	
    return 0;
}

Measured memory_bytes: 9984
#include<iostream>
#include<set>
using namespace std;
int WhichColor(int rate) {
    if (rate >= 1 && rate <= 399)
        return 1;
    if (rate >= 400 && rate <= 799)
        return 2;
    if (rate >= 800 && rate <= 1199)
        return 3;
    if (rate >= 1200 && rate <= 1599)
        return 4;
    if (rate >= 1600 && rate <= 1999)
        return 5;
    if (rate >= 2000 && rate <= 2399)
        return 6;
    if (rate >= 2400 && rate <= 2799)
        return 7;
    if (rate >= 2800 && rate <= 3199)
        return 8;
    else
        return 0;
}
int main() {
    set<int> s;
    int N;
    while (cin >> N) {
        s.clear();
        int a, k = 0;
        for (int i = 1; i <= N; i++) {
            cin >> a;
            int color = WhichColor(a);
            if (color == 0)
                k++;
            s.insert(color);
        }
        int min = s.size();
        int max = min;
        if (k > 0) {
            if (min > 1)
                min -= 1;
            max += k - 1;
        }
        cout << min << " " << max << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
*/

//#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 510031;

string st;
int X,Y;
vector<int> ve[N];
int dp[N];

bool knap(vector<int> v,int need){
	for (int i=0;i<=need;i++){
		dp[i]=0;
	}
	dp[0]=1;
	for (int i=0;i<v.size();i++){
		for (int j=need;j>=0;--j){
			if (dp[j])
				dp[j+v[i]]=1;
		}
	}
	return dp[need];
}

bool solve(vector<int> ve,int need){
	int S=0;
	for (int i=0;i<ve.size();i++){
		S+=ve[i];
	}
	int should_get=S-need;
	if (should_get<0)
		return false;
	if (should_get%2)
		return false;
	should_get/=2;
	return knap(ve,should_get);
}

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin>>st>>X>>Y;

	int ptr=0;
	while (ptr<st.size()&&st[ptr]=='F'){
		++ptr;
		--X;
	}

	int Q=0;
	int cnt=0;

	for (int i=ptr;i<st.size();i++){
		if (st[i]=='T'){
			ve[Q].push_back(cnt);
			cnt=0;
			Q^=1;
		}
		else
			++cnt;
	}
	ve[Q].push_back(cnt);

	if (solve(ve[0],X)&&solve(ve[1],Y)){
		cout<<"Yes"<<endl;}
		else
			cout<<"No"<<endl;

	cin.get(); cin.get();
	return 0;
}


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


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
    	int n = s.nextInt();
    	int a = s.nextInt();
    	long[] ar = new long[n];
    	long sum=0;
    	for(int i=0;i<n;i++) {
    		ar[i] = s.nextInt();
    	}
    	Arrays.sort(ar);
     	for(int i=0;i<(n-a);i++) {
     		sum+=ar[i];
     		
     	}
    	System.out.println(sum);
    	
    	
    	
    }	
}


Measured memory_bytes: 57128
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,k;
  cin >> n >> k;
  vector<ld> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]++;
  ld u=0,ans;
  rep(i,k) u+=a[i];
  ans=u;
  rep(i,n-k){
    u-=a[i];
    u+=a[i+k];
    ans=max(ans,u);
  }
  ld y=2;
  ans/=y;
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3328
def chmin(a, b):
  if a > b:
    return b
  else:
    return a

def main():
  dp = [1e9]*100010
  hs = [0]*100010
  
  N = int(input())
  hs[:N] = map(int, input().split())
  
  dp[0] = 0
  for i in range(N):
    dp[i+1] = chmin(dp[i+1], dp[i]+abs(hs[i+1]-hs[i]))
    dp[i+2] = chmin(dp[i+2], dp[i]+abs(hs[i+2]-hs[i]))
  print(dp[N-1])
  return

if __name__ == '__main__':
  main()

Measured memory_bytes: 15516
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a0,a1,a2;
    a0 = a1 = a2 = 0;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        if(a%4 == 0) a2++;
        else if(a%2 == 0) a1++;
        else a0++;
    }
    if(a0 <= a2) cout << "Yes" << endl;
    else if(a0-1 == a2 && a1 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [0]*n
        self.n = n
    def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def same(self,x,y):
        return bool(self.find(x)==self.find(y))

def main():
    N,M = map(int,stdin.readline().split())
    uf = UnionFind(N)
    p = list(map(int,stdin.readline().split()))
    ans = 0
    for _ in range(M):
        x,y = map(int,stdin.readline().split())
        x -= 1
        y -= 1
        uf.union(x,y)
    for i in range(N):
        tmp = p[i]-1
        if not uf.same(tmp,i):continue
        else:ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 18544
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand rng
using namespace std; void solve();
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;

struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
  int main(){solve_dbg();}
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<int,int>;
constexpr int MOD = 998244853;
mt19937_64 rng(58);
template<typename T>inline T ceil(T a,T b){return (a + b - 1) / b;}
/////////

void solve(){
  ini(N); vi H(N); in(H);
  int ans = 0 , cur = 0;
  rep(i , N - 1){
    if(H[i] >= H[i + 1]) cur++;
    else cur = 0;
    amax(ans , cur);
  }
  out(ans);

}


Measured memory_bytes: 640
N = int(input())
X_list = list(map(int, input().split()))

min_X = min(X_list)
max_X = max(X_list)

min_cost = 0
for p in range(min_X, max_X + 1):

    cost = 0
    for i in range(N):
        cost += (X_list[i] - p) ** 2
    
    if cost < min_cost or min_cost == 0:
        min_cost = cost

print(min_cost)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n,z,w;
    cin>>n>>z>>w;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<vector<int>> x(n+1,vector<int>(n+1)),
                        y(n+1,vector<int>(n+1));
    for(int i=0;i<n;i++){
        if(i==0)x[n][i]=abs(z-a[n-1]);
        else x[n][i]=abs(a[i-1]-a[n-1]);
    }
    for(int i=0;i<n;i++){
        if(i==0)y[i][n]=abs(w-a[n-1]);
        else y[i][n]=abs(a[i-1]-a[n-1]);
    }
    for(int i=n-1;i>=0;i--){
        for(int j=n-1;j>=0;j--){
            if(i==j)continue;
            if(j+1!=i){
                x[i][j]=y[i][j+1];
            }else{
                x[i][j]=y[i][j+2];
            }
            if(i>j){
                x[i][j]=min(x[i][j],x[i+1][j]);
            }else{
                x[i][j]=x[j+1][j];
            }
            if(i+1!=j){
                y[i][j]=x[i+1][j];
            }else{
                y[i][j]=x[i+2][j];
            }
            if(i<j){
                y[i][j]=max(y[i][j],y[i][j+1]);
            }else{
                y[i][j]=x[i][i+1];
            }
        }
    }
    cout<<y[0][1]<<endl;
}


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

int main()
{
    int N,M;
    cin >> N >> M;
    int num[N]; //N桁の整数

    //初期化
    for(int i = 0; i < N; i++){
        num[i] = -1;
    }

    //M回入力
    int Si,Ci;
    int flag = 0;
    for(int i = 0; i < M; i++){
        cin >> Si >> Ci;
        if(num[Si-1] != -1 && num[Si-1] != Ci){ //-1じゃないところに異なる数字を入れたらアウト
            flag = -1;
        }
        num[Si-1] = Ci; //Si桁目にCiを入れる
    }

    //Nが一桁
    if(N == 1){ 
        if(flag == -1){
            cout << -1 << endl;
            return 0;
        }

        if(num[0] == -1){ //Nに何も入ってなければ0を出力
            cout << 0 << endl;
            return 0;
        }else{                  //Nになんか入ってればそのまま出力
            cout << num[0] << endl;
            return 0;
        }
    }

    //最上位が0ならアウト
    if(num[0] == 0) flag = -1;
    if(flag == -1){
        cout << -1 << endl;
        return 0;
    }

    //空き桁(-1が入っている配列)に数字を入れる
    if(num[0] == -1) num[0] = 1; //最上位は1を入れる
    for(int i = 1; i < N; i++){
        if(num[i] == -1) num[i] = 0; //ほかの桁は0を入れる
    }

    //表示
    for(int i = 0; i < N; i++){
        cout << num[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string str1,str2,str3;
	cin>>str1>>str2;
	int x[str1.size()+1][str2.size()+1],y[str1.size()+1][str2.size()+1],dp[str1.size()+1][str2.size()+1];
	char v[str1.size()+1][str2.size()+1];
	for(int i=0;i<=str1.size();i++)
	{
		for(int j=0;j<=str2.size();j++)
		{
			if(i==0 || j==0) {
				v[i][j]='\0';
				x[i][j]=i;
				y[i][j]=j;
				dp[i][j]=0;
			}
			else
			{
				if(str1[i-1]==str2[j-1])
				{
					//str3=v[i-1][j-1]+str1[j-1];
					v[i][j]=str1[i-1];
					x[i][j]=i-1;
					y[i][j]=j-1;
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else 
				{
					if(dp[i-1][j]>=dp[i][j-1])
					{
						dp[i][j]=dp[i-1][j];
						v[i][j]=v[i-1][j];
						x[i][j]=x[i-1][j];
						y[i][j]=y[i-1][j];
					}
					else
					{
						dp[i][j]=dp[i][j-1];
						v[i][j]=v[i][j-1];
						x[i][j]=x[i][j-1];
						y[i][j]=y[i][j-1];
					}
				}	
			}
		}
	}
	int m=str1.size(),n=str2.size(),a,b;
	while(1)
	{
		if(v[m][n]=='\0') break;
	//	cout<<v[m][n];
		str3=v[m][n]+str3;
		a=m;
		b=n;
		m=x[a][b];
		n=y[a][b];
	}
	cout<<str3<<endl;
	return 0;
}

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

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

    int mi = INT_MAX, ma = 0, a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        mi = min(mi, a);
        ma = max(ma, a);
    }

    cout << abs(mi - ma) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
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<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#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 itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

int ans=INF;
vi v;

void rec(int n, int t){
    // cout<<"rec"<<t<<endl;
    rep(i, v.size()){
        if(n <= t*10+v[i]){
            ans = min(ans,t*10+v[i]);
        }
        else{
            if(t==0&&v[i]==0)continue;
            rec(n, t*10+v[i]);
        }
    }
    return;
}

int main(void) {
    
    int n,k;
    cin>>n>>k;
    set<int> s;
    rep(i,k){
        int d;
        cin>>d;
        s.insert(d);
    }
    rep(i,10){
        if(!s.count(i))v.push_back(i);
    }
    rec(n,0);
    fin(ans);
}


Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(A);
		int[] B = new int[N];
		for(int i=0;i<N;i++) {
			B[i] = A[N-i-1];
		}
		long ans = 0;
		for(int i=0;i<=N-2;i++) {
			if(i==0) {
				ans += B[0];
			} else {
				ans += B[(i+1)/2];
			}
		}
		System.out.println(ans);
    }
}


Measured memory_bytes: 60248
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

void dfs(
        vector<vector<int>> &G,
        vector<vector<int>> &W,
        vector<int> &color,
        int u,
        int c) {
    color[u] = c;
    for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (color[v] != -1) continue;
        int newColor = (c + W[u][i]) % 2;
        dfs(G, W, color, v, newColor);
    }
}

int main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N), W(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(v); G[v].push_back(u);
        W[u].push_back(w); W[v].push_back(w);
    }

    vector<int> color(N, -1);
    dfs(G, W, color, 0, 0);

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

Measured memory_bytes: 14080
#include <iostream>
#include <string>
#include <vector>
#include<sstream>
 
using namespace std;
 
int main() {
    int count = 0;
    string str_w, str = "CODEFESTIVAL2016";
    cin >> str_w;
 
    for (int i = 0; i < 16; i++)
    {
        if (str_w[i] != str[i])
        {
            count++;
        }
    }
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 256
h,w=[int(j) for j in input().split()]
s=[input()for i in range(h)]
par=[-1 for i in range(h*w)]    #par<0なら自身が親で要素の個数、>0なら子で親の位置示す
def root(a):
    if par[a]<0:
        return a
    else:
        return root(par[a])

def size(a):
    return -par[root(a)]

def connect(a,b):
    a=root(a)
    b=root(b)
    if a==b:
        return False
    if size(a)<size(b):
        a,b=b,a
    par[a]+=par[b]
    par[b]=a
    return True

for i in range(h):
    for j in range(w):
        for x,y in [(1,0),(-1,0),(0,1),(0,-1)]:
            p,q=i+x,j+y
            if 0<=p<h and 0<=q<w:
                if s[p][q]!=s[i][j]:
                    if root(w*p+q)!=root(w*i+j):
                        connect(w*p+q,w*i+j)

from collections import Counter
c=Counter()
for i in range(h):
    for j in range(w):
        p=i*w+j
        q=root(p)
        if c[q]==0:
            c[q]=[0,0]
        if s[i][j]=="#":
            c[q][0]+=1
        else:
            c[q][1]+=1
ans=0
for i in c:
    ans+=c[i][0]*c[i][1]
print(ans)

Measured memory_bytes: 69892
import sys
def input():
    return sys.stdin.readline()[:-1]

n = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

minimum = 10**13
for u in range(1, int(n**0.5) + 1):
    if n % u == 0:
        cand = u + (n/u)
        if cand < minimum:
            minimum = cand
            i, j = u, n/u

print(int(i+j-2))



Measured memory_bytes: 40172
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, m;
	cin >> n >> m;
	VI h(n);
	REP(i, n) { cin >> h[i]; }
	VI2D edges(n);
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		edges[a - 1].push_back(b - 1);
		edges[b - 1].push_back(a - 1);
	}
	int result = 0;
	REP(i, n) {
		bool check = true;
		EACH(e, edges[i]) {
			if(h[i] <= h[e]) {
				check = false;
				break;
			}
		}
		if(check) {
			result++;
		}
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 8804
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll; 
using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  int ans = 0;
  if(n%m > 0){ 
    ans = n/m + 1;
    } else {
      ans = n/m;
    }   
  cout << ans << endl; 
}


Measured memory_bytes: 256
# https://abc113.contest.atcoder.jp/tasks/abc113_c
def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
P, Y = [0 for _ in range(M)], [0 for _ in range(M)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())

data = [[P[i], Y[i], 1, i] for i in range(M)]
data.sort(key=lambda x: x[1])  # sort by year
data.sort(key=lambda x: x[0])  # sort by prefectures

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  # original order
ans = []
for di in data:
    ans.append(pad(di[0]) + pad(di[2]))
print('\n'.join(ans))


Measured memory_bytes: 40012
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
 
int main(){
    fastio
    ll n , x ; 
    cin >> n >> x ; 
    vector<ll> v(n) ; 
    for(ll i=0;i<n;i++){
    	cin >> v[i] ; 
    }
    ll ans = 0 ; 
    for(ll i=0;i<n-1;i++){
    	if ( v[i]+v[i+1] <= x ) continue ; 
    	ll need = v[i] + v[i+1] - x ; 
    	ans += need ; 
    	if ( v[i+1] >= need ){
    		v[i+1] -= need ; 
    	}
    	else{
    		need -= v[i+1] ; 
    		v[i+1] = 0 ; 
    		v[i] -= need ; 
    	}
    }
    cout << ans << endl;
    return 0 ;
}

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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var gcdL = new int[N];
        var gcdR = new int[N];
        var gcdLNow = A[0];
        var gcdRNow = A[^1];
        for (int i = 0; i < N; i++)
        {
            gcdL[i] = gcdLNow = (int)GcdLcm.Gcd(gcdLNow, A[i]);
            gcdR[^(i + 1)] = gcdRNow = (int)GcdLcm.Gcd(gcdRNow, A[^(i + 1)]);
        }

        var gcd = new int[N];
        for (int i = 0; i < N; i++)
        {
            gcd[i] = (i == 0) ? gcdR[i + 1] :
                (i == N - 1) ? gcdL[i - 1] :
                (int)GcdLcm.Gcd(gcdL[i - 1], gcdR[i + 1]);
        }

        var ans = gcd.Max();

        WriteLine(ans);
    }
}
static class GcdLcm
{
    public static long Gcd(long a, long b) => (b != 0) ? Gcd(b, a % b) : a;
    public static long Lcm(long a, long b) => a / Gcd(a, b) * b;
}


Measured memory_bytes: 39716