akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
typedef pair<P, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int DX[4] = {-1, 0, 1, 0};
int DY[4] = {0, -1, 0, 1};

int K;
int W, H;
char S[20][20];
int id[20][20];
int dp[20][20][1<<10];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> W >> H) {
    if (W == 0 && H == 0) break;

    K = 0;
    int sx = -1, sy = -1;
    rep(y, H) {
      rep(x, W) {
        cin >> S[x][y];
        if (S[x][y] == 'o') sx = x, sy = y;
        if (S[x][y] == '*') id[x][y] = K++;
      }
    }
    rep(i, W) {
      rep(j, H) {
        rep(k, 1<<K) {
          dp[i][j][k] = INF;
        }
      }
    }

    queue<P2> q;
    q.push(P2(P(sx, sy), P(0, 0)));
    dp[sx][sy][0] = 0;

    while (!q.empty()) {
      P2 p = q.front(); q.pop();
      int x, y, b, d;
      tie(x, y) = p._1;
      tie(b, d) = p._2;
      rep(k, 4) {
        int nx = x+DX[k], ny = y+DY[k];
        if (nx<0 || nx>=W || ny<0 || ny>=H) continue;
        if (S[nx][ny] == 'x') continue;
        int nb = b;
        if (S[nx][ny] == '*') nb |= (1<<id[nx][ny]);
        if (dp[nx][ny][nb] > d+1) {
          dp[nx][ny][nb] = d+1;
          q.push(P2(P(nx, ny), P(nb, d+1)));
        }
      }
    }

    int m = INF;
    rep(i, W) {
      rep(j, H) {
        m = min(m, dp[i][j][(1<<K)-1]);
      }
    }
    if (m == INF) cout << -1 << "\n";
    else cout << m << "\n";
  }
  return 0;
}

Measured memory_bytes: 4828
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define el endl
#define ll long long int
int main()
{ ll a,k,i,p,q;
cin>>a>>k;
p=a%k;
q=(((a/k)+1)*k)-a;
if(p>q)cout<<q<<el;
else cout<<p<<el;}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  string s,t;
  cin >> n >> s >>t;
  string ans = "";
  rep(i,n){
    ans = ans + s[i] + t[i];
  }
  pri(ans);

  


  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int x = 0, a = 0;
		int N  = sc.nextInt();
		String S = sc.next();
		for(int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if(c == 'I') x++;	
			else if(c == 'D') x--;
			if(a < x) {
				a = x;
			}
		}
		System.out.println(a);
 
	}
 
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(void)
{
 int d,n;
 int i,s;

 scanf("%d%d", &d,&n);

 if(n==100) n++;

   if(d==0) s=n;

 else if(d==1) s=n*100;

 else if(d==2) s=n*100*100;

 printf("%d\n", s);
 return 0;
}


Measured memory_bytes: 128
twos =   [2 ** i for i in range(21) if 2 ** i <= 1000000]
threes = [3 ** i for i in range(21) if 2 ** i <= 1000000]
fives =  [5 ** i for i in range(21) if 2 ** i <= 1000000]
muls = [x * y * z for x in twos for y in threes for z in fives]
muls.sort()
def under(n):
  cnt = 0
  for i in muls:
    if i <= n:
      cnt += 1
    else:
      break
  return cnt

while True:
  s = input()
  if s == "0":
    break

  m, n = map(int, s.split())
  print(under(n) - under(m - 1))



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

const int INF = 1e+9;

