akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

struct UnionFind {
  vector<int> data;
  vector<ll> dis;
  UnionFind(int size) : data(size, -1), dis(size,0) { }
  bool unionSet(int x, int y, ll d) {
    ll disx = dist(x);
    ll disy = dist(y);
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) {
        swap(x, y), d=-d;
        swap(disx,disy);
      }
      data[x] += data[y]; data[y] = x;
      dis[y] = disx + d - disy;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    if (data[x]<0) return x;
    else {
      int r = root(data[x]);
      dis[x] += dis[data[x]];
      return data[x] = r; // root(data[x]);
    }
    // return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
  int dist(int x) {
    root(x);
    return dis[x];
  }
};

int main() {
  int n,m;
  while(cin>>n>>m,n||m) {
    UnionFind uf(n);
    REP(i,m) {
      // REP(j,n) cout << uf.data[j] << " "; cout << endl;
      // REP(j,n) cout << uf.dis[j] << " "; cout << endl;
      char c; cin >> c;
      if (c == '!') {
        int a, b, d;
        cin >> a >> b >> d;
        a--;b--;
        uf.unionSet(a,b,d);
      } else {
        int a, b;
        cin >> a >> b;
        a--;b--;
        if (uf.findSet(a,b)) {
          ll d1 = uf.dist(a);
          ll d2 = uf.dist(b);
          cout << d2-d1 << endl;
        } else {
          puts("UNKNOWN");
        }
      }
    }
  }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;
using PIC = pair<int32, char>;

int32 table[112345][20] = {};
int32 N, Q;
int64 L;
vector<int64> x;

void init(){
	REP(i, N){
		table[i][0] = upper_bound(all(x), x[i]+L)-x.begin()-1;
	}
	REP(i, 19){
		REP(j, N){
			table[j][i+1] = table[table[j][i]][i];
		}
	}
}

int main(void){
	cin >> N;
	x.resize(N);
	REP(i, N) cin >> x[i];
	cin >> L >> Q;
	init();
	REP(_, Q){
		int32 a, b;
		cin >> a >> b; a--; b--;
		if(a > b) swap(a, b);
		int32 res = 0;
		while(table[a][0] < b){
			REP(i, 20){
				if(table[a][i] >= b){
					a = table[a][i-1];
					res += 1 << (i-1);
					break;
				}
			}
		}
		res++;
		cout << res << endl;
	}
}

Measured memory_bytes: 17920
/*
ACplease
　　 ●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#include <cassert>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------------------------------------
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);
    srand((unsigned)time(NULL));
    
    int n,c[200000+10],a[200000+10];
    cin >> n;
    for(int i=1;i<=n;i++){
    	cin >> a[i];
    	c[a[i]]++;
    }
    int sum = 0;
    for(int i=0;i<=n;i++){
    	if(c[i] >= 2){
    		sum += 1ll*c[i]*(c[i]-1)/2;
    	}
    }
    for(int i=1;i<=n;i++){
    	cout << sum-c[a[i]]+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <cstring>

int half[2001]; //0<=a, b<=1000 として a+b となる組み合わせの数

void makeSet(){
	memset(half, 0, sizeof(half));
	//半分全列挙
	for(int i=0; i<=1000; ++i){
		for(int j=0; j<=1000; ++j){
			int k=i+j;
			++half[k];
		}
	}
}

int solve(int n){
	int num=0;
	int max=n<2000?n:2000; //Counterが半分全列挙の上限を超えない為

	for(int i=0; i<=max; ++i){
		if(n-i<=2000) num+=half[i]*half[n-i]; //左半分の組み合わせ * 右半分の組み合わせ = 全組み合わせ
	}
	return num;
}

int main(){
	makeSet();

	while(true){
		int n;
		std::cin>>n;
		if(std::cin.eof()) break;
		
		std::cout<<solve(n)<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int n;
	double xa,ya,ra,xb,yb,rb;
	double d;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
		d = ((xa-xb)*(xa-xb))+((ya-yb)*(ya-yb));
		if(sqrt(d)+rb<ra)
		printf("2\n");
		else if(sqrt(d)+ra<rb)
		printf("-2\n");
		else if(sqrt(d)<=ra+rb)
		printf("1\n");
		else
		printf("0\n");
	}
}

Measured memory_bytes: 3152
#include <stdio.h>

int main(){
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);

  if(1 <= a && a <= 9 && 1 <= b && b <= 9){
    printf("%d\n", a*b);
  }else{
    printf("-1\n");
  }

  return 0;
}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll N, M;
vi A;

void solve(){
    rep(i, M){
        N -= A[i];
    }

    if(N < 0) cout << -1 << endl;
    else cout << N << endl;
}

int main(){
    cin >> N >> M;
    A.resize(M);

    rep(i, M) cin >> A[i];

    solve();
}


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

int main(){
  string s;
  cin>>s;
  if((s[0]==s[1] && s[1]==s[2]) || (s[1]==s[2] && s[2]==s[3])){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int main() {
  int i, j;
  int h, w;
  cin >> h >> w;
  vector<vector<char>> board(h, vector<char>(w));
  for(i=0; i<h; i++) {
    for(j=0; j<w; j++) {
      cin >> board.at(i).at(j);
    }
  }
  
  vector<bool> cutH(h, false);
  vector<bool> cutW(w, false);
  for(i=0; i<h; i++) {
    if(board.at(i).at(0) == '.') {
      for(j=0; j<w; j++) {
        if(board.at(i).at(j) == '#')
          break;
      }
      if(j==w)
        cutH.at(i) = true;
    }
  }
  for(j=0; j<w; j++) {
    if(board.at(0).at(j) == '.') {
      for(i=0; i<h; i++) {
        if(board.at(i).at(j) == '#')
          break;
      }
      if(i==h)
        cutW.at(j) = true;
    }
  }
  
  for(i=0; i<h; i++) {
    if(!cutH.at(i)) {
      for (j=0; j<w; j++) {
        if(!cutW.at(j))
          cout << board.at(i).at(j);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
var   s:ansistring;   i,sum,cnt:longint;
begin
    readln(s);
    for i:=1 to length(s) do
      begin 
          if s[i]='S' then inc(sum);
            if s[i]='T' then 
              begin
                if (sum<>0)then begin dec(sum);inc(cnt,2);end;
              end;
      end;
   writeln(length(s)-cnt);
end.

Measured memory_bytes: 384
import sys

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = ''
q2 = ''
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1 += C
        else:
            q2 += C

ans = ''
if state == 0:
    print(q1[::-1], end='')
    print(S, end='')
    print(q2)
else:
    print(q2[::-1], end='')
    print(S[::-1], end='')
    print(q1)


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

using namespace std;

const int INF = 1e9;

int main(){
	int n;
	cin >> n;
	vector<int> h(n),dp(n,INF);
	for(int &x:h) cin >> x;
	dp[0] = 0;
	for(int i=0;i<n;++i){
		if(i+1 < n){
			dp[i+1] = min(dp[i+1],dp[i] + abs(h[i]-h[i+1]));
		}
		if(i+2 < n){
			dp[i+2] = min(dp[i+2],dp[i] + abs(h[i]-h[i+2]));
		}
	}


	/*
	for(int i=0;i<n;++i){
		cout << dp[i] << " \n"[i==n-1];
	}
	*/

	cout << dp[n-1] << '\n';

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;



void solve(long long N, long long X, long long Y){
    // 頂点数と辺数
    int M;
    M = N+1;

    vector<int> counts(N);
    fill(counts.begin(), counts.end(), 0);

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N+1);
    for (int i = 0; i < N; ++i) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[X-1].push_back(Y-1);
    G[Y-1].push_back(X-1);

    for(int i = 0; i < N; i++) {
        // BFS のためのデータ構造
        vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
        queue<int> que;

        // 初期条件 (頂点 0 を初期ノードとする)
        dist[i] = 0;
        que.push(i); // 0 を橙色頂点にする

        // BFS 開始 (キューが空になるまで探索を行う)
        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : G[v]) {
                if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }

        // 結果出力 (各頂点の頂点 0 からの距離を見る)
        for (int v = i; v < N; ++v){
            // cout << v << ": " << dist[v] << endl;
            counts[dist[v]]++;
        }
    }
    for(int i = 1; i < counts.size(); i++) {
        cout << counts[i] << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
    return 0;
}


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

