akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n,k;
  cin >>n>>k;
  string s;
  cin >>s;
  vector<int> ren(n+1,-1);
  vector<char> ren_p(n+1,'x');
  vector<int> ren_num(n+2,-1);
  int ct=0,mae_id=0;
  char mae_m=' ';
  rep(i,n){
    if(i==0){
      ren[0]=1;
      ren_p[0]=s.at(i);
      mae_m=s.at(i);
      mae_id=0;
    }else{
      if(s.at(i)==mae_m){
        ren[mae_id]++;
      }else{
        ren[i]=1;
        ren_p[i]=s.at(i);
        mae_m=s.at(i);
        mae_id=i;
      }
    } 
  }
  int cct=1;
  ren_num[0]=0;
  rep(i,n){
    if(ren[i]!=-1){
      ren_num[cct]=ren_num[cct-1]+ren[i];
      cct++;
    }
  }
  /*rep(i,n+2){
    cout << ren_num[i]<<endl;
  }*/
  // 出力
  int ans=0;
  rep(i,n+2){
    if(ren_num[i]==-1) break;
    int j=0;
    if(s.at(0)=='0'){
      if(i%2==0){
        j=max(0,i-2*k-1);
      }else{
        j=max(0,i-2*k);
      }
      ans =max(ans,ren_num[i]-ren_num[j]);
    }else{
      if(i%2==0){
        j=max(0,i-2*k);
      }else{
        j=max(0,i-2*k-1);
      }
      ans =max(ans,ren_num[i]-ren_num[j]);
    }
  }
  cout <<ans <<endl;
}



Measured memory_bytes: 1280
import sys
from collections import deque
def chs(s,t,md):###chooseではない
    res = 1
    for i in range(s-t+1,s+1):
        res *= i
        res%=md
    """
    for i in range(1,t+1):
        i2 = pow(i,md-2,md)
        res*=i2
        res%=md
    """
    return(res)

mod = 10**9+7
n, k = map(int, input().split( ))
E = [[] for _ in range(n)]
Deg = [0]*n
for _ in range(n-1):
    a,b = map(int, input().split( ))
    a-=1
    b-=1
    E[a].append(b)
    E[b].append(a)

Done = [False]*n
dp = [1]*n

Q = deque()
#rootを0に指定
Q.append(0)
#outのDeg
Deg=[0]*n
P = [-1]*n
Done[0] = True

while Q:
    u = Q.popleft()
    for v in E[u]:
        if not Done[v]:
            Done[v] = True
            Deg[u] +=1
            if Deg[u]>k:
                print(0)
                sys.exit()
            P[v] = u
            Q.append(v)
ans = chs(k,Deg[0]+1,mod)###+1
e0 = set(E[0])
#print(k-1,Deg[0],ans)
for i in range(1,n):
    ans*=chs(k-2,Deg[i],mod)
    ans %=mod
    #print(i,Deg[i],ans)
print(ans)


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

int main() {
    int N, M;
    cin >> N >> M;
    int H[N];
    vector <bool> C(N, true);
    for (int i=0; i<N; i++) cin >> H[i];
    for (int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (H[a]<=H[b]) C[a]=false;
        if (H[b]<=H[a]) C[b]=false;
    }
    int count=0;
    for (int i=0; i<N; i++){
        if (C[i]==true) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 4020
N = int(raw_input())
H = list(map(int,raw_input().split()))
ans = []
count = 0
i = 0
while i <= N:
  if N == 1:
    ans.append(0)
    break
  if H[i] >= H[i+1]:
    count = count + 1
  else:
    ans.append(count)
    count=0
  i = i+1
  if i == N-1:
    ans.append(count)
    break

print max(ans)

Measured memory_bytes: 11340
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int h,w,i=0,m=0;
  cin >> h >> w;
  int a[w];
  do{
    cin >> a[i];
    h-=a[i];
    i++;
  }while(i < w);
  if(h <= 0) cout << "Yes";
  else cout << "No";
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N, K;
    std::cin >> N >> K;

    vector<int> H(N);
    REP(i, N) {
        std::cin >> H[i];
    }

    SORT(H);

    auto ans = INF;
    for(int i = 0; i <= N - K; i++) {
        if(H[i + K - 1] - H[i] < ans) {
            ans = H[i + K - 1] - H[i];
        }
    }

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

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	string s;
	int out=0;
	while(cin>>s){
		string tmp;
		tmp=s;
		reverse(all(tmp));
		if(s==tmp)out++;
	}
	cout<<out<<endl;
}

Measured memory_bytes: 1192
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    var (l, r) = readLine()!!.split(' ').map(String::toInt)
    repeat(m - 1) {
        val (l2, r2) = readLine()!!.split(' ').map(String::toInt)
        l = Math.max(l, l2)
        r = Math.min(r, r2)
    }
    println(Math.max(r - l + 1, 0))
}


