akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int getLargestRectangle(vector<int>& hight) {
    int w = hight.size(),res = 0;
    stack<P> st;
    for (int i = 0;i < w;++i) {
        if (st.empty()) {
            if (hight[i]) st.push(P(hight[i],i));
        } else {
            int t = st.top().first;
            if (t < hight[i]) st.push(P(hight[i],i));
            else if (t > hight[i]) {
                int l = i;
                while (!st.empty() && hight[i] < st.top().first) {
                    P p = st.top();
                    l = p.second;
                    res = max(res,(p.first)*(i-l));
                    st.pop();
                }
                if (st.empty() || st.top().first < hight[i]) st.push(P(hight[i],l));
            }
        }
    }
    return res;
}

int getLargestRectangle(vector<vector<int>>& grid) {
    int h = grid.size(),w = grid[0].size();
    vector<vector<int>> hight(h,vector<int>(w));
    hight = grid;
    for (int j = 0;j < w;++j) for (int i = 1;i < h;++i) if (hight[i][j]) hight[i][j] += hight[i-1][j];
    for (int i = 0;i < h;++i) hight[i].emplace_back(0);
    int res = 0;
    for (int i = 0;i < h;++i) res = max(res,getLargestRectangle(hight[i]));
    return res;
}

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<int>> t(h,vector<int>(w));
    for (int i = 0;i < h;++i) for (int j = 0;j < w;++j) {
        int c;
        cin >> c;
        t[i][j] = c^1;
    }
    cout << getLargestRectangle(t) << endl;
    return 0;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<vector<int>> E(N), EE(N);
        vector<int> A(N-1), B(N-1);
        rep(i, N-1) {
            int a, b; cin >> a >> b;
            E[a-1].push_back(b-1);
            E[b-1].push_back(a-1);
            EE[a-1].push_back(i);
            EE[b-1].push_back(i);
            A[i] = a - 1;
            B[i] = b - 1;
        }
        int ans = 0;
        rep(i, N) set_max(ans, (int)E[i].size());
        cout << ans << endl;

        vector<int> indices;
        function<void(int,int)> dfs = [&] (int now, int prev) {
                       indices.push_back(now);
                       for(int nxt: E[now]) if(nxt != prev) dfs(nxt, now);
                   };
        dfs(0, -1);
        vector<int> nxt(N);
        vector<set<int>> used(N);
        vector<int> colors(N-1,-1);
        for(int j : indices) {
            for(int i : EE[j]) {
                if(colors[i] >= 0) continue;
                int a = A[i], b= B[i];
                int c = max(nxt[a], nxt[b]);
                while(used[a].count(c) or used[b].count(c)) {
                    if(nxt[a] == c and used[a].count(nxt[a])) nxt[a]++;
                    if(nxt[b] == c and used[b].count(nxt[a])) nxt[b]++;
                    c++;
                }
                used[a].insert(c);
                used[b].insert(c);
                assert(c + 1 <= ans);
                colors[i] = c;
            }
        }
        rep(i, N-1) cout << 1 + colors[i] << endl;

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 27640
#include <iostream>

using namespace std;

int main() {
		int D, G, p[11], c[11];
		cin >> D >> G;
		for (int i = 0; i < D; i++) {
				cin >> p[i] >> c[i];
		}

		int ans = 1e9;
		for (int mask = 0; mask < (1 << D); mask++) {
				int s = 0, num = 0, rest_mask = -1;
				for (int i = 0; i < D; i++) {
						if (mask >> i & 1) {
								s += 100 * (i+1) * p[i] + c[i];
								num += p[i];
						} else {
								rest_mask= i;
						}
				}

				if (s < G) {
						int s1 = 100 * (rest_mask + 1);
						int need = (G - s + s1 - 1) / s1;
						if (need >= p[rest_mask]) continue;
						num += need;
				}

				ans = min(ans, num);
		}
		cout << ans << endl;
		return 0;
}


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