public class Main {

	public static final int mod = 1000000007;
	
	public static int count(int k) { //count number of ones in binary
		int c = 0;
		while (k > 0) {
			k &= k-1;
			c++;
		}
		return c;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] s;
		boolean[][] matches = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			s = br.readLine().split(" ");
			for (int j = 0; j < n; j++)
				matches[i][j] = Integer.parseInt(s[j]) == 1;
		}

		int[] dp = new int[(1 << n)];
		dp[0] = 1;
		for (int j = 0; j < (1 << n) - 1; j++) {
			int left = count(j); //number of women left
			for (int i = 0; i < n; i++) { //left therefore goes from n toward zero
				if (matches[left][i] && !((j & (1<<i)) == 1)) {
					//if man [i] can be matched with woman [#remaining]
					//and this woman has not already been taken
					dp[j^(1<<i)] = (dp[j^(1<<i)] + dp[j]) % mod;
					
					//then add onto the case where this woman is taken (XOR)
					//the number of possibilities if she had not
				}
			}
		}
		System.out.println(dp[(1<<n)-1]);

	}

}


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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for(int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  for(int i = 0; i < n; i++){
    cin >> c.at(i);
  }
  
  int value = 0;
  int ans = 0;
  
  for(int bit = 0; bit < (1<<n); ++bit){
    for(int i = 0; i < n; i++){
      if(bit & (1 << i)){
        ans = ans + v.at(i) - c.at(i);
      }
    }
    if(ans > value){
      value = ans;
    }
    ans = 0;
  }
   cout << value << endl;
}
      
    

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <cmath>
#include <algorithm>
#include <cassert>