Measured memory_bytes: 57108
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector")
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 12005;

bool _ok1[N], _ok2[N], _ok3[N];
bool* ok1 = _ok1 + 6005;
bool* ok2 = _ok2 + 6005;
bool* ok3 = _ok3 + 6005;

bool cmp(string& x, string& y) {
	if(x.size() != y.size()) return false;
	for(int i=0;i<(int)x.size();i++) {
		if(x[i] == '?' || y[i] == '?') continue;
		if(x[i] != y[i]) return false;
	}	
	return true;
}

void go(string a, string b, bool* ok) {
	for(int i=0;i<=(int)(a.size()+b.size());i++) {
		int l = max(i, (int)b.size());
		int r = min(i+(int)b.size()-1, (int)a.size()+(int)b.size()-1);
		string x = a.substr(l-b.size(), r-l+1);
		string y = b.substr(l-i, r-l+1);
		ok[i] = cmp(x, y);
	}
}

signed main()
{
	IO_OP;
	memset(_ok1, 1, sizeof _ok1);
	memset(_ok2, 1, sizeof _ok2);
	memset(_ok3, 1, sizeof _ok3);
	string a, b, c;
	cin >> a >> b >> c;
	go(a, b, ok1);
	go(a, c, ok2);
	go(b, c, ok3);
	int mn = INF;
	int T = a.size() + b.size() + c.size();
	for(int i=-T;i<=T;i++)
		for(int j=-T;j<=T;j++) {
			if(ok1[i] && ok2[j]) {
				bool okk = true;
				int tt = j - i + (int)b.size();
				if(tt < N && tt >= 0 && !ok3[tt]) okk = false;
				if(!okk) continue;
				int l = max({0, (int)b.size() - i, (int)c.size() - j});
				int r = max({(int)a.size(), i, j});
				int cur = (l + r);
				if(cur < mn) {
					mn = cur;
				}
			}
		}
	cout << mn << endl;
}





Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }

