akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<vector<int> > edges;
int main(){
    int n, m;
    string s;
    cin >> n >> m >> s;
    edges.resize(4*n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        for(int q = 0; q < 2; q++){
            int num = 0;
            if(s[a] == 'A' && s[b] == 'A') num = 0;
            if(s[a] == 'A' && s[b] == 'B') num = 1;
            if(s[a] == 'B' && s[b] == 'B') num = 2;
            if(s[a] == 'B' && s[b] == 'A') num = 3;
            edges[4*a + num].push_back(4*b + (num+1) % 4);
            swap(a, b);
        }
    }
    vector<int> deg(4*n, 0);
    for(int a = 0; a < 4*n; a++){
        for(int b : edges[a]){
            deg[b]++;
        }
    }
    vector<int> bfs;
    int st = 0;
    for(int a = 0; a < 4*n; a++){
        if(deg[a] == 0) bfs.push_back(a);
    }
    while(st < bfs.size()){
        int a = bfs[st];
        st++;
        for(int b : edges[a]){
            deg[b]--;
            if(deg[b] == 0) bfs.push_back(b);
        }
    }
    
    if(bfs.size() < 4*n){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	double molecule = 1, denominator = 0;
	vector<int> a(n);
	rep (i, n) {
	  cin >> a[i];
	  molecule *= a[i];
	}
	rep (i, n) denominator += molecule / a[i];
	cout << fixed << setprecision(7);
	cout << molecule / denominator << endl;
    
    return 0;
}



Measured memory_bytes: 3832
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i)==82&&s.charAt(i+1)==76){
				int hoz = i;
				int rcnt = 0;
				int lcnt = 0;
				int k = 0;
				for(;s.charAt(hoz)==82&&hoz>=0;hoz--){
					if(k==0){
						lcnt++;
					}else{
						rcnt++;
					}
					k=1-k;
					if(hoz == 0)break;
				}
				hoz = i+1;
				k = 1;
				for(;s.charAt(hoz)==76&&hoz<s.length();hoz++){
					if(k==0){
						lcnt++;
					}else{
						rcnt++;
					}
					k=1-k;
					if(hoz == s.length()-1)break;
				}
				System.out.print(lcnt + " " + rcnt + " ");
				i++;
			}else{
				System.out.print(0 + " ");
			}
		}
	}
}


Measured memory_bytes: 33228
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}


int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//     int t;
//      cin >> t;

//      while(t--){

     
// }

   string s;
   cin >> s;
   int len = s.length();
   int val  = s[len-1] - '0';
   if(val == 2 || val == 4 || val == 5 || val == 7 || val == 9)cout << "hon" << endl;
   else if(val == 0 || val == 1 || val == 6 || val == 8)cout << "pon" << endl;
   else cout << "bon" << endl;


 

return 0;
}



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

using namespace std;
using ll = long long;

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

  const ll mod = 1e9 + 7;

  int n;
  cin >> n;

  vector<int> cnt(1e3 + 1);
  auto d = [&](int n) {
    for (int i = 2; i * i <= n; i++) {
      while (n % i == 0) {
        n /= i;
        cnt[i]++;
      }
    }
    if (n > 1)
      cnt[n]++;
  };

  for (int i = 1; i <= n; i++) {
    d(i);
  }

  ll ans = 1;
  for (int i = 2; i <= 1e3; i++) {
    ans = ans * (cnt[i] + 1);
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
N = int(input())

divs = [0]*(N+1)

for i in range(1,N+1):
    for j in range(1,N+1):
        if i*j > N:
            break
        divs[i*j] += 1

ans = 0
for i in range(1,N+1):
    ans += i*divs[i]
print(ans)



Measured memory_bytes: 145992
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, b, c;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
	int odd=0;
  int even=0;
    for (int i = 1; i <= n; i++)
    {
        if(i%2==0){
          even++;
        }
      else{
        odd++;
      }
    }
    cout << even*odd << "\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 10000000
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
int main()
{
	int n;
	cin >> n;
	char C[n+1];
	for(int i = 0; i < n; i++)
		cin >> C[i];
	int right = 0, left = 0;
	int ans = INF;
	for(int i = 0; i < n; i++)
	{
		if(i == 0)
		{
			for(int j = 1; j < n; j++)
			{
				if(C[j] == 'E')
					right++;
			}
		}
		else
		{
			if(C[i] == 'E')
				right--;
			if(C[i - 1] == 'W')
				left++;
		}
		if(right + left < ans)
			ans = right + left;
	//	cout << left << " " << right << endl;
	}
	cout << ans << endl;
	return 0;
}



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

using namespace std;

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

    int n, k; cin >> n >> k; vector<int> h(n), min_cost(n,INT_MAX);

    for(int i = 0; i < n; ++i)
        cin >> h[i];

    min_cost.front() = 0;

    for(int i = 1; i < n; i++)
        for(int j = 0, l = i-1; j < k and l >= 0; j++, l--)
            min_cost[i] = min(min_cost[i],min_cost[l]+abs(h[i]-h[l]));

    cout << min_cost.back();
}

