akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int S = sc.nextInt();
		if (S>=5010) S=5009;
		int[] u = new int[M];
		int[] v = new int[M];
		int[] a = new int[M];
		int[] b = new int[M];
		for (int i=0;i<M;i++) {
			u[i] = sc.nextInt()-1;
			v[i] = sc.nextInt()-1;
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		int[] c = new int[N];
		int[] d = new int[N];
		for (int i=0;i<N;i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}

		long INF = 3_000_000_000_000_000_000L;
		long[][] dp = new long[N][5010]; // dp[pos][money]
		for (int i=0;i<N;i++) {
			for (int j=0;j<5010;j++) {
				dp[i][j] = INF;
			}
		}
		dp[0][S] = 0;
		for (int j=0;j<5010;j++) {
			if (j+c[0]<5010) dp[0][j+c[0]] = Math.min(dp[0][j+c[0]], dp[0][j]+d[0]);
		}

		for (int i=0;i<110;i++) {
			for (int k=0;k<M;k++) {
				for (int j=0;j<5010;j++) {
					if (j+c[u[k]]<5010) dp[u[k]][j+c[u[k]]] = Math.min(dp[u[k]][j+c[u[k]]], dp[u[k]][j]+d[u[k]]);
				}
				for (int j=0;j<5010;j++) {
					if (j-a[k]>=0) dp[v[k]][j-a[k]] = Math.min(dp[v[k]][j-a[k]], dp[u[k]][j]+b[k]);
				}
				for (int j=0;j<5010;j++) {
					if (j-a[k]>=0) dp[u[k]][j-a[k]] = Math.min(dp[u[k]][j-a[k]], dp[v[k]][j]+b[k]);
				}
				for (int j=0;j<5010;j++) {
					if (j+c[v[k]]<5010) dp[v[k]][j+c[v[k]]] = Math.min(dp[v[k]][j+c[v[k]]], dp[v[k]][j]+d[v[k]]);
				}
			}
		}

		for (int i=1;i<N;i++) {
			long ans = INF;
			for (int j=0;j<5010;j++) {
				ans = Math.min(ans, dp[i][j]);
			}
			System.out.println(ans);
		}

		// for (int i=0;i<N;i++) {
		// 	StringBuilder sb = new StringBuilder();
		// 	for (int j=0;j<10;j++) {
		//  		sb.append(dp[i][j]);
		//  		sb.append(" ");
		// 	}
		// 	System.out.println(sb);
		// }
	}
}

Measured memory_bytes: 42520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    rep(i, N){
        cin >> x.at(i) >> y.at(i) >> z.at(i);
    }
    ll ans = 0;
    rep(t, 1 << 3){
        bitset<3> s(t);
        vector<ll> X(N), Y(N), Z(N);
        if(s.test(0)){
            rep(i, N){
                X.at(i) = -1 * x.at(i);
            }
        }
        else{
            rep(i, N){
                X.at(i) = x.at(i);
            }
        }
        if(s.test(1)){
            rep(i, N){
                Y.at(i) = -1 * y.at(i);
            }
        }
        else{
            rep(i, N){
                Y.at(i) = y.at(i);
            }
        }
        if(s.test(2)){
            rep(i, N){
                Z.at(i) = -1 * z.at(i);
            }
        }
        else{
            rep(i, N){
                Z.at(i) = z.at(i);
            }
        }
        vector<vector<tuple<ll, ll, ll>>> cake(N+1, vector<tuple<ll, ll, ll>>(N+1));
        rep(i, N+1){
            cake.at(i).at(0) = make_tuple(0, 0, 0);
        }
        rep(i, N){
            rep(j, i+1){
                if(j == i){
                    cake.at(i+1).at(j+1) = make_tuple(get<0>(cake.at(i).at(j)) + X.at(i), get<1>(cake.at(i).at(j)) + Y.at(i), get<2>(cake.at(i).at(j)) + Z.at(i));
                    continue;
                }
                ll old = get<0>(cake.at(i).at(j+1)) + get<1>(cake.at(i).at(j+1)) + get<2>(cake.at(i).at(j+1));
                ll ate = get<0>(cake.at(i).at(j)) + X.at(i) + get<1>(cake.at(i).at(j)) + Y.at(i) + get<2>(cake.at(i).at(j)) + Z.at(i);
                if(ate > old){
                    cake.at(i+1).at(j+1) = make_tuple(get<0>(cake.at(i).at(j)) + X.at(i), get<1>(cake.at(i).at(j)) + Y.at(i), get<2>(cake.at(i).at(j)) + Z.at(i));
                }
                else{
                    cake.at(i+1).at(j+1) = cake.at(i).at(j+1);
                }
            }
        }
        chmax(ans, get<0>(cake.at(N).at(M))+get<1>(cake.at(N).at(M))+get<2>(cake.at(N).at(M)));
    }
    cout << ans << endl;
}

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

using namespace std;

typedef complex<double> P;

double const EPS = 1e-10;

double cross(P const& a, P const& b) {
  return imag(conj(a)*b);
}