int n;string s;
string check(string t){
    for(int i=1;i<=n+1;i++){
        if(t[i]=='S'&&s[i]=='o'){
            t+=t[i-1];
        }
        if(t[i]=='S'&&s[i]=='x'){
            t+=(t[i-1]=='S'? 'W':'S');
        }
        if(t[i]=='W'&&s[i]=='o'){
            t+=(t[i-1]=='S'? 'W':'S');
        }
        if(t[i]=='W'&&s[i]=='x'){
            t+=t[i-1];
        }
    }
    return t;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    
    cin>>n>>s;
    s+=s[0];
    vector<string> t(4);
    t[0]="SS";
    t[1]="SW";
    t[2]="WS";
    t[3]="WW";
    vector<string> u(4);
    rep(i,4){
        u[i]=check(t[i]);
        // cout<<u[i]<<endl;
        
        if(u[i].substr(0,2)==u[i].substr(u[i].size()-2,2)){
            rep(j,u[i].size()-2){
                cout<<u[i][j];
            }
            cout<<endl;
            return 0;
        }
        
    }
    cout<<-1<<endl;
    
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MAX 100007
#define MOD 1000000007
#define MODL 1000000007LL
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

// Trace dinâmico
template<typename T>
void trace(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void trace(T a, Args... args) { cout << a << " "; trace(args...); }

// Debugador de recursão
int recNum = 0;
void prTabs() { for (int ii = 0; ii < recNum; ++ii) cout << "    "; }
template<typename... Args>
void recInit(Args... args) { prTabs(); trace("rec(", args..., ")"); recNum++; }
template<typename T>
void recEnd(T a) { prTabs(); trace("->", a); recNum--;}

int MD(int x) {
	if(x < 0) return x+MOD;
	if(x >= MOD) return x-MOD;
	return x;
}

ll MDL(ll x) {
	return (x%MODL+MODL)%MODL;
}

ll modpow(ll a, ll b, ll m) {
	if (!b) return 1LL;
	if (b&1LL) return a*modpow(a, b-1, m)%m;
	ll r = modpow(a, b>>1, m);
	return r*r%m;
}

//m prime
ll invmod(ll a , ll m) {
	return modpow(a, m-2, m);
}



ll n, t, a, b, c;
int main(){
	sc("%lld %lld", &n, &t);
	int r = 0;
	while(n--) {
		sc("%lld %lld", &a, &b);
		if (a*a + b*b <= t*t) {
			r++;
		}
	}
	pr("%d\n", r);
 	return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        vector<int> v(n);
        for(int i = 0; i < n; i++) cin >> v[i];
        sort(v.begin(), v.end());
        int ans = 0;
        for(int i = 1; i < n - 1; i++)
        {
            ans += v[i];
        }
        ans /= n - 2;
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3040
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

int check(const vector<string> &field, int x, int y, char c){
	if(field[y][x] != '.'){ return 0; }
	int result = 0;
	for(int i = 0; i < 8; ++i){
		int px = x + dx[i], py = y + dy[i];
		for(int j = 0; 0 <= px && px < 8 && 0 <= py && py < 8; ++j){
			if(field[py][px] == '.'){ break; }
			if(field[py][px] == c){
				result += j;
				break;
			}
			px += dx[i]; py += dy[i];
		}
	}
	return result;
}
void put(vector<string> &field, int x, int y, char c){
	field[y][x] = c;
	for(int i = 0; i < 8; ++i){
		int px = x + dx[i], py = y + dy[i];
		for(int j = 0; 0 <= px && px < 8 && 0 <= py && py < 8; ++j){
			if(field[py][px] == '.'){ break; }
			if(field[py][px] == c){
				while(py != y || px != x){
					field[py][px] = c;
					px -= dx[i]; py -= dy[i];
				}
				break;
			}
			px += dx[i]; py += dy[i];
		}
	}
}

int main(){
	vector<string> field(8);
	for(int i = 0; i < 8; ++i){ cin >> field[i]; }
	for(int i = 0; i < 64; ++i){
		int maxval = 0, x = 0, y = 0;
		for(int j = 0; j < 8; ++j){
			for(int k = 0; k < 8; ++k){
				int c = check(field, k, j, 'o');
				if(c > maxval){ maxval = c; x = k; y = j; }
			}
		}
		if(maxval > 0){ put(field, x, y, 'o'); }
		maxval = 0, x = 0, y = 0;
		for(int j = 0; j < 8; ++j){
			for(int k = 0; k < 8; ++k){
				int c = check(field, k, j, 'x');
				if(c >= maxval){ maxval = c; x = k; y = j; }
			}
		}
		if(maxval > 0){ put(field, x, y, 'x'); }
	}
	for(int i = 0; i < 8; ++i){
		cout << field[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main(void)
{
	int x, y;
	cin >> x >> y;
	if ((4*x-y) >= 0 && (4*x-y) <= 2*x && (4*x-y)%2 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>

#define MAX 100005

typedef struct{
  char name[10]; 
  int qtime;
  int endtime;
} Process;

Process Q[MAX];
int head=0,tail=0;
int time=0;

void enqueue(Process);
Process dequeue(void);

int main()
{
  int n,q; // n = プロセス数、 q = クオンタム
  int i,count=0;
  Process *P;
  Process *E;
  Process P1;

  //入力
  scanf("%d %d",&n,&q);
  P = (Process *)malloc( n * sizeof(Process));
  E = (Process *)malloc( n * sizeof(Process));
   
  for(i=0;i<n;i++){
    scanf("%s",P[i].name);
    scanf("%d",&P[i].qtime);
    enqueue(P[i]);
  }

  //処理
  while(head != tail){
    if(Q[head].qtime <= q){

      time += dequeue().qtime;
      Q[head-1].endtime = time;
      E[count] = Q[head-1];
      
      count++;
      
      //printf("1\n");
    }
    else {
      time += q;
      P1 = dequeue();
      P1.qtime -= q;
      enqueue(P1);
      //printf("0\n");
    }
  }

  for(i=0;i<count;i++){
    printf("%s %d\n",E[i].name,E[i].endtime);
  }
  return 0;
}

void enqueue(Process x)
{
  Q[tail] = x;
  tail=(tail+1)%MAX;
}

Process dequeue()
{
  Process x;
  x = Q[head];
  Q[head].qtime = 0;
  head=(head+1)%MAX;

  return x;
}

  

  




Measured memory_bytes: 5652
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n;
    scanf("%d", &n);

    int a = n / 1000;
    n = n % 1000;
    int b = n / 100;
    n = n % 100;
    int c = n / 10;
    n = n % 10;
    int d = n;

    char op[8][3] = {
        {'+', '+', '+'},
        {'-', '+', '+'},
        {'+', '-', '+'},
        {'+', '+', '-'},
        {'-', '-', '+'},
        {'+', '-', '-'},
        {'-', '+', '-'},
        {'-', '-', '-'},
    };

    for (int i = 0; i < 8; i++) {
        int total;
        char op1, op2, op3;
        if (op[i][0] == '+') {
            total = a + b;
            op1 = '+';
        } else {
            total = a - b;
            op1 = '-';
        }

        if (op[i][1] == '+') {
            total = total + c;
            op2 = '+';
        } else {
            total = total - c;
            op2 = '-';
        }

        if (op[i][2] == '+') {
            total = total + d;
            op3 = '+';
        } else {
            total = total - d;
            op3 = '-';
        }

        if (total == 7) {
            printf("%d%c%d%c%d%c%d=7\n", a, op1, b, op2, c, op3, d);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] A = new int[N][N - 1];
		V[][] vs = new V[N][N];
		int[][] d = new int[N][N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N - 1; j++) {
				A[i][j] = sc.nextInt() - 1;
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				vs[i][j] = vs[j][i] = new V(i, j);
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N - 2; j++) {
				vs[i][A[i][j]].add(vs[i][A[i][j+1]]);
				d[i][A[i][j+1]]++;
				d[A[i][j+1]][i]++;
			}
		}
		Queue<V> que = new LinkedList<>();
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				if (d[i][j] == 0) {
					que.offer(vs[i][j]);
					vs[i][j].depth = 1;
				}
			}
		}
		int cnt = 0;
		while (!que.isEmpty()) {
			V v = que.poll();
			cnt++;
			for (V w: v) {
				d[w.p][w.q]--;
				w.depth = Math.max(w.depth, v.depth + 1);
				if (d[w.p][w.q] == 0) {
					que.offer(w);
				}
			}
		}
		if (cnt != N * (N - 1) / 2) {
			System.out.println(-1);
			return;
		}
		int diam = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				diam = Math.max(diam, vs[i][j].depth);
			}
		}
		System.out.println(diam);
	}
	static class V extends ArrayList<V>
	{
		int p, q;
		int depth = 0;
		V(int _p, int _q) {p = _p; q = _q;}
	}
}

Measured memory_bytes: 329700
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int n;
char s[100001];
int main()
{
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i]=='A'&&s[i+1]=='C') 
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
} 

