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

vector<int> to[200005];
vector<int> ans;

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

int main() {
    int n, q;
    cin >> n >> q;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define INF 20160307
#define MAX_N 60
#define MAX_C 26
#define MAX_D 7

char T[MAX_C + 2] = ".ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int x[MAX_N][MAX_N];
int wa[MAX_D][MAX_N][MAX_N];
int genkai[MAX_C + 1][2][2], aru[MAX_C + 1], g[MAX_C + 1][2][2];
int H, W, N; char c; vector<int>aru2;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int i = 0; i < MAX_D; i++) {
			for (int j = 0; j < MAX_N; j++) {
				for (int k = 0; k < MAX_N; k++) {
					x[j][k] = 0;
					wa[i][j][k] = 0;
				}
			}
		}
		for (int i = 0; i <= MAX_C; i++) {
			aru[i] = 0;
			for (int j = 0; j < 2; j++) {
				genkai[i][j][0] = INF;
				genkai[i][j][1] = -INF;
				g[i][j][0] = INF;
				g[i][j][1] = -INF;
			}
		}
		cin >> H >> W;
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				cin >> c;
				for (int k = 0; k < MAX_C + 1; k++) {
					if (T[k] == c) {
						x[i][j] = k;
						if (k != 0) {
							genkai[k][0][0] = min(genkai[k][0][0], i);
							genkai[k][0][1] = max(genkai[k][0][1], i);
							genkai[k][1][0] = min(genkai[k][1][0], j);
							genkai[k][1][1] = max(genkai[k][1][1], j);
							aru[k] = 1;
						}
					}
				}
			}
		}
		aru2.clear();
		for (int i = 1; i <= MAX_C; i++) {
			if (aru[i] == 1) {
				aru2.push_back(i);
				g[aru2.size() - 1][0][0] = genkai[i][0][0];
				g[aru2.size() - 1][0][1] = genkai[i][0][1];
				g[aru2.size() - 1][1][0] = genkai[i][1][0];
				g[aru2.size() - 1][1][1] = genkai[i][1][1];
			}
		}
		int cnt = aru2.size();
		for (int i = 0; i < aru2.size(); i++) {
			for (int j = 1; j <= H; j++) {
				for (int k = 1; k <= W; k++) {
					if (x[j][k] == aru2[i]) {
						wa[i][j][k] = 1;
					}
				}
			}
			for (int j = 1; j <= H; j++) {
				for (int k = 1; k <= W; k++) {
					wa[i][j][k] += wa[i][j][k - 1];
				}
			}
			for (int j = 1; j <= W; j++) {
				for (int k = 1; k <= H; k++) {
					wa[i][k][j] += wa[i][k - 1][j];
				}
			}
		}
		vector<int>a1(cnt, 0);
		for (int i = 0; i < cnt; i++) {
			a1[i] = i;
		}
		int X1, Y1, X2, Y2, menseki, cnt2, wa2;
		do {
			for (int i = 0; i < cnt; i++) {
				X1 = g[a1[i]][0][0], X2 = g[a1[i]][0][1];
				Y1 = g[a1[i]][1][0], Y2 = g[a1[i]][1][1];
				menseki = (X2 - X1 + 1)*(Y2 - Y1 + 1);
				cnt2 = 0;
				for (int j = 0; j <= i; j++) {
					wa2 = wa[a1[j]][X1 - 1][Y1 - 1] + wa[a1[j]][X2][Y2] - wa[a1[j]][X1 - 1][Y2] - wa[a1[j]][X2][Y1 - 1];
					cnt2 += wa2;
				}
				if (menseki != cnt2) {
					goto E;
				}
			}
			cout << "SAFE" << endl;
			goto owata;
		E:;
		} while (next_permutation(a1.begin(), a1.end()));
		cout << "SUSPICIOUS" << endl;
	owata:;
	}
	return 0;
}

Measured memory_bytes: 1324
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

ll min(ll a, ll b) { return a < b ? a : b;}
ll max(ll a, ll b) { return a > b ? a : b;}