Measured memory_bytes: 1024
N=int(input())
S=input()

answer=[]
sumple=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

for i in range(len(S)):
    answer.append(sumple[(sumple.index(S[i])+N+1)%26-1])
print(''.join(map(str,answer)))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#define _USE_MATH_DEFINENS
#include <cmath>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int a, b, h;
    cin >> a >> b >> h;

    cout << (a + b) * h / 2 << endl;
}


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

#define pb push_back
#define mp make_pair
#define F(i, a, n) for(int i=a;i<n;i++)
#define REP(i, n) F(i, 0, n)
#define REP1(i, n) for(int i=1;i<=n;i++)
#define REV(i, n) for(int i=n;i>=0;i--)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef unsigned long long ll;

const ll MAX = 1e6 + 5;

int n;
ll fac[MAX];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	fac[0] = 1;
	REP1(i, MAX){
		fac[i] = (fac[i - 1] % MOD) * (i % MOD); 
	}
	cin>>n;
	cout<<fac[n] % MOD;
	return 0;
}

Measured memory_bytes: 8064
from datetime import date
while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    result = date(2004, m, d).isoweekday()
    print("Monday"*(result==1)+"Tuesday"*(result==2)+"Wednesday"*(result==3)+"Thursday"*(result==4)+"Friday"*(result==5)+"Saturday"*(result==6)+"Sunday"*(result==7))

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


