akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int nMax=1000;
const int mMax=100010;
const int inf=1000010;

int n,m,map[nMax][nMax],mark[mMax],mpp[nMax][nMax];
//

int dis[nMax],fff[nMax],ans,mintree[nMax][2],nk;
int prim(bool isis){   //  自己的prim模板。
    int i, j, now,aaa,bbb;
    int  min_node, min_edge;
    for(i = 1; i <=n; i ++)
        dis[i] = inf-10;
    now = 1;
    ans = 0;
    nk=1;
    for(i = 0; i < n-1; i ++){
        dis[now] = -1;    //   将dis[]的&#20540;&#36171;-1，表示已&#32463;加入生成&#26641;中。
        min_edge = inf;
        for(j = 1; j <= n; j ++)    //   更新&#27599;个&#39030;点所&#23545;&#24212;的dis[]&#20540;。
            if(now != j && dis[j] >= 0 ){
                if(map[now][j]<dis[j]){
                    dis[j]=map[now][j];
                    fff[j]=now;
                }
                if(dis[j] < min_edge){
                    min_edge = dis[j];
                    min_node = j;
                }
            }
        now = min_node;
       if(isis==1){
            aaa=now;
            bbb=fff[now];
            mintree[nk][0]=aaa;
            mintree[nk++][1]=bbb;
       }
        ans += min_edge;
    }
    return ans;
}