int main(void) {
  ll i, j, k, l, n, x, y, ans = 10e18;
  scanf("%lld%lld", &n, &k);
  vector<pii> vec;
  for(i = 0; i < n; ++i) {
    scanf("%lld%lld", &x, &y);
    vec.push_back(make_pair(x, y));
  }
  sort(vec.begin(), vec.end());
  for(i = 0; i < n; ++i) for(j = k + i - 1; j < n; ++j) {
    vector<ll> t;
    ll u = max(vec[i].second, vec[j].second), d = min(vec[i].second, vec[j].second);
    for(l = i + 1; l < j; ++l) t.push_back(vec[l].second);
    sort(t.begin(), t.end());
    ll p = 10e18;
    if(k > 2) for(l = 0; l < j - i - k + 2; ++l) p = min(p, max(u, t[l + k - 3]) - min(d, t[l]));
    if(k == 2) p = u - d;
    ans = min(ans, p * (vec[j].first - vec[i].first));
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
n = input()
a = list(map(int, input().split()))
ans = 0

while(True):
    t = True
    for i in a:
        if i%2:
            t = False
    if t:
            ans += 1
            a = [int(x/2) for x in a]
    else:
        break
print(str(ans))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define all(x) (x).begin(),(x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define pob pop_back
#define sw swap
using LL = long long;
using ULL = unsigned long long;
#define FOR(i, m, n) for(int i = m;i < n;i++)
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,c;
     cin >> N;
     vector<int>Mochi(N);
     rep(i,N){
         cin >> Mochi[i];
     }
     
      SORT(Mochi);
      rep(i,N){
      if (Mochi[i]<Mochi[i+1]){
      c++;
      }
    }
  cout << c+1; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define    For(i,n) for(int i=0;i<n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    nl     "\n"
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int

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

    //test
    {
        ll a,b,c,x,y,z;
        cin>>a>>b>>c;
        a=abs(a);
        if(a>=c)
        
        {
            a=a-c; b--;
            x=a/c;
            if(a%c!=0)x++;
            if(x<=b)

            {
                a=a-(x*c);b-=x;
                if(b%2==1)a+=c;
                cout<<abs(a);
            }
            else if(x>b)
            {
                a=a-(b*c);
                cout<<a;
            }
        }

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


Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	ans := (a + b) / 2

	if (a+b) %2 != 0 {
		_, _ = fmt.Fprint(writer, "IMPOSSIBLE")
	} else {
		_, _ = fmt.Fprintf(writer, "%d", ans)
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N=2e5+5;
int n,k,x[N];
double sum=0,ans;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=0;i<k;i++)
	{
		sum+=(double)(x[i]+1)/2;
	}
	ans=sum;
	for(int i=k;i<n;i++)
	{
		sum-=(double)(x[i-k]+1)/2;
		sum+=(double)(x[i]+1)/2;
//		cout<<sum<<endl;
		ans=max(ans,sum);
	}
	printf("%.2f\n",ans);
	return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define f(i,a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ld float
#define fd(i,a, b) for (ll i = a; i >= b; i--)

 /*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll on=n*(n-1);
    ll tw=m*(m-1);
    cout<<(on+tw)/2<<endl;


}


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        char[] d = S.toCharArray();
        for (int i = 0; i < d.length; i++) {
            if (d[i] == '7') {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 35692
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

#define EPS 1e-6

using namespace std;

int main(){

   int n,a;
   while(true){


   cin >> n;
   if(n==0) break;

   vector<int>v;
   int s=0;
   v.push_back(s);

   rep(i,n){
   cin >> a;
   s+=a;
   v.push_back(s);
   }

   int m=-1000000;
   REP(i,1,n)
   REP(j,0,i-1)
   if(v[i]-v[j]>m) m=v[i]-v[j];

   cout << m << endl;

   v.clear();

   }

	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int tmpmin=1e9;
int main(int argc,char const* argv[])
{
  string s;
  int ssize;
  cin >> s;
  ssize=s.size();
  int minic=0;
  if(s[0]=='A')
    {
      bool exC=false;
      for(int i=2;i<ssize-1;i++)
	{
	  if(s[i]=='C' && exC==false)
	    {
	      exC=true;
	    }
	  else if(s[i]=='C' && exC==true)
	    {
	      cout << "WA" << endl;
	      return 0;
	    }
	}
      if(!exC)
	{
	  cout << "WA" << endl;
	  return 0;
	}
      for(int i=0;i<ssize;i++)
	{
	  if(int(s[i]-'a')>=0)
	    {
	      minic++;
	    }
	}
      if(minic!=(ssize-2))
	{
	  cout << "WA" << endl;
	  return 0;
	}
      else
	{
	  cout << "AC" << endl;
	  return 0;
	} 
    }
  else
    {
      cout << "WA" << endl;
      return 0;
    }
  return 0;
}


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

int main() {
	vector<int> A(3);
	for (int i = 0; i < 3; i++) cin >> A[i];
	int cost = 0;
	int M = 0;
	
	vector<int> B(3);
	B[0] = abs(A[0] - A[1]);
	B[1] = abs(A[1] - A[2]);
	B[2] = abs(A[0] - A[2]);

	for (int i = 0; i < 3; i++) {
		M = max(B[i], M);
		cost += B[i];
	}
	cout << cost - M << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
inline int xmod(int a, int b) {
    return (a >= 0) ? a%b : a%b + b;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;

    int len=1000050;
    int* li = new int[len];
    int fi=0, la=0;

    string op;
    int key;
    for (int i=0; i<n; ++i) {
        cin >> op;
        if (op == "insert") {
            cin >> key;
            fi = xmod(fi-1, len);
            li[fi] = key;
        } else if (op == "deleteFirst") {
            while (li[fi] == -1) fi = (fi+1) % len;
            fi = (fi+1) % len;
        } else if (op == "deleteLast") {
            while (li[xmod(la-1, len)] == -1) la = xmod(la-1, len);
            la = xmod(la-1, len);
        } else {
            cin >> key;
            for (int j=fi; j!=la; j=(j+1)%len) {
                if (li[j] == key) {
                    li[j] = -1;
                    break;
                }
            }
        }
    }

    bool nospace = true;
    for (int i=fi; i!=la; i=(i+1)%len) {
        if (li[i] == -1) continue;
        if (nospace) {
            cout << li[i];
            nospace = false;
        } else {
            cout << " " << li[i];
        }
    }
    cout << endl;

    delete[] li;
    return 0;
}

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

int main(){
    int n,i;
    string ver;
    int list[4]={0,0,0,0};
    cin>>n;
    for (i=0;i<n;i++){
        cin>>ver;
        if (ver=="AC"){
            list[0]++;
        }
        if (ver=="WA"){
            list[1]++;
        }
        if (ver=="TLE"){
            list[2]++;
        }
        if (ver=="RE"){
            list[3]++;
        }
    }
    cout<<"AC"<<" x "<<list[0]<<endl;
    cout<<"WA"<<" x "<<list[1]<<endl;
    cout<<"TLE"<<" x "<<list[2]<<endl;
    cout<<"RE"<<" x "<<list[3]<<endl;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int m[2][100];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < 2; i++)for (int j = 0; j < num; j++)scanf("%d", &m[i][j]);
	int maxi = 0;
	for (int i = 0; i < num; i++)
	{
		int t = 0;
		for (int j = 0; j <= i; j++)t += m[0][j];
		for (int j = i; j < num; j++)t += m[1][j];
		maxi = max(maxi, t);
	}
	printf("%d\n", maxi);
}

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

template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		ModInt ret{this->integer_}, pow_ope{operand.integer_};
		for (int64_t pow_mod{mod_ - 2}; pow_mod > 0; pow_mod >>= 1)
		{
			if (pow_mod & 1)
				ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }
};

////////////////
// 組み合わせ //
///////////////

template<int64_t mod_ = 1'000'000'007, int max_ = 200'000>
class Combination {
public:
	std::array<ModInt<mod_>, max_ + 1> inv, fact, finv;

	constexpr Combination()
	{
		inv[0] = inv[1] = fact[0] = fact[1] = finv[0] = finv[1] = 1;
		for (int num{2}; num <= max_; num++)
		{
			inv[num] = (mod_ - (int64_t)inv[mod_ % num] * (mod_ / num) % mod_) % mod_;
			fact[num] = num * fact[num - 1] % mod_;
			finv[num] = inv[num] * finv[num - 1] % mod_;
		}
	}

	constexpr ModInt<mod_> getCombi(const int n, const int r)
	{
		if (r < 0 || n < 0 || n - r < 0) return 0;
		return fact[n] * finv[r] * finv[n - r];
	}

	constexpr ModInt<mod_> getPerm(const int n, const int r)
	{
		if (r < 0 || n < 0 || n - r < 0) return 0;
		return fact[n] * finv[n - r];
	}
};
Combination<> combi;

template<typename T>
T pow(T a, int64_t b)
{
	T ret(1);
	while (b)
	{
		if (b & 1) ret *= a;
		b >>= 1;
		a *= a;
	}
	// printf("%lld\n", (int64_t)ret);
	return ret;
}

int main()
{
	int64_t n, a, b, c;
	scanf("%lld%lld%lld%lld", &n, &a, &b, &c);
	ModInt<> N(n), A(a), B(b), C(c), ans(0);
	A /= 100ll;
	B /= 100ll;
	C /= 100ll;

	for (int64_t i{n}; i <= 2 * n - 1; i++)
	{
		ans += combi.getCombi(i - 1, n - 1) * (pow(A / (A + B), n) * pow(B / (A + B), i - n) + pow(B / (A + B), n) * pow(A / (A + B), i - n)) * ModInt<>(i) / (A + B);
	}
	printf("%lld\n", (int64_t)ans);

	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
int main(void){
    // Your code here!
    int d , t, s;
    scanf("%d %d %d",&d,&t,&s);
    if (d <=s*t) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

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

int main()
{
    ll r;
    cin >> r;
    print(r*r);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char**argv){
    vector<int> a;

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

    int k;
    cin >> k;

    bool ans = false;
    for (int i = 0; i < 5; i++){
        for (int j = 0; j < 5; j++){
            if (a[i] - a[j] > k) ans = true;
        }
    }

    if (ans) cout << ":(" << endl;
    else cout << "Yay!" << endl;

    return 0;
}
















Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    private static int[] calcPrimes(int n) {
        boolean[] table = new boolean[n + 1];
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (!table[i]) {
                for (int j = i + i; j <= n; j += i) {
                    table[j] = true;
                }
            }
        }
        int counter = 0;
        for (int i = 2; i <= n; i++) {
            if (!table[i]) {
                counter++;
            }
        }
        int[] result = new int[counter];
        int index = 0;
        for (int i = 2; i <= n; i++) {
            if (!table[i]) {
                result[index++] = i;
            }
        }
        return result;
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        int[] primes = calcPrimes(50000 + 1000);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int minimum = 0;
            int maximum = 0;
            for (int i = 0; i < primes.length ; i++) {
                if (primes[i] > n) {
                    minimum = primes[i];
                    break;
                }
            }
            for (int i = primes.length - 1; i >= 0 ; i--) {
                if (primes[i] < n) {
                    maximum = primes[i];
                    break;
                }
            }
            System.out.println(String.format("%d %d", maximum, minimum));
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main() {
	int n; cin >> n;
	int ans = 0;
	while (ans * (ans + 1) / 2 < n) ans++;
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#define MOD 924844033
int dp[2005][2005][2];
int main()
{
	// freopen("AGC005-D.in", "r", stdin);
	int n, k;
	scanf("%d%d", &n, &k);
	dp[0][0][0] = 1;
	int cur = 0;
	for (int i = 0; i < k << 1; i++)
	{
		for (int j = i; j < n; j += k << 1)
		{
			int nxt = cur ^ 1;
			memset(dp[nxt], 0, sizeof(dp[nxt]));
			dp[nxt][0][0] = 1;
			for (int x = 1; x <= n; x++)
			{
				dp[nxt][x][0] = (dp[cur][x][0] + dp[cur][x][1]) % MOD;
				if (j >= k)
					(dp[nxt][x][0] += dp[cur][x - 1][0]) %= MOD;
				if (j + 2 * k < n)
				{
					(dp[nxt][x][1] += dp[cur][x - 1][0]) %= MOD;
					(dp[nxt][x][1] += dp[cur][x - 1][1]) %= MOD;
				}
				else if (j + k < n)
				{
					(dp[nxt][x][0] += dp[cur][x - 1][0]) %= MOD;
					(dp[nxt][x][0] += dp[cur][x - 1][1]) %= MOD;
				}
			}
			cur ^= 1;
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)
	{
		int prod = dp[cur][i][0];
		for (int j = 1; j <= n - i; j++)
			prod = (long long)prod * j % MOD;
		(ans += (i & 1 ? -1 : 1) * prod) %= MOD;
	}
	printf("%d\n", (ans + MOD) % MOD);
	return 0;
}


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

#define ll long long

int main(){
  ll n,k,ans=0;
  cin>>k>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
    cin>>a[i];
  ll min=0;
  for(ll i=0;i<n;i++){
    ll v=0;
    if(i<n-1){
      v=a[i+1]-a[i];
      ans+=v;
    }
    else{
      v=k-a[i]+a[0];
      ans+=v;
    }
    if(min<v)
      min=v;
  }
  cout<<ans-min;
  return 0;
}


Measured memory_bytes: 5188
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <memory>        // unique_ptr, shared_ptr, weak_ptr
#include <cstring>
#include <cmath>

using namespace std;

using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;

#define _LIBCPP_DEBUG 0
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
	long long Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;

	S = min(S, min(H*2, Q*4));
	if (N == 1) cout << S << endl;
	else {
		if (D >= 2*S) cout << N*S << endl;
		else {
			if (N % 2 == 0) cout << N/2*D << endl; 
			else cout << N/2*D+S << endl;
		}
	}

	return 0;
}


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

int main(void)
{
    string S;
    cin >> S;

    vector<char> v;
    
    for(int i = 0; i < S.length(); i++)
    {
        if(S[i] == '0')
            v.push_back('0');
        else if(S[i] == '1')
            v.push_back('1');
        else if(S[i] == 'B')
        {
            if(v.size() > 0)
                v.pop_back();
        }
    }
    for(auto vi : v)
        cout << vi;
    cout << endl;

    return 0;
}

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

int main() {
  int N, M, a, b;
  cin >> N >> M;
  
  vector<int> vec(N);
  //for (int i = 0; i < N; i++) vec.at(i) = i;
  
  for (int i = 0; i < M; i++) {
  cin >> a >> b;
  vec.at(a - 1)++;
  vec.at(b - 1)++;
  }
  for (int i = 0; i < N; i++) cout << vec.at(i) << endl;  
}

Measured memory_bytes: 3636
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
ans_0 = 0
ans_n = 0
for i in range(len(a)):
  if x > a[i]:
    ans_0 += 1
  else:
    ans_n += 1
print(min(ans_0,ans_n))


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main(int argc, const char * argv[]) {
    int n, taro=0 ,hana=0;
    char t[101], h[101];
    
    scanf("%d", &n);
    
    for (int i=0; i<n; i++) {
        scanf("%s %s", t, h);
        //printf("%s %s\n", t, h);
        if (strcmp(t,h) == 0) {
            taro++;
            hana++;
        }else if (strcmp(t,h) > 0){
            taro+=3;
        }else if (strcmp(t,h) < 0){
            hana+=3;
        }
    }
    printf("%d %d\n", taro, hana);
    
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1000000000000;
string alp="abcdefghijklmnopqrstuvwxyz";

ll digitsum(ll n,ll b){
    if (n<b){
        return n;
    }
    return digitsum(n/b,b)+n%b;
}

int main(){
    ll n,s;
    cin >> n >> s;
    ll m=sqrt(n);
    ll ans=INF;
    for (ll i=2;i<=m;i++){
        if (digitsum(n,i)==s){
            ans=i;
            break;
        }
    }
    if (ans==INF){
        for (ll i=m;i>0;i--){
            ll x=n-s+i;
            if (x%i==0&&x/i>s-i&&s-i>=0&&x/i!=1&&i<x&&x/i>m&&x>0){
                ans=min(ans,x/i);
            }
        }
    }
    if (ans==INF){
        if (n==s){
            ans=n+1;
        }
    }
    if (ans!=INF){
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    S = int(input())
    nums = list(map(int, input().split()))
    nums.sort()

    print(nums[int(S/2)] - nums[int(S/2 - 1)])


if __name__ == '__main__':
    main()



Measured memory_bytes: 15068
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <set>

template <typename Container, class T>
bool _contains(const Container& c, T v)
{
  return std::find(c.begin(), c.end(), v) != c.end();
}

/**
 * check n has ng digits.
 * \param n target value
 * \param ngs ng digits
 * return true: contain NG digits, false: not contain.
 */
bool contains(int n, const std::vector<int>& ngs)
{
  std::string sn = std::to_string(n);
  std::set<int> digits;

  for(auto d : sn) {
    if(!_contains(digits, d)) {
      digits.insert(d - '0');
    }
  }

  bool contains = false;
  for(auto d : ngs) {
    if(_contains(digits, d)) {
      //  std::cout << "digits contains " << d << std::endl;
      contains = true;
      break;
    }
  }

  return contains;
}

int main()
{
  int N, K;
  std::cin >> N >> K;
  std::vector<int> D(K);
  for(int i = 0; i < K; i++) {
    std::cin >> D[i];
  }

  // check N * 1
  int total = 0;
  for(total = N; ;total++) {
    //  if(i % 1000 == 0) {
    //  std::cout << i << std::endl;
    //  }
    if(!contains(total, D)) {
      break;
    }
  }

  std::cout << std::fixed << total << std::endl;

  return 0;
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {
 	public static void main(String[] args) {
     	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
      	if(a+b >= c) {
         System.out.println("Yes"); 
        } else {
          System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
//
//  Road2Master.cpp
//  Road2Master
//
//  Created by Rakhman Abdirashov on 12/14/19.
//  Copyright © 2019 Rakhman Abdirashov. All rights reserved.
//
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
 
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define vectors vector<vector<llong> >
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)
 
const long long MXN = 2e5 + 10;
const long long MNN = 1e4 + 520;
const long long MOD = 10007;
const long long INF = 1e18;
const long long OO = 1e9;
 
typedef long long llong;
typedef unsigned long long ullong;
 
using namespace std;

int n, m;
vector<int> g[MXN];
bool used[MXN];
deque<int> ans;

void dfs(int x){
    used[x] = 1;
    ans.push_back(x);
    for(int i = 0; i < g[x].size(); i++){
        int to = g[x][i];
        if(used[to] == 0){
            dfs(to);
            break;
        }
    }
}

void dfs1(int x){
    used[x] = 1;
    if(x != 1) ans.push_front(x);
    for(int i = 0; i < g[x].size(); i++){
        int to = g[x][i];
        if(used[to] == 0){
            dfs1(to);
            break;
        }
    }
}

int main(){
    ios;
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1);
    dfs1(1);
    cout << ans.size() << nl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << ' ';
    }
}


Measured memory_bytes: 9216
program E
    implicit none
    integer::N, K, C, i, j, l, m, p, q
    integer, allocatable::v(:), u(:)
    character(len=200005)::S
    read(*,*) N, K, C
    read(*,*) S
    allocate(v(K))
    allocate(u(K))
    l = -500000
    m = 500000
    j = 1
    p = 1

    do i = 1, N
        q = N - i + 1
        if(S(i:i) == "o" .and. i - l > C) then
            v(j) = i
            l = i
            j = j+1
        end if
        if(j > K) then
            exit
        end if
    end do

    do i = 1, N
        q = N - i + 1
        if(S(q:q) == "o" .and. m - q > C) then
            u(p) = q
            m = q
            p = p+1
        end if
        if(p > K) then
            exit
        end if
    end do

    do i = 1, K
        if(v(i) == u(K-i+1)) then
            write(*,*) v(i)
        end if
    end do
    stop
end program E

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

int main() {

    int a,b,k;

    cin >> a >> b >> k;

    set<int> s;

    if(a+k <= b){
        for(int i=a; i<a+k; i++){
            s.insert(i);
        }
        for(int i=b; i>b-k; i--){
            s.insert(i);
        }
    }
    else{
        for(int i=a; i<=b; i++){
            s.insert(i);
        }
    }

    for(auto i : s){
        cout << i << endl;
    }

    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll N;
  scanf("%lld", &N);

  ll c = 0;
  for (ll i = 0; i < N; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);

    if (a == b) {
      c++;
      if (c >= 3) {
        break;
      }
    } else {
      c = 0;
    }
  }

  if (c >= 3) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
	double a,b,C;
	cin >> a >> b >> C;
	cout << fixed << setprecision(5);
	cout << 0.5*a*b*sin(C*M_PI/180) << endl;
	cout << a+b+pow(a*a+b*b-2*a*b*cos(C*M_PI/180),0.5) << endl;
	cout << b*sin(C*M_PI/180) << endl;
	return 0;
}

Measured memory_bytes: 3504
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second

int gcd(int a,int b) {return b?gcd(b,a%b):a;}

const int maxn=4000010;

int n,times,a[maxn],dfn[maxn],deg[maxn];
int tote,FIR[maxn],TO[maxn],NEXT[maxn];
int vis[maxn];
priority_queue<pair<int,int> > q;

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

int search(int u)
{
	int Ans=u;
	vis[u]=1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (vis[v]) continue;
		int tmp=search(v);
		Ans=a[Ans]<a[tmp]?Ans:tmp;
	}
	return Ans;
}

void dfs(int u)
{
	vis[u]=2;
	dfn[u]=++times;
	vector<pair<int,int> > son;
	son.clear();
	for (int p=FIR[u];p;p=NEXT[p])
		son.push_back(make_pair(a[TO[p]],TO[p]));
	sort(son.begin(),son.end());
	for (int i=0;i<(int)son.size();i++)
		if (vis[son[i].Y]!=2) dfs(son[i].Y);
}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (i=1;i<=n;i++)
	for (j=i+1;j<=n;j++)
		if (gcd(a[i],a[j])!=1)
			addedge(i,j),addedge(j,i);

	vector<pair<int,int> > root;
	for (i=1;i<=n;i++)
		if (!vis[i])
		{
			int tmp=search(i);
			root.push_back(make_pair(a[tmp],tmp));
		}
	sort(root.begin(),root.end());
	for (i=0;i<(int)root.size();i++) dfs(root[i].Y);

	tote=0;
	memset(FIR,0,sizeof(FIR));
	for (i=1;i<=n;i++)
	for (j=1;j<=n;j++)
		if (gcd(a[i],a[j])!=1&&dfn[i]<dfn[j])
			addedge(i,j),deg[j]++;

	for (i=1;i<=n;i++)
		if (!deg[i]) q.push(make_pair(a[i],i));
	while (!q.empty())
	{
		pair<int,int> u=q.top(); q.pop();
		printf("%d ",u.X);
		for (int p=FIR[u.Y];p;p=NEXT[p])
		{
			int v=TO[p];
			if (!(--deg[v])) q.push(make_pair(a[v],v));
		}
	}
}


Measured memory_bytes: 60416
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

bool prime[1000001]; //10^6

//素数列挙
void init_prime()
{
	memset(prime,1,sizeof(prime));
	prime[0] = prime[1] = false;
	for(int i = 2; i < sizeof(prime); i++) if(prime[i])
		for(int j = i * 2; j < sizeof(prime); j += i) prime[j] = false;
}

int main(){
	init_prime();
	vector<int> v;
	FOR(i,10000) if(prime[i] && prime[i+2]) v.push_back(i+2);

	int n; 
	while(cin>>n,n){
		int a = *(upper_bound(v.begin(),v.end(),n)-1);
		printf("%d %d\n",a-2,a);
	}

	return 0;
}

Measured memory_bytes: 2176
#-*-coding:utf-8-*-
import itertools

def main():
    a, b = map(int, input().split())
    s = input()

    try:
        s1 = int(s[:a])
        s2 = int(s[a+1:])
        s3 = s[a:a+1]
        if s3 == '-':
            print('Yes')
        else:
            print('No')
    except:
        print('No')


if __name__ == '__main__':
    main()
    

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

typedef unsigned long long ull;
#define rep(i,a) for(int i=0; i<int(a); i++)

int n, s, a[200];
ull dp[2][25];

ull solve(){
    memset(dp, 0, sizeof(dp));
    ull *cur = dp[0], *prev = dp[1];
    prev[a[0]] = 1;
    for (int i = 1; i < n; i++){
        memset(cur, 0, sizeof(dp)/2);
        rep(j, 20 + 1){
            int t1 = j + a[i];
            if (0 <= t1 && t1 <= 20){
                cur[t1] += prev[j];
            }
            int t2 = j - a[i];
            if (0 <= t2 && t2 <= 20){
                cur[t2] += prev[j];
            }
        }
        swap(cur, prev);
    }

    return prev[s];
}

int main(){
    while (cin >> n){
        n--;
        rep(i, n) cin >> a[i];
        cin >> s;
        cout << solve() << endl;
    }
}

Measured memory_bytes: 1152
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;


int main(){
  int n; ll  k; cin >> n >> k; ll a[n]; ll G;
  rep(i, n){
    cin >> a[i]; if(i==0) G = a[0]; G = gcd(G, a[i]);
  }
  sort(a, a+n);
  if(k<=a[n-1] && k%G==0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}
      

Measured memory_bytes: 4280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1_3_B
{
    class Program
    {
        static void Main(string[] args)
        {
            //1つの整数xを読み込み、それをそのまま出力する。
            //xが終わりの時入力の終わりを示し、このデータセットの出力は行わない

            //for文で記述する場合

            //for (int i = 1; i > 0; i++)
            //{
            //    int x = int.Parse(Console.ReadLine());
            //    if (x == 0) break;
            //    else Console.WriteLine("Case {0}: {1}", i, x);
            //}

            //while文で記述する場合

            var count = 1;
            var i = 1;

            while (i != 0)              //while(条件式)　条件式内の条件が続く限り処理を繰り返す
                                        //i != 0 iが0じゃないとき
            {
                i = int.Parse(Console.ReadLine());
                if (i != 0) Console.WriteLine("Case {0}: {1}", count, i);
                count++;
            }
        }
    }
}



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

#define mp make_pair
#define LL long long

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2010, Mod = 1e9 + 7;
int f[N][N], fac[N * N], ifac[N * N];
int fpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1ll * a * a % Mod)
		if (b & 1) res = 1ll * res * a % Mod;
	return res;
}
int C(int n, int m) {
	if (n < m) return 0;
	return 1ll * fac[n] * ifac[m] % Mod * ifac[n - m] % Mod;
}
void pls(int &x, int y) { x += y; if (x >= Mod) x -= Mod; }
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>(), k = gi<int>();
	if (k == 1) { puts("1"); return 0; }
	for (int i = fac[0] = 1; i <= n * k; i++)
		fac[i] = 1ll * fac[i - 1] * i % Mod;
	ifac[n * k] = fpow(fac[n * k], Mod - 2);	
	for (int i = n * k; i; i--)
		ifac[i - 1] = 1ll * ifac[i] * i % Mod;
	f[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= i; j++) {
			f[i][j] = f[i - 1][j];
			if (j) pls(f[i][j], 1ll * f[i][j - 1] * (n - j + 1) % Mod * C((n - j + 1) * k - i + j - 2, k - 2) % Mod);
		}
	printf("%d\n", f[n][n]);
	return 0;
}


Measured memory_bytes: 48632
import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		String s=scan.next();
		int len=s.length();
		int count_0=0;
		int count_1=0;
		for (int i=0;i<len;++i) {
			if(s.charAt(i)=='0')++count_0;
			if(s.charAt(i)=='1')++count_1;
		}
		System.out.print(Math.min(count_0,count_1)*2);
}
}
//end


