akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

struct DICE {
	int num[7];
};

void throwdice(char, struct DICE *);
int judge(struct DICE *, struct DICE *);
int issame(struct DICE *, struct DICE *);

int main(void)
{
	struct DICE dice[100];
	int i, j, n, flag=1;
	
	scanf("%d",&n);
	for(i=0; i<n; i++) {
		for(j=1; j<=6; j++) {
		scanf("%d",&dice[i].num[j]);
		}
	}
	for(i=0; i<n-1; i++) {
		for(j=i+1; j<n; j++) {
			if( issame(&dice[i], &dice[j]) ) {
				flag = 0;
			}
		}
	}
	if(flag) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

void throwdice(char ch, struct DICE *dice)
{
	int temp;
	switch (ch) {
	case 'N':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[5] ;
		dice->num[5] = dice->num[1] ;
		dice->num[1] = dice->num[2] ;
		dice->num[2] = temp;
		break;
	case 'S':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[2] ;
		dice->num[2] = dice->num[1] ;
		dice->num[1] = dice->num[5] ;
		dice->num[5] = temp;
		break;
	case 'E':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[3] ;
		dice->num[3] = dice->num[1] ;
		dice->num[1] = dice->num[4] ;
		dice->num[4] = temp;
		break;
	case 'W':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[4] ;
		dice->num[4] = dice->num[1] ;
		dice->num[1] = dice->num[3] ;
		dice->num[3] = temp;
		break;
	}
}

int judge(struct DICE *dice1, struct DICE *dice2)
{
	int i, j, flag=0, cnt;
	for (i=0; i<4; i++) {
		cnt = 0;
		for (j=1; j<=6; j++) {
			if(dice1->num[j] == dice2->num[j]) {
				cnt++;
			}
		}
		if(cnt == 6) {
			flag = 1;
		}
		throwdice('E',dice1);
	}
	return flag;
}

int issame(struct DICE *dice1, struct DICE *dice2)
{
	int i;
	
	if ( judge(dice1,dice2) ) {
		return 1;
	}
	
	throwdice('S',dice1);
	if ( judge(dice1,dice2) ) {
		return 1;
	}
	
	throwdice('W',dice1);
	throwdice('S',dice1);
	if ( judge(dice1,dice2) ) {
		return 1;
	}
	
	throwdice('S',dice1);
	throwdice('S',dice1);
	if ( judge(dice1,dice2) ) {
		return 1;
	}
	
	throwdice('E',dice1);
	throwdice('S',dice1);
	if ( judge(dice1,dice2) ) {
		return 1;
	}
	
	throwdice('E',dice1);
	throwdice('S',dice1);
	if ( judge(dice1,dice2) ) {
		return 1;
	}
	return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector< set<int> > vs(N+1);
  set<int> s;
  queue<int> que;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    vs.at(a).insert(b);
    s.insert(a);
    if(a==1){
      que.push(b);
    }
  }
  while(!que.empty()){
    if(s.count(que.front())){
      if(vs.at(que.front()).count(N)){
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
    que.pop();
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 24320
from sys import exit

class WeightedUnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weights = [0] * (n+1)

    def find(self, x):
        if self.parent[x] == x:
            return x
        nx = self.find(self.parent[x])
        self.weights[x] += self.weights[self.parent[x]]
        self.parent[x] = nx
        return nx

    def unite(self, x, y, d):
        rx = self.find(x)
        ry = self.find(y)
        if rx == ry:
            return
        if self.rank[rx] < self.rank[ry]:
            self.parent[rx] = ry
            self.weights[rx] = d + self.weights[y] - self.weights[x]
        else:
            self.parent[ry] = rx
            self.weights[ry] = - d + self.weights[x] - self.weights[y]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weights[x] - self.weights[y]

n, m = map(int, input().split())
wuf = WeightedUnionFind(n)
for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    if not wuf.same(l, r):
        wuf.unite(l, r, d)
    else:
        if wuf.diff(l, r) != d:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 102432
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;
	int cnt[10010] = {};
	for(int x = 1;x <= 100;x++){
		for(int y = 1;y <= 100;y++){
			for(int z = 1;z <= 100;z++){
				int f = x*x + y*y + z*z + x*y + y*z + z*x;
				if(f <= n)cnt[f]++;
			}
		}
	}
	for(int i = 1;i <= n;i++)cout << cnt[i] << endl;



	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://atcoder.jp/contests/aising2020/tasks/aising2020_a


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<tuple>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const int INF = 1e5;
const ll MAXN = 1e6;

int main()
{
    int n;
    cin>>n;
    int w[n];
    rep(i,n)cin>>w[i];
    int ans=INF;
    rep(i,n)
    {
        int s1=0;
        int s2=0;
        rep(j,i+1)
        {
            s1+=w[j];
        }
        for(int j=i+1;j<n;j++)
        {
            s2+=w[j];
        }
        if(ans>abs(s2-s1))ans=abs(s2-s1);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int x[3][3];
int dx[3],dy[3];
int main(){
	int i,j,n,a;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			scanf("%d",&x[i][j]);
		}
	}
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		for(j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(x[j][k]==a){
					x[j][k]=-1;
				}
			}
		}
	}
	for(i=0;i<3;i++){
		dx[0]+=x[0][i];
		dx[1]+=x[1][i];
		dx[2]+=x[2][i];
		dy[0]+=x[i][0];
		dy[2]+=x[i][2];
		dy[1]+=x[i][1];
	}
	for(i=0;i<3;i++){
		if(dx[i]==-3||dy[i]==-3){
			printf("Yes");
			return 0;
		}
	}
	if(x[0][0]+x[1][1]+x[2][2]==-3||x[0][2]+x[1][1]+x[2][0]==-3){
		printf("Yes");
		return 0;
	}
	printf("No");
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
vector<int>g[2100];
int R[2100];
int L[2100];
int K[2100];
char in[2100];

int cnt(int a,int b){
	int ret=0;
	R[a]=0;
	if(in[a]=='1')ret++;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]==b)continue;
		ret+=cnt(g[a][i],a);
		R[a]+=R[g[a][i]]+K[g[a][i]];
	}
	K[a]=ret;
	return ret;
}
void dfs(int a,int b){
	L[a]=0;
	int od=0;
	int MX=0;
	int SUM=0;
	int at=0;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]==b)continue;
		dfs(g[a][i],a);
		if((L[g[a][i]]+K[g[a][i]])%2)od++;
		SUM+=R[g[a][i]]+K[g[a][i]];
		if(MX<R[g[a][i]]+K[g[a][i]]){
			MX=R[g[a][i]]+K[g[a][i]];
			at=g[a][i];
		}
	}
	od%=2;
	int mm=MX*2-SUM;
	if(mm>0){
		if((L[at]+K[at])*2-(SUM-R[at]+L[at])<0)mm=0;
		else mm=(L[at]+K[at])*2-(SUM-R[at]+L[at]);
	}
	L[a]=max(od,mm);
	//printf("%d: %d %d %d %d %d\n",a,at,MX,SUM,L[a],R[a]);
}
int main(){
	int a;scanf("%d",&a);
	scanf("%s",in);
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	int ret=mod;
	for(int i=0;i<a;i++){
		cnt(i,-1);
		dfs(i,-1);
		if(L[i]==0){
			ret=min(ret,R[i]/2);
		}
	}
	if(ret==mod)ret=-1;
	printf("%d\n",ret);
}

