akhauriyash/Code-Regression huggingface dataset:
/**
 * CatChecker
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

import static java.lang.Integer.parseInt;

public class Main {

	static Set<String> cat = new HashSet<>();
	static Set<String> rabbit = new HashSet<>();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		cat.add("");
		cat.add("mew");

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			System.out.println(isCat(line) ? "Cat" : "Rabbit");
		}
	}

	static boolean isCat(String S) {

		if (cat.contains(S)) return true;
		if (rabbit.contains(S)) return false;

		if (S.charAt(0) == 'm'
				&& S.charAt(S.length() - 1) == 'w'
				&& S.indexOf('e') > 0) {
			boolean ret = false;
			String _S = S.substring(1, S.length() - 1);
			for (int i = 0; i < _S.length(); i++) {
				if (_S.charAt(i) == 'e') {
					ret = isCat(_S.substring(0, i)) & isCat(_S.substring(i + 1));
					if (ret) {
						cat.add(S);
						break;
					} else {
						rabbit.add(S);
					}
				}
			}
			return ret;
		}

		return false;
	}
}

Measured memory_bytes: 180072
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
  int n;
  cin >> n;
  int p[n], pmax=10, sum=0;
  for(int i=0; i<n; i++){
    cin >> p[i];
    pmax= max(pmax, p[i]);
    sum = sum + p[i];
  }

  cout << sum - pmax / 2 << endl;
  
  return 0;
}
    

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

long long a[7];
int main()
{
  for (int i = 0; i < 7; i++){
    cin >> a[i];
  }

  long long m = min(min(a[0], a[3]), a[4]);
  /*
  a[0] -= m;
  a[3] -= m;
  a[4] -= m;
  */

  long long ans = 0;
  for (int i = 0; i <= min(m, 100ll); i++){
    ans = max(ans, 3 * i + (a[0] - i) / 2 * 2 + (a[3] - i) / 2 * 2 + (a[4] - i) / 2 * 2);
  }

  cout << ans + a[1] << endl;
}


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

int main() {
  int N; cin >> N;
  vector<string> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  vector<int> num(4);
  for (int i = 0; i < N; i++) {
    if (A[i] == "AC") num[0]++;
    else if (A[i] == "WA") num[1]++;
    else if (A[i] == "TLE") num[2]++;
    else num[3]++;
  }
  
  cout << "AC x " << num[0] << endl;
  cout << "WA x " << num[1] << endl;
  cout << "TLE x " << num[2] << endl;
  cout << "RE x " << num[3] << endl;
}

Measured memory_bytes: 6348
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<string>
#include<set>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<cmath>
#include<cstdlib>


