akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
public class Main {
	static int[][] dp;
	static int h;
	static int w;
	static int k;
	public static void main(String[] args) throws Exception{
		int num = 998244353;
 
		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		StringTokenizer st = new StringTokenizer(bf.readLine());
 		h = Integer.parseInt(st.nextToken());
 		w = Integer.parseInt(st.nextToken());
 		k = Integer.parseInt(st.nextToken());
 		StringTokenizer coords = new StringTokenizer(bf.readLine());
 		int x1 = Integer.parseInt(coords.nextToken());
 		int y1 = Integer.parseInt(coords.nextToken());
 		int x2 = Integer.parseInt(coords.nextToken());
 		int y2 = Integer.parseInt(coords.nextToken());
 		char[][] c = new char[h+1][w+1];
 		dp = new int[h+1][w+1];
 		for(int i = 1;i<=h;i++){
 			String line = bf.readLine().trim();
 			for(int j = 1;j<=w;j++){
 				c[i][j] = line.charAt(j-1);
 			}
 		}
 		// EVERYTHING IS INFLATED BY ONE
 		dp[x1][y1] = 1;
 		
 		Queue<Integer> bfs = new LinkedList<Integer>();
 		ArrayList<Integer> first = new ArrayList<Integer>();
 		bfs.add((x1-1)*w+(y1-1));
 		while(!bfs.isEmpty()){
 			int p = bfs.remove();
 			int tx = p/w+1;
 			int ty = p%w+1;
 			for(int i = tx+1;i<=Math.min(tx+k,h);i++){
 				if (c[i][ty] == '@')
 					break;
 				if (dp[i][ty] != 0 && dp[tx][ty]+1 > dp[i][ty])
 					break;
 				if (dp[i][ty] == 0)
 					bfs.add((i-1)*w+(ty-1));
 				dp[i][ty] = dp[tx][ty]+1;
 				
 			}
 			
 			for(int i = tx-1;i>=Math.max(tx-k,1);i--){
 				if (c[i][ty] == '@')
 					break;
 				if (dp[i][ty] != 0 && dp[tx][ty]+1 > dp[i][ty])
 					break;
 				if (dp[i][ty] == 0)
 					bfs.add((i-1)*w+(ty-1));
 				dp[i][ty] = dp[tx][ty]+1;
 
 			}
 			
 			for(int i = ty+1;i<=Math.min(ty+k,w);i++){
 				if (c[tx][i] == '@')
 					break;
 				if (dp[tx][i] != 0 && dp[tx][ty]+1 > dp[tx][i])
 					break;
 				if (dp[tx][i] == 0)
 					bfs.add((tx-1)*w+(i-1));
 				dp[tx][i] = dp[tx][ty]+1;
 				
 			}
 			
 			for(int i = ty-1;i>=Math.max(ty-k,1);i--){
 				if (c[tx][i] == '@')
 					break;
 				if (dp[tx][i] != 0 && dp[tx][ty]+1 > dp[tx][i])
 					break;
 				if (dp[tx][i] == 0)
 					bfs.add((tx-1)*w+(i-1));
 				dp[tx][i] = dp[tx][ty]+1;
 			}
 		}
 		out.println(dp[x2][y2]-1);
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}

Measured memory_bytes: 57540
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  
    