Measured memory_bytes: 512
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
L = LI()
x = max(L)
L.sort()
L[-1] = 0
y = sum(L)
if x < y:
    print('Yes')
else:
    print('No')

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ull H,count=1;	cin>>H;
  	if(H==1)	cout<<"1"<<endl;
	else{
  	while(1){
		H/=2;
		count++;
		if(H==1)	break;
	}
  	ull ans=1;
	FOR(i,0,count)	ans*=2;
  	cout<<ans-1<<endl;
    }

    return 0;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String r = null;
		while ((r = br.readLine()) != null) {
			String[] s = r.split(" ");
			int a = Integer.valueOf(s[0]);
			int b = Integer.valueOf(s[1]);
			System.out.println(String.valueOf(a + b).length());
		}
	}
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  string t = "";
  rep(i, s.size()) {
    if(s[i] != 'x') t += s[i];
  }
  string u = t;
  reverse(all(t));
  if(t == u) {
    int idx = 0;
    int len = -1;
    rep(i, s.size()) {
      if(s[i] == t[idx]) idx++;
      if(idx >= t.size()/2+(t.size()%2)) {
	len = i+1;
	break;
      }
    }
    assert(~len);
    int ans = 0;
    int l = 0, r = s.size()-1;
    while(l < len) {
      while(s[l] == s[r]) l++, r--;
      //cout << l << " " << r << endl;
      if(l >= r) break;
      if(s[l] == 'x') ans++, l++;
      else if(s[r] == 'x') ans++, r--;
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


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

int main() {
    int M, C, N;
    while (cin >> M >> C >> N, M || C || N) {
        vector<deque<int>> vd(M+1);
        for (int i = 1; i <= 100; i++) vd[M].push_back(i);

        queue<queue<int>> vs;
        for (int i = 0; i < N; i++) {
            int k;
            cin >> k;
            queue<int> q;
            for (int j = 0; j < k; j++) {
                int x;
                cin >> x;
                q.push(x);
            }
            vs.push(q);
        }

        int ans = 0;
        while (vs.size()) {
            auto q =  vs.front();
            vs.pop();
            int book = q.front();
            q.pop();
            if (q.size() > 0) vs.push(q);

            for (int i = 0; i <= M; i++) {
                for (int j = 0; j < vd[i].size(); j++) {
                    if (vd[i][j] == book) {
                        ans += i + 1;
                        vd[i].erase(vd[i].begin() + j);
                        break;
                    }
                }
            }

            if (vd[0].size() < C) {
                vd[0].push_back(book);
                ans += 1;
            } else {
                int p1 = -1, p2 = -1;
                for (int i = 1; i <= M; i++) {
                    if (vd[i].size() < C || i == M) {
                        if (p1 < 0) {
                            p1 = i;
                            if (i == M || vd[i].size() + 1 < C) i--;
                        } else if (p2 < 0) {
                            p2 = i;
                        }
                    }
                }

                int rebook = vd[0].front();
                vd[0].pop_front();
                
                vd[p2].push_back(rebook);
                vd[0].push_back(book);

                ans += (p1 + 1) * 2 + 1;
                ans += p2 + 2;
            }
        }

        cout << ans << endl;
    }

  return 0;
}

Measured memory_bytes: 3184
# https://atcoder.jp/contests/abc174/tasks/abc174_e

from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))

