akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())

b={i:0 for i in range(1,n+1)}

for i in range(k):
  d=int(input())
  a=list(map(int,input().split()))
  for j in range(d):
    b[a[j]]=1

count=0
for i in range(1,n+1):
  if b[i]==0:
    count+=1
print(count)

Measured memory_bytes: 9204
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int[]a=new int[2];
        a[0]=0;
        a[1]=0;
        for(int i=0;i<3;i++){
            int x=sc.nextInt();
            if(x==5){
                a[0]++;
            }
            if(x==7){
                a[1]++;
            }
        }
        if((a[0]==2)&&(a[1]==1)){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

        
        
}
        
        
    }


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

int main(){
        int n;
        char s[300001];
        cin >> n >> s;

        int ans=0;
        for(int i=1; i<n; i++){
                if(s[i]=='E') ans++;
        }

        int count=ans;
        for(int i=1; i<n; i++){
                if(s[i]=='E') count--;
                if(s[i-1]=='W') count++;
                if(count<ans) ans=count;
        }

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


Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define A 80
#define B 65
#define C 50
#define D 30

int main()
{
	int n,x,i,j,k,count=0;

	while(1)
	{
		count = 0 ;
		cin >> n >> x ;
		if((n==0)&&(x==0)) break ;

		for(k=1;k<=n;k++)
		{
			for(j=1;j<=n;j++)
			{
				for(i=1;i<=n;i++)
				{
					if(i!=j&&j!=k&&k!=i)
					{
						if(x==i+j+k) count++;
					}
				}
			}
		}
		cout << count/(3*2) << endl ;
	}

	


	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<long> box(0);
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    long a;
    cin >> a;
    box.push_back(a);
  }
  stable_sort(box.begin(), box.end());
  for(int i=0; i<box.size()-1; i++){
    if(box.size()==0) break;
    if(box.at(i)==box.at(i+1)){
      box.erase(box.begin()+i, box.begin()+i+2);
      i--;
    }
  }
  cout << box.size() << endl;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int a, z;
  a = s.find('A');
  z = s.find_last_of('Z');
  int ans = z - a + 1;

  cout << ans <<  endl;
  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++)

