akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int w, h;
char map_[20][20];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int fill(int x, int y) {
    int count = 1;
    map_[x][y] = '#';
    for (int i=0; i<4; i++) {
        int x_new = x+dx[i];
        int y_new = y+dy[i];
        if (0 <= x_new && x_new < w && 0 <= y_new && y_new < h) {
            if (map_[x_new][y_new] == '.') {
                count += fill(x_new, y_new);
            }
        }
    }
    return count;
}

int main() {
    int x_start, y_start;
    while (true) {
        cin >> w >> h;
        if (w == 0) {
            break;
        }
        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                cin >> map_[j][i];
                if (map_[j][i] == '@') {
                    x_start = j;
                    y_start = i;
                }
            }
            cin.ignore(1);
        }
        cout << fill(x_start, y_start) << endl;
    }
    return 0;
}

Measured memory_bytes: 1172
#include<stdio.h>

int selectionSort(int A[], int N){
	int i, j, t, sw = 0, minj;
	for ( i = 0; i < N - 1; i++ ){
		minj = i;
		for( j = i; j < N; j++ ){
			if( A[j] < A[minj] )minj = j;
		}
		t = A[i]; A[i] = A[minj]; A[minj] = t;
		if( i != minj ) sw++;
	}
	return sw;
}

int main(void){
	int A[100], N, i, sw;
	
	scanf( "%d", &N);
	for( i = 0; i < N; i++ ) scanf("%d",&A[i]);
	
	sw = selectionSort(A, N);
	
	for( i = 0; i < N; i++ ){
		if( i > 0 ) printf(" ");
		printf( "%d", A[i]);
	}
	
	printf("\n");
	printf("%d\n", sw);
	
	return 0;
}


Measured memory_bytes: 2104
# 問題文
# 高橋君の夏休みはN日間です。
# 夏休みの宿題が M個出されており、i番目の宿題をやるにはAi日間かかります。
# 複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
# 夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか？
# ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。

# n（夏休みの日数）,m（宿題の数）：標準入力
# リストの中のA(宿題日)：リストを作成し、標準入力
n, m = map(int, input().split())
A = list(map(int, input(). split()))

# 最大で n −合計(A1+. . .+AM)日間遊ぶことができる
if n < sum(A):   # 夏休みの日数より宿題日が多い場合：宿題をやる日数が足りない→終わらせることができない
    print(-1)
else:
    print(n-sum(A)) # その他→宿題は終わる→夏休みの日数-宿題日

# NameError: name 'N' is not defined

Measured memory_bytes: 9828
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

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

	int n = s.size();
	
	while (1) {
		n -= 2;
		string a = s.substr(0, n / 2);
		string b = s.substr(n / 2, n / 2);
		if (a == b) {
			cout << n << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= 4; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

/* a と b の最小公倍数を求める */
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}

ll power(ll a, ll b)
{
     ll pow = 1;
     while ( b ) 
     {
            if ( b & 1 ) 
            {
              pow = pow * a;
              --b;
            }
            a = a*a;
            b = b/2;
     }
     return pow;
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N), b(N);
    vector< map<ll, ll> > factors(N);
    REP(i, N) {
        cin >> a[i];
        b[i] = a[i] / 2;
        factors[i] = prime_factor(b[i]);
    }

    ll n_2power_min = 1e9, n_2power_max = 0;
    REP(i, N) {
        n_2power_min = min(n_2power_min, factors[i][2]);
        n_2power_max = max(n_2power_max, factors[i][2]);
    }
    if(n_2power_min != n_2power_max) {
        cout << 0 << endl;
        return 0;
    }

    map<ll, ll> lcm_factors;
    ll lcm = 1;
    REP(i, N) {
        lcm = LCM(lcm, b[i]);
        if(lcm > M) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (M / lcm - 1) / 2 + 1 << endl;
    return 0;
}


Measured memory_bytes: 22016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    vector<int> b(n - 1);
    for (int i = 0; i < n - 1; i++) {
        cin >> b[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            sum += b[i];
        } else if (i == n - 1) {
            sum += b[i - 1];
        } else {
            sum += min(b[i - 1], b[i]);
        }
    }
    cout << sum << endl;
    return 0;
}

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