L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0

while i<100:
    i +=1
    for num in A:
        cnt += ceil(num/ans)-1
    if cnt <=K:
        R = ans
    elif cnt>=K:
        L = ans
    else:
        #print("fin",i-1,cnt,ans)
        break           
    ans = (R+L)/2
    cnt=0
        
print(ceil(ans))

Measured memory_bytes: 104764
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;


ll pow(ll a, ll b){
    int ans = 1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


const int N=1e5;


void run(){
	
	int n; cin>>n;
	
	vi v(n);
	FOR(i,0,n) cin>>v[i];
	
	map<int, int> m, p;
	int x=0, ans=0, b;
	
	for(int i=0; i<n; i=i+2){
		if(!m.count(v[i])){
			m[v[i]]=1;
		}
		else m[v[i]]=m[v[i]]+1;
		
		if(m[v[i]]>x){
			x=m[v[i]]; b=v[i];
		}
	}
	
	
	int y=0, c;
	
	for(int i=1; i<n; i=i+2){
		if(!p.count(v[i])){
			p[v[i]]=1;
		}
		else p[v[i]]=p[v[i]]+1;
		
		if(p[v[i]]>y){
			y=p[v[i]]; c=v[i];
		}
	}
		
	if(b==c){
		int w=0, z=0;
		for(auto xd : m){
			if(xd.fst==b) continue;
			w=max(w,xd.snd);
		}
		for(auto xd : p){
			if(xd.fst==c) continue;
			w=max(w,xd.snd);
		}
		ans=n-x-max(w,z);
	}
	else ans=n-x-y;
	
	cout<<ans<<"\n";
}


int main(){
	
	fastio;
	
	int tt=1; 
	//cin>>tt;
	
	while(tt--){
		run();
	}
	
	return 0;
}


Measured memory_bytes: 8260
#include <iostream>
#include <string>
#include <vector>
#include <set>

int main() {
    int n, q;
    std::string s;
    std::cin >> n >> s >> q;

    std::vector<std::set<int>> ap(26);
    for (int i = 0; i < n; i++) {
        ap[s[i] - 'a'].insert(i);
    }

    while (q--) {
        int f;
        std::cin >> f;

        if (f == 1) {
            int i;
            char c;
            std::cin >> i >> c;
            i--;

            for (int j = 0; j < 26; j++) {
                auto it = ap[j].find(i);
                if (it != ap[j].end()) {
                    ap[j].erase(*it);
                    break;
                }
            }

            ap[c - 'a'].insert(i);

        } else {
            int l, r;
            std::cin >> l >> r;
            l--;

            int ans = 0;
            for (int j = 0; j < 26; j++) {
                if (ap[j].lower_bound(l) != ap[j].end() && *ap[j].lower_bound(l) < r) {
                    ans++;
                }
            }

            std::cout << ans << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 24196
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <bitset>
#include <memory>

constexpr long long int MOD = 1000000007;
long long int count(int current, int max_rest, int min_rest, const std::vector<std::pair<int, int>>& vec, std::vector<std::vector<long long int>>& memo) {
	if (min_rest < 0) return 0;
	if (current == vec.size()) return 1;
	if (memo[current][min_rest] >= 0) return memo[current][min_rest];
	return memo[current][min_rest] = (count(current + 1, std::max(max_rest - vec[current].first, min_rest - vec[current].second), std::min(max_rest - vec[current].first, min_rest - vec[current].second), vec, memo) +
		count(current + 1, std::max(max_rest - vec[current].second, min_rest - vec[current].first), std::min(max_rest - vec[current].second, min_rest - vec[current].first), vec, memo)) % MOD;
}
int main() {
	int n, m; std::cin >> n >> m;
	std::vector<int> books(n), which(n, -1); for (auto& b : books) std::cin >> b;
	std::vector<std::vector<int>> edges(n);
	for (auto i = 0; i < n; ++i) {
		for (auto j = 0; j < i; ++j) if (books[j] > books[i]) {
			edges[i].push_back(j);
			edges[j].push_back(i);
		}
	}
	std::stack<int> stack;
	std::vector<std::pair<int, int>> sub_groups;
	for (auto i = 0; i < n; ++i) if (which[i] == -1) {
		stack.push(i);
		int count0{ 1 }, count1{ 0 };
		which[i] = 0;
		while (!stack.empty()) {
			const auto top = stack.top(); stack.pop();
			for (const auto next : edges[top]) if (which[next] != 1 - which[top]) {
				if (which[next] != -1) {
					std::cout << 0 << '\n';
					return 0;
				}
				which[next] = 1 - which[top];
				if (which[next] == 0) ++count0;
				else ++count1;
				stack.push(next);
			}
		}
		sub_groups.emplace_back(count0, count1);
	}
	std::vector<std::vector<long long int>> memo(sub_groups.size(), std::vector<long long int>(m + 1, -1));
	std::cout << count(0, m, m, sub_groups, memo) << std::endl;
}


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

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);
  vector< T > prev(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      prev[e.to] = idx;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return prev;
}


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

  int n,m;
  cin >> n >> m;
   WeightedGraph< int > g(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a].emplace_back(b,1);
    g[b].emplace_back(a,1);
  }
  auto res = dijkstra(g,0);
  cout << "Yes" << endl;
  rep1(i,n-1){
    cout << res[i]+1 << endl;
  }

  return 0;
    

}


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

int main() {
    double N, M, D;
    cin >> N >> M >> D;
    double A = 2 * (N - D);
    if(D == 0) A = N;
    double B = A / (N * N);
    double C = B * (M - 1);
    printf("%.10lf\n", C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxN = 105;
const int maxW = 1e5+5;
const int INF = 1e9;
 
long long DP[maxW];
pair<int, int> A[maxN];
int n, w;
 
void solve() {
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        A[i] = {a, b};
    }
    for(int i = 0; i < n; i++){
        int price = A[i].second;
        int weight = A[i].first;
        for(int j = w; j >= 0; j--){
            if(j-weight < 0) break;
            DP[j] = max(DP[j], DP[j-weight]+price);
        }
    }
    cout << DP[w] << "\n";
 
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    bool multitest = false;
    //multitest = true;
    if (multitest) {
        int t; cin >> t;
        while (t--)
            solve();
    }
    else
        solve();
}

Measured memory_bytes: 4440
import sys
from collections import defaultdict as dd
from bisect import bisect_left as bl
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (N + 1)
d = dd(list)
for i in range(N):
  d[a[i]].append(i)
for i in range(N - 1, -1, -1):
  j = bl(d[a[i]], i)
  if j == len(d[a[i]]) - 1:
    dp[i] = a[i]
  else:
    dp[i] = dp[d[a[i]][j + 1] + 1]
p = dp[0]
t = 1
l = [0, dp[0]]
if l[-1] == 0:
  t -= 1
  l.pop()
d[0].append(-1)
for _ in range(N):
  p = dp[d[p][0] + 1]
  t += 1
  if p == 0: break
  l.append(p)
p = l[(K - 1) % t]
i = d[p][0] + 1
res = []
while i < N:
  j = bl(d[a[i]], i)
  if j < len(d[a[i]]) - 1:
    i = d[a[i]][j + 1]
  else:
    res.append(a[i])
  i += 1
print(*res)

Measured memory_bytes: 119244
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int n;
	cin >> n;
	vl a(n + 2);
	rep1(i, n) {
		cin >> a[i];
	}
	a[n + 1] = 0;
	ll sum = 0;
	rep1(i, n + 1) {
		sum += abs(a[i] - a[i - 1]);
	}
	rep1(i, n) {
		ll temp = sum;
		temp -= abs(a[i] - a[i - 1]);
		temp -= abs(a[i + 1] - a[i]);
		temp += abs(a[i + 1] - a[i - 1]);
		cout << temp << endl;
	}
	
}

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

int main() {
 
  int r,D,x,a,b,c,d,e,f,g,h,i,j ;
  cin >>r>>D>>x ;
  a = r*x - D;
  b = r*a - D;
  c = r*b - D;
  d = r*c - D;
  e = r*d - D;
  f = r*e - D;
  g = r*f - D;
  h = r*g - D;
  i = r*h - D;
  j = r*i - D;
  cout << a <<endl;
  cout << b <<endl;
  cout << c <<endl;
  cout << d <<endl;
  cout << e <<endl;
  cout << f <<endl;
  cout << g <<endl;
  cout << h <<endl;
  cout << i <<endl;
  cout << j <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
set<int> S;
int a[200010];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
	}
	int Ans = 1, pp = 0;
	for(int i = 1; i <= k; ++ i) {
		S.insert(a[i]);
		if(a[i] < a[i - 1] && i > 1) {
			++ pp;
		}
	}
	int wt = 0;
	if(pp == 0) Ans = 0, wt = 1;
	//cerr << pp << endl;
	
	for(int i = k + 1; i <= n; ++ i) {
		int cnt = 0;
		if(a[i - k] > a[i - k + 1]) -- pp;
		if(a[i - 1] > a[i]) ++ pp;
		if(pp == 0) {
			S.erase(a[i - k]);
			S.insert(a[i]);
			wt = 1;
			continue;
		}
		if(a[i - k] == *S.begin()) {
			++ cnt;
		}
		S.erase(a[i - k]);
		S.insert(a[i]);
		if(a[i] == *S.rbegin()) {
			++ cnt; 
		}
		if(cnt != 2) ++ Ans; 
	}
	printf("%d\n", Ans + wt);
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main{
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		if(x < a)
			System.out.println(0);
		else
			System.out.println(10);
	}
}