#define TEST_ASSERT(msg, cond) do { if (cond) { cout << msg << " => pass" << endl;} else { cout << msg << " => failed" << endl;} } while(0)

using namespace std;

namespace {
  int H, W;
}

int bfs(const vector<vector<char>>& s) {
  vector<vector<int>> distance(H, vector<int>(W, INT_MAX));
  queue<pair<int, int>> q;
  q.push(pair<int, int>(0, 0));
  distance[0][0] = 0;

  while (!q.empty()) {
    pair<int, int> pos = q.front();
    q.pop();

    int currentDis = distance[pos.first][pos.second];
    //cout << "i, j = " << pos.first << ", " << pos.second << endl;
    //cout << "dis = " << currentDis << endl;

    if (pos.first == H - 1 && pos.second == W - 1) {
      return distance[pos.first][pos.second];
    }

    if (pos.first - 1 >= 0) {
      int i = pos.first - 1;
      int j = pos.second;
      int dis = distance[pos.first][pos.second] + 1;
      if (s[i][j] == '.' && distance[i][j] > dis) {
        distance[i][j] = dis;
        q.push(pair<int, int>(i, j));
      }
    }
    if (pos.first + 1 < H) {
      int i = pos.first + 1;
      int j = pos.second;
      int dis = distance[pos.first][pos.second] + 1;
      if (s[i][j] == '.' && distance[i][j] > dis) {
        distance[i][j] = dis;
        q.push(pair<int, int>(i, j));
      }
    }
    if (pos.second - 1 >= 0) {
      int i = pos.first;
      int j = pos.second - 1;
      int dis = distance[pos.first][pos.second] + 1;
      if (s[i][j] == '.' && distance[i][j] > dis) {
        distance[i][j] = dis;
        q.push(pair<int, int>(i, j));
      }
    }
    if (pos.second + 1 < W) {
      int i = pos.first;
      int j = pos.second + 1;
      int dis = distance[pos.first][pos.second] + 1;
      if (s[i][j] == '.' && distance[i][j] > dis) {
        distance[i][j] = dis;
        q.push(pair<int, int>(i, j));
      }
    }
  }
  return -1;
}

int main() {
  cin >> H >> W;

  if (H <= 0 || W <= 0) {
    cout << 0 << endl;
    return 0;
  }

  vector<vector<char>> s(H, vector<char>(W));

  int cntWhite = 0;
  for (int i = 0; i < H; i++) {  
    for (int j = 0; j < W; j++) {
      char val;
      cin >> val;
      s[i][j] = val;

      //cout << val << endl;

      if (val == '.') cntWhite++;
    }
  }
  int dis = bfs(s);
  if (dis >= 0) {
    cout << cntWhite - dis - 1 << endl;
  }
  else {
    cout << -1 << endl;
  }
  //cout << cntWhite << endl;

  return 0;
}


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