int val[mMax];
int main(){
    int i,j,a,b,c;
    while(scanf("%d%d",&n,&m)!=EOF){
        for(i=1;i<=n;i++)for(j=1;j<=n;j++)map[i][j]=inf;
        memset(mark,0,sizeof(mark));
        for(i=1;i<=m;i++){
            scanf("%d%d%d",&a,&b,&c);
            map[a][b]=map[b][a]=c;
            mpp[a][b]=mpp[b][a]=i;
            val[i]=c;
        }

        int sum = prim(1);
        a=map[mintree[1][0]][mintree[1][1]];
        map[mintree[1][0]][mintree[1][1]]=map[mintree[1][1]][mintree[1][0]]=inf;
        if(sum!=prim(0)){
            mark[mpp[mintree[1][0]][mintree[1][1]]]=1;
        }
        for(i=2;i<=n-1;i++){
            map[mintree[i-1][0]][mintree[i-1][1]]=map[mintree[i-1][1]][mintree[i-1][0]]=a;
            if(mark[mpp[mintree[i][0]][mintree[i][1]]])continue;
            a=map[mintree[i][0]][mintree[i][1]];
            map[mintree[i][0]][mintree[i][1]]=map[mintree[i][1]][mintree[i][0]]=inf;
            b=prim(0);
//            cout<<b<<endl;
            if(sum!=b){
                mark[mpp[mintree[i][0]][mintree[i][1]]]=1;
            }
        }
        ans=0,sum=0;
        for(i=1;i<=m;i++){
            if(mark[i]){
                ans++;
                sum+=val[i];
            }
        }
        printf("%d %d\n",ans,sum);
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	ll n, a, b, x[100000], y[100000];
	ll ans = 0;
	cin >> n >> a >> b;
	rep(i, n) cin >> x[i];
	rep(i, n - 1) {
		y[i] = x[i + 1] - x[i];
	}
	sort(y, y + (n - 1), greater<int>());
	rep(i, n - 1) {
		if(y[i] * a > b) ans += b;
		else ans += y[i] * a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
#include <climits>
namespace orliv {
namespace graph {
struct Edge {
  typedef int weight_type;
  static constexpr weight_type INF =
      std::numeric_limits<weight_type>::max() - 100;

  int from, to;
  weight_type w;
  Edge(int from, int to, weight_type w = 1) : from(from), to(to), w(w) {}
  bool operator<(const Edge& rhs) const {
    if (w != rhs.w) return w > rhs.w;
    if (from != rhs.from) return from < rhs.from;
    return to < rhs.to;
  }
};

typedef Edge::weight_type Weight;
typedef std::vector<Edge> Edges;
typedef std::vector<Weight> Weights;
typedef std::vector<int> Path;
}
typedef std::vector<graph::Edges> Graph;
}
#endif
//}}}
//{{{ bellmanford.cc
#ifndef INCLUDE_GRAPH_HPP
#include "graph.hpp"
#endif

namespace orliv {
namespace graph {
namespace bellmanford_util {
Path buildPath(int t, std::vector<int>& prev) {
  Path path;
  for (int u = t; u >= 0; u = prev[u]) path.emplace_back(u);
  std::reverse(path.begin(), path.end());
  return std::move(path);
}
}

bool bellmanford(const Graph& g, int s, Weights& dist, std::vector<int>& prev) {
  const int V = g.size();
  auto inf = Edge::INF;
  dist.assign(V, inf);
  prev.assign(V, -1);
  dist[s] = 0;
  bool negative_cycle = false;
  for (int i = 0; i < V; i++) {
    for (const auto& v : g) {
      for (const auto& e : v) {
        if (dist[e.from] == Edge::INF) continue;
        if (dist[e.to] <= dist[e.from] + e.w) continue;
        dist[e.to] = dist[e.from] + e.w;
        prev[e.to] = e.from;
        if (i == V - 1) {
          dist[e.to] = -Edge::INF;
          negative_cycle = true;
        }
      }
    }
  }
  return !negative_cycle;
}
std::pair<bool, Weights> bellmanford(const Graph& g, int s) {
  std::vector<int> prev;
  Weights dist;
  bool ok = bellmanford(g, s, dist, prev);
  return std::move(std::make_pair(ok, std::move(dist)));
}
}
}
//}}}

using namespace std;

typedef long long ll;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int V = in(), E = in(), r = in();
  orliv::Graph g(V);
  for (int i = 0; i < E; i++) {
    int s = in(), t = in(), d = in();
    g[s].emplace_back(s, t, d);
  }
  auto res = orliv::graph::bellmanford(g, r);
  if (!res.first) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }
  for (auto w : res.second) {
    if (w == orliv::graph::Edge::INF) {
      cout << "INF" << endl;
    } else {
      cout << w << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>

int main(void)
{
	char len[1001];
	int i;
	
	scanf("%s", len);
	getchar();
	
	i = 0;
	while (len[i] != '\0'){
		if ('D' <= len[i] && len[i] <= 'Z'){
			len[i] -= 3;
		}
		else {
			switch (len[i]){
				case 'A':
				len[i] = 'X';
				break;
				
				case 'B':
				len[i] = 'Y';
				break;
				
				case 'C':
				len[i] = 'Z';
				break;
			}
		}
		i++;
	}
	
	printf("%s\n", len);
	
	return (0);
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100010];

bool solve() {
    sort(a, a+n);
    if (a[n-1] - a[0] > 1) return false;
    if (a[n-1] - a[0] == 0) {
        return a[0] == n-1 || n >= 2 * a[0];
    }
    int s = 0;
    while (a[s] == a[0]) {
        s++;
    }
    return a[n-1] > s && n - s >= 2 * (a[n-1] - s);
}

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

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

    input();
    cout << (solve()?"Yes":"No") << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 a, b, c;
  std::cin >> a >> b >> c;
  std::cout << (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b) ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


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

    ll sum = 0;
    priority_queue<ll> left;
    priority_queue<long long, vector<long long>, greater<long long> > right;

    ll l_sum = 0, r_sum = 0;

    rep(_, q) {
        int type;
        cin >> type;

        if (type == 1) {
            ll a, b;
            cin >> a >> b;
            sum += b;

            if (left.size() > right.size()) {
                // right に
                int t = left.top();
                if (a >= t) {
                    right.push(a);
                    r_sum += a;
                } else {
                    left.pop();
                    l_sum -= t;
                    left.push(a);
                    l_sum += a;
                    right.push(t);
                    r_sum += t;
                }
            } else {
                // left に
                if (left.empty()) left.push(a), l_sum += a;
                else {
                    int t = right.top();
                    if (a <= t) {
                        left.push(a);
                        l_sum += a;
                    } else {
                        right.pop();
                        r_sum -= t;
                        right.push(a);
                        r_sum += a;
                        left.push(t);
                        l_sum += t;
                    }
                }
            }

        } else {
            ll x = left.top();
            ll res = (x * (ll) left.size() - l_sum)
                     + (r_sum - x * (ll) right.size()) + sum;
            cout << x << ' ' << res << endl;
        }
    }

}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
struct option
{
    int x,y,z;
};
int vacation(option *arr,int n)
{
    int dp[n][3];
    dp[0][0]=arr[0].x;
    dp[0][1]=arr[0].y;
    dp[0][2]=arr[0].z;
    for(int i=1;i<n;i++)
    {
        dp[i][0]=arr[i].x+max(dp[i-1][1],dp[i-1][2]);
           dp[i][1]=arr[i].y+max(dp[i-1][0],dp[i-1][2]);
              dp[i][2]=arr[i].z+max(dp[i-1][1],dp[i-1][0]);
    }
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main()
{
    int n;
    cin>>n;
    option *arr=new option[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i].x>>arr[i].y>>arr[i].z;
    }
    int ans=vacation(arr,n);
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(){
  int a,b,i,j;
  scanf("%d%d",&a,&b);
  char s[101][101];
  for(i=1;i<=50;i++){
    for(j=1;j<=100;j++){
      if(i%2==1 && j%2==1 && a-1!=0){
        s[i][j]='.';
        a--;
      }
      else
        s[i][j]='#';
    }
  }
  for(i=100;i>=50;i--){
    for(j=0;j<=100;j++){
      if(i%2==1 && j%2==1 && b-1!=0){
        s[i][j]='#';
        b--;
      }
      else
        s[i][j]='.';
    }
  }
  puts("100 100");
  for(i=1;i<=100;i++){
    for(j=1;j<=100;j++)
      printf("%c",s[i][j]);
    puts("");
  }
  return 0;
}


Measured memory_bytes: 128
use std::io;
 
fn main() {
  let mut buffer = String::new();
  io::stdin().read_line(&mut buffer).unwrap();
  let chars = buffer.as_str().chars().collect::<Vec<char>>();
  if chars[2] == chars[3] && chars[4] == chars[5] {
  	println!("Yes");
  } else {
    println!("No");
  };
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end(), greater<ll>());
  //rep(i, n) cout << h[i] << endl;
  ll ans = 0;
  //cout << "h.size:" << h.size() << endl;
  if (k >= h.size()) {
    ans = 0;
  } else {
    for(int i = k; i < n; i++) {
      //cout << "h[k]: "<< h[i] << endl;
      ans += h[i];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
S = input()
S_arr = list(S)

ans = []
#print(S_arr)
for i in S_arr:
    if i in ans:
        pass
    else:
        ans.append(i)

#print(ans)
if len(ans) != 2:
    print("No")
else:
    if S.count(ans[0]) == S.count(ans[1]):
        print("Yes")
    else:
        print("No")
    

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}



int main(){
    ll a, b; cin >> a >> b;
    ll i = 2;
    map<ll, ll> mp1, mp2;
    mp1[1] = 1;
    mp2[1] = 1;
    while(a >= i*i){
        if(a % i == 0){
            mp1[i]++;
            a /= i;
        }else{
            i++;
        }
    }
    mp1[a]++;
    i = 2;
    while(b >= i*i){
        if(b % i == 0){
            mp2[i]++;
            b /= i;
        }else{
            i++;
        }
    }
    mp2[b]++;
    ll ans = 0;
    for(auto &x: mp1){
        if(mp2[x.first] != 0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#define MAXN 200005
#define LL long long
using namespace std;

int n;
LL a[MAXN], ans;
map<LL , int> mmp;

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld", &a[i]);
        a[i]+=a[i-1];
    }
    mmp[0]=1;
    for(int i=1; i<=n; i++)
    {
        mmp[a[i]]++;
        ans+=max(mmp[a[i]]-1, 0);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 14336
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    int n, m;
    List<List<Integer>> graph;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        m = sc.nextInt();
        graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new LinkedList<>());
        }
        for (int i = 0; i < m; i++) {
            int from = sc.nextInt() - 1;
            int to = sc.nextInt() - 1;
            graph.get(from).add(to);
            graph.get(to).add(from);
        }
        solve();
    }

    void solve() {
        for (int i = 0; i < n; i++) {
            System.out.println(graph.get(i).size());
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                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;
        }
    }
}


Measured memory_bytes: 23124
n = int(input())
l = [int(input()) for _ in range(n)]

if l[0] == 2:
    print(1)
    exit()

x = l[0]-1
z = 1
for i in range(10**5):
    z += 1
    if l[x] == 2:
        break
    else:
        x = l[x]-1

if z == 100001:
    print('-1')
else:
    print(z)


Measured memory_bytes: 7084
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(0, min(b, d) - max(a, c));
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n>>a;
  if(n<a) cout<<0;
  else cout<<10;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
 //  cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
	public static void main(String[] args) {
      int d,t,s;
      Scanner sc=new Scanner(System.in);
      d=sc.nextInt();
      t=sc.nextInt();
      s=sc.nextInt();
      int dis=s*t;
      if(dis>=d)
      {
    	  System.out.println("Yes");
      }
      else {
    	  System.out.println("No");
      }
      sc.close();
	}

}


Measured memory_bytes: 35596
N, K = map(int, input().split())
ans = 0
MOD = 10 ** 9 + 7

tot = [0]
for i in range(N + 1):
    tot.append(tot[-1] + i)

for k in range(K, N + 2):
    p = tot[k]
    q = tot[-1] - tot[-(1 + k)]
    ans += q - p + 1
    ans %= MOD

print(ans)

Measured memory_bytes: 79480
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int h, w, n;
    cin >> h >> w >> n;

    int len = max(h, w);
    int ans = (n + len - 1) / len;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# AOJ 0162 Hamming Numbers
# Python3 2018.6.23 bal4u

MAX = 1000000

t = [0]*(MAX+5)

a5 = 1
for i in range(9):
	a3 = 1
	for j in range(13):
		a35 = a5*a3
		if a35 > MAX: break
		a2 = 1
		for k in range(20):
			if a35*a2 > MAX: break
			t[a35*a2] = 1
			a2 <<= 1
		a3 *= 3
	a5 *= 5
while 1:
	a = input()
	if a == '0': break
	m, n = map(int, a.split())
	print(sum(t[m:n+1]))



Measured memory_bytes: 21216
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    vi a(3);
    int inputMax = 0;
    REP(i, 3) {
        cin >> a[i];
        chmax(inputMax, a[i]);
    }
    int k;
    cin >> k;
    int r = 0;
    bool isUsed = false;
    REP(i, 3) {
        if (inputMax == a[i] && !isUsed) {
            r += a[i] * (1 << k);
            isUsed = true;
        } else {
            r += a[i];
        }
    }
    debug((1 << k));
    cout << r;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3608
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int H, W;
    cin >> H >> W;
    int A[H][W], B[H][W], C[H][W];
    int maximum = 80 * 160 + 1;
    bool D[H][W][maximum];

    rep(i,H) {
        rep(j,W) cin >> A[i][j];
    }
    rep(i,H) {
        rep(j,W) cin >> B[i][j];
    }

    rep(i,H) {
        rep(j,W) {
            C[i][j] = abs(A[i][j] - B[i][j]);
            rep(k,maximum) D[i][j][k] = false;
        }
    }

    D[0][0][C[0][0]] = true;

    rep(i,H) {
        rep(j,W) {
            rep(k,maximum) {
                if (j > 0) D[i][j][k] = D[i][j][k] || D[i][j - 1][abs(k - C[i][j])];
                if (i > 0) D[i][j][k] = D[i][j][k] || D[i - 1][j][abs(k - C[i][j])];
                if (j > 0) D[i][j][k] = D[i][j][k] || D[i][j - 1][k + C[i][j]];
                if (i > 0) D[i][j][k] = D[i][j][k] || D[i - 1][j][k + C[i][j]];
            }
        }
    }

    rep(i,81) {
        if (D[H - 1][W - 1][i]) {
            cout << i << endl;
            return 0;
        }
    }

    

    return 0;
}

Measured memory_bytes: 80384
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    int x;
    cin >> x;
    int cnt = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(i * 500 + j * 100 + k * 50 == x) cnt++;
            }
        }
    }
    cout << cnt;
    
}

