akhauriyash/Code-Regression huggingface dataset:
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	int a,b,c;cin>>a>>b>>c;
	if(4*a*b<(c-a-b)*(c-a-b)  and (c-a-b)>0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end();

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

ll sum(int n){
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}
using namespace std;


int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   string s; cin >> s;
   
   int cnt1 = 0;
   int cnt2 = 0;
   for(int i = 0; i < s.size(); i++){
      if(s[i] == '1') cnt1++;
      if(s[i] == '0') cnt2++;
   }
   cout << min(cnt1, cnt2) * 2;
   return 0;
}


Measured memory_bytes: 512
def idx_to_wxy(x, y, idx):
    return (2 * x + 1 + (idx % 2) * (2 - idx), 2 * y + 1 + (1 - idx % 2) * (1 - idx))
ws = [[0]*11 for _ in range(11)]
for i in range(1, 10):
    if i % 2:
        ws[i][2], ws[i][4], ws[i][6], ws[i][8] = map(int, list(input()))
    else:
        ws[i][1], ws[i][3], ws[i][5], ws[i][7], ws[i][9] = map(int, list(input()))
x = y = 0
ds = list('RDLU')
d = 'R'
while True:
    print(d, end='')
    idx = ds.index(d)
    x += (idx % 2) * (2 - idx)
    y += (1 - idx % 2) * (1 - idx)
    if x == y == 0:
        break
    for i in range(-1, 3):
        if ws[idx_to_wxy(x, y, (idx + i) % 4)[0]][idx_to_wxy(x, y, (idx + i) % 4)[1]]:
            d = ds[(idx + i) % 4]
            break
print('')

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

#define MAX_N 55555
typedef long long ll;

bool isprime[MAX_N];