int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0;i<N;i++) cin >> H.at(i);
  
  int count = 1;
  int maxH = H.at(0);
  for(int i=1;i<N;i++){
    if(maxH<=H.at(i)){
      count++;
      maxH = H.at(i);
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ret = 0;
int dfs(vector<bool>& vu,vector<int>& val,vector<vector<int>>& adj,int node){
  if(vu[node]) return val[node];
  if(adj[node].empty()){
    val[node] = 0;
    return 0;
  }
  for(int i : adj[node]){
    val[node] = max(val[node],1+dfs(vu,val,adj,i));
  }
  vu[node] = true;
  return val[node];
}
int main(){
  int N,M,x,y;
  cin >> N >> M;
  vector<vector<int>> adj(N);
  while(M--){
    cin >> x >> y;
    adj[x-1].push_back(y-1);
  }
  vector<bool> vu(N);
  vector<int> val(N);
  int ret = 0;
  for(int i = 0; i < N; ++i) ret = max(ret,dfs(vu,val,adj,i));
  cout << ret;
  return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    map<string,ll> mp;
    rep(i,n){
        string s; cin >> s;
        sort(all(s));
        mp[s]++;
    }
    ll res = 0;
    for(auto a:mp){
        if(a.second >1)
            res += (a.second-1)*a.second/2;
    }
    cout << res << endl;
}


Measured memory_bytes: 11264
import numpy as np
n, k = map(int, input().split())
s = input()
s = s.replace('LR', 'L,R').replace('RL', 'R,L').split(',')
s = np.array(list(map(len, s))) - 1
ans = sum(s)
ans += k*2
ans = min(n-1, ans)
print(ans)

Measured memory_bytes: 15104
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const A = parseInt(args[0][0], 10)
	const B = parseInt(args[0][1], 10)
	let num = 0
	let sum = 1

	while (true) {
		if (sum >= B) break
		sum--
		sum += A
		num++
	}

	console.log(num)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

const int MAX = 1000001;

int factor[MAX] = { 0 };
void solve()
{
    factor[1] = 1;
    for (int i = 2; i < MAX; i++)
        factor[i] = i;
    for (int i = 4; i < MAX; i += 2)
        factor[i] = 2;
    for (int i = 3; i * i < MAX; i++) {
        if (factor[i] == i) {
            for (int j = i * i; j < MAX; j += i) {
                if (factor[j] == j)
                    factor[j] = i;
            }
        }
    }
}

int calculateNoOFactors(int n)
{
    if (n == 1)
        return 1;

    int ans = 1;

    int dup = factor[n];

    int c = 1;
    int j = n / factor[n];

    while (j != 1) {

        if (factor[j] == dup)
            c += 1;

        else {
            dup = factor[j];
            ans = ans * (c + 1);
            c = 1;
        }
        j = j / factor[j];
    }

    ans = ans * (c + 1);

    return ans;
}


int main()
{
    solve();

    int n;
    cin >> n;

    int sum = 0;

    for (int i = 1; i < n; i++)
        sum += calculateNoOFactors(i);

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 7540
#include<cstdio>

using namespace std;


int a[100005];

int main(){
    int n,ct = 0,ev = 0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    for(int i = 1; i <= 100000; i++){
        if(a[i] > 0) {
            ct++;
            ev += (a[i]+1)%2;
        }

    }
    printf("%d",ct - ev%2);



}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long h, n, i, j, k, x;
	cin >> h >> n;
	vector<long long> a(n), b(n);
	for (i = 0; i < n; i++) cin >> a[i] >> b[i];
	vector<long long> dp(h + 1, 1LL << 60);
	dp[0] = 0;
	for (i = 0; i < h; i++) {
		for (j = 0; j < n; j++) {
			x = min(h, i + a[j]);
			dp[x] = min(dp[x], dp[i] + b[j]);
		}
	}

	cout << dp[h] << "\n";

	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){
    int t = A;
    int a = C;
    while (true) {
        a -= B;
        if (a <= 0) break ;
        t -= D;
        if (t <= 0) break ;
    }
    if (a <= 0) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


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

using namespace std;

// input
ll a,b,c,d;

ll gcd(ll x, ll y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y%x,x);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> a >> b >> c >> d;

  ll lcm = (c*d) / gcd(c,d);

  ll left = b / c,right = b / d;
  ll duplex = b / lcm;

  ll to_b = left + right - duplex;

  a--;

  left = a / c,right = a / d;
  duplex = a / lcm;

  ll to_a = left + right - duplex;

  cout << (b-a) - (to_b - to_a) << "\n";
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define emb emplace_back
#define em emplace
#define ii pair<int,int>
#define iii pair<int ,ii>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define allc(x) x.begin(),x.end(),cmp
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;

char s[MAXN];
int b[MAXN],w[MAXN];
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 0 ; i < n ; i++){
        scanf(" %c",&s[i]);
    }
    for(int i = 1 ; i <= n ; i++){
        if(s[i - 1] == '#'){
            b[i]++;
        }
        b[i] += b[i - 1];
    }
    for(int i = n ; i >= 1 ; i--){
        if(s[i - 1] == '.'){
            w[i]++;
        }
        w[i] += w[i + 1];
    }
    int ans = MAXN + 1;
    // for(int i = 1 ; i <= n ; i++){
    //     printf("%d ",b[i]);
    // }
    // printf("\n");
    // for(int i = 1 ; i <= n ; i++){
    //     printf("%d ",w[i]);
    // }
    for(int i = 0 ; i <= n ; i++){
        ans = min(ans , b[i] + w[i + 1]);
    }
    printf("%d",ans);
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n-h+1)*(n-w+1) << endl;

  return 0;
}

Measured memory_bytes: 256
n = input()
for i in range(2**3):
    ss =""
    ss +=n[0]
    for j in range(3):
        if((i >> j )&1==True):
            ss += "+"
            ss += n[j+1]
        else:
            ss += "-"
            ss += n[j+1]
    ans = eval(ss)
    if (ans == 7):
        ss += "=7"
        print(ss)
        break

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main(){
  int n,m; cin >>n >>m;
  vector<int>v(n,-1);
  for(int i=0; i<m; i++){
    int s,c; cin >>s >>c;
    if(n!=1&&s==1&&c==0){cout <<-1; return 0;}
    if(v[s-1]==-1) v[s-1]=c;
    if(v[s-1]!=c){cout <<-1; return 0;}
  }
  for(int i=0; i<n; i++){
    if(v[i]==-1){
      if(n-1){
        if(i) v[i]=0;
        else v[i]=1;
      }
      else v[i]=0;
    }
    cout <<v[i];
  }
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    vector<int> rew(210, 0);
    rew[0] = 300000;
    rew[1] = 200000;
    rew[2] = 100000;
    int X, Y;
    cin >> X >> Y;
    if(X == 1 and Y == 1) {
        cout << 1000000 << endl;
        return 0;
    }
    cout << rew[X - 1] + rew[Y - 1] << endl;
    return 0;
}

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

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