int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  bool ok = true;
  if(a.at(a.size()-1) !=b.at(0)) ok = false;
  if(b.at(b.size()-1) != c.at(0)) ok = false;
  
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int main(){
 int n,x,i,j;
 char s;
 int cards[4][13];

 for(i=0;i<4;i++){
  for(j=0;j<13;j++){
   cards[i][j]=0;
  }
 }

 cin >> n;
 for(i=0;i<n;i++){
  cin >> s >> x;
  switch(s){
   case 'S': cards[0][x-1]=1; break;
   case 'H': cards[1][x-1]=1; break;
   case 'C': cards[2][x-1]=1; break;
   case 'D': cards[3][x-1]=1; break;
  }
 }

 for(i=0;i<13;i++){
  if(cards[0][i]==0)cout << "S " << i+1 << endl;
 }
 for(i=0;i<13;i++){
  if(cards[1][i]==0)cout << "H " << i+1 << endl;
 }
 for(i=0;i<13;i++){
  if(cards[2][i]==0)cout << "C " << i+1 << endl;
 }
 for(i=0;i<13;i++){
  if(cards[3][i]==0)cout << "D " << i+1 << endl;
 }

 return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  map<int, vector<int>> jobs;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    jobs[M-a].push_back(b);
  }
  
  priority_queue<int> pq;
  long long ans = 0;
  for (int i = M; i >=0; i--) {
    for (auto j: jobs[i]) {
      pq.push(j);
    }

    if(!pq.empty()){
      ans += (long long)pq.top();
      pq.pop();
    }
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100000
#define INF (1<<29)
 
vector<int> G[MAX];
 
vector<int> bfs(int N)
{
    vector<int> d(N, INF);
    d[0] = 0;
     
    queue<int> Q;
    Q.push(0);
 
    while (!Q.empty()) {
        int v = Q.front(); Q.pop();
        for (int i = 0; i < (int)G[v].size(); i++) {
            int to = G[v][i];
            if (d[v] + 1 < d[to]) {
                d[to] = d[v] + 1;
                Q.push(to);
            } 
        }
    }
    return d;
}

set<int> st, edges[MAX], edges2[MAX];

void erase(int v)
{
    for (auto &e: edges2[v]) {
        if (e != 0 && edges[e].count(v) > 0) {
            edges[e].erase(v);
            if (edges[e].size() == 0) {
                st.insert(e);
                erase(e);
            }
        }
    }
}

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(M), b(M);
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
 
    auto d = bfs(N);
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int)G[i].size(); j++) {
            int to = G[i][j];
            if (d[i] + 1 == d[to]) {
                edges[to].insert(i);
                edges2[i].insert(to);
            }
        }
    }
    
    int R;
    for (int i = 0; i < Q; i++) {
        cin >> R;
        R--;        
        int s = a[R], t = b[R];
        if (s != 0) {
            if (d[s] == d[t] + 1 && edges[s].count(t) > 0) {
                edges[s].erase(t);
            }
            if (st.count(s) == 0 && edges[s].size() == 0) {
                st.insert(s);
                erase(s);
            }   
        }
        if (t != 0) {                  
            if (d[t] == d[s] + 1 && edges[t].count(s) > 0) {
                edges[t].erase(s);
            }

            if (st.count(t) == 0 && edges[t].size() == 0) {
                st.insert(t);
                erase(t);
            }     
        }              
        cout << st.size() << endl;;
    }    
    return 0;
}