using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); 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--)
//end.DEFINE---}}}

//end.template ---}}}

int main() {
  int N;
  int N_cp;
  int SN = 0;
  int num;
  cin >> N;

  N_cp = N;

  while (N) {
    num = N % 10;
    SN += num;
    N /= 10;
  }

  if (N_cp % SN == 0) cout << "Yes" << endl;
  else if (N_cp % SN != 0) cout << "No" << endl;

  return (0);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
struct Line {
	int from;
	int to;
	int id;
	long long int cost;
};
struct aa {
	Line l;
	pair<long long int,int> time;
};
class Compare {
public:
	//aa?????????????????¶
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
map<string, int>mp;
vector<pair<long long int,int>>memo;
int main() {
	int N;long long int  T; cin >> N >> T;
	memo = vector<pair<long long int, int>>(100000, make_pair(1e18,0));
	vector<vector<Line>>ls(300000);
	string Start, Goal; cin >> Start >> Goal;
	mp[Start] = 0;
	mp[Goal] = 1;
	int num = 2;
	int id = 0;
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		vector<int>stas;
		for (int j = 0; j < a; ++j) {
			string st; cin >> st;
			if (mp.find(st) == mp.end()) {
				mp[st] = num;
				num++;
			}
			stas.push_back(mp[st]);

		}
		for (int j = 0; j < a - 1; ++j) {
			int a; cin >> a;
			ls[stas[j]].push_back(Line{ stas[j],stas[j + 1],id,a });
			ls[stas[j+1]].push_back(Line{ stas[j+1],stas[j],id,a });
			id++; 
		}
		id++;
	}
	priority_queue<aa, vector<aa>, Compare>que;

	que.push(aa{ Line{-1,0,-100,0},make_pair(-T,-1) });
	long long int ans = -1;
	int change = -1;
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		const int nowid = atop.l.id;
		const int nowtime = atop.time.first;
		const int nowchange = atop.time.second;
		const int now = atop.l.to;
		if (now == 1) {
			ans = nowtime;
			change = nowchange;
			break;
		}
		for (auto l : ls[now]) {
			const bool sameid = abs(l.id - nowid)<=1;
			const long long int nexttime = sameid ? nowtime + l.cost : nowtime + l.cost + T;
			const int nextchange = sameid ? nowchange : nowchange + 1;
			const auto nextp = make_pair(nexttime, nextchange);
			if (nextp < memo[l.id]) {
				memo[l.id] = nextp;
				que.push(aa{ l,nextp });
			}
		}

	}
	if (ans == -1) {
		cout << -1 << endl;
	}
	else {
		cout << ans << " " << change << endl;
	}
	return 0;
}

Measured memory_bytes: 27204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
//#define endl "\n"

