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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

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

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int R, G, B; cin >> R >> G >> B;
	int K; cin >> K;
	
	int ans = 0;
	while (G <= R) {
		++ans;
		G *= 2;
	}
	while (B <= G) {
		++ans;
		B *= 2;
	}
	print((ans <= K) ? "Yes" : "No");
}

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

int main() {
	//input
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	//calculation
	int countA = (C + B - 1)/ B;
	int countB = (A + D - 1) / D;

	//output
	if (countA <= countB) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}


	return 0;
}


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

using namespace std;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

void sub()
{
    const auto S(cin2var<string>());
    string r;
    if (S == "Sunny") {
        r = "Cloudy";
    }
    else if (S == "Cloudy") {
        r = "Rainy";
    }
    else if (S == "Rainy") {
        r = "Sunny";
    }
    cout << r << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    sub();
    return 0;
}

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

int main(void){

	string c1,c2;
	cin>>c1>>c2;
	if(c1[0]==c2[2]&&c1[2]==c2[0]&&c1[1]==c2[1])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[22][(1<<22)];
ll mod=1e9+7;
ll solve(vector<vector<ll>> &v,int i,int womenset,int n){
    if(i==n+1){
        if(womenset==0){
            return 1;
        }
        return 0;
    }
    if(dp[i][womenset]!=-1){
        return dp[i][womenset];
    }
    ll ans=0;
    for(ll women=0;women<n;women++){
       bool avail=(((womenset) & (1<<women))==0) ? 0:1;
       if(avail && v[i][women+1]){
           ans=(ans+solve(v,i+1,(womenset^(1<<women)),n));
           ans=ans%mod;
       }
    }
    return dp[i][womenset]=ans;
}
int main(){
    ll n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    vector<vector<ll> >v(n+1,vector<ll> (n+1));
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            cin>>v[i][j];
        }
    }

    cout<<solve(v,1,((1<<n)-1),n);

    return 0;
}


Measured memory_bytes: 724476
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node Node;
struct node{
    Node* prev;
    Node* next;
    int val;
};

Node *head = NULL;
Node *tail = NULL;

void insert(int val){
    Node* p_head = head;
    //??°???node?????????
    Node* node = malloc(sizeof(Node));
    node->val = val;
    node->next = p_head;
    node->prev = NULL;
    //??????????????\
    head = node;
    if(p_head != NULL){
        p_head->prev = node;
    }
    //?????????????´??????´??????tail????¨??????????
    if(tail==NULL){
        tail = node;
    }
}

void delete(int val){
    Node* c_node = head;
    //????´???°???0??§????????°???????????????
    if(head == NULL) return;
    //???????????????????????¢?????????
    while(c_node != NULL && c_node->val != val){
        c_node = c_node->next;
    }
    if(c_node == NULL) return;
    
    //????´???°???1?????´???
    if(head->next == NULL){
        head = NULL;
        tail = NULL;
    }
    //????´????1????????§?????????????????????????±????head?????´???
    else if(c_node == head)
    {
        head = c_node->next;
        head->prev = NULL;
    }
    //????´????1????????§?????????????????????????±????tail?????´???
    else if(c_node == tail)
    {
        tail = c_node->prev;
        tail->next = NULL;
    }
    else
    {
        c_node->prev->next = c_node->next;
        c_node->next->prev = c_node->prev;
    }
    free(c_node);
}

void deleteFirst(void){
    Node* p_head = head;
    //????´???°???0??§????????°???????????????
    if(head == NULL) return;
    
    //????´???°???2??\????????´???
    if(head->next != NULL)
    {
        head = head->next;
        head->prev = NULL;
    }
    else
    //????´???°???1?????´???
    {
        head = NULL;
        tail = NULL;
    }
    free(p_head);
}

void deleteLast(void){
    Node* p_tail = tail;
    //????´???°???0??§????????°???????????????
    if(tail == NULL) return;
    
    //????´???°???2??\????????´???
    if(tail->prev != NULL)
    {
        tail = tail->prev;
        tail->next = NULL;
    }
    //????´???°???1?????´???
    else
    {
        head = NULL;
        tail = NULL;
    }
    free(p_tail);
}

void printAll(void){
    Node* node = head;
    if(node == NULL) return;
    while(node != NULL){
        printf("%d", node->val);
        node = node->next;
        if(node != NULL) printf(" ");
    }
    printf("\n");
}

int main(void){
    int i;
    int num;
    char operator[20];
    int operand;
    
    scanf("%d", &num);
    
    for(i=0;i<num;i++){
        scanf("%s", operator);
        if(strcmp(operator, "insert") == 0){
            scanf("%d", &operand);
            insert(operand);
        }
        else if(strcmp(operator, "delete") == 0){
            scanf("%d", &operand);
            delete(operand);
        }
        else if(strcmp(operator, "deleteFirst") == 0){
            deleteFirst();
        }
        else if(strcmp(operator, "deleteLast") == 0){
            deleteLast();
        }
    }
    printAll();
    return 0;
}