int main(){
  int N,M;
  cin >> N;
  M = N;

  
  int count = 0;
  while(N != 0){
    count += (N%10);
    N /= 10;
  }
  
  if(M%count == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

bool compare(const std::string& lhs, const std::string& rhs)
{
    if (lhs.size() != rhs.size())
        return false;
    if (lhs == rhs)
        return true;

    std::size_t l = lhs.size();
    for (auto i = 1; i < l; ++i)
    {
        if (lhs.substr(l-i, i) == rhs.substr(0, i) && lhs.substr(0, l-i) == rhs.substr(i, l-i))
            return true;
    }
    return false;
}

int main(void)
{
    std::string lhs, rhs;
    std::getline(std::cin, lhs);
    std::getline(std::cin, rhs);
    std::cout << (compare(lhs, rhs)? "Yes": "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>void chmax(T& x, T y){if(x < y) x = y;}
int N;
vector<int> as;
int cnt[100];
bool flag = true;

int main(){
    cin >> N;
    int mx = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        cnt[a]++;
        chmax(mx, a);
    }

    for(int i = mx; i > (mx + 1) / 2; i--){
        if(cnt[i] < 2) flag = false;
    }
    for(int i = 0; i < (mx + 1) / 2; i++){
        if(cnt[i] > 0) flag = false;
    }
    if(mx % 2 == 0){
        if(cnt[mx / 2] != 1) flag = false;
    }else{
        if(cnt[(mx + 1) / 2] != 2) flag = false;
    }
    cout << (flag ? "Possible" : "Impossible")  << endl;
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

struct Query {
	int l;
	int r;
	int index;
};

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N, Q;
	cin >> N >> Q;
	vector<int> C(N);
	for (auto& ci : C)
		cin >> ci;
	int sN = sqrt(N);
	vector<vector<Query> > q(sN+1);
	vector<int> A(Q);
	forn(i, Q)
	{
		Query aq;
		aq.index = i;
		cin >> aq.l >> aq.r;
		aq.l--;
		aq.r--;
		q[aq.l / sN].push_back(aq);
	}
	for (auto& qi : q)
	{
		if(qi.empty())
			continue;
		sort(qi.begin(), qi.end(), [](const Query& a, const Query& b) {
			return a.r < b.r;
		});
		vector<uint32_t> counter(N+1);
		int currl = min_element(qi.begin(), qi.end(), [](const Query& a, const Query& b) {
			return a.l < b.l;
		})->l;
		int currr = currl-1;
		int answ = 0;
		for (const auto& actq : qi) {
			while (currr < actq.r) {
				++currr;
				if (counter[C[currr]] == 0) {
					++answ;
				}
				counter[C[currr]]++;
			}
			while (currl > actq.l) {
				--currl;
				if (counter[C[currl]] == 0) {
					++answ;
				}
				counter[C[currl]]++;
			}
			while (currl < actq.l) {
				counter[C[currl]]--;
				if (counter[C[currl]] == 0) {
					--answ;
				}
				++currl;
			}
			A[actq.index] = answ;
		}
	}

	for (auto ai : A)
	{
		cout << ai << endl;
	}
	return 0;
}


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

int main(){
  int N;
  cin>>N;
  std::vector<int> a(N),b(N);
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)cin>>b[i];
  for(int i=1;i<N;i++)a[i]+=a[i-1];
  for(int i=1;i<N;i++)b[N-1-i]+=b[N-1-i+1];
  int ans=0;
  for(int i=0;i<N;i++)ans=max(ans,a[i]+b[i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
/*

    author : s@if

*/

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

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int ara[15][15];

bool f(int n, int m, int d)
{

    ll dis = 0, kk;

    for(int i=0; i<d; i++)
    {
        dis+=(ara[n][i]-ara[m][i])*(ara[n][i] - ara[m][i]);
    }

    kk = sqrt(dis);

    if(kk*kk==dis)
        return true;
    else
        return false;
}

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n>>m;

    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
            cin>>ara[i][j];
    }

    int ans = 0;

    for(i=0; i<n; i++)
    {
        for(j=i+1; j<n; j++)
        {
            if(f(i,j,m))
                ans++;
        }
    }

    cout<<ans<<endl;

   // main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000
 
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	
	int n,w;

	cin >> n >> w;

	ii a[n];

	ll dp[n+1][w+1];

	
	for (int i = 0; i < n; ++i){
		cin >> a[i].F >> a[i].S;
	}

	for (int i = 0; i <= w; ++i){
		dp[0][i] = 0;	
		for (int j = 1; j <= n; ++j){
			if(a[j-1].F > i) dp[j][i] = dp[j-1][i];
			else dp[j][i] = max(dp[j-1][i-a[j-1].F] + a[j-1].S,dp[j-1][i]);
		}
	}

	/*for (int i = 0; i < n+1; ++i){
		for (int j = 0; j < w+1; ++j){
			cout << dp[i][j] << ' ';
		}
		cout << '\n';
	}*/

	cout << dp[n][w] << '\n';


	return 0;
}

Measured memory_bytes: 79104
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<i64>();
    let mut ans = 0i64;
    for i in 1..n + 1 {
        if i % 3 == 0 || i % 5 == 0 {
            continue;
        }
        ans += i;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2064
#include <stdio.h>

int main(){
  int n,i,j,k,a[4005],b[4005],c[3]={0,0,0},f,g,p;
  char s[4005],d[3]={'R','G','B'};
  long m=1;
  scanf("%d",&n);
  scanf("%s",&s);
  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      if(s[i]==d[j]){
        a[i]=j;
        c[j]++;
        break;
      }
    }
  }
  m*=c[0];
  m*=c[1];
  m*=c[2];
  for(i=1;i<=n/2;i++){
    for(j=0;(j<i)&&(j+i<n);j++){
      f=0;
      p=-1;
      for(k=j;k<n-i;k+=i){
        g=(a[k]!=a[k+i]);
        if(g&&f&&(p!=a[k+i])){
          m--;
        }
        f=g;
        p=a[k];
      }
    }
  }
  printf("%ld",m);
  return(0);
}

Measured memory_bytes: 1756
/*
[diverta2019] C - AB Substrings
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e4;

int N;
string s[MAX_N];

ll solve() {
    int c1 = 0, c2 = 0, c3 = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int)s[i].length() - 1; j++) {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
                ans++;
            }
        }
        if (s[i][0] == 'B') {
            if (s[i].back() == 'A') {
                c1++;
            } else {
                c2++;
            }
        } else if (s[i].back() == 'A') {
            c3++;
        }
    }

    if (c1 == 0) {
        ans += min(c2, c3);
    } else if (c2 + c3 > 0) {
        ans += c1 + min(c2, c3);
    } else {
        ans += c1 - 1;
    }

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll long long 
#define db double
#define all(v) v.begin(),v.end()

using namespace std;

/*

ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}

*/
/*
class dsu{
public:    
vi<ll> v;


void init(ll n){
    v.assign(n+1,-1);
}

 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}

};
*/



int main(){
    //IOS;
    ll t;
    t=1;
    map<string,ll> mp;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"]<<"\n";
    return 0;
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
bool dp[100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,K;
    cin>>N>>K;
    int a[N];
    rep(i,0,N) cin>>a[i];
    rep(i,0,K+1){
        bool t=false;
        rep(j,0,N){
            if(i>=a[j]&&dp[i-a[j]]==0) t=true;
        }
        dp[i]=t;
    }
    cout <<(dp[K]?"First":"Second")<<"\n";
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

int main() {
  int h , w;
  cin >> h >> w;
  char grid[h+50][w+50];
  fill(grid[h], grid[h+2], ' ');
  for(int i = 1; i <= h; i++){
    string s; cin >> s;
    for(int j = 1; j <= w; j++){
      grid[i][j] = s[j-1];
    }
  }
  int res[h+50][w+50];
  fill(res[0], res[h+2], 0);
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      if(grid[i][j] == '#'){
        res[i][j] = -1;
      } else {
        int cnt = 0;
        rep(k, 8){
          int y = i + dy[k];
          int x = j + dx[k];
          if(grid[y][x] == '#') cnt++;
        }
        res[i][j] = cnt;
      }
    }
  }
   for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      if(res[i][j] == -1) cout << '#';
      else cout << res[i][j];
    }
    cout << ln;
  } 
  
}
  


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout  << "Right" << endl;
  }
}

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