Measured memory_bytes: 25684
fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(' ').map { it.toInt() }
    val points = (0 until n).map { readLine()!!.split(' ').map { it.toInt() } }
    var ans = 0
    for (i in 0 until n - 1) {
        for (j in i + 1 until n) {
            val distance = (0 until d)
                    .map { Math.pow((points[i][it] - points[j][it]).toDouble(), 2.0) }
                    .sum()
                    .let { Math.sqrt(it) }
            if (distance == Math.floor(distance)) {
                ans++
            }
        }
    }
    println(ans)
}


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

int main() {
  int price[] = {1, 5, 10, 50, 100, 500};

  while (true) {
    int sum = 0;

    for (int i = 0; i < 6; i++) {
      int c;
      if(!(cin >> c)) return 0;
      sum += price[i] * c;
    }

    cout << (sum >= 1000) << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
using namespace std;
long long n,a,b[1000000],c,p;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;if(b[0]==1 || c>a){cout<<"No"<<endl;continue;}
		if(c==a && p!=a){cout<<"No"<<endl;continue;}p++;
		if(a>=1000000){cout<<"Yes"<<endl;continue;}
		b[a]++;while(b[a]>=2){b[a]-=2;b[a-1]++;a--;p--;}
		while(c<=999998 && b[c+1]==1)c++;
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 7092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000500

ll n, a, b, c, dp[M][5];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a >> b >> c;
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a;
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b;
        dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c;
    }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
        

fast();
//ll t;cin>>t;while(t--)
{
   ll n,z,w;
   cin>>n>>z>>w;
   ll a[n];
   for(int i=0;i<n;i++)
   {
     cin>>a[i];
   }
   ll ans=0;
   if(n==1)
   {
     ans=(abs(a[n-1]-w));

   }
   else
      ans=max(abs(a[n-2]-a[n-1]),(abs(a[n-1]-w)));
   cout<<ans<<endl;

}
return 0;
}