    int n;
    cin>>n;

    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int x=(n/i);
        ans+=((x*(x+1))/2)*i;
    }
    
    cout<<ans;

} 
    


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

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i = 0; i < M; i++)
    cin >> X[i];
  if (M <= N)
  {
    cout << 0 << endl;
    return 0;
  }
  sort(X.begin(), X.end());
  vector<int> dif(M - 1);
  for (int i = 0; i < M - 1; i++)
    dif[i] = X[i + 1] - X[i];
  sort(dif.begin(), dif.end());
  long long ans = 0;
  for (int i = 0; i < max(0, M - N); i++)
    ans += dif[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second

#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int main() {
    clue();
    return 0;
}
int clue() {

    string s;
    cin>>s;
    int n=s.size();
    lli sum=0;
    f1(i,n) {
        sum+=s[i]-'0';
    }
    (sum%9==0)?cout<<"Yes"<<endl:cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3740
N = int(input())
S = input()
w = S.count(".")
b = 0

ans = N
ans = min(ans, b+w)
for i in range(N):
    if(S[i] == "#"):
        b += 1
    else:
        w -= 1
    ans = min(ans, b+w)
print(ans)

Measured memory_bytes: 3500
N = int(input())
A = list(map(int, input().split()))

def selectionSort(A,N):
    cnt = 0
    
    for i in range(N-1):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            cnt += 1
        A[i], A[minj] = A[minj], A[i]
    print(*A)
    print(cnt)
    
selectionSort(A, N)

Measured memory_bytes: 7732
#include<bits/stdc++.h>
#define MAX_V 10001
#define f first
#define s second
#define mp make_pair
#define mod 1000000007
#define inf 1e8
using namespace std;
 
typedef long long ll;
 
int V,m;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
vector<pair<int,int> > vpp;
bool used[MAX_V]={};
int cmp[MAX_V];
ll dp[MAX_V];
vector<int> e[MAX_V];
  
void add_edge(int from, int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}
  
void dfs(int v){
  used[v] = true;
  for(int i = 0;i < G[v].size();i++){
    if(!used[G[v][i]])dfs(G[v][i]);
  }
  vs.push_back(v);
}
  
void rdfs(int v,int k){
  used[v] = true;
  cmp[v] = k;
  for(int i = 0;i < rG[v].size();i++){
    if(!used[rG[v][i]]) rdfs(rG[v][i],k);
  }
}
  
void scc(){
  memset(used,0,sizeof(used));
  vs.clear();
  for(int v = 0;v < V;v++){
    if(!used[v]) dfs(v);
  }
  memset(used,0,sizeof(used));
  int k = 0;
  for(int i = vs.size() - 1;i >= 0;i--){
    if(!used[vs[i]])rdfs(vs[i],k++);
  }
  return;
}
 
ll rec(int v,int cm){
  ll res=1;
  int tmp=cmp[v];
  if(tmp==cm)return 1;
  if(dp[tmp]!=inf)return dp[tmp];
  //  if(rG[v].size()==0)return dp[tmp]=2;
 
  for(int i=0;i<e[tmp].size();i++){
    int now=e[tmp][i];
    for(int j=0;j<rG[now].size();j++){
      int next=rG[now][j];
      res*=rec(next,tmp);
      res%=mod;
    }
  }
  return dp[tmp]=res+1;
}
 
int main()
{
  int a,b,q;
 
  cin>>V>>m;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;b--;
    add_edge(a,b);
  }
  
  scc();
 
  for(int i=0;i<V;i++){
    vpp.push_back(mp((-1)*cmp[i],i));
  }
  sort(vpp.begin(),vpp.end());
 
  for(int i=0;i<V;i++)vpp[i].f=(-1)*vpp[i].f;
 
  for(int i=0;i<vpp.size();i++)e[vpp[i].f].push_back(vpp[i].s);
 
  for(int i=0;i<V;i++)dp[i]=inf;
  ll ans=1;
  for(int i=0;i<vpp.size();i++){
    if(dp[vpp[i].f]==inf){
      ans*=rec(vpp[i].s,inf);
      ans%=mod;
    }
  }
 
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int k[200010], l[200010], r[200010];
void solve() {
	int n; cin >> n;
	int64_t ans = 0;
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>> pqL, pqR;
	for(int i = 0; i < n; ++i) {
		cin >> k[i] >> l[i] >> r[i];
		if(k[i] == n) {
			ans += l[i];
		} else if(l[i] == r[i]) {
			ans += l[i];
		} else if(l[i] < r[i]) {
			pqR.emplace(n - k[i], r[i], i);
		} else {
			pqL.emplace(k[i], l[i], i);
		}
	}
	priority_queue<tuple<int, int>> pq;
	for(int i = n; i >= 1; --i) {
		while(not pqL.empty()) {
			auto [a, c, idx] = pqL.top();
			if(a < i) break;
			pqL.pop();
			pq.emplace(c - r[idx], idx);
		}
		if(not pq.empty()) {
			auto [_, idx] = pq.top();
			pq.pop();
			ans += l[idx];
		}
	}
	while(not pq.empty()) {
		auto [_, idx] = pq.top();
		pq.pop();
		ans += r[idx];
	}
	for(int i = n - 1; i >= 0; --i) {
		while(not pqR.empty()) {
			auto [a, c, idx] = pqR.top();
			if(a <= i) break;
			pqR.pop();
			pq.emplace(c - l[idx], idx);
		}
		if(not pq.empty()) {
			auto [_, idx] = pq.top();
			pq.pop();
			ans += r[idx];
		}
	}
	while(not pq.empty()) {
		auto [_, idx] = pq.top();
		pq.pop();
		ans += l[idx];
	}
	cout << ans << '\n';
}

int main() {
	int t; cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 8220
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf =1 << 30;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int len, n;
vi objs;

const int L = 11;
int memo[1 << L][1 << L];

int rec(int used, int yes){
    int& ret = memo[used][yes];
    if(ret != -1) return ret;

    int cnt = 0;
    rep(i, n){
        if((objs[i] & used) == yes) cnt++;
    }
    if(cnt <= 1) return ret = 0;

    ret = inf;
    rep(i, len){
        if(used & (1 << i)) continue;

        int nused = used | (1 << i);
        chmin(ret, max(rec(nused, yes | (1 << i)), rec(nused, yes)));
    }

    ret++;
    return ret;
}

int main(void){
    for(; cin >> len >> n, len;){
        objs = vi(n);
        for(auto & e : objs){
            string in; cin >> in;
            rep(i, len){
                if(in[i] == '1'){
                    e |= (1 << i);
                }
            }
        }

        rep(i, 1 << len) rep(j, 1 << len) memo[i][j] = -1;
        cout << rec(0, 0) << endl;
    }

    return 0;
}

Measured memory_bytes: 19524
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val tt = listOfInt()
    val tSum = tt.sum()
    val m = nextInt()

    var ans = ""
    (1..m).forEach {
        val (p, x) = listOfInt()
        ans += "${tSum - tt[p-1] + x}\n"
    }

    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 36004
import fractions

n = int(input())
lst = list(map(int, input().split()))

ans = 0
left = [0]
right = [0] * (n+1)

for i in range(n):
  left.append(fractions.gcd(left[-1],lst[i]))
  right[n-1-i] = fractions.gcd(right[n-i],lst[n-1-i])

for i in range(n):
  x = fractions.gcd(left[i], right[i+1])
  if ans < x:
    ans = x
print(ans)

Measured memory_bytes: 16144
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int AllCost(int v, vector<int> & c) {
	int i, ans = 0;
	rep(i, c.size()) {
		if (v & (1 << i)) {
			ans += c[i];
		}
	}
	return ans;
}

int Judge(int k, int v, vector<vector<int>>& d) {
	int i, j;
	vector<int> s(d[0].size(), 0);
	rep(i, d.size()) {
		if (v & (1 << i)) {
			rep(j, d[i].size()) {
				s[j] += d[i][j];
			}
		}
	}
	rep(i, s.size()) {
		if (s[i] < k) {
			return false;
		}
	}
	return true;
}

int Search(int n, int k, int v, vector<int> &c, vector<vector<int>> & d) {
	if (n == c.size()) {
		if (Judge(k, v, d))
			return AllCost(v, c);
		else
			return INF;
	}
	int ans = Search(n + 1, k, v << 1, c, d);
	chmin(ans, Search(n + 1, k, (v << 1) + 1, c, d));
	return ans;
}


int main(void) {
	int num, i, j, m, k, ans;
	cin >> num >> m >> k;
	vector<int> c(num);
	vector<vector<int>> d(num, vector<int>(m));
	rep(i, num) {
		cin >> c[i];
		rep(j, m)
			cin >> d[i][j];
	}
	ans = Search(0, k, 0, c, d);
	if (ans == INF)
		printf("-1\n");
	else
		cout << ans << "\n";
	return 0;
}

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

using namespace std;
#define ld long double
const int Nmax = 50 + 5;
int a[Nmax], n;

ld nr;

int main()
{

    cin >> n;
    for(int i = 1; i <= n; ++i)cin >> a[i];

    sort(a +  1, a + n + 1);

    nr = a[1];
    for(int i = 2; i <= n; ++i)
        nr = (nr + a[i]) / 2.0;

    cout << nr;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B, C;
  cin>>A>>B>>C;
  if((A<C && C<B) || (B<C && C<A)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder text = new StringBuilder();
		while (true) {
			int numA = scan.nextInt();
			int numB = scan.nextInt();
			if (numA == 0 && numB == 0) {
				scan.close();
				text.deleteCharAt(text.lastIndexOf("\n"));
				System.out.println(text.toString());
				break;
			} else {
				if (numA <= numB)
					text.append(numA).append(" ").append(numB).append("\n");
				if (numA > numB)
					text.append(numB).append(" ").append(numA).append("\n");
			}
		}
	}

}

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	vector<string> s;
	
	int H, W;
	
	cin>>H>>W;
	
	s.resize(H);
	
	for(int i = 0; i < H; i++){
		cin>>s[i];
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			int con = 0;
			if(s[i][j] == '#') continue;
			for(int k = -1; k <= 1; k++){
				for(int l = -1; l <= 1; l++){
					if(!l &&!k) continue;
					if(i+k < 0 || i+k >= H || j+l < 0 || j+l >= W) continue;
					if(s[i+k][j+l] == '#') con++;
				}
			}
			s[i][j] = '0' + con;
		}
	}
	
	for(int i = 0; i < H; i++){
		cout<<s[i]<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = Console.ReadLine().Trim().Split(' ');
            int iK = int.Parse(sS[0]);

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

            // 解析
            int iOut = 1;
            for (int i = 0; i < iN; i++)
            {
                if (iOut * 2 < iOut + iK) { iOut *= 2; }
                else { iOut += iK; }
            }

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

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


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int left = a + b;
  int right = c + d;
  
  if(left > right)
    cout << "Left" << endl;
  else if(right > left)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
n=int(input())

sp=[]
for i in range(n):
    a=list(map(str,input().split()))
    a.append(i+1)
    sp.append(a)
    
sp=sorted(sp,key=lambda x:int(x[1]),reverse=True)
sp=sorted(sp,key=lambda x:x[0])

for i in range(len(sp)):
    print(sp[i][2])
    






Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define f first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010


int main(){
	IOS;
	ll k,x;cin>>k>>x;
	ll sum=k*500;
	if(sum>=x)cout<<"Yes";
	else cout<<"No";
	
	return 0;
}



Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
r = 10 ** 9 + 7
d = defaultdict(int)
for n in range(1, N+1):
    temp = n
    i = 2
    while i ** 2 <= temp:
        while temp % i == 0:
            d[i] += 1
            temp //= i
        i += 1
        if temp < i:
            break
    if temp != 1:
        d[temp] += 1
ans = 1
if d != {}:
    for v in d.values():
        ans = (ans * (v + 1)) % r
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
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; }

int main(){
    ll n;
    ll k;
    cin >> n>>k;
    vector<ll> a(n),b(n,1e9);
    rep(i,n){
        cin >> a[i];
    }
    ll des=1;
 
    if(k<1e6){
        rep(i,k){
            des=a[des-1];
        }
        cout << des << endl;
        return 0;
    }

    ll dev,offset;
    ll rest;
    for(ll i=0; i<=k; ++i){
        if(b[des-1]==1e9){
            b[des-1]=i;
        }
        else{
            dev= i-b[des-1];
            offset = b[des-1];
            rest = k-offset;
            break;
        }
        des=a[des-1];
    }
    int index;
    auto itr=find(b.begin(),b.end(),rest%dev+offset);
    index=distance(b.begin(),itr);
    
    cout << index+1 << endl;
    
    return 0;
}

Measured memory_bytes: 6424
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 32
#define P 32

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    struct ci
    {
      char  name[ 16 ];
      int   time[ 32 ];
      int   time_c;
      int   point;
    }   d[ N ];
    int p[ P ] = { 0 };
    int res;
    int n;

    scanf ( " %d", &n );
    if ( !( n ) ) break ;
    for ( i = 0; i < n; ++i )
    {
      scanf ( " %s %d", d[ i ].name, &d[ i ].time_c );
      for ( j = 0; j < d[ i ].time_c; ++j )
      {
        scanf ( " %d", d[ i ].time + j );
        ++p[ d[ i ].time[ j ] ];
      }
      d[ i ].point = 0;
    }

    for ( i = 0; i < n; ++i )
    for ( j = 0; j < d[ i ].time_c; ++j )
    {
      d[ i ].point += n - p[ d[ i ].time[ j ] ] + 1;
    }

    qsort ( d, n, sizeof ( struct ci )
          , (int (*)( const void *, const void * ))strcmp );
    for ( res = 0, i = 1; i < n; ++i )
    {
      if ( d[ i ].point < d[ res ].point )
      {
        res = i;
      }
    }

    printf ( "%d %s\n", d[ res ].point, d[ res ].name );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int k;
deque<int>ans;
deque<int> ng(deque<int>s)
{
	int p=s.size()-1;
	while(p>=0&&s[p]==9)
	{
		s[p]=0;
		--p;
	}
	if(p==-1) s.push_front(1);
	else ++s[p];
	while(1)
	{
		int b=-1;
		for(int i=0;i<s.size()-1;++i)
		 if(abs(s[i]-s[i+1])>1)
		 {
		 	b=i;
		 	break;
		 }
		if(b==-1) break;
		if(s[b]<s[b+1]) ++s[b];
		int c=max(s[b]-1,0);
		for(int i=b+1;i<s.size();++i)
		{
			s[i]=c;
			c=max(c-1,0);
		}
	}
	return s;
}
int main()
{
	cin>>k;
	for(int i=1;i<=k;++i)
	 ans=ng(ans);
	for(int i=0;i<ans.size();++i)
	 cout<<ans[i];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
char s[MAXN];
int a[3];
void Solve() {
    read(N);
    int ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
        scanf("%s",s + 1);
        int l = strlen(s + 1);
        for(int j = 1 ; j < l ; ++j) {
            if(s[j] == 'A' && s[j + 1] == 'B') ++ans;
        }
        if(s[1] == 'B' && s[l] == 'A') ++a[2];
        else if(s[1] == 'B') ++a[1];
        else if(s[l] == 'A') ++a[0];
    }
    int t = min(a[2],min(a[0],a[1]));
    ans += t * 2;
    a[2] -= t;a[0] -= t;a[1] -= t;
    ans += min(a[0],a[1]);
    if(a[2]) {
        if(t) ans += a[2];
        else if(max(a[0],a[1])) ans += a[2];
        else ans += a[2] - 1;
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

bool check(int a, int b) {
	return a > b;
}

int main() {
	llint a, b, c, k;
	cin >> a >> b >> c >> k;
	if (abs(a - b)) {

	}
	if (k % 2 == 0) {
		cout << a - b << endl;
	}
	else {
		cout << b - a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//author: dazhong_feliks

#include <bits/stdc++.h>
using namespace std;

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

   vector<int> vec(N);
   for(int i =0; i<N;i++){
   cin >> vec.at(i);
   }
  
   sort(vec.begin(), vec.end());
   reverse(vec.begin(), vec.end());

   int ansA = 0;
   int ansB = 0;

   for(int i = 0; i < N; i = i + 2){
     ansA += vec.at(i);
    }
    for(int i = 1; i < N; i = i + 2 ){
      ansB += vec.at(i);
    }
   cout << ansA - ansB << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n+1)
a.insert(0,0)
for i in range(1,n+1):
	ans[a[i]] += i
ans.pop(0)
ans = [str(ans[s]) for s in range(n)]
print(" ".join(ans))

Measured memory_bytes: 23724
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (int)(n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

#define int long long
const int N = 666;
const int inf = 1e18;
int n, a[N][N], sum[N][N];

inline void U(int &x, int y) { x = min(x, y); }

inline int calc(int u, int d, int l, int r) {
	return sum[d][r] - sum[u - 1][r] - sum[d][l - 1] + sum[u - 1][l - 1];
}

signed main(void) {
	read(n);
	rep (i, n) rep (j, n) if (i != j) read(a[i][j]);
	rep (i, n) rep (j, n) sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
	vector <vector <int> > dp(n + 1, vector <int> (n + 1, inf));
	dp[0][0] = 0;
	rep (i, n) {
		vector <vector <int> > new_dp(n + 1, vector <int> (n + 1, inf));
		re0 (p1, i) re0 (p2, i) if (dp[p1][p2] < inf) {
			int cost = calc(i, i, 1, p2) + calc(p1 + 1, i - 1, i, i);
			U(new_dp[p1][p2], dp[p1][p2] + cost);
			U(new_dp[i][p1], dp[p1][p2] + cost);
		}
		swap(dp, new_dp);
	}
	int ans = inf;
	re0 (p1, n + 1) re0 (p2, n + 1) U(ans, dp[p1][p2]);
	cout << ans << "\n";
}


Measured memory_bytes: 12232
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
	int A, B, C, D, E; cin >> A >> B >> C >> D >> E;
	int F; cin >> F;
	if(E - A <= F) cout << "Yay!\n";
	else cout << ":(\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;

import java.io.*;

public class Main {
	
	void solve(int N) {
		
		Random rand = new Random();
		rand.setSeed(System.nanoTime());
		
		final int MAX_STEP = 420;
		
		char[] as1 = "..##".toCharArray();
		char[] as2 = ".#.#".toCharArray();
		
		String s1 = "";
		String s2 = "";
		
		int[] order = {0, 1, 2, 3};
		int phase = 0;
		
		outer:
		for (int step = 0; step < MAX_STEP; step++){
			shuffle(order, rand);
			for (int i = 0; i < order.length; i++) { 
				String ns1, ns2;
				if (phase == 0) {
					ns1 = s1 + as1[order[i]];
					ns2 = s2 + as2[order[i]];
				} else {
					ns1 = as1[order[i]] + s1;
					ns2 = as2[order[i]] + s2;
				}
			
				System.out.println(ns1);
				System.out.println(ns2);
				System.out.flush();
			
				String response = sc.next();
				if (response.charAt(0) == 'T') {
					s1 = ns1;
					s2 = ns2;
					break;
				} else if (response.charAt(0) == 'F') {
					if (i + 1 == order.length) {
						phase++;
					}
				} else {
					break outer;
				}
			}
		}
		
	}
	

	void shuffle(int[] a, Random random) {
		int n = a.length;
		for (int i = 0; i < n; i++) {
			int j = i + random.nextInt(n - i);
			int t = a[i];
			a[i] = a[j];
			a[j] = t;
		}
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	Scanner sc = null;
	public void run() throws Exception {
		sc = new Scanner(System.in);
		int N = sc.nextInt();
		solve(N);
		System.out.flush();
	}
}

Measured memory_bytes: 12960
#include <stdio.h>
#include <string.h>
//
//ツテツスツトツサツブツミツッツシツδδ督づ崢づヲ
//
//
 
double max(double a, double b)
{
    if (a > b){
        return (a);
    }
    return (b);
}
 
int main(void)
{
    int i, j, k;
    int n, m;
    double gr[100][100];
    double dp[100][100];
    double ans;
    int upd;
    
    while (1){
        scanf("%d%d", &n, &m);
        
        if (n + m == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++){
                scanf("%lf", &gr[i][j]);
            }
        }
        
        memset(dp, 0, sizeof(dp));
        for (i = 0; i < n; i++){
            dp[0][i] = 1;
        }
        
        ans = 0.00;
        for (i = 1; i < m; i++){
            for (j = 0; j < n; j++){
                upd = 0;
                for (k = 0; k < n; k++){
                    if (upd == 0){
                        dp[i][j] = dp[i - 1][k] * gr[k][j];
                        upd = 1;
                    }
                    else {
                        dp[i][j] = max(dp[i][j], dp[i - 1][k] * gr[k][j]);
                    }
                }
            }
        }
        
        for (i = 0; i < n; i++){
            ans = max(ans, dp[m - 1][i]);
        }
        
        printf("%.2lf\n", ans);
        
    }
    
    return (0);
}
 

Measured memory_bytes: 0
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
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;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

int n,m,a[1100], b[1100];bool c[1100][20]={};
int dp[10000],t[20];
signed main(){
  cin>>n>>m;
  rep(i,10000)dp[i] = INF;
  rep(i,20)t[i] = INF;
  dp[0] = 0;
  rep(i,m){
    cin>>a[i]>>b[i];
    rep(j,b[i]){
      int cc;cin>>cc;cc--;
      c[i][cc] = true;
      //chmin(t[i], a[i]);
    }
  }
  rep(bit,1<<n){
    rep(i,m){
      int bb = bit;
      rep(j,n){
        if(c[i][j]){
          bb |= (1<<j);
        }
      }
      chmin(dp[bb], dp[bit] + a[i]);
    }
  }
  cout << (dp[(1<<n)-1] == INF ? -1 : dp[(1<<n)-1]) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a[5];
    for(int i=0;i<5;++i)cin>>a[i];
    sort(a,a+5);
    reverse(a,a+5);
    for(int i=0;i<5;++i){
        if(i!=4)cout<<a[i]<<" ";
        else cout<<a[i]<<endl;
    }
}

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

int main() {
  int N; cin>>N;
  int count = 0;
  bool isSame = false;
  vector<vector<int>> dice(N,vector<int>(2));
  for(int i=0; i<N; ++i) {
    cin>>dice[i][0]>>dice[i][1];
    if(dice[i][0]==dice[i][1]) count++;
    else count=0;
    if(count >= 3) isSame = true;
  }
  if(isSame) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3628
import sys

indata = sys.stdin.read().strip().splitlines()[1]
numbers = list(map(int, indata.split(" ")))
ans = 0
for i in range(1, len(numbers)):
  p = i - 1
  n = i + 1
  if n >= len(numbers):
    break
  if numbers[p] < numbers[i] < numbers[n] or\
     numbers[n] < numbers[i] < numbers[p]:
    ans += 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=3005;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN],e[MAXN],f[MAXN],x[MAXN],y[MAXN];
bool dw[MAXN][MAXN],lef[MAXN][MAXN],vis[MAXN][MAXN];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int cntx=0,cnty=0;
    x[++cntx]=0,y[++cnty]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        x[++cntx]=a[i],x[++cntx]=b[i],y[++cnty]=c[i];
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&d[i],&e[i],&f[i]);
        x[++cntx]=d[i],y[++cnty]=e[i],y[++cnty]=f[i];
    }

    /// pre-process
    sort(x+1,x+cntx+1);
    cntx=unique(x+1,x+cntx+1)-(x+1);
    sort(y+1,y+cnty+1);
    cnty=unique(y+1,y+cnty+1)-(y+1);
//    printf("%d %d\n",cntx,cnty);
//    for(int i=1;i<=cntx;i++)
//        printf("%d ",x[i]);
//    printf("\n");
//    for(int i=1;i<=cnty;i++)
//        printf("%d ",y[i]);
//    printf("\n");
    for(int i=1;i<=n;i++)
    {
        a[i]=lower_bound(x+1,x+cntx+1,a[i])-x;
        b[i]=lower_bound(x+1,x+cntx+1,b[i])-x;
        c[i]=lower_bound(y+1,y+cnty+1,c[i])-y;
        for(int j=a[i];j<b[i];j++)
            dw[j][c[i]]=1;
    }
    for(int i=1;i<=m;i++)
    {
        d[i]=lower_bound(x+1,x+cntx+1,d[i])-x;
        e[i]=lower_bound(y+1,y+cnty+1,e[i])-y;
        f[i]=lower_bound(y+1,y+cnty+1,f[i])-y;
        for(int j=e[i];j<f[i];j++)
            lef[d[i]][j]=1;
    }

    /// bfs
    int sx=lower_bound(x+1,x+cntx+1,0)-x;
    int sy=lower_bound(y+1,y+cnty+1,0)-y;
    queue<pair<int,int>>q;
    q.push({sx,sy});
    while(!q.empty())
    {
        int nx,ny;
        tie(nx,ny)=q.front();
        q.pop();
        if(vis[nx][ny])continue;
//        printf("%d %d\n",nx,ny);
        vis[nx][ny]=1;
        /// dw
        if(ny>0 && !dw[nx][ny])
            q.push({nx,ny-1});
        /// lef
        if(nx>0 && !lef[nx][ny])
            q.push({nx-1,ny});
        /// up
        if(ny<cnty && !dw[nx][ny+1])
            q.push({nx,ny+1});
        /// rig
        if(nx<cntx && !lef[nx+1][ny])
            q.push({nx+1,ny});
    }

    /// cal answer
    ll res=0;
    for(int i=0;i<=cntx;i++)
        for(int j=0;j<=cnty;j++)if(vis[i][j])
        {
            if(i==0 || i==cntx || j==0 || j==cnty)
                return 0*printf("INF\n");
            res+=1LL*(x[i+1]-x[i])*(y[j+1]-y[j]);
        }
    return 0*printf("%lld\n",res);
}
/*
2 2
-1 1 -1
-1 1 1
-1 -1 1
1 -1 1
*/


Measured memory_bytes: 26876
def divisible(n) :
    divisors = []
    for i in range(1, int(n ** 0.5) + 1) :
        if n % i == 0 :
            divisors.append(i)
            if i != n // i :
                divisors.append(n // i)
    divisors.sort(reverse=True)
    return divisors

N, K = map(int,input().split())
xs = list(map(int,input().split()))
divs = divisible(sum(xs))

for div in divs :
    test = [x % div for x in xs]
    test.sort()
    sum_test = sum(test)
    change = sum(test[:-sum_test//div])
    if change <= K :
        ans = div
        break
print(ans)



Measured memory_bytes: 3064
#include<iostream>
using namespace std;
// 入力例
// 6
// 5 6 4 2 1 3

void selectionSort(int A[],int N){
    int min,minj,i,j,count;
    count = 0;
    
    for(i=0; i<N-1;i++){
        min = A[i];
        minj = i;
        
        for(j=i;j<N;j++){
            if(A[j]<min) {
                min=A[j];
                minj=j;
            }
        }
        if(i!=minj) {
            swap(A[i],A[minj]);
            count++;
            
        }
    }
    for(i=0;i<N;i++) {
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout <<endl;
    cout << count << endl;
}


  
int main(){
    int N,A[100];
    cin >> N;
    
    for(int i=0; i < N ;i++) cin >> A[i];
    // cout << A[5];
    selectionSort(A,N);

    return 0;

}


Measured memory_bytes: 3100
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");

    int count = 0;
    int a = Integer.parseInt(str2[0]);
    int b = Integer.parseInt(str2[1]);
    int c = Integer.parseInt(str2[2]);
    int d;
    for (int i = a; i <= b; i++){
      d = c % i;
      if (d == 0){count++;}
    }
    System.out.println(count);
  }
}

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

#define INF 1E18



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

    int cnt = 1;
    rep(i,n){
        if(a[i]%2==0) cnt *= 2;
        else cnt *= 1;
    }

    cout << pow(3,n) - cnt <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>

using namespace std;

int main() {
  int n;
  int64_t sum = 0;
  vector<int> a;

  cin >> n;
  for (int i=0; i < n; i++) {
    int tall;
    cin >> tall;
    a.push_back(tall);
  }

  for (int i=1; i < n; i++) {
    if ( a[i-1] > a[i] ) {
      sum += a[i-1] - a[i];
      a[i] = a[i-1];
    }
  }
  cout << sum << "\n";
}

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

public class Main {

	public static void main(String[] args) {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String str;
		try {
			str = input.readLine();
			
			System.out.println(str.toUpperCase());

		} catch (IOException e) {
			// TODO ????????????????????? catch ????????????
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 24388
/*
  ->->->->->-> Vora Mahammadasim <-<-<-<-<-<-
*/
#include<bits/stdc++.h>
#include<stdio.h>
#define int long long
#define pb emplace_back
#define Mod 1000000007
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    set<string>s;
    while(n--){
        string p;
        cin>>p;
        s.insert(p);
    }
    cout<<s.size()<<'\n';
}


Measured memory_bytes: 19232
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    ll sum = 0;
    for (ll i = 1; i <= 999;i++){
        sum += i;
        if(i==b-a){
            cout << sum - b << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N] = string_to_int(inputs[0])
    i = N
    while 1:
        i_str = str(i)
        prev = i_str[0]
        is_ok = True
        for c in i_str:
            if c != prev:
                is_ok = False
                break
        if is_ok:
            return i
        i += 1


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


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

using namespace std;
const int nmax = 106;
char str[nmax];
set<char> s;
set<char> s2;
int main() {
//    freopen("in.txt","r",stdin);
    int len;
    scanf("%d",&len);
    scanf("%s",str+1);
    int ans = 0;
    for(int i = 1;i<=len-1;++i){
        int temp = 0;
        s.clear(); s2.clear();
        for(int j = 1;j<i+1;++j){
            if(s.count(str[j]) == 0){
                s.insert(str[j]);
            }
        }
        for(int j = i+1;j<=len;++j){
            if(s.count(str[j]) && s2.count(str[j]) == 0){
                temp++;
                s2.insert(str[j]);
            }

        }
        ans = max(ans,temp);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int solve[100005];
int main()
{
    long long int n,m,i,x,counter1=0,counter2=0; string WA="WA",AC="AC",s;
    cin>>n>>m;
    long long int p[n+1];
    for(i=0;i<m;i++)
    {
        cin>>x;
        cin>>s;
        if(s==WA)
        {
            if(p[x]!=2)
                solve[x]++;
        }
        else if(s==AC)
        {
            if(p[x]!=2)
            {
                counter1++;
                counter2+=solve[x];
            }
            p[x]=2;
        }
    }
    cout<<counter1<<" "<<counter2<<endl;
    return 0;
}

Measured memory_bytes: 1664
def main(N, X):
    def calc_cost(p):
        return sum((x-p)**2 for x in X)

    return min(map(calc_cost, range(max(X) + 1)))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Node[] nodes = input();
		StringBuilder stringBuilder = new StringBuilder();
		for (Node node : nodes) {
			stringBuilder.append("node " + node.getId());
			stringBuilder.append(": parent = " + node.getParent().getId());
			stringBuilder.append(", depth = " + node.getDepth());
			stringBuilder.append(", " + node.getType());
			stringBuilder.append(", [");
			for (int j = 0; j < node.getChildren().size(); j++) {
				if (j != 0) {
					stringBuilder.append(", ");
				}
				stringBuilder.append(node.getChildren().get(j).getId());
			}
			stringBuilder.append("]\n");
		}
		System.out.print(stringBuilder);
		
	}
	
	public static Node[] input() throws NumberFormatException, IOException {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		int num = Integer.parseInt(bufferedReader.readLine());
		Node[] nodes = new Node[num];
		for (int i = 0; i < num; i++) {
			nodes[i] = new Node(i);
		}
		for (int i = 0; i < num; i++) {
			String[] elements = bufferedReader.readLine().split(" ");
			int id = Integer.parseInt(elements[0]);
			int nextNum = Integer.parseInt(elements[1]);
			nodes[id].setId(id);
			List<Node> children = new ArrayList<>();
			for (int j = 0; j < nextNum; j++) {
				int element = Integer.parseInt(elements[j + 2]);
				children.add(nodes[element]);
				nodes[element].setParent(nodes[id]);
			}
			nodes[id].setChildren(children);
		}
		return nodes;
	}
}

class Node {
	/** ??????????????§??? */
	private int id = -1;
	/** ????????????????????§??? */
	private Node parent;
	/** ?????????????????????????????§??? */
	private List<Node> children = new ArrayList<>();
	public Node(int id) {
		this.id = id;
		if (id != -1) {
			parent = new Node(-1);
		}
	}
	
	public int getDepth() {
		if (id == -1 || parent.getId() == -1) {
			return 0;
		} else {
			return parent.getDepth() + 1;
		}
	}
	
	public String getType() {
		if (parent.getId() == -1) {
			return "root";
		} else if (children.isEmpty()) {
			return "leaf";
		} else {
			return "internal node";
		}
	}

	/**
	 * ????????????????????????
	 * @return id
	 */
	public int getId() {
		return id;
	}

	/**
	 * ???????????????????????????
	 * @param id ??????????????? id
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * ?????????????????????
	 * @return parent
	 */
	public Node getParent() {
		return parent;
	}

	/**
	 * ????????????????????????
	 * @param parent ??????????????? parent
	 */
	public void setParent(Node parent) {
		this.parent = parent;
	}

	/**
	 * ??????????????????????????????
	 * @return children
	 */
	public List<Node> getChildren() {
		return children;
	}

	/**
	 * ????????????????????????
	 * @param children ??????????????? children
	 */
	public void setChildren(List<Node> children) {
		this.children = children;
	}

}

Measured memory_bytes: 116200