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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
const int N = 2e5 + 1;
const int lg = 20;
const ll mod = 0xfffff;

void solve() {
  ll n, k;
  scanf("%lld%lld", &n, &k);
  n %= k;
  printf("%lld\n", min(abs(n - k), n));
}

int main() {
  // int _; scanf("%d", &_) while (_--)
  solve();
	return 0;
}


Measured memory_bytes: 256
from heapq import heappop as hpop
from heapq import heappush as hpush

def main():
  
  while True:
    n, m = map(int, input().split())
    
    if not n:
      break
    
    cost_edges = [[] for _ in range(m)]
    time_edges = [[] for _ in range(m)]
  
    for _ in range(n):
      a, b, c, t = map(int, input().split())
      cost_edges[a - 1].append((c, b - 1))
      cost_edges[b - 1].append((c, a - 1))
      time_edges[a - 1].append((t, b - 1))
      time_edges[b - 1].append((t, a - 1))
    
    k = int(input())
  
    for _ in range(k):
      start, goal, r = map(int ,input().split())
      start -= 1
      goal -= 1
      
      if r:
        edges = time_edges
      else:
        edges = cost_edges
  
      que = [(0, start)]
      visited = [False for _ in range(m)]
      
      while que:
        score, station = hpop(que)
        visited[station] = True
        
        if station == goal:
          print(score)
          break
  
        for c, to_station in edges[station]:
          if not visited[to_station]:
            hpush(que, (score + c, to_station))

main()


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

int main()
{
  string s;
  cin >> s;
  if (s == "SUN") {
    cout << 7 << endl;
  } else if (s == "MON") {
    cout << 6 << endl;
  } else if (s == "TUE") {
    cout << 5 << endl;
  } else if (s == "WED") {
    cout << 4 << endl;
  } else if (s == "THU") {
    cout << 3 << endl;
  } else if (s == "FRI") {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
}


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

int main() {
long long int N,M,L=3000;
  cin >>N;
  int S[N];
  for(int i=0;i<N;i++){
    cin >>S[i];
  }
  sort(S,S+N);
  cout <<S[N/2]-S[(N/2)-1];
}

  

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

#define pb push_back

const int N = 5e3L + 11;

int c[N], r[N];
int dis[N];
vector <int> e[N];

int d[N];
bool v[N];
vector <int> bfs(int s, int lim) {
	fill(v, v + N, 0);
	v[s] = 1; d[s] = 0;
	queue <int> q; q.push(s);
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i : e[x]) if(!v[i]) {
			v[i] = 1;
			d[i] = d[x] + 1;
			q.push(i);
		}
	}
	vector <int> r;
	for(int i = 0; i < N; i ++)
		if(v[i] && d[i] <= lim) r.pb(i);
	return r;
}

int main() {
	ios :: sync_with_stdio(false);
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> c[i] >> r[i];
	for(int i = 1; i <= m; i ++) {
		int u, v; cin >> u >> v;
		e[u].pb(v); e[v].pb(u);
	}

	set <pair <int, int>> st;
	dis[1] = 0; fill(dis + 2, dis + n + 1, 1e9L);
	for(int i = 1; i <= n; i ++)
		st.insert({dis[i], i});
	while(!st.empty()) {
		auto p = *st.begin(); st.erase(st.begin());
		int s = p.second;
		for(int i : bfs(s, r[s]))
			if(dis[i] > dis[s] + c[s]) {
				st.erase({dis[i], i});
				dis[i] = dis[s] + c[s];
				st.insert({dis[i], i});
			}
	}
	cout << dis[n] << '\n';
}

Measured memory_bytes: 3760
from sys import exit

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

for x in a:
    if x == 0:
        print(0)
        exit()