Measured memory_bytes: 37244
#include<cstdio>
const int MAXN=200005,MAXA=8010,ZERO=2003,MOD=1000000007;

int PowMod(int a,int b)
{
    int ret=1;
    while(b)
    {
        if(b&1)
            ret=1LL*ret*a%MOD;
        a=1LL*a*a%MOD;
        b>>=1;
    }
    return ret;
}

int fac[MAXA],ifac[MAXA];

void Init()
{
    fac[0]=1;
    for(int i=1;i<MAXA;i++)
        fac[i]=1LL*fac[i-1]*i%MOD;
    ifac[MAXA-1]=PowMod(fac[MAXA-1],MOD-2);
    for(int i=MAXA-2;i>=0;i--)
        ifac[i]=1LL*ifac[i+1]*(i+1)%MOD;
}

int N;
int A[MAXN],B[MAXN];
int dp[MAXA/2][MAXA/2];

int main()
{
    Init();
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        scanf("%d%d",&A[i],&B[i]);
        dp[ZERO-A[i]][ZERO-B[i]]++;
    }
    for(int i=1;i<MAXA/2;i++)
        for(int j=1;j<MAXA/2;j++)
            dp[i][j]=((dp[i][j]+dp[i][j-1])%MOD+dp[i-1][j])%MOD;
    int ans=0;
    for(int i=1;i<=N;i++)
        ans=(ans+dp[ZERO+A[i]][ZERO+B[i]])%MOD;
    for(int i=1;i<=N;i++)
        ans=(ans-1LL*fac[2*(A[i]+B[i])]*ifac[2*A[i]]%MOD*ifac[2*B[i]]%MOD)%MOD;
    ans=(ans+MOD)%MOD;
    ans=1LL*ans*PowMod(2,MOD-2)%MOD;
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 64384
#include <bits/stdc++.h> 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vll>;
using vb = vector<bool>;
 