int main() {
  long long int X;
  long long int total = 100; 
  int year = 0;
  cin >> X;
  
  while(total<X) {
    total *= 1.01;
    year++;
  }
  
  cout << year << endl;
  return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
import java.math.*;

class Main {

    static int[] perm = {1, 2, 6, 24, 120, 720, 5040, 40320};
    //40320, 5040, 720, 120, 24, 6, 2, 1};

    static int calc(int[] P, int N)  {
        TreeSet<Integer> set = new TreeSet<Integer>();
        for (int i = 1; i <= N; i++) {
            set.add(i);
        }

        int ret = 1;
        for (int i = 0; i < N - 1; i++) {
            int digitNumber = P[i];
            int rank = set.headSet(digitNumber).size();
            set.remove(digitNumber);

            ret += perm[set.size() - 1] * rank;
            //System.out.println(String.format("digit,rank,size,perm,ret=%d %d %d %d %d",digitNumber,rank, set.size(), perm[set.size() - 1], ret));
        }

        return ret;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];
        int[] Q = new int[N];

        for (int i = 0; i < N; i++) {
            P[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {
            Q[i] = sc.nextInt();
        }


        int a = calc(P, N);
        int b = calc(Q, N);

        //System.out.println(a);
        //System.out.println(b);
        System.out.println(Math.abs(a - b));
    }

}


Measured memory_bytes: 21844
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(arr[k-1])

Measured memory_bytes: 38488
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n,m; cin >> n >> m;
	vector<vector<int>> s(m,vector<int>());
	rep(i,m){
		int k; cin >> k;
		Rep(k){
			int sw; cin >> sw;
			s[i].push_back(sw-1);
		}
	}
	vector<bool> p(m);
	rep(i,m){
		bool tmp;
		cin >> tmp;
		p[i] = tmp;
	}
	int ans = 0;
	rep(bits, 1 << n){
		rep(i,m){
			bool res = false;
			for(int k: s[i]){
				if(bits >> k & 1){
					res = !res;
				}
			}
			if(res != p[i]){
				goto wrong;
			}
		}
		ans++;
		wrong:;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($h, $w) = split / /, <STDIN>);
my (@s, @que);
my $c = 0;
for my $i (1..$h) {
  chomp (my $in = <STDIN>);
  my @b = split //, $in;
  for my $j (1..$w) {
    if ($b[$j-1] eq '.') {
      $s[$i][$j] = -1;
    } else {
      $c++;
    }
  }
}
push @que, 1;
push @que, 1;
$s[1][1] = 0;
while (@que) {
  my ($i, $j);
  $i = shift @que;
  $j = shift @que;
  my $cnt = $s[$i][$j];
  if ($s[$i+1][$j] == -1) {
    $s[$i+1][$j] = $cnt + 1;
    push @que, $i+1;
    push @que, $j;
  }
  if ($s[$i-1][$j] == -1) {
    $s[$i-1][$j] = $cnt + 1;
    push @que, $i-1;
    push @que, $j;
  }
  if ($s[$i][$j+1] == -1) {
    $s[$i][$j+1] = $cnt + 1;
    push @que, $i;
    push @que, $j+1;
  }
  if ($s[$i][$j-1] == -1) {
    $s[$i][$j-1] = $cnt + 1;
    push @que, $i;
    push @que, $j-1;
  }
}
my $ans = ($s[$h][$w]==-1) ? -1 : $h * $w - $c - 1 - $s[$h][$w];
say $ans;

Measured memory_bytes: 896
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var hw = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            string[] map = new string[hw[0]];
            int[][] ans = new int[hw[0]][];
            for (int i = 0; i < hw[0]; i++)
            {
                map[i] = Console.ReadLine();
                ans[i] = new int[hw[1]];
            }
            for (int i = 0; i < hw[0]; i++)
            {
                for (int j = 0; j < hw[1]; j++)
                {
                    CountBomb(ref ans, map, i, j);
                }
            }
            for (int i = 0; i < hw[0]; i++)
            {
                for (int j = 0; j < hw[1]; j++)
                {
                    Console.Write(map[i][j] == '#' ? "#" : ans[i][j].ToString());
                }
                Console.WriteLine();
            }
        }
        static void CountBomb(ref int[][] ans, string[] map, int h, int w)
        {
            int[] P = new int[2] { h, w };
            int[][] move = new int[8][]
            {
                new int[2] { -1, 1 }, new int[2] { 0, 1 }, new int[2] { 1, 1 },
                new int[2] { -1, 0 }, new int[2] { 1, 0 },
                new int[2] { -1, -1 }, new int[2] { 0, -1 }, new int[2] { 1, -1 }
            };

            for (int i = 0; i < 8; i++)
            {
                int Ph = P[0] + move[i][0];
                int Pw = P[1] + move[i][1];
                if (Ph >= 0 && Ph < map.Count() && Pw >= 0 && Pw < map[0].Length)
                {
                    if (map[Ph][Pw] == '#') ans[h][w]++;
                }
            }
        }
    }
}

