akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{

   int n,i,d,j,p,x,a[100],b[100],s;

   scanf("%d%d%d",&n,&d,&x);

   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      b[i]=0;
   }

   for(i=0;i<n;i++){
      p = 1;
      for(j=1;j<=d;j++){
         if(p==j){
            b[i]++;
            p+=a[i];
         }
      }
   }

   s=0;

   for(i=0;i<n;i++){
      s = s+b[i];
   }

   s+=x;

   printf("%d\n",s);

   return 0;

}



Measured memory_bytes: 128
#include<stdio.h>
unsigned char dp[190][190][190][20];
char s[190][190];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%s",s[i]);
	}
	for(int i=n-1;i>=0;i--)
	{
		for(int j=m-1;j>=0;j--)
		{
			bool ok0=true;
			for(int k=j;k<m;k++)
			{
				if(s[i][k]!=s[i][j])
				{
					ok0=false;
				}
				if(!ok0)
				{
					dp[i][j][k][0]=0;
				}
				else if(s[i][j]==s[i+1][j])
				{
					dp[i][j][k][0]=dp[i+1][j][k][0]+1;
				}
				else
				{
					dp[i][j][k][0]=1;
				}
			}
			for(int k=1;k<=16;k++)
			{
				int now=j;
				for(int l=j;l<m;l++)
				{
					dp[i][j][l][k]=0;
					if(dp[i][j][l][k-1])
					{
						dp[i][j][l][k]=dp[i][j][l][k-1]+dp[i+dp[i][j][l][k-1]][j][l][k-1];
					}
					while(now<l&&dp[i][j][now][k-1]>dp[i][now+1][l][k-1])
					{
						now++;
					}
					if(now<l&&dp[i][j][now][k-1]>dp[i][j][l][k])
					{
						dp[i][j][l][k]=dp[i][j][now][k-1];
					}
					if(now>j&&dp[i][now][l][k-1]>dp[i][j][l][k])
					{
						dp[i][j][l][k]=dp[i][now][l][k-1];
					}
				}
			}
		}
	}
	for(int i=0;i<=16;i++)
	{
		if(dp[0][0][m-1][i]>=n)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 131200
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
const ll INF=1e15;
#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
const double pi = acos(-1.0);
int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}

long long binpows(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)  //impar
            res = res * a;
        a = a * a;
        b >>= 1;  // /2
    }
    return res;
}
const int mod=1e9+7;
int binpow(int a, int b, int m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//CHECAR SE PRECISA DE LONG LONG
int dp[3234][3234][2];
vector<int> v;
int n;
int resolve(int l, int r, bool f){
	if(l==r){
		if(f){
			return v[l];
		}else{
			return 0;
		}
	}
	int &x=dp[l][r][f];
	if(x!=-1){
		return x;
	}

	if(f){
		x=0;
		x=max(x,resolve(l+1,r,!f)+v[l]);
		x=max(x,resolve(l,r-1,!f)+v[r]);
	}else{
		x=INF;
		x=min(x,resolve(l+1,r,!f));
		x=min(x,resolve(l,r-1,!f));
	}
	return x;
}
void solve(){
	memset(dp,-1,sizeof(dp));
	cin>>n;
	v.resize(n);
	int sum=0;
	for(auto &i: v){
		cin>>i;
		sum+=i;
	}
	cout<<resolve(0,n-1,true)-(sum-resolve(0,n-1,true))<<endl;
}
//revise as variaveis e a ordem nas funções
signed main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 167264
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int n,k;string s;
	cin>>s;cin>>k;n=s.size();
	rep(i,n-1){
		int now=(s[i]-'a');
		if(now>0 && now+k>=26){
			s[i]='a';k-=26-now;
		}
	}
	int now=(s[n-1]-'a');now+=k;now%=26;
	s[n-1]=('a'+now);
	cout<<s<<endl;
}


Measured memory_bytes: 512
N = int(input())
A = []
max1 = 0
max2 = 0

for _ in range(N):
    tmp = int(input())
    A.append(tmp)
    if tmp > max1:
        max1 = tmp
    elif tmp > max2:
        max2 = tmp

for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)


Measured memory_bytes: 89648
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  ll n,a[111111];
  int f=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2)f=1;
  }
  if(f)cout<<"first"<<endl;
  else cout<<"second"<<endl;
  return 0;
}