int main()
{
	int N, P;
	std::cin >> N >> P;
	std::vector<int> A(N);
	int total = 0, even_num = 0, odd_num = 0;
	int num[2] = { 0, 0 };
	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
		total += A[i];
		num[A[i] % 2]++;
	}

	long long ans = 0;

	if (num[1] == 0) {
		if (P == 0)
			ans = pow(2, N);
		else
			ans = 0;
	} else {
		ans = pow(2, N - 1);
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (a, b, k) = get!(i32, i32, i32);
    let mut v = Vec::new();
    for i in 1..std::cmp::min(a, b) + 1 {
        if a % i == 0 && b % i == 0 {
            v.push(i);
        }
    }
    //eprintln!("{:?}", v);
    println!("{}", v[v.len() - k as usize]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
    int A,B,C;
    cin>>A>>B>>C;
    REP(i,100){
        if(i*A%B==C){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define pb push_back
int main(){
	int n,ans=1;
	vector<int> a;
	cin>>n;
	for(int i=0;i<n;++i){
		int v;
		cin>>v;
		if(a.empty()||a[a.size()-1]!=v){
			a.pb(v);
		}
	}
	if(a.size()==1){
		cout<<1<<endl;
		return 0;
	}
	for(int i=0;i<a.size()-2;++i){
		if((a[i]<a[i+1]&&a[i+1]>a[i+2])||(a[i]>a[i+1]&&a[i+1]<a[i+2])){
			++ans;
			++i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 892
s = list(input())

res1, res2 = len(s), len(s)
for i in range(len(s)):
    if i % 2 == 0:
        if int(s[i]) == 0:
            res1 -= 1
        if int(s[i]) == 1:
            res2 -= 1
    else:
        if int(s[i]) == 1:
            res1 -= 1
        if int(s[i]) == 0:
            res2 -= 1

ans = min(res1, res2)
print(ans)


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define ll long int

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

    string t = s.substr(0,4);

    int n = stoi(t);

    if(n < 2019){
        cout << "Heisei" << endl;
    }else{
        t = s.substr(5,2);
        n = stoi(t);
        if(n <= 4){
            cout << "Heisei" << endl;
        }else{
            cout << "TBD" << endl;
        }
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; string s;
	cin>>N; cin>>s;
	if(N%2){
		cout<<"No"; return 0;
	}
	int tr=1;
	for(int i=0;i<N/2;i++){
		if(s[i] != s[i+(N/2)]) tr=0;
	}
	if(tr) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int matrix[110][110];
int d[110];
int f[110];
int n;
int elapsed = 1;

void visit(int v) {
  d[v] = elapsed++;

  FOR(i, 1, n + 1) {
    if (matrix[v][i] && d[i] < 0 ) {
      visit(i);
    }
  }
  f[v] = elapsed++;
}

int main() {
  REP(x, 110) {
    REP(y, 110) {
      matrix[x][y] = 0;
    }
    d[x] = -1;
    f[x] = -1;
  }

  // int n;
  cin >> n;

  REP(_, n) {
    int v, num;
    cin >> v >> num;

    REP(i, num) {
      int cv;
      cin >> cv;
      matrix[v][cv] = 1;
      // matrix[cv][v] = 1;
    }
  }


  FOR(v, 1, n + 1) {
    if (d[v] < 0) {
      visit(v);
    }
  }

  FOR(v, 1, n + 1) {
    cout << v << " " << d[v] << " " << f[v] << endl;
  }


  return 0;
}

Measured memory_bytes: 3148
/****************************
*  Developer : joshi08
*  Date  :  21-06-2020
*  Year  :  2020
****************************/

#include <bits/stdc++.h>

#define lli long long int
#define mod 1000000007
#define fi first
#define se second
#define ii pair<lli, lli>
#define mp make_pair
#define endl '\n'
const double PI = 3.141592653589793238460;
lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a);}
lli max(lli a, lli b) {if (a > b) return a; else return b;}
lli min(lli a, lli b) {if (a < b) return a; else return b;}
lli power(lli a,lli b) {lli i,p=1; for(i=0;i<b;i++){p*=a;} return p;}

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

	lli i,j=0,k,m,n;
	cin>>n>>k;
	
	vector<lli> v;
	for(i=0;i<n;i++)
	{
		cin>>m;
		v.push_back(m);
		
		
	}
	
	sort(v.begin(),v.end());
	
	for(i=0;i<k;i++)
	{
		j+=v[i];
	}
	cout<<j;

    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}



int main()
{
	//IOS;
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2) cout<<b-a;
    else cout<<a-b;

	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;

P dp[51][51]={};

ll x[100001];
ll y[100001];
int main() {
	int w,a,b;
	cin>>w>>a>>b;
	cout<<max(0,max(a-b-w,b-a-w))<<endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> vec(10, vector<int>(10));
  rep(i, N) {
    int s, e;
    e = (i+1) % 10;
    s = to_string(i+1).at(0)-'0';
    vec.at(s).at(e) += 1;
  }
  int ans = 0;
  rep(s, 10) {
    if (s == 0) continue;
    rep(e, 10) {
      // cout << s << "-" << e << "=" << vec.at(s).at(e) << endl;
      ans += vec.at(s).at(e) * vec.at(e).at(s);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    const double PI = acos(-1);
    int R;
    cin >> R;
    cout << 2 * PI * R << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <iomanip>

using namespace std;

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

	vector<int> L;
	vector<int> R;

/*	for (int i = 0; i < M;i++) {
		int tmp;
		cin >> tmp;
		L.push_back(tmp);
		cin >> tmp;
		R.push_back(tmp);
	}
	*/
	int L_max = 0;
	int R_min = N;
	for (int i = 0; i < M;i++) {
			int tmp;
			cin >> tmp;
			if (tmp > L_max) {
				L_max = tmp;
			}
			cin >> tmp;
			if (tmp < R_min) {
				R_min = tmp;
			}
	}

	if (R_min - L_max + 1 > 0) {
		cout << R_min - L_max + 1 << endl;
	}
	else {
		cout << 0<< endl;
	}


}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}

struct edge{ll to,cost;};
typedef pll P;
struct graph{
    ll V;
    vector<vector<edge>> G;
    vecll d;
    graph(ll n){ init(n); }
    void init(ll n){
        V=n;
        G.resize(V);
        d.resize(V,LONG_MAX);
    }
    void add_edge(ll s,ll t,ll cost){
        edge e;
        e.to=t;
        e.cost=cost;
        G[s].pb(e);
        e.to=s;
        G[t].pb(e);
    }
    void dijkstra(ll s){
        REP(x,d) x=LONG_MAX;
        d[s]=0;
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            ll v=p.second;
            if(d[v]<p.first)continue;
            REP(e,G[v]){
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }
    }
};

int main(){
    int n=in(),m=in(),s=in()-1,t=in()-1;
    vector<graph> g(2,n);
    rep(i,m){
        int a=in()-1,b=in()-1,u=in(),v=in();
        g[0].add_edge(a,b,u);
        g[1].add_edge(a,b,v);
    }
    g[0].dijkstra(s);
    g[1].dijkstra(t);
    vecll ans(n);
    ans[n-1]=g[0].d[n-1]+g[1].d[n-1];
    rep3(i,n-2,0)ans[i]=min(ans[i+1],g[0].d[i]+g[1].d[i]);
    ll k=1000000000000000;
    REP(x,ans)cout<<k-x<<endl;
}

Measured memory_bytes: 19712
function setUp(input) {
  input = input.split("\n");
  N = Number(input[0].split(" ")[0]);
  VList = input[1].split(" ").map(function (d, i) {
    return Number(d);
  });
  CList = input[2].split(" ").map(function (d, i) {
    return Number(d);
  });
  main();
}
function main() {
  var max = 0;
  VList.forEach(function (d, i) {
    var value = d - CList[i];
    if (value > 0) {
      max += value;
    }
  })
  console.log(max);
}

setUp(require("fs").readFileSync("/dev/stdin", "utf8"));

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

namespace AtCoderBeginnerContest152
{
	class Program
	{
		private const int ModNum = 1000000007;

		static void Main(string[] args)
		{
			var number = int.Parse(Console.ReadLine());
			var cij = new int[10, 10];

			for (var i = 1; i <= number; i++)
			{
				cij[HighestNumber(i), i % 10]++;
			}

			var result = 0;
			for (var i = 0; i < 10; i++)
			{
				for (var j = 0; j < 10; j++)
				{
					result += cij[i, j] * cij[j, i];
				}
			}

			Console.WriteLine(result);
		}

		private static int HighestNumber(int num)
		{
			var result = num / 1;
			while (result >= 10)
			{
				result /= 10;
			}
			return result;
		}
	}
}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_144A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B;

            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);

            if (A <= 9 && A >= 1 && B <= 9 && B >= 1)
                Console.WriteLine(A * B);
            else
                Console.WriteLine("-1");
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a=1;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<i;j++){
            if(s[i]==s[j]) a=0;
        }
    }
    if(a) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define SORT(c) sort(ALL((c)))
#define debug(x)                 \
    do {                         \
        std::cout << #x << ": "; \
        view(x);                 \
    } while (0)

template <typename T>
void view(T e) {
    std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
    for (const auto& e : v) {
        std::cout << e << ", ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
    for (const auto& v : vv) {
        view(v);
    }
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M);
    unordered_map<ll, vector<ll>> m;
    Graph g(N + 1);
    rep(i, M) {
        cin >> a[i] >> b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    vector<ll> dist(N + 1, LLONG_MAX);
    queue<ll> q;
    dist[1] = 0;
    q.push(1);

    while (!q.empty()) {
        ll v = q.front();
        q.pop();
        for (auto x : g[v]) {
            if (x == N && (dist[v] + 1) <= 2) {
                puts("POSSIBLE");
                return 0;
            }
            if (dist[x] > dist[v] + 1) {
                dist[x] = dist[v] + 1;
                q.push(x);
            }
        }
    }

    puts("IMPOSSIBLE");

    return 0;
}


Measured memory_bytes: 21340
n=int(input())
s=[["a",1]]
d=[chr(ord("a")+i)for i in range(10)]
for i in range(n-1):
    t=[]
    for j in s:
        for h in range(j[1]):
            t.append([j[0]+d[h],j[1]])
        t.append([j[0]+d[h+1],j[1]+1])
    s=t.copy()
for i in sorted(s):
    print(i[0])

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<vector<ll>> adj;
int dfs(int n=0, int p=-1) {
  int result = 0;
  for (auto x: adj[n]) {
    if (x==p) continue;
    result ^= dfs(x,n);
  }
  if (p!=-1) result++;
  // cout << n << " " << p << " " << result << endl;
  return result;
}

int main() {
  int N; cin >> N;
  adj.resize(N);
  rep(i,N-1) {
    ll x, y; cin >> x >> y; x--; y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  string result = dfs() ? "Alice" : "Bob";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 11904
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N, T;
int A[100010];
int B[100010];

int main() {
  cin >> N >> T;
  int m = 0;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    if (i == 0) B[i] = A[i];
    else        B[i] = min(B[i-1], A[i]);

    if (A[i] >= B[i]) {
      m = max(m, A[i] - B[i]);
    }
  }
  int ans = 0;
  for (int i=0; i<N; i++) {
    if (A[i] - B[i] == m) ans++;
  }
  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main(){
    int a = 0, x[3] = {0};
    string s[3]; cin >> s[0] >> s[1] >> s[2];

    for( ; x[a] - s[a].size(); ) a = s[a][x[a]++] - 'a';

    cout << char('A' + a);
}


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

int main() {
    int N;
    scanf("%d", &N);
    char S[605][605], T[605][605];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            char c;
            scanf(" %c", &c);
            S[i][j] = S[i + N][j] = S[i][j + N] = S[i + N][j + N] = c;
            T[j][i] = T[j + N][i] = T[j][i + N] = T[j + N][i + N] = c;
        }
    }

    int ab[305][305];
    memset(ab, -1, N * 305 * sizeof(int));
    int ans = 0;
    for (int a = 0; a < N; ++a) for (int b = 0; b < N; ++b) {
        if (~ab[a][b]) ans += ab[a][b];
        else {
            int ok = 1;
            for (int i = 0; i < N; ++i) {
                if (memcmp(S[i + a] + b, T[i + b] + a, i + 1)) {
                    ok = 0;
                    break;
                }
            }
            ans += ok;
            ab[a][b] = ok;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1280
import math
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
csf = [IL() for i in range(N-1)]

ans = [0]*N

for j in range(N-1):
	for i in range(j,N-1):
		if ans[j] <= csf[i][1]:
			ans[j] = csf[i][1] + csf[i][0]
			continue
		else:
			tmp = ans[j]//csf[i][2]
			while csf[i][2]*tmp < ans[j]:
				tmp += 1
			ans[j] = csf[i][2]*tmp + csf[i][0]

for i in ans:
	print(i)

Measured memory_bytes: 12544
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  int xl=0,xr,yb=0,yt;
  cin>>xr>>yt;
  int n;
  cin>>n;
  rep(i,n){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1)xl=max(xl,x);
    if(a==2)xr=min(xr,x);
    if(a==3)yb=max(yb,y);
    if(a==4)yt=min(yt,y);
  }
  if(xr-xl<=0||yt-yb<=0)cout<<0<<endl;
  else cout<<(xr-xl)*(yt-yb)<<endl;
}


Measured memory_bytes: 3544
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;

int const MAX_N = 512 * 1024;

void my_gets(char * st) {
	int len = 0;
	char ch = getc(stdin);
	while (ch != '\n' && ch != '\r' && ch != 0 && !feof(stdin)) {
		st[len++] = ch;
		ch = getc(stdin);
	}
	st[len] = 0;
}

int const DX[4] = { -1, 1, 0, 0 };
int const DY[4] = { 0, 0, -1, 1 };

char st[1024];
int s[512][512];
int n, m;
int nnew[512][512];
int x[512 * 512], y[512 * 512];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	my_gets(st);
	sscanf(st, "%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		my_gets(st);
		for (int j = 0; j < m; j++) s[i][j] = st[j] == '#';
	}

	long long ans = 0;

	for (int i=0; i<n; i++)
		for (int j=0; j<m; j++)
			if (s[i][j] && !nnew[i][j]) {
				int p_read = 0, p_write = 1;
				x[p_read] = i;
				y[p_read] = j;
				nnew[i][j] = 1;
				long long white = 0;
				while (p_read < p_write) {
					int xx = x[p_read];
					int yy = y[p_read];
					p_read++;

					for (int k = 0; k < 4; k++) {
						int new_xx = xx + DX[k];
						int new_yy = yy + DY[k];
						if (new_xx >= 0 && new_xx < n && new_yy >= 0 && new_yy < m && s[new_xx][new_yy] != s[xx][yy] && !nnew[new_xx][new_yy]) {
							nnew[new_xx][new_yy] = 1;
							x[p_write] = new_xx;
							y[p_write] = new_yy;
							p_write++;
							if (s[new_xx][new_yy] != s[i][j]) white++;
						}
					}
				}
				long long black = p_write - white;
				ans += black * white;
			}

	cout << ans;
	return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define fo(i,s,n)    for(auto i=s;i<n;++i)
#define foo(i,s,n)    for(auto i=s;i>=n;--i)
#define ll long long
#define ull unsigned long long int
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            int t; cin>>t; while(t--)
const int MOD = 1000000007;
ll mod(ll x){
    return (x%MOD + MOD)%MOD;
}
ll mul(ll a , ll b){
    return mod(mod(a)*mod(b));
}
bool comp(pair<ll,ll>& a, pair<ll,ll>& b)
{
    if(a.second == b.second)
    return a.first > b.first;
    else
    return b.second < a.second;
}
static int rowNbr[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
static int colNbr[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int main()
{
    fast
    ll k ,i;
    cin>>k;
    ll total = 0;
    for(i=1;i<=1e6;i++)
    {
        total = ((total*10)+7)%k;
        if(total==0)
        {
            cout<<i<<endl;
            break;
        }
    }
    if(i>=1e6)
    {
        cout<<-1<<endl;
    }




    return 0;
}





Measured memory_bytes: 3644
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	REP(i,0,n-1) {
		int val;
		cin>>val;
		arr[i]=val-i-1;
	}
	sort(arr.begin(),arr.end());
	int req = arr[(n)/2];
	ll sum = 0;
	for(int i:arr) {
		sum+=abs(i-req);
	}
	cout<<sum;
}//sum-nsum=n*b;
//-2// 2 1 0 1 1 1 1
int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main(){
    int N;
    cin >> N;
    int D_a, D_b;
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> D_a >> D_b;
        
        if (D_a != D_b){
            count = 0;
            continue;
        }
        count += 1;
        if (count > 2){
            cout << "Yes" << '\n';
            return 0;
        }
        
    }
    cout << "No" << '\n';
    return 0;
}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define P				pair<string, int>
#define fi				first
#define se				second

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
	int n; cin >> n;
	
	int a, res = INF;
	REP( i, n ) {
		int cnt = 0;
		cin >> a;
		while( a % 2 == 0 ) {
			a /= 2;
			cnt++;
		}
		chmin( res, cnt );
	}

	cout << res << endl;
}

Measured memory_bytes: 256
l = [0,0,0,0]
s = gets.chomp
4.times { |i| l[i] = s[i].to_i }
finish = false
result = ""
["+","-"].each do |fst|
  ["+","-"].each do |snd|
    ["+","-"].each do |trd|
      ans = l[0].send(fst,l[1])
      ans = ans.send(snd,l[2])
      ans = ans.send(trd,l[3])
      if ans == 7
        result = "#{l[0]}#{fst}#{l[1]}#{snd}#{l[2]}#{trd}#{l[3]}=7"
        finish = true
      end
      break if finish
    end
    break if finish
  end
  break if finish
end
print result,"\n"


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

void trace(int A[], int N){
    for (int i = 0; i < N; i++){
        if(i>0){
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N){
    int j, i, v;
    for(i = 1; i < N; i++) {
        v = A[i]; // 2
        j = i - 1; // 0
        while (j >= 0 && A[j]> v){ // 0 >= 0 && 5 > 2 
            A[j + 1] = A[j]; //index 1 = 5
            j--; // -1
        }
        A[j + 1] = v; // index 0 = 2
        trace(A, N);
    }
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    trace(A, N);
    insertionSort(A, N);
    return 0;
}



Measured memory_bytes: 3156
k = int(input())

def gcd(a, b): # a<=b
    if b%a==0:
        return a
    else:
        c = b%a
        if a < c:
            return gcd(a, c)
        else:
            return gcd(c, a)

sum = 0
for i in range(1, k+1):
    sum += i
for i in range(1, k):
    for j in range(i+1, k+1):
        sum += gcd(i, j) * 6
for i in range(1, k-1):
    for j in range(i+1, k):
        for l in range(j+1, k+1):
            sum += gcd(gcd(i, j), l) * 6
print(sum)


Measured memory_bytes: 9212
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long K = stdIn.nextLong();
		long D = stdIn.nextLong();
		
		X = Math.abs(X);
		
		long step = Math.min(K, X / D);
		K -= step;
		X -= step * D;
		
		if(K % 2 == 0) {
			System.out.println(X);
		}else {
			System.out.println(D - X);
		}
		
		
	}
}

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == -1)
      break;

    if (n == 0) {
      cout << n << endl;
      continue;
    }

    vector<int> ans;
    while (n) {
      ans.push_back(n%4);
      n /= 4;
    }

    for (int i = ans.size()-1; i >= 0; --i)
      cout << ans[i];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		while(true){
			String[] line = br.readLine().split(" ");
			int m = Integer.parseInt(line[0]);
			int f = Integer.parseInt(line[1]);
			int r = Integer.parseInt(line[2]);
			if( m == -1 && f == -1 && r == -1) break;
			else if( m == -1 || f == -1 || m+f < 30 ) System.out.println("F");
			else if( m+f >= 80 ) System.out.println("A");
			else if( 65 <= m+f && m+f < 80 ) System.out.println("B");
			else if( 50 <= m+f && m+f < 65 || r >= 50 ) System.out.println("C");
			else if( 30 <= m+f && m+f < 50 ) System.out.println("D");
		}
	}
}

Measured memory_bytes: 24412
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
ll b[1000010];ll a[1000010];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;cin >> n;
    for (int i = 0; i < n; ++i)
    {
    	ll d;cin >> d;
    	a[d]++;
    }
    int ans=0;
    for(int i=1;i<=1000000;i++)
    {
    	if(a[i]==1 and b[i]==0)ans++;
    	if(a[i]==0)continue;
    	ll d=i;
    	while(d<=1000000)
    	{
    		b[d]=1;d+=i;
    	}
    }
    cout << ans;
    }