Measured memory_bytes: 13396
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		long[] numline = Stream.of(sc.nextLine().split(" ", 0)).mapToLong(Long::parseLong).toArray();
		Main main = new Main();
		Arrays.sort(numline);
		long numsMax = numline[line[0] - 1];
		long let = numline[0];
		if (line[0] > 1) {
			for (int i = 1; i < line[0]; i++) {
				let = main.GCD(numline[i], let);
			}
		}
		if (line[1] <= numsMax && line[1] % let == 0) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
		sc.close();
	}

	public long GCD(long num1, long num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}
}

Measured memory_bytes: 47448
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let a = scan.readn::<i64>(n);
    let mut ret = 3f64.powi(n as i32) as i64;
    let mut d = 1;
    for i in 0..n {
        if a[i] % 2 == 0 {
            d *= 2;
        }
    }
    println!("{}", ret - d);
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
import datetime
import string
import re
import math

K=int(input())
if K % 2 == 0 or K % 5 == 0:
    print("-1")
else:
    s = 7
    count = 1
    while True:
        if s % K == 0:
            print(count)
            break
        else:
            count += 1
            s = (s % K)*10 + 7

Measured memory_bytes: 10020
S = input()
N = int(S)
ans = 0
if len(S) == 1:
    ans = N
if len(S) >= 2:
    ans += 9