ans = 1
for x in a:
    if x > 1000000000000000000//ans+1:
        print(-1)
        exit()
    ans *= x
    if ans > 1000000000000000000:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 21652
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n) {
    rep(j, d) { cin >> x[i][j]; }
  }
  vector<int> a(40 * 40 * 10 + 1, 0);
  rep(i, n) {
    repz(j, i + 1, n) {
      vector<int> x1 = x[i];
      vector<int> x2 = x[j];
      int sum = 0;
      rep(k, d) {
        int xtemp = x1[k] - x2[k];
        xtemp *= xtemp;
        sum += xtemp;
      }
      a[sum]++;
    }
  }
  int i = 1;
  int res = 0;
  while (i*i < SIZE(a)) {
    res += a[i * i];
    i++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
N,L=map(int,input().split())
A=[int(x) for x in input().split()]

psbl=False
ans=0
for i in range(1,N):
  if A[i-1]+A[i]>=L:
    psbl=True
    ans=i-1
    break
if psbl==False:
  print("Impossible")
else:
  print("Possible")
  for i in range(ans):
    print(i+1)
  for j in range(N-1-ans):
    print(N-j-1)

Measured memory_bytes: 14184
import sys
import numpy as np 

n, m = map(int, sys.stdin.readline().split())
x = np.array(sys.stdin.readline().split(), dtype=np.int64)
x.sort()

def main():
    d = np.sort(x[1:] - x[:-1])[::-1]
    d = np.concatenate((np.array([0]), np.cumsum(d)))
    res = d[m-1] - d[min(n, m) - 1]
    print(res)

if __name__ ==  '__main__':
    main()

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int sum = 0;
    sum += min(k, n) * x;
    sum += max((n-k), 0) * y;
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
function main(input) {
  const temp = input.trim().split(' ');
  const x = parseInt(temp[0], 10);
  const t = parseInt(temp[1], 10);
  const a = x - t;
  if (a >= 0) {
    console.log(a);
  } else {
    console.log(0);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29816
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];

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

    int x = d[n/2], y = d[n/2 - 1];

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

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b;
    cin >> a >> b;

    if(a%3==0||b%3==0||(a+b)%3==0) {
        cout << "Possible" << endl;
    }
    else cout << "Impossible" << endl;
    return 0;
}


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

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

	int n; cin >> n;
	vector<int> ans;
	int cnt = 0;
	if(n == 0) {
		cout << 0 << endl;
		return 0;
	}
	while(n != 0) {
		if(abs(n % 2) == 1) {
			ans.push_back(1);
			if(cnt % 2 == 0) {
				n--;
			}
			else {
				n++;
			}
		}
		else {
			ans.push_back(0);
		}
		n /= 2;
		cnt++;
	}
	for(int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i];
	}
	cout << endl;
	return 0;
}	


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<stack>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(n) n.begin(),n.end()
#define SIZE 2048

struct P{
  int x,y;
  P(int x1, int y1){x=x1,y=y1;}
};

bool board[SIZE][SIZE];

void compress(vector<int> &x1, vector<int> &x2, vector<int> &y1, vector<int> &y2, int &W, int &H){
  vector<int> xs, ys;
  unsigned int size = x1.size();
  for(int i=0; i<size; i++){
    for(int d=-1; d<=1; d++){
      int tx1 = x1[i] + d, tx2 = x2[i] + d, ty1 = y1[i] + d, ty2 = y2[i] + d;
      if(0<=tx1 && tx1 <=W) xs.push_back(tx1);
      if(0<=tx2 && tx2 <=W) xs.push_back(tx2);
      if(0<=ty1 && ty1 <=H) ys.push_back(ty1);
      if(0<=ty2 && ty2 <=H) ys.push_back(ty2);
    }
  }
  sort(all(xs)); sort(all(ys));
  xs.erase(unique(all(xs)), xs.end()); ys.erase(unique(all(ys)), ys.end());
  
  memset(board,0,sizeof(board));

  for(int i=0; i<size; i++){
    x1[i] = find(all(xs), x1[i]) - xs.begin();
    x2[i] = find(all(xs), x2[i]) - xs.begin();
    y1[i] = find(all(ys), y1[i]) - ys.begin();
    y2[i] = find(all(ys), y2[i]) - ys.begin();
    for(int y=y1[i]; y<y2[i]; y++){
      memset(board[y]+x1[i], 1, x2[i]-x1[i]);
    }
  }
  
  W = xs.size()-1; H = ys.size()-1;
}

void dfs(bool Map[SIZE][SIZE], P start, int W, int H){
  static const int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
  stack<P> st;
  st.push(start);
  while(st.size()){
    P s = st.top();
    st.pop();
    rep(i, 4){
      P t = P(s.x+dx[i], s.y+dy[i]);
      if(t.y>=0 && t.x>=0 && t.y<H && t.x<W && Map[t.y][t.x]==false){
	Map[t.y][t.x]=true;
	st.push(t);
      }
    }
  }
}