Measured memory_bytes: 256
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n;
ll c[26];
ll d[400][26];

vector<int> curr;

ll calc(){
	ll last[26];
	
	memset(last,-1,sizeof(last));
	
	ll res=0;
	rep(x,0,n){
		res+=d[x][curr[x]];
		last[curr[x]]=x;
		
		rep(y,0,26) res-=c[y]*(x-last[y]);
		
		cout<<res<<endl;
	}
	
	return res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	rep(x,0,26) cin>>c[x];
	
	rep(x,0,n){
		rep(y,0,26) cin>>d[x][y];
	}
	
	
	rep(x,0,n){
		int t;
		cin>>t;
		curr.push_back(t-1);
	}
	
	calc();
}


Measured memory_bytes: 3696
//選択ソート
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] a = new int [n];
		int count = 0;
		
		for(int i = 0; i < a.length; i++) {
			a[i] = stdIn.nextInt();
		}
		
		for(int i = 0; i < a.length; i++) {
			int minj = i;
			for(int j = i; j < a.length; j++) {
				if(a[j] < a[minj]) {
					minj = j;
				}
			}
			if(i != minj) {
			int t = a[i];
			a[i] = a[minj];
			a[minj] = t;
			count++;
			}
		}
		
		for(int i = 0; i < a.length - 1; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[a.length - 1]);
		System.out.println(count);
	}

}



Measured memory_bytes: 26388
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 1e9+7;

string S;

ll N, K;
ll ans;
bool flag;