const int INF = 2e9+5;
const ll LLINF = (1LL << 60) + 5;
 
/*
  filippos
  Contest : AtCoder DP contest
  Task : K - Stones
*/
 
int main(){
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

  int n, k; cin >> n >> k;
  vi v(n);
  for(int &i : v)
    cin >> i;

  vi win(k + 1, 0);
  for(int i = 0; i <= k; i++){
    for(int s : v){
      if(s > i) break;
      if(!win[i - s]) {
        win[i] = 1;
        break;
      }
    }
  }

  cout << (win[k] ? "First" : "Second");

  return cout << endl, 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, k; cin >> n >> k;
  ll div = n-(n/k*k);
  cout << min(n, min(abs(div-k), div)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            r=(r*a)%m;
        b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

int main(){
    string s,t,u; cin>>s>>t;
    ll a,b; cin>>a>>b;
    cin>>u;
    if(u==s)a--;
    else b--;
    cout<<a<<" "<<b<<endl;
    return 0;
}
/*
5 2
. #
# #
# .
# #
. #
*/


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int A[5];
    for(int i = 0; i < 5; i++){
        cin >> A[i];
    }
    int ans =  0;
    int diff = 0;
    for(int i = 0; i < 5; i++){
        if(A[i]%10 == 0) {
            ans += A[i];
        }
        else{
            ans += ((A[i]+10)/10)*10;
            diff = max(diff, ((A[i]+10)/10)*10-A[i]);
        }

    }
    cout << ans-diff << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10001
typedef struct{
  int parent, left, right;
} Tree;
Tree T[MAX];
//int s=0,t=0;
#define NIL -1
int getheight(int);
void print(void);
int i,v,j,n,k,depth=0,num,l,r,degree=0,height=0;

int main()
{

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].parent=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL && r!=NIL){
      T[l].parent=v;
      T[r].parent=v;
    }
    else if(l!=NIL && r==NIL){
      T[l].parent=v;
    }
    else if(l==NIL && r!=NIL){
      T[r].parent=v;
    }
  }

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,T[i].parent);
    if(T[i].parent==NIL){
      printf("sibling = -1, ");
    }
    else if(T[T[i].parent].left==i){
      printf("sibling = %d, ",T[T[i].parent].right);
    }
    else{
      printf("sibling = %d, ",T[T[i].parent].left);
    }
    printf("degree = ");
    if(T[i].left!=NIL && T[i].right!=NIL){
      printf("2, ");
    }
    else if(T[i].left==NIL && T[i].right==NIL){
      printf("0, ");
    }
    else printf("1, ");

    num=i;
    while(T[num].parent!=NIL){
      depth++;
      num=T[num].parent;
    }
    printf("depth = %d, ",depth);
    depth=0;

    printf("height = ");
    height=getheight(i);
    printf("%d,",height);
    //s=0;t=0;

    if(T[i].parent==NIL){
      printf(" root\n");
    }
    else if(T[i].left==NIL && T[i].right==NIL){
      printf(" leaf\n");
    }
    else {
      printf(" internal node\n");
      }
  }
  return 0;
}