int main()
{
    string A, B, C;
    cin >> A >> B >> C;
    cout << (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef vector<int> vi;
#define pb push_back
#define sz(a) int(a.size())

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,a[N],b[N],c[N],type[N],fa[N],out[N],in[N],ans=1e9,cnt;
vi vec[N],val[3];

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

int cal(int lim) {
	int ret=1e9;
	for(auto t:val[0]) lim-=t;
	sort(val[1].begin(),val[1].end(),greater<int>());
	sort(val[2].begin(),val[2].end(),greater<int>());
	int p=0,s=0;
	while(p<sz(val[2])&&s<lim) s+=val[2][p],++p;
	for(int i=0;i<=sz(val[1]);i++) {
		if(i) {
			s+=val[1][i-1];
			while(p&&s-val[2][p-1]>=lim) s-=val[2][p-1],--p;
		}
		if(s>=lim) ret=min(ret,i+2*p);
	}
	return ret;
}

int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++) {
		a[i]=gi(),b[i]=gi(),c[i]=gi();
		if(a[i]!=b[i]) ++cnt;
		fa[getf(a[i])]=getf(b[i]);
		++out[a[i]];++in[b[i]];
	}
	for(int i=1;i<=n;i++) vec[getf(i)].pb(i);
	int x=0;
	for(int i=1;i<=n;i++)
		if(getf(i)==i) {
			bool fl=1;
			for(auto t:vec[i]) fl&=(in[t]==1)&&(out[t]==1);
			if(fl) {
				if(sz(vec[i])==1) type[i]=1;
				else {
					++cnt;++x;
					for(auto t:vec[i]) type[t]=2;
				}
			}
			else for(auto t:vec[i]) type[t]=3;
		}
	if(!x) return cout<<cnt,0;
	int mx0=-1,mx1=-1;
	for(int i=1;i<=m;i++)
		if(c[i]>1) {
			if(type[a[i]]==1) val[2].pb(c[i]-2);
			else if(type[a[i]]==2) val[0].pb(c[i]-1);
			else if(a[i]==b[i]) val[1].pb(c[i]-1),mx1=max(mx1,c[i]-1);
			else val[0].pb(c[i]-1),mx0=max(mx0,c[i]-1);
		}
	if(mx0==-1&&mx1==-1) return cout<<-1,0;
	if(mx0!=-1) {
		val[0].erase(find(val[0].begin(),val[0].end(),mx0));
		ans=cal(x-mx0);val[0].pb(mx0);
	}
	if(mx1!=-1) {
		val[1].erase(find(val[1].begin(),val[1].end(),mx1));
		ans=min(ans,cal(x-mx1)+1);
	}
	if(ans>1e8) ans=-1; else ans+=cnt;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 10972
def main():
    import sys
    input=sys.stdin.readline
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    for i in range(k):
        B=[0]*(n+1)
        for j in range(n):
            a=A[j]
            B[max(0,j-a)]+=1
            B[min(n,j+a+1)]-=1
        for j in range(n):
            B[j+1]+=B[j]
        A=B.copy()
        if sum(A[:-1])==n**2:
            break
    print(*A[:-1])
if __name__ == '__main__':
    main()

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

int main(void)
{
    char s[100];
    scanf("%s",s);
    int n = strlen(s);
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n/2+i+1]){
            printf("No\n");
            return 0;
        }
        else if(s[n/2+i+1]!=s[n-i-1]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(1000000)

N = int(input())
X = [[] for _ in range(N)]

for i in range(N-1):
    a,b,c = map(int,input().split())
    X[a-1].append((b-1,c))
    X[b-1].append((a-1,c))

cost = [-1]*N
def calc(i,c):
    # 指定の頂点までのコストを代入
    cost[i] = c
    # 頂点から移動できる頂点があれば
    for ni,nc in X[i]:
        # 初期状態のままなら計算
        if cost[ni] == -1:
            calc(ni,c+nc)

Q,K = map(int,input().split())
# 事前計算
calc(K-1,0)

for i in range(Q):
    x,y = map(int,input().split())
    print(cost[x-1]+cost[y-1])



Measured memory_bytes: 131632
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    string s;
    int i, sum=0, len;
    cin >> s;
    len=s.size();
    for (i=0; i<len; i++) sum+=s[i]-48;
    if (sum%9) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3772
n=int(input())
a=list(map(int,input().split()))
co=[0]*(10**5)
s=sum(a)
for i in a:
  co[i-1]+=1
for i in range(int(input())):
  b,c=map(int,input().split())
  s=s+(c-b)*co[b-1]
  print(s)
  co[c-1]+=co[b-1]
  co[b-1]=0

Measured memory_bytes: 20976
import random
from copy import deepcopy

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]