bool is_parallel(P const& a1, P const& a2, P const& b1, P const& b2)
{ return abs(cross(a2-a1, b2-b1)) < EPS; }

int main() {
  
  int N; cin >> N;
  for(int i=0; i<N; i++) {
    P ps[4];
    for(int i=0; i<4; i++)
      cin >> ps[i].real() >> ps[i].imag();
    printf("%s\n", (is_parallel(ps[0], ps[1], ps[2], ps[3]) ? "YES" : "NO" ));
  }
  
  return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;

class FenwickTree {
	vi ft;

public:
	FenwickTree() {}
	void resize(int n) { ft.resize(n+1); }

	void add(int k, int v) {
		while (k < sz(ft)) {
			ft[k] += v;
			k += k & -k;
		}
	}

	int sum(int k) {
		int r = 0;
		while (k > 0) {
			r += ft[k];
			k -= k & -k;
		}
		return r;
	}

	int sum(int a, int b) {
		return sum(b) - sum(a-1);
	}
};

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	string s;
	cin >> n >> s;

	FenwickTree ft[26];
	for (int i = 0; i < 26; i++) ft[i].resize(n);
	for (int i = 0; i < n; i++)
		ft[s[i]-'a'].add(i+1, 1);

	int q, t, i, l, r;
	string c;
	for (cin >> q; q > 0; q--) {
		cin >> t;
		if (t == 1) {
			cin >> i >> c;
			if (s[i-1] != c[0]) {
				ft[s[i-1]-'a'].add(i, -1);
				ft[c[0]-'a'].add(i, 1);
			}
			s[i-1] = c[0];
		}
		else {
			cin >> l >> r;
			int ans = 0;
			for (int j = 0; j < 26; j++)
				if (ft[j].sum(l, r) > 0) ans++;
			cout << ans << "\n";
		}
	}
}


Measured memory_bytes: 51716
cmin = lambda a,b : a if a<b else b
cmax = lambda a,b : a if a>b else b
iin = lambda : int(input())
lin = lambda : list(map(int,input().split()))
rin = lambda n : [int(input()) for _ in range(n)]

n,a,b = map(int,input().split())

d,m = divmod(n,a+b)

print(d*a+m if m<a else d*a+a)

Measured memory_bytes: 3064
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    t1 = n - m
    t2 = m
    print(int((t1 * 100 + t2 * 1900) / (1 / 2) ** t2))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return f?x:-x;
}
std::map<int, bool> mp;
int main(int argc, char const *argv[]) {
	int n = read(), ans = 0;
	for (int i = 1; i <= n; i++) {
		int x = read();
		if (mp[x]) ans --, mp[x] = 0;
		else       ans ++, mp[x] = 1;
	}
	printf("%d\n", ans);
	return 0;
}

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

#define rep(v,c) for(int v=0; v<(int)c; ++v)

using pint=pair<int,int>;
using vint=vector<int>;
using vvint=vector<vector<int>>;

constexpr int INF=(1<<30);