long long mod_pow(long long x, long long n) {
	if (n == 0) return 1;
	long long res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

const int MAX_NUM = 2100;
long long fact[MAX_NUM], inv[MAX_NUM];

long long comb(long long n, long long k) {
	if (n < k || n < 0 || k < 0) return 0;
	if (fact[0] == 0) {
		fact[0] = 1; inv[0] = 1;
		for (int i = 1; i < MAX_NUM; i++) {
			fact[i] = fact[i - 1] * i % mod;
			inv[i] = mod_pow(fact[i], mod - 2);
		}
	}
	return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);


	cin >> N>>K;

	FOR(i, 1, K + 1) {
		if (i == 1)cout << N - K + 1 << endl;
		else cout << (comb(N - K + 1, i)*comb(K - 1, i - 1))%MOD << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, cnt[26]{}, ans=0;
    string s;
    cin >> n >> s;
    for(auto c : s){
        if(c>='a' && c<= 'z') cnt[c-'a']++;
    }
    vector<int> ls;
    for(int i=9;i>1;i--){
        bool update = true;
        while(update){
            update = false;
            ls.clear();
            REP(j,26){
                if(cnt[j]>=i){
                    ls.push_back(j);
                }
            }
            if(ls.size()>=2){  // 同じ個数が2個以上あるならカッコでくくる
                ans += ls.size()*2+4;
                update = true;
            }
            else ans += ls.size()*4;
            for(auto j : ls) cnt[j] -= i;
        }
    }
    REP(i,26) if(cnt[i]>0) ans+=2;
    ans--;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

typedef pair< int, int > Pi;
typedef pair< Pi, Pi > Pii;

struct node {
  Pi point;
  int cost, delta, used;
  bool operator<(const node& n) const 
  {
    return(cost > n.cost);
  }
};

int main()
{
  int R, C;
  string a[30];
  Pi S, G;

  cin >> R >> C;
  for(int i = 0; i < R; i++) {
    cin >> a[i];
    for(int j = 0; j < C; j++) {
      if(a[i][j] == 'S') S = make_pair(j, i), a[i][j] = '.';
      else if(a[i][j] == 'G') G = make_pair(j, i), a[i][j] = '.';
    }
  }

  priority_queue< node > que;
  int min_cost[30][30][5][4];
  fill_n(***min_cost, 30 * 30 * 5 * 4, INF);

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

  que.push((node){S, 0, 4, 0});
  min_cost[S.first][S.second][4][0] = 0;

  while(!que.empty()) {    
    node p = que.top(); que.pop();
    if(p.cost > min_cost[p.point.first][p.point.second][p.delta][p.used]) continue;
    if(p.point == G) {
      cout << p.cost << endl;
      break;
    }
    for(int i = 0; i < 4; i++) {
      int ny = p.point.second + dy[i], nx = p.point.first + dx[i];
      if(ny < 0 || ny >= R || nx < 0 || nx >= C) continue;
      if(a[ny][nx] == '#') continue;
      node next = p;
      next.point = make_pair(nx, ny);
      if(a[ny][nx] == 'o' || (p.delta == i && next.used > 0) || a[ny][nx] == '.') {
        next.cost  = p.cost + 1;
        if(a[ny][nx] == '.' && !(p.delta == i && next.used > 0)) ++next.cost;
        if(p.delta == i) next.used = p.used - 1;
        else             next.used = 0;
        next.delta = i;
        if(next.cost < min_cost[nx][ny][i][next.used]) {
          min_cost[nx][ny][i][next.used] = next.cost;
          que.push(next);
        }
      }

      next.cost = p.cost + 3;
      next.delta = i;
      next.used = 2;
      if(next.cost < min_cost[nx][ny][i][next.used]) {
        min_cost[nx][ny][i][next.used] = next.cost;
        que.push(next);
      }
    }
  }

}

Measured memory_bytes: 1300
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
a = list(range(1,k+1))
b = list(range(1,k+1))
c = list(range(1,k+1))

for i in a:
    for j in b:
        for k in c:
            ans += gcd(i,j,k)
print(ans)

Measured memory_bytes: 74964
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e6+1;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      string s;
      cin>>s;
      int n=s.length();
      int k;
      cin>>k;
      int ans=0;
      int o1=0,o2=0;
      for(int i=0;i<n;i++) 
      {
            int j=i;
            int cnt=0;
            while(j<n&&s[j]==s[i]) j++,cnt++;
            j--;
            if(i==0)
            {
                  if(j==n-1)
                  {
                        cout<<(n*k/2);
                        return 0;
                  }
                  else{
                        o1+=cnt;
                  }
            }
            else if(j==n-1)
            {
                  o2+=cnt;
            }
            else{
                  ans+=cnt/2;
            }
            i=j;
      }    
      // cout<<ans<<" ";
      // cout<<ans<<" "; 
      int orz=ans*k+o1/2+o2/2;
      if(s[0]==s[n-1])
      {
            orz+=(k-1)*((o1+o2)/2);
      }
      else{
            orz+=(k-1)*((o1/2)+(o2/2));
      }
      cout<<orz;
}
// I never lose. I either win or I learn

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

#define int long long
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 rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int k,r; cin >> k >> r;
    if(k>=10){
        cout<<r<<endl;
    }else{
        cout<<r+100*(10-k)<<endl;
    }
}

Measured memory_bytes: 256
import numpy as np