#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    bool b=true;
    ll ans=0;
    while(b){
        b=false;
        ll sum=0;
        ll d[n];
        rep(i,0,n-1){
            d[i]=a[i]/n;
            a[i]=a[i]-d[i]*n;
            sum+=d[i];
        }
        if(sum>0)b=true;
        rep(i,0,n-1){
            a[i]=a[i]+sum-d[i];
        }
        ans+=sum;
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 256
function main()
	X,Y=parse.(Int,split(readline()))
	a,b,c,flg=-1,-1,-1,0
	for n= 0:X
		for m=0:X-n
			l=X-n-m
			if Y==1000n+5000m+10000l
				a=l
				b=m
				c=n
				flg+=1
				break
			end
		end
		if flg>0
			break
		end
	end
	println(string(a," ",b," ",c))
end

main()

Measured memory_bytes: 173096
#include <bits/stdc++.h>
using namespace std;
 
#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
 #define PI acos(-1)
 #define MOD ((int)1e9+7)
typedef long long     ll;
 
//-*-*-*-*-*-*-*-*-
 
 

 
const int N=2e5+100;
ll visited[100005];
//ll a[200000];
 

#define lop(i,n) for(int i=0;i<n;++i)
//ll n,m,mod;

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

const int MAX = 2e5 + 10 ;
void finis(){cout<<-1;}

 map<ll,ll>mp;
int main()
{  ios::sync_with_stdio(0);
    cin.tie(0);
ll ans=0;
  ll n,k;
     cin>>n;ll a[n];ll sum=0;
     for(int i=0;i<n;i++){cin>>a[i];mp[a[i]]++;sum+=a[i];}cin>>k;
      for(int i=0;i<k;i++){ll x,y;
          cin>>x>>y;
          sum-=x*mp[x];sum+=y*mp[x];mp[y]+=mp[x];mp[x]=0;
          cout<<sum<<endl;
      }
    
 
    
 
 
 
}


Measured memory_bytes: 10244
//鎴戝ソ寮卞憖
//杩欑棰橀兘鍋氫笉鏉?
//qwq
//qwq
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 100000
#define INF 10000000000000000
#define Fi first
#define Se second
int n,m;
int u,v;
long long S;
long long vis[2][MAXN+5];
vector < pair<int,long long> > G[MAXN+5];
long long R,L=0;
bool flag=0;
int Get_num(int x)
{
	if(x==-1)x=0;
	return x;
}
void dfs(int x,int p,long long sum)
{
	if(flag)return ;
	for(int i=0;i<G[x].size();i++)
	{
		int xnext=G[x][i].Fi;
		long long val=G[x][i].Se;
		int Pnum=Get_num(p);
		long long Nsum=sum+p*val;
		//printf("::%d %d\n",xnext,Nsum);
		if(vis[Pnum][xnext]!=INF)
		{
			if(Nsum!=vis[Pnum][xnext])flag=1;
			continue;
		}
		else vis[Pnum][xnext]=Nsum;
		if(Pnum==0)L=max(L,Nsum);
		else R=min(R,Nsum);
		dfs(xnext,-p,Nsum);
	}
}
int main()
{
	//freopen("graph.in","r",stdin);
	//freopen("graph.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld",&u,&v,&S);
		G[u].push_back(make_pair(v,S));
		G[v].push_back(make_pair(u,S));
	}
	for(int i=0;i<=1;i++)
		fill(vis[i]+1,vis[i]+MAXN+1,INF);
	R=INF;
	dfs(1,1,0);
	if(flag){printf("0\n");return 0;}
	long long Nx=0;
	for(int i=1;i<=n;i++)
		if(vis[0][i]!=INF&&vis[1][i]!=INF)
		{
			long long X=(vis[0][i]+vis[1][i])/2;
			if(Nx!=0)
			{
				if(X!=Nx){flag=1;break;}
			}
			else Nx=X;
		}
	if(flag){printf("0\n");return 0;}
	if(Nx)
	{
		if(Nx>L&&Nx<R)printf("1");
		else printf("0");
		return 0;
	}
	printf("%lld",max(R-L-1,(long long)0));
}


Measured memory_bytes: 21760
N = int(input())
H = list(map(int,input().split()))
a = 0
ans = [0]
for i in range(N - 1):
    if H[i + 1] <= H[i]:
        a += 1
        if i == N - 2:
            ans.append(a)
    else:
        ans.append(a)
        a = 0
ans = sorted(ans)
l = len(ans)
print(ans[l - 1])

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


int main(){
 int n;
  cin>>n;
  vector<int> p(n),q(n);
  for(int i=0;i<n;i++) cin>>p[i];
  for(int i=0;i<n;i++) cin>>q[i];
  vector<int> a(n);
  for(int i=0;i<n;i++) a[i]=i+1;
  int i=0;
  int aa,bb;
  do{
    i++;
    bool pp=true,qq=true;
    for(int j=0;j<n;j++){
      if(p[j]!=a[j]) pp=false;
      if(q[j]!=a[j]) qq=false;
    }
    if(pp) aa=i;
    if(qq) bb=i;
  }while(next_permutation(a.begin(),a.end()));
  cout<<abs(aa-bb)<<endl;
}

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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    printf("%d",a[n/2+1]-a[n/2]);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main(){
  int n;
  cin>>n;
  int ans = 1;
  while(ans<=n){
    ans *= 2;
  }
  cout<<ans/2<<endl;


}



Measured memory_bytes: 256
package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan() 
	t := scanner.Text()
	tr := []rune(t)
	
	if tr[len(tr)-1] == 's' {
		fmt.Printf("%ses\n", t)
		return
	}
	fmt.Printf("%ss\n", t)
}


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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/