void prime(){
    isprime[0]=isprime[1]=true;
    for(int i=2;i<=MAX_N;i++){
        if(!isprime[i]){
            for(int j=i*2;j<=MAX_N;j+=i){
                isprime[j]=true;
            }
        }
    }
}
int main(){
    prime();
    int n;
    cin>>n;
    int temp=10;
    for(int i=0;i<n;i++){
        for(int j=temp;j<MAX_N;j++){
            if(!isprime[j]&& j%5==1){
                cout<<j<<" ";
                temp=j+1;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
let rec solve a b = function
  | 0 -> (a, b)
  | k -> solve (b + a / 2) (a / 2) (k - 1)

let () = Scanf.scanf "%d %d %d" @@ fun a b k ->
  let (a, b) = solve a b k in
  if k mod 2 = 0
  then Printf.printf "%d %d\n" a b
  else Printf.printf "%d %d\n" b a



Measured memory_bytes: 384
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    make2(ll,n,d);
    ll c=0;
    fr(i,n){
        make2(ll,x,y);
        if(x*x+y*y<=d*d) c++;
    }

    cout<<c<<endl;

    return 0;
}


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

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

def swap(a, b):
    t = a
    a = b
    b = t
    return [a, b]

def bubble_sort(l):
    count = 0
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
    return l, count

l, count = bubble_sort(A)
print(' '.join(str(x) for x in l))
print(count)

Measured memory_bytes: 7772
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int A,B,C;
    cin>>A>>B>>C;
    cout<<min(B/A,C)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<ll>ch[2010];
ll ans[2010];
int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	a--;b--;
	ch[a].push_back(b);
	ch[b].push_back(a);
	for(ll i=0;i<n-1;i++){
		ch[i].push_back(i+1);
		ch[i+1].push_back(i);
	}
	for(ll i=0;i<n;i++){
	queue<ll>q;
	q.push(i);
	ll dx[2010];
	for(ll j=0;j<n;j++){
		dx[j]=-1;
	}
	dx[i]=0;
	while(q.size()!=0){
		ll now=q.front();
		q.pop();
		for(ll i=0;i<ch[now].size();i++){
			ll next=ch[now][i];
			if(dx[next]!=-1){
				continue;
			}
			else{
				dx[next]=dx[now]+1;
				ans[dx[next]]++;
				q.push(next);
			}
		}
	}
	}
	for(ll i=1;i<n;i++){
		cout << ans[i]/2<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[55];
ll dpp[55];
ll n,x;

ll rec(ll level,ll x){
    if(level==0){
        if(x<=0)return 0;
        else return 1;
    }
    else{
        if(x<=1+dp[level-1]){
            return rec(level-1,x-1);
        }
        else return dpp[level-1]+1+rec(level-1,x-dp[level-1]-2);
    }
}

int main(void){
    dp[0]=1;
    dpp[0]=1;
    for(ll i=1;i<55;i++){
        dp[i]=2*dp[i-1]+3;
        dpp[i]=2*dpp[i-1]+1;
    }
    cin>>n>>x;
    cout<<rec(n,x)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    int H, W, i, j, judge=1, judge2;
    string s[100];

    cin >> H >> W;

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

    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(s[i][j]=='#'){
                if(i>0 && s[i-1][j]=='#'){
                    judge2 = 1;
                }
                else if(i<H-1 && s[i+1][j]=='#'){
                    judge2 = 1;
                }
                else if(j>0 && s[i][j-1]=='#'){
                    judge2 = 1;
                }
                else if(j<W-1 && s[i][j+1]=='#'){
                    judge2 = 1;
                }
                else{
                    judge = 0;
                }
            }
        }
    }

    if(judge==1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(x, y);
    int ans = 0;
    while (x <= y) {
        ans++;
        x *= 2;
    }
    cout << ans << endl;




    return 0;
}




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

enum Seat {
    MALE = 0,
    FEMALE = 1,
    VACANT = 2,
    UNKNOWN = 3
};

int main() {
    int n;
    std::cin >> n;
    std::vector<Seat> seats(n);
    for (int i = 0; i < n; ++i) {
        seats[i] = UNKNOWN;
    }
    int queries_count = 0;
    std::string query_result = "";
    int query = 0;
    std::cout << query << "\n";
    std::flush(std::cout);
    int left = 0;
    int right = n - 1;
    ++queries_count;
    std::cin >> query_result;
    if (query_result == "Vacant") {
        seats[query] = VACANT;
        return 0;
    } else if (query_result == "Male") {
        seats[query] = MALE;
    } else {
        seats[query] = FEMALE;
    }

    query = n / 2;
    std::cout << query << "\n";
    std::flush(std::cout);
    ++queries_count;
    std::cin >> query_result;
    if (query_result == "Vacant") {
        seats[query] = VACANT;
        return 0;
    } else if (query_result == "Male") {
        seats[query] = MALE;
    } else {
        seats[query] = FEMALE;
    }

    int dist = query - 0 + 1;
    if (seats[0] == seats[query]) {
        if (dist % 2 == 0) {
            left = 0;
            right = query;
        } else {
            left = query;
            right = 0;
        }
    } else {
        if (dist % 2 == 0) {
            left = query;
            right = 0;
        } else {
            left = 0;
            right = query;
        }
    }

    while (queries_count < 20 && query_result != "Vacant") {
        if (right == 0) {
            query = (left + n) / 2;
        } else {
            query = (left + right) / 2;
        }
        if (seats[query] != UNKNOWN) {
            ++query;
        }

        std::cout << query << "\n";
        std::flush(std::cout);
        ++queries_count;
        std::cin >> query_result;
        if (query_result == "Vacant") {
            seats[query] = VACANT;
            return 0;
        } else if (query_result == "Male") {
            seats[query] = MALE;
        } else {
            seats[query] = FEMALE;
        }

        dist = query - left + 1;
        if (seats[left] == seats[query]) {
            if (dist % 2 == 0) {
                right = query;
            } else {
                left = query;
            }
        } else {
            if (dist % 2 == 0) {
                left = query;
            } else {
                right = query;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1236
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 2e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

vector<int> e[maxn];
int vis[maxn];
ll v[maxn];

void bfs() {
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int u = q.front();
        vis[u] = 1;
        q.pop();
        for (auto x : e[u]) {
            if (vis[x]) continue;
            q.push(x);
            v[x] += v[u];
        }
    }
}

void solve() {
    int n, q;
    cin >> n >> q; 
    for (int i = 0; i < n - 1; i++) {
        int u,v ;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for (int i = 0; i < q; i++) {
        int p;
        ll x;
        cin >> p >> x;
        v[p] += x;
    }
    bfs();
    for (int i = 1; i <= n; i++) {
        if (i == 1) cout << v[i];
        else cout << " " << v[i];
    }
    cout << endl;
}

int main(void) {
    FAST_IO;
    
    solve();
    
    return 0;
}

Measured memory_bytes: 17140
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

int main(){
    int k;
    string s;
    cin >> k >> s;
    
    if(s.length() <= k){
        cout << s << endl;    
    } else {
        string ans = s.substr(0,k);
        cout << ans;
        cout << "...";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
#define nw ans=min(ans,(LL)(R1-R2)*(B1-B2))
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=200005;
int n,suf[N];
struct ex{int x,y;}d[N];
inline bool operator < (const ex &a,const ex &b) {return a.x<b.x;}
int main( )
{
  int i,x,y,R1,R2,B1,B2,pre;LL ans=1e18;
  n=read( );R1=0;R2=1e9;
  for(i=1;i<=n;i++)
    {
      x=read( );y=read( );
      if(x>y) d[i].x=y,d[i].y=x;
      else d[i].x=x,d[i].y=y;
      R1=max(R1,d[i].y);
      R2=min(R2,d[i].y);
    }
  sort(d+1,d+n+1);
  B1=d[n].x;B2=d[1].x;nw;
  R2=d[1].x;B1=max(B1,d[1].y);pre=d[1].y;
  for(i=2;i<n;i++) 
    {
      if((B2=d[i].x)>pre) break;
      nw;B1=max(B1,d[i].y);pre=min(pre,d[i].y);
    }
  B2=pre;nw;
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;

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

            int[] nums = new int[5];

            for (int i = 0; i < 5; i++)
            {
                nums[i] = int.Parse(input[i]);
            }
                

            Array.Sort(nums);
            Array.Reverse(nums);

            string ans = "";
            for (int i= 0;i<5;++i)
            {
                ans += nums[i];

                if (i != 4)
                {
                    ans+=" ";
                }
                
            }
            Console.WriteLine(ans);
            
        }
    }
}



Measured memory_bytes: 15984
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[200100];
ll m=0;
ll b[200100]={};
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=n;i>=1;i--){
		int cou=0;
		for(int j=1;j<=n/i;j++){
			if(b[i*j]==1){
				cou++;
			}
		}
		if((cou+a[i])%2==1){
			b[i]=1;
			m++;
		}
	}
	cout<<m<<endl;
	for(int i=1;i<=n;i++){
		if(b[i]==1){
			cout<<i<<" ";
		}
	}
	if(m!=0)cout<<endl;
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
using namespace std;
const int MAXTIME = 1260;
void fill(vector<bool> &a,int s,int l){
  for(int i = s;i < l;i++){
    a[i] = true;
  }
  return;
}
int solve(vector<bool> &a,int s,int l){
  int ans = 0;
  for(int i = s;i < l;i++){
    if(a[i]){
      ans++;
    }
    /*    if(a[i] == 1 && a[i+1] == 0){
      ans--;
      }*/
  }
  return ans;
}
int main(){
  while(1){
    int N,M;
    cin >> N >> M;
    if(N == 0 && M == 0)break;
    vector<vector<bool> > students(M,vector<bool>(MAXTIME+2,false));
    //int students[10000][1260] = {0};
    vector<vector<int> > keep(M,vector<int>(N+1,0));


    int r;
    cin >> r;
    for(int i = 0;i < r;i++){
      int t,n,m,s;
      cin >> t >> n >> m >> s;
      if(s == 0){
	fill(students[m-1],keep[m-1][n-1],t);
      }else if(s == 1){
	keep[m-1][n-1] = t;
      }
    }
    int q;
    cin >> q;
    for(int i = 0;i < q;i++){
      int ts,te,m;
      cin >> ts >> te >> m;
      cout << solve(students[m-1],ts,te) << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 33352
n=int(input())
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

b=groupby(sorted([int(i) for i in input().split()]))
l=len(b)
co=0
for i in range(l):
    co+=(b[i][1]-1)
if co%2==0:
    print(l)
else:
    print(l-1)


Measured memory_bytes: 17704
import sys

def to_i(e):
  return int(e)

def solve(n,s,a):
  if n == 1:
    if s>=a and s<=9:
      return 1
    else:
      return 0
  result = 0
  for i in xrange(a, s-a):
    result += solve(n-1, s-i, i+1)
  return result

while True:
  line = sys.stdin.readline()
  if line == "0 0\n": break
  l = map(to_i, line.rstrip().split(" "))
  n = l[0]
  s = l[1]
  print solve(n,s,0)

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

int main()
{
  int M, D, sum = 0;
  cin >> M >> D;

  for (int i = 4; i < M + 1; i++)
  {
    for (int j = 22; j < D + 1; j++)
    {
      if (j % 10 == 1)
      {
      }
      else if (i == (j / 10) * (j % 10))
      {
        sum++;
      }
    }
  }
  cout << sum << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	vector<int64> A(N);
	REP(i, N) cin >> A[i];
	bool ok = 1;
	REP(i, N) {
	  if (A[i] % 2 == 0) {
	    if (A[i] % 3 != 0 && A[i] % 5 != 0) {
	      ok = 0;
	    }
	  }
	}
	if (ok) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i%2 == 1:
            sym1 = "#"
            sym2 = "."
        else:
            sym1 = "."
            sym2 = "#"

        for j in range(w):
            if j%2 == 1:
                print(sym1,end="")
            else:
                print(sym2,end="")
        print("")
    
    print("")

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

const int mod=1e9+7;

int main(){
    int n;
    string s;
    cin>>n>>s;
    ll ans=1;
    map<char,int>mp;
    rep(i,n)mp[s[i]]++;
    for(auto&p:mp){
        ans=ans*(p.second+1)%mod;
    }
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}



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

  rep(i, s.size()){
    if(i%2==0){
      cout << s[i];
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

bool contain(int n, vector<int>& v) {
    string s = to_string(n);
    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < v.size(); j++) {
            if(s[i] - '0' == v[j]) {
                return true;
            }
        }
    }
    return false;
}

signed main() {
    int n, k; cin >> n >> k;
    vector<int> d(k);
    for(int i = 0; i < k; i++) cin >> d[i];

    int ans = n;
    while(true) {
        bool flag = contain(ans, d);
        if(flag) ans++;
        else {
            cout << ans << endl;
            return 0;
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];

  for (int i = 0; i < N; i++)
    if (h[0] == 0 && h[i] >= 1)
      swap(x[0], x[i]), swap(y[0], y[i]), swap(h[0], h[i]);

  int Cx, Cy, H;
  for (Cx = 0; Cx <= 100; Cx++) {
    for (Cy = 0; Cy <= 100; Cy++) {
      bool flag = true;
      for (int i = 0; i < N; i++) {
        if (i == 0) H = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy);
        if (max(H - abs(x[i] - Cx) - abs(y[i] - Cy), 0) != h[i]) flag = false;
      }
      if (flag) goto end;
    }
  }

end:

  cout << Cx << " " << Cy << " " << H << endl;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var a = Read();
        var b = Read();
        Console.WriteLine(GetAccumXOR(b) ^ GetAccumXOR(a == 0 ? 0 : a - 1));
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static long GetAccumXOR(long end)
    {
        return (end % 2 == 0 ? end : 0) | (((end & 1) + ((end & 2) >> 1)) & 1);
    }

    static readonly TextReader In = Console.In;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static long Read()
    {
        long res = 0;
        int next = In.Read();
        while (48 > next || next > 57) next = In.Read();
        while (48 <= next && next <= 57)
        {
            res = res * 10 + next - 48;
            next = In.Read();
        }
        return res;
    }
}


Measured memory_bytes: 11092
#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;

//
// nCk mod m
//
// Complexity:
//     preprocessing: O(max{n,k} log max{n,k}) time
//     query: O(1) time
//

const int MAX_N = 6000000;
const int MOD = 1000000007;
long long inv[MAX_N + 1], fac[MAX_N + 1], finv[MAX_N + 1];

void init() {
    inv[1] = fac[0] = fac[1] = finv[0] = finv[1] = 1;
    for (int i = 2; i <= MAX_N; ++i) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fac[i] = fac[i - 1] * i % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long nPk(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

long long nCk(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return nPk(n, k) * finv[k] % MOD;
}

long long nHk(int n, int k) {
    if (n < 0 || k < 0) return 0;
    return nCk(n + k - 1, k);
}

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

    init();
    int A, B, C, Sx, Sy;
    while (cin >> A >> B >> C >> Sx >> Sy, A + B + C) {
        int sum = 0, lim = (A == 0 ? 0 : Sx + 1);
        FOR (i, A, lim + 1) {
            int sub = 1, j = Sy - Sx + i;
            if (B > 0 && j < B) continue;
            if (B == 0 && j != 0) continue;
            if (A) (sub *= nHk(A, i - A)) %= MOD;
            if (B) (sub *= nHk(B, j - B)) %= MOD;
            (sub *= nHk(A + B + C, Sx - i)) %= MOD;
            (sum += sub) %= MOD;
        }
        cout << sum * nCk(A + B + C, A) % MOD * nCk(B + C, B) % MOD << endl;
    }
}


Measured memory_bytes: 143792
#include <bits/stdc++.h>
using namespace std;
 int N, K;
vector<int> d;
vector<vector<int>> A;

void input(){
  cin >> N >> K;
  d.resize(K);
  A.resize(K, vector<int>());
  for(int i=0;i<K;i++){
    cin >> d[i];
    A[i].resize(d[i]);
    for(int j =0; j<d[i];j++){
      cin >> A[i][j];
    }
  }
}

void solve(){
  int ans =0;
  for(int i=1;i<=N;i++){
    bool have = false;
    for(auto v : A){
      for(auto p:v){
        if(p == i)have = true;
      }
    }
    if(!have)ans++;
  }
  cout << ans <<endl;
}

int main(){
  input();
  solve();
  return 0;
}


Measured memory_bytes: 3612
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make(map[int]int, 0)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		var t int
		t = nextInt(sc)
		if a[t] > 0 {
			a[t] = 0
		} else {
			a[t] = 1
		}
	}
	// fmt.Println("a", a)
	ans := 0
	for _, v := range a {
		if v > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7424
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)

for i in range(M):
    x, y, c = list(map(int, input().split()))
    tmp = a[x-1] + b[y-1] - c
    if ans > tmp:
        ans = tmp

print(ans)

Measured memory_bytes: 18612
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  int n;
  string s;
  cin>>n>>s;
  int a=0,b=0;
  rep(i,0,n){
    if(s[i]=='R') a++;
    else b++;
  }
  if(a>b) co("Yes");
  else co("No");
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[4][4];
bool f(int a1,int a2,int a3,int b1,int b2,int b3)
{
    if(a[2][1]==a2+b1&&a[2][2]==a2+b2&&a[2][3]==a2+b3&&a[3][1]==a3+b1&&a[3][2]==a3+b2&&a[3][3]==a3+b3)
        return 1;
    return 0;
}
int main()
{
    for(int i = 1;i <= 3;i++)
        for(int j = 1;j <= 3;j++)
            cin >> a[i][j];
    for(int i = 0;i <= min(a[1][1],min(a[1][2],a[1][3]));i++)
        for(int j = 0;j <= min(a[2][1],min(a[2][2],a[2][3]));j++)
            for(int l = 0;l <= min(a[3][1],min(a[3][2],a[3][3]));l++)
                if(f(i,j,l,a[1][1]-i,a[1][2]-i,a[1][3]-i))
                {cout << "Yes";return 0;}
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    int ans = 0;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(),l.end());
    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            for(int k = j+1; k< n; k++){
                if(l[i] != l[j] && l[j] != l[k]){
                    if(l[k] < l[i] + l[j] )ans++;
                    //cout << l[i] << " " << l[j] << " " << l[k] << endl;
                    //cout << i+1 << " " << j+1 << " " << k+1 << endl;
                    

                }
                
            }
        }
    }
        
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 3640
from bisect import bisect_right as br

def main():
    S = [s for s in input()]
    T = [t for t in input()]
    slen = len(S)
    tlen = len(T)

    dic = {}
    for i in range(slen):
        if S[i] in dic:
            dic[S[i]].append(i)
        else:
            dic[S[i]] = [i]

    ans = 0
    pre = 0
    if T[0] in dic:
        if T[0] != S[0]:
            ans = dic[T[0]][0]
            pre = dic[T[0]][0]
    else:
        print(-1)
        return 

    for j in range(1,tlen):
        t = T[j]
        if t in dic:
            point = br(dic[t],pre)
            if point == len(dic[t]):
                ans += slen - pre + dic[t][0]
                pre = dic[t][0]
            else:
                if pre == dic[t] == point:
                    ans += slen
                else:
                    ans += dic[t][point] - pre
                    pre = dic[t][point]
        else:
            print(-1)
            return
    print(ans + 1)
    return 
main()

Measured memory_bytes: 55764
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
S = []
R = -1000000001
#それぞれについての累積和の計算
for i in range(N):#このループはN個の初期マスの時のループ
    t = i  # tは現在の位置
    cnt = 0  # 累積和
    sum = []  # 累積和のリスト
    res = 0
    while True:#このループは一つの初期マスの累積和。最初のコマに戻るまで
        t = P[t]-1
        cnt += C[t]
        sum.append(cnt)
        if t == i:
            break
    #S.append(sum)
    if len(sum) >=  K:
        res = max(sum[:K])
    else:
        if sum[-1] <= 0:
            res = max(sum)
        else:
            score1 = sum[-1] * (K // len(sum) - 1) + max(sum)
            score2 = sum[-1] * (K // len(sum))
            r = K % len(sum)
            if r != 0:
                score2 += max(0, max(sum[:r]))
            res = max(score1,score2)
    R = max(R,res)
print(R)


Measured memory_bytes: 81328
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int main(){
	string s;
	int lu,ru,ld,rd;
	int n;
	while(cin>>n&&n){
		int ans=0;
		bool l=false,r=false;
		rep(i,n){
			cin>>s;
			if(s[0]=='l')l=!l;
			else r=!r;
			if(ans%2&&!l&&!r)ans++;
			else if(ans%2==0&&l&&r)ans++;

		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

int main()
{
	ll n, k, s;
	while (cin >> n >> k >> s, n | k | s) {
		vector<ll> x(n), y(n), z(n);
		for (int i = 0; i < n; i++) {
			cin >> x[i] >> y[i] >> z[i];
		}
		if (k == 1) {
			cout << s * s * 6 << endl;
			continue;
		}
		vector<vector<P>> G(n);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j) {
					ll dx = s - abs(x[i] - x[j]), dy = s - abs(y[i] - y[j]), dz = s - abs(z[i] - z[j]);
					if (dx > 0 && dy > 0 && dz > 0) {
						G[i].push_back(P(j, (dx * dy + dy * dz + dz * dx) * 2));
					}
				}
			}
		}
		ll res = s * s * 6 * k, d = 0;
		for (int i = 0; i < n; i++) {
			for (int l = 0; l < 2; l++) {
				vector<int> v;
				vector<ll> used(n);
				ll tmp = 0;
				bool flag = true;
				used[i] = -1;
				if (G[i].size() <= l) continue;
				for (auto p : G[i]) {
					used[p.first] += p.second;
				}
				v.push_back(G[i][l].first);
				for (int j = 0; j < k - 1; j++) {
					while (!v.empty() && used[v.back()] < 0) {
						v.pop_back();
					}
					if (v.empty()) {
						flag = false;
						break;
					}
					auto ne = v.back(); v.pop_back();
					tmp += used[ne];
					used[ne] = -1;
					for (auto p : G[ne]) {
						if (used[p.first] >= 0) {
							used[p.first] += p.second;
							v.push_back(p.first);
						}
					}
				}
				if (flag) {
					d = max(d, tmp);
				}
			}
		}
		cout << (d ? res - d : -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
n =int(input())
kotae=0
a = input().split(" ")
lint_a = [int(n) for n in a]
lista = sorted(lint_a, reverse = True)
if n%2==0:
  kotae+=lista[0]
  b=n//2+1
  for i in range(1,b-1):
    kotae+=lista[i]*2
else:
  kotae+=lista[0]
  b=(n+1)//2
  kotae+=lista[b-1]
  for i in range(1,b-1):
    kotae+=lista[i]*2
print(kotae)

Measured memory_bytes: 33216
#include <iostream>
#include <math.h>

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((abs(c-a) <= d) || ((abs(a-b) <= d) && (abs(b-c) <= d)))
        cout << "Yes";
    else
        cout << "No";
    return 0;

}

Measured memory_bytes: 256
ans = []
O = list(input())
E = list(input())
for i in range(min(len(O),len(E))):
    ans.append(O[i])
    ans.append(E[i])
if len(O)!=len(E):
    if len(O)>len(E):
        ans.append(O[len(O)-1])
    else:
        ans.append(E[len(E)-1])
ans1 = ''.join(ans)
print(ans1)

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	int n;
	double res = 0;
	cin >> n;
	rep(i, 0, n - 1)
	{
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY")
		{
			res += x;
		}
		else
		{
			res += x * 380000;
		}
	}
	cout << res << endl;
}



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

int main( )
{
    set<int> a, b, c;
    int x, y;
    a.insert(1);
    a.insert(3);
    a.insert(5);
    a.insert(7);
    a.insert(8);
    a.insert(10);
    a.insert(12);
    b.insert(4);
    b.insert(6);
    b.insert(9);
    b.insert(11);
    c.insert(2);

    cin >> x >> y;
    if ( a.find(x) != a.end() && a.find(y) != a.end() ) {
        cout << "Yes\n";
    }
    else if ( b.find(x) != b.end() && b.find(y) != b.end() ) {
        cout << "Yes\n";
    }
    else if ( c.find(x) != c.end() && c.find(y) != c.end() ) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
int n;
using edge = struct {LL to; LL cost;};
vector<vector<edge>> g;
VL color;

void dfs(int v, int par) {
	for (auto&& e : g[v]) {
		if (e.to == par) continue;
		color[e.to] = color[v] ^ (e.cost == 1 ? 1 : 0);
		dfs(e.to, v);
	}
}

int main(int argc, char const* argv[])
{
	cin >> n;
	g = vector<vector<edge>>(n);
	color = VL(n,-1);
	color[0] = 0;
	for (int i = 0; i < n-1; i++) {
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		c = c%2;
		g[a].push_back(edge{b, c});
		g[b].push_back(edge{a, c});
	}
	dfs(0, -1);
	for (int i = 0; i < n; i++) {
		cout << color[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 9984
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        while(x!=0 || y!=0){
            if(x<y){
                System.out.println(x+" "+y);
            }else{
                System.out.println(y+" "+x);
            }
            x = sc.nextInt();
            y = sc.nextInt();
        }
    }
}


Measured memory_bytes: 35904
import java.util.Scanner;

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

        int n = sc.nextInt();
        int d = sc.nextInt();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans++;
            i += d*2;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll val[103] , w[103] , n , mw , dp[103][100009];
ll knapsack(ll i , ll v)
{
    if(i > n) return 0 ;
    if(dp[i][v] != -1) return dp[i][v] ;
    ll a = 0 , b = 0 ;
    if(v + w[i] <= mw)a = val[i] + knapsack(i+1,v + w[i]) ;
    b = knapsack(i+1,v) ;
    return dp[i][v] = max(a,b) ;
}
int main()
{
    memset(dp,-1,sizeof(dp)) ;
    cin>>n>>mw ;
    for(ll i = 1 ; i <= n ; i++) cin>>w[i]>>val[i] ;
    ll k = knapsack(1,0) ;
    cout<<k<<endl ;
}


Measured memory_bytes: 80768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    string s;
    int q;
    cin>>s>>q;
    
    deque<char> deq;
    rep(i,s.size()){
        deq.push_back(s[i]);
    }

    bool rev=false;
    rep(i,q){
        int t;
        cin>>t;
        if(t==1) rev=!rev;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(f==1){
                if(rev) deq.push_back(c);
                else deq.push_front(c);
            }
            else{
                if(rev) deq.push_front(c);
                else deq.push_back(c);
            }
        }
    }

    if(rev) reverse(all(deq));
    for(auto c : deq){
        cout<<c;
    }
    cout<<endl;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
}

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

const int INF = 1e9;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int H, N; 
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

    // dp[N]体力がNのやつを倒すために最低限な魔力.
    vector<int> dp(H + 1, INF);
    dp[0] = 0;
    // モンスターのHPをノードとしたDPを作成
    for (int i = 1; i <= H; i++) {
        for (int j = 0; j < N; j++) {
            dp[i] = min(dp[max(i - A[j], 0LL)] + B[j], dp[i]);
        }
    }
    cout << dp[H] << endl;
    return 0;
}





Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n, m = 26, x;
  scanf("%d",&n);
  scanf("%d",&x);
  vi a(m);
  rep(i,n) {
    string s;
    cin >> s;
    a[s[0]-'A']++;
  }
  int ans = 0;
  while (1) {
    sort(rng(a)); reverse(rng(a));
    bool ok = true;
    rep(i,x) {
      a[i]--;
      if (a[i] < 0) ok = false;
    }
    if (!ok) break;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
struct edge{
    int to;
    int cap;
    int rev;
};
struct Ford{
    vector<vector<edge>> G;
    int V;
    vector<int> used;
    Ford(int N){
        V = N;
        used.resize(V, 0);
        G.resize(V);
    }
    void add(int u, int v, int c){
        edge e1 = {v, c, (int)G[v].size()};
        G[u].push_back(e1);
        edge e2 = {u, 0, (int)G[u].size() - 1};
        G[v].push_back(e2);
    }
    int dfs(int s, int t, int f){
        if(s == t) return f;
        used[s] = 1;
        for(edge &e: G[s]){
            if(used[e.to] == 0 && e.cap > 0){
                long long temp = dfs(e.to, t, min(f, e.cap));
                if(temp > 0){
                    e.cap -= temp;
                    G[e.to][e.rev].cap += temp;
                    return temp;
                }
            }
        }
        return 0;
    }
    int solve(int s, int t){
        int ans = 0;
        int INF = 1e9;
        while(1){
            used.assign(V, 0);
            int res = dfs(s, t, INF);
            if(res == 0) return ans;
            ans += res;
        }
    }
};
int main(){
    int X, Y, E;
    cin >> X >> Y >> E;
    Ford Ford(X + Y + 2);
    for(int i = 0; i < X; i++) Ford.add(X + Y, i, 1);
    for(int i = 0; i < Y; i++) Ford.add(X + i, X + Y + 1, 1);
    for(int i = 0; i < E; i++){
        int x, y;
        cin >> x >> y;
        Ford.add(x, X + y, 1);
    }
    int ans = Ford.solve(X + Y, X + Y + 1);
    cout << ans << endl;
}


Measured memory_bytes: 3292
def solve():
    n = int(input())
    av = list(map(int, input().split(' ')))
    cur = 1
    ans = 0
    s = sum(av)
    for i in range(n+1):
        if cur < av[i]: return -1
        ans += cur
        s -= av[i]
        cur -= av[i]
        if (s <= cur * 2):
            j = 1
            while i + j < n + 1:
                ans += j * av[i + j]
                j += 1
            break
        cur *= 2
    return ans

print(solve())


Measured memory_bytes: 78040
n=int(input())
li1=0
li2=0
li3=0
for i in range(0,n):
    a,b,c=[int(x) for x in input().split()]
    li11=a+max(li2,li3)
    li22=b+max(li1,li3)
    li33=c+max(li1,li2)
    li1=li11
    li2=li22
    li3=li33
print(max(li1,li2,li3))


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

struct Point{
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    
    Point operator + (Point p) const {return Point(x+p.x,y+p.y);}
    Point operator - (Point p) const {return Point(x-p.x,y-p.y);}
    Point operator * (double d) const {return Point(x*d,y*d);}
    
    double SqrLength() const{
        return x*x+y*y;
    }
    
    void Read(){
        scanf("%lf%lf",&x,&y);
    }
    
    void Write(){
        printf("%.10f %.10f\n",x,y);
    }
    
    double x,y;  

    friend double Dot(Point p1,Point p2){
        return p1.x*p2.x+p1.y*p2.y;
    }
};

struct Line{
    Line(){}
    Point s,t;
    
    friend Point Project(Point p,Line l){
        Point dir=l.t-l.s;
        return l.s+dir*(Dot(dir,p-l.s)/dir.SqrLength());
    }
};

int main(){
    Line l;
    l.s.Read(); l.t.Read();
    int n; scanf("%d",&n);
    while(n--){
        Point p,q;
        p.Read();
        q=Project(p,l);
        q.Write();
    }
    return 0;
}


Measured memory_bytes: 3248