int main(){
  int W,H,N;
  while(cin>>W>>H, W|H){
    cin>>N;    
    vector<int> x1, x2, y1, y2;
    rep(i,N){
      int a, b, c, d;
      cin>>a>>b>>c>>d;
      x1.push_back(a);y1.push_back(b);
      x2.push_back(c);y2.push_back(d);
    }

    compress(x1,x2,y1,y2,W,H);
    int count = 0;
    rep(y, H){
      rep(x, W){
	if(board[y][x]!=true){
	  count++;
	  dfs(board, P(x, y), W, H);
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 7640
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

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

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}


int main()
{


	int a, b;
	cin >> a >> b;

	int wa, wb;
	
	int ans = -1;

	
	for (int i = 1; i < 20000; i++) {
		wa = (i * 8) / 100;
		wb = (i * 10) / 100;

		if (a == wa && b == wb) {
			ans = i;
			break;
		}



	}

	cout << ans << endl;


	return 0;

}



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

#define ll long long
#define ar array

int main() {

    ios::sync_with_stdio(false);
    
  	int a, b;
  	
  	cin >> a >> b;
  	
  	if (a>8 || b>8){
  		cout<<":("<<endl;
	}else{
		cout<<"Yay!"<<endl;
	}
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

// sv:始点ノード, pa:親, pac：親の色, g：グラフ, ans：答え格納用
void dfs(lli sv, lli pa, lli pac, vector<vector<pair<lli, lli>>> &g, vector<lli> &ans){
    lli c = 1;
    if(c == pac) c++;

    for(auto p: g[sv]){
        // 子から親の方向は考えない
        if(p.first == pa) continue;
        ans[p.second] = c;
        dfs(p.first, sv, c, g, ans);
        c++;
        if(c == pac) c++;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    
    lli n;
    cin >> n;
    // グラフ（隣接ノード, エッジ番号）
    vector<vector<pair<lli, lli>>> g(n);
    for(lli i=0; i<n-1; i++){
        lli n1, n2;
        cin >> n1 >> n2;
        n1--; n2--; // 0-Origin
        g[n1].emplace_back(n2, i);
        g[n2].emplace_back(n1, i);
    }

    // 最大の次数を持つノード
    lli maxc = 0;
    for(lli i=0; i<n; i++) chmax(maxc, (lli)g[i].size());

    // 0番のノードを始点にDFS
    vector<lli> ans(n-1, -1);
    dfs(0, -1, -1, g, ans);

    // 答えの出力
    cout << maxc << endl;
    for(auto p: ans) cout << p << endl;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n;
  cin >> n;
  string s;
  cin >> s;

  size_t ans = 0;
  char lastchar = '\0';

  for (auto && elem : s)
  {
    if (lastchar != elem)
    {
      ++ ans;
      lastchar = elem;
    }
  }
  cout << ans << endl;
}


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

struct Unionfind {
	vector< int > par;
	Unionfind(int N) : par(N,-1){
	}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(x == y) return 0;
		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return 1;
	}
	int root(int k) {
		if(par[k] < 0) return (k);
		return (par[k] = root(par[k]));
	}
	bool same(int x, int y){
		x = root(x);
		y = root(y);
		return x==y;
	}
	int size(int k) {
		return (-par[root(k)]);
	}
};

int main() {
	int64_t n,m;
	cin >> n >> m;
	vector<int> a(m),b(m);
	for(int i=0; i<m; i++) {
		cin >> a.at(i) >> b.at(i);
		a.at(i)--;b.at(i)--;
	}
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	vector<int64_t> cnt(m+1,n*(n-1)/2);
	Unionfind uf(n);
	for(int i=0; i<m; i++){
		cnt.at(i+1) = cnt.at(i);
		if(!uf.same(a.at(i),b.at(i))) cnt.at(i+1) -= uf.size(a.at(i))*uf.size(b.at(i));
		uf.unite(a.at(i),b.at(i));
	}
	cnt.pop_back();
	reverse(cnt.begin(),cnt.end());
	
	for(auto i:cnt) cout << i << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
int main(void){

  int A=0,B=0,K=0,n=0;
  int num[100]={0};
  scanf("%d%d%d",&A,&B,&K);
  
  for(int i=1;i<=100;i++){
  	if(A%i == 0 && B%i == 0){
    	num[n]=i;
      	n++;
    }
  }
  
  printf("%d",num[n-K]);
  
  
 return 0;
}

Measured memory_bytes: 128
<?php

  
  list($a, $b) = explode(" ", trim(fgets(STDIN)));
  
  echo lcm($a, $b);

  
  // 最小公約数（２つ）（ユークリッドの互除法）
function gcd($a, $b){
  if($b===0){
    return $a;
  }
  return gcd($b, $a%$b);
}

// 最小公約数（３つ）（ユークリッドの互除法）
function gcdMulti($arr){
  $cnt = count($arr);
  $gcd = $arr[0];
  for($i=0;$i<$cnt;$i++){
    $gcd = gcd($gcd, $arr[$i]);
  }
  return $gcd;
}

// 最大公倍数（２つ）
function lcm($a, $b){
  return $a*$b/gcd($a, $b);
}

Measured memory_bytes: 4604
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0) break;

            for(int j=0; j<H; j++){
                for(int i=0; i<W; i++){
                    if((i+j)%2 == 0)System.out.print("#");
                    else System.out.print(".");
                } 
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 37992
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long a,b,c;
	cin>>a>>b>>c;
	if(c-a-b>=0&&4*a*b<(c-a-b)*(c-a-b))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
 } 

Measured memory_bytes: 3660
#include<stdio.h>
int main()
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (x >= r&&x <= W - r&&y >= r&&y <= H - r)
	{
		printf("Yes\n");

	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2696
#include<stdio.h>
#include<stdlib.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int sz=1e5;
int qLen,qHead,Q[sz],*cave[sz];
void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}
int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}
int main(void)
{
  int A,B,N,M,x,y;
  x=scanf("%d %d",&N,&M);
  int room[N],path[N]={0};
  rep(i,N)room[i]=-1;
  rep(i,M)
  {
    x=scanf("%d %d",&A,&B);A--,B--;
    cave[A]=(int*)realloc(cave[A],sizeof(int)*(path[A]+1));
    cave[A][path[A]]=B;path[A]++;
    cave[B]=(int*)realloc(cave[B],sizeof(int)*(path[B]+1));
    cave[B][path[B]]=A;path[B]++;
  }
  room[0]=0;PUSH(0);
  while(qLen)
  {
    x=POP();
    rep(i,path[x]){y=cave[x][i];if(!(room[y]<0))continue;room[y]=x,PUSH(y);}
  }
  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);
}

Measured memory_bytes: 8520
def kouyakusu(a, b)
  loop do
    rem = b % a
    return a if rem == 0
    a, b = rem, a
  end
end

def kobaisu(a, b)
  a*b / kouyakusu(a, b)
end

while str = gets
  a, b = str.split( ).map(&:to_i).sort
  puts "#{kouyakusu(a, b)} #{kobaisu(a, b)}"
end

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

#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

typedef long long int ll;
typedef long double ld;

const int  N = 1e5+7;
const int inf = INT_MAX;
const int MOD = 1e9+7;

void solve()
{
   string s,t;
   cin >> s >> t;
   int ans = 0;
   for(int i=0;i<s.length();i++)
   {
      if(s[i] != t[i])
      {
         ans++;
      }
   }
   cout << ans;
}

int32_t main()
{
   IOS;
   //freopen("input.txt", "rt", stdin);
   //freopen("output.txt", "wt", stdout);
   int t=1;
   //cin >> t;
   for(int i=1;i<=t;i++)
   {
      //cout<<"Case #"<<i<<": ";
      solve();
   }
   return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>
#include <cassert>
#include <iso646.h>

using namespace std;

typedef long long i64;

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

    int n;
    cin >> n;

    set<int> s;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;

        if (s.count(a))
            s.erase(a);
        else
            s.insert(a);
    }

    cout << s.size();
}

Measured memory_bytes: 4992
//2020.1.9
//s1270188 xxxmk2
//alds1_08a

#include<stdio.h>
#include<stdlib.h>

//struct
struct node{
  int key;
  struct node *p, *l, *r;
};
typedef struct node *Node;

//prototype
void insert(int);
void pr_pre(Node);
void pr_in(Node);
void del_all(Node);

//global
Node root;

int main(){
  int num, i, j;
  char cmd[10];
  
  //input
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%s",cmd);

    if(cmd[0]=='i'){//insert
      scanf("%d",&j);
      insert(j);
    }
    
    else if(cmd[0]=='p'){//print
      pr_in(root);
      printf("\n");
      pr_pre(root);
      printf("\n");
    }
  }

  del_all(root);
  return 0;
}

void insert(int n){
  Node x=root, y=NULL, z;

  z=malloc(sizeof(struct node));
  z->key=n;
  z->l=z->r=NULL;

  while(x!=NULL){
    y=x;
    if(z->key < x->key) x=x->l;
    else x=x->r;
  }
  z->p=y;

  if(y==NULL) root=z;
  else if(z->key < y->key) y->l=z;
  else y->r=z;
  
}

void pr_pre(Node data){
  printf(" %d",data->key);
  if(data->l!=NULL) pr_pre(data->l);
  if(data->r!=NULL) pr_pre(data->r);
}

void pr_in(Node data){
  if(data->l!=NULL) pr_in(data->l);
  printf(" %d",data->key);
  if(data->r!=NULL) pr_in(data->r);
}

void del_all(Node data){
  if(data->l!=NULL) del_all(data->l);
  if(data->r!=NULL) del_all(data->r);
  free(data);
}



Measured memory_bytes: 25228
from itertools import permutations


def is_possible_case(per):
    prv_node = 0
    for node in per:
        if node not in g[prv_node]:
            return 0
        prv_node = node
    return 1


if __name__ == '__main__':
    N, M = map(int, input().split())
    g = {i: [] for i in range(N)}
    for _ in range(M):
        a, b = map(int, input().split())
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)

    ans = 0
    for per in permutations([i for i in range(1, N)]):
        ans += is_possible_case(per)

    print(ans)