int getheight(int i)
{
  int s=0,t=0;
  if(T[i].left==NIL && T[i].right==NIL)return 0;

  if(T[i].left!=NIL){
  s=getheight(T[i].left)+1;
  }
  if(T[i].right!=NIL){
  t=getheight(T[i].right)+1;
  }
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

void print(){
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,T[i].parent);
    if(T[i].parent==NIL){
      printf("sibling = -1, ");
    }
    else if(T[T[i].parent].left==i){
      printf("sibling = %d, ",T[T[i].parent].right);
    }
    else{
      printf("sibling = %d, ",T[T[i].parent].left);
    }
    printf("degree = ");
    if(T[i].left!=NIL && T[i].right!=NIL){
      printf("2, ");
    }
    else if(T[i].left==NIL && T[i].right==NIL){
      printf("0, ");
    }
    else printf("1, ");

    num=i;
    while(T[num].parent!=NIL){
      depth++;
      num=T[num].parent;
    }
    printf("depth = %d, ",depth);
    depth=0;

    printf("height = ");
    height=getheight(i);
    printf("%d,",height);
    //s=0;t=0;

    if(T[i].parent==NIL){
      printf(" root\n");
    }
    else if(T[i].left==NIL && T[i].right==NIL){
      printf(" leaf\n");
    }
    else {
      printf(" internal node\n");
      }
  }
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    ll h; cin >> h;
    ll ct = 1;
    ll ans = 0;
    while (h > 0) {
        ans += ct;
        h /= 2;
        ct *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define allr(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define sp " "
#define double long double
#define pb push_back
#define ff first
#define int long long
#define ss second
#define vi vector<int>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define bruh freopen("bruh.txt", "r", stdin)
#define fo freopen("output.txt", "w", stdout)
#define pii pair<int, int>

long long inf = 2e18;
long long minf = -inf;

using namespace std;

signed main() {

#ifndef ONLINE_JUDGE
	//freopen("bruh.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<string , int > mp;
	int mx = 0;
	while (n--) {
		string s;
		cin >> s;
		mp[s]++;
		mx = max(mx, mp[s]);
	}
	vector<string > v;
	for (auto i : mp) {
		if (i.ss == mx)v.pb(i.ff);
	}
	sort(all(v));
	for (auto i : v)cout << i << endl;



}




Measured memory_bytes: 25584
#include<cstdio>
#include<cmath>
using namespace std;

typedef long double D;

int n,m,k,N;

D rec(int d,int sum){
  if(d==n){
    sum -= k;
    if(sum<1)sum = 1;
    return (D)sum/N;
  }

  D res = 0;
  for(int i=1;i<=m;i++)res += rec(d+1,sum+i);
  return res;
}

int main(){
  while(scanf("%d%d%d",&n,&m,&k),n+m+k){
    N = pow(m,n);
    printf("%.9Lf\n",rec(0,0));
  }
}
    

Measured memory_bytes: 1120
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x = I()
xgcd = gcd(x,360)
xlcm = 360 * x // xgcd
print(xlcm//x)


Measured memory_bytes: 10516
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();
    const MOD: i64 = 1000000007;

    let mut v = vec![0; n];
    for i in a {
        v[i as usize] += 1;
    }

    let mut ok = true;
    if n % 2 == 0 {
        for i in 0..n / 2 {
            if i % 2 == 0 && v[i] > 0 {
                ok = false;
            } else if i % 2 != 0 && v[i] != 2 {
                ok = false;
            }
        }
    } else {
        for i in 0..n / 2 + 1 {
            if i == 0 && v[i] != 1 {
                ok = false;
            } else if i % 2 != 0 && v[i] > 0 {
                ok = false;
            } else if i > 0 && i % 2 == 0 && v[i] != 2 {
                ok = false;
            }
        }
    }

    if !ok {
        println!("0");
    } else {
        println!(
            "{}",
            v.iter()
                .filter(|&&i| i > 0)
                .fold(1, |acc, &i| (acc * i) % MOD)
        );
    }
}


Measured memory_bytes: 6396
N, M = map(int, input().split())
min = -1
max = 10**5+1
for i in range(M):
    L, R = map(int, input().split())
    if L > min:
        min = L
    if R < max:
        max = R

if max >= min:
    print(max-min+1)
else:
    print(0)


Measured memory_bytes: 3060
h,w = map(int,input().split())
g = [['#'] * (w+2) for i in range(h+2)]
c = 0
for i in range(h):
  g[i+1][1:-1] = list(input())
  c += g[i+1][1:-1].count('#')
d = {}
d[0] = [(1,1)]
vi = set()
vi.add((1,1))
i = 0
while d[i]:
  l = d[i]
  d[i+1] = []
  for cur in l:
    for a,b in [[1,0],[0,1],[-1,0],[0,-1]]:
      to = (cur[0]+a,cur[1]+b)
      if to == (h,w):
        print(h*w-c-i-2)
        exit()
      if g[to[0]][to[1]] == '.' and to not in vi:
        vi.add(to)
        d[i+1].append(to)
  i += 1
print(-1)

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

int main(){
    int N;
    vector<int> a(100);
    cin >>N;
    for(int i=0;i<N;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end()-100+N);
    cout <<(a.at(N-1)-a.at(0))<<endl;
}

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

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

const int mx=105, inf=2e9+77;
int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i];
	int ret=inf;
	for (int x=-mx; x<=mx; x++) {
		int cur=0;
		for (int i=0; i<n; i++) {
			int diff=x-a[i];
			cur+=diff*diff;
		}
		ret=min(ret,cur);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
import fractions
n, start = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]

x_list.sort()

current_gcd = 0
for i in range(0, n):
    gap = abs(start - x_list[i])
    current_gcd = fractions.gcd(current_gcd, gap)

print(current_gcd)

Measured memory_bytes: 16280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////
int a[200010];
int cnt[200010];
int main() {
	int n; cin >> n;
	REP(i, n-1) {
		cin >> a[i];
		a[i]--;
		cnt[i] = 0;
	}
	REP(i, n) {
		cnt[a[i]]++;
	}
	REP(i, n) {
		if (i == 0)cout << cnt[i]-1 << endl;
		else cout << cnt[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 5160
num = int(input())
a = input().split()
b = list(map(int, a))
sum = sum(b)

X = [0]*num
X1 = 0
for i in range(num):
  if((2*i+1) >= num):
    break
  X1 = b[2*i+1] + X1
X[0] = sum - 2 * X1

for i in range(1,num):
  X[i] = b[i-1]*2 - X[i-1]
print(" ".join(map(str, X)))

Measured memory_bytes: 26264
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#define int long long
#define MAX(a,b) ((a) > (b)) ? (a) : (b)
#define MIN(a,b) ((a) < (b)) ? (a) : (b)

using namespace std;

bool flg[100005] = { 0 };

signed main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		flg[a] = true;
	}

	int cnt = 0;
	for (int i = 0; i <= 100000; i++)
	{
		if (flg[i])
		{
			cnt++;
		}
	}

	if (cnt % 2 == 1)
		cout << (cnt) << endl;
	else
		cout << (cnt - 1) << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
//by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
int x, y;main(void) {
  read(x); read(y);
  if(x % y == 0) cout << "-1\n";
  else cout << x << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
using namespace std;
int main(){
	int h,w;
	int n,x[1000],y[1000];
	cin>>h>>w;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	int count=0;
	for(int i=1;i<n;i++){
		if((x[i-1]>x[i]&&y[i-1]>y[i])||(x[i-1]<x[i]&&y[i-1]<y[i])){
			int xd=abs(x[i-1]-x[i]);
			int yd=abs(y[i-1]-y[i]);
			if(xd>=yd)
				count+=xd;
			if(xd<yd)
				count+=yd;
		}
		if((x[i-1]<=x[i]&&y[i-1]>=y[i])||(x[i-1]>=x[i]&&y[i-1]<=y[i])){
			int xd=abs(x[i-1]-x[i]);
			int yd=abs(y[i-1]-y[i]);
			count+=xd+yd;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1168
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
inline void read(int &x)
{
	x=0;
	int p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
char s[101000];
int tot[5];
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
		tot[s[i]-'a'+1]++;
	int minn=min(tot[1],min(tot[2],tot[3]));
	tot[1]-=minn;tot[2]-=minn;tot[3]-=minn;
	if(tot[1]==0)
	{
		if(tot[2]>=2||tot[3]>=2)return puts("NO"),0;
		return puts("YES"),0;
	}
	else if(tot[2]==0)
	{
		if(tot[1]>=2||tot[3]>=2)return puts("NO"),0;
		return puts("YES"),0;
	}
	else if(tot[3]==0)
	{
		if(tot[1]>=2||tot[2]>=2)return puts("NO"),0;
		return puts("YES"),0;
	}
	return 0;
}

Measured memory_bytes: 384
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

from string import ascii_lowercase

al = ascii_lowercase

N = INT()
ans = []

while N > 0:
    N -= 1
    ans.append(al[N % 26])
    N //= 26
    
ans.reverse()
print("".join(map(str, ans)))

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

int main() {
  const int mod = 1'000'000'007;

  int n;
  string s;
  cin >> n >> s;

  vector<int> v(26);
  for (char c : s) v[c-'a']++;

  ll ans = 1;
  for (int i : v)
  {
    ans *= i + 1;
    ans %= mod;
  }

  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 3720
#include<iostream>
using namespace std;
int main(){
	long long int x;
	long long int des,ans;
	cin >> x;
	for(int i=0;i<=x;i++){
		des = i * (i + 1) / 2;
		//cout << "i:" << i << " des:" << des << endl;
		if(des >= x){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,k;
    scanf("%d %d",&n,&k);
    int i;
    long long int ans;
    ans=k;
    for(i=1;i<=n-1;i++){
        ans*=k-1;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128