def main():
    MOD = int(1e9 + 7)

    n, k = map(int, input().split())
    can = [[int(c) for c in input().split()] for _ in range(n)]
    can = np.array(can, dtype=object)

    answer = np.eye(n, dtype=object)
    while k:
        if k % 2:
            answer = np.dot(answer, can) % MOD
        can = np.dot(can, can) % MOD
        k //= 2

    total = 0
    for i in range(n):
        for j in range(n):
            total += answer[i, j]
            if total >= MOD:
                total -= MOD

    print(total)


if __name__ == "__main__":
    main()


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    ll k;
    cin >> k;

    //sampleより最大10桁なことがわかる
    vector<vector<ll>> dp(11, vector<ll>(10));
    vector<ll> digitsum(11);

    rep(i, 10){
        dp[1][i] = 1;
    }

    //1~9の9通り
    digitsum[1] = 9;

    if(k <= 9){
        cout << k << endl;
    }else{

        [&]{
            for(int i = 2; i <= 10; i++){

                ll tmpsum = 0;
                rep(j, 10){
                    if(j == 0){
                        dp[i][j] = dp[i - 1][j] + dp[i - 1][j + 1];
                    }else if(j == 9){
                        dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
                    }else{
                        dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1];
                    }

                    if(j != 0) tmpsum += dp[i][j];
                }

                digitsum[i] = digitsum[i - 1] + tmpsum;

                if(digitsum[i] >= k){
                    //桁数は分かった
                    int digit = i;

                    vector<int> ans(digit + 1);

                    ll tmpcount = digitsum[i - 1];

                    //最初の桁
                    for(int j = 1; j <= 9; j++){
                        if(tmpcount + dp[digit][j] >= k){
                            ans[1] = j;
                            k = k - tmpcount;
                            break;
                        }else{
                            tmpcount += dp[digit][j];
                        }
                    }

                    //2桁以降

                    for(int d = 2; d <= digit; d++){
                        tmpcount = 0;

                        for(int j = max(ans[d - 1] - 1, 0); j <= min(ans[d - 1] + 1, 9); j++){
                            if(tmpcount + dp[digit + 1 - d][j] >= k){
                                ans[d] = j;
                                k = k - tmpcount;
                                break;
                            }else{
                                tmpcount += dp[digit + 1 - d][j];
                            }
                        }
                    }

                    for(int j = 1; j <= digit; j++){
                        cout << ans[j];
                    }
                    cout << endl;
                    return;
                }
            }
        }();

        /*
        for(int i = 1; i <= 10; i++){
            for(int j = 0; j <= 9; j++){
                cerr << dp[i][j] << " ";
            }
            cerr << endl;
        }
        */

    }

    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  string s;
  cin >> s;
  LL piv = s.size()/2;
  LL answer = piv;
  for(;answer<s.size() && s[piv] == s[answer] && s[piv] == s[s.size() - 1 - answer];++answer);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i_, n) cout << a[i_] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always



int main() {
    
    
    

    int n;
    while (cin >> n && n) {
        string s[n]; rep(i, n) cin >> s[i];
        rep(i, n) {
            string tmp;
            tmp += s[i][0];
            rep(j, SZ(s[i]) - 1) {
                if (s[i][j] == 'a' || s[i][j] == 'i' || s[i][j] == 'u' ||
                    s[i][j] == 'e' || s[i][j] == 'o') {
                    tmp += s[i][j + 1];
                }
            }
            s[i] = tmp;
        }
        //rep(i, n) cout << s[i] << " "; cout << endl;
        sort(s, s + n);
        
        rep3(i, 1, 51) { //何文字まで同じのあるか
            map<string, int> mp;
            int flg = 0;
            rep(j, n) {
                if (SZ(s[j]) < i) {
                    if (mp[s[j]]) {
                        flg = 1;
                        break;
                    }
                    mp[s[j]] = 1;
                } else {
                    if (mp[s[j].substr(0, i)]) {
                        flg = 1;
                        break;
                    }
                    mp[s[j].substr(0, i)] = 1;
                }
            }
            if (flg && i == 50) {
                out(-1);
                break;
            }
            if (flg) continue;
            out(i);
            break;
        }
        
    }
}




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