Measured memory_bytes: 21844
n, m = map(int, input().split())
Hn = list(map(int, input().split()))
abn = [list(map(int, input().split())) for _ in range(m)]
pool = [[] for h in Hn]
for ab in abn:
    pool[ab[0]-1].append(Hn[ab[1]-1])
    pool[ab[1]-1].append(Hn[ab[0]-1])
ans = 0
for i in range(n):
    if len(pool[i]) == 0:
        ans += 1
    else:
        if max(pool[i]) < Hn[i]:
            ans += 1
print(ans)


Measured memory_bytes: 41276
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val d = sc.nextInt()
    val c = (0 until 26).map { sc.next().toInt() }
    val s = (0 until d).map {
        (0 until 26).map { sc.next().toInt() }
    }
    println(problemintroduction_to_heuristics_contest(d, c, s))
}

fun problemintroduction_to_heuristics_contest(
    D: Int,
    c: List<Int>,
    s: List<List<Int>>
): String {
    val last = LongArray(26) { 0 }
    val satisfactions = LongArray(26) { 0 }
    val ans = IntArray(D) { 1 }
    for (d in 0 until D) {
        var max = -Long.MAX_VALUE
        var maxIndex = 0
        for (i in 0 until 26) {
            val tmp = max
            max = Math.max(max, c[i] * ((d + 1) - last[i]))
            if (tmp != max) maxIndex = i
        }

        var selected = maxIndex
        if (s[d].max()!! > 15000) {
            selected = s[d].indexOf(s[d].max()!!)
        }
        ans[d] = selected + 1
        satisfactions[selected] += s[d][selected].toLong()
        last[selected] = d + 1L
        for (j in 0 until 26) {
            satisfactions[j] -= c[j] * ((d + 1) - last[j])
        }
    }
//    debugLog(satisfactions.sum())
    return ans.joinToString("\n")
}