int main() {
	double r;
	cin >> r;
	printf("%.10f", 2 * PI * r);
	
	return 0;
}










Measured memory_bytes: 3816
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

const LL inf = 112345678;
LL N, M, ans;
std::vector<LL>a, b, c;
std::vector<std::vector<LL>>dist;

void warshall_floyd(LL V)
{
	for (LL k = 1; k <= V; ++k)
	{
		for (LL i = 1; i <= V; ++i)
		{
			for (LL j = 1; j <= V; ++j)
			{
				dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
}

int main()
{
	in >> N >> M;
	a.resize(M), b.resize(M), c.resize(M);
	rep(i, M) in >> a[i] >> b[i] >> c[i];
	dist.resize(N + 1);
	rep(i, dist.size()) dist[i].resize(N + 1);
	rep(i, dist.size()) rep(j, dist[i].size()) dist[i][j] = inf;
	rep(i, N) dist[i + 1][i + 1] = 0;
	rep(i, M) dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
	warshall_floyd(N);
	rep(i, M)
	{
		bool flag = true;
		rep(j, N)
		{
			if (dist[j + 1][b[i]] == dist[j + 1][a[i]] + c[i] || dist[j + 1][a[i]] == dist[j + 1][b[i]] + c[i])
			{
				flag = false;
				break;
			}
		}
		if (flag) ++ans;
	}
	out << ans << std::endl;
	return 0;
}


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

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

    int k = 1+n%2;
    ll dp[n+1][4];
    rep(i, n+1)rep(j, k+1) dp[i][j] = INT64_MIN/2;
    dp[0][0] = 0;
    rep(i, n){
        rep(j, k+1){
            dp[i+1][j+1] = max<ll>(dp[i+1][j+1], dp[i][j]);
            ll now = dp[i][j];
            if((i+j)%2 == 0) now += a[i];
            dp[i+1][j] = max<ll>(dp[i+1][j], now);
        }
    }
    cout << dp[n][k] << endl;

    return 0;
}

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

int		main(void)
{
	int ct = 0;
	int N, K;
	int d;
	int A[100];
	int sunuke;

	for (int k = 0; k < 100; k++)
	{
		A[k] = 0;
	}

	cin >> N >> K;
	for (int i = 0; i < K; i++)
	{
		cin >> d;
		for (int j = 0; j < d; j++)
		{
			cin >> sunuke;
			A[sunuke - 1]++;
		}
	}
	for (int i = 0; i < N; i++)
	{
		if (A[i] == 0)
		{
			ct++;
		}
	}
	cout << ct << endl;

	return (0);
}

Measured memory_bytes: 3604
n = int(input())
a = [0]*210
for i in range(n+1) :
  if(i%2 == 0) : continue
  res = 1
  for j in range(1, int(i/2)+1) :
    if(i%j == 0) : res += 1
  a[i] = res
print(a.count(8))

Measured memory_bytes: 3060
#include<fstream>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<unordered_map>
#include<cctype>
#define DN 1005
#define x first
#define y second
using namespace std;
int n,sum,f,ma;
string s;
int main()
{
    cin>>s;
    n=s.size();
    s=" "+s;
    for(int i=1;i<=n;i++)
    {
        f=s[i]-'0';
        if(f!=0)
            ma=max(ma,f-1+9*(n-i));
        sum+=f;
    }
    ma=max(ma,sum);
    cout<<ma;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) {
        cin >> l[i];
    }
    int cnt = 0;
    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            for (int k = j+1; k < n; k++) {
                if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
                if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, H;
    cin >> N >> H;

    using P = tuple<int, int>;

    priority_queue<P, vector<P>> q;
    vector<int> A(N);
    vector<int> B(N);
    REP(n, N) {
        cin >> A[n] >> B[n];
        q.push( mt(B[n], 1) );
        q.push( mt(A[n], 0) );
    }

    int ans = 0;
    while (H > 0) {
        auto p = q.top();
        auto damage = get<0>(p);
        if (get<1>(p) == 1) {
            q.pop();
            H -= damage;
            ans++;
        }
        else {
            ans += (H + (damage - 1)) / damage;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#include "debug.h"
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
double startTime;
double getCurrentTime() {
return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n ;
   cin>>n;
   map<string,int> s;
   while(n--){
   	 string k;
   	 cin>>k;
   	 s[k]++;
   }
   int mx=0;
   for(auto &p:s)if(mx<p.second)mx = p.second;
   for(auto &p:s)if(mx==p.second)puts(p.first.c_str());
   
}

Measured memory_bytes: 23936
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
int read(){
	int nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
int n,m,fs[M],nt[M<<1],to[M<<1],len[M<<1],tmp;
int f[M],sz[M],w[M],u,v,ct[M],cnt[4];
bool vis[M];
LL ans;
int fd(int x){return x==f[x]?x:f[x]=fd(f[x]);}
void link(int x,int y,int dst){nt[tmp]=fs[x],fs[x]=tmp,to[tmp]=y,len[tmp++]=dst;}
LL mul(int x,int y){return (LL)x*(LL)y;}
bool dfs(int x,int now){
	now+=now<0?3:0,now-=now>2?3:0;
	if(vis[x]&&now!=w[x]) return false;
	else if(vis[x]) return true;
	vis[x]=true,cnt[now]++,w[x]=now;
	for(int i=fs[x];i!=-1;i=nt[i]) if(!dfs(to[i],now+len[i])) return false;
	return true;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) f[i]=i,sz[i]=1,fs[i]=-1,vis[i]=false;
	for(int i=1;i<=m;i++){
	    u=read(),v=read(),link(u,v,1),link(v,u,-1);
	    u=fd(u),v=fd(v),ct[v]++;
	    if(u!=v) f[u]=v,sz[v]+=sz[u],ct[v]+=ct[u];
	}
	for(int i=1;i<=n;i++){
		if(i!=fd(i)) continue;
		cnt[0]=cnt[1]=cnt[2]=0;
		if(!dfs(i,0)) ans+=mul(sz[i],sz[i]);
		else if(!cnt[0]||!cnt[1]||!cnt[2]) ans+=ct[i];
		else ans+=mul(cnt[0],cnt[1])+mul(cnt[1],cnt[2])+mul(cnt[2],cnt[0]);
	}
	printf("%lld\n",ans); return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

struct UnionFind
{
  vector<int> par;
  vector<int> siz;
  UnionFind(int N) : par(N), siz(N, 1) {for (int i = 0; i < N; i++) par[i] = i;}
  void init(int N) {
    siz.assign(N, 1);
    par.resize(N);
    for(int i = 0; i < N; ++i) par[i] = i;
  }
  int root(int x) {
    while(par[x] != x) {x = par[x] = par[par[x]];}
    return x;
  }
  bool unite(int x, int y)
  {
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool isSame(int x, int y) {return root(x) == root(y); }
  int size(int x) { return siz[root(x)]; }
};

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll g = a[0];
  rep(i, n) g = __gcd(g, a[i]);
  ll max_a = *max_element(ALL(a));

  if(max_a >= k && k%g==0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    string S;
    cin >> S;
    int N = S.size();
    auto ans = vcd(int, N, 0);
    int i, j;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'R')
        {
            for (j = i+1; j < N && S[j] == 'R'; j++);
            ans[j-1] += (j-i) / 2 + (j-i) % 2;
            ans[j] += (j-i) / 2;
            i = j-1;
        }
        else
        {
            for (j = i+1; j < N && S[j] == 'L'; j++);
            ans[i-1] += (j-i) / 2;
            ans[i] += (j-i) / 2 + (j-i) % 2;
            i = j-1;
        }
    }
    cout << ans[0];
    for (i = 1; i < N; i++) cout << " " << ans[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 20000

//rev: G[to][rev]で逆辺にアクセスできるようにしている
struct edge {int to, cap, rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to, cap, (int)G[to].size()});
	G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

//vからtに流せたフローの量を返す　fはvが保持しているフローの量
int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i=0;i<G[v].size();i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		memset(used,0,sizeof(used));//usedを0で初期化してるだけ
		int f = dfs(s,t,INF);
		if(f==0) return flow;
		flow += f;
	}
}

int main(void){
	int h,w;cin>>h>>w;
	vector<string> A;
	int si,sj,ti,tj;
	rep(i,h){
		string s; cin>>s;
		A.push_back(s);
	}
	rep(i,h){
		rep(j,w){
			char a = A[i][j];
			int node = i*w+j;
			int cost = 1;
			if(a == '.') continue;
			if(a == 'S'){
				cost = INF;
				si = i;
				sj = j;
			}
			if(a == 'T'){
				cost = INF;
				ti = i;
				tj = j;
			}
			add_edge(node, node+h*w, cost);
			rep(x, w){
				if(x == j) continue;
				if(A[i][x] != '.') add_edge(node+h*w, i*w+x, cost);
			}
			rep(y, h){
				if(y == i) continue;
				if(A[y][j] != '.') add_edge(node+h*w, y*w+j, cost);
			}
		}
	}
	ll ans = max_flow(si*w+sj,ti*w+tj);
	cout<<(ans == INF ? -1 : ans)<<endl;;
	return 0;
}

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

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

  vector<int> a;
  int sum(0);
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    sum += a;
  }
  int ans = n - sum;
  if (ans < 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long answer = 0;
        for (int i = 0; i < N; i++) {
            int l = scan.nextInt();
            int r = scan.nextInt();
            answer += r-l+1;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 24404
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n = I()


def dfs(s):
    if int(s) > n:
        return 0
    ans = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ans += dfs(s + c)
    return ans


print(dfs("0"))


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

int main(){
    int m, f, r;  // m=<50, f=<50, r=<100

    // processing inputs
    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1) break;
        // not receive exam
        else if(m==-1 || f==-1) cout << "F" << endl;
        // receive exam
        else{
            if     (m+f>=80) cout << "A" << endl;
            else if(m+f>=65) cout << "B" << endl;
            else if(m+f>=50) cout << "C" << endl;

            else if(m+f>=30){
                if(r>=50) cout << "C" << endl;
                else      cout << "D" << endl;
            }
            else             cout << "F" << endl;
        }
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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;

int main(){
    Init();
    ll a, b, c; cin >> a >> b >> c;
    (a == b+c || b == a+c || c == a+b) ? Yes() : No();
}

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

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

	if(s=="keyence"){
		cout<<"YES" ;
		return ;
	}

	int n=s.length() ;

	for(int i=0;i<n;i++){
		
		for(int j=i;j<n;j++){
		
			string x="" ;

			for(int k=0;k<n;k++){

				if(k>=i && k<=j){
					continue ;
				}
				else{
					x.push_back(s[k]) ;
				}

			}

			if(x=="keyence"){
				cout<<"YES" ;
				return ;
			}

			//cout<<x<<"\n" ;
		}
	}

	cout<<"NO" ;

}



int main(){
	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

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

int main(){
	int n,m;
	int p[1001];
	int wa[1001 * 1001];
	while(1){
	cin >> n >> m;
	if(!n && !m) break;
	int ma = 0;
	for(int i = 0;i < n;i++) cin >> p[i];
	p[n] = 0;
	for(int i = 0;i < n + 1;i++){
		for(int j = 0;j < n + 1;j++) wa[i * (n + 1) + j] = p[i] + p[j];
	}
	sort(wa,wa + (n + 1) * (n + 1));
	for(int i = 0;i < n + 1;i++){
		for(int j = 0;j < n + 1;j++){
			int up = upper_bound(wa,wa + (n + 1) * (n + 1),m - (p[i] + p[j])) - wa,low = lower_bound(wa,wa + (n + 1) * (n + 1),m - (p[i] + p[j])) - wa;
			if(up - low == 0){
				if(low != 0) ma = max(ma,p[i] + p[j] + wa[low - 1]);
			}else if(up - low == 1){
				ma = m;
			}
		}
	}
	cout << ma << endl;
	}
	return 0;	
}

Measured memory_bytes: 6936
#include<stdio.h>
int main(void)
{
    double a,b,c,d,e,f,x,y;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF)
    {
    y=(c*d-a*f)/(b*d-a*e);
    x=(c*e-b*f)/(a*e-b*d);
        if(x==0)
            x=0.0;
        if(y==0)
            y=0.0;
        printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 652
n , x = map(int, input().split())
l = list(map(int, input().split()))
tmp = [0] * (n + 1)
sum = 0
for i in range(n):
    sum += l[i]
    tmp[i + 1] = sum 

cnt = 0
for i in range(len(tmp)):
    if tmp[i] <= x:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064