Measured memory_bytes: 19240
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int N;
int cnt;

s64 solve(int an, int a1)
{
    s64 ret = 0;
    if (an > N || a1 > N) return ret;
    if (an == a1 && an <= N) ++ret;
    if (an * 10 + a1 <= N)
    {
        ++ret;
    }
    else
    {
        return ret;
    }

    an *= 100;
    s64 cond = 9;
    s64 ak = 0;
    s64 temp = an + ak * 10 + a1;
    if (temp < 1) return ret;
    while (temp <= N)
    {
        ++cnt;
        ++ret;
        ++ak;
        if (ak > cond)
        {
            ak = 0;
            an *= 10;
            cond = cond * 10 + 9;
        }
        temp = an + ak * 10 + a1;
    }

    return ret;
}

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

    cin >> N;

    s64 ans = 0;
    s64 c[10][10];
    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            c[i][j] = solve(i, j);
        }
    }

    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            ans += c[i][j] * c[j][i];
        }
    }

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



Measured memory_bytes: 256
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = 0
end
local a = {}
for i = 1, n do
  a[i] = 1 + io.read("*n")
end
local ev = n % 2 == 0
local impossible = false
for i = 1, n do
  if(ev) then
    if(a[i] % 2 == 1) then
      impossible = true
      break
    end
  else
    if(a[i] % 2 == 0) then
      impossible = true
      break
    end
  end
  if(a[i] == 1) then
    if(t[1] == 1) then
      impossible = true
      break
    end
  elseif(t[a[i]] == 2) then
    impossible = true
    break
  end
  t[a[i]] = t[a[i]] + 1