Measured memory_bytes: 48056
#include<bits/stdc++.h>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

bool c[20000];
int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		memset(c, false, sizeof(c));
		c[0] = true;
		P d[20000];
		for (int e = 0; e < b; e++) {
			int f, g, h; scanf("%d%d%d", &f, &g, &h); g--; h--;
			d[e] = P(f, p(g, h));
		}
		sort(d, d + b);
		for (int e = 0; e < b; e++) {
			if (c[d[e].second.first]) {
				c[d[e].second.second] = true;
			}
		}
		int e = 0;
		for (bool f : c) {
			if (f)e++;
		}
		cout << e << endl;
	}
}

Measured memory_bytes: 3372
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,ans[505],k,tot;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=n,j=1;j<=k&&i<=m;i++,j++)
		ans[++tot]=i;
	for(int i=m,j=1;j<=k&&i>=n;i--,j++)
		ans[++tot]=i;
	sort(ans+1,ans+tot+1);
	for(int i=1;i<=tot;i++)
		if(ans[i]!=ans[i-1])
			printf("%d\n",ans[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 58;
const int INT_INF = 1 << 28;
const double PI = acos(-1.0);

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    auto solve = [&](int x, int y, int z) {
        bool a = false, b = false, c = false;
        rep(i, N) {
            if (!a)
                if (S[i] - '0' == x)
                    a = true;
                else
                    continue;
            else if (!b)
                if (S[i] - '0' == y)
                    b = true;
                else
                    continue;
            else if (S[i] - '0' == z)
                c = true;
        }
        if (a && b && c)
            return true;
        else
            return false;
    };
    int ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            rep(k, 10) {
                if (solve(i, j, k)) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3688
extern crate proconio;
use proconio::input;
use std::collections::HashSet;
use num::integer::lcm;

fn main() {
    input!{
        n: usize,
        m: u64,
        a: [u64; n]
    };

    let b: HashSet<u64> = a.iter().map(|x| x/2).collect();

    let ans = ||{
        let mut prd = 1;
        for i in b.iter() {
            prd = lcm(prd, *i);
            if prd > 1e9 as u64{
                return 0;
            }
        }

        for i in b.iter() {
            if prd / *i % 2 == 0 {
                return 0;
            }
        }

        return ( m/prd + 1 )/2;
    };

    println!("{}", ans());

}



Measured memory_bytes: 4236
N = int(input())

a = 0
b = 0
c = 0
ans = 0

for _ in range(N):
    s = input()
    flag = False
    for i in range(len(s)):
        if (flag == True) and (s[i] == "B"):
            ans += 1
            flag = False
        elif (s[i] == "A"):
            flag = True
        else:
            flag = False
    if (s[0] == "B" and s[-1] == "A"):
        c += 1
    elif (s[0] == "B"):
        b += 1
    elif (s[-1] == "A"):
        a += 1
if c > 0:
    ans += c - 1
    c = 1
    if (a > 0 or b > 0):
        ans += 1
print(ans + min(a, b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n;string s;cin>>n>>s;
  if(n%2){
    cout<<"No";return 0;
  }
  if(s.substr(0,n/2)==s.substr(n/2,n/2))cout<<"Yes";
  else cout<<"No";
}

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

int main()
{
	int n; cin >> n;
	
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) { cin >> a.at(i); }
	
	vector<int> ans(n + 1);
	for (int i = 1; i <= n; i++) { ans[a.at(i)] = i; }

	for (int i = 1; i <= n; i++) { cout << ans[i] << " "; }

	return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll h,w,k;
  cin>>h>>w>>k;
  vector<vector<ll> > vv(h,vector<ll>());
  rep(y,0,h){
    string s;
    cin>>s;
    rep(x,0,s.sz){
      vv[y].pb(s[x]-'0');
    }
  }
  ll mn = 1000000000;
  rep(i,0,(1<<(h-1))){
    ll b = 0;
    ll c = 0;
    vector<vector<vector<ll> > > vvv;
    vector<vector<ll> > vv1;
    rep(j,0,h-1){
      vv1.pb(vv[j]);
      ll a = (i>>j)&1;
      b += a;
      if(a==1){
        vvv.pb(vv1);
        vv1.clear();
      }
    }
    rep(j,h-1,h){
      vv1.pb(vv[j]);
    }
    vvv.pb(vv1);
    ll d[11];
    clr(d,0);
    rep(j,0,w){
      ll d1[11];
      clr(d1,0);
      rep(l,0,vvv.sz){
        rep(m,0,vvv[l].sz){
          d1[l] += vvv[l][m][j];
        }
      }
      ll flag = 0;
      rep(l,0,vvv.sz){
        if(d1[l]>k)goto f;
        if(d[l]+d1[l]>k)flag = 1;
      }
      if(flag==1){
        c++;
        rep(l,0,vvv.sz){
          d[l] = d1[l];
        }
      }
      else{
        rep(l,0,vvv.sz){
          d[l] += d1[l];
        }        
      }
    }
    mn = min(mn,b+c);
    f:;
  }
  cout << mn << endl;
  return 0;
}

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

int main()
{

        int N, K, X, Y;
        cin >> N >> K >> X >> Y;

        int k = (N < K) ? N : K;
        int m = N - K;
        if (m < 0) m = 0;

        int ans = (X * k) + (Y * m);
        cout << ans << endl;


}


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

// int count1=0;

int calcYakuNum(int num){
    int res=0;
    for(int i=1;i*i<=num;i++){
        // count1++;
        if(num%i==0){
            if(num/i==i) res++;
            else res = res+2;
        }
    }
    return res;

}

int main(){
    int N;
    cin>>N;
    int ans=0;
    for(int i=1;i<N;i++){
        ans += calcYakuNum(i);
    }
    cout<<ans<<endl;
    // cout<<count1<<endl;
}

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

using namespace std;
#define int long long
const int INF = 200000000007;


  
signed main(){
    int a;
    cin>>a;
    if((a%100)<13&&(a%100)>0){
        if(a/100 < 13 && a/100 >0) cout<<"AMBIGUOUS";
        else cout<<"YYMM";
    }else{
        if(a/100 < 13 && a/100 >0) cout<<"MMYY";
        else cout<<"NA";
    }

   
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,pas=2019,l,r;
long long f(long long q, long long w){
    if(q<w) return 0;
    if(w==0) return q/2019+1;
    return (q-w)/2019+1;
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>l>>r;
    for(c=0; c<2019; c++){
        for(d=0; d<2019; d++){
            if(pas>c*d%2019){
                if(c==d){
                    if(f(r,c)>f(l-1,c)+2) pas=c*d%2019;
                    continue;
                }
                if(f(r,c)!=f(l-1,c)&&f(r,d)!=f(l-1,d)) pas=c*d%2019;
            }
        }
    }
    cout<<pas;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int a,b,d,r;

 double f;

 scanf("%d %d",&a,&b);

 d = a/b;

 r = a%b;

 f =(double)a/(double)b;
 
   printf("%d %d %lf\n",d,r,f);

 return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long h;
long long f(long long x){
	if(x==1)return 1;
	return 2*f(x/2)+1;
}
int main(){
	cin>>h;
	cout<<f(h)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main(){
    int num;
    cin >> num;
    
    map<string, int> memo;
    for(int i=0; i<num; i++){
        string s;
        cin >> s;
        memo[s] += 1;
    }
    int count=0;
    for(auto x : memo){
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 19148
from itertools import product as pro

n = int(input())
s = str(input())

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
cnt = len(r)*len(g)*len(b)

length = max(len(r), len(g), len(b))
if length == len(r):
    max1 = set(r)
    min1 = g
    min2 = b

if length == len(g):
    max1 = set(g)
    min1 = r
    min2 = b

if length == len(b):
    max1 = set(b)
    min1 = g
    min2 = r

for i, j in pro(min1, min2):
    if 2*j-i in max1:
        cnt -= 1
    if 2*i-j in max1:
        cnt -= 1
    if (i+j)/2 in max1:
        cnt -= 1

print(cnt)


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

ll Gauss(ll n) {
    return n * (n + 1) / 2;
}

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

    ll ans = 0;
    int l = 1;
    while (l <= n)
    {
        ans += Gauss(n / l) * l;
        l++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	void kaijou_set(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		/*
		int a = kaijou[n];int b = 1;int m = modulo-2;
		while(m!=0){
			if(m%2){
				b=mod(b*a);
			}
			a=mod(a*a);
			m/=2;
		}
		*/
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	int N,K;
	cin>>N>>K;
	
	combi c;
	c.kaijou_set(10000);
	
	for(int i=1;i<=K;i++){
	cout<<mod(c.combination(N-K+1,i)*c.combination(K-1,i-1))<<endl;
/*
		if(K-i+1>=i-1)cout<<mod(c.combination(N-K+1,i)*c.combination(K,i-1))<<endl;
		else cout<<mod(c.combination(N-K+1,i))<<endl;*/
		
		
	}
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for (ll i = 0LL; i < n; i++)
#define repext(i, a, b) for (ll i = a; i < b; i++)
#define reprev(i, n) for (ll i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (ll i = b - 1; i >= a; i--)

#define repv(v, values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0LL)
#define srt(vec) sort(vec_all(vec))
#define rev(vec) reverse(vec_all(vec))
#define revsrt(vec) \
    srt(vec);       \
    rev(vec)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

template <typename T, typename S>
void dump_dic(map<T, S> dic)
{
    for (auto v : dic)
    {
        cout << v.first << ": " << v.second << endl;
    }
}

template <typename T>
T gcd(T a, T b)
{
    if (a < b)
    {
        swap(a, b);
    }

    while (b != 0)
    {
        a = a % b;
        swap(a, b);
    }

    return a;
}

ll list_gcd(vector<ll> lis)
{
    ll ret = 0;
    repv(v, lis) {
        ret = gcd(ret, v);
    }

    return ret;
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);

    int max = 0;
    rep(i, n) {
        cin >> a[i];
        if (a[i] > max) {
            max = a[i];
        }
    }

    if (max < k) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    ll l_gcd = list_gcd(a);

    if (k % l_gcd == 0) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC171
{
    class A
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var p = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            //var NK = Console.ReadLine();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var AB = Console.ReadLine().Split().Select(long.Parse).ToArray();

            var sum = 0L;
            for (int i = 0; i < NK[1]; i++)
            {
                sum += p[i];
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 28672
/**
 * File    : E.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-17 22:01:10
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
ll a[1010];
ll maxi;
vector<bool> ans;
vector<int> res;

void flush()
{
  while (ans.size() > 1)
  {
    int M = ans.size();
    for (auto i = 0; i < M - 2; i++)
    {
      if (!ans[i] && !ans[i+1] && !ans[i+2])
      {
        res.push_back(i + 1);
        ans.erase(ans.begin() + i);
        ans.erase(ans.begin() + i);
        goto EXIT;
      }
    }
    if (!ans[0])
    {
      res.push_back(0);
      ans.erase(ans.begin());
      goto EXIT;
    }
    if (!ans[ans.size() - 1])
    {
      res.push_back(ans.size() - 1);
      ans.erase(ans.begin() + ans.size() - 1);
      goto EXIT;
    }
    assert(ans.size() >= 3 && ans[0] && !ans[1] && ans[2]);
    res.push_back(1);
    ans.erase(ans.begin());
    ans.erase(ans.begin());
  EXIT:
    continue;
  }
  cout << maxi << endl;
  cout << res.size() << endl;
  for (auto x : res)
  {
    cout << x + 1 << endl;
  }
}

int main()
{
  cin >> N;
  ans = vector<bool>(N, false);
  for (auto i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  bool allminus = true;
  maxi = -1000000007;
  int maxi_i = 0;
  for (auto i = 0; i < N; i++)
  {
    if (a[i] >= 0)
    {
      allminus = false;
      break;
    }
    else
    {
      if (maxi < a[i])
      {
        maxi = a[i];
        maxi_i = i;
      }
    }
  }
  if (allminus)
  {
    ans[maxi_i] = true;
    flush();
    return 0;
  }
  maxi = 0;
  int maxi_k = 0;
  for (auto k = 0; k < 2; k++)
  {
    ll temp = 0;
    for (auto i = k; i < N; i += 2)
    {
      if (a[i] >= 0)
      {
        temp += a[i];
      }
    }
    if (maxi < temp)
    {
      maxi = temp;
      maxi_k = k;
    }
  }
  for (auto i = maxi_k; i < N; i += 2)
  {
    if (a[i] >= 0)
    {
      ans[i] = true;
    }
#if DEBUG == 1
    cerr << "ans[" << i << "] = " << ans[i] << endl;
#endif
  }
  flush();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

LL n;
string s1 = "ABC", s2 = "ABD";

int main() {
	scanf("%lld", &n);
	if (n < 1000) {
		cout << s1 << endl;
		return 0;
	}
	cout << s2 << endl;
	return 0;
}
		

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m)
{
  int ret = n % m;
  if (ret < 0)
    ret += m;
  return ret;
}

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

int32_t main()
{
  DESYNC;
  int n, m;
  cin >> n >> m;
  char mat[n][m];
  int dp[n][m];
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      cin >> mat[i][j];
      dp[i][j] = INF;
    }
  }
  if (mat[0][0] == '#')
    dp[0][0] = 1;
  else
    dp[0][0] = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      if (mat[i][j] == '#')
      {
        if (i + 1 < n)
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        if (j + 1 < m)
          dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
      }
      else
      {
        if (i + 1 < n)
        {
          if (mat[i + 1][j] == '#')
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
          else
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
        if (j + 1 < m)
        {
          if (mat[i][j + 1] == '#')
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
          else
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
        }
      }
    }
  }
  cout << dp[n - 1][m - 1] << endl;
}


Measured memory_bytes: 384
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define PI acos(-1)

using namespace std;

struct edge_t{
	int to;
	int cost;
};

ll int dp[100010][2];
int flag=0;
ll int xdet=INF;
vector<edge_t> graph[100010];

int init(int x){
	int i;
	for(i=1;i<=x;i++){
		dp[i][0]=INF;
		dp[i][1]=INF;
	}
	return 0;
}

int search(int x, ll int c ,int b){
	int i;
	struct edge_t e;
	if(flag==-1) return 0;

	if(dp[x][0]!=INF){
		if(dp[x][1]==b){
			if(dp[x][0]!=c){
				flag=-1;
			}
		}else{
			if(xdet==INF){
				if((-b*c-dp[x][1]*dp[x][0])%2!=0){
					flag=-1;
				}else{
					xdet=(-b*c-dp[x][1]*dp[x][0])/2;
				}
			}else{
				if(xdet*2!=-b*c-dp[x][1]*dp[x][0]){
					flag=-1;
				}
			}
		}
		return 0;
	}

	dp[x][0]=c;
	dp[x][1]=b;

	for(i=0;i<graph[x].size();i++){
		e=graph[x][i];
		search(e.to,e.cost-c,-b);
	}
	return 0;
}

int main(void)
{
	//変数の宣言
	int n,m;
	int u,v,s;
	struct edge_t edge;

	//よく使う変数
	int i,j,k,l;
//	int flag=0;
	ll int ans=0;
	int count=0;
	ll int temp,temp1,temp2;
//	int max,min;
	int len;
	int sum=0;
	int ok,ng;



	//データの読み込み


	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);


	for(i=0;i<m;i++){
		scanf("%d %d %d",&u,&v,&s);
//		scanf_s("%d %d %d",&u,&v,&s);
		edge.to=v;
		edge.cost=s;
		graph[u].push_back(edge);
		edge.to=u;
		graph[v].push_back(edge);
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	init(n);
	search(1,0,1);

	if(flag==-1){
		printf("0");
		return 0;
	}else{
		temp1=INF;
		temp2=INF;
		for(i=1;i<=n;i++){
			if(dp[i][1]==1){
				temp1=min(temp1,dp[i][0]);
			}else{
				temp2=min(temp2,dp[i][0]);
			}
		}
		if(xdet==INF){
			ans=max(0,temp1+temp2-1);
		}else{
			ans=min(1,max(0,temp1+temp2-1));
		}
	}
		
	

	//	printf("計算部分終了\n");

	//出力

	//	for(i=1;i<=n;i++){
	//		printf("dp[%d][0]=%lld,dp[%d][1]=%lld\n",i,dp[i][0],i,dp[i][1]);
	//	}

	printf("%lld",ans);


	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 11904