def min_max(l):
    l_min = min(l)
    l_max = max(l)
    return [1+(i - l_min) / (l_max - l_min) for i in l]

dd = [max(s[i]) for i in range(d)]
qq = min_max(c)
dd = min_max(dd)

ddd = [i for i in range(d)]
qqq = [i for i in range(26)]

ans = []
last = [0]*26
for i in range(d):
    ma_po = -10**10
    ma_di = 0
    for j in range(26):
        po = s[i][j]
        for k in range(26):
            if k == j:
                continue
            po -= c[k]*(i+1-last[k])
        if po > ma_po:
            ma_po = po
            ma_di = j
    last[ma_di] = i+1
    ans.append(ma_di+1)

def score(l):
    lastd = [0]*26
    point = 0
    for j,k in enumerate(l):
        kk = k-1
        point += s[j][kk]
        lastd[kk] = j+1
        for l in range(26):
            point -= c[l]*(j+1-lastd[l])
    return point

ma = score(ans)

def random_search():
    global ans,ma
    li = deepcopy(ans)
    D = random.choices(ddd,k=1,weights=dd)[0]
    lin = [p+1 for p in range(26)]
    Q = random.choices(qqq,k=1,weights=qq)[0]
    li[D] = Q+1
    if score(li) > ma:
        ans = deepcopy(li)
        ma = score(li)

for i in range(25000):
    random_search()

for i in ans:
    print(i)

Measured memory_bytes: 90192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		String[] square = new String[x];
		
		for (int i = 0; i < square.length; i++) {
			square[i] = scan.next();
		}
		
		boolean[] col = new boolean[y];
		boolean[] row = new boolean[x];

		for (int i = 0; i < square.length; i++) {
			for (int j = 0; j < col.length; j++) {
				if (square[i].charAt(j) == '#') {
					row[i] = true;
					col[j] = true;
				}
			}
		}
		
		for (int i = 0; i < row.length; i++) {
			if (row[i]) {
				for (int j = 0; j < col.length; j++) {
					if (col[j]) {
						System.out.print(square[i].charAt(j));
					}
				}
			}
			System.out.println();
		}
		
		System.out.println();
	}
}

Measured memory_bytes: 24748
#include <iostream>
#include <unordered_set>

int main()
{
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N;
    string s;
    
    unordered_set<string> stringSet;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> s;
        stringSet.insert(s);
    }
    cout << stringSet.size();
    return 0;
}


Measured memory_bytes: 13816
/***

   Author : Md. Jashim Uddin
   From   : RMSTU

 ***/
#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     pob             pop_back()
#define     ll              long  long int
#define     fast            ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define      mx              95000005

int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3552
N, M, C  = map(int, input().split())

B = list(map(int,input().split()))

count = 0

for i in range(N):
    A = list(map(int, input().split()))
    sum = 0
    for j in range(M):
        sum += A[j] * B[j]
    if (sum + C) > 0:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int h[1000][1000];