if len(S) >= 4:
    ans += 900
if len(S) >= 6:
    ans += 90000
if len(S) == 3: 
    ans += N - 99    
if len(S) == 5:
    ans += N - 9999
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
const int N=2005;
int l[N][N],r[N][N];
bool a[N][N];
char s[N];
int main(){
	int h,w;
	scanf("%d%d\n",&h,&w);
	for (int i=0;i<h;i++){
		scanf("%s",s);
		for (int j=0;j<w;j++) a[i][j]=(s[j]=='#');
	}
	for (int i=h-1;i;i--){
		for (int j=0;j<w;j++) a[i][j]^=a[i-1][j];
		for (int j=w-1;j;j--) a[i][j]^=a[i][j-1];
		a[i][0]=a[i][w]=1;
		for (int j=0;j<w;j++)
			if (a[i][j]) l[i][j]=j;else l[i][j]=l[i][j-1];
		for (int j=w;j;j--)
			if (a[i][j]) r[i][j]=j;else r[i][j]=r[i][j+1];
	}
	int ans=std::max(h,w);
	for (int j=1;j<w;j++)
		for (int i=1,k=0,L=0,R=w;i<h;i++)
		if (a[i][j]) k=i,L=0,R=w;
		else{
			L=std::max(L,l[i][j]);
			R=std::min(R,r[i][j]);
			ans=std::max(ans,(R-L)*(i-k+1));
		}
	printf("%d\n",ans);
}

Measured memory_bytes: 35584
N = gets.to_i
A = gets.split.map(&:to_i)
C = A.group_by(&:itself)
total = C.inject(0){|s,(k,v)| s + v.size * (v.size - 1) / 2 }
puts A.map{|a| n = C[a].size; total - (n * (n - 1) / 2) + ((n - 1) * (n - 2) / 2) }


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, m;
  cin >> n >> m;
  vi ans(n);
  int ac = 0, wa = 0;
  rep(i,m) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(ans[p] <= 0) {
      if(s == "AC") {
        wa += abs(ans[p]);
        ac++;
        ans[p] = 1;
      }
      else {
        ans[p]--;
      }
    }
  }
  cout << ac << ' ' << wa;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;


namespace Library
{
    public class Miscelleneous
    {
        public static void print(object j){Console.WriteLine(j.ToString());}
        public static void print(string s){Console.WriteLine(s);}
        
        public static string Minimize(string s){
            char[] cs=s.ToCharArray();
            if(cs[0]<=90&&cs[0]>=65)cs[0]=(char)(cs[0]+32);
            return new string(cs);
            }
        public static void Main(){
            Dictionary<string,int> Stat=new Dictionary<string,int>();
            string[] ss=Console.ReadLine().Split(' ');
            ss[0]=Minimize(ss[0]);
            int j;
            int ml=ss.Max(i=>i.Length);
            string Resl=ss.First(i=>i.Length==ml);
            
            foreach(string s in ss){
                if(Stat.TryGetValue(s,out j))Stat[s]++;
                else Stat.Add(s,1);
            }
            int mw=Stat.Max(i=>i.Value);
            string Resw=Stat.First(i=>i.Value==mw).Key;
            
            print(Resw+" "+Resl);
        }
    }
}