Measured memory_bytes: 31788
s=input()
p=input()
b=s
s+=s
ans=0
same_count=0
for i in range(len(b)):
    for j in range(len(p)):
        if s[i+j]==p[j]:
            same_count+=1

    if same_count==len(p):
        ans=1
    same_count=0

if ans==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Globalization;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(l);
            Array.Reverse(l);
            int ans = 0;
            for(int i = 0; i < a[1]; i++)
            {
                ans += l[i];
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main() {
	int m, n;
	while (cin >> m >> n, m, n) {
		int t[100];
		int h[100];
		for (int i = 0;i < m;i++)cin >> t[i];
		for (int i = 0;i < n;i++)cin >> h[i];

		int st = 0, sh = 0;
		for (int i = 0;i < m;i++)st += t[i];
		for (int i = 0;i < n;i++)sh += h[i];

		int a = 1e8, b = 1e8;
		int flg = 1;

		for (int i = 0;i < m;i++) {
			for (int j = 0;j < n;j++) {
				if (st - t[i] + h[j] == sh - h[j] + t[i]) {
					if (t[i] + h[j] < a + b) {
						a = t[i];
						b = h[j];
						flg = 0;
					}
				}
			}
		}
		if (flg == 1)cout << -1 << endl;
		else cout << a << ' ' << b << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 97797
 */
public class Main {
    public static void main(String[] args) {
        System.out.println(new Main().run(args, System.in));
    }
    public String run(String[] args, InputStream in) {
        String result = null;
        try {
            
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String[] val = reader.readLine().replaceAll("\\s+", " ").split(" ");
            
            int R = Integer.parseInt(val[0]);
            int G = Integer.parseInt(val[1]);
            int B = Integer.parseInt(val[2]);
            
            if (((R*100 + G *10 + B) % 4) == 0) {
                result = "YES";
            } else {
                result = "NO";
            }                       
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
}


Measured memory_bytes: 21204
# include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

long long *value, *weight, dp[100005][102]={};

int main()
{
	fast;
    long long n,w, ans;
    cin>>n>>w;
    value = new long long[n+1];
    weight = new long long[n+1];
    weight[0]=value[0]=0;
    for(int i=0; i<n; i++){
        cin>>weight[i+1]>>value[i+1];
    }
    for(int i=1; i<=n; i++){
    	for(int j=1; j<=w; j++){
    		if(j-weight[i]>=0)
    		dp[j][i]=max(dp[j][i-1], dp[j-weight[i]][i-1]+value[i]);
    		else dp[j][i] =dp[j][i-1];
		}
	}
//    for(int i=1; i<=w; i++){
//    	for(int j=1; j<=n; j++){
//    		cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
    cout<<dp[w][n];
    return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n;
char s[5252];
int table[5252];

int main(){
	scanf("%d",&n);
	scanf("%s",s);

	int ans = 0;
	FOR(l,1,n){
		string pat(s+l);
		table[0] = -1;
		int j = -1;
for (int i = 0; i < pat.size(); i++) {
  while (j >= 0 && pat[i] != pat[j]) j = table[j];
  j++;
  table[i+1] = j;
}
		int i=0, p=0;
		while(i<l && p<pat.size()){
			if(s[i] == pat[p]){
				i++; p++;
				CHMAX(ans, p);
			}else if(p==0){
				i++;
			}else{
				p = table[p];
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
import sys
import math

input = sys.stdin.readline

N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

arr1 = make_divisors(N)
arr2 = make_divisors(N-1)
arr1.pop()
arr2.pop()

ans = len(arr2)

for value in arr1:
    temp = N
    while temp % value == 0:
        temp = temp // value
        if temp == 0:
            break
    if temp % value == 1:
        ans += 1

print(ans)


Measured memory_bytes: 3316
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> ps(N);
    rep(i,0,N) {
        cin >> ps[i];
    }
    vector<ll> sum(N+1);
    rep(n,1,N+1) {
        sum[n] = ps[n-1] + sum[n-1];
    }
    ll max_sum = numeric_limits<ll>::min();
    rep(i,0,N-K+1) {
        max_sum = max(max_sum, sum[i+K] - sum[i]);
    }
    double ans = ((double)max_sum + (double)K) / 2.0;
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    if(S.length() != A + B + 1 || S[A] != '-'){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i<S.length(); i++){
        if(i != A && S[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N];
long long dif[N];
int a , b;
vector < int > v[N];
long long dfs(int node , int parent){
    dif[node] = arr[node];
    vector < long long > s;
    s.clear();
    long long sum = 0;
    for(int next : v[node]){
        if(next != parent){
            s.push_back(dfs(next , node));
            sum += s.back();
            dif[node] -= arr[next];
        }
    }
    if(v[node].size() == 1){
        return dif[node];
    }
    if(dif[node] > 0){
        printf("NO\n");
        exit(0);
    }
    long long val = -dif[node];
    long long mx = 0;
    long long get;
    for(auto it : s){
        mx = max(mx , it);
    }
    if(mx <= sum - mx){
        get = sum >> 1;
    }
    else{
        get = sum - mx;
    }
    if(val > get){
        printf("NO\n");
        exit(0);
    }
    dif[parent] += val;
    return sum - val * 2;
}
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , arr + i);
    }
    if(n == 2){
        if(arr[1] != arr[2]){
            cout << "NO\n";
            return 0;
        }
        cout << "YES\n";
        return 0;
    }
    arr[0] = 0;
    for(int i = 1 ; i < n ; ++i){
        scanf("%d %d" , &a , &b);
        v[a].emplace_back(b);
        v[b].emplace_back(a);
    }
    for(int i = 1 ; i <= n ; ++i){
        if(v[i].size() > 1){
            long long val = dfs(i , 0);
            if(val != 0){
                cout << "NO\n";
            }
            else{
                cout << "YES\n";
            }
            return 0;
        }
    }
}

Measured memory_bytes: 17536
#include <iostream>
#include <vector>
using namespace std;
#define MAX 1299710
int main (){
	bool pr[MAX];
	int a;
	vector <int> prl;
	for(int i=0;i<MAX;i++) pr[i]=true;
	pr[0]=false;
	pr[1]=false;
	
	for(int i=0;i*i<MAX;i++){
		if(pr[i]){
			for(int j=i*i;j<=MAX;j=j+i){
				pr[j]=false;
			}
		}
	}
	for(int i=0,j=0;i<100000;j++){
	    if(pr[j]==true){
	        prl.push_back(j);
	        i++;
	    }
	}
	while(cin>>a){
		if(a==0)break;
		if(pr[a]){
		    cout << 0 <<endl;
		}
		else{
		    auto ansitr=lower_bound(prl.begin(),prl.end(),a);
		    cout<< *ansitr - *(ansitr-1) <<endl;
		}
	}
}

Measured memory_bytes: 4624
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

// int MOD = 998244353;
int MOD = 1000000007;

signed main(){
    
    ll m,d;
    cin >> m >> d;
    int ans = 0;
    for(int i = 1; i<= m;i++){
        for(int j = 1;j <= d;j++){
            if(i == (j/10)*(j%10) && (j%10) >=2 && j/10 >= 2)ans++;
        }
    }
    cout << ans << endl;
    
    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://jsc2019-qual.contest.atcoder.jp/tasks/jsc2019_qual_a
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc125.contest.atcoder.jp/tasks/abc125_a


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
typedef pair<int,int> P;
const int INF = 1<<29;

int eight[] = {0,1,2,3,5,7,8,9};

int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(!n)break;

        vector<int> ans;
        while(n){
            int a = n&7;
            ans.push_back(eight[a]);
            n >>= 3;
        }
        for(int i=ans.size()-1;i>=0;i--){
            printf("%d",ans[i]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ll n,t;
  cin>>n>>t;
  vector<pair<ll,ll>> vp;
  vector<ll> zeroa;
  for(auto&& i:irange(0l,n)) {
    ll a,b;
    cin>>a>>b;
    if (a == 0) zeroa.push_back(b + 1);
    else vp.emplace_back(a+1,a+b+1);
  }
  boost::sort(vp, [](auto&& lhs, auto&& rhs) {
      return lhs.second * rhs.first + rhs.second < rhs.second * lhs.first + lhs.second;
      });
  ll INF = 1e11;
  vecll dp(31, INF);
  dp[0] = 0;
  for (auto&& p : vp) {
    ll a,b;
    tie(a, b) = p;
    vecll tmp = dp;
    for(auto&& i:irange(0,30)) {
      tmp[i+1] = min(tmp[i+1], a * dp[i] + b);
    }
    swap(dp, tmp);
  }
  ll ans = 0;
  boost::sort(zeroa);
  ll m = zeroa.size();
  for (auto&& i:irange(0l,31l)) {
    ll sum = dp[i];
    if (sum > t) break;
    ans = max(ans, i);
    for (auto&& j:irange(0l,m)) {
      sum += zeroa[j];
      if (sum > t) break;
      ans = max(ans, i + j + 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6512
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: String,
    }

    const RADIX: u32 = 10;

    let sum = n.chars().map(|c| c.to_digit(RADIX).unwrap()).sum::<u32>();

    if sum % 9 == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2352
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	bool vis[100010];
	int tot=0;
	int h[100010],a,b;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int j=1;j<=m;j++)
	{
		cin>>a>>b;
		if(h[a]<h[b]) vis[a]=true;
		else if(h[a]==h[b]) vis[a]=vis[b]=true;
		else vis[b]=true;
	}	
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==false)
		{
			tot++;
		}
	}
	cout<<tot;
	return 0;
}

Measured memory_bytes: 4124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  if (s.size() == 2)
    cout << s << endl;
  else
  {
    reverse(s.begin(), s.end());
    cout << s << endl;
  }

  return 0;
}


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

int main(){
string b;
  cin>>b;
 if(b=="A"){
 cout<<"T"<<endl;
 } 
  if(b=="T"){
  cout<<"A"<<endl;
  }
  if(b=="C"){
  cout<<"G"<<endl;
  }
  if(b=="G"){
  cout<<"C"<<endl;
  }
}


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

int main()
{
vector<vector<int>> board;
vector<vector<bool>> check;
vector<int> count;
int H,ans=0;bool c=true;scanf("%d",&H);
while(H!=0)
{
ans=0;c=true;
board.resize(0);check.resize(0);board.resize(H);check.resize(H);
for(int i=0;i<H;i++){board[i].resize(5);check[i].resize(5,false);}
for(int i=0;i<H;i++)for(int j=0;j<5;j++)scanf("%d ",&board[i][j]);
while(c)
{
c=false;
for(int i=0;i<H;i++)
{
count.resize(0);count.resize(5,1);
for(int j=0;j<5;j++){if(check[i][j]){count[j]=0;continue;}if(j==0)continue;if(board[i][j-1]==board[i][j])count[j]+=count[j-1];}
for(int j=4;j>-1;j--)if(count[j]>2&&!check[i][j]){ans+=count[j]*board[i][j];for(int k=j;k>j-count[j];k--)check[i][k]=true;c=true;break;}
}
for(int j=0;j<5;j++)
{
  int stack=H-1;
  for(int i=H-1;i>-1;i--)if(!check[i][j]){board[stack][j]=board[i][j];check[i][j]=true;check[stack][j]=false;stack--;}
}
}
printf("%d\n",ans);
scanf("%d",&H);
}
}


Measured memory_bytes: 3160
n = int(input())
arr = list(map(int,input().split()))
cache = 1000
numStock = 0
for i in range(1,n):
    if arr[i]>arr[i-1]:
        available = cache//arr[i-1]
        cache -= arr[i-1]*available
        numStock += available
    else:
        cache += arr[i-1]*numStock
        numStock = 0

if numStock>0:
    cache += arr[-1]*numStock

print(cache)


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

int main()
{
	long long int n, t, a;
	cin >> n >> t >> a;
	
	t*=1000;
	vector<long long int> h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
	
	}
	long long int ans = 100000000000;
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		long long int x = abs((t - h.at(i) * 6)-a*1000);
		
		
		if (ans>=x)
		{
			c = i + 1;
			ans = x;
		}
	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int stack[10];
int cur = 0;

void push(int x){
	stack[cur] = x;
	cur++;
}

int pop(){
	cur--;
	return stack[cur];
}

int main(){
	int n;
	
	scanf("%d", &n);
	push(n);
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			printf("%d\n", pop());
		}else {
			push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 1028
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c,k = LI()
if a + b >= k:
    print(min(a,k))
else:
    print(a - (k - a - b))

Measured memory_bytes: 65504
#include<iostream>
#include<stdio.h>
#include<cmath>

using namespace std;

#define PI 3.141592654

struct point{
	double x;
	double y;
};

struct input{
	double length;
	double theta;
};

double get_radian( double theta_deg );
ostream& operator << ( ostream& s , point& p );

int main(void)
{
	input data;
	point goal = { 0.0 , 0.0 };
	double theta = 90;

	while(1)
	{
		scanf("%lf , %lf" , &data.length , &data.theta );
		if( data.length == 0 && data.theta == 0 ) break;

		goal.x += data.length * cos( get_radian(theta) );
		goal.y += data.length * sin( get_radian(theta) );

		theta -= data.theta;
	}
	cout << goal;
}

double get_radian( double theta_deg )
{
	return theta_deg*PI/180;
}

ostream& operator << ( ostream& s , point& p )
{
	return s << int(p.x) << endl << int(p.y) << endl;
}

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



int main() {
  string S,T;
  cin >> S;
  reverse(S.begin(),S.end());
  int i=0;
  while(i<S.size()){
    if(S[i]=='m' && S[i+1]=='a' && S[i+2]=='e'){
      T+="maerd";
      i+=5;
    }
    else if(S[i]=='r' && S[i+1]=='e' && S[i+2]=='m'){
      T+="remaerd";
      i+=7;
    }
    else if(S[i]=='e' && S[i+1]=='s' && S[i+2]=='a'){
      T+="esare";
      i+=5;
    }
    else if(S[i]=='r' && S[i+1]=='e' && S[i+2]=='s'){
      T+="resare";
      i+=6;
    }
    else
      break;
  }
  if(T==S)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#define N 1003
using namespace std;
struct edge{
	int to, nxt;
}e[N * N * 3];
int n, cnt;
int ins[N * N], mp[N][N], fir[N * N], t[N * N];
queue < int > Q;
int id(int ,int);
void add(int ,int);
int main(){
	scanf("%d", &n); int ans = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j < n; ++j)
			scanf("%d", mp[i] + j);
	for(int i = 1; i <= n; ++i)
		for(int j = 2; j < n; ++j)
			add(id(i, mp[i][j - 1]), id(i, mp[i][j]));
	for(int i = 1; i <= n * n; ++i){
		if(!ins[i]) Q.push(i);
		t[i] = 1;
	}
	while(!Q.empty()){
		int u = Q.front(); Q.pop(); ans = max(ans, t[u]);
		for(int i = fir[u]; i; i = e[i].nxt){
			int v = e[i].to;
			--ins[v];
			if(!ins[v])
				Q.push(v), t[v] = t[u] + 1;
		}
	}
	for(int i = 1; i <= n * n; ++i) 
		if(ins[i]) ans = -1;
	cout << ans << endl;
	return 0;
}
int id(int x,int y){
	if(x > y) swap(x, y);
	return (x - 1) * n + y;
}
void add(int u,int v){
	e[++cnt] = (edge){v, fir[u]}; fir[u] = cnt; ++ins[v];
	return ;
}

Measured memory_bytes: 28756
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

anum = [1 for i in range(n)]
bnum = [0 for i in range(n)]
cnum = [0 for i in range(n)]
i = 0
j = 0
count = 0
while j < n:
    while i < n :
        if a[i] >= b[j]:
            break
        count += anum[i]
        i += 1
    bnum[j] = count
    j += 1
i = 0
j = 0
count = 0
while j < n:
    while i < n  :
        if b[i] >= c[j]:
            break
        count += bnum[i]
        i += 1
    cnum[j] = count
    j += 1
print(sum(cnum))

Measured memory_bytes: 25204
/*input
1000 1 1000
*/
 
 
#include <bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define INTMAX  2147483647
#define INTMIN  -2147483648
#define LLMAX 9223372036854775807
#define LLMIN -9223372036854775808
#define MOD 1000000007
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.1415926535
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr

// cout<<fixed<<setprecision(10)<<(v1+v2+v3)<<endl;
  
struct node{
    ll val;
};


long long int minimum = 100000000000000;

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

struct ct_s_h {long long int cts, cth, index;};

bool compare(long long int a, long long int b) {
	if(gcd(a,b) < minimum)
		return 1;
	else return 0;
}






int main(){
	long long int n,x,t; cin>>n>>x>>t;
	cout<<(long long int)ceil(1.0*n/x)*t<<endl;
	return 0;	
}















 

Measured memory_bytes: 3740
n = gets.to_i
tt = 0
tx = 0
ty = 0
ans = ''
n.times do |i|
  t, x, y = gets.split.map(&:to_i)
  move = (x - tx).abs + (y - ty).abs
  if move <= t - tt && move % 2 == (tt - t) % 2
    ans = 'Yes'
  else
    ans = 'No'
    break
  end
end
puts ans


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

const int MAX_N=100;
const ll INF=1e16;
int N;
struct edge{
	int to;
	ll cap;
	int rev;
	edge(int t=-1,ll c=0,int r=-1):to(t),cap(c),rev(r){}
};

vector<edge> G[MAX_N+2];

void add_edge(int s,int t,ll c){
	G[s].push_back(edge(t,c,G[t].size()));
	G[t].push_back(edge(s,0,(int)G[s].size()-1));
}
int ite[MAX_N+2],lev[MAX_N+2],prevv[MAX_N+2],pree[MAX_N+2];
void bfs(){
	memset(lev,-1,sizeof(lev));
	lev[0]=0;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(auto e:G[v]){
			if (lev[e.to]==-1 && e.cap>0){
				lev[e.to]=lev[v]+1;
				que.push(e.to);
			}
		}
	}
}
ll dfs(int v){
	if (v==1){
		return INF;
	}
	for(int &i=ite[v];i<(int)G[v].size();i++){
		edge e=G[v][i];
		if (lev[v]+1==lev[e.to] && e.cap>0){
			ll f=dfs(e.to);
			if (f!=0){
				prevv[e.to]=v;
				pree[e.to]=i;
				return min(f,e.cap);
			}
		}
	}
	return 0;
}
ll mxflow(){
	ll fl=0;
	for(;;){
		bfs();
		if (lev[1]==-1){
			break;
		}
		memset(ite,0,sizeof(ite));
		for(;;){
			ll f=dfs(0);
			if (f==0){
				break;
			}else{
				fl+=f;
				for(int v=1;v!=0;v=prevv[v]){
					G[prevv[v]][pree[v]].cap-=f;
					G[v][G[prevv[v]][pree[v]].rev].cap+=f;
				}
			}
		}
	}
	return fl;
}

int main(){
	cin>>N;
	ll sm=0;
	REP(i,N){
		ll a;
		cin>>a;
		if (a>0){
			sm+=a;
			add_edge(i+2,1,a);
		}else{
			add_edge(0,i+2,-a);
		}
	}
	FOR(i,1,N+1){
		FOR(j,i+1,N+1){
			if (j%i==0){
				add_edge(i+1,j+1,INF);
			}
		}
	}
	cout<<sm-mxflow()<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#define N 300001

using namespace std;

main(){
  bool data[N];

  for(int i=0;i<N;i++){
    if(i%7==1 || i%7==6) data[i]=true;
    else data[i]=false;
  }

  data[1]=false;
  for(int i=0;i<N;i++){
    if(data[i]){
      for(int j=i+i;j<N;j+=i){
	data[j]=false;
      }
    }
  }
  int pri[35814];
  for(int i=0, j=0;i<N;i++){
    if(data[i]){
      pri[j++]=i;
    }
  }
  pri[35813]=-1;
  bool ans[35813];
  int in;
  while(1){
    cin >> in;
    if(in==1) break;

    for(int i=0;i<35813;i++){
      ans[i]=false;
    }

    for(int i=0;i<35813;i++){
      if(in%pri[i]==0){
	ans[i]=true;
      }
    }

    printf("%d:", in);
    for(int i=0;i<35813;i++){
      if(ans[i]) cout << ' ' << pri[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1372
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5 + 4;
int n,k;
ll a[MAXN];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(int i=k+1,p=1;i<=n;i++,p++) {
        if(a[i] > a[p]) {
            puts("Yes");
        } else {
            puts("No");
        }
    }
    return 0;
}


Measured memory_bytes: 5328
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	String a = scan.next();
	String b = scan.next();

	if(a.length() > b.length()){
	    System.out.println("GREATER");
	}else if(b.length() > a.length()){
	    System.out.println("LESS");
	}else{
	    int flag = -1;
	    for(int i = 0; i < a.length(); i++){
		if(a.charAt(i) > b.charAt(i)){
		    System.out.println("GREATER");
		    flag = 1;
		    break;
		}else if(b.charAt(i) > a.charAt(i)){
		    System.out.println("LESS");
		    flag = 1;
		    break;
		}
	    }
	    if(flag == -1){
		System.out.println("EQUAL");
	    }
	}
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int n,m;cin>>n>>m;
  vi s(m);
  vector<char> c(m);
  rep(i,m) cin>>s[i]>>c[i];
  int keta =9;
  while(n-1){
    keta =keta*10+9;
    n--;
  }
  
  bool ok=true;
  for(int i=(((keta+1)/10)/10)*10;i<=keta;i++){
    string suu =to_string(i);
    
    ok=true;
    for(int j=0;j<m;j++){
      if(suu[s[j]-1]!=c[j] ){
      
        ok=false;
      }
    }
    if(ok){
      cout<<i<<endl;
      break;
    }
  }
  if(!ok) cout<< -1<<endl;
  
}
  

Measured memory_bytes: 768
n = int(input())
s = len(str(n))
if s == 1:
    print(n)
else:
    #print(s)
    a0 = n % 10
    a = [a0]
    for i in range(2,s+1):
        b = n % (10**i)
        #print(b)
        d = 0
        for k in range(2,i+1):
            d = d + (2**(i-k))*(b//(10**(i+1-k))) + a[i-k]
            #print(d)
        a.append(d+b)
        #print(a)
    print(a[s-1])

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

int main()
{
    int n, a[100005];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    int db = 0, sh = 1;
    for(int i = 1; i < n; i++){
        if(a[i] == a[i - 1]) db++;
        else sh++;
    }
    cout << sh - db % 2 << endl;
}

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

int main(){

    int n,cu; 

    int rea[50],ano[50];

    while(1){

        cin>>n>>cu;

        if(n==0 && cu == 0) break;    

        for(int i=0; i<n; i++) rea[i] = n-i;

        for(int i=0; i<cu; i++){

            int p,num; cin>>p>>num;

            for(int j=0; j<n; j++) ano[j] = rea[j];

            for(int j=0; j<p-1; j++) ano[ j + num] = rea[j];

            for(int j=0; j<num; j++) ano[j] = rea[j+p-1];

            for(int j=0; j<n; j++) rea[j] = ano[j];
        }

    cout<<rea[0]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3080
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100005
int n,a[MAXN],sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	if(sum%2) printf("NO\n");
	else printf("YES\n");
	return 0;
}


Measured memory_bytes: 512
let levenshtein_distance s t =
  let m = String.length s in
  let n = String.length t in
  let d = Array.make_matrix (m + 1) (n + 1) 0 in
  let rec dudu i =
    if i <= m then begin
      d.(i).(0) <- i;
      dudu (i + 1)
    end in
  let rec wa i =
    if i <= n then begin
      d.(0).(i) <- i;
      wa (i + 1)
    end in
  let rec doit = function
    | (i, _) when i > m -> d.(m).(n)
    | (i, j) when j > n -> doit (i + 1, 1)
    | (i, j) ->
      let c = if s.[i-1] = t.[j-1] then 0 else 1 in
      let t = if d.(i-1).(j) + 1 < d.(i).(j-1) + 1 then d.(i-1).(j) + 1 else d.(i).(j-1) + 1 in
      d.(i).(j) <- if d.(i-1).(j-1) + c < t then d.(i-1).(j-1) + c else t;
      doit (i, j + 1) in
  dudu 1; wa 1; doit (1, 1)

let () =
  let s1 = read_line () in
  let s2 = read_line () in
  Printf.printf "%d\n" (levenshtein_distance s1 s2)

Measured memory_bytes: 10316
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll tt(double x){
	ll d=(ll)x;
	if(x-d==0)
		return d;
	else
		return d+1;
}
int main(){
	ll x,y;
	cin>>x>>y;
	ll i;
	ll f=0;
	for(i=1;i<=2000;i++){
		ll p,q;
		p=floor(i*0.08);
		q=floor(i*0.1);
		if(p==x&&q==y){
			f=1;
			break;
		}
	}
	if(f)
		cout<<i;
	else
		cout<<"-1";
	
}


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

typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

// 残りがkこの場合、dp(k)が書き込まれていれば、それを返す
// k == 0の場合、負け
// k > 0 の場合、dp(k-ai)のどれかがfalseならaiを選んでtrueにセット
//              dp(k-ai)の全てがtrueなら変更しない

int N, K;
vector<int> ai;
vector<int> dp;

int main() {
  cin >> N >> K;
  ai = vector<int>(N);
  for (int i=0;i<N;i++) cin >> ai.at(i);
  dp = vector<int>(K+100, false);
  
  for (int i = 1; i <= K; ++i) {
        for (int j : ai) {
            if (i >= j){
              dp.at(i) |= !dp.at(i - j);
            }
        }
    }

  cout << (dp.at(K) ? "First" : "Second") << endl;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int H, W;
    cin >> H >> W;

    vector<int> dx{1, 0, -1, 0};
    vector<int> dy{0, 1, 0, -1};
    vv<char> s(H, v<char>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> s[i][j];
        }
    }

    for (int i = 1; i < H-1; i++)
    {
        for (int j = 1; j < W-1; j++)
        {
            if (s[i][j] == '#' &&s[i][j-1]=='.'&&s[i-1][j]=='.'&&s[i+1][j]=='.'&&s[i][j+1]=='.')
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }


    cout << "Yes" << endl;
    return 0;
}

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

const long long inf=1e18+2137;
const long long MAXN=5e4;
vector<pair<long long,long long>> g[MAXN];

long long dist[MAXN];
int ok[MAXN];
bool odw[MAXN];

void dfs(int u)
{
    odw[u]=true;
    for(auto v:g[u])
        if(!odw[v.first])
            dfs(v.first);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,m,a,b;
    long long c,p;
    cin>>n>>m>>p;
    for(long long i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        g[a].emplace_back(make_pair(b,p-c));
    }
    dfs(1);
    for(int i=1;i<=n;i++)
    {
        if(odw[i])
            ok[i]++;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            odw[j]=false;
        dfs(i);
        if(odw[n])
            ok[i]++;
    }
    for(long long i=2;i<=n;i++)
        dist[i]=inf;
    for(long long i=1;i<n;i++)
        for(long long u=1;u<=n;u++)
            for(auto v:g[u])
                if(dist[u]!=inf&&dist[u]+v.second<dist[v.first])
                    dist[v.first]=dist[u]+v.second;
    for(long long u=1;u<=n;u++)
            for(auto v:g[u])
                if(ok[u]==2&&dist[u]!=inf&&dist[u]+v.second<dist[v.first])
                {
                    cout<<-1<<"\n";
                    return 0;
                }
    if(dist[n]==inf)
        cout<<-1<<"\n";
    else
        cout<<max((long long)0,-dist[n]);
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
vector<ll> a, p;
ll f(ll n, ll x) {
	if (n == 0) {
		if (x <= 0)return 0;
		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() {
	ll N, X; cin >> N >> X;
	a.push_back(1);
	p.push_back(1);
	for (int i = 0; i < N; ++i) {
		a.push_back(a[i] * 2 + 3);
		p.push_back(p[i] * 2 + 1);
	}
	cout << f(N, X) << endl;
	cin >> N;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORS(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define SORT(v,n) sort(v,v+n)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,n,0)
#define si(n) scanf("%d",&n)
#define sc(s) scanf("%s",s)

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int,vector<int>,greater<int> > PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll,vector<ll>,greater<ll> > PQSL;

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y){
    return (x / gcd(x, y)) * y;
}

int main(void){
    char A[4];
    cin >> A;

    if(A[0]==A[1] and A[2]==A[3] and A[0]!=A[2]) puts("Yes");
    else if(A[0]==A[2] and A[1]==A[3] and A[0]!=A[1]) puts("Yes");
    else if(A[0]==A[3] and A[1]==A[2] and A[0]!=A[1]) puts("Yes");
    else puts("No");


    return 0;
}



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

int idx[1000],a[1000],b[1000],c[1000];
int main(){
    int n;
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>idx[i]>>a[i]>>b[i]>>c[i];

        int A,B,C,D;
        cin>>A>>B>>C>>D;
        bool flag=false;
        for(int i=0;i<n;i++){
            if(a[i]>A)continue;
            if(b[i]>B)continue;
            if(c[i]>C)continue;
            if(a[i]*4+b[i]*9+c[i]*4>D)continue;
            flag=true;
            cout<<idx[i]<<endl;
        }
        if(flag==false)cout<<"NA"<<endl;
    }
    return 0;
}

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

 int main() {
 int n;
 cin >> n;
 vector<int> p(n);
 rep(i, n) cin >> p[i];
 int k = 0;
 rep(i, n) if(p[i] != i + 1) k++;
 if(k <= 2) cout << "YES" << endl;
 else cout << "NO" << endl;
 return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

constexpr int MAX_N = 10,
              MAX_Q = 50;

int N, M, Q, A[MAX_N];
int as[MAX_Q], bs[MAX_Q], cs[MAX_Q], ds[MAX_Q];

int64 DFS(int index) {
    if (index == N) {
        int64 res = 0;
        for (int i = 0; i < Q; i++) {
            if (A[bs[i]] - A[as[i]] == cs[i]) {
                res += ds[i];
            }
        }
        return res;
    }
    int start = (index > 0) ? A[index - 1] : 1;
    int64 res = 0;
    for (int num = start; num <= M; num++) {
        A[index] = num;
        res = max(res, DFS(index + 1));
    }
    return res;
}

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

    cin >> N >> M >> Q;

    for (int i = 0; i < Q; i++) {
        cin >> as[i] >> bs[i] >> cs[i] >> ds[i];
        as[i]--;
        bs[i]--;
    }

    cout << DFS(0) << endl;

    return 0;
}



Measured memory_bytes: 3116
idx = 1
while True:
    n = int(input())
    if n==0: break
    x = []
    y = []
    for _ in range(n):
        a,b = map(int,input().split())
        x.append(a)
        y.append(b)
    x.append(x[0])
    y.append(y[0])

    s = 0.0
    for i in range(n):
        s += x[i]*y[i+1] - x[i+1]*y[i]
    print(idx, abs(s/2))
    idx += 1
    input()

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

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var buff = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var H = buff[0];
            var W = buff[1];
            var N = buff[2];
            var canvas = new Dictionary<Tuple<int, int>, ulong>();
            var xcanvas = new Dictionary<int, Dictionary<int, ulong>>();
            for (int i = 0; i < N; i++)
            {
                buff = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var a = buff[0] - 1;
                var b = buff[1] - 1;
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        var x = a - j;
                        var y = b - k;
                        if (0 <= x && x + 2 < H)
                        {
                            if (xcanvas.ContainsKey(x))
                            {
                                if (0 <= y && y + 2 < W)
                                {
                                    var ycanvas = xcanvas[x];
                                    if (ycanvas.ContainsKey(y))
                                    {
                                        ycanvas[y]++;
                                    }
                                    else
                                    {
                                        ycanvas.Add(y, 1);
                                    }
                                }
                            }
                            else if (0 <= y && y + 2 < W)
                            {
                                var ycanvas = new Dictionary<int, ulong>();
                                ycanvas.Add(y, 1);
                                xcanvas.Add(x, ycanvas);
                            }
                        }
                    }
                }
            }
            var ans = new ulong[10];
            foreach (var x in xcanvas)
            {
                foreach(var y in x.Value)
                {
                    ans[y.Value]++;
                }
            }
            ulong zero = (ulong)(H - 2) * (ulong)(W - 2);
            foreach(var a2 in ans)
            {
                zero -= a2;
            }
            ans[0] = zero;
            foreach (var a2 in ans)
            {
                Console.WriteLine(a2);
            }

        }
    }
}


Measured memory_bytes: 92016
#include"bits/stdc++.h"
using namespace std;
int main() {
	int n, a, b, c;
	int masatoy[101];
	int max = 0;
	cin >> n;
	cin >> a >> b;
	cin >> c;
	max = c / a;
	for (int i = 0; i < n; i++) {
		cin >> masatoy[i];
	}
	int nedan = a;
	sort(masatoy, masatoy + n);
	for (int i = n - 1; i > -1; i--) {
		nedan += b;
		c += masatoy[i];
		int max2 = (c) / nedan;
		if (max2 > max) { max = max2; }
	}
	cout << max << endl;
}
	

Measured memory_bytes: 3108
#include "bits/stdc++.h"

using namespace std;
using int64 = long long int;

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

    deque<char> d;
    for (auto &c : s)
    {
        d.push_back(c);
    }

    bool reverse = false;

    int q;
    cin >> q;

    for (int _ = 0; _ < q; _++)
    {
        int op;
        cin >> op;

        if (op == 1)
        {
            reverse = !reverse;
        }
        else
        {
            int f;
            string c;
            cin >> f >> c;

            bool front = f == 1;
            if (reverse)
            {
                front = !front;
            }

            if (front)
            {
                d.push_front(c[0]);
            }
            else
            {
                d.push_back(c[0]);
            }
        }
    }

    if (reverse)
    {
        for (int i = d.size() - 1; i >= 0; i--)
        {
            cout << d[i];
        }
    }
    else
    {
        for (int i = 0; i < d.size(); i++)
        {
            cout << d[i];
        }
    }

    cout << endl;
}

Measured memory_bytes: 896