Measured memory_bytes: 3616
def gcd(a, b):
  if a < b:   
  	a, b = b, a
  y = a % b
  if y == 0:
  	return b
  else:
  	a, b = b, y
  	return gcd(a,b)
x = [int(i) for i in input().split()]
fac = []
fac.append(1)
i = gcd(x[0], x[1])
for j in range(2, i + 1):
  if (i % j == 0):
    fac.append(j)
print(fac[::-1][x[2]-1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int res = n;
    rep(i, n+1) {
        // a(6, 9)進法でnの桁和を求める
        int cnt=0, t=i;
        while (t>0) cnt+=t%6, t/=6;
        t=n-i;
        while (t>0) cnt+=t%9, t/=9;
        chmin(res, cnt);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int m,n;
	int s=0,cnt=0; double a=0;

	while(scanf("%d,%d",&m,&n)!=EOF)
	{
		s+=m*n;
		a+=n;
		cnt++;
	}

	a=a/cnt+0.5;
	printf("%d\n%d\n",s,(int)a);
  return 0;
}

Measured memory_bytes: 1020
function main(arg) {
	arg = arg.trim().split(' ');
  	arg = arg.map(str => parseInt(str, 10));
  	var out = '-1';
  	if (arg[0] > 9) {
		console.log(out);    
    } else if(arg[1] > 9) {
    	console.log(out);
    } else {
    	out = arg[0] * arg[1]
      	console.log(out);
    }
  	//arg.forEach(ele => out = ele > 9 ? '-1' : false);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a;
	cin>>a;
	if(a=="SSS")
		cout<<0;
	else if(a=="SSR")
		cout<<1;
	else if(a=="SRS")
		cout<<1;
	else if(a=="RSS")
		cout<<1;
	else if(a=="RRS")
		cout<<2;
	else if(a=="SRR")
		cout<<2;
	else if(a=="RSR")
		cout<<1;
	else if(a=="RRR")
		cout<<3;		
	return 0;
	
	
}

Measured memory_bytes: 3632
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]


satisfaction = 0
last = [0]*26

for i in range(D):
    # print('i')

    best_sat = -100000000000
    for t in range(26):
        t_sat = S[i][t] + satisfaction - \
                sum([C[k]*((i+1)-last[k]) for k in range(26)]) + C[t]*((i+1)-last[t])
        # print(str(t)+'t:'+str(t_sat)+', b:'+str(best_sat))
        if t_sat > best_sat:
            best_T = t
            best_sat = t_sat

    # print(best_sat)
    satisfaction = best_sat
    last[best_T] = i + 1
    # print('i:'+str(i))
    # print(last)
    print(best_T+1)
    # print(satisfaction)


Measured memory_bytes: 9336