Measured memory_bytes: 40812
#include <iostream>
#include <set>
#include <map>
using namespace std;

int main() {
	int n[5];
	while(cin >> n[0] && n[0]){
		set<int> kind;
		kind.insert(n[0]);
		for(int i = 1; i < 5; ++i){
			cin >> n[i];
			kind.insert(n[i]);
		}
		int ans[5] = {0};
		if(kind.size() == 1){
			for(int i = 0; i < 5; ++i)
				ans[i] = 3;
		}
		else if(kind.size() == 3){
			for(int i = 0; i < 5; ++i)
				ans[i] = 3;
		}
		else{
			int win = 0;
			if(kind.find(1) != kind.end() && kind.find(2) != kind.end())
				win = 1;
			else if(kind.find(2) != kind.end() && kind.find(3) != kind.end())
				win = 2;
			else
				win = 3;
			
			for(int i = 0; i < 5; ++i){
				if(n[i] == win)
					ans[i] = 1;
				else
					ans[i] = 2;
			}
		}
		for(int i = 0; i < 5; ++i)
			cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans=-1;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        --a[i];
    }
    int now=0;
    rep(i,n) {
        now=a[now];
        if (now==1) {
            ans=i+1;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		long b = 0;
        for(int i=1;i<=a;i++){if(i%3!=0 && i%5!=0){b+=i;
                                                 }
                            }
       
		System.out.println(b);
	}
}


Measured memory_bytes: 35764
N, M = map(int, input().split())
mod = 10 ** 9 + 7
K = max(N, M)
kaijo = [1] * (K + 1) 

for i in range(K):
    kaijo[i + 1] = ((i + 1) * kaijo[i]) % mod
    
if abs(N - M) > 1:
    print(0)
    
else:
    res = 1
    res *= kaijo[N] * kaijo[M]
    if N == M:
        res *= 2
    
    print(res % mod)


Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  rep(i,N)cin >> v[i];
  v.push_back(-1);
  int count = 0;
  int pre = -1;
  int sum = 0;
  rep(i,N+1){
    if(pre==v[i])++count;
    else{
      sum += count/2;
      count = 1;
    }
    pre = v[i];
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;
ll fact[N];

ll be(ll b, ll p) {
    if (p == 0)
        return 1;
    if (p % 2 == 0) {
        ll x = be(b, p / 2);
        return (x * x) % M;
    } else return (b * be(b, p - 1)) % M;
}

ll ncr(ll n, ll r) {
    return (fact[n] * be((fact[r] * fact[n - r]) % M, M - 2)) % M;
}

ll npr(ll n, ll r) {
    return (fact[n] * be((fact[n - r]), M - 2)) % M;
}

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

    fact[0] = 1;
    for (int i = 1; i < N; ++i) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= M;
    }

    ll notDeranged = 0;
    ll totalPermutations = npr(m, n);
    for (int i = 1; i <= n; ++i) {
        notDeranged = (notDeranged + (i & 1 ? 1 : -1) * (ncr(n, i) * npr(m - i, n - i)) % M) % M;
        if (notDeranged < 0) {
            ll x = ceil(abs(notDeranged) / (double) M);
            notDeranged += M * x;
        }

    }
    ll deranged = (totalPermutations - notDeranged + M) % M;

    cout << (totalPermutations * deranged) % M << endl;
}



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