int main() {
	ll N,r=0;
	string S;
	map<char,vector<int>> m;
	cin >> N >> S;

	m['R'] = vector<int>(N,0);
	m['G'] = vector<int>(N,0);
	m['B'] = vector<int>(N,0);

	rep(i,N) {
		m.at(S.at(N-1-i)).at(N-1-i) = 1;

		if(i != 0) {
			m['R'].at(N-1-i) += m.at('R').at(N-i);
			m['G'].at(N-1-i) += m.at('G').at(N-i);
			m['B'].at(N-1-i) += m.at('B').at(N-i);
		}
	}

	rep(i,N)
		for(int j=i+1; j<N-1; ++j) {
			if(S.at(i) == S.at(j))
				continue;
			string t=""; t+=S.at(i); t+=S.at(j);
			char p;
			sort(t.begin(), t.end());

			if(t == "BG")
				p = 'R';
			else if(t == "BR")
				p = 'G';
			else
				p = 'B';

			r += m.at(p).at(j+1);
			
			if(j+(j-i)<N && S.at(j+(j-i)) == p)
				--r;
		}

	cout << r << endl;
}

Measured memory_bytes: 3692
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

/*
0 1 2 3
1 3 2 4

0 2 1 3
1 2 3 4
*/
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		vector<PII> w(N);
		REP(i, N) {
			cin>>w[i].first;
			w[i].second = i;
		}
		sort(ALL(w));
		ll co = 1;
		ll mx = 0;
		REP(i, N) {
			if(0<i) {
				if(w[i-1].second < w[i].second) co++;
				else co = 1;
			}
			mx = max(mx, co);
		}
		cout<<N-mx<<endl;
//		break;
	}
	
	return 0;
}


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

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

  int s = 0;
  int p = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += abs(p - a[i]);
    p = a[i];
  }
  s += abs(p);

  for (int i = 0; i < n; i++) {
    int sum = s;

    if (i == 0) {
      int af = abs(a[i] - a[i + 1]);
      af += abs(a[i]);
      sum -= af;

      sum += abs(a[i + 1]);
    } else if (i == n - 1) {
      int be = abs(a[i - 1] - a[i]);
      be += abs(a[i]);
      sum -= be;

      sum += abs(a[i - 1]);
    } else {
      int af = abs(a[i] - a[i + 1]);
      int be = abs(a[i - 1] - a[i]);
      sum -= af + be;

      sum += abs(a[i - 1] - a[i + 1]);
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1664
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");

  	tmp = input[0].split("");

  	var sum = 0;
  	for (var i = 0; i < tmp.length; i++) {
      sum = sum + parseInt(tmp[i], 10);
    }
 
  	// console.log("%d", sum);
  	var N = sum;
 
    if (N % 9 === 0 ) {
      	console.log("Yes");
    } else {
        console.log("No");
    }
  
  
  
	//出力
	// console.log('%d',result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 34676
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int n,x,a[109],y;
int now,pos;

int main(){
	scanf("%d%d",&x,&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&y);
		a[y] = 1;
	}
	now = x;
	while(1){
		if(a[now] == 0) break;
		now++;
	}
	pos = x - 1;
	while(1){
		if(a[pos] == 0) break;
		pos--;
	}
	if(now-x < x-pos) printf("%d",now);
	else printf("%d",pos);
}


Measured memory_bytes: 3824
#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
vector<ll> devide(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i != 0) continue;
    res.emplace_back(i);res.emplace_back(n/i);
  }
  sort(res.begin(),res.end());
  return res;
}
int main(){
  ll n,m,d;
  cin>>n>>m;
  vector<ll> f=devide(m);
  FOR(i,0,SIZE(f)){
    if(f[i]>=n){d=f[i];break;}
  }
  cout<<m/d<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll l,r;
cin>>l>>r;
ll a[l]={};
ll gc=1000000000000;
for(ll i=0; i<l; i++){
cin>>a[i];}
sort(a,a+l);
for(ll i=0; i+r-1<l; i++){
gc=min(a[i+r-1]-a[i],gc);}
cout<<gc<<endl;}


Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

string solve()
{
    ll N;
    cin >> N;
    return string("ABC") + to_string(N);
}

int main()
{
    do {
        cout << solve() << endl;
    } while (DEBUG);
}


Measured memory_bytes: 764
#include<iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int ki=0,gu=0;
	int a;
	for(int i=0;i<n;i++)
	{
		cin >> a;
		if(a%2==0)	gu++;
		else		ki++;
	}
	
	cout << (ki%2==0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){ ;
int main() {
int N;
cin>>N;
int A=0;
int B=0;
vector<char>C(N);
rep(i,N)
cin>>C.at(i);
if(C.at(i)=='W'){
    A++;
}
else
{
    B++;
}
}
if(A==0||B==0){
  cout<<0<<endl;
}
else {
    int count=0;
    for(int i=N-1; i>N-A-1; i--){
        if(C.at(i)=='R'){
            count++;
        }  
    }
    cout<<count<<endl;
}
 }