Measured memory_bytes: 1024
// 2018, Sayutin Dmitry.

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    string s = input<string>();

    int num_black = 0;
    int64_t ans = 0;

    for (char ch: s)
        if (ch == 'B')
            num_black += 1;
        else
            ans += num_black;

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


Measured memory_bytes: 1356
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();

		double ArrayA[] = new double[a];

		double ans = 0.0;

		for (int i = 0; i < a; i++) {
			ans += 1/sc.nextDouble();
		}

		ans = 1/ans;

		System.out.println(ans);

	}
}


Measured memory_bytes: 23252
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define lint long long
using namespace std;

int main()
{
  int N;
  cin>>N;

  int cnt=1,ans=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a==cnt){
      cnt++;
    }else{
      ans++;
    }
  }
  if(ans==N){
    ans=-1;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
    vector<double> p(N);
    rep(i, N) cin >> p[i];

    dp[1][0] = 1 - p[0];
    dp[1][1] = p[0];

    for (ll i = 2; i <= N; ++i) rep(j, N + 1){
            dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
            if(j >= 1) dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
    }
    
    double ans = 0;
    rep(j, N + 1) if (j > N - j) ans += dp[N][j];
    print(ans);

    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
string ZERO;
string dust;
void print(int a) {
    cout << " " << (a % (2 * N)) + 1;
}
char ans[200];
map<char, vector<int>> mp;
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cout << "?";
    for(int i = 0; i < N; i++) print(i);
    cout << endl;
    cin >> ZERO;
    int ok = 2 * N - 1;
    int ng = 0;
    while(ok - ng > 1) {
        int mid = (ok + ng) / 2;
        cout << "?";
        for(int i = 0; i < N; i++) {
            print(mid + i);
        }
        cout << endl;
        cin >> dust;
        if(dust == ZERO) ng = mid;
        else ok = mid;
    }
    for(int i = 0; i < 2 * N; i++) {
        if(ok <= i && i < ok + N) continue;
        if(ok <= i + 2 * N && i + 2 * N < ok + N) continue;
        cout << "?";
        for(int j = 0; j < N - 1; j++) {
            print(ok + j);
        }
        print(i);
        cout << endl;
        cin >> dust;
        ans[i] = dust[0];
        mp[ans[i]].push_back(i);
    }
    for(int i = 0; i < 2 * N; i++) {
        if((ok <= i && i < ok + N) || (ok <= i + 2 * N && i + 2 * N < ok + N)) {
        //cerr << i << endl;
            cout << "?";
            for(int i = 0; i < N / 2; i++) {
                print(mp['B'][i]);
            }
            for(int i = 0; i < N / 2; i++) {
                print(mp['R'][i]);
            }
            print(i);
            cout << endl;
            cin >> dust;
            ans[i] = dust[0];
        }
    }
    cout << "! ";
    for(int i = 0; i < 2 * N; i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

vector<bool> check;
vi x, y;
int N; 


int main(){
    cin >> N;
    x.resize(N), y.resize(N);
    map<pii, int> mp;
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
        mp[{x[i], y[i]}]=i;
    }
    int res=INF;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i == j) continue;
            int p=x[j]-x[i], q=y[j]-y[i], cost=N;
            vector<bool> check(N, 0);
            for(int k=0; k<N; k++){
                if(check[k]) continue;
                int n=1;
                check[k]=true;
                while(mp.count({x[k]+n*p, y[k]+n*q})){
                    check[mp[{x[k]+n*p, y[k]+n*q}]]=true;
                    n++;
                }
                int m=1;
                while(mp.count({x[k]-m*p, y[k]-m*q})){
                    check[mp[{x[k]-m*p, y[k]-m*q}]]=true;
                    m++;
                }
                cost-=n-1+m-1;
            }
            res=min(res, cost);
        }
    }
    if(N == 1) res=1;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3612
<?php
list($n, $m) = ints();
for($i = 1; $i <= $n; $i++){
    $r[$i] = 0;
    $c[$i] = 1;
}
$r[1] = 1;
for($i = 0; $i < $m; $i++){
    list($f, $t) = ints();
    $c[$f]--;
    $c[$t]++;
    $r[$t] = $r[$t] || $r[$f];
    if($c[$f] == 0){
        $r[$f] = 0;
    }
}
echo array_sum($r),"\n";



function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 14840
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 
int r[7][6];
int c[6][7];