end
if(impossible) then
  print(0)
else
  local c = 1
  for i = 2, n do
    if(0 < t[i]) then c = (c * 2) % 1000000007 end
  end
  print(c)
end


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

struct UnionFind {
  // If the vertex is a parent, this value will be the number of vertices that
  // belongs to the set, multiplied by -1 Otherwise, this value will be the
  // parent's id
  vector<int> r;

  UnionFind(int N) { r = vector<int>(N, -1); }

  int root(int x) {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) { return -r[root(x)]; }
};

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

  // Make friends-sets
  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A -= 1;
    B -= 1;
    UF.unite(A, B);
  }

  // Find the maximum friends-set
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, UF.size(i));
  }

  cout << ans << endl;
}

Measured memory_bytes: 4052
#include <iostream>

using namespace std;

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

  // A: 0101...
  // B: 1010...
  int A = 0;
  int B = 0;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      if (S[i] != '0')
        A++;
      else
        B++;
    } else {
      if (S[i] != '1')
        A++;
      else
        B++;
    }
  }

  cout << (A < B ? A : B) << endl;

  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

// https://atcoder.jp/contests/abc175/submissions/15981498
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n), c(n);
    cin >> p >> c;
    rep(i, n) --p[i];
    
    ll ans = -INF;
    rep(i, n) { // 始点を全部試す
        int now = i;
        vector<int> v;
        ll sum = 0;
        while (1) {
            v.eb(c[now]);
            sum += c[now];
            
            now = p[now];
            if (now == i) break;
        }
        
        ll acc = 0;
        rep(j, sz(v)) {
            if (j + 1 > k) break; // k個まで, debuged
            acc += v[j];
            chmax(ans, acc + max(0LL, max(0, (k - (j + 1))) / sz(v) * sum));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

vector<int64_t> a(55),p(55);

int64_t F(int64_t n, int64_t x){
    if(n == 0){
        if(x <= 0)return 0LL;
        else return 1;
    }
    else if(x <= 1 + a[n-1]){
        return F(n-1, x-1);
    }
    else{
        return p[n-1] + 1 + F(n-1, x - 2 - a[n-1]);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int64_t n, x; cin >> n >> x;
    a[0] = p[0] = 1;
    for(int i=1; i<=n; ++i){
        a[i] = 2*a[i-1]+3;
        p[i] = 2*p[i-1]+1;
    }
    cout<< F(n,x) <<endl;
}

Measured memory_bytes: 256
def solve(N,Y):
    for x in range(N+1):
        for y in range(N-x+1):
            z = N-(x+y)
            if(10*x + 5*y + z == Y):
                print("{} {} {}".format(x,y,z))
                return 0

    print("-1 -1 -1")
    
N,Y = map(int, input().split())
Y //= 1000

solve(N,Y)

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

string s, t, u;
long long a, b;

int main() {
  cin >> s >> t >> a >> b >> u;
  if(s == u)
    --a;
  else if(t == u)
    --b;

  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
     
    using namespace std;
    typedef long long ll;
    #define rep(i, n) REP(i, 0, (n))
    #define REP(i, a, n) for(typeof(n) i=(a); i<(n); i++)
     
    int N;
    int a[100010];
     
    int main() {
    	cin >> N;
    	int mini = 0, maxi = 0;
    	ll total = 0;
    	REP(i, 1, N+1) {
    	    cin >> a[i];
    	    total += abs(a[i-1]-a[i]);
    	}
        total += abs(a[N]);
        REP(i, 1, N+1) {
            cout << total - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i-1]-a[i+1])) << endl;
        }
    }

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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 1010
#define MAX_V MAX_N

class FordFullkerson {
    public:
        // 辺を表す構造体(行先、容量、m_G[i]における逆辺のインデックス)
        struct Edge {int to, cap, rev; };

        // from から to へ向かう容量 cap の辺をグラフに追加する
        void add_edge(int from, int to, int cap) {
            m_G[from].push_back((Edge){to, cap, static_cast<int>(m_G[to].size())});
            m_G[to].push_back((Edge){from, 0, static_cast<int>(m_G[from].size() - 1)});
        }

        // 増加パスを DFS で探す
        int dfs(int v, int t, int f) {
            if (v == t) { return f; }
            m_Used[v] = true;
            for(int i = 0; i < m_G[v].size(); ++i) {
                Edge &e = m_G[v][i];  // v から延びるエッジ i
                if(!m_Used[e.to] && e.cap > 0) {
                    int d = dfs(e.to, t, min(f, e.cap));
                    if(d > 0) {
                        e.cap -= d;
                        m_G[e.to][e.rev].cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }

        // s から t への最大流を求める
        int max_flow(int s, int t) {
            int flow = 0;
            for(;;) {
                memset(m_Used, 0, sizeof(m_Used));
                int f = dfs(s, t, INF);
                if(f == 0) { return flow; }
                flow += f;
            }
            return flow;
        }
    public:
        vector<Edge> m_G[MAX_V];  // グラフの隣接リスト表現 (index: ノード番号)
        bool m_Used[MAX_V];       // DFS で既に調べたかのグラフ
};

int N;
vector< pair<int, int> > red, black;

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

    cin >> N;
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        red.push_back({x, y});
    }
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        black.push_back({x, y});
    }

    FordFullkerson ff;
    int s_id = N * 2 + 1;
    int t_id = N * 2 + 2;

    REP(i, N) {
        // s -> 赤
        ff.add_edge(s_id, i, 1);
        // 黒 -> t
        ff.add_edge(i + N, t_id, 1);
        REP(j, N) {
            // 赤 -> 黒
            if(red[i].first < black[j].first && red[i].second < black[j].second) {
                ff.add_edge(i, j + N, 1);
            }
        }
    }

    int ans = ff.max_flow(s_id, t_id);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void seek(int x, int y, int[][] map){
		if(map[y][x] == 1){
			map[y][x] = 0;
			seek(x+1, y+1, map);
			seek(x  , y+1, map);
			seek(x-1, y+1, map);
			seek(x+1, y  , map);
			seek(x-1, y  , map);
			seek(x+1, y-1, map);
			seek(x  , y-1, map);
			seek(x-1, y-1, map);
		}
	}

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {

			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(w == 0 && h == 0){
				break;
			}
			
			int[][] map = new int[h+2][w+2];

			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					map[i][j] = 0;
				}
			}
			
			for(int i = 1; i < h+1; i++){
				for(int j = 1; j < w+1; j++){
					map[i][j] = sc.nextInt();
				}
			}
			
			int count = 0;
			for(int i = 1; i < h+1; i++){
				for(int j = 1; j < w+1; j++){
					if(map[i][j] == 1){
						seek(j,i,map);
						count++;
					}
				}
			}
			
			System.out.println(count);
			
		}
	}

}

Measured memory_bytes: 13000
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := iScan()
	d := make(map[int]struct{})
	d[s] = struct{}{}
	for i := 2; ; i++ {
		if s%2 == 0 {
			s /= 2
		} else {
			s = 3*s + 1
		}
		if _, ok := d[s]; ok {
			fmt.Println(i)
			break
		} else {
			d[s] = struct{}{}
		}
	}
}


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

using namespace std;

int main (void){
      int a;
      int b;
      int c;

      int d;

      cin >> a;
      cin >> b;
      cin >> c;

      if (a < b){
            d = a;
            a = b;
            b = d;
      }

      if (b < c){
            d = b;
            b = c;
            c = d;
      }

      if (a < b){
            d = a;
            a = b;
            b = d;
      }

      a = a * 10 + b;
      cout << a + c << "\n";
      return 0;
}


Measured memory_bytes: 256