Measured memory_bytes: 3536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String half = s.substring(0, n / 2);

		if (n % 2 == 0 && s.matches(half.concat(half))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}


Measured memory_bytes: 21972
n = int(input())
s = input()

# r[i] : s[i:]に何個あるか
r = [0] * (n + 1)
g = [0] * (n + 1)
b = [0] * (n + 1)

ss = s[::-1]
for i in range(n):
    c = ss[i]
    # if i > 0:
    #     r[i] = r[i - 1]
    #     g[i] = g[i - 1]
    #     b[i] = b[i - 1]

    r[i + 1] = r[i] + (c == 'R')
    g[i + 1] = g[i] + (c == 'G')
    b[i + 1] = b[i] + (c == 'B')

    # if ss[i] == 'R':
    #     r[i] += 1
    # if ss[i] == 'G':
    #     g[i] += 1
    # if ss[i] == 'B':
    #     b[i] += 1

r = r[::-1]
g = g[::-1]
b = b[::-1]

ans = 0



# rgb
for i in range(n):
    if s[i] != 'R':
        continue
    for j in range(i + 1, n):
        if s[j] != 'G':
            continue
        d = j - i
        ans += b[j]
        if j + d < n and s[j + d] == 'B':
            ans -= 1
# rbg
for i in range(n):
    if s[i] != 'R':
        continue
    for j in range(i + 1, n):
        if s[j] != 'B':
            continue
        d = j - i
        ans += g[j]
        if j + d < n and s[j + d] == 'G':
            ans -= 1
# grb
for i in range(n):
    if s[i] != 'G':
        continue
    for j in range(i + 1, n):
        if s[j] != 'R':
            continue
        d = j - i
        ans += b[j]
        if j + d < n and s[j + d] == 'B':
            ans -= 1
# gbr
for i in range(n):
    if s[i] != 'G':
        continue
    for j in range(i + 1, n):
        if s[j] != 'B':
            continue
        d = j - i
        ans += r[j]
        if j + d < n and s[j + d] == 'R':
            ans -= 1
# brg
for i in range(n):
    if s[i] != 'B':
        continue
    for j in range(i + 1, n):
        if s[j] != 'R':
            continue
        d = j - i
        ans += g[j]
        if j + d < n and s[j + d] == 'G':
            ans -= 1
# bgr
for i in range(n):
    if s[i] != 'B':
        continue
    for j in range(i + 1, n):
        if s[j] != 'G':
            continue
        d = j - i
        ans += r[j]
        if j + d < n and s[j + d] == 'R':
            ans -= 1

print(ans)


Measured memory_bytes: 69224
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
struct ver {P p;int c;};

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    char s[H][W];
    int sx,sy;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> s[i][j];
            if(s[i][j]=='S'){
                sx=j;
                sy=i;
            }
        }
    }
    queue<ver> q;
    q.push({mp(sx,sy),0});
    int ans=800;
    while(q.size()){
        ver t=q.front();q.pop();
        int x=t.p.fs;
        int y=t.p.sc;
        if(x==0||x==W-1||y==0||y==H-1){
            ans=min(ans,1);
        }
        ans=min({ans,(x+K-1)/K+1,(y+K-1)/K+1,(W-2-x+K)/K+1,(H-2-y+K)/K+1});
        if(t.c==K) continue;
        for(int i=0;i<4;i++){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(0<=nx&&nx<W&&0<=ny&&ny<H&&s[ny][nx]=='.'){
                s[ny][nx]='#';
                q.push({mp(nx,ny),t.c+1});
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
import sys
sys.setrecursionlimit(10000000)
import numpy as np
from heapq import heapify, heappop, heappush
import copy
from math import gcd, ceil
from collections import deque
# queueとして使う場合 push, popleftを使う
from bisect import bisect_left, bisect_right
from decimal import *
# bisect_left: 配列の順序関係が崩れない条件で挿入することができる一番左の点
# bisect_right: 配列の順序関係が崩れない条件で挿入することができる一番右の点
# A = [1, 1, 1, 2, 2, 2, 4]
# print(bisect_left(A, 2))  # 3
# print(bisect_right(A, 2))  # 6
# print(bisect_left(A, 3))  # 6
# print(bisect_right(A, 3))  # 6


def main():
    A, B = input().split()
    A = Decimal(A)
    B = Decimal(B)
    print(int((A * B)))


if __name__ == '__main__':
    main()


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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

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

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;
}

Measured memory_bytes: 256