Measured memory_bytes: 9232
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
 
using namespace std;
 
#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 pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
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);
}

int main()
{
	int h,w;
    cin >> h >> w;
    char s[h][w];
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#' && s[i-1][j]!='#' && s[i][j-1]!='#' && s[i+1][j]!='#' && s[i][j+1]!='#'){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k, a, b, x, y;

int main(){
	cin>>k;
	cin>>a>>b;
	x=min(a, b);
	y=max(a, b);
	if(k==1)cout<<"OK"<<endl;
	else if(k<=abs(a-b))cout<<"OK"<<endl;
	else{
		for(int i=x; i<=y; i++){
			if(i%k==0){
				cout<<"OK"<<endl;
				break;
			}
			if(i==y)cout<<"NG"<<endl;
		}
	}
}


Measured memory_bytes: 3632
// Anve$hi $hukla
#include <bits/stdc++.h>
using namespace std;
struct ${$(){ios_base::sync_with_stdio(false);cin.tie(NULL);}}$;

typedef long long LL;
const int Maxn = 200005;

int main() {
   string s;
   cin >> s;
   cout << s.substr(0, 4) << " " << s.substr(4) << endl;   
   return 0;
}


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

#define all(x)        (x).begin(),(x).end()
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int,int>
#define vi            vector<int>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
const int N = 2e5 + 1;
const int lg = 20;
const ll mod = 0xfffff;


void solve() {
  string s; cin >> s;
  bool w = 1;
  rep(i, 1, 6)
  w &= s[2] == s[3];
  w &= s[4] == s[5];
  cout << (w ? "Yes" : "No") << "\n";
}

int main() {
  // freopen("input.in", "r", stdin);
  // freopen("input.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// cout<<setprecision(15);
	// int t; cin>>t; while(t--)
	solve();
	return 0;
}



Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        string line = Console.ReadLine();
        int strLen = line.Length;
        string result = "";
        for (int i = 0; i < strLen; i++)
        {
            if (i % 2 == 0)
                result += line[i];
        }

        Console.WriteLine(result);
    }
}

Measured memory_bytes: 34772
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}

int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    ll K; cin >> K;
    vi a(N), b(N); 
    int AMAX = 0;
    REP(i, N) {
        cin >> a[i] >> b[i];
        AMAX = max(AMAX, a[i]);
    }

    vl h(AMAX + MGN, 0);

    REP(i, N){
        h[a[i]] += b[i];
    }

    ll sum = 0;
    int ans = 0;
    FOR(i,1, AMAX + 1) {
        sum += h[i];
        if (K <= sum) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> P;

double cross(P a, P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

double distance_l_p(P a, P b, P c){
	return abs(cross(b-a, c-a)) / abs(b-a);
}

P symmetric_point(P a, P b, P c){
	P un1 = ((b-a) * P(0, 1)) / abs(b-a);
	P un2 = ((b-a) * P(0,-1)) / abs(b-a);

	if(cross(b-a, c-a) > 0){
		return c - 2 * distance_l_p(a,b,c) * un1;
	}
	else{
		return c - 2 * distance_l_p(a,b,c) * un2;
	}
}

int main(void){
	P p[3],d;
	double x,y;

	while(1){
		for(int i=0;i<3;i++){
			if(scanf("%lf,%lf",&x,&y) == EOF) return 0;
			if(i != 2) getchar();
			p[i] = P(x,y);
		}
		d = symmetric_point(p[0],p[1],p[2]);
		printf("%.6lf %.6lf\n",d.real(),d.imag());
	}
}

Measured memory_bytes: 0
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
                

                int a = int.Parse(array[0]);

                int b = int.Parse(array[1]);

            int ans = (a - 1) * (b - 1);
                Console.WriteLine(ans);
            
        }
    }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	char x, y;
	cin >> x >> y;
	char ans;
	if (x == y)ans = '=';
	else if (x < y)ans = '<';
	else ans = '>';
	cout << ans << endl;
}



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

typedef complex<double> point;

struct line : public vector<point> {
	line() { push_back(0); push_back(0); }
	line(const point& a, const point& b) { push_back(a); push_back(b); }
};

struct circle {
	point p; double r;
	circle() : p(0),r(0) {}
	circle(const point& p, const double r) : p(p), r(r) {}
};