int main(void){
  int h,w; cin>>h>>w;
  vvint a(h,vint(w,0));
  rep(i,h) rep(j,w) cin>>a[i][j];
  
  int ans=INF;
  rep(i,h){
    rep(j,w){
      int tmp=0;
      rep(k,h){
        rep(l,w){
          tmp+=a[k][l]*min(abs(i-k),abs(j-l));
        }
      }
      ans=min(ans,tmp);
    }
  }
  cout<<ans<<endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 100000000;
  for(int i=0; i<n; i++) {
    cin >> a.at(i);
    int count = 0;
    int temp = a.at(i);
    while(temp%2 == 0) {
      temp = temp/2;
      count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef long long ll;
typedef pair<long long , long long> P;
typedef pair<P, ll> Pll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll N;
    cin >> N;
    vector<P> A(N);
    REP(i,N){
        ll x, y;
        cin >> x>> y;
        A[i] = P(x, y);
    }    
    map<P, ll> m;
    REP(i, N){
        FOR(j, 0, N){
            if(j==i) continue;
            ll dx = (A[i].first-A[j].first);
            ll dy = (A[i].second-A[j].second);
            m[P(dx, dy)]++;
        }
    }
    Pll grad = Pll(P(0,0), 0);
    for(auto x: m){
        if(x.first.first==0 and x.first.second==0) continue;
        if(x.second>grad.second) grad = x;
    }
    ll res = N - grad.second;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<iomanip>
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace boost::multiprecision;
#define ll long long int
#define fori(n) for(int i=0;i<n;i++)
#define tcase ll t; cin>>t;while(t--)
// cpp_int boost_factorial(int num) 
// { 
//     cpp_int fact = 1; 
//     for (int i=num; i>1; --i)     
//         fact *= i; 
//     return fact; 
// } 

ll solver(){
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(k<=x/d) return x-(k*d);

    k-=(x/d);
    if(k==0) return x/d;
    x=x%d;
    // cout<<k<<" "<<(x-(2*d))<<endl;
    ll mi=INT_MAX;
    if(k%2==0) mi=min(abs(x-(2*d)),x);
    else mi=min(abs(x-d),x+d);

    return mi;
}

int main()
{
    /* code */
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);     
    cout<<solver()<<endl;  
    return 0;
}

Measured memory_bytes: 3636
A,B,C,D = map(int,input().split())
count = 0
point = 0

if D-A >= 0:
    point = A
    D -= A
    if D-B >= 0:
        D -= B
        if D-C >= 0:
            point -= C
            print(point)
        else:
            point -= D
            print(point)
    else:
        print(point)
else:
    point = D
    print(point)

Measured memory_bytes: 9196
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>
#include <bitset>
#include <map>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
//           123456789

ll d1, d2, n, c, f = 0;

int main() {
    cin >> n;
    rep(i,n){
        cin >> d1 >> d2;
        if (d1 == d2) c++;
        else c = 0;

        if (c == 3) f = 1;
    }
    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main(){
  string s,t;
  int count = 0;
  
  cin >> s >> t;
  
  for(int i=0;i<s.size();i++){
    if(s[i] != t[i]){
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
static const ll MOD = 1000000007;

int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  sort(H.begin(), H.end());
  if(K >= N){
    cout << 0 << endl;
  }else{
    ll res = 0;
    for(int i = 0; i < N - K; i++){
      res += H[i];
    }
    cout << res << endl;
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, source_len, sign_len, count = 0, suffix;
  string source, sign;

  cin >> n >> source;
  source_len = source.length();

  while (n--) {
	cin >> sign;
	sign_len = sign.length();
	for (int j = 0; j < sign_len; j++) {
	  for (int k = 0; k <= sign_len / 2; k++) {
		for (int l = 0, suffix = j; l < source_len; l++) {
		  if (source[l] != sign[suffix]) break;
		  if (l == source_len - 1) { count++; goto end; }
		  if ((suffix += k + 1) >= sign_len) break;
		}
	  }
	}
  end:;
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1208
<?php
	fscanf(STDIN, "%d", $n);

	for($i = 0; $i < $n; $i++) {
		fscanf(STDIN, "%d %d %d", $arr[0], $arr[1], $arr[2]);
		sort($arr);

		if(($arr[0] * $arr[0] + $arr[1] * $arr[1]) == ($arr[2] * $arr[2])) {
			print "YES\n";
		}
		else {
			print "NO\n";
		}
	}
?>

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

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

   ll m=n, l=1, p=26;
   while(m>=p){
      m-=p;
      p*=26;
      l++;
   }
   string s="";
   p=1;
   rep(i, l){
      s+=m/p%26+'a';
      p*=26;
   }

   reverse(s.begin(), s.end());

   cout << s << endl;
   return 0;
}


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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 998244353
#define MAXN 10000013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
ll ans;
ll fact[MAXN], ifact[MAXN], pw2[MAXN];

ll expo(ll a, ll e)
{
	if (e == 0) return 1;
	if (e & 1)
	{
		return expo(a * a % INF, e >> 1) * a % INF;
	}
	return expo(a * a % INF, e >> 1);
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	cin >> N;
	fact[0] = 1;
	FOR(i, 1, N + 10)
	{
		fact[i] = fact[i - 1] * i % INF;
	}
	ifact[N + 9] = expo(fact[N + 9], INF - 2);
	FORD(i, N + 9, 0)
	{
		ifact[i] = ifact[i + 1] * (i + 1) % INF;
	}
	pw2[0] = 1;
	FOR(i, 1, N + 10)
	{
		pw2[i] = pw2[i - 1] + pw2[i - 1]; if (pw2[i] >= INF) pw2[i] -= INF;
	}
	N /= 2;
	ans = 1;
	FOR(i, 0, 2 * N)
	{
		ans *= 3; ans %= INF;
	}
	FOR(i, N + 1, 2 * N + 1)
	{
		ans -= 2 * fact[2 * N] * ifact[2 * N - i] % INF * ifact[i] % INF * pw2[2 * N - i];
		ans %= INF;
	}
	if (ans < 0) ans += INF;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 234752
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
    ll n,m;
    cin>>n>>m;

    ll s[m],c[m];
    ll a[n];
    memset(a,-1,sizeof(a));
    ll i,j;
    for(i=0;i<m;i++)
    {
       cin>>s[i]>>c[i];
       s[i]--;
    }
    
    for(i=0;i<m;i++)
    {
        if(a[s[i]]>=0)
        {
            if(c[i]!=a[s[i]])
            {
                cout<<"-1\n";
                return;
            }
        }
        else{
           a[s[i]]=c[i];
        }
    }
    if(n==1)
    {
        if(a[0]==-1)
        {
            cout<<"0\n";
            return;
        }
    }
    ll f=0;
    for(i=0;i<n;i++)
    {
        if(a[i]>0)
        {
            f=1;
        }
        if(!f)
        {
            if(a[i]==0&&n>1)
            {
                cout<<"-1\n";
                return;
            }
        }
        if(a[i]==-1)
        {
            if(f)
            {
                a[i]=0;
            }
            else{
                a[i]=1;
                f=1;
            }
        }
    }

    for(i=0;i<n;i++)cout<<a[i];
    

}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define PB push_back
using namespace std;
vector<int> g[200200];
int cnt[19], clr[200200], u, v, n, m;

bool Color(int x) {
	for(int i = 0; i < g[x].size(); i++) {
		int v = g[x][i];
		if(clr[v] == clr[x]) return 0;
		if(clr[v]) continue;
		clr[v] = clr[x] ^ 1;
		cnt[clr[v]]++;
		if(!Color(v)) return 0; 
	}
	return 1;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d%d", &u, &v);
		g[u].PB(v);
		g[v].PB(u);
	}
	clr[1] = 3;
	cnt[3] = 1;
	if(Color(1)) {
		printf("%lld\n", 1LL * cnt[3] * cnt[2] - m);
	} else printf("%lld\n", 1LL * n * (n - 1) / 2 - m);
	return 0;
}

Measured memory_bytes: 8832
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>

using namespace std;


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    int a[n], ans=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n-1]-a[0];
}


Measured memory_bytes: 256
def selection_sort(n):
    c = 0
    r = n[:]
    l = len(r)
    for i in range(0, l):
        mini = i
        for j in range(i, l):
            if (r[j] < r[mini]):
                mini = j
        if mini != i:
            r[i], r[mini] = r[mini], r[i]
            c += 1
    return r, c

if __name__ == '__main__':
    limit = int(input())
    n = list(map(int, input().split()))[:limit]
    r, c = selection_sort(n)
    print(' '.join(map(str, r)))
    print(c)



Measured memory_bytes: 5600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

std::string s;
int n;

int main(){
	std::cin >> s;
	scanf("%d", &n);
	for(int i = 0; i < s.length(); i += n){
		printf("%c", s[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
import fractions
A, B, K = map(int, input().split())
# はじめにgcd(a, b)を求める
G = fractions.gcd(A, B)
# Gの約数がA, Bの公約数になるのでこれを列挙し、大きい順に並べてK番目を出力
i = 1
divisors = []
while i ** 2 <= G:
	if G % i == 0:
		divisors.append(i)
		divisors.append(G // i)
	i += 1
divisors = sorted(list(set(divisors)))[:: -1]
print(divisors[K - 1])


Measured memory_bytes: 5308
/* C - H and V */

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

int main(){
  int H, W, K, ans = 0;
  cin >> H >> W >> K;
  vector<vector<char>> c(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> c.at(i).at(j);
    }
  }
  // bit全探索: (1 << n)は2^n, 0:No(塗らない), 1:Yes(塗る)
  for(int maskR = 0; maskR < (1 << H); maskR++){
    for(int maskC = 0; maskC < (1 << W); maskC++){
      int black = 0;
      for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
          // i行j列を塗らないとわかったら、そこが黒のときカウントする
          if(!(maskR & (1 << i)) && !(maskC & (1 << j)) && c.at(i).at(j) == '#'){
            black++;
          }
        }
      }
      if(black == K){
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    string s,t;cin>>s>>t;
    int ss=s.size(),ts=t.size();
    string tmp;
    int ans=inf,sum;
    rep(i,ss-ts+1){
        tmp=s.substr(i,ts);
        sum=0;
        rep(j,tmp.size())if(t[j]!=tmp[j])sum++;
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    if((i & 1 ^ 1 && s[i] == 'L') || (i & 1 && s[i] == 'R')){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3568
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
b = []
for i in range(len(a)-1):
    b.append(i+1)
b.append(b[-1])
b.reverse()
for i in range(len(a)):
    ans += a[i] * (1/2 ** b[i]) 
print(ans)

Measured memory_bytes: 38384
N, Y = map(int, input().split())

def f():
    for i in range(N+1):
        for j in range(9):
            k = N-i-j

            if i<0 or j<0 or k<0:
                continue

            if i*10000+j*5000+k*1000 == Y:
                print(i, j, k)
                return

    print(-1,-1,-1)

f()

Measured memory_bytes: 9176
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <memory>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <deque>
#include <unordered_set>
#include <stack>
#include <functional>

using namespace std;


//#define int long long

signed main() {
#ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);
#endif
    int n, x;
    cin >> n >> x;
    vector <int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (x >= v[i]) {
            x -= v[i];
            ++ans;
        }
    }
    if (x == v.back()) {
        ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#define log(args...)
#else
#define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); logf(_it, args); }
void logf(istream_iterator<string> it) {
}
template<typename T, typename ... Args>
void logf(istream_iterator<string> it, T a, Args ... args) {
	cout << *it << " = " << a << endl;
	logf(++it, args...);
}
#endif

#define forn(i,k,n) for(ll i=(k); i<(n); i++)

const double PI = acos(-1);
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
	cini(n);
	cini(k);	// base

	int ans = 0;
	while (n) {
		ans++;
		n /= k;
	}
	cout << ans << endl;
}

int main() {
	cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	solve();
}



Measured memory_bytes: 256
import functools
n = list(map(int,input().split()))
ans = 0
for i in range(n[0]+1):
  s = list(map(int,str(i)))
  sum = functools.reduce(lambda a,b: a+b, s)
  if n[1]<= sum and sum <= n[2]:
    ans+=i
print(ans)

Measured memory_bytes: 3680
#include <iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define g 9.80
#define eps 1e-8
int top;

int n;
double v,xx,yy;
struct rectangle
{
       double l,r,b,t;
}rec[101];

bool judge(double a,double len )
{
     int i;
     double hh = a*xx*(xx-len);
     double hi = -a*len*len/4.0;//抛物&#32447;最高点的y坐&#26631; 
     if ( yy-hh>eps || yy-hi>eps ) return false;//抛物&#32447;&#39134;&#36807;pig下方 
     for ( i=1;i<=n;i++ )
     {
         if ( rec[i].l>xx ) break;//障碍物的左&#36793;界大于pig的x坐&#26631; 
         double h1 = a*rec[i].l*(rec[i].l-len );//左&#36793;界&#23545;&#24212;的高度 
         double h2 = a*rec[i].r*(rec[i].r-len );//右&#36793;界&#23545;&#24212;的高度 
         if ( h1>=rec[i].b && h1<=rec[i].t ) return false;
         if ( h2>=rec[i].b && h2<=rec[i].t ) return false;//撞上&#36793;界 
         if ( h1<rec[i].b && h2<rec[i].b ) //抛物&#32447;从矩形下方&#39134;&#36807; 
              if (  len/2-rec[i].l>eps && rec[i].r-len/2>eps && hi-rec[i].b>eps  ) 
                 return false;//抛物&#32447;最高点在矩形中或者高于矩形 
         if ( rec[i].l<=xx && rec[i].r>=xx  && rec[i].b>yy ) //pig 在一个矩形的下面 
             if ( hh>rec[i].t ) return false;
     }
     return true;
}


void solve()
{
     int i;
     double h,t,vx,vy,len;
     for ( i=1;i<=1000000;i++ )
     {
           vy=double(i)/1000000*v;
           vx=sqrt(v*v-vy*vy);
           t=vy/g;
           h = g*t*t/2;
           len = vx*2*t;
           if ( xx-len>eps ) continue;
           else
           {
               double a = (-2*vy*vy)/(g*len*len);
               if ( judge(a,len) )
               {
                    printf("Yes\n");
                    return ;
               }
           }
     }
     printf("No\n");
}

bool cmp(rectangle a,rectangle b)
{
     return a.l<b.l;
}

int main()
{
    int i;
    while ( scanf("%d %lf %lf %lf",&n,&v,&xx,&yy)!=EOF )
    {
          for ( i=1;i<=n;i++ )
          {
              scanf("%lf %lf %lf %lf",&rec[i].l,&rec[i].b,&rec[i].r,&rec[i].t);
              rec[i].r = min(xx,rec[i].r);
          }
          sort(rec+1,rec+n+1,cmp);
          solve();
    }
    return 0;
}
          
          
          
          

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

int main() {
int n;
cin >> n;
vector<long long> a(n);
long long sum = 0LL;
for(int i = 0; i < n; i++) {
long long x; cin >> x;
sum+=x;
a[i] = sum;
}
long long diff = 1e15;
for(int i = 0; i < n-1; i++) {
  long long x = sum-a[i]*2;
  if(x<0) x = -x;
  if(diff > x) diff=x;
}
cout << diff << endl;
return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long x,a,b,c;cin >> x;
  for(a=1;a<50000000;a++){
    for(b=a-1;b>=-50000000;b--){
      c = a*a*a*a*a-(b*b*b*b*b);
      if(c>x) break;
      if(c==x){
        cout << a << " " << b << "\n";return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 12/8/2018, 9:12:11 PM
# Powered by Visual Studio Code
#

n = gets.to_i
a = []
n.times{
  a << gets.to_i
}
puts a.inject(:+) - a.max/2

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
ll dp[200200][5];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    rep(i,N+1)rep(j,5)dp[i][j] = INFLL;
    rep(j,5)dp[0][j] = 0;
    rep(i,N){
        rep(j,5){
            //k <= j
            for(int k = 0; k <= j;k++){
                //0を置くパート
                if(j == 0 || j == 4){
                chmin(dp[i+1][j], dp[i][k] + A[i]);
                }
                //2以上の偶数を置くパート
                if(j == 1 || j == 3){
                    if(A[i] == 0){
                        chmin(dp[i+1][j], dp[i][k] + 2);
                    }
                    else{
                        chmin(dp[i+1][j], dp[i][k] + A[i] % 2);
                    }
                }
                //奇数を置くパート
                if(j == 2){
                    chmin(dp[i+1][j], dp[i][k] + (A[i] + 1) % 2);
                }
            }
        }
    }
    ll ans = INFLL;
    /*
    rep(i,N+1){
        rep(j,5){
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }*/
    rep(j,5)chmin(ans, dp[N][j]);
    cout << ans << endl;
}

Measured memory_bytes: 9600
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N;
int u,v;
vector<vector<int>> G;
vector<int> dist;
int ans = 0;
void dfs(int k, int p){
    if(k != v) dist[k] = dist[p]+1;
    if(k == u) return;
    for(int l : G[k]){
        if(l == p) continue;
        dfs(l,k);
    }
}

vector<int> t;

void dfs2(int k, int p){
    if(dist[k] == dist[u]/2+1){
        t.push_back(k);
        return;
    }

    for(int l : G[k]){
        if(l == p) continue;
        dfs2(l,k);
    }
}

vector<bool> visited;
void dfs3(int k, int p){
    if(k == t[0]) return;
    visited[k] = true;
    for(int l : G[k]){
        if(l == p) continue;
        dfs3(l,k);
    }
}

vector<int> dist2;
void dfs4(int k, int p){
    if(visited[k]) return;
    if(k != t[0]) dist2[k] = dist2[p]+1;

    for(int l : G[k]){
        if(l == p) continue;
        dfs4(l,k);
    }
    
}


int main(){
    cin >> N;
    G.resize(N);
    dist.resize(N,INF);
    visited.resize(N,false);
    dist2.resize(N,-INF);
    cin >> u >> v;
    u--; v--;
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dist[v] = 0;
    dfs(v,-1);

    dfs2(u,-1);
    //rep(i,N) cout << dist[i] <<  " ";
    //cout << endl;

    dfs3(v,-1);

    dist2[t[0]] = 0;
    dfs4(t[0],-1);

    ans += dist[u]/2+1;
    int now = 0;
    rep(i,N){
        now = max(now,dist2[i]);
    }
    //cout << dist[u] << " " << now << endl;
    ans += now-1;



    cout << ans << endl;

}


Measured memory_bytes: 10240
#include <cstdio>
#include <cstring>
using namespace std;
int main(void){
    
    char s[11];
    char a[11] = {};
    
    int n=0;
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++){
        if(s[i]=='0'){
            a[n] = '0';
            n++;
        } else if(s[i] == '1'){
            a[n] = '1';
            n++;
        } else if(s[i] == 'B'){
            if(n!=0) n--;
            a[n] = '\0';
        }
    }
    
    printf("%s\n",a);
    
    return 0;
}


Measured memory_bytes: 128
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		int ans;
		int large;

		ans = Math.min(a, b);
		large = Math.max(a, b);

		ans += Math.min(large, c);

		System.out.println(ans);

	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27040
S = int(input())
x0, y0 = 0, 0
n = pow(S, 1 / 2) + 1
n = int(n)
x1, y2 = n, n
x2 = n ** 2 - S
y1 = 1
num = 10 ** 9
if x1 <= num and y1 <= num and x2 <= num and y2 <= num:
    print(x0, y0, x1, x2, y1, y2)
else:
    x0, y0 = 0, 0
    n = 10 ** 9
    x1, y2 = n, n
    x2 = n ** 2 - S
    y1 = 1
    print(x0, y0, x1, x2, y1, y2)


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

int main(void){
    int h,w;
    while(true){
        cin >> h >> w;
        if(h==0 && w==0) return 0;
        for(int i=0; i<h; i++){
            cout << "#";
            for(int j=1; j<w-1; j++){
                if(i==0 || i==h-1) cout << "#";
                else cout << ".";
            }
            cout << "#" << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
bool f(int x){
  int keta=0;
  while(x){
    keta++;
    x/=10;
  }
  if(keta%2==1) return true;
  return false;
}
int main(){
  int n;
  cin>>n;
  int count=0;
  for(int i=1;i<=n;i++){
    if(f(i)) count++;
  }
  cout<<count<<endl;
}

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

int main(){
    int N,K,ans;
    ans = 1;
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
    if (ans <=K){
        ans *=2;
    }else{
    ans +=K;
    }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[300020];
int t[8][2],f[300020][8],p=1000000007;
int main() 
{
	t[0][0]=2;t[0][1]=1;t[1][0]=3;t[1][1]=5;t[2][0]=4;t[2][1]=7;t[3][0]=6;t[3][1]=1;t[4][0]=2;t[4][1]=2;t[5][0]=5;t[5][1]=5;t[6][0]=3;t[6][1]=3;t[7][0]=2;t[7][1]=1;
	scanf("%s",s);
	int n=strlen(s);
	f[n][1]=1,f[n][5]=1;
	for(int i=n-1;i>=0;i--)
		for(int j=0;j<8;j++) 
		{
			if(s[i]!='1') 
				f[i][j]+=f[i+1][t[j][0]];
			if(s[i]!='0')
				f[i][j]+=f[i+1][t[j][1]];
			f[i][j]%=p;
		}
	printf("%d\n", f[0][0]);
}

Measured memory_bytes: 9984
#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, bool> elem;

int main()
{
    vector<elem> is_prime(50021 + 1);

    is_prime.at(0) = elem(0, false);
    is_prime.at(1) = elem(1, false);

    for (size_t i = 2; i < 50021 + 1; i++) {
        is_prime.at(i) = elem(i, true);
    }

    for (size_t i = 2; i < is_prime.size() / 2; i++) {
        if (is_prime.at(i).second) {
            for (size_t j = i * 2; j < is_prime.size(); j += i) {
                is_prime.at(j).second = false;
            }
        }
    }

    int in;
    while (cin >> in) {
        for (size_t it = in - 1; it != 0; it--) {
            if (is_prime.at(it).second) {
                cout << is_prime.at(it).first << " ";
                break;
            }
        }

        for (size_t it = in + 1; it != is_prime.size(); it++) {
            if (is_prime.at(it).second) {
                cout << is_prime.at(it).first << endl;
                break;
            }
        }
    }

    return 0;
}

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

const int MAXN = 200005, mod = 1e9+7;

inline int read()
{
	int a = 0, c;
	do c = getchar(); while (!isdigit(c));
	while (isdigit(c)) {
		a = a*10+c-'0';
		c = getchar();
	}
	return a;
}

struct point {
	int w, id;
	friend bool operator < (const point &a, const point &b)
	{ return a.w < b.w; }
};

int n, x, y, c[MAXN], w[MAXN];
vector<point> v[MAXN];
int fa[MAXN];
inline int findf(int nd)
{ return fa[nd]?fa[nd]=findf(fa[nd]):nd; }
inline void link(int u, int v)
{
	u = findf(u), v = findf(v);
	if (u != v) fa[u] = v;
}
map<int,int> st[MAXN];
int siz[MAXN];

int fac[MAXN], ifac[MAXN], inv[MAXN];

int main()
{
	n = read(), x = read(), y = read();
	inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = (mod-(long long)mod/i*inv[mod%i]%mod)%mod;
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = (long long)fac[i-1]*i%mod, ifac[i] = (long long)ifac[i-1]*inv[i]%mod;
	for (int i = 1; i <= n; i++) {
		c[i] = read(), w[i] = read();
		v[c[i]].push_back({w[i], i});
	}
	for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < v[i].size(); j++) {
			if (v[i][j].w+v[i][0].w <= x)
				link(v[i][j].id, v[i][0].id);
			else break;
		}
	}
	int pos = -1;
	for (int i = 1; i <= n; i++)
		if (!v[i].empty() && (pos == -1 || v[i][0] < v[pos][0]))
			pos = i;
	assert(pos != -1);
	int min_weight = 1e9;
	for (int i = 1; i <= n; i++) {
		if (i == pos) continue;
		for (int j = 0; j < v[i].size(); j++) {
			if (v[i][j].w+v[pos][0].w <= y) {
				link(v[i][j].id, v[pos][0].id);
				min_weight = min(min_weight, v[i][j].w);
			}
			else break;
		}
	}
	for (int i = 1; i < v[pos].size(); i++) {
		if (v[pos][i].w + min_weight <= y) link(v[pos][i].id, v[pos][0].id);
		else break;
	}
	for (int i = 1; i <= n; i++) {
		int f = findf(i);
		st[f][c[i]]++;
		siz[f]++;
	}
	int ans = 1;
	for (int i = 1; i <= n; i++)
		if (fa[i] == 0) {
			ans = (long long)ans*fac[siz[i]]%mod;
			for (auto j : st[i]) 
				ans = (long long)ans*ifac[j.second]%mod;
		}
	cout << ans << endl;
	return 0;
}


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


void solve(long long N, long long K){
    cout << (N%K == 0 ? "0" : "1") << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin >> n;
	cin >> s;
	int ans = 0;
	for(int i=0;i<(int)s.length()-2;i++) {
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<atcoder/fenwicktree.hpp>
using namespace atcoder;
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pll = pair<ll, ll>;
using tp3 = tuple<ll, ll, ll>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

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

    fenwick_tree<ll> fw(N);
    rep(i, N)fw.add(i, a[i]);
    rep(_, Q) {
        ll com;
        cin >> com;
        if (com == 0) {
            ll p, x;
            cin >> p >> x;
            fw.add(p, x);
        }
        else {
            ll l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 12136
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;
int max(int A, int B) {
	if (A > B) { return A; }
	return B;
}

int N;
int a[100000], b[100000];
int color_list[100000];
vector <int> adj_edges[100000];

int main() {
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		adj_edges[a[i]].push_back(i);
		adj_edges[b[i]].push_back(i);
	}

	for (int i = 0; i < N - 1; i++) {
		color_list[i] = -1;
	}

	int max_adj = 0;
	for (int i = 0; i < N; i++) {
		max_adj = max(max_adj, adj_edges[i].size());

	}
	cout << max_adj << "\n";
	int color_used[100000];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < max_adj; j++) {
			color_used[j] = 0;
		}
		for (int j = 0; j < adj_edges[i].size(); j++) {
			if (color_list[adj_edges[i][j]] != -1) {
				color_used[color_list[adj_edges[i][j]]] = 1;
			}
		}
		int p = 0;
		for (int j = 0; j < adj_edges[i].size(); j++) {
			if (color_list[adj_edges[i][j]] == -1) {
				while (color_used[p] == 1) {
					p++;
				}
				color_list[adj_edges[i][j]] = p;
				color_used[p] = 1;
			}
		}

	}

	for (int i = 0; i < N - 1; i++) {
		cout << color_list[i] + 1 << "\n";
	}
}

Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  string a,b;
  cin >> a >> b;
  string s = a+ b;
  int c = atoi(s.c_str());
  REP(i,c) {
    if (i*i == c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n,m,q = list(map(int,input().split()))
c = []
query = []

for i in range(n):
  c.append([0*i for i in range(n)])
for i in range(m):
  train = []
  train = list(map(int,input().split()))
  c[train[0]-1][train[1]-1] += 1
for i in range(q):
  query.append(list(map(int,input().split())))

for i in range(n):    
  for j in range(n):
    if j > 0:
      c[i][j] += c[i][j-1]
    else:
      pass

for i in range(n):    
  for j in range(n):
    if i > 0:
      c[i][j] += c[i-1][j]
    else:
      pass

for l in query:    
  if l[0]-1 >= 1 and l[1]-1 >= 1:
    print(c[l[1]-1][l[1]-1] - c[l[1]-1][l[0]-2] - c[l[0]-2][l[1]-1] + c[l[0]-2][l[0]-2])
  elif l[1]-1 > 0:
    print(c[l[1]-1][l[1]-1])
  else:
    print(c[0][0])

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

int main(){
  int n,ue,sita,kotae=0;
  cin>>n;
  ue=n/100;
  sita=n%100;
  if(0<ue&&ue<13){
    kotae++;
  }
  if(0<sita&&sita<13){
    kotae+=2;
  }
  switch(kotae){
    case 0:
      cout<<"NA";
      break;
    case 1:
      cout<<"MMYY";
      break;
    case 2:
      cout<<"YYMM";
      break;
    case 3:
      cout<<"AMBIGUOUS";
      break;
  }
}
  

Measured memory_bytes: 256
<?php
$p = [10,2,1];
$a[] = trim(fgets(STDIN));
$a[] = trim(fgets(STDIN));
$a[] = trim(fgets(STDIN));
$sum = trim(fgets(STDIN)) / 50;

$dp[0][0] = 1;
for($i = 1; $i <= 3; $i++){
    foreach($dp[$i - 1] as $price => $count){
        for($j = 0; $j <= $a[$i - 1]; $j++){
            @$dp[$i][$price + $p[$i-1] * $j] += $dp[$i-1][$price];
        }
    }
}
echo @$dp[3][$sum]+0;



Measured memory_bytes: 4604
//Bismillahir Rahmanir Rahim//
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int c=0;
    cin>>s;
    if(s[0]=='R') c++;
    if(s[1]=='R') c++;
    if(s[2]=='R') c++;
    if(s[1]=='S'&&s[0]=='R'&&s[2]=='R') c--;
    cout<<c<<endl;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
  int n;
  scanf("%d",&n);
  int ne=0;
  int i=1;
  while(n!=0)
  {
    int dig=n%10;
    if(dig==1)
      ne+=9*i;
    else
      ne+=i;
    i*=10;
    n/=10;
  }
  printf("%d",ne);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin>>k;
  cin>>a>>b;
  int falt=0;
  for(int i=1;i<1000;i++){
    int x=k*i;
    if(x>=a&&x<=b){
      falt=1;
      break;
    }
    if(x>b) break;
  }
  if(falt){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3596
def resolve():
    N = int(input())
    H = list(map(int, input().split()))
    ans = [0]
    count = 0
    for i in range(len(H) - 1):
        if H[i] >= H[i + 1]:
            count += 1
        else:
            ans.append(count)
            count = 0
    if count != 0:
        ans.append(count)
    print(max(ans))
resolve()

Measured memory_bytes: 20520
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &k)
	answer := findMax(a, b, c, k)
	fmt.Println(answer)
}

func findMax(a, b, c, k int) int {
	if a >= k {
		return k
	}
	if a+b < k {
		return a - (k - a - b)
	}
	return a
}


Measured memory_bytes: 1816
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 60

int main(){

	int N;
	scanf("%d",&N);

	int table[N];

	int num_2 = 0,num_neg2 = 0,num_neg1 = 0;

	for(int i = 0; i < N; i++){
		scanf("%d",&table[i]);

		switch(table[i]){
		case 2:
			num_2++;
			break;
		case -2:
			num_neg2++;
			break;
		case -1:
			num_neg1++;
			break;
		default:
			//Do nothing
			break;
		}
	}

	if(num_neg2%2 == 0){
		num_neg1 = 0;
	}else{
		if(num_neg1 == 0){
			num_neg2 -= 1;
		}else{
			num_neg1 = 1;
		}
	}

	printf("%d\n",num_2+num_neg2+num_neg1);

	for(int i = 0; i < N; i++){
		switch(table[i]){
		case 2:
			printf("%d\n",i+1);
			break;
		case -2:
			if(num_neg2 > 0){
				printf("%d\n",i+1);
				num_neg2--;
			}
			break;
		case -1:
			if(num_neg1 > 0){
				printf("%d\n",i+1);
				num_neg1--;
			}
			break;
		default:
			//Do nothing
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 3220