int main() {
	int n, m, a, l;
	cin >> n >> m;
	bool painted[256] = {0};
	for(int i = 0; i < m; ++i){
		cin >> a >> l;
		for(int j = a; j < a + l; ++j){
			painted[j % n] = true;
		}
	}
	int start = INF;
	for(int i = 0; i < n; ++i){
		if(!painted[i])
			start = i;
	}
	if(start == INF){
		cout << n << " " << "1" << endl;
	}
	else{
		int cnt = 0;
		int ans[256] = {0};
		for(int i = start + 1; (i % n) != start; ++i){
			if(painted[i % n]){
				cnt++;
			}
			else{
				ans[cnt]++;
				cnt = 0;
			}
		}
		if(cnt > 0)
			ans[cnt]++;
		for(int i = n - 1; i >= 1; --i){
			if(ans[i]){
				cout << i << " " << ans[i] << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1168
#include <iostream>
#include <algorithm>
using namespace std;
int n,k;
int a[100010];
int b[100010];
int main()
{
	cin >>n>>k;
	for (int i=0;i<n;i++) cin >>a[i];
	b[0]=0;
	for (int i=1;i<n;i++)
	{
		b[i]=1e9;
		for (int j=1;j<=min(k,i);j++)
		    b[i]=min(b[i],b[i-j]+abs(a[i]-a[i-j]));
	}
	cout <<b[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	lint N, Q;
	cin >> N >> Q;
	vector<deque<lint>>A(N);
	rep(i, Q) {
		lint a;
		cin >> a;
		if (a == 0) {
			lint t, x;
			cin >> t >> x;
			A[t].push_front(x);
		}
		else if (a == 1) {
			lint t;
			cin >> t;
			if (!A[t].empty()) {
				cout << A[t][0] << endl;
			}
		}
		else if (a == 2) {
			lint t;
			cin >> t;
			if (!A[t].empty()) {
				A[t].pop_front();
			}
		}
	}
}




Measured memory_bytes: 5256
#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<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int waru(int n){
    int sum=0;
    while(n>0){
        n=n/10;
        sum++;
    }
    return sum;
}
   


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

    int a,b;
    cin>>a>>b;
    string s;
    string r;

    int sum=0;
    for(int i=a;i<=b;i++){
        s=to_string(i);
        if(s[0]==s[4] && s[1]==s[3])sum++;
        
    }
    
    
    cout<<sum<<endl;

}



Measured memory_bytes: 3720
def insertionSort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            cnt += 1
        a[j + g] = v

def shellSort(a, n):
    global cnt
    g = []
    h = 1
    for i in range(21):
        if h > n:    break
        g.append(h)
        h = h*3 + 1
    m = len(g)
    print(m)
    new_list = list(reversed(g))
    printArray(new_list)
    for i in range(len(g)-1, -1, -1):
        insertionSort(a, n, g[i])
    print(cnt)
    for i in range(len(a)):
        print(a[i])



#配列の出力
def printArray(array):
    print(' '.join(map(str, array)))

###----------mainここから---------------

#配列の要素数と要素の入力(複数行)
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 0
shellSort(a, n)


Measured memory_bytes: 45520
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N,M,start,goal;

struct Info{
	Info(){
		town = pre_town = 0;
		speed = time = 0.0;
	}

	Info(int arg_town,int arg_speed,double arg_time,int arg_pre_town){
		town = arg_town;
		speed = arg_speed;
		time = arg_time;
		pre_town = arg_pre_town;
	}
	int town,speed,pre_town;
	double time;
};

struct Road{
	Road(int arg_to,double arg_dist,int arg_speed_limit){
		to = arg_to;
		dist = arg_dist;
		speed_limit = arg_speed_limit;
	}
	int to,speed_limit;
	double dist;
};

void func(){

	double min_Time[N+1][N+1][31];

	for(int i = 1; i <= N; i++){
		for(int k = 1; k <= N; k++){
			for(int p = 1; p <= 30; p++)min_Time[i][k][p] = DBL_MAX;
		}
	}

	scanf("%d %d",&start,&goal);

	vector<Road> V[N+1];

	int from,to,limit;
	double dist;
	for(int i = 0; i < M; i++){
		scanf("%d %d %lf %d",&from,&to,&dist,&limit);
		V[from].push_back(Road(to,dist,limit));
		V[to].push_back(Road(from,dist,limit));
	}

	Info first;
	first.speed = 0;
	first.time = 0.0;
	first.town = start;
	first.pre_town = -1;

	queue<Info> Q;
	Q.push(first);

	int next_town,next_speed;
	double distance;

	while(!Q.empty()){

		if(Q.front().town == goal && Q.front().speed == 1){
			Q.pop();
		}else if(Q.front().time > min_Time[Q.front().town][Q.front().pre_town][Q.front().speed]){
			Q.pop();
		}else{

			for(int i = 0; i < V[Q.front().town].size();i++){
				next_town = V[Q.front().town][i].to;
				if(next_town == Q.front().pre_town)continue;

				limit = V[Q.front().town][i].speed_limit;
				distance = V[Q.front().town][i].dist;

				for(int k = -1;k <= 1; k++){
					next_speed = Q.front().speed + k;
					if(next_speed <= 0 || next_speed > limit)continue;

					if(min_Time[next_town][Q.front().town][next_speed] > Q.front().time + distance/(double)next_speed){
						min_Time[next_town][Q.front().town][next_speed] = Q.front().time + distance/(double)next_speed;
						Q.push(Info(next_town,next_speed,Q.front().time+distance/(double)next_speed,Q.front().town));
					}
				}
			}

			Q.pop();
		}
	}

	double minimum = DBL_MAX;
	for(int i = 1; i <= N; i++){
		minimum = min(minimum,min_Time[goal][i][1]);
	}
	if(minimum == DBL_MAX){
		printf("unreachable\n");
	}else{
		printf("%.6lf\n",minimum);
	}
}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3152
# -*- coding: utf-8 -*-
#標準入力の取得
N,M = map(int,input().split())
A = list(map(int,input().split()))

cutoff = sum(A)/(4*M)
count_pop = sum(i >= cutoff for i in A)


if count_pop<M :
    print("No")
else:
    print("Yes")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define mod 1000000007
#define N 100009
using namespace std;

int n,m; vi ans,f,a[9];
vi inv(vi a){
	int i; vi f; f.resize(n+1);
	for	(i=1; i<=n; i++) f[a[i]]=i;
	return f;
}
vi mrg(vi a,vi b){
	int i; vi c; c.resize(n+1);
	for (i=1; i<=n; i++) c[i]=b[a[i]];
	return c;	
}
void opt(vi f){
	int i;
	for (i=1; i<=n; i++) printf("%d%c",f[i],i<n?' ':'\n');	
}
int main(){
	scanf("%d%d",&n,&m);
	int i;
	a[1].resize(n+1); a[2].resize(n+1);
	for (i=1; i<=n; i++) scanf("%d",&a[1][i]);
	for (i=1; i<=n; i++) scanf("%d",&a[2][i]);
	if (m==1){ opt(a[1]); return 0; }
	for (i=3; i<=7; i++) a[i]=mrg(inv(a[i-2]),a[i-1]);
	f=mrg(mrg(inv(a[2]),a[1]),mrg(a[2],inv(a[1])));
	int tmp=(m-2)/6;
	m-=tmp*6;
	ans.resize(n+1);
	for (i=1; i<=n; i++) ans[i]=i;
	for (; tmp; tmp>>=1,f=mrg(f,f)) if (tmp&1) ans=mrg(ans,f);
	ans=mrg(mrg(ans,a[m]),inv(ans));
	opt(ans);
	return 0;
}


Measured memory_bytes: 6700
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    sort(a, a + n);

    p(a[n - 1] - a[0]);
}


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

using namespace std;

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

typedef modint<1000000007> mint;

mint memo1[100010];
mint memo2[100010];

mint comb(int x, int y) {
  mint ans = 1;
  for (int i = 1; i <= y; i++) {
    ans *= x - y + i;
    ans /= i;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 2);
  for (int i = 1; i <= n + 1; i++) {
    cin >> a[i];
  }
  auto b = a;
  sort(b.begin(), b.end());
  int diff = -1;
  for (int i = 1; i <= n + 1; i++) {
    if (i != b[i]) {
      diff = b[i];
      break;
    }
  }
  int start = -1, end = -1;
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] == diff) {
      if (start == -1) {
        start = i;
      } else {
        end = i;
        break;
      }
    }
  }
  int com = start - 1 + n + 1 - end;
  memo1[1] = n + 1;
  for (int i = 1; i <= n; i++) {
    memo1[i + 1] = memo1[i] * (n + 1 - i) / (i + 1);
  }
  memo2[0] = 1;
  memo2[1] = com;
  for (int i = 1; i < com; i++) {
    memo2[i + 1] = memo2[i] * (com - i) / (i + 1);
  }
  for (int k = 1; k <= n + 1; k++) {
    mint ans = memo1[k];
    if (com >= k - 1) {
      ans -= memo2[k - 1];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
int n,tot;
int arr[10001];
string s[10001];
string x;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>s[i]>>arr[i];
    }
    cin>>x;
    bool found=false;
    for (int i=0;i<n;i++){
        if (found) tot+=arr[i];
        if (x==s[i]) found=true;
    }
    cout<<tot;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAXINT = 200000;

// ll int check!
int main() {
  ll n, k;
  cin >> n >> k;
  ll sum = 0;
  for(int i = k; i < n+2; i++) {
    ll tmp_max = i * (n + 1 - i) + 1;
    //cout << tmp_max << endl;
    sum += tmp_max;
    sum %= MOD;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3584
package main

import (
	"fmt"
)

var (
	n int
	s string
)

func main() {
	fmt.Scan(&n)
	fmt.Scan(&s)
	var answer int
	for i := 0; i < n-2; i++ {
		if s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' {
			answer++
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Pi 3.14159265358979323846264338327950L

vector<int> edges[200005];


bool bfs(int n,int m, vector<int>& dis)
{
    queue<int> q;
    q.push(1);
    dis[1]=0;
    vector<int> visited(n+1,0);
    visited[1]=1;
    int visits=1;
    while(!q.empty())
    {
        int i=q.front();
        q.pop();
        for(auto j:edges[i])
        {
            if(visited[j]==0)
            {
                ++visits;
                visited[j]=1;
                dis[j]=i;
                q.push(j);
            }
        }
    }
    if(visits==n)
        return true;
    return false;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin >> t;
    while(t--){
        int n,m;
        cin>>n>>m;
        for(int i=0;i<m;i++)
        {
            int a,b;
            cin>>a>>b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vector<int> dis(n+1,1e10);
        bool flag=bfs(n,m,dis);
        if(!flag) cout<<"NO\n";
        else
        {
            cout<<"Yes\n";
            for(int i=2;i<=n;i++)
                cout<<dis[i]<<endl;
        }

}
return 0;

}


Measured memory_bytes: 13032
#include <algorithm>
#include <cstdio>
#include<iostream>
#include <cstring>
#include<stdlib.h>
#include<time.h>
#include<algorithm>
#define LL long long 
using namespace std;
const int maxn=3005;
int n,m;
int f[maxn][3*maxn][2];
const LL mod=1e9+7;
void Dp(){
for(int i=1;i<=n;i++)
f[i][0][1]=1;
f[0][0][0]=1;	

for(int j=0;j<=3*m;j++)
 for(int i=0;i<=n;i++)
{
if(j%3==1&&i>n-1) continue;
if(j%3==0&&i>n)  continue;
if(j%3==2&&i>n+1) continue;
if(i==0) {f[i][j][0]=(f[i][j][0]+f[i][j][1])%mod;f[i][j][1]=0;}
if(j%3==1)f[i+1][j+1][1]=(f[i+1][j+1][1]+f[i][j][1])%mod;
else {f[i][j+1][1]=(f[i][j+1][1]+f[i][j][1])%mod; if(i>0) f[i-1][j+1][1]=(f[i-1][j+1][1]+f[i][j][1])%mod;}
if(j%3==1)f[i+1][j+1][0]=(f[i+1][j+1][0]+f[i][j][0])%mod;
else {f[i][j+1][0]=(f[i][j+1][0]+f[i][j][0])%mod; if(i>0) f[i-1][j+1][0]=(f[i-1][j+1][0]+f[i][j][0])%mod;}
//printf("f[%d][%d][0]=%d f[%d][%d][1]=%d \n",i,j,f[i][j][0],i,j,f[i][j][1]);
}

}



int main(){
//freopen("C:\\Users\\deii\\Desktop\\test.txt","r",stdin);
//freopen("C:\\Users\\deii\\Desktop\\out.txt","w",stdout);	
scanf("%d%d",&n,&m);
Dp();
LL ans=0;
for(int i=0;i<=n;i++)
ans=(ans+f[i][3*m][0])%mod;
printf("%lld",ans);	
}

Measured memory_bytes: 211584
n,m=map(int,input().split())
A=list(int(input()) for i in range(m))+[-1]
dp=[0]*(n+1)
dp[0]=1
j=0
for i in range(1,n+1):
    if i==A[j]:
        dp[i]=0
        j +=1
    else:
        dp[i]=(dp[i-1]+dp[i-2])

print(dp[n]%1000000007)

Measured memory_bytes: 460020
import Control.Monad
import Data.List
import Data.Maybe

main = do
    n <- readLn :: IO Int
    pn <- map read . words <$> getLine :: IO [Int]
    qn <- map read . words <$> getLine :: IO [Int]
    let n' = sort $ permutations [1 .. n]
    let pn' = fromJust $ elemIndex pn n'
    let qn' = fromJust $ elemIndex qn n'
    print $ abs $ pn' - qn'

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    while(true){
        int D, E;
        std::cin >> D >> E;
        
        if(!D){break;}
        double res = 1e300;
    
        for(int x=0;x<=D;++x){
            int y = D - x;
            res = min(res, abs(sqrt(x * x + y * y) - E));
        }

        printf("%.10f\n", res);
    }
}



Measured memory_bytes: 3164
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)

typedef long long ll;
typedef unsigned long long ull;

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

int pts[110];
set<int> pset;
map<int, int> plist;

int main(){
    int a,b; char c;
    while(cin >> a >> c >> b){
        if(a == 0 && b == 0) break;
        pts[a] = b;
        pset.insert(b);
    }
    int n = 1;
    RFOREACH(it, pset){
        plist.insert(make_pair(*it, n++));
    }
    while(cin >> a){
        cout << plist[pts[a]] << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
N, X, M = map(int, input().split())

a = X
path = [a]  # path: 数列Ai
done = set([a])  # done: 既に登場したAiの項
while True:
    na = pow(a, 2, M)
    if na in done:
        s = path.index(na)  # 繰り返しが始まる箇所
        break
    else:
        path.append(na)
        done.add(na)
        a = na

if N < s + 1:  # N項目がループが始まる箇所よりも前の場合
    ans = sum(path[:N])
else:
    rest = N - s  # rest: ループに入った後の項目数
    x, y = divmod(rest, len(path) - s)  # x: ループを回る回数, y: 最後の1週に満たない項数

    ans = sum(path[:s])  # ループに入る前の和
    ans += sum(path[s:]) * x  # ループを繰り返す部分の和
    ans += sum(path[s: s + y])  # ループの最後の1週に満たない部分の和
print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
ll grandy(ll n) {
    if (n == 0) return 0;
    if (n % 2 == 1) return 1;
    return grandy(n / 2) * 2;
}
struct Node {
    ll depth;
    Node *lch, *rch;
    Node(ll depth) : depth(depth), lch(NULL), rch(NULL) {}
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, L; cin >> n >> L;
    Node* root = new Node(0);
    rep(i, n) {
        string s; cin >> s;
        Node* node = root;
        each(c, s) {
            if (c == '0') {
                if (node->lch == NULL) {
                    node->lch = new Node(node->depth+1);
                }
                node = node->lch;
            }
            else {
                if (node->rch == NULL) {
                    node->rch = new Node(node->depth+1);
                }
                node = node->rch;
            }
        }
    }
    function<ll(Node*)> dfs = [&](Node* node) {
        if (node->lch == NULL && node->rch == NULL) return 0LL;
        ll res = 0;
        if (node->lch == NULL) {
            res ^= grandy(L - node->depth);
        }
        else {
            res ^= dfs(node->lch);
        }
        if (node->rch == NULL) {
            res ^= grandy(L - node->depth);
        }
        else {
            res ^= dfs(node->rch);
        }
        return res;
    };
    if (dfs(root) != 0) {
        cout << "Alice" << endl;
    }
    else {
        cout << "Bob" << endl;
    }
}


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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
int bcnt[4096];

inline int c(int n, int w){
  int res=0;
  for(int i=0; n && i<w; i++){
    if(n&1) res++;
    n>>=1;
  }
  return res;
}

int solve(vi const& v, int const h, int const w){
  int ans=0;
  rep(mask,1<<w){
    int t=0;
    rep(i,h){
      int m=v[i]^mask;
      //int x=c(m,w);
      int x=bcnt[m];
      x=max(w-x,x);
      t+=x;
    }
    ans=max(ans,t);
  }
  return ans;
}

int main(){
  int h,w;
  for(int i=0; i<(1<<12); i++){
    int x=c(i,20);
    bcnt[i]=x;
    //printf("cnt[%d]=%d;\n",i,x);
  }

  //exit(0);
  
  while(cin>>h>>w && h+w){
    vvi v(h,vi(w));
    vi o(w);
    rep(i,h)rep(j,w) cin>>v[i][j];
    rep(i,w){
      int t=0;
      rep(j,h){
	t<<=1;
	t|=v[j][i];
      }
      o[i]=t;
    }
    cout << solve(o,w,h) << endl;
  }
}

Measured memory_bytes: 1612
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

int main() {
  int n, ans = 0;
  string s;

  cin>>n;
  cin>>s;

  for(int i = 0; i<n-2; i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      ans++;
    }
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}
fn main() {
    let n:i32 = read();
    let mut vect: Vec<i32> = read_vec();
    vect.sort();
    println!("{}", vect[(n / 2) as usize] - vect[(n / 2 - 1) as usize]);
}

Measured memory_bytes: 4352
import java.util.*;
import java.io.*;

public class Main {
	
	public void solve() throws IOException{
		int n = nextInt();
		int[] height = new int[6];
		for(int i = 0; i < n; i++){
			double h = nextDouble();
			if( h < 165 ){
				height[0]++;
			} else {
				int index = (int)(h-165)/5 + 1;
				index = Math.min(5, index);
				height[index]++;
			}
		}
		for(int i = 0; i < 6; i++){
			writer.print((i+1) + ":");
			while( height[i]-- > 0 ){
				writer.print("*");
			}
			writer.println();
		}
	}			
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public double nextDouble() throws IOException{
		return Double.parseDouble(nextToken());
	}
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 9324
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
map<ll,bool>used;
inline ll oper(ll n,ll m){
	while(n>=m){
		if(n%m==0)n/=m;
		else n%=m;
	}
	return n;
}
set<ll>ans;
int main(void){
	ll n;
	cin>>n;
	if(n==1){
		cout<<0;
		return 0;
	}
	if(n==2){
		cout<<1;
		return 0;
	}
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(oper(n,i)==1){
				ans.insert(i);
			}
			if(oper(n,n/i)==1){
				ans.insert(n/i);
			}
		}
//		cout<<i<<' '<<k<<endl;
	}
	n--;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ans.insert(i);
			ans.insert(n/i);
		}
//		cout<<i<<' '<<k<<endl;
	}
	cout<<ans.size()+2;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
int dx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
int dy[] = { -1, -1, -1, 0, 1, 1, 1, 0 };

int main(){
	int w, h;
	while( cin >> w >> h && w && h ){
		int field[52][52];
		stack< pair<int, int> > st;
		for( int i = 1; i <= h; i++ ){
			for( int j = 1; j <= w; j++ ){
				cin >> field[i][j];
			}
		}
		int sum = 0;
		for( int i = 1; i <= h; i++ ){
			for( int j = 1; j <= w; j++ ){
				if( field[i][j] == 1 ){
					sum++;
					field[i][j] = 0;
					st.push( pair<int, int>(i, j) );
					while( !st.empty() ){
						int x0 = st.top().second;
						int y0 = st.top().first;
						st.pop();
						for( int k = 0; k < 8; k++ ){
							int x = x0 + dx[k];
							int y = y0 + dy[k];
							if( field[y][x] == 1 ){
								st.push( pair<int, int>(y, x) );
								field[y][x] = 0;
							}
						}
					}
				}
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1232
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

//#include "atcoder.hpp"

long long gcd(long long a, long long b) {
    if (a>b) swap(a,b);
    
    auto r = b % a;
    
    return (r ? gcd(r, a) : a);
}

int main() {
    long long X, Y, Z, K;
    
    cin >> X >> Y >> Z >> K;
    long long A[1000], B[1000], C[1000];
    
    REP(i,X)
        cin >> A[i];
    REP(i,Y)
    cin >> B[i];
    REP(i,Z)
    cin >> C[i];
    
    multiset<long long> XY;
    
    REP(i,X) REP(j,Y) {
        long long tmp = A[i] + B[j];
        if (XY.size() < 1000 || tmp > *XY.begin()) XY.insert(tmp);
    }
    
    priority_queue<long long> XYZ;
    int cnt = 3000;
    for (auto it = XY.rbegin(); cnt-- && it != XY.rend(); ++it)
    REP(i,Z) {
        XYZ.push(*it + C[i]);
    }
    
    while (K--) {
    cout << XYZ.top() << endl;
        XYZ.pop();
    }
    
    return 0;
}



Measured memory_bytes: 81764
#include <algorithm>  
#include <iostream>  
#include <iomanip>
#include <sstream>  
#include <string>  
#include <cstring>
#include <cmath>
#include <vector>  
#include <queue>  
#include <stack>
#include <deque>
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>
#include <cstdint>
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
#include <fstream>
#include <ios>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <utility>
#include <array>
#include <numeric>
#include <complex>
#include <memory>



using namespace std;

using i32 = int32_t;
using u32 = uint32_t;

using i64 = int64_t;
using u64 = uint64_t;


i64 Gcd(i64 a, i64 b) {
    return b == 0 ? a : Gcd(b, a % b);
}

void Solve() {
    i64 n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    if (s.front() != t.front()) {
        cout << -1 << '\n';
        return;
    }
    i64 lcm{ n * m / Gcd(n, m) };
    int step_s{ static_cast<int>(lcm / m) };
    int step_t{ static_cast<int>(lcm / n) };
    int i{ 0 };
    int j{ 0 };
    while (true) {
        if (s[i] != t[j]) {
            cout << -1 << '\n';
            return;
        }
        i += step_s;
        j += step_t;
        if (i >= n || j >= m) {
            break;
        }
    }
    cout << lcm << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ifstream input{ "input.txt" };
    //cin.rdbuf(input.rdbuf());

    Solve();

    return 0;
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/agc040/tasks/agc040_a

#include "algorithm"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  string S;
  cin >> S;

  ll N = S.size() + 1;
  vector<ll> values(N, -1);

  vector<bool> root(N);

  rep(i, N) {
    char c = i == N - 1 ? '#' : S[i];
    if ((i == 0 || S[i - 1] == '>') && (i == N - 1 || S[i] == '<')) {
      root[i] = true;
      values[i] = 0;
    }
  }

  rep(i, N) {
    if (!root[i]) continue;

    for (ll j = i; (j < S.size()) && S[j] == '<'; j++) {
      if (values[j + 1] > values[j]) continue;
      values[j + 1] = values[j] + 1;
    }
  }

  for (ll i = N - 1; i >= 0; i--) {
    if (!root[i]) continue;

    for (ll j = i; (j >= 1) && S[j - 1] == '>'; j--) {
      if (values[j - 1] > values[j]) continue;
      values[j - 1] = values[j] + 1;
    }
  }

  ll res = 0;
  for (auto v : values) {
    res += v;
  }

  cout << res << endl;
}

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

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

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

  return 0;
}
#endif

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

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

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

    cout << v[i];
  }

  cout << endl;
}

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


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 1e9

int main(int argc, char const *argv[])
{
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (a * b) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int H,W; cin >> H >> W;
    char a[H][W];
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> a[i][j];
        }
        
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if(a[i][j] == '#') break;
            if(j==W-1){
                for (int k = 0; k < W; k++)
                {
                    a[i][k] = '@';
                }
            }
        }
    }
    for (int j = 0; j < W; j++)
    {
        for (int i = 0; i < H; i++)
        {
            if(a[i][j] == '#') break;
            if(i==H-1){
                for (int k = 0; k < H; k++)
                {
                    a[k][j] = '@';
                }
            }
        }
    }
    
    for (int i = 0; i < H; i++)
    {
        int cnt = 0;
        for (int j = 0; j < W; j++)
        {
            if(a[i][j] != '@') cout << a[i][j];
            else cnt++;
        }
        if(cnt != W) cout << endl;
    }

}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> x(N), y(N);
    for(int i=0; i<N; i++) {
        cin >> x[i] >> y[i];
    }
    
    int ans = N;
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            int p = x[i] - x[j];
            int q = y[i] - y[j];
            if(!(p != 0 or q != 0)) continue;

            vector< vector<int> > G(N);
            vector<int> deg(N);
            for(int u=0; u<N; u++) {
                for(int v=0; v<N; v++) {
                    if(x[u] + p == x[v] and y[u] + q == y[v]) {
                        G[u].emplace_back(v);
                        deg[v] = 1;
                    }
                }
            }

            int cand = N - accumulate(deg.begin(), deg.end(), 0);
            ans = min(ans, cand);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# D
N, M = map(int, input().split())
A_list = list(map(int, input().split()))
needs_list = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# DP
DP = [-1]*(N+8)
DP[0] = 0
for i in range(N):
    for a in A_list:
        j = i+needs_list[a]
        DP[j] = max(DP[j], DP[i]*10+a)
print(DP[N])

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  int X = b-a;
  int Y = c-b;
  
  if (X==Y) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    I vec;
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    int co[9]={0};
    REP(a,N){
        int v = vec.at(a);
        if(399>=v&&v>=1){
            co[0]++;
        }else
        if(799>=v&&v>=400){
            co[1]++;
        }else
        if(1199>=v&&v>=800){
            co[2]++;
        }else
        if(1599>=v&&v>=1200){
            co[3]++;
        }else
        if(1999>=v&&v>=1600){
            co[4]++;
        }else
        if(2399>=v&&v>=2000){
            co[5]++;
        }else
        if(2799>=v&&v>=2400){
            co[6]++;
        }else
        if(3199>=v&&v>=2800){
            co[7]++;
        }else{
            co[8]++;
        }
    }
    int ansm=0,ansb= 0;
    for(int a = 0;a < 9;a++){
        if(co[a]!=0&&a!=8){
            ansm++;
            ansb++;
        }else
        if(a==8){
            ansm+=co[8];
            if(ansb==0)ansb++;
        }
    }
    cout<<ansb<<" "<<ansm<<endl;
    return 0;
}


Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    MOD = 10 ** 9 + 7
    
    if N == M:
        ans = 1
        for i in range(2, N + 1):
            ans = ans * i % MOD
        ans = (ans ** 2 % MOD) * 2 % MOD
        print(ans)
    elif 1 < abs(N - M):
        print(0)
    else:
        ans = 1
        for i in range(2, N + 1):
            ans = ans * i % MOD
        for i in range(2, M + 1):
            ans = ans * i % MOD
        print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; long long m; cin >> n >> m;
  vector<int> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a));
  int lb = 2, ub = 200001;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    long long big = 0;
    REP(i, n) big += n - (lower_bound(ALL(a), mid - a[i]) - a.begin());
    (big >= m ? lb : ub) = mid;
  }
  vector<long long> sum(n + 1, 0);
  FOR(i, 1, n + 1) sum[i] = sum[i - 1] + a[i - 1];
  long long ans = 0, pat = 0;
  REP(i, n) {
    int idx = lower_bound(ALL(a), lb - a[i]) - a.begin();
    ans += 1LL * a[i] * (n - idx) + sum[n] - sum[idx];
    pat += n - idx;
  }
  ans -= (pat - m) * lb;
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

bool unbalance(string s) {
    return (s[0] == s[1] || s[1] == s[2] || s[2] == s[0]);
}

int main() {
    string s;
    cin >> s;
    int l = s.length();

    rep(i, l - 2) {
        if (unbalance(s.substr(i, 3))) {
            printf("%d %d\n", i + 1, i + 3);
            return 0;
        }
    }

    if (l == 2 && s[0] == s[1]) {
        printf("1 2\n");
        return 0;
    }

    printf("-1 -1\n");
    return 0;
}



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

int main(){
	int n; cin >> n;
	vl p(n); rep(i,n)cin >> p[i];
	sort(p.begin(), p.end());
	int ans = p[n-1]/2;
	rep(i,n-1)ans += p[i];
	cout << ans << endl;

}

Measured memory_bytes: 256