ll MARCH[5];
int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

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

    int n;
    cin >> n;

    ll m, a, r, c, h;
    m = a = r = c = h =0;
    REP(i, n) {
        string s;
        cin >> s;
        if (s[0] == 'M') m++;
        if (s[0] == 'A') a++;
        if (s[0] == 'R') r++;
        if (s[0] == 'C') c++;
        if (s[0] == 'H') h++;
    }

    MARCH[0] = m;
    MARCH[1] = a;
    MARCH[2] = r;
    MARCH[3] = c;
    MARCH[4] = h;

    ll ans = 0;
    REP(i, 10)
        ans += MARCH[P[i]] * MARCH[Q[i]] * MARCH[R[i]];

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#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>;
const int MOD=1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans=0;
  rep(i,n-1) {
    for(int j=i+1; j<n; j++) {
      ans+=a[i]*a[j];
    }
  } 

  cout << ans << endl;
}


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

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
    V[i] = abs(X - V[i]);
  }
  int ans = V[0];
  for (int i = 1; i < N; i++) {
    ans = gcd(ans, V[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	int n, k; cin >> n >> k;
	ll out = n / k;
	out = out * out*out;
	if (k%2 == 0) {
		int d = k / 2;
		if (n >= d) {
			ll add = (n - d) / k + 1;
			add = add * add*add;
			out += add;
		}
	}
	cout << out << endl;
	return 0;
}

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

using ll = long long;

int main()
{
    int N, T;
    std::cin >> N >> T;

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

    int min = 1001;
    for (int i = 0; i < N; i++)
    {
        if (t[i] <= T)
        {
            min = std::min(c[i], min);

        }
    }

    if (min == 1001)
    {
        std::cout << "TLE" << std::endl;
    }
    else
    {
        std::cout << min << std::endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pair<int,int>>
#define mi          map<int,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(i=a;i<b;i++)
#define inf         INT_MAX

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

using namespace std;
void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)cout<<n*t/x;
    else cout<<(n/x+1)*t;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
	int a[11][11],n,i,j;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)
		{
			a[i][n] = 0;
			for(j=0;j<n;++j)
			{
				scanf("%d", &a[i][j]);
				a[i][n] += a[i][j];
			}
		}
		for(j = 0; j <= n; ++j)
		{
			a[n][j] = 0;
			for(i = 0; i < n; ++i)
				a[n][j] += a[i][j];
		}
		for(i = 0; i <= n; ++i)
		{
			for(j = 0; j <= n; ++j)
			{
				printf("%5d",a[i][j]);
			}
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const bool DEBUG = 0;
const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s,t; cin>>s>>t;
	ll ans=INF;
	forn(i,0,s.length()-t.length()+1)
	{
		ll sum=0;
		forn(j,i,i+t.length())
		{
			if(s[j]!=t[j-i]) sum++;
		}
		ans=min(ans, sum);
	}
	
	cout<<ans<<'\n';
	
	return 0;
}


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

int main(){
  int r, c, sheet[100][100], rsum[100] = {0}, csum[101] = {0};
  cin >> r >> c;
  for(int i = 0; i < r; i++){
  	for(int j = 0; j < c; j++){
  		cin >> sheet[i][j];
  		rsum[i] += sheet[i][j];
  	}
  }
  for(int i = 0; i < c; i++){
  	for(int j = 0; j < r; j++){
  		csum[i] += sheet[j][i];
  	}
  	csum[c] += csum[i];
  }
  for(int i = 0; i < r; i++){
  	for(int j = 0; j < c; j++){
  		cout << sheet[i][j] << ' ';
  	} 
  	cout << rsum[i] << endl;
  }
  for(int i = 0; i < c; i++){
  	cout << csum[i] << ' ';
  }
  cout << csum[c] << endl;
  return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template <typename T>
void vecin(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vint a(m), b(m);
    vector<vint> c(m, vint(n));
    REP(i,m){
        cin >> a[i] >> b[i];
        REP(j,b[i]){
            cin >> c[i][j];
        }
    }
    vint kagi(m);
    REP(i,m){
        int now = 0;
        REP(j,b[i]){
            now += (1 << (c[i][j] - 1));
        }
        kagi[i] = now;
        //cout << now << endl;
    }
    vector<vector<ll>> dp(m + 1, vector<ll>((1 << n) + 1, INF));
    REP(i,m + 1){
        dp[i][0] = 0;
    }
    REP(i, m)
    {
        for (int j = 0; j < (1 << n); ++j)
        {
            dp[i + 1][j | kagi[i]] = min(dp[i + 1][j | kagi[i]], dp[i][j] + a[i]);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    /*
    ll ans = INF;
    REP(i, m + 1)
    {
        ans = min(ans, dp[i][(1 << n) - 1]);
    }*/
    /*
    REP(i, m+1)
    {
        for (int j = 0; j < (1 << n); ++j)
        {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }/*/
    //if (ans == INF){
    if (dp[m][(1 << n) - 1] == INF){
        cout << -1 << endl;
    }else{
        cout << dp[m][(1 << n) - 1] << endl;
    }
}

Measured memory_bytes: 32384
import java.util.*;
 
public class Main{
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
    	int num1 = sc.nextInt();
        int num2 = sc.nextInt();
		if(num1 == 2 && num2 == 2){
        	System.out.println("Yes");
        }else if((num1 == 4 || num1 == 6 || num1 == 9 || num1 == 11) 
                 && (num2 == 4 || num2 == 6 || num2 == 9 || num2 == 11)){
        	System.out.println("Yes");
        }else if((num1 == 1 || num1 == 3 || num1 == 5 || num1 == 7 || num1 == 8 || num1 == 10 || num1 == 12) 
                 && (num2 == 1 || num2 == 3 || num2 == 5 || num2 == 7 || num2 == 8 || num2 == 10 || num2 == 12)){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
	}
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

ll n, m;

ll ans;

int main(void) {
  // Here your code !
  scanf("%lld %lld", &n, &m);

  if (m == 1 && n == 1) {
    ans = 1;
  }
  else if (m == 1 && n > 1) {
    ans = n - 2;
  }
  else if (m > 1 && n == 1) {
    ans = m - 2;
  }
  else {
    ans = (n - 2) * (m - 2);
  }

  printf("%lld\n", ans);

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI k(m), p(m);
  VVI s(m, VI(n, 0));
  rep(i, m) {
    cin >> k[i];
    rep(j, k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, m) {
    int q;
    cin >> q;
    p[i] = q % 2;
  }
  int ans = 0;
  for(int i = 0; i < 1 << n; ++i) {
    bool flag = true;
    rep(j, m) {
      int sum = 0;
      rep(l, k[j]) sum += (i >> s[j][l]) & 1;
      if((sum & 1) != p[j]) flag = false;
    }
    if(flag) ans++;
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

bool isStringEven(std::string const & str) {
	if (str.length() % 2 == 1) return false;

	std::size_t length = str.length();
	return str.substr(0, length / 2) == str.substr(length / 2, length / 2);
}

int main() {
	std::string S;
	std::cin >> S;

	for (std::size_t i = S.length() - 1; i >= 1; --i) {
		std::string str = S.substr(0, i);
		if (isStringEven(str)) {
			std::cout << str.length() << std::endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline

from collections import Counter

class Osa_k:
    def __init__(self, n):
        self.n = n
        self.min_factor = [int(x) for x in range(n+1)]
        
        self.is_prime = [True] * (self.n + 1)
        self.is_prime[0] = False
        self.is_prime[1] = False
        for j in range(4, self.n+1, 2):
            self.is_prime[j] = False
            self.min_factor[j] = 2
        for i in range(3, int(self.n**0.5) + 1, 2):
            if not self.is_prime[i]:
                continue
            for j in range(i * 2, self.n + 1, i):
                self.is_prime[j] = False
                if self.min_factor[j] >= i:
                    self.min_factor[j] = i
    
    def calulate(self, x):
        ans = []
        while x > 1:
            key = self.min_factor[x]
            while x%key == 0:
                ans.append(key)
                x //= key
        counter = set(ans)
        return counter
        

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    key = a[0]
    sc = False
    for i in range(1, n):
        key = math.gcd(key, a[i])
    
    if key == 1:
        sc = True
    
    
    pc = True
    osak = Osa_k(10**6+1)
    
    sub = set()
    
    judge = dict()
    for i in range(n):
        key = osak.calulate(a[i])
        for v in key:
            if v in judge:
                pc = False
            judge[v] = 1
            
    
    if pc:
        print("pairwise coprime")
    elif sc:
        print("setwise coprime")
    else:
        print("not coprime")

    
    
    
    
    
if __name__ == "__main__":
    main()



Measured memory_bytes: 207624
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a;
	cin >> a;
	int y;
	cin>> y;
	if (y%2==0 && y>=2*a && y<=4*a) cout << "Yes";
	else cout<< "No";

	
	
	
	return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#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)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[1000][1000];

int main(){
  int n,K;
  cin >> n >> K;
  ll h[n+1]={};
  rep(i,n)cin >> h[i+1];
  rep(i,500)rep(j,500)dp[i][j]=longinf;
  dp[0][K]=0;
  ll ans=longinf;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=K;j++){
      if(dp[i][j]<longinf){
        for(int k=i+1;k<=min(n,i+j+1);k++){
          dp[k][j-(k-i-1)]=min(dp[k][j-(k-i-1)],dp[i][j]+max(0LL,h[k]-h[i]));
        }
      }
    }
  }
  for(int i=0;i<=n;i++)for(int j=0;j<=K;j++)if(i+j>=n)ans=min(ans,dp[i][n-i]);
  cout << ans << endl;
return 0;}

Measured memory_bytes: 4352
while True:
    H,W = map(int,input().split())
    if H == W == 0:
        break
    else:
        for j in range(H):
            for i in range(W):
                if (i+j) % 2 == 0:
                    print("#", end="")
                else:
                    print(".", end="")
            print()
        print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int A,B,C;

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

Measured memory_bytes: 256
N=int(input())
num=0
ans='No'
for i in range(1,10**3):
    if i*(i+1)>2*N:
        break
    elif i*(i+1)==2*N:
        num=i
        ans='Yes'
        break
print(ans)
if ans=='Yes':
    print(num+1)
    arr=[[num] for i in range(num+1)]
    n=1
    for i in range(num+1):
        j=1
        while len(arr[i]) != num+1:
            arr[i].append(n)
            arr[i+j].append(n)
            j+=1
            n+=1
    
    for a in arr:
        print(a[0],end='')
        for x in a[1:]:
            print(' {}'.format(x),end='')
        print('')

Measured memory_bytes: 9424
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

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

signed main(){
    int m, n;
    while(1){
        cin >> m >> n;
        if(m + n == 0) break;
        string s;
        int k, y = 0, x = 0, dir = 0;
        for(int c = 2;; c++){
            cin >> s;
            if(s == "STOP") break;
            if(s == "RIGHT") dir = (dir + 1) % 4;
            else if(s == "LEFT") dir = (dir + 3) % 4;
            else if(s == "BACKWARD" || s == "FORWARD"){
                cin >> k;
                int p = 1;
                if(s == "BACKWARD") p = -1;
                rep(i, 0 ,k){
                    int ty = y + p*dy[dir];
                    int tx = x + p*dx[dir];
                    if(!(0 <= ty && ty < n && 0 <= tx && tx < m)) break;
                    y = ty; x = tx;
                }
            }
            //cout << c << ' ' << x << ' ' << y << endl;
        }
        cout << x + 1 << ' ' << y + 1 << endl;
    }
}

Measured memory_bytes: 1212
import numpy as np
N = int(input())
Abs = int(np.sqrt(N))
if Abs ** 2 == N:
    print(Abs + Abs - 2)
else:
    min = N + 1
    min_i = 1
    for i in range(1, Abs + 1):
        tmp = N // i
        if tmp * i == N:
            if min > tmp:
                min = tmp
                min_i = i
    print(min + min_i - 2)

Measured memory_bytes: 14240
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3636
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
f = 0
ans = 1
for i in 1..n-1
  if f == 0
    if a[i] > a[i-1]
      f = 1
    elsif a[i] < a[i-1]
      f = 2
    end
  elsif f == 1
    if a[i] < a[i-1]
      f = 0
      ans += 1
    end
  else
    if a[i] > a[i-1]
      f = 0
      ans += 1
    end
  end
end
p ans

Measured memory_bytes: 9484
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]
N, A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip().split()[0]

A-=1
B-=1
C-=1
D-=1

stone = []
count=0
for i in range(N-1):
  if S[i]=="#" and S[i+1]=="#":
    count +=1
  stone.append(count)

def f(i, j):
  s = stone[j-1] - stone[i]
  if s==0:
    return True
  else:
    return False

if C < B:
  if f(A,C) and f(B,D):
    print("Yes")
  else:
    print("No")
elif C < D:
  if f(A,C) and f(B,D):
    print("Yes")
  else:
    print("No")
else:
  space = []
  count=0
  for i in range(N-2):
    if S[i]=="." and S[i+1]=="." and S[i+2]==".":
      count +=1
    space.append(count)
  
  s = space[D-1]-space[B-2]
  if s != 0:
    if f(A,C):
      print("Yes")
    else:
      print("No")
  else:
    print("No")
    
                   

Measured memory_bytes: 18884
#include<bits/stdc++.h>
#define H 500005
using namespace std;
int h,A[H];

void maxHeapify(int x){
  int l=x*2,r=x*2+1,lag;
  if(l<=h&&A[l]>A[x])lag=l;
  else lag=x;
  if(r<=h&&A[r]>A[lag])lag=r;
  if(lag!=x){
    swap(A[x],A[lag]);
    maxHeapify(lag);
  }
}

void buildMaxHeap(){
  for(int i=h/2;i>=1;i--)
    maxHeapify(i);
}

int main(){
  cin>>h;
  for(int i=1;i<=h;i++)cin>>A[i];
  buildMaxHeap();
  for(int i=1;i<=h;i++)
    cout<<" "<<A[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int h,n; cin >> h >> n;
  int sum=0; 
  REP(i,n){
    int tmp;
    cin >> tmp;
    sum += tmp;
  }
  if( sum >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 3640
from sys import stdin
def LI(): return list(map(int,stdin.readline().rstrip().split()))
 
inp = LI()
n,Y = [inp.pop(0) for _ in range(2)]

Y = Y//1000
for i in range(n,-1,-1):
    if 10*i<=Y:
        for j in range(n-i,-1,-1):
            tmp = 10*i+5*j+n-i-j
            if tmp == Y:
                print(str(i)+' '+str(j)+' '+str(n-i-j))
                exit()
            elif tmp < Y:
                break

print('-1 -1 -1')

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

int b(int d, int n) {

  if(d == 0) {
    if(n==100) {
      return 101;
    }
    return n;
  }
  if(d==1) {
    if(n == 100) {
      return 10100;
    }
    return 100*n;
  }
  if(n == 100) {
    return 1010000;
  }
  return n * 10000;
}


int main() {
  int d, n;
  cin >> d >> n;
  cout << b(d, n);
}

Measured memory_bytes: 3620
import sys
from operator import itemgetter

def solve():
    input = sys.stdin.readline
    N = int(input())
    work = [[int(i) for i in input().split()] for _ in range(N)]
    work.sort(key = itemgetter(1))
    currentTime = 0
    for i in range(N):
        a, b = work[i]
        if a + currentTime <= b:
            currentTime += a
        else:
            print("No")
            break
    else: print("Yes")

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 41196
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
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 LINF (long long)4e18

using ll = long long;



int main(){
  string S; cin >> S;
  int n = S.size();
  int ans = 0;
  repr(i,2,n){
    string S2 = S.substr(0,i);
    int n2 = S2.size();
    bool ok = false;
    if(n2 % 2 == 0){
      string S21 = S2.substr(0,n2 / 2);
      string S22 = S2.substr(n2 / 2,n2 / 2);
      if(S21 == S22) ok = true;
    }
    if(ok) ans = max(ans,n2);
  }
  cout << ans << endl;
}
  


  


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

int n, a, b;

int f(int n)
{
    int t = 0;
    for (; n; t += n % 10, n /= 10);
    return !(t < a || t > b);
}
int main()
{
    cin >> n >> a >> b;

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += f(i) * i;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

int main(){
    int N; cin >> N;
    double ans = 0;
    rep(i, 0, N){
        double x; string u;
        cin >> x >> u;
        if(u == "BTC"){
            ans += x * 380000;
        } else {
            ans += x;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3756
#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>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i = 1; i <= n; ++i) cin >> a.at(i);
    
    vector<int> box(n+1);
    for (int i = n; 0 < i; --i) {
        int sum = 0;
        for (int j = i; j <= n; j += i) {
            sum += box.at(j);
        }
        sum %= 2;
        box.at(i) = (sum + a.at(i)) % 2;
    }

    int m = 0;
    vector<int> b;
    for (int i = 1; i <= n; ++i) {
        m += box.at(i);
        if (box.at(i) == 1) b.push_back(i);
    }

    int x = b.size();
    cout << m << endl;
    rep(i,x) {
        cout << b.at(i);
        if (i < x-1) cout << ' ';
    }
    if (0 < x) cout << endl;
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

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

int main(int argc, char *argv[])
{
  int n, a;
  while (cin >> n >> a) {
    int x[n];
    for (int i = 0; i < n; ++i) {
      cin >> x[i];
    }

    const int N = 53;
    const int SUM = N * 51;
    static lli dp[N][N][SUM];
    fill(&dp[0][0][0], &dp[N - 1][N - 1][SUM - 1] + 1, 0);
    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < N; ++j) {
        for (int k = 0; k < SUM; ++k) {
          unless (dp[i][j][k]) continue;
          // choose
          dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
          // ignore
          dp[i + 1][j][k] += dp[i][j][k];
        }
      }
    }
    
    lli s = 0;
    for (int card = 1; card < N; ++card) {
      for (int sum = 0; sum < SUM; ++sum) {
        if (sum % card == 0 && sum / card == a) {
          s += dp[n][card][sum];
        }
      }
    }

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


Measured memory_bytes: 59520
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll x;
    cin >> x;
    ll p = x / 500;
    ll q = (x - 500 * p) / 5;
    cout << 1000 * p + 5 * q << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
prevt,prevx,prevy = 0,0,0
for i in range(N):
    t, x, y = map(int,input().split())
    dt,dx,dy = t-prevt,x-prevx,y-prevy
    if dt < dx+dy or (dt-dx-dy)%2 != 0:
        print('No')
        exit()
    prevt,prevx,prevy = t,x,y
print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
#include <functional>
 
using namespace std;
typedef long long ll;
const ll INF = 1e18;

# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()
# define pb push_back
 
ll N, M;

bool isPalindrome(string s) {
  string t = s;
  reverse(t.begin(), t.end()); // t をひっくり返す
  return s == t; // 比較する
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    bool ans = true;
    if (!isPalindrome(s)) {
        ans = false;
    }
    string leftSub = s.substr(0, s.size()/2);
    if (!isPalindrome(leftSub)) {
        ans = false;
    }
    
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 384
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex> //正規表現
using namespace std;
#define _GLIBCXX_DEBUG /GCC環境下で[]による配列要素参照のエラーを出す
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
  int n;
  cin>>n;
  vector<int>vec(n);
  char stone;
  rep(i,n){
    cin>>stone;
    //cout<<stone;
    if(stone=='R'){
      vec.at(i)=1;
    }else{vec.at(i)=0;}
    //cout<<vec[i];
  }

  int R,W;
  R=0;
  W=n-1;
  int cnt=0;
  
  while(R<=n-1&&vec.at(R)==1){
    R+=1;
  }
  while(W>=0&&vec.at(W)==0){
    W-=1;
  }
  //cout<<R<<W<<endl;
  if(R>=W){
    cout<<0;
    return 0;
  }
  while(R<W){
      cnt+=1;
      vec.at(R)=1;
      vec.at(W)=0;
     while(R<=n-1&&vec.at(R)==1){
    R+=1;
  }
  while(W>=0&&vec.at(W)==0){
    W-=1;
  }
  if(R>=W){
    cout<<cnt;
    return 0;
  }
} 
}

  

Measured memory_bytes: 4028
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N, Q; cin >> N >> Q;
		if (N == 0 && Q == 0) break;
		vector<int> a(100);
		while (N--) {
			int M; cin >> M;
			while (M--) {
				int i; cin >> i;
				a[i]++;
			}
		}
		int _i = 0; Q--;
		for (int i = 1; i < 100; i++)
			if (a[i] > Q) {
				_i = i;
				Q = a[i];
			}
		cout << _i << endl;
	}
}

Measured memory_bytes: 1200
num = [int(x) for x in input().split()]
num.sort()
cnt = 0
while True:
    if num[0] == num[1] and num[1] == num[2]:
        break
    cnt += 1
    if num[1] == num[2]:
        if num[0] < num[1]:
            num[0] += 2
        else:
            num[1] += 1
            num[2] += 1
    else:
        num[0] += 1
        num[1] += 1
print(cnt)


Measured memory_bytes: 3060
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] data = Console.ReadLine().Split(' ');
        double a = double.Parse(data[0]);
        double b = double.Parse(data[1]);
        double C = double.Parse(data[2]);
        double radian = C / 180 * Math.PI;
        double h = b * Math.Sin(radian);
        double S = a * b * Math.Sin(radian) / 2;
        double L = a + b + Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(radian));
        Console.WriteLine("{0:f7}", S);
        Console.WriteLine("{0:f7}", L);
        Console.WriteLine("{0:f7}", h);
    }
}

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

using namespace std;
const int N = 1e5 + 3;
int n, a[N], gcdL[N], gcdR[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		gcdL[i] = __gcd(gcdL[i - 1], a[i]);
	}
	for (int i = n; i; --i)
		gcdR[i] = __gcd(gcdR[i + 1], a[i]);
	int res = 0;
	for (int i = 1; i <= n; ++i)
		res = max(res, __gcd(gcdR[i + 1], gcdL[i - 1]));
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
int c=a+b;
if(c%3==0 || a%3==0 || b%3==0)
cout<<"Possible";
else
cout<<"Impossible";
system("pause");
return 0;
}

Measured memory_bytes: 504
Format = ["((( a . b ) . c ) . d )", "(( a . b ) . ( c . d ))", "(( a . ( b . c )) . d )", "( a . (( b . c ) . d ))", "( a . ( b . ( c . d )))"]
Operator = ["*", "+", "-"]
def rec(expression)
  return [expression] if !expression.include?(".")
  result = Array.new
  Operator.each do |operator|
    result += rec(expression.sub(/\./, operator))
  end
  result
end
while (a, b, c, d = gets.chomp.split.sort).find{|v| v != "0"} do
  answer = ""
  [a, b, c, d].permutation(4) do |list|
    Format.each do |expression|
      list.each do |n|
        expression = expression.sub(/[a-d]/, n)
      end
      rec(expression).each do |e|
        answer = e if eval(e) == 10
      end
    end
  end
  puts answer != "" ? answer : "0"
end

Measured memory_bytes: 6356
#include <bits/stdc++.h>
#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)
#define sp(n) setprecision(n)
#define mp make_pair
#define mt make_tuple
#define pi 3.14159265358979323846264
#define MOD 1000000007

using namespace std;
/*
int primeFactors(ll n)  
{  ll f=0;
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        f++;
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            f++; 
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        f++;
        
 return f;        
}  
  
bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = ((C[i - 1][j - 1] + C[i - 1][j]))%MOD;}}}
    return C[n][k];
 }
 
ll gcd(ll a, ll b){if (b == 0)
        return a;return gcd(b, a % b);}
 
ll expmod(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}
//define temp-functions below
 
 
//some definitions and global variables
vector<ll> primes;
void storePrime(ll n){
    fori(n){
        if(isPrime(i+1)&&(n%(i+1)==0)){primes.push_back(i+1);}
    }
}*/


int main(){ //ake cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
 ll k,a,b;
 cin>>k>>a>>b;
 if(k==1||a%k==0||b%k==0) {cout<<"OK";return 0;}
 a=a/k;b=b/k;
 if(a==b) {cout<<"NG";return 0;}
 cout<<"OK";




return 0;}

Measured memory_bytes: 3648
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
tree=[[] for i in range(n)]
for i in range(m):
    a,b=MI()
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)
q=deque([0])
ind=[-1 for i in range(n)]
#print(tree)
ind[0]=0
while q:
    u=q.popleft()
    #print(u)
    for j in tree[u]:
        if ind[j]<0:
            ind[j]=u
            q.append(j)
#print(ind)
print("Yes")
for i in range(1,n):
    print(ind[i]+1)

Measured memory_bytes: 34212
n = int(input())
A = list(map(int,input().split()))
B = A.copy()
A.sort()

ans_ato = A[n//2]
ans_mae = A[n//2-1]

for b in B:
    if b < ans_ato:
        print(ans_ato)
    else:
        print(ans_mae)

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

int a[3];

int main() {
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a+3);

    if (a[0] + a[1] == a[2]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	string s;
	cin >> s;
	int cur = 0;
	int ans = 0;
	rep(i, 3) {
		if (s[i] == 'R') cur++;
		else cur = 0;
		chmax(ans, cur);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.lang.*

fun main(args: Array<String>) {
    val H = readLine()!!.toInt()
    val W = readLine()!!.toInt()
    val N = readLine()!!.toInt()

    val max = Math.max(H,W).toDouble()

    println(Math.ceil(N.toDouble()/max).toInt())

}

Measured memory_bytes: 29820
function Main(input) {
  input = input.trim().split('\n');
  H = Number(input[0].split(' ')[0]);
  M = input.slice(1).map(v => v.split(' ').map(Number));

  dp = Array(H + 1).fill(Infinity);
  dp[0] = 0;
  M.forEach(item => {
    for (i = 0; i <= H; i=(i+1)|0) {
      targetPointIndex = Math.min(i + item[0], H);
      dp[targetPointIndex] = Math.min(dp[targetPointIndex], dp[i] + item[1]);
    }
  });
  console.log(dp[H]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10028
#include<cstdio>
bool red[100001],white[100001];
int num[100001];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    red[1]=true;
    white[1]=false;
    num[1]=1;
    for(int i=2;i<=n;i++){
        red[i]=false;
        white[i]=true;
        num[i]=1;
    }
    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        num[x]--;
        num[y]++;
        red[y]=red[x]||red[y];
        white[y]=white[x]||white[y];
        red[x]=red[x]&&(num[x]>0);
        white[x]=white[x]&&(num[x]>0);
    }
    int ans=0;
    for(int i=1;i<=n;i++)if(red[i])ans++;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 768
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        String S = sc.next();
      int a = 1;//初期値には必ず1匹は存在しているため0ではない
      for(int i =1; i<N; i++){
      if(S.charAt(i)!=S.charAt(i-1)){//後半のchar()-1は公式である,ここでi=0にしてしまうとマイナスの数値が出てきてしまう
        a = a+1;                     //1番目と0番目の文字が違っている場合文字のカウントを行う
      }
      }
      System.out.println(a);//異なった文字ではない場合,カウントしない
    }
}

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

typedef long long ll;
const ll inf=1e18;
int N;
ll a[500];
ll sum[500]={};
vector<vector<ll>> dp;

ll solve(int l=0,int r=N){
    if(r-l==1) return 0;
    ll &ret=dp[l][r];
    if(ret!=inf) return ret;
    for(int i=l+1;i<=r-1;i++){
        ret=min(ret,solve(l,i)+solve(i,r)+sum[r]-sum[l]);
        //cout << ret << endl;
    }
    return ret;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=1;i<=N;i++){
        sum[i]=sum[i-1]+a[i-1];
    }
    dp.assign(N+1,vector<ll>(N+1,inf));
    ll ans=solve();
    cout << ans << endl;
}

Measured memory_bytes: 1536