void turn() {
	int nr[7][6], nc[6][7];
	rep(i,6) {
		rep(j,7) {
			nc[i][j] = r[6-j][i];
		}
	}
	rep(i,7) {
		rep(j,6) {
			nr[i][j] = c[5-j][i];
		}
	}
	rep(i,7) {
		rep(j,6) {
			r[i][j] = nr[i][j];
		}
	}
	rep(i,6) {
		rep(j,7) {
			c[i][j] = nc[i][j];
		}
	}
}

int main() {
	rep(i,7) {
		rep(j,6) {
			r[i][j] = 0;
		}
	}
	rep(i,6) {
		rep(j,7) {
			c[i][j] = 0;
		}
	}
	string s;
	rep2(i,1,5) {
		cin >> s;
		rep2(j,1,5) {
			
			r[i][j] = s[j-1] - '0';
		}
		cin >> s;
		rep2(j,1,6) {
			c[i][j] = s[j-1] - '0';
		}
	}
	cin >> s;
	rep2(i,1,5) {
		r[5][i] = s[i-1] - '0';
	}

	int x = 0, y = 0;
	int gx = 0, gy = 0;
	char d[4] = {'R', 'U', 'L', 'D'};
	int dir = 0;
	while(1) {		
		if(!c[y][x+1] && !c[y+1][x+1] && !r[y+1][x+1]) {
			// turn 180
			dir = (dir+2) % 4;
			cout << d[dir];
			rep(i,2) turn();
			x = 4 - x;
			y = 4 - y;
			gx = 4 - gx;
			gy = 4 - gy;
			x++;
			if(x == gx && y == gy) break;
			continue;
		}
		if(c[y][x+1] == 1) {
			// turn left
			dir = (dir+1) % 4;
			cout << d[dir];
			turn();
			swap(y = 4 - y, x);
			swap(gy = 4 - gy, gx);
			x++;
			if(x == gx && y == gy) break;

			continue;
		} 
		if(r[y+1][x+1] == 1) {
			// go straight
			cout << d[dir];
			x++;
			if(x == gx && y == gy) break;
			continue;
		}
		if(c[y+1][x+1] == 1) {
			// turn right
			dir = (dir+3) % 4;
			cout << d[dir];
			rep(i,3) turn();
			swap(x = 4 - x, y);
			swap(gx = 4 - gx, gy);
			x++;
			if(x == gx && y == gy) break;

		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

template <class Iit>
void vout(const Iit &begin,const Iit &end,ostream &out) {
    for(auto it = begin; it != end; it++) {
        auto tmp = it;
        if (++tmp == end) out << *it << '\n';
        else out << *it << " ";
    }
}


int main(void)
{
    IOS
    // const char B = '0';
    constexpr int BW = 11;
    const char W = '1';    
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> ss(h);
    REP(i,h) cin >> ss[i];
    vector<vector<int>> rsum(h+1,vector<int>(w+1));

    FOR(y,1,h+1) FOR(x,1,w+1) {
        rsum[y][x] = rsum[y-1][x] + rsum[y][x-1] - rsum[y-1][x-1] + ((ss[y-1][x-1] == W) ? 1 : 0);
        //if (x == w) cerr << rsum[y][x] << endl;
    }
    auto calcrsum = [&](const int x1,const int y1,const int x2,const int y2) {
        //cerr << x1 << y1 << x2 << y2 << endl;
        return rsum[y2][x2] - rsum[y1][x2] - rsum[y2][x1] + rsum[y1][x1];
    };


    int ans = h*w;
    int hpow = pow(2,h-1);
    REP(i,hpow) {
        bitset<BW> bs(i);
        bs <<= 1;
        int tmp = bs.count();
        bs.set(0); bs.set(h);
        //cerr << bs << endl;
        vector<int> cut;
        REP(j,BW) if (bs[j]) cut.push_back(j);
        // vout(ALL(cut),cerr);
        int x1 = 0, x2 = 1;

        while(x2 <= w) {
            //cerr << x1 << " " << x2 << endl;
            bool ok = true,oneok = true;
            REP(j,cut.size()-1) {
                if (calcrsum(x1,cut[j],x2,cut[j+1]) > k) {
                    ok = false;
                    if (x2-x1 == 1) oneok = false;
                }
            }
            if (!oneok) {
                tmp = h*w;
                break;
            } else if (!ok) {
                x1 = x2-1;
                tmp++;
            } else {
                x2++;
            }
        }
        // cerr << tmp << endl;
        ans = min(ans,tmp);
    }
    

    cout << ans << '\n';

    return 0;
}

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

int main() {
	unsigned long long a, b, x;
	unsigned long long  count = 0;
	cin >> a >> b >> x;
	
	if (a != 0) {
		cout << b / x - (a -1)/ x << endl;
	}
	else {
		cout << b / x + 1 << endl;
	}
}

Measured memory_bytes: 256
L, R = map(int, input().split())
mini = mod = 2019

for i in range(L, R+1):
    for j in range(i+1, R+1):
        mod = (i * j) % 2019
        mini = min(mini, mod)
        
        if (mini == 0):
            print(mini)
            exit()
        
print(mini)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
    int i,t,n,a[100];
    scanf("%d",&n);
    for(i=0;i<=n-1;i+=1){
        scanf("%d",&a[i]);
    }
    for(t=n-1;t>=0;t-=1){
        if(t==0){
            printf("%d\n",a[t]);
        }
        else{
            printf("%d ",a[t]);
        }
    }
    return 0;
}

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

ll n, a, b, c, d;
string s;

bool dfs (ll i, ll j) {
    cerr << i << endl;
    cerr << j << endl;
    if (i == c-1 && j == d-1) return true;

    if (d > c) {
        // B１すすむ
        if (s[j+1] == '.' && s[j+1] != '#' && j != i+1 &&j != d-1) return dfs(i, j+1);
        // B２すすむ
        if (s[j+1] == '#' && s[j+2] == '.' && j != d-1) return dfs(i, j+2);
        // A１すすむ
        if (s[i+1] == '.' && i+1 != j && i != c-1) return dfs(i+1, j);
        // A２すすむ
        if (s[i+1] == '#' && s[i+2] == '.' && i+2 != j && i != c-1) return dfs(i+2, j);
    }
    if (d < c) {
        // AがBを追い越す
        if (i+1 == j && s[i+2] == '.' && i != c-1) return dfs(i+2, j);
        // A１すすむ
        if (s[i+1] == '.' && s[i+1] != '#' && i+1 != j && i != c-1) return dfs(i+1, j);
        
        if (s[i+1] == '#' && s[i+2] == '.' && i+2 != j && i != c-1) return dfs(i+2, j);

        if (s[j+1] == '.' && s[j+1] != '#' && j != i+1 && j != d-1) return dfs(i, j+1);

        if (s[j+1] == '#' && s[j+2] == '.' && j != d-1) return dfs(i, j+2);

    }
    if (s[i+1] == '#' && i+2 == j) return false;
    
    if (s[i+1] == '#' && s[i+2] == '#') return false;

    if (s[j+1] == '#' && s[j+2] == '#') return false;
}

int main() {
    cin >> n >> a >> b >> c >> d;
    cin >> s;

    if (dfs(a-1, b-1)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int x, y, z;
    cin >> x >> y >> z;

    int ans = (x - z) / (y + z);
    
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define inf 0x3f3f3f3f
using namespace std;

const int maxn = 2e5;
typedef unsigned long long ULL;
typedef long long ll;

int n,A,B,C;
string s[maxn];

int main(){
    int X;cin>>X;
    for(int i=-1000;i<=1000;i++){
        for(int j=-1000;j<=1000;j++){
            ll A=1ll*i*i*i*i*i;
            ll B=1ll*j*j*j*j*j;
            if(A-B==X){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 9884
a, b, k = map(int, input().split())

ans = list(range(a, a+k)) + list(range(b-k+1, b+1))
ans.sort()
ans2 = []
for i in ans:
    if a<=i<=b and i not in ans2:
        ans2.append(i)

for j in ans2:
    print(j)

Measured memory_bytes: 3060
N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i).sort.reverse!
B = gets.chomp.split.map(&:to_i)
C = gets.chomp.split.map(&:to_i).sort!

ans = 0
N.times do |i|
  a_idx =  A.bsearch_index { |x| x < B[i] }
  c_idx =  C.bsearch_index { |x| x > B[i] }

  next if a_idx.nil? || c_idx.nil?

  c_cnt = N - c_idx
  a_cnt = N - a_idx

  ans += c_cnt * a_cnt
end

puts ans


Measured memory_bytes: 25276
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll m=1e9+7;
ll lev=0;
ll n,k;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p)%m;
p=(p*p)%m;
k>>=1;
}
return a;
}
using namespace std;
vector<ll> v[1000000+1];
ll vis[1000000+1]={0};
void dfs(ll u,ll p,ll lev)
{
    vis[u]=lev;
for(auto x: v[u])
{
if(x!=p)
{
dfs(x,u,lev+1);
}
}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
  
  double r;
  cin>>r;
  double ans=3.1415926535*r*2;
  printf("%.10f",ans); 
     cout<<"\n"; 
 } 
}


Measured memory_bytes: 27244
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2399

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int N;
  while (cin >> N && N) {
    bool D[110][110];
    fill(&D[0][0], &D[0][0]+110*110, false);
    for (auto i=0; i<N; i++) {
      int M;
      cin >> M;
      for (int j=0; j<M; j++) {
	int p;
	cin >> p;
	D[i][p] = true;
      }
    }
    int K;
    cin >> K;
    vector<int> E;
    for (auto i=0; i<K; i++) {
      int l;
      cin >> l;
      E.push_back(l);
    }
    int c = 0;
    int last;
    for (auto i=0; i<N; i++) {
      for (auto j=0; j<E.size(); j++) {
	if (!D[i][E[j]]) {
	  goto EXIT;
	}
      }
      c++;
      last = i+1;
      // cerr << "c = " << c << ", last = " << last << endl; 
    EXIT:
      continue;
    }
    if (c != 1) {
      cout << "-1" << endl;
    } else {
      cout << last << endl;
    }
  }
}

Measured memory_bytes: 1228
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = Counter(a).most_common()[::-1]
# print(cnt)
# print(cnt)
ans = 0
for i in range(len(cnt) - k):
    ans += cnt[i][1]
print(ans)


Measured memory_bytes: 41160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
typedef long long ll;
int main(){
  int h,w,n; cin >> h >> w >> n;
  int t = max(h, w);
  int r = 1+(n /t);
  if(n%t==0){ r=n/t;}
  cout << r;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		boolean t = false;
		int cnt = 1;
		while (true) {
			if ((a * cnt) % b == c) {
				t = true;
			}
			if (cnt == b) {
				break;
			}
			cnt++;
		}
		if (t) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 23252
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define LEN(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
using ll = long long;
using llu = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod(ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

////////////////////////// Solution starts below. //////////////////////////////

vector<string> vec = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
	string s;
	cin >> s;
	int ans = 0;
	int p = 0;
	while(vec[p] != s) ++p;
	while(vec[p] != "SUN") {
		p = (p+1)%7;
		++ans;
	}

	if(!ans) ans += 7;
	cout << ans << '\n';

	return 0;
}


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

int main(){
	string s;
	cin>>s;
	s=s+"X";
	int start=0;
	int p;
	int len;
	long long int numBC;
	long long int sumBC;
	long long int ans=0;
	while (start<s.length()) {
		p=0;
		len=0;
		numBC=0;
		sumBC=0;
		while (s[start+p]=='A'||s.substr(start+p,2)=="BC") {
			if (s[start+p]=='A') {
				p++;
			}else {
				numBC++;
				sumBC+=len;
				p+=2;
			}
			len++;
		}
		ans+=sumBC-numBC*(numBC-1)/2;
		start+=p+1;
	}
	cout<<ans<<endl;
}

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

int main() {
	string str;
	int m, h;
    
	while(cin >> str,str != "-"){
		cin >> m;
		for (int i = 0; i < m; ++i) {
			cin >> h;
			str.append(str.substr(0, h)).erase(0, h);
		}
		cout << str << endl;
	}
    
	return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 2e3 + 5;

int n,x,y,a[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			a[min(abs(i-j),min(abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1))]++;
		}
	}
	for(int i=1;i<n;i++){
		cout<<a[i]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 256
program max_gcd
  implicit none
  integer :: n, a(500) = 0, s, d(100000) = 0, num = 0, i, j, x(500) = 0
  integer(8) :: k, m, p, q
  read(*,*) n, k
  read(*,*) a(1:n)
  s = sum(a(1:n))
  do i = 1, s
    if (i*i > s) exit
    if (mod(s,i) /= 0) cycle
    num = num+1
    d(num) = i
    if (s/i /= i) then
      num = num+1
      d(num) = s/i
    end if
  end do
  call quick_sort(d(1:num))
  do i = num, 1, -1
    x(1:n) = mod(a(1:n),d(i))
    call quick_sort(x(1:n))
    m = 1e18
    q = sum(int(d(i)-x(1:n),8))
    p = 0_8
    do j = 1, n
      p = p+int(x(j),8)
      q = q-int(d(i)-x(j),8)
      m = min(m,max(p,q))
    end do
    if (m <= k) then
      write(*,'(i0)') d(i)
      stop
    end if
  end do
  stop
contains
  recursive subroutine quick_sort(a)
    implicit none
    integer, intent(inout) :: a(:)
    integer :: p, c
    integer :: n, l, r, m
    n = size(a)
    l = 1
    r = n
    m = (l+r)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      c = a(l)
      a(l) = a(r)
      a(r) = c
      l = l+1
      r = r-1
    end do
    if (l > 2) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end subroutine quick_sort
end program max_gcd

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

char L[100005];
int dp1[100005];
int dp2[100005];
signed main(){
    scanf("%s",L);
    int Ll=strlen(L);
    dp1[0]=2;//一番上の桁が1
    dp2[0]=1;//一番上の桁が0(確定)
    for(int i=1;i<Ll;i++){
        if(L[i]=='0'){
            //A XOR B = 0 <=> A=0,B=0
            dp1[i]+=dp1[i-1];
            dp2[i]+=dp2[i-1];
            //A XOR B = 1 //dp1は超えちゃうからだめ
            dp2[i]+=dp2[i-1]*2;
        }else{
            //A XOR B =0 //dp1にはならない
            dp2[i]+=dp1[i-1]+dp2[i-1];
            //A XOR B = 1
            dp1[i]+=dp1[i-1]*2;
            dp2[i]+=dp2[i-1]*2;
        }
        dp1[i]%=mod;
        dp2[i]%=mod;
        //rintf("%lld/%lld-",dp1[i],dp2[i]);

    }
    printf("%lld",(dp2[Ll-1]+dp1[Ll-1])%mod);
    return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		System.out.println(n*n*n);
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    char c; cin >> c;
    if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u')) cout << "vowel";
    else cout << "consonant";
}

Measured memory_bytes: 3608
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#include <vector>
#include<cstdio>
#include <numeric>
#include <queue>
#include <list>
using namespace std;

int main(){
    int N;cin>>N;
    int n=N%10;
    if(n==1 || n==0 ||n==6||n==8){
        cout<<"pon"<<endl;
    }
    if(n==2 || n==4 ||n==5||n==7||n==9){
        cout<<"hon"<<endl;
    }
    if(n==3){
        cout<<"bon"<<endl;
    }
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll cost[10][10];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  rep(i,10) rep(j,10) cin>>cost[i][j];
  vvll a(h,vll(w));
  rep(i,h) rep(j,w) cin>>a[i][j];
  
  vll costTo1(10);
  rep(i,10){
    queue<pll> q;
    vll dist(10,INF);
    dist[i]=0;
    q.emplace(i,0);
    while(!q.empty()){
      auto p=q.front(); q.pop();
      ll v=p.first, c=p.second;
      if(dist[v]<c) continue;
      rep(nv,10){
        if(v==nv) continue;
        if(dist[nv]>dist[v]+cost[v][nv]){
          dist[nv]=dist[v]+cost[v][nv];
          q.emplace(nv,dist[nv]);
        }
      }
      costTo1[i]=dist[1];
    }
  }
  ll ans=0;
  rep(i,h) rep(j,w) if(a[i][j]!=-1) ans+=costTo1[a[i][j]];
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
const int maxN = int(1e5+10);
int e[maxN]={},o[maxN]={};
int num[maxN]={};

int main(){
    int n;
    cin >> n;
    if(n==1){
        cout << "Hello World" << endl;
    }else{
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	 ios_base::sync_with_stdio(0); cin.tie(0);
    int a, b, c, x;
	int count = 0;
	cin >> a >> b >> c >> x;
 
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (x == i * 500 + j * 100 + k * 50) {
					count++;
				}
			}
		}
	}
	cout << count << endl;
		
	
}

Measured memory_bytes: 256
N = int(input())
w = list(map(int, input().split()))
T = int(N/2)

s1 = sum(w[:T])
s2 = sum(w[T:])
diff = abs(s1-s2)

for i in range(N):
  if s1 > s2:
    s1 -= w[T-1]
    s2 += w[T-1]
    T -= 1
    if abs(s1-s2) > diff:
      break;
    else:
      diff = abs(s1-s2)
  elif s1 < s2:
    s1 += w[T]
    s2 -= w[T]
    T += 1
    if abs(s1-s2) > diff:
      break;
    else:
      diff = abs(s1-s2)
  else:
    break;
    
print(diff)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,i,x,d,c=1,s=0;
 	cin>>n>>x;
 	int a[n],b[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
 	for(i=0;i<n;i++)
 		{
 			s=s+a[i];
 			if(s<=x)
 				c++;
		 }
		 cout<<c<<endl;
 }

Measured memory_bytes: 3588
#include <stdio.h>
//#define DEBUG

/*??°????????°?????????????????°??§????´?*/
int map[14][14] = {{}};



void search(int,int);

int main (void){


	while (1){
		char str[12] = {};
		int counter = 0 ;
		int i = 0 ;
		int j = 0 ;
		/*??°??????????????????*/

		for( i = 0 ; i < 12 ; i++){
				if(scanf("%s",str) == EOF){			//EOF???????????£??????????????´??§??????
					return 0;
				}
				for ( j = 0 ; j < 12 ; j++){
					map[i+1][j+1] = str[j] - '0';
				}
		}



		for(i = 0 ; i < 14 ; i++){
			for( j = 0 ; j < 14 ; j++){
				if(map[i][j]){			//?????°?????£??????

					search(i,j);		//???????????¢??°???????????????
					counter++;			//???????????¢??°????????????????????£?????°??£??????????????¶?????°??????????????¢??????
				}
			}
		}


#ifdef DEBUG
		//??°????????¶????????¨????????????
		for(i = 0 ; i < 14 ; i++){
			for( j = 0 ; j < 14 ; j++){
				printf("%2d",map[i][j]);
			}
			printf("\n");
		}
#endif

		printf("%d\n",counter);




	}
	return 0;
}

/*???????????¢??°*/
void search(int x,int y){
	map[x][y] = 0 ;				//?????¨??°??????????????¨???????¶?????????????
	if(map[x][y-1]){			//???????????????????????§?¨???§???????????¢??°???????????????
		search(x,y-1);
	}
	if(map[x][y+1]){			//???????????????????????§?¨???§???????????¢??°???????????????
		search(x,y+1);
	}
	if(map[x-1][y]){			//???????????????????????§?¨???§???????????¢??°???????????????
		search(x-1,y);
	}
	if(map[x+1][y]){			//???????????????????????§?¨???§???????????¢??°???????????????
		search(x+1,y);
	}
	/*????????¢??°?????§?¨??????¨????????¨???0??????????????¢??°?????????????????????
	 main????????????????????°?¶???????1?????¨???0????????£?????????*/
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<ll>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end()
const ll INF=1e18;
const double PI=4*atan(1);

#define SpeedForce                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base,ll exp);
void solve();
ll POW(ll base,ll exp);
ll gcd(ll a,ll b);

int32_t main(){
    SpeedForce
    ll i = 0,j = 0;

    int t;
    t=1;
    //cin >> t;
    while (t--){
        //cout << fixed << setprecision(10);
        solve();
    }
}

void solve(){
   ll x,y;
   cin >> x >> y;
   if(y<=4*x && y>=2*x && y%2==0) cout << "Yes";
   else cout << "No";
}

ll POW(ll base,ll exp){
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base);
        base = ((ll)base * base);
        exp >>= 1;
    }
    return result;
}

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

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

Measured memory_bytes: 3608
#include <stdio.h>
 
 int main(void){
 
    int a,b,c,x;
    
    scanf("%d %d %d",&a,&b,&c);
 
         if(b < a){
        x = a;
        a = b;
        b = x;
 
   }    if(c < b){
        x = b;
        b = c;
        c = x;
 
   }    if(b < a){
        x = a;
        a = b;
        b = x;
   }

   printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2080
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    x,y=input().split()
    if x<y:
        print("<")
    elif x>y:
        print(">")
    else:
        print("=")

main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int bound = 1000;
vector<int> g[bound*bound];
int h[bound*bound];
int cnt = 0;

void tps( int p ){
	if( h[p] <= 1  ){
		h[p] = min(0, h[p]);
		++cnt;
		for( auto next : g[p] ) tps( next );
	} else {
		--h[p];
	}
}

int dist[bound*bound];
bool besucht[bound*bound];

int dfs( int p ){
	if( besucht[p] ) return dist[p];
	besucht[p] = true;
	int res = 0;
	for( auto nextp : g[p] ){
		res = max(res, dfs(nextp)+1);
	}
	return dist[p] = res;
}

int main(){
	int n; cin >> n;
    set<int> candy;
	int prev = 0, cur = 0;
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j < n-1; ++j ){
			prev = cur;
			int a = i, b;
			cin >> b; --b;
			if( a > b ) swap(a, b);
			cur = bound*a+b;
			candy.insert(cur);
			if( j == 0 ) continue;
			g[prev].push_back(cur);
			++h[cur];
		}
	}
	vector<int> cookie;
	for( auto p : candy ) if( h[p] == 0 ) cookie.push_back(p);
	for( auto p : cookie ) tps(p);
	if( cnt != candy.l_ength() ){
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	for( auto p : candy ){
		ans = max(ans, dfs(p));
	}
	cout << ans+1 << endl;
}

Measured memory_bytes: 71552
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/30 10:40:41 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	int	n;
	cin >> n;

	vector<vector<int>>	dp(3, vector<int>(n + 1));
	rep(i, n)
	{
		int	a, b, c;
		cin >> a >> b >> c;
		dp.at(0).at(i + 1) = max(dp.at(1).at(i), dp.at(2).at(i)) + a;
		dp.at(1).at(i + 1) = max(dp.at(0).at(i), dp.at(2).at(i)) + b;
		dp.at(2).at(i + 1) = max(dp.at(0).at(i), dp.at(1).at(i)) + c;
	}
	cout << max({dp.at(0).back(), dp.at(1).back(), dp.at(2).back()}) << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
	int n,i,j,minj,a[100],count,tmp;
	count = 0;
	
	scanf("%d",&n);
	
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
		}
		
	for(i = 0;i < n;i++){
		minj = i;
		for(j = i; j < n;j++){
			if(a[j] < a[minj]){
			minj = j;
			}
		}
		if(minj != i){
			tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
			count++;
		}
	}
	
	for (i = 0; i < n; i++) {
		printf("%d", a[i]);
		if(i < n -1)
			putchar(' ');
	}
	printf("\n");
	printf("%d\n", count);
		
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll A(N);
  REP(i,N) IN(A[i]);

  ll M = 1000;

  REP(i,N-1){
    if(A[i]<A[i+1]){
      ll tmp = M/A[i];
      M = M - tmp*A[i];
      M = M + tmp*A[i+1];
    }
  }

  OUT(M);

  return 0;
}

Measured memory_bytes: 3652
N=int(input())
S=input()
A=["SS","SW","WS","WW"]

X=""
for a in A:
    T=a
    for i in range(1,N-1):
        if T[-1]=="S":
            if S[i]=="o":
                T+=T[-2]
            else:
                if T[-2]=="S":
                    T+="W"
                else:
                    T+="S"
        else:
            if S[i]=="o":
                if T[-2]=="S":
                    T+="W"
                else:
                    T+="S"
            else:
                T+=T[-2]

    F=True
    if (T[0]=="S") and not((S[0]=="o")^(T[1]==T[-1])):
        pass
    elif (T[0]=="W") and not((S[0]=="x")^(T[1]==T[-1])):
        pass
    else:
        F=False

    if (T[-1]=="S") and not((S[-1]=="o")^(T[0]==T[-2])):
        pass
    elif (T[-1]=="W") and not((S[-1]=="x")^(T[0]==T[-2])):
        pass
    else:
        F=False

    if F:
        X=T

if X:
    print(X)
else:
    print(-1)


Measured memory_bytes: 9560
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let mut a = read::<i64>();

  println!("{}", if 0 < a && a < 1200 { "ABC" } else {"ARC"});
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll N; cin >> N;
    map<ll,ll> M;
    rep(i,N){
        ll a; cin >> a;
        M[a]++;
    }
    
    vector <ll> V;
    for (auto i:M){
        if (i.second>1){
            V.push_back(i.first);
            if (i.second>3) V.push_back(i.first);
        }
    }
    
    if (V.size()<2) cout << 0 << endl;
    else{
        sort(V.begin(),V.end(),greater<int>());
        cout << V[0]*V[1] << endl;
    }
}

Measured memory_bytes: 6528
a,b,c = map(int, input().split())
k = int(input())
aa,bb,cc = a,b,c
ans = False
for i in range(k,-1,-1):
  aa,bb,cc = a,b,c
  cc *= 2**i
  bb *= 2**(k-i)
  if cc>bb>aa:
    ans = True
    break
    
if ans:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9204