int main() {
  int A, B, C, X, ans = 0;
  cin >> A >> B >> C >> X;

  rep(i, A+1) {
    rep(j, B+1) {
      rep(k, C+1) {
        if (500 * i + 100 * j + 50 * k == X) ans++;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
s = list(str(input()))
s1 = s[:len(s)//2]
s2 = list(reversed(s))[:len(s)//2]

ans = 0

for _s1, _s2 in zip(s1, s2):
    if _s1 == _s2:
        pass
    else:
        ans += 1

print(ans)


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

// ??????: http://tubo28.me/algorithm/union-find/
struct UnionFind {
    vector<int> parent;
    int set_num;

    UnionFind(int n) {
        parent.resize(n, -1);
        set_num = n;
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x != y) {
            // ????´???°????°?????????????
            // big < small
            // if (size(x) < size(y)) swap(x, y);
            if (size(x) > size(y)) swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            set_num--;
        }
    }

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

    int find(int x) {
        if (parent[x] < 0) {
            return x;
        }
        return parent[x] = find(parent[x]);
    }

    int size(int x) {
        return -parent[find(x)];
    }

    int size() {
        return set_num;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);

    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            uf.unite(x, y);
        } else {
            cout << (uf.is_same(x, y) ? 1 : 0) << endl;
        }
    }
    return 0;
}

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

int main() {
  int n,mcnt = 0;
  bool zeroflag = false;
  long min = 1000000001;
  cin >> n;
  long long ans = 0;
  vector<long>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
    ans += abs(data[i]);
    if(data[i] == 0){
      zeroflag = true;
    }
    if(abs(data[i]) < min){
      min = abs(data[i]);
    }
    if(data[i] < 0){
      mcnt++;
    }
  }
  if(mcnt%2 == 0 || zeroflag){
    cout << ans << endl;
    return 0;
  }
  else{
    cout << ans-2*min << endl;
    return 0;
  }
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> cnt;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  int a = 0, b = 0;
  a = cnt.size();
  for (auto&& w : cnt) {
    if (w.second % 2 == 0) b++;
  }
  if (b % 2 == 1) a--;
  cout << a << endl;
}

Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint H,N;
    cin >> H >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    lint sum=accumulate(A,A+N,0LL);
    if(sum>=H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define FR first
#define SE second

using namespace std;

typedef pair<int,int> pr;

int n,m;

bool in[405][405],can[405][405];

pr a[100005];
bool vis[405];

bool calc(int x) {
  memset(vis,0,sizeof(vis));
  vis[x]=1;
  for(int i=m;i>0;i--) {
  	int p=a[i].FR,q=a[i].SE;
  	if (vis[p]&&vis[q]) return 0;
  	else if (vis[p]) vis[q]=1;
  	else if (vis[q]) vis[p]=1;
  }
  for(int i=1;i<=n;i++)
    if (vis[i]) in[x][i]=1;
  return 1;
}

bool del[405];

int main() {
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	a[i]=pr(x,y);
  }
  for(int i=1;i<=n;i++) del[i]=calc(i);
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      for(int k=j+1;k<=n;k++) can[j][k]|=(in[j][i]&in[k][i]);
  int ans=0;
  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
      if (del[i]&&del[j]&&!can[i][j]) ans++;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main(void)
{
	int paper[30][30]={};
	int x,y,size;
	char c;
	while(cin>>x>>c>>y>>c>>size)
	{
		x+=10;
		y+=10;
		if(size>=1)
		{
			paper[x][y]++;
			paper[x+1][y]++;
			paper[x-1][y]++;
			paper[x][y+1]++;
			paper[x][y-1]++;
		}
		if(size>=2)
		{
			paper[x-1][y-1]++;
			paper[x-1][y+1]++;
			paper[x+1][y-1]++;
			paper[x+1][y+1]++;
		}
		if(size>=3)
		{
			paper[x+2][y]++;
			paper[x-2][y]++;
			paper[x][y+2]++;
			paper[x][y-2]++;
		}
	}
	int white,max;
	white=max=0;
	for(int i=10;i<20;i++){
		for(int j=10;j<20;j++){
			if(paper[i][j]==0)white++;
			else if(paper[i][j]>max)max=paper[i][j];
		}
	}
	cout<<white<<endl<<max<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


int factorial(int n){
  if(n == 0) return 1;
  return n*factorial(n-1);
}

int divisor(int a){
  int cnt = 0;
  for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
  return cnt;
}

int comb(int n, int k){
  return factorial(n) / (factorial(n-k)*factorial(k));
}

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main(){
  string s;int K;
  cin >> s >> K;
  int N = s.size();
  vector<string> v;
  rep(i,N){
    for(int j = 1; j+i <= N; j++){
      if(j > K) break;
      v.push_back(s.substr(i,j));
    }
  }
  sort(v.begin(),v.end());
  int id = 1;
  string pre = "";
  string ans;
  rep(i,v.size()){
    if(id == K) ans = v[i];
    if(pre == v[i]) continue;
    id++;
    pre = v[i];
      
  }
  cout << ans << endl;
  
  return 0;
}









Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
inline ll lcm(ll a, ll b) { return a /__gcd(a, b) * b; }

int main(){
  cin>>n;
  ll g=-1;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    if(i==0){
      g=a;
      continue;
    }
    g=lcm(g,a);
  }
  cout<<g<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int A,B,C,K; cin>>A>>B>>C>>K;
  int ans=A-B;
  if(K%2==1)
    ans=B-A;
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

deque<int> mindq, maxdq;
int n, k;
int p[216000];
bool same[216000];
bool sorted;
bool increase[216000];

int main(){
    cin >> n >> k;
    for(int i = 0;i < n;i++)cin >> p[i];
    Int ans = n-k+1;
    for(int i = 0;i < n;i++){
        while(!mindq.empty() && p[mindq.back()] > p[i])mindq.pop_back();
        while(!maxdq.empty() && p[maxdq.back()] < p[i])maxdq.pop_back();
        mindq.push_back(i);
        maxdq.push_back(i);
        if(i >= k){
            while(!mindq.empty() && mindq.front() < i - k)mindq.pop_front();
            while(!maxdq.empty() && maxdq.front() < i - k)maxdq.pop_front();
            if(mindq.front() == i-k && maxdq.front() == i){
                same[i] = true;
            }
        }
        if(i < n-1)
            increase[i+1] = p[i+1] > p[i];
    }
    int increase_sum = 0;
    for(int i = 1;i < n;i++){
        increase_sum += increase[i];
        if(i >= k)increase_sum -= increase[i-k+1];
        //      cout << increase_sum << " " << i <<endl;
        if(increase_sum == k-1){
            same[i] = true;
            sorted = true;
        }
    }
    for(int i = k-1;i < n;i++){
//        cout << i << " "  << same[i] <<endl; 
        if(same[i])ans--;
    }
    if(sorted)ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2048
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //個数入力
            int N = int.Parse(Console.ReadLine());

            //中身入力
            string[] Sn = new string[N];
            Sn = Console.ReadLine().Split(' ');

            string number = "Three";

            foreach(string ja in Sn)
            {
                if(ja == "Y")
                {
                    number = "Four";
                }

            }

            Console.WriteLine(number);
            Console.ReadLine();

        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;

int num[22][22], n;
int dp[1<<21][22], target;
int mod = 1e9+7;

int answer(int mask, int idx) {
	if(mask == target) return 1;
	if(idx == n) return 0;
	if(dp[mask][idx] != -1) return dp[mask][idx];

	int ret = 0;
	for(int i = 0; i < n; i++) {
		if(mask & (1<<i)) continue;
		if(!num[idx][i]) continue;
		ret = (ll)(ret + answer(mask | (1<<i), idx+1)) % mod;
	} 
	return dp[mask][idx] = ret;
}

int main()
{	
	cin >> n;
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> num[i][j];
	target = (1<<n) - 1;
	memset(dp, -1, sizeof dp);
	cout << answer(0, 0);
    return 0;
}

Measured memory_bytes: 180480
#include <bits/stdc++.h>
using namespace std;
#define fio                         \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);                    \
cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, a, n, q, k, i, l, m, c, u, f, j, p, r, x, y, s, b, d;
    p= 1001;
    bool ar[p];
    ar[0]=false;
    ar[1]=false;
    for (i = 2; i <= p; i += 1)
        ar[i] = true;
    ar[0] = false;
    ar[1] = false;

    for (i = 2; i * i <= p; i += 1)
    {
        if (ar[i] == true)
            for (j = i * i; j <= p; j += i)
                ar[j] = false;
    }
    map<ll, ll>mp;
    for (i=0;i<p;i++)
        if (ar[i]==true)mp[i]=1;

    cin>>n;

    for (auto h : mp)
    {
        p=h.ff;
        while (p<=n) {
            mp[h.ff]+=n/p;
            p*=h.ff;
        }
    }

    c=1;
    // for (auto h : mp)
    //     cout<<h.ff<<" "<<h.ss<<endl;
    for (auto h : mp)
        c=(c*h.ss)%MOD;
    cout<<c<<endl;


    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    while(1){
        cin >> H >> W;
        if(H==0) break;
        
        for(int i = 0; i < H; ++i){
            for(int j = 0; j < W; ++j){
                if( (i+j) % 2 == 0){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3068
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> X(N),Y(N),H(N);
  for(int i=0;i<N;i++){
    cin >> X[i] >> Y[i] >> H[i];
  }
  bool flag=true;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      int height=0;
      for(int k=0;k<N;k++){
        if(H[k]!=0){
          height=H[k]+abs(i-X[k])+abs(j-Y[k]);
          break;
        }
      }
      flag=true;
      for(int k=0;k<N;k++){
        if(max(height-abs(X[k]-i)-abs(Y[k]-j),0)!=H[k]){
          flag=false;
          break;
        }
      }
      if(flag){
        cout << i << " " << j << " " << height << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  int ans=0;
  rep(i,n)if(a[i]==i+1){
    ans++;
    if(i==n-1)swap(a[i],a[i-1]);
    else swap(a[i],a[i+1]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
n, m = map(int, input().split())

s = [0] * (n + 1)
for i in range(m):
    l, r = map(int, input().split())
    s[l - 1] += 1
    s[r] -= 1

for i in range(n):
    s[i + 1] += s[i]
print(s.count(m))


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;

    if (s.find('a') == string::npos) {
        cout << "No" << endl;
        return 0;
    }
    if (s.find('b') == string::npos) {
        cout << "No" << endl;
        return 0;
    }
    if (s.find('c') == string::npos) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iM = int.Parse(sS[1]);
            List<int> lstVote = new List<int>();
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < sS.Length; i++) { lstVote.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Yes";
            int iMax = lstVote.Sum();
            decimal iCmp = (decimal)iMax / (4M * (decimal)iM);
            lstVote.Sort(); lstVote.Reverse();
            for (int i = 0; i < iM; i++)
            {
                if ((decimal)lstVote[i] < iCmp) { sOut = "No"; break; };
            }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 28216
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<ll> a(mx);
ll n,k;

bool finish(ll x){
  ll cnt=0;
  for(int i=0; i<n; i++){
    if(a[i]<0){
      ll v = (x<0?(x+a[i]-1):x)/a[i]; 
      cnt += a.begin()+i - lower_bound(a.begin(),a.begin()+i, v);
    } else if(a[i]==0){
      if(x>=0){ cnt += i; }
    } else {
      ll v = (x>=0?x:(x-a[i]+1))/a[i];
      cnt += upper_bound(a.begin(),a.begin()+i, v) - a.begin();
    }
  }
  return cnt>=k;
}
 
int main(){
  cin >> n >> k;
  a.resize(n);
  rep(i,n){cin>>a[i];}
  sort(a.begin(),a.end());
  ll l=-longinf,r=longinf,mid=(r+l)/2;
  while(r-l>1){
    mid=(r+l)/2;
    if(finish(mid)){ r=mid; }else{ l=mid; }
  }
  ll ans = r;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int N, K;
vector<vector<int>> G;
vector<pair<int, int>> LR;
bool ng = false;
vector<int> ans;

void merge(pair<int, int> &x, pair<int, int> y){
    if(x.second == 1<<30){
        x.first = y.first-1;
        x.second = y.second+1;
        return;
    }
    if((x.first+(1<<20))%2 == (y.first+(1<<20))%2){
        ng = true;
        return;
    }
    x.first = max(x.first, y.first-1);
    x.second = min(x.second, y.second+1);
    if(x.first > x.second){
        ng = true;
        return;
    }
}

void dfs(int cur, int prv){
    for(int nxt : G[cur]){
        if(nxt == prv) continue;
        dfs(nxt, cur);
        if(LR[nxt].second==(1<<30)) continue;
        merge(LR[cur], LR[nxt]);
    }
    if(ng) return;
}

void dfs2(int cur, int prv){
    for(int nxt : G[cur]){
        if(nxt == prv) continue;
        merge(LR[nxt], LR[cur]);
        dfs2(nxt, cur);
    }
    if(ng) return;
}

int main(){
    cin >> N;
    G.resize(N);
    LR.resize(N, make_pair(-(1<<30), 1<<30));
    ans.resize(N, 1<<30);
    REP(i, N-1){
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    cin >> K;
    REP(i, K){
        int V, P;
        cin >> V >> P;
        V--;
        LR[V] = make_pair(P, P);
    }

    dfs(0, -1);
    if(ng){
        cout << "No" << endl;
        return 0;
    }
    dfs2(0, -1);
    if(ng){
        cout << "No" << endl;
        return 0;
    }

    REP(i, N){
        if(LR[i].second != 1<<30){
            ans[i] = LR[i].first;
        }
    }
    cout << "Yes" << endl;
    REP(i, N){
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> Score(N);
    for (int i = 0; i < Q; i++)
    {
        int A;
        cin >> A;
        --A;
        Score[A]++;
    }

    for (int i = 0; i < N; i++)
    {
        if (K - (Q - Score[i]) > 0)
        {
            cout << "Yes" << endl;
        } else
        {
            cout << "No" << endl;
        }
        
        
    }
    

  return 0;
}


Measured memory_bytes: 1024
/*input
3
1000000000 1000000000 1000000000
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
    os << x << " ";
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

/******************************** START *********************************/
const int N = 405;
vector < ll > v;
ll dp[N][N];


ll func(int l, int r)
{
  if(l == r) {
    return 0;
  }
  if(dp[l][r] > -1) {
    return dp[l][r];
  }

  ll res = INF;
  for(int i = l; i < r; i ++) {
    res = min(res, func(l, i) + func(i + 1, r) + v[r] - v[l - 1]);
  }
  return dp[l][r] = res;
}

int main()
{
  ifalse;
  int n;
  cin >> n;
  v.resize(n + 1);
  for(int i = 0; i < n; i ++) {
    cin >> v[i + 1];
  }
  for(int i = 1; i <= n; i ++) {
    v[i] += v[i - 1];
  }

  memset(dp, -1, sizeof(dp));
  cout << func(1, n), nl;
  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=2e3+11;
const int M=2e6+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;

ll dp[N];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int n,x,y;
  cin>>n>>x>>y;
  for(int i=1;i<n;i++){
    for(int j=i+1;j<=n;j++){
      int dist1=j-i;
      int dist2=abs(x-i)+1+abs(j-y);
      int dist=min(dist1,dist2);
      dp[dist]++;
    }
  }
  for(int i=1;i<n;i++){
    cout<<dp[i]<<nl;
  }
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

void unique_count(vector<long> &a, vector<vector<long>> &b) {
	// erase(b.begin(), b.end());
	for (long i=0; i<a.size(); i++)
		if ((i>0)&&(a.at(i)==a.at(i-1)))
			b.back().at(1)++;
		else
			b.push_back({a.at(i), 1});
	return;
}

long	Comb(long A, long B) {
	B=min(B, A-B);
	long S=1;
	long D=1;
	while(B>0) {
		S *=A;
		S /=D;
		A--;
		B--;
		D++;
	}
	return S;
}

int	main() {
	long N, A, B;
	cin >>N >>A >>B;
	long A0=A;
	vector<long> v(N, 0);
	Rep0(i, N)
		cin >>v.at(i);
	Sort(v);
	vector<vector<long>> w;
	unique_count(v, w);
	double AVE=0.0;
	long S;
	if (A>w.back().at(1)) {
		long SS=0;
		while(A>=w.back().at(1)) {
			SS +=w.back().at(0)*w.back().at(1);
			A -=w.back().at(1);
			w.pop_back();
		}
		SS +=A*w.back().at(0);
		AVE=((double)SS)/A0;
		S=Comb(w.back().at(1), A);
	} else {
		AVE=w.back().at(0);
		for (long i=A; i<=min(B, w.back().at(1)); i++)
			S +=Comb(w.back().at(1), i);
	}
	cout <<fixed <<setprecision(10) <<(double)AVE <<endl;
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  char a[4];
  int c = 0;

    scanf("%s", a);
  for (int i = 0; i < 4; i++) {
    if(a[i] == '2') {
      c++;
    }
  }
  
  printf("%d", c);
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0,i[10];
	string xx[]={"0","7","5","3"};
	cin >> n;
	for(i[0]=0;i[0]<4;i[0]++)
	for(i[1]=0;i[1]<4;i[1]++)
	for(i[2]=0;i[2]<4;i[2]++)
	for(i[3]=0;i[3]<4;i[3]++)
	for(i[4]=0;i[4]<4;i[4]++)
	for(i[5]=0;i[5]<4;i[5]++)
	for(i[6]=0;i[6]<4;i[6]++)
	for(i[7]=0;i[7]<4;i[7]++)
	for(i[8]=0;i[8]<4;i[8]++)
	{
		int x[4] = {};
		bool add = true;
		bool x3,x5,x7;
		x3 = x5 = x7 = false;
		string k;
		for(int j=0;j<9;j++){
			x[i[j]]++;
			k += xx[i[j]];
			if(i[j]==0&&(x[1]+x[2]+x[3])!=0)
				add = false;
			if(i[j]==1)x7=true,x[1]++;
			if(i[j]==2)x5=true,x[2]++;
			if(i[j]==3)x3=true,x[3]++;
		}
		if(add)if(x7&&x5&&x3)if(stoi(k)<=n)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/ python3.8
n=int(input())
p=[int(x) for x in input().split()]
ans=0
for i in range(1,n-1):
    if max(p[i - 1], p[i + 1]) > p[i] > min(p[i - 1], p[i + 1]):
        ans += 1
print(ans)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
int read() {
	int f = 1, x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -f;
		ch = getchar();
	} while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return f * x;
}
int main() {
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; ++i) if (i % k == 0) return puts("OK"), 0;
	puts("NG");
	return 0;
}






Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=3e5+99;
struct node{int id;ll a,b;}p[N];
int n,m,fa[N],vis[N],cur[N];
ll a[N],b[N],sum[N],ans[N];
vector<int>g[N];
bool cmp(node a,node b){return a.a<b.a;}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		a[i]=max(a[i],b[i]);
		p[i]=(node){i,a[i],b[i]};
		sum[i]=b[i];
	}
	for(int i=1,x,y;i<=m;i++)scanf("%d%d",&x,&y),g[x].push_back(y),g[y].push_back(x);
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++)fa[i]=i,ans[i]=1e18;
	for(int i=1,j;i<=n;i=j+1)
	{
		j=i;while(p[j+1].a==p[i].a)j++;
		for(int k=i;k<=j;k++)vis[p[k].id]=1;
		for(int k=i;k<=j;k++)
		{
			int x=p[k].id;
			for(int t=0;t<g[x].size();t++)
			{
				int to=find(g[x][t]);
				if(!vis[to])continue;
				cur[g[x][t]]=to;
			}
		}
		for(int k=i;k<=j;k++)
		{
			int x=p[k].id;
			for(int t=0;t<g[x].size();t++)
			{
				int to=find(g[x][t]);
				if(!vis[to]||find(x)==to)continue;
				int y=find(x),z=find(to);
				fa[z]=y;
				sum[y]+=sum[to];
			}
		}
		for(int k=i;k<=j;k++)
		{
			int x=p[k].id;
			for(int t=0;t<g[x].size();t++)
			{
				int to=cur[g[x][t]];
				if(!vis[to]||i==vis[to])continue;
				ll now=find(x),cst=max(a[x],ans[to]+b[x])+sum[now]-sum[to]-b[x];
				ans[now]=min(ans[now],cst);
			}
			int y=find(x);
			ans[y]=min(ans[y],a[y]+sum[y]-b[x]);
		}
	}
	cout<<ans[find(1)]<<endl;
}

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

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(long long int &x){int k,m=0;x=0;for(;;){k=gc();if(k==45){m=1;break;}if(48<=k&&k<=57){x=k-48;break;}}for(;;){k=gc();if(k<48||k>57)break;x=x*10+k-48;}if(m)x=-x;}
static inline void uread(long long int &x){int k;x=0;for(;;){k=gc();if(48<=k&&k<=57){x=k-48;break;}}for(;;){k=gc();if(k<48||k>57)break;x=x*10+k-48;}}

long long int R, C, N, a[114514], b, i;
vector<pair<long long, long long>> p;

bool isedge(long long x, long long y){
    return ((x == 0) || (x == R)) || ((y == 0) || (y == C));
}

long long int encode(long long int x, long long int y){
    if(y == 0)return x;
    if(x == R)return y + R;
    if(y == C)return R * 2 + C - x;
    if(x == 0)return R * 2 + C * 2 - y;
}

int main(){
    uread(R);
    uread(C);
    uread(N);
    for(; i < N; ++i){
        uread(*a);
        uread(a[1]);
        uread(a[2]);
        uread(a[3]);
        if(isedge(*a, a[1]) && isedge(a[2], a[3])){
            p.push_back(make_pair(encode(*a, a[1]), i));
            p.push_back(make_pair(encode(a[2], a[3]), i));
        }
    }
    sort(p.begin(), p.end());
    *a = 0;
    a[1] = 0;
    a[2] = 0;
    a[3] = 0;
    stack<long long> s;
    for(pair<long long, long long> P : p){
        if(a[P.second] == 0){
            ++a[P.second];
            s.push(P.second);
        }else{
            if(s.top() == P.second){
                s.pop();
            }else{
                return puts("NO") & 0;
            }
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 6256
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintStream out = System.out;

        out.println(Arrays.stream(in.nextLine().trim().split(" ")).map(s -> s.substring(0, 1)).collect(Collectors.joining()));
    }
}


Measured memory_bytes: 26964
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


#define ll int
#define FOR(i,a) for(ll i=0;i<(ll)a.size();i++)
#define pb push_back
#define ld long double
#define mp make_pair 
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=2e5+500;
const ll inf=1e9+100;

vector<ll> vec[maxn];
vector<ll> rvec[maxn];

ll seg[maxn*4];
ll lazy[maxn*4];

ll Y;

void add(ll node,ll v){
	seg[node]+=v;
	lazy[node]+=v;
}
void shift(ll a){
	add(2*a,lazy[a]);
	add(2*a+1,lazy[a]);
	lazy[a]=0;
}
void update(ll L,ll R,ll node,ll l,ll r,ll v){
	if(l<=L && R<=r){
		add(node,v);
		return;
	}
	if(r<=L || R<=l){
		return;
	}
	shift(node);
	ll mid=(L+R)/2;
	update(L,mid,2*node,l,r,v);
	update(mid,R,2*node+1,l,r,v);
	seg[node]=max(seg[2*node],seg[2*node+1]);
}
int main(){
	ll n,m,ans=0;
	cin>>n>>m;
	ans=max(0,(n-m));
	Y=m+5;
	for(ll i=0;i<n;i++){
		ll l,r;
		cin>>l>>r;
		vec[r].pb(l);
		rvec[l].pb(r);
	}
	ll cnt=0;
	for(ll i=1;i<=m+1;i++){
		// find_i-1
		cnt-=vec[i-1].size();
		cnt+=rvec[i-1].size();
		update(0,Y,1,i-1,i,cnt-m);
		ans=max(ans,seg[1]);
		update(0,Y,1,0,i,1);
		for(auto l:vec[i]){
			update(0,Y,1,l,i,-1);
		}
	}
	cout<<endl<<ans;
}








Measured memory_bytes: 23040
# 幅優先探索
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)
# 例2のlinksの出力結果
# [[], [6, 5], [4, 6], [4, 5], [3, 2, 6, 5], [3, 1, 4, 6], [1, 4, 2, 5]]
result = [-1] * (N + 1)
# 例2のq出力結果
# deque([1])
# deque([6, 5])リスト1幅優先探索だからより深い方
# deque([5, 1, 4, 2])6を押し出してリスト6を挿入
# deque([1, 4, 2, 3])5を押し出してリスト5から残りの3を挿入
# deque([4, 2, 3])
# deque([2, 3])
# deque([3])
# deque([])
q = deque([1])
# 全部押し出されたら1周
while q:
    # qの先頭を押し出す
    i = q.popleft()
    # 上から順に見ていく
    for j in links[i]:
        # resultのj番目が-1なら次の処理というか基本-1
        # 例えばrsultリストの1が-1ならリスト1の「6,4」の左側6を挿入する
        if result[j] == -1:
            result[j] = i
            # 処理したら右に追加してまた押し出す
            q.append(j)
# result j qの出力結果
# [-1, -1, -1, -1, -1, -1, 1]
# 6
# [-1, -1, -1, -1, -1, 1, 1]
# 5
# [-1, 6, -1, -1, -1, 1, 1]
# 1
# [-1, 6, -1, -1, 6, 1, 1]
# 4
# [-1, 6, 6, -1, 6, 1, 1]
# 2
# [-1, 6, 6, 5, 6, 1, 1]
# 3
print('Yes')
# 開業で文字列として羅列
print('\n'.join(str(i) for i in result[2:]))

Measured memory_bytes: 106220
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))

I = A.index(1)

left = I
right = N - I - 1

left_q, left_r = divmod(left, K-1)
right_q, right_r = divmod(right, K-1)

res = math.ceil((left_r+right_r)/(K-1))
print(res + left_q + right_q)


Measured memory_bytes: 13812
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: i32 = read();
    let a: i32 = read();
    if x < a {
        println!("{}", 0);
    } else {
        println!("{}", 10);
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    static TreeSet<Integer> all = new TreeSet<>();
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    set.add(sc.nextInt());
		}
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
		    if (!set.contains(sc.nextInt())) {
		        System.out.println(0);
		        return;
		    }
		}
		System.out.println(1);
	}
}



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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

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

    println(2*b - a);
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int n, m;
int a[110];
signed main()
{
  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }

  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= n - 1; j++){
      if(a[j] % i > a[j + 1] % i){
	swap(a[j], a[j + 1]);
      }
    }
  }

  for(int i = 1; i <= n; i++){
    cout << a[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = b[a[0]-1]
for i in range(1,n):
    ans += b[a[i]-1]
    if a[i] == a[i-1] + 1:
        ans += c[a[i-1]-1]

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  
  int n = s.size();
  bool ok = false;
  if(s[0] == 'A'){
    int c = s.find("C");
    if(c>=2 && c<n-1){
      ok = true;
      rep(i,n){
        if(!i) continue;
        if(i==c) continue;
        if(s[i]<'a' || s[i]>'z') ok = false;
      }
    }
  }
  cout << ( ok ? "AC" : "WA" ) << endl;
  return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':

    n = int(input())
    xs = [int(c) for c in input().split()]

    xs_sorted = sorted(xs)
    cand_s, cand_l = xs_sorted[n // 2 - 1], xs_sorted[n // 2]

    for x in xs:
        print(cand_l if x <= cand_s else cand_s)



Measured memory_bytes: 93780
M=10**9+7
n=int(input())
a=list(map(int,input().split()))
import fractions as f
l,r=a[0],1
for i in range(1,n):
  g=f.gcd(l,a[i])
  s,t=l//g,a[i]//g
  l,r=s*t*g,(r*t+s)%M
print(r)

Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
struct Segtree{
    
    ll data[1000010],datb[1000010];
    
    Segtree(){
        for(int i=0;i<200010;i++){
            data[i] = 0;
            datb[i] = 0;
        }
    }
    
    void add(int a,int b,int x,int k,int l,int r){
        if(a <= l && r <= b) data[k] += x;
        else if(l <= b && a <= r){
            datb[k] += (min(b,r)-max(a,l)+1) * x;
            add(a,b,x,k*2+1,l,(l+r)/2);
            add(a,b,x,k*2+2,(l+r)/2+1,r);
        }
    }
    
    ll sum(int a,int b,int k,int l,int r){
        if(b < l || r < a) return 0;
        else if(a <= l && r <= b) return data[k]*(r-l+1) + datb[k];
        else {
            ll res = (min(b,r)-max(a,l)+1) * data[k];
            res += sum(a,b,k*2+1,l,(l+r)/2);
            res += sum(a,b,k*2+2,(l+r)/2+1,r);
            return res;
        }
    }
    
};

Segtree seg;

int main(void){
    int n,q,s,t;
    ll a,x;
    cin >> n >> q;
    for(int i=0;i<q;i++){
        cin >> a;
        if(a == 0){
            cin >> s >> t >> x;
            seg.add(s-1,t-1,x,0,0,n-1);
        } else {
            cin >> s;
            cout << seg.sum(s-1,s-1,0,0,n-1) << endl;
        }
    }
    return(0);
}



Measured memory_bytes: 6712
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x3,y3,x4,y4;
  x3=x2-(y2-y1);
  y3=y2+(x2-x1);
  x4=x1-(y2-y1);
  y4=y1+(x2-x1);
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


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

int calc(int x){
    int a=0;
    while(x>0){
        a=a+x%10;
        x=x/10;
    }
    return a;
}


int main(){
    int N,A,B;
    cin>>N>>A>>B;

    int ans=0;
    for(int i=1;i<=N;i++){
        int a=0;
        a=calc(i);
        if(A<=a&&a<=B) {
            ans = ans + i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void){

    int n;
    string str;
    cin >> n >> str;
    int value = 0;
    int maxValue;
    int index = 0;
    int ans = 0;

    for(int i = 0;str[i] != '\0';i++){
        if(str[i] == 'W') value--;
        if(str[i] == 'E') value++;
        if(i == 0) maxValue = value;

        if(maxValue <= value){
            maxValue = value;
            index = i;
        }
    }

    for(int i = 0; str[i] != '\0';i++){
        if(i < index && str[i] == 'W') ans++;
        if(i > index && str[i] == 'E') ans++;
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
        int n, y;
        scanf("%d%d", &n, &y);
        for (int i = 0; i <= n; i ++) {
                for (int j = 0; j <= n; j ++) {
                        int k = n - i - j;
                        if (k < 0) continue;
                        if (10000 * i + 5000 * j + 1000 * k == y) {
                                printf("%d %d %d\n", i, j, k);
                                return 0;
                        }
                }
        }
        printf("%d %d %d\n", -1, -1, -1);
        return 0;
}



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

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    //引数一つの時は距離1
    edge(int t, lint c = 1) : to(t), cost(c) {
    }
};

// warshall_floyd
// dは隣接行列(long long intを使うこと)
void warshall_floyd(vector<vector<long long int>>& d) {
    long long int n = d.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (d[i][k] == LLONG_MAX || d[k][j] == LLONG_MAX) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    vector<vector<lint>> d(h * w, vector<lint>(h * w, LLONG_MAX));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') {
                if (i - 1 >= 0)
                    if (s[i - 1][j] == '.') {
                        d[i * w + j][(i - 1) * w + j] = 1;
                    }
                if (i + 1 < h) {
                    if (s[i + 1][j] == '.') {
                        d[i * w + j][(i + 1) * w + j] = 1;
                    }
                }
                if (j - 1 >= 0) {
                    if (s[i][j - 1] == '.') {
                        d[i * w + j][i * w + j - 1] = 1;
                    }
                }
                if (j + 1 < w) {
                    if (s[i][j + 1] == '.') {
                        d[i * w + j][i * w + j + 1] = 1;
                    }
                }
            }
        }
    }
    for (int i = 0; i < h * w; i++) {
        d[i][i] = 0;
    }
    warshall_floyd(d);
    lint ans = 0;
    for (int i = 0; i < h * w; i++) {
        for (int j = 0; j < h * w; j++) {
            if (d[i][j] == LLONG_MAX) {
                continue;
            }
            ans = max(d[i][j], ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1536