const double pi=M_PI;
const double inf = 1e20;
const double eps = 1e-10;
point  unit (const point& v) { return v/abs(v); }
point  ortho(const point& v) { return v*point(0,1); }
point  vec  (const line&  l) { return l[1]-l[0]; }
double dot  (const point& a, const point& b) { return (a*conj(b)).real(); }
double cross(const point& a, const point& b) { return (conj(a)*b).imag(); }

int ccw(const point& a, const point& b, const point& c) {
	point u=b-a, v=c-a;
	if(cross(u,v) > 0 ) return +1;
	if(cross(u,v) < 0 ) return -1;
	if(  dot(u,v) < 0 ) return +2;
	if(abs(u) < abs(v)) return -2;
	return 0;
}

int ccw(const line& l, const point& p) {
	return ccw(l[0], l[1], p);
}

bool intersectSS(const line& s, const line& t) {
	return ccw(s,t[0])*ccw(s,t[1]) <= 0
	    && ccw(t,s[0])*ccw(t,s[1]) <= 0;
}

/// [verified 1] ヘロンの公式
double heron(double a, double b, double c) {
	double s = (a + b + c) / 2.0;
	return sqrt( s * (s-a) * (s-b) * (s-c) );
}

/// [verified 1] 円と円の交点
line crosspointCC(const circle& a, const circle& b) {
	double l = abs(b.p-a.p);;
	double d = 2.0 * heron(l, a.r, b.r) / l;
	double t = sqrt(a.r*a.r - d*d);
	point  v = t * unit(b.p-a.p) ;
	point  w = d * unit(ortho(v));
	return line(a.p+v+w, a.p+v-w);
}
int N;
circle c[128];		
line x[128];

bool check(const line& v, int s, int t) {
	for(int i=s+1; i<t; i++) {
		if(!intersectSS(v, x[i])) return false;
	}
	return true;
}

int main()
{
	while(cin>>N, N)
	{
		for(int i=0; i<N; i++) {
			cin>>c[i].p.real()>>c[i].p.imag()>>c[i].r;
		}

		for(int i=0; i<N-1; i++) {
			x[i+1] = crosspointCC(c[i],c[i+1]);
		}
		x[0] = line(c[  0].p, c[  0].p);
		x[N] = line(c[N-1].p, c[N-1].p);

		double dp[128][2];
		for(int i=0; i<=N; i++) {
			dp[i][0]=dp[i][1]=inf;
		}
		dp[0][0]=dp[0][1]=0;

		int test[128][2]={0};

		for(int i=1; i<=N; i++)
		for(int j=0; j<i;  j++)
		{
			for(int s=0; s<2; s++)
			for(int t=0; t<2; t++)
			{
				line l(x[j][s], x[i][t]);
				if(check(l,j,i)) { 
					if(dp[j][s]+abs(vec(l)) < dp[i][t]) {
						dp[i][t] = dp[j][s]+abs(vec(l));
						test[i][t] = j*100 + s;
					}
				}
			}
		}
		cout.setf(ios::fixed);
		cout.precision(10);
		cout << min(dp[N][0], dp[N][1]) << endl;
	}
}

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

int main(int argc, char *argv[]) {
  int64_t N;
  std::cin >> N;
  std::vector<int> nums;
  for(int i = 0; i < N; i++) {
    int v;
    std::cin >> v;
    nums.push_back(v);
  }
  std::vector<int> ways;
  while(nums.size()) {
    int old_size = nums.size();
    for(int i = nums.size() - 1; i >= 0; i--){
      if(nums[i] != (i + 1)) continue;
      nums.erase(nums.begin() + i);
      ways.push_back(i + 1);
      break;
    }
    if(old_size == nums.size()) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  for(auto it = ways.rbegin(); it != ways.rend(); ++it) std::cout << *it << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
double dp[600];
double A[600], B[600];
vector<int> G[600];
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		G[s].push_back(t);
	}
	dp[N - 1] = 0;
	for (int v = N - 2; v >= 0; v--) {
		for (int to : G[v]) {
			dp[v] += (dp[to] + 1);
		}
		dp[v] /= G[v].size();
	}
	double ans = dp[0];
	for (int s = 0; s < N; s++) {
		if (G[s].size() == 1) continue;
		A[s] = 1;
		B[s] = 0;
		for (int i = s + 1; i < N; i++) {
			A[i] = 0;
			B[i] = dp[i];
		}
		for (int i = s - 1; i >= 0; i--) {
			A[i] = B[i] = 0;
			for (int to : G[i]) {
				A[i] += A[to] / G[i].size();
				B[i] += (B[to] + 1) / G[i].size();
			}
		}
		for (int to : G[s]) {
			double x = (dp[s] * G[s].size() - (dp[to] + 1)) / (G[s].size() - 1);
			ans = min(ans, A[0] * x + B[0]);
		}
	}
	printf("%.15lf\n", ans);
}

Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli a, b, n;
    cin >> n >> a >> b;
    lli c = n / (a + b);
    lli ans = 0;
    ans += a * c;
    n %= (a + b);
    (n > a ? ans += a : ans += n);
    out(ans);
}