int main(){
    int n;
    cin >> n;
    int k = INF;
    rep(i, 1000){
        if (i * (i + 1) / 2 == n){
            k = i;
            break;
        }
    }
    if (k == INF){
        cout << "No" << endl;
        return 0;
    }
    int row = 0, now = 1;
    rep(i, k){
        for (int j = 0; j <= i; j++){
            h[row][j] = now;
            now++;
        }
        row++;
    }

    rep(i, k) rep(j, k){
        if (i >= j) h[j][i] = h[i][j];
    }

    // rep(i, k) {
    //     rep(j, k) cout << h[i][j];
    //     cout << endl;
    // }

    vector<vector<int>> ans;

    rep(i, k){
        vector<int> v;
        rep(j, k) v.push_back(h[i][j]);
        ans.push_back(v);
    }
    ans.push_back({});
    rep(i, k) ans.back().push_back(h[i][i]);

    cout << "Yes" << endl;
    cout << k + 1 << endl;
    rep(i, k + 1){
        cout << k << " ";
        rep(j, k) cout << ans[i][j] << " ";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3968
#include<stdio.h>
int main(){
    int n,m,l;
    int i,j,k;
    long int a[101][101],b[101][101],c[101][101]={0};
    /*入力部*/
    scanf("%d %d %d",&n,&m,&l);
    for(i = 0;i < n;i++){
        for(j = 0;j < m;j++){
            scanf("%ld",&a[i][j]);
        }
    }
    for(i = 0;i < m;i++){
        for(j = 0;j < l;j++){
            scanf("%ld",&b[i][j]);
        }
    }
    /*出力部*/
    for (i = 0; i < n; i++){
        for(j = 0;j < l;j++){
            for(k = 0;k < m;k++)c[i][j] += a[i][k] * b[k][j];
            printf("%ld",c[i][j]);
            printf((j + 1 < l)? " ": "");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2080
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

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

    if((a==b&&b!=c)||(a==c&&b!=c)||(b==c&&a!=c)){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;

signed main(){  
    string s,t;
    cin >> s >> t;
    ll cnt = 0;
    rep(i,0,s.size()){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3916
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define p 1000000007
#define inv2 500000004
#define rt register int
#define ll long long
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,ans[505][505];
int main(){
    k=read();
    if(k<=500){
        writeln(k);
        for(rt i=1;i<=k;i++)for(rt j=1;j<=k;j++)cout<<i<<" \n"[j==k];
        return 0;
    }
    writeln(n=500);
    for(rt i=1;i<=n;i++){
        ans[1][i]=i;
        for(rt x=n,y=i%n+1;x!=1;x--,y=y%n+1)ans[x][y]=i;
    }
    for(rt i=n+1;i<=k;i++){
        if((i+i)&1)ans[1][i]=i;
        for(rt x=n,y=i%n+1;x!=1;x--,y=y%n+1)if((i+y)&1)ans[x][y]=i;
    }
    for(rt i=1;i<=n;i++)for(rt j=1;j<=n;j++)cout<<ans[i][j]<<" \n"[j==n];
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define m 998244353
#define MAXN 50000 + 5
#define BLK_SIZE 225
using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll 
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define con continue
#define endl "\n"
 
//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
int modexpo(int a , int b)
{
    int res = 1;
    while(b)
    {
        if (b & 1)
            res = (res * a) % m;
        b = b / 2;
        a = (a * a) % m;
    }
    return res;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

string in;
int tot[55][55];

int main()
{
	ios_base::sync_with_stdio(false);
	ll n,x;
	cin >> n >> x;
	vll v(n),a(n);
	rep(i, n) {
		cin >> v[i];
		a[i] = abs(v[i] - x);
	}
	REP(i, 1, n) {
		a[i] = gcd(a[i - 1], a[i]);
	}
	cout << a[a.size() - 1] << endl;
	return 0;
}

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

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int& i : B) cin >> i;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int sum = C;
		for (int j = 0; j < M; ++j) {
			int A;
			cin >> A;
			sum += A * B[j];
		}
		if (sum > 0) ++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	if(n==3){
		cout << 2 << " " << 5 << " " << 63 << endl;
	}
	else if(n==4){
		cout << 2 << " " << 5 << " " << 20 << " " << 63 << endl;
	}
	else{
		vector<ll> ans;
		ans.pb(2);
		ans.pb(4);
		ans.pb(6);
		ans.pb(3);
		ans.pb(9);
		n-=5;
  		vector<ll> v2;
  		for(int i = 8; i <= 30000; i+=2){
  			v2.pb(i);
  		}
  		vector<ll> v3;
  		for(int i = 15; i <= 30000; i+=6){
    		v3.pb(i);
  		}
  		ll index2 = 0;
  		ll index3 = 0;
  		while(1){
  			if(n==0){
  				break;
  			}
  			else if(n==1){
  				ans.pb(v2[index2+2]);
  				break;
  			}
  			else if(n==2){
  				ans.pb(v2[index2]);
  				ans.pb(v2[index2+1]);
  				break;
  			}
  			else{
  				if(index3+1<v3.sz){
  					ans.pb(v3[index3]);
  					ans.pb(v3[index3+1]);
  					index3+=2;
  					n-=2;
  				}
  				else{
  					ans.pb(v2[index2]);
  					ans.pb(v2[index2+1]);
  					ans.pb(v2[index2+2]);
  					index2+=3;
  					n-=3;
  				}
  			}
  		}
  		rep(i,0,ans.sz){
  			cout << ans[i];
  			if(i!=ans.sz-1)cout << " ";
  		}
  		cout << endl;
  	}
	return 0;
}

Measured memory_bytes: 832
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("gymnastics.in", "r", stdin)
#define fout freopen("gymnastics.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000
#define basay break
#define bmbr exit(0)

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
int r;

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin >> r;
    int arr1[r], arr2[r], vc[r], f[r], fe = 1, abc[r];
    for (int i = 0 ; i < r ; ++ i) {
        cin >> arr1[i];
    }
    for (int i = 0 ; i < r ; ++ i) {
        cin >> arr2[i];
    }
    for (int i = 0 ; i < r ; ++ i) {
        f[i] = fe;
        fe ++;
    }
    int P = 0, Q = 0, x = 1, cnt_san1 = 0, cnt_san2 = 0;
    do {
        int cnt1 = 0, cnt2 = 0;
        for (int i = 0 ; i < r ; ++ i) {
            vc[i] = f[i];
        }
        for (int j = 0 ; j < r ; ++ j) {
            if (arr1[j] == vc[j]) cnt1 ++;
        }
        for (int g = 0 ; g < r ; ++ g) {
            if (arr2[g] == vc[g]) cnt2 ++;
        }
        if (cnt1 == r) {
            P = x;
        }
        else if (cnt2 == r) {
            Q = x;
        }
        x ++;
    } while (next_permutation(f, f + r));
    if (P != 0 && Q != 0) cout << abs(P - Q);
    else cout << 0;
    ///time;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    int cnt = 1;

    rep(i,n-1){
        char c1 = s[i];
        char c2 = s[i+1];
        if(c1 != c2) cnt++;
    }

    cout << cnt << endl;
    

    //cout << fixed << setprecision(6) << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3748
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 110000
#define LL long long
using namespace std;
struct node{int y,nex;}a[2*N];
int fir[N],len,n,m,cnt,u,v,o,num,f[N],g[N],c[N],A[N];
LL ans;
void ins(int x,int y)
{
    a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void dfs(int x,int fa)
{
    for(int k=fir[x];k;k=a[k].nex)
    {
        int y=a[k].y;
        if(y==fa) continue;
        if(c[y]==0)
        {
            c[y]=-c[x];
            dfs(y,x);
        }
        else
        {
            u=x;v=y;
            if(c[x]==c[y]) o=1;
            else o=0;
        }
    }
}
void dp(int x,int fa)
{
    f[x]=c[x];
    for(int k=fir[x];k;k=a[k].nex)
    {
        int y=a[k].y;
        if(y==fa || (x==u && y==v) || (x==v && y==u)) continue;
        dp(y,x);
        f[x]+=f[y];
        g[x]+=g[y];
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        ins(x,y);ins(y,x);
    }
    c[1]=1;
    dfs(1,0);
    if(m==n-1)
    {
        dp(1,0);
        if(f[1]) {printf("-1\n");return 0;}
        for(int i=1;i<=n;i++) ans+=abs(f[i]);
        printf("%lld\n",ans);
    }
    else if(o==1)
    {
        dp(1,0);
        if(f[1]%2) {printf("-1\n");return 0;}
        int t=f[1];
        c[u]-=t/2;c[v]-=t/2;ans=abs(t/2);
        dp(1,0);
        for(int i=1;i<=n;i++) ans+=abs(f[i]);
        printf("%lld\n",ans);
    }
    else
    {
        g[u]++;g[v]--;
        dp(1,0);
        if(f[1]) {printf("-1\n");return 0;}
        for(int i=1;i<=n;i++)
            if(g[i]==0) ans+=abs(f[i]);
            else if(g[i]==1) A[++num]=-f[i];
            else A[++num]=f[i];
        A[++num]=0;
        sort(A+1,A+num+1);
        int t=A[(num+1)/2];
        for(int i=1;i<=num;i++) ans+=abs(t-A[i]);
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 8448
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

int d[100010][31];
int sd[100010];

int main(){
  int n,C; cin >> n >> C;
  vector<tiii> abc(n);
  rep(i,n){
    int a,b,c;
    cin >> a >> b >> c; c--;
    abc[i]=tiii(a,b,c);
  }
  sortt(abc);
  rep(i,n){
    itn a,b,c;
    tie(a,b,c)=abc[i];
    if(d[a][c]==-1) d[a][c]++;
    else d[a-1][c]++;
    d[b][c]--;
  }
  rep(i,100010)rep(j,C) sd[i]+=d[i][j];
  rep(i,100009){
    sd[i+1]=sd[i]+sd[i+1];
  }
  int ans=0;
  rep(i,100010){
    chmax(ans,sd[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 17048
n = int(raw_input())
l = [map(int, raw_input().split()) for _ in range(n-1)]
m = []
for i in range(n-1):
    m.append(l[i][1]+l[i][0])
    for j in range(i):
        if m[j] <= l[i][1]:
            m[j] = m[i]
        else:
            k = (m[j] + l[i][2] - 1) / l[i][2] * l[i][2]
            m[j] = k +  l[i][0]
m.append(0)
for i in m:
    print i


Measured memory_bytes: 2692
import numpy as np
import math

def main():
    N, K = map(int, input().split())
    prob = 0
    for i in range(1, N + 1):
        score = i
        if (score >= K):
            left = N - score + 1
            prob += left / N
            break
        else:
            num = 1
            while(True):
                if (score * 2 < K):
                    num += 1
                    score *= 2
                else:
                    prob += 1/(N * (2)**num)
                    break
    print(prob)


if __name__ == '__main__':
    main()

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

typedef pair<int,int> PII;

int main(){
	int n;
	cin>>n;
	int l[10];

	int total=0,mx=0;
	for (int i = 0; i < n; ++i){
		cin>>l[i];
		total+=l[i];
		mx=max(mx,l[i]);
	}

	if((total-mx)>mx)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int dp[400][400][400];
signed main(){
	string s;int K;cin>>s>>K;
	rep(i,s.size()){
		for(int j=s.size()-1;j>i;j--){
			rep(k,K+1){
				if(s[i]==s[j]){
					dp[i+1][j-1][k]=max(dp[i+1][j-1][k],dp[i][j][k]+1);
				}
				{
					dp[i+1][j-1][k]=max(dp[i+1][j-1][k],dp[i][j][k]);
					dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
					dp[i][j-1][k]=max(dp[i][j-1][k],dp[i][j][k]);
					if(k<K){
						dp[i+1][j-1][k+1]=max(dp[i+1][j-1][k+1],dp[i][j][k]+1);
					}
				}
			}
		}
	}
	int Max=0,id=0;
	rep(i,s.size())rep(k,s.size())rep(j,K+1){
		if(Max<dp[i][k][j]){
			Max=dp[i][k][j];
			id=0;
		}
		if(Max==dp[i][k][j]){
			id=max(id,k-i+1);
		}
	}/*
	if(s.size()%2==1){
		cout<<Max*2+1<<endl;
	}
	else{
		if(Max*2!=s.size())cout<<Max*2+1<<endl;
		else cout<<Max*2<<endl;
	}
	//cout<<Max*2+2<<vendl;*/
	if(id)cout<<Max*2+1<<endl;
	else cout<<Max*2<<endl;
}

Measured memory_bytes: 188160
S = str(input())
# if len(S) % 2 == 0:
mid = len(S)//2
left = S[:mid]
right = S[mid:]
ans = 0
# print(left)
# print(right)
for i in range(mid):
    # print(left[i])
    # print(right[-(i+1)])
    if left[i] != right[-(i+1)]:
        ans += 1
print(ans)


Measured memory_bytes: 2940