#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  long long ans = 0,tmp = 0;
  vector<long long> a(n),b(n + 1,0);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    b[i + 1] = b[i] + a[i];
  }
  for(int i = 1;i < n + 1;i++){
    tmp = (b[n] - b[i]) % MOD * a[i - 1] % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6412
#include<bits/stdc++.h>
using namespace std;
#define N 2000000
#define maxn (N + 10)
#define maxm (maxn * 2)
#define pb push_back
#define lc (id * 2)
#define rc (id * 2 + 1)
typedef long long ll;
const ll INF = (1e8);
const ll mod = (1e9 + 7);
ll pra[maxn],prb[maxn];
int main(){
    ll n,m,k;scanf("%lld%lld%lld",&n,&m,&k);
    for(int i = 1;i <= n;i++){
        scanf("%lld",&pra[i]);pra[i] += pra[i - 1];
    }
    for(int i = 1;i <= m;i++){
        scanf("%lld",&prb[i]);prb[i] += prb[i - 1];
    }
    ll ans = 0;
    for(int i = 0;i <= n;i++){
        if(pra[i] > k)break;
        ll l = 0,r = m,p = 0;
        while(l <= r){
            ll mid = (l + r) / 2;
            if(prb[mid] + pra[i] <= k){
                p = mid;l = mid + 1;
            }
            else{
                r = mid - 1;
            }
        }
        ans = max(ans,i + p);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 6936
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

int main() {
    string s,t;
    cin >> s >> t;
    ll ans=0;
  	rep(i,s.size())
      if (s[i] != t[i]) ++ans;
  
    cout << ans << endl;
    return 0;
}


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

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

const long long MOD = 1000000007;

int main(){
  int n,m;
  cin >> n >> m;
  int ans = n*(n-1)/2 + m*(m-1)/2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, K;
	ll x[50], y[50];
	cin >> n >> K;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i];

	ll ans = 4e18;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) {
				for (int l = 0; l < n; ++l) {
					ll sx = min(min(x[i], x[j]), min(x[k], x[l]));
					ll ex = max(max(x[i], x[j]), max(x[k], x[l]));
					ll sy = min(min(y[i], y[j]), min(y[k], y[l]));
					ll ey = max(max(y[i], y[j]), max(y[k], y[l]));
					if (sx == ex || sy == ey)
						continue;

					int cnt = 0;
					for (int t = 0; t < n; ++t) {
						if (sx <= x[t] && x[t] <= ex && sy <= y[t] && y[t] <= ey)
							cnt++;
					}
					if (cnt >= K) {
						ans = min(ans, (ex - sx) * (ey - sy));
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,M=get_i
tree=array(N,0)
M.times do|i|
  a,b=get_i.map{|x| x-=1}
  tree[a]+=1
  tree[b]+=1
end
if tree.count{|x| x.even?}==N
    puts "YES"
else
    puts "NO"
end

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

int pow2(int x, int n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  if (n % 2) return x * pow2(x, n - 1);
  int y = pow2(x, n / 2);
  return y * y;
}

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

  int n;
  cin >> n;
  cout << pow2(2, floor(log2(n))) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int hamming(int n)
{
	if (n == 1){
		return (1);
	}
	
	if (n % 2 == 0){
		hamming(n / 2);
	}
	else if (n % 3 == 0){
		hamming(n / 3);
	}
	else if (n % 5 == 0){
		hamming(n / 5);
	}
	else {
		return (0);
	}
}

int main(void)
{
	int m, n, i, num;
	
	while (scanf("%d %d", &m, &n), m != 0){
	
		num = 0;
		
		for (i = m; i <= n; i++){
			num += hamming(i);
		}
		
		printf("%d\n", num);
	}
	
	return (0);
}

Measured memory_bytes: 596
n=gets.to_i
ss=[]
rests=[]
n.times do
  si=gets.to_i
  ss.push(si)
  rests.push(si) if si%10!=0
end
max=ss.sort.inject(:+)
if max%10!=0
  puts max
elsif rests.size==0
  puts 0
else
  puts max-rests.sort[0]
end


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

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

    long long residual = N % K;
    long long ans = min(abs(residual - K), residual);

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


Measured memory_bytes: 256
#include <stdio.h>
     
    int main(void){
        int a = 0;
        char b[4];
        scanf("%s",b);

        for(int i=0;i<4;i++){
                if(b[i] == '+')a++;
                else if(b[i] == '-')a--;
        }
        printf("%d\n",a);
        return 0;
    }

Measured memory_bytes: 128
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if n == 1:
    num_list = list(range(10))
else:
    num_list = list(range(10**(n-1), 10**n))
        
for i in num_list:
    flg = True
    for s, c in sc:
        if str(i)[s-1] != str(c):
            flg = False
            break
    if flg:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 62656
#include<stdio.h>
int main(){
	int i,w,h,n,x[1000],y[1000],xwalk,ywalk,sumwalk=0;
	scanf("%d%d%d",&w,&h,&n);
	for(i=0;i!=n;i++){
		scanf("%d%d",&x[i],&y[i]);
	}
	for(i=0;i<n-1;i++){
		xwalk=x[i+1]-x[i];
		ywalk=y[i+1]-y[i];
		if(xwalk>=0&&ywalk>=0||xwalk<0&&ywalk<0){   //?????????????????????????????????????????¨???
			if(xwalk<0){
				xwalk*=-1;
				ywalk*=-1;
			}
			if(xwalk>ywalk){
				sumwalk+=xwalk;
			}
			else{
				sumwalk+=ywalk;
			}
		}
		if(xwalk<0&&ywalk>=0||xwalk>=0&&ywalk<0){   //?¶??????????????????????????????????????????????????????¨???
			if(ywalk<0){
				ywalk*=-1;
			}
			else if(xwalk<0){
				xwalk*=-1;
			}
			sumwalk+=xwalk+ywalk;
		}
	}
	printf("%d\n",sumwalk);
}

Measured memory_bytes: 2716
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];

    vll rain(N);
    ll low = 0, high = 2 * A[0] + 2;
    while (high - low > 2) {
        ll mid = (high + low) / 2 / 2 * 2;

        bool minus = false;
        ll r = mid;
        rep(i, 0, N) {
            ll dnext = A[i] - r / 2;

            if (dnext < 0) {
                minus = true;
            }

            r = dnext * 2;
        }

        if (r < mid) high = mid;
        else low = mid;
    }

    cout << low;
    ll r = low;
    rep(i, 1, N) {
        r = (A[i - 1] - r / 2) * 2;
        cout << " " << r;
    }
    cout << endl;
}

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

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

#define ALL(v) v.begin(), v.end()

int main() {
  //std::cout << std::fixed << std::setprecision(20);

  int64_t N;
  cin >> N;
  vector<int64_t> X(N);

  REP(i,N) cin >> X[i];

  int64_t m = 1000000000000000000000000000000000;
  FOR(i,1,100){
    int64_t total = 0;
    REP(j,N){
      total += (X[j] - i) * (X[j] - i);
    }
    m = min(m,total);
  }

  cout << m << endl;

}

Measured memory_bytes: 256
#include<cstdio>
const int MAXN = 400;
const int MOD = 998244353;
int inv[MAXN + 5];
struct mint{
	int x;
	mint(int _x=0) : x(_x) {}
	friend mint operator + (const mint &a, const mint &b) {return a.x + b.x >= MOD ? a.x + b.x - MOD : a.x + b.x;}
	friend mint operator - (const mint &a, const mint &b) {return a.x - b.x < 0 ? a.x - b.x + MOD : a.x - b.x;}
	friend mint operator * (const mint &a, const mint &b) {return 1LL * a.x * b.x % MOD;}
	friend mint operator / (const mint &a, const int &b) {return a * inv[b];}
};
mint pow_mod(mint b, int p) {
	mint ret = 1;
	while( p ) {
		if( p & 1 ) ret = ret*b;
		b = b*b;
		p >>= 1;
	}
	return ret;
}
void init() {
	inv[1] = 1;
	for(int i=2;i<=MAXN;i++)
		inv[i] = MOD - 1LL*inv[MOD%i]*(MOD/i)%MOD;
}
mint coef[MAXN + 5][MAXN + 5];
int A[MAXN + 5], B[MAXN + 5], N, SA, SB;
void read() {
	scanf("%d", &N);
	for(int i=0;i<N;i++)
		scanf("%d%d", &A[i], &B[i]), SA += A[i], SB += B[i];
}
mint tmp[MAXN + 5][MAXN + 5];
void get() {
	coef[0][0] = 1;
	for(int i=0;i<N;i++) {
		for(int j=0;j<=SA;j++)
			for(int k=0;k<=SB;k++)
				tmp[j][k] = coef[j][k], coef[j][k] = 0;
		mint p = mint(A[i]) / SA, f = MOD - 1;
		for(int l=0;l<B[i];l++,f=f/l*p)
			for(int j=0;j<=SA;j++)
				for(int k=l;k<=SB;k++)
					coef[j][k] = coef[j][k] + f*tmp[j][k-l];
		for(int j=A[i];j<=SA;j++)
			for(int k=0;k<=SB;k++)
				coef[j][k] = coef[j][k] + tmp[j-A[i]][k];
	}
	for(int i=0;i<=SA;i++)
		for(int j=0;j<=SB;j++)
			coef[i][j] = 0 - coef[i][j];
	coef[SA][0] = coef[SA][0] + 1;
}
/*
let t = e^(x/S)
t^S - (t^Ai - (x*Ai/S)^j/j!)
*/
int solve() {
	mint ret = 0, f = 1;
	for(int j=0;j<=SB;j++,f=f*j)
		for(int i=0;i<=SA;i++) {
			mint p = mint(i) / SA;
			p = pow_mod(1 - p, MOD - 2 - j);
			ret = ret + coef[i][j]*p*f;
		}
	return ret.x;
}
int main() {
	init(), read(), get();
	printf("%d\n", solve());
}

Measured memory_bytes: 1408
s = input()

YYMM = False
MMYY = False
month = []
for i in range(1,13):
  if len(str(i))==1:
    month.append("0"+str(i))
  else:
    month.append(str(i))
    
if s[:2] in month:
  MMYY = True
  
if s[2:] in month:
  YYMM = True
  
if MMYY is True and YYMM is True:
  print("AMBIGUOUS")
elif MMYY is True and YYMM is False:
  print("MMYY")
elif MMYY is False and YYMM is True:
  print("YYMM")
else:
  print("NA")



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
    int n;
    scanf("%d",&n);
    for (int i = 1; i <= n; i++) {
        char ch[2];
        scanf("%s",ch);
        if (ch[0] == 'Y') {
            puts("Four");
            return 0;
        }
    }
    puts("Three");
    return 0;
}


Measured memory_bytes: 256
import static java.lang.System.*;

import java.util.Random;
import java.util.Scanner;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();


	public boolean check(char c1,char c2,char c3,char d1,char d2,char d3){
		return (c1=='*' ||c2=='*' || c3=='*') &&  (d1=='*' ||d2=='*' || d3=='*');
	}

	public void run() {
		TCase:while(true){
			char[][][] dice=new char[6][3][3];

			for(int i=0;i<6;i++){
				for(int j=0;j<3;j++){
					dice[i][j]=sc.next().toCharArray();
					if(dice[i][j][0]=='#')return;
				}
			}

			if(check(dice[0][2][0],dice[0][2][1],dice[0][2][2],
					dice[2][2][0],dice[2][2][1],dice[2][2][2])){
				ln(0);continue;
			}

			if(check(dice[0][0][0],dice[0][1][0],dice[0][2][0],
					dice[2][0][2],dice[2][1][2],dice[2][2][2])){
				ln(1);continue;
			}
			if(check(dice[0][0][2],dice[0][1][2],dice[0][2][2],
					dice[2][0][0],dice[2][1][0],dice[2][2][0])){
				ln(1);continue;
			}
			if(check(dice[4][2][0],dice[4][2][1],dice[4][2][2],
					dice[5][0][0],dice[5][0][1],dice[5][0][2])){
				ln(1);continue;
			}
			if(check(dice[4][0][0],dice[4][0][1],dice[4][0][2],
					dice[5][2][0],dice[5][2][1],dice[5][2][2])){
				ln(1);continue;
			}

			if(check(dice[0][0][0],dice[0][0][1],dice[0][0][2],
					dice[2][0][0],dice[2][0][1],dice[2][0][2])){
				ln(2);continue;
			}
			if(check(dice[4][0][0],dice[4][1][0],dice[4][2][0],
					dice[5][0][0],dice[5][1][0],dice[5][2][0])){
				ln(2);continue;
			}
			if(check(dice[4][0][2],dice[4][1][2],dice[4][2][2],
					dice[5][0][2],dice[5][1][2],dice[5][2][2])){
				ln(2);continue;
			}
			if(check(dice[1][0][0],dice[1][1][0],dice[1][2][0],
					dice[3][0][2],dice[3][1][2],dice[3][2][2])){
				ln(2);continue;
			}
			if(check(dice[1][0][2],dice[1][1][2],dice[1][2][2],
					dice[3][0][0],dice[3][1][0],dice[3][2][0])){
				ln(2);continue;
			}


			if(check(dice[1][0][0],dice[1][0][1],dice[1][0][2],
					dice[3][0][0],dice[3][0][1],dice[3][0][2])){
				ln(3);continue;
			}
			if(check(dice[1][2][0],dice[1][2][1],dice[1][2][2],
					dice[3][2][0],dice[3][2][1],dice[3][2][2])){
				ln(3);continue;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 20616
#include<bits/stdc++.h>
#define DBG(x) cerr << #x << “ = ” << (x) << endl
#define Rep(i,a,b) for (int i = a, to = b; i < to; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

typedef long long Long;

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	Long n; cin>>n;
    Long tam[n];
    Rep(i,0,n){
        cin>>tam[i];
    }
    Long total = 0;
    Rep(i,1,n){
        if(tam[i-1]>tam[i]){
            total += tam[i-1]-tam[i];
            tam[i] = tam[i-1];
        }else{
            continue;
        }
    }
    cout<<total;
	return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s,t;
  cin >> s >> t;
  REP(i,s.size()){
    if(s[i]!=t[i]){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 3636
use std::io::*;

fn main() {
	let input = {
		let mut buf = vec![];
		stdin().read_to_end(&mut buf);
		unsafe { String::from_utf8_unchecked(buf) }
	};
	let mut lines = input.split('\n');

	let (n, q): (usize, u32) = {
		let line = lines.next().unwrap();
		let mut iter = line.split(' ');
		(
			iter.next().unwrap().parse().unwrap(),
			iter.next().unwrap().parse().unwrap(),
		)
	};

	let mut queue = std::collections::VecDeque::with_capacity(n);

	let iter = lines.take(n).map(|l| {
		let mut iter = l.split(' ');
		(
			iter.next().unwrap(),
			iter.next().unwrap().parse::<u32>().unwrap(),
		)
	});
	queue.extend(iter);

	let mut total = 0;

	while let Some((name, time)) = queue.pop_front() {
		if time <= q {
			total += time;
			println!("{} {}", name, total);
		} else {
			total += q;
			queue.push_back((name, time - q));
		}
	}
}



Measured memory_bytes: 6976
N, M = map(int, input().split())
K_A = []
M_A  =[0 for _ in range(M)]
ans = 0
for i in range(N):
	k_a = map(int, input().split())
	K_A.append(list(k_a))
for i in range(N):
	for j in range(1, len(K_A[i])):
		M_A[K_A[i][j]-1] += 1
for i in range(len(M_A)):
	if M_A[i] == N:
		ans += 1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct uftree{
	int par[100005];
	int rank[100005];
	int sz[100005];
	uftree(){
	}
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
			sz[i]=1;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}

	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y]){
			par[x]=y;
			sz[y]+=sz[x];
		}else{
			if(rank[x]==rank[y])rank[x]++;
			par[y]=x;
			sz[x]+=sz[y];
		}
	}

	bool same(int x,int y){
		return find(x)==find(y);
	}
};


uftree uf;
int n;
P p[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&p[i].first,&p[i].second);
		swap(p[i].first,p[i].second);
	}
	uf.init(100001);
	sort(p,p+n);
	for(int i=0;i+1<n;i++){
		if(p[i].first==p[i+1].first){
			uf.unite(p[i].second,p[i+1].second);
		}
	}
	int prev=-1;
	set<int> se;
	ll ans=0;
	for(int i=0;i<n;i++){
		if(p[i].first!=prev){
			se.clear();
		}
		int v=uf.sz[uf.find(p[i].second)];
		if(v>=2){
			//printf("%d %d\n",v,ans);
			if(se.find(uf.find(p[i].second))==se.end()){
				ans+=v-1;
				se.insert(uf.find(p[i].second));
			}else{
				ans--;
			}
		}
		prev=p[i].first;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2176