Measured memory_bytes: 3600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GetEverything solver = new GetEverything();
        solver.solve(1, in, out);
        out.close();
    }

    static class GetEverything {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            long[] a = new long[m];
            int[] cc = new int[m];

            for (int i = 0; i < m; i++) {
                a[i] = in.nextLong();
                int b = in.nextInt();
                int c = 0;
                for (int j = 0; j < b; j++) {
                    c += (1 << in.nextInt() - 1);
                }
                cc[i] = c;
            }

            // dp[鍵mまでつかった][箱の状態] = 最小コスト
            long[][] dp = new long[m + 1][(1 << n) + 1];
            for (int i = 0; i <= m; i++) {
                Arrays.fill(dp[i], Integer.MAX_VALUE);
            }

            dp[0][0] = 0;
            // 使う鍵
            for (int i = 0; i < m; i++) {
                // 箱の状態
                for (int j = 0; j < (1 << n); j++) {
                    // 鍵を使わない
                    dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j]);

                    // 鍵を使った箱の状態
                    int status = j | cc[i];
                    dp[i + 1][status] = Math.min(dp[i + 1][status], dp[i][j] + a[i]);
                }
            }


            if (dp[m][(1 << n) - 1] == Integer.MAX_VALUE) {
                out.println(-1);
                return;
            }
            out.println(dp[m][(1 << n) - 1]);
        }

    }
}



Measured memory_bytes: 81532
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
inline int read(){
    int re = 0,ch = getchar();
    while(!isdigit(ch))ch = getchar();
    while(isdigit(ch))re = (re<<1)+(re<<3)+ch-'0',ch = getchar();
    return re;
}
const int maxn = 200010;
struct edge{
    int v,w,nxt;
}e[maxn];
int h[maxn],cnt;
inline void add(int u,int v,int w){
    e[++cnt].v = v;
    e[cnt].w = w;
    e[cnt].nxt = h[u];
    h[u] = cnt;
}
inline int color(int c){
    if(c >= 3)c -= 3;
    if(c < 0)c += 3;
    return c;
}
int col[maxn],cnum[3],nsz,esz;
bool flag = 1,vis[maxn];
void coloring(int u){
    cnum[col[u]]++;nsz++;vis[u] = 1;
    for(int i = h[u];i;i = e[i].nxt){
        int v = e[i].v;
        if(e[i].w == 1)esz++;
        if(!vis[v]) col[v] = color(col[u] + e[i].w),coloring(v);
        else if(col[v] != color(col[u] + e[i].w)) flag = 0;
    }
}
int n,m;
long long ans;
int main(){
    n = read(),m = read();
    int u,v;
    for(int i = 1;i <= m;i++){
        u = read(),v = read();
        add(u,v,1);
        add(v,u,-1);
    }
    for(int i = 1;i <= n;i++){
        if(vis[i])continue;
        memset(cnum,0,sizeof(cnum));
        nsz = 0,esz = 0,flag = 1;
        coloring(i);
        if(!flag) ans += (long long)nsz * nsz;
        else if(cnum[0] && cnum[1] && cnum[2]) 
            ans += (long long)cnum[0] * cnum[1]
             + (long long)cnum[1] * cnum[2] + (long long)cnum[2] * cnum[0];
        else ans += esz;
    }
    printf("%lld",ans);
    return 0;
} 

Measured memory_bytes: 6784
n = gets.to_i
a =[]
ans = "Yes"
for num in 0..n-1 do
words = gets.chomp
  a << words
end

for num in 0..n-1 do
  b = a.count(a[num])
  if b == 2
    ans = "No"
  end
end

for num in 0..n-2 do
  c = a[num].slice(-1)
  d = a[num+1].slice(0)
  if c != d 
    ans = "No"
  end
end
puts ans

Measured memory_bytes: 1788