akhauriyash/Code-Regression huggingface dataset:
//gauravsinghh
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 1000000000
#define lim 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
int main(){
    IOS
    //io_set();

    cout << fixed << setprecision(10);
    double a, b, k;
    cin >> a >> b >> k;
    double h = k/(a*a);
    double half = b/2.0;
    double pk = a*b*b;
    double dk = a*a*b;
    if(h == half){
    	cout << 45 << endl;
    }
    else if(h < half){
    	double angle = atan((2.0*k)/pk);
    	angle *= (180.0/PI);
    	cout << 90 - angle << endl;
    }
    else{
    	double angle = atan((a*a*a)/(2.0*(dk - k)));
    	angle *= (180.0/PI);
    	cout << 90 - angle << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1

def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2)}
    return L2, C


MOD = 998244353
N = int(readline())
XY = [list(map(int, readline().split())) for _ in range(N)]
XY.sort()

Z = [-10**10]
for x, y in XY:
    Z.append(y)

_, CC = compress(Z)
XY = [(x, CC[y]) for x, y in XY] 

SS, SB, BS, BB = [None]*N, [None]*N, [None]*N, [None]*N

T = BIT(N)
for i in range(N):
    k = i
    y = XY[i][1]
    l = T.get(y)
    SS[i] = l
    SB[i] = k-l
    T.add(y, 1)
T = BIT(N)
for i in range(N-1, -1, -1):
    k = N-1-i
    y = XY[i][1]
    l = T.get(y)
    BS[i] = l
    BB[i] = k-l
    T.add(y, 1)

P2 = [1]*1341398
for i in range(1, len(P2)):
    P2[i] = P2[i-1]*2%MOD

ans = 0
for i in range(N):
    ss = SS[i]
    sb = SB[i]
    bs = BS[i]
    bb = BB[i]
    ans = (ans + P2[N-1])%MOD
    ans = (ans + P2[N-1-ss-bb]*(P2[ss]-1)*(P2[bb]-1))%MOD
    ans = (ans + P2[N-1-sb-bs]*(P2[sb]-1)*(P2[bs]-1))%MOD
    ans = (ans - (P2[sb]-1)*(P2[bs]-1)*(P2[ss]-1)*(P2[bb]-1))%MOD
    
print(ans)
    

Measured memory_bytes: 170208
import sys
import  math
from heapq import *
import fractions
import bisect
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
c=list(ns())
ans=0
w_l=[]
r_l=[]
for i in range(len(c)):
    if(c[i]=='W'):
        w_l.append(i)
    else:
        r_l.append(i)
    
w_l.sort()
r_l.sort(reverse=True)

for i in range(min(len(w_l),len(r_l))):
    if(w_l[i]<r_l[i]):
        ans+=1
    
print(ans)





Measured memory_bytes: 19984
import java.util.*;
 
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int ans = 0;
        if (X == 1 && Y == 1) {
            ans = 1000000;
        } else {
            if (X == 1) {
                ans += 300000;
            }
            if (Y == 1) {
                ans += 300000;
            }
            if (X == 2) {
                ans += 200000;
            }
            if (Y == 2) {
                ans += 200000;
            }
            if (X == 3) {
                ans += 100000;
            }
            if (Y == 3) {
                ans += 100000;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){

    string S;
    cin >> S;

    int S_length = S.length();


    while(S_length > 0){
        if (S.substr(0, 5) == "dream" && S[5] != 'e'){
            S_length = S_length - 5;
            S = S.substr(5);
        }else if (S.substr(0,5) == "dream" && S.substr(5, 5) == "erase"){
            S_length = S_length - 5;
            S = S.substr(5);
        }else if(S.substr(0,7) == "dreamer"){
            S_length = S_length - 7;
            S = S.substr(7);
        }else if (S.substr(0,5) == "erase" && S[5] != 'r') {
            S_length = S_length - 5;
            S = S.substr(5);
        }else if (S.substr(0,6) == "eraser") {
            S_length = S_length - 6;
            S = S.substr(6);
        }else{
            break;
        }
    }

    if (S_length == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 608
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	vector< int > num;
	int i = 1;
	while (1) {
		if (i > N)
			break;
		int j = N / i;
		if (i <= j) {
			num.push_back(1);
			i++;
		} else {
			num.push_back(N / j - i + 1);
			i = N / j + 1;
		}
	}
	M = num.size();
	vector< vector< int > > dp(K + 1, vector< int >(M + 1, 1));
	vector< vector< int > > S(K + 1, vector< int >(M + 1, 0));
	rep(j, M) S[0][j + 1] = 1;
	rep(i, K) rep(j, M) {
		(dp[i + 1][j + 1] = S[i][M - j] * num[j]) %= MOD;
		(S[i + 1][j + 1] = S[i + 1][j] + dp[i + 1][j + 1]) %= MOD;
	}
	int ans = S[K][M];
	cout << ans << endl;
	//cout << num;
	//cout << dp;
	return 0;
}

Measured memory_bytes: 101256
#include<iostream>
 
using namespace std;
 
int main(){
 
  int a,b,c;
 
  cin >> a >>b>>c;
 
  if(b-a==c-b){
    cout << "YES" << endl;
  }else if(a-b==b-c){
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
    
 
 
 
 
 
  return 0;
}

Measured memory_bytes: 256
import random


d=int(input())
C=[int(i) for i in input().split()]
s=[[int(i) for i in input().split()] for q in range(d)]

sco=0
L=[0 for i in range(26)]
ans=[]

#calc
for i in range(d):
    mayou=random.choice(range(26))
    est=s[i][mayou]+C[mayou]*(i+1-L[mayou])
    ans.append(mayou)
    #print(mayou+1) #output

sco=est

##以下表示
"""
L=[0 for i in range(26)]
for q in range(d):
    t=ans[q]
    sco+=s[q][t]
    
    
    L[t]=q+1
    for i in range(26):
        if L[i]!=-1:
            sco-=C[i]*(q+1-L[i])
    
    print(sco)
"""


m=1000000

for que in range(m):
    newsco=sco
    dn,q=random.choice(range(1,d)),random.choice(range(1,27))
    dn-=1
    q-=1
    old=ans[dn]
    ans[dn]=q
    now=dn
    cnt=1
    while now!=0 and ans[now]!=old:
        now-=1
        cnt+=1
    now=dn
    while now!=d and ans[now]!=old:
        newsco-=cnt*C[old]
        now+=1
        cnt+=1
    newsco-=s[dn][old]
    newsco+=s[dn][q]
    now=dn
    cnt=1
    while now!=0 and ans[now]!=q:
        now-=1
        cnt+=1
    now=dn
    while now!=d and ans[now]!=q:
        newsco+=cnt*C[q]
        now+=1
        cnt+=1
    #print(newsco)
    if newsco>sco:
        sco=newsco
        #print(newsco)
    else:
        ans[dn]=old

for ele in ans:
    print(ele+1)
    

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

using namespace std;

int main(){
  int X;
  cin >> X;
  
  int fh,f;
  fh=X/500;
  f=(X-fh*500)/5;
  
  fh=fh*1000;
  f=f*5;
  
  cout << fh+f << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
double eps=1e-8;
ll mod=1e9+7;
ll inf=1e9;
priority_queue<P,vector<P>,greater<P> > pq;

int main(){
  ll n,m;
  cin>>n>>m;
  ll ans=n*m-2*(n+m)+4;
  if(n==1&&m==1)ans=1;
  else if(n==1||m==1)ans=n*m-2;
  cout<<ans<<endl;
  return 0;
}


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




int main() 
{
	#ifndef ONLINE_JUDGE
	freopen("D_IN.txt","r",stdin);
	freopen("D_Out.txt","w",stdout);
	#endif
	
	vector<string> v;
	int n,k;
	cin>>n>>k;
	fori(0,n)
	{
		string s;
		cin>>s;
		v.push_back(s);
	}
	sort(v.begin(),v.end());

	fori(0,n)
	{
		cout<<v[i];
	}
	
	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()

int f(int x){
    if(x%2 == 0) return x/2;
    else return 3*x+1;
}

int main(){
    int s; cin>>s;
    map<int,bool> M; M[s]=true;
    int c = 1;
    while(1){
        c++;
        s = f(s);
        if(M.find(s) == M.end()) M[s]=true;
        else break;
    }
    cout<<c<<endl;
}

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

int main() {
    int N;
    int d[100];
    cin >> N;
    for (int i = 0; i < N; ++i) scanf("%d", &d[i]);

    set<int> values; // insert するときに重複を取り除いてくれます
    for (int i = 0; i < N; ++i) {
        values.insert(d[i]); // 挿入します
    }

    // set のサイズを出力します
    printf("%d\n",values.size());
}

Measured memory_bytes: 256
program main
    implicit none
    integer(8) a, b, v, w, t
    integer flag

    read(*,*) a, v
    read(*,*) b, w
    read(*,*) t

    flag = 0

    if(a > b) then
        if(a-v*t <= b-w*t) then
            flag = 1
        end if
    else if (a < b) then
        if(a+v*t >= b+w*t) then
            flag = 1
        end if
    else if (a == b) then
        flag = 1
    end if

    if(flag == 1) then
        write(*,*) "YES"
    else
        write(*,*) "NO"
    end if

end program



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

int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) cout << "GREATER" << endl;
    else if (a.size() < b.size()) cout << "LESS" << endl;
    else{
        bool bigger = 0;
        int eq = 0;
        int length = a.size();
        for (int k = 0; k <= length; k++){
            int i = a[k] - '0';
            int j = b[k] - '0';
            if (i > j){
                bigger = 1;
                break;
            }
            else if (i < j){
                break;
            }
            else if (i == j) eq++;
        }

        if (bigger) cout << "GREATER" << endl;
        else if(eq == length + 1) cout << "EQUAL" << endl;
        else cout << "LESS" << endl;
    }
    return 0;
}

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

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

int main() {
    int n,k; cin >> n >> k;
    int h[n]; rep(i,n) cin >> h[i];
    int ans = 0;
    rep(i,n) {
        if (h[i] >= k) ans++;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3952
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
z=[]
for i in range(w):
  if i%2==0:
    for j in range(h):
      z.append([j,i])
  else:
    for j in range(h):
      z.append([h-j-1,i])
count=0
ans=[]
for i,(y,x) in enumerate(z):
  if a[y][x]%2!=0 and i<len(z)-1:
    count+=1
    ans.append(i)
    a[z[i+1][0]][z[i+1][1]]+=1
print(count)
for i in ans:
  print(z[i][0]+1,z[i][1]+1,z[i+1][0]+1,z[i+1][1]+1)

Measured memory_bytes: 43060
#-*- coding: utf-8 -*-

n, m = map(int, raw_input().split())
t = [0] * m
mx = t * n
for i in xrange(n):
	mx[i] = map(int, raw_input().split())

v = [0] * m
for i in xrange(m):
	v[i] = input()

for i in xrange(n):
	t = 0
	for j in xrange(m):
		t += mx[i][j] * v[j]
	print t

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

int main(){
  double t,x; cin>>t>>x;
  cout<< t/x <<endl;
}

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

#define io(F) string t_="";ifstream fin(t_+F+".in");ofstreamfout(t_+F+".out")
#define qio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define graph unordered_map<int, unordered_set<int>>
typedef long long ll;

int main() {
	qio; ll k; cin >> k;
	ll sm = 0;
	forl(i, 1, k+1) {
		forl(j, 1, k+1) {
			forl(z, 1, k+1) {
				sm += __gcd(i, __gcd(j, z));
			}
		}
	}
	println(sm);
}


Measured memory_bytes: 3624
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	map<char, string> encode;
	encode[' '] = "101";
	encode['\''] = "000000";
	encode[','] = "000011";
	encode['-'] = "10010001";
	encode['.'] = "010001";
	encode['?'] = "000001";
	encode['A'] = "100101";
	encode['B'] = "10011010";
	encode['C'] = "0101";
	encode['D'] = "0001";
	encode['E'] = "110";
	encode['F'] = "01001";
	encode['G'] = "10011011";
	encode['H'] = "010000";
	encode['I'] = "0111";
	encode['J'] = "10011000";
	encode['K'] = "0110";
	encode['L'] = "00100";
	encode['M'] = "10011001";
	encode['N'] = "10011110";
	encode['O'] = "00101";
	encode['P'] = "111";
	encode['Q'] = "10011111";
	encode['R'] = "1000";
	encode['S'] = "00110";
	encode['T'] = "00111";
	encode['U'] = "10011100";
	encode['V'] = "10011101";
	encode['W'] = "000010";
	encode['X'] = "10010010";
	encode['Y'] = "10010011";
	encode['Z'] = "10010000";
	const char* decode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

	string str;
	while(getline(cin, str)){
		string secret;
		rep(i, str.size()){
			secret += encode[str[i]];
		}
		if(secret.size()%5 != 0)
			secret += string(5-secret.size()%5, '0');

		string answer;
		for(int i=0; i<int(secret.size()); i+=5){
			int n = 0;
			rep(j, 5) n += (1 << (4-j)) * (secret[i+j] - '0');
			answer += decode[n];
		}
		puts(answer.c_str());
	}
	return 0;
}

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

using namespace std;

int main (){
	int n;
	cin >> n;
	int c = 0;
	for(int i = 3;i < 55555;i+=2){
		bool flag = 1;
		for(int j = 2;j <= sqrt(i);j++){
			if(i%j == 0)flag = 0;
		}
		if(flag == 0)continue;
		if(i%5 == 1){
			if(c != 0) cout << " ";
			cout << i;
			c++;
			if(c == n)break;
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int kk = sc.nextInt();
        
        List<Long> aList = new ArrayList<>();
        List<Long> bList = new ArrayList<>();
        List<Long> cList = new ArrayList<>();
        
        for(int i = 0; i < x; i++)
            aList.add(sc.nextLong());
        Collections.sort(aList, Collections. reverseOrder());
        
        for(int i = 0; i < y; i++)
            bList.add(sc.nextLong());
        Collections.sort(bList, Collections. reverseOrder());
            
        for(int i = 0; i < z; i++)
            cList.add(sc.nextLong());
        Collections.sort(cList, Collections. reverseOrder());

        PriorityQueue<Long> pq = new PriorityQueue<>();
        
        for(int i = 0; i < x; i++) {
            for(int j = 0; j < y; j++)
                for(int k = 0; k < z; k++) {
                    long sum = aList.get(i) + bList.get(j) + cList.get(k);
                    pq.offer(sum);
                    if(pq.size() > kk){
                        pq.poll();
                        if(sum <= pq.peek()) break;
                    }
                    
                }
        }
        List<Long> list = new ArrayList<>();
        while(!pq.isEmpty())
            list.add(pq.poll());
        for(int i = list.size() - 1; i >= 0; i--)
            System.out.println(list.get(i));
    }
}


Measured memory_bytes: 42664
a=int(input())
b=int(input())

if a == 1 and b == 2:
  print(3)
if a == 1 and b == 3:
  print(2)
if a == 2 and b == 3:
  print(1)
if a == 2 and b == 1:
  print(3)
if a == 3 and b == 2:
  print(1)
if a == 3 and b == 1:
  print(2)
  


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int 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;
}

int main() {
  int N;
  cin >> N;
  repp(i, 1, N) {
    if ((int)(i * 1.08) == N) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {

	string a, b;
	cin >> a >> b;
	if (a > b) cout << ">" << endl;
	else if (a < b) cout << "<" << endl;
	else cout << "=" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  bool ans = true;
  vector<int> nums(n);
  for (int i=0; i<n; ++i){
    cin >> nums[i];
  }

  sort(nums.begin(), nums.end());
  for (int i=0; i<n-1; ++i){
    if (nums[i] == nums[i+1]) {
      ans = false;
    }
  }
  if (ans) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

        while (sc.hasNextInt()) {
            int X = sc.nextInt();
            int A = sc.nextInt();
            int B = sc.nextInt();

            if (B - A <= 0) {
                System.out.println("delicious");
            } else if (B - A <= X) {
                System.out.println("safe");
            } else {
                System.out.println("dangerous");
            }
        }
    }
}


Measured memory_bytes: 21972
/**
*    author:  Dooloper
*    created: 13.04.2020 22:15:49
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
typedef unsigned long long ll;


ll count_num(char first, char second, char therd, int N,string S,vector<int> cnt){
   ll sum = 0;
   for(int i = 0; i < N; i++){
      if(S[i] == first){
         for(int j = i+1; j < N; j++){
            if(j+1 < N &&S[j] == second){
               sum += cnt[N-1] - cnt[j+1];
               if( 2*j -i < N &&S[2*j - i] == therd){
                  sum--;
               }
               if(j+1<N && S[j+1] == therd){
                  sum++;
               }
            }
         }
      }
   }
   // cout<<sum<<" ";
   return sum;
}

int main() {
   cin.tie(0);

   int N;cin>>N;
   string S;cin>>S;

   vector<int> cntR(N,0);
   vector<int> cntG(N,0);
   vector<int> cntB(N,0);

   char R = 'R';
   char G = 'G';
   char B = 'B';

   if(S[0] == R){
         cntR[0] = 1;
   }else if(S[0] == G){
         cntG[0] = 1;
   }else{
         cntB[0] = 1;
   }

   for(int i = 1; i < N; i++){
      if(S[i] == R){
         cntR[i] = 1;
      }else if(S[i] == G){
         cntG[i] = 1;
      }else{
         cntB[i] = 1;
      }
      cntR[i] += cntR[i-1];
      cntG[i] += cntG[i-1];
      cntB[i] += cntB[i-1];
   }

   ll sum = 0;

   // for(int i = 0;i<N;i++)
   //    cout<<cntG[i];

   sum += count_num(R,G,B,N,S,cntB);
   // cout<<sum<<endl;
   sum += count_num(R,B,G,N,S,cntG);
   // cout<<sum<<endl;
   sum += count_num(G,R,B,N,S,cntB);
   // cout<<sum<<endl;
   sum += count_num(G,B,R,N,S,cntR);
   // cout<<sum<<endl;
   sum += count_num(B,R,G,N,S,cntG);
   // cout<<sum<<endl;
   sum += count_num(B,G,R,N,S,cntR);
   // cout<<sum<<endl;

   cout<<sum<<endl;
   return 0;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n,k int
	fmt.Scan(&n,&k)
	
	h := make([]int, n)
	
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}
	//fmt.Println(h)
	sort.Sort(sort.Reverse(sort.IntSlice(h)))
	//fmt.Println(h)
	
	sum := 0;
	for i := k; i < n; i++ {
		sum += h[i]
	}
	fmt.Println(sum)

}

Measured memory_bytes: 6964
import bisect
A,B,Q = map(int, input().split())
S = [int(input()) for i in range(A)]
T = [int(input()) for i in range(B)]
S = sorted(S)
T = sorted(T)

for j in range(Q):
    x = int(input())
    a = S[bisect.bisect_left(S, x)-1]
    b = T[bisect.bisect_left(T, x)-1]
    if x <=S[-1]:
        a_ = S[bisect.bisect_right(S,x)]
    else:
        a_ = S[bisect.bisect_right(S,x)-1]
    if x <= T[-1]:
        b_ = T[bisect.bisect_right(T,x)]
    else:
        b_ = T[bisect.bisect_right(T,x)-1]
    y = min([abs(a-x)+abs(b-a),abs(a-x)+abs(b_-a),abs(a_-x)+abs(b-a_),abs(a_-x)+abs(b_-a_),
            abs(b-x)+abs(a-b),abs(b-x)+abs(a_-b), abs(b_-x)+abs(a-b_), abs(b_-x)+abs(b_-a_)])
    print(y)

Measured memory_bytes: 17756
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
string S, T;
signed main(){
  int x, a, b;
  cin >> x >> a >> b;
  if(abs(x-a)<abs(x-b)) cout << 'A' << endl;   
  else cout << 'B' << endl;
  return 0;
}

Measured memory_bytes: 3552
/*
 * ID: 3041
 * Problem: round and round
 */

#include <stdio.h>

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

    int index = 0, value;
    int i;
    for (i = 0; i < query; i++) {
        int command, k;
        scanf("%d %d", &command, &k);

        switch (command) {
            case 0:
                value = (index + k) % n;
                printf("%d\n", value ? value : n);
                break;
            case 1:
                index = (index + k) % n;
                break;
        }
    }

    return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
#define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

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

    ll a,b;
    cin>>a>>b;
    cout<<a*b;    
  
    return 0;
}


Measured memory_bytes: 3612
#![allow(non_snake_case)]

// Input
#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
#[allow(unused_imports)]
use std::cmp::{min,max};

// Main
fn main(){
    input!{
        n: usize,
        k: usize,
        d: [u64; k],
    }
    for i in n..100000{
        if i.to_string().chars().all(|x| !d.contains(&(x as u64 - 48))){
            println!("{}", i);
            return;
        }
    }
}


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

using namespace std;

const int MOD = 998244353;

void upd(int &x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;
}
int f[3010][3010][3][3];
int A,B,C,D;

int main() {
    scanf("%d%d%d%d",&A,&B,&C,&D);
    f[A][B][0][0] = 1;
    int ans = 0;
    for (int i=A;i<=C;i++) {
        for (int j=B;j<=D;j++) {
            for (int k=0;k<3;k++) {
                for (int l=0;l<3;l++) {
                    int nk, nl;
                    int v = f[i][j][k][l];
                    if (!v) continue;
                    //printf("f[%d][%d][%d][%d] = %d\n",i,j,k,l,v);
                    if (i == C && j == D) upd(ans, v);
                    // add i
                    upd(f[i+1][j][1][l], 1LL * v * (j - 1) % MOD);
                    upd(f[i+1][j][1][min(l+1,2)], v);

                    // add j
                    if (k != 1 || i == A) {
                        upd(f[i][j+1][k][1], 1LL * v * (i - 1) % MOD);
                    }
                    if (min(k+1,2) != 1 || i == A) {
                        upd(f[i][j+1][min(k+1,2)][1], v);
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
}

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

int n, m, cnt[100001];
bool ac[100001];
char ver[2];
int main() {
    scanf("%d%d", &n, &m);
    int d;
    int accepted = 0, p = 0;
    for (int i = 0; i <m; ++i) {
        scanf("%d %s", &d, ver);
        if (string(ver) == "AC") {
            if (!ac[d]) {
                accepted++;
                p += cnt[d];
                ac[d] = true;
            }
        } else if (!ac[d]) {
            cnt[d]++;
        }
    }
    printf("%d %d\n", accepted, p);
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  int cnt = 0, tmp = 1;
  for(int i=0; i<n; i++){
    if(a[i] == tmp) tmp++;
    else cnt++;
  }
  if(tmp == 1) cout << -1;
  else cout << cnt;
  cout << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        long h = sc.nextLong();

        // 処理
        long cnt = 1;
        long out = 0;
        while (h > 1) {
            out += cnt;
            h /= 2;
            cnt *= 2;
        }
        out += cnt;

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

// 二人でニムっぽいゲーム
// 山N個
// 各山A[i]個の石
// 山iから1<=a<=floor(X/K[i])個取れる
// A[i]=0, 1<=i<=N の状態で自分のターンになったら負け
// 1<=N<=200
// 1 <= A[i], K[i] <= 10^9
// Grundy数がわかればいい。
// g(x, k) : x個の山, k個取れるときのGrundy数
// k>xのとき
// g(x, k) = 0
// k=1, x>0 のとき
// g(x, k) = 1
// 1<=y<=x//k
// をすべて試すのは無理
// 実験すると規則が見つかる
// k ∣ n のとき
// g(n, k) = n/k
// k ∤ n のとき
// g(n, k) = g(n-floor(n/k)-1, k)
// kが大きいとき時間かかりそう
// floor(n, k) = a をi回引いて
// n-(a+1)*i <= k*a
// となればいい
// よって
// (n-ka)/(a+1) <= i
// 最小のi回a+1ずつ引く

int g(int n, int k) {
    if (n < k)RT 0;
    if (n%k == 0)RT n / k;
    int a = n / k;
    RT g(n - max(1, ((n - k*a) / (a + 1)))*(a + 1), k);
}

void test() {
    const int N = 100;
    const int K = 3;
    static int f[N];
    FOR(i, 1, N) {
        set<int> S;
        FOR(j, 1, i / K + 1) {
            S.insert(f[i-j]);
        }
        for (int j = 0; S.count(j);++j)f[i]++;
        // assert(i%K || f[i] == i / K);
        cout << f[i] << endl;
        assert(g(i, K) == f[i]);
    }
}

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

    // test();
    int nim = 0;
    int N;
    cin >> N;
    rep(i, N) {
        int a, k;
        cin >> a >> k;
        nim ^= g(a, k);
    }
    cout << (nim ? "Takahashi" : "Aoki") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

//#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int N,Q,par[100010],par2[100010],mark[100010],q[100010],first[100010];
char c[100010];

int f(int v){
    if(mark[v]) return v;
    return par2[v]=f(par[v]);
}

int main(){
	while(cin>>N>>Q && N){
        fill(mark,mark+N+1,0);
        fill(first,first+Q,0);
        mark[1]=1;
        
        rep2(i,2,N+1) cin>>par[i];
        
        rep(i,Q){
            cin>>c[i]>>q[i];
            if(c[i]=='M' && mark[q[i]]==0){
                first[i]=1;
                mark[q[i]]=1;
            }
        }
        
        rep2(i,1,N+1) par2[i]=f(i);
        
        ll ans=0;
        for(int i=Q-1;i>=0;i--){
            if(c[i]=='M'){
                if(first[i]){
                    mark[q[i]]=0;
                    par2[q[i]]=f(q[i]);
                }
            }else{
                ans+=f(q[i]);
            }
        }
        
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(){
int suma;
int a, b;
cin>>a>>b;
if(a==b){
    suma=a+b;
}else if(a>b){
    suma=a+a-1;
}else suma =b+b-1;
cout <<suma;
    return 0;
}

Measured memory_bytes: 3572
from collections import deque

H,W = map(int,input().split())
S = [input() for _ in range(H)]

A = [[-1 for _ in range(W)] for _ in range(H)]
A[0][0] = 1

dxdy = [(0,1),(0,-1),(1,0),(-1,0)]
queue = deque()
queue.append((0,0))

while queue:
    x,y = queue.popleft()

    if S[x][y] == "#":
        continue

    for dx,dy in dxdy:
        if 0 <= x+dx < H  and  0 <= y+dy < W:
            if S[x+dx][y+dy] == "." and A[x+dx][y+dy] == -1:
                A[x+dx][y+dy] = A[x][y] + 1
                queue.append((x+dx,y+dy))

cnt_white = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            cnt_white += 1

if A[H-1][W-1] == -1:
    print(-1)
else:
    print(cnt_white - A[H-1][W-1])

Measured memory_bytes: 3316
s = list(map(int, list(input())))

acc = [0]*(len(s)+1)
digit = 1

for i in reversed(range(0, len(s))):
    si = s[i] * digit % 2019
    acc[i] = (acc[i+1] + si) % 2019
    digit *= 10
    digit %= 2019

cnt = [0]*2019
ans = 0
for i in range(0, len(s)+1):
    ans += cnt[acc[i]]
    cnt[acc[i]] += 1

print(ans)

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

vector<int> keys;
vector<char> big;
vector<char> sml;

int main(){
	//make big and sml array
	for(int i = 0; i < 26; i++){
		big.push_back('Z' - i);
		sml.push_back('z' - i);
	}
	for(int i = 0; i < 26; i++){
		big.push_back('z' - i);
		sml.push_back('Z' - i);
	}
	for(int i = 0; i < 100; i++){
		big.push_back(big[i]);
		sml.push_back(sml[i]);
	}

while(1){//start

	//init
	keys.clear();

	int n;
	cin >> n;
	if(n == 0) break;
	for(int i = 0; i < n; i++){
		int temp;
		cin >> temp;
		keys.push_back(temp);
	}

	//extend keys
	for(int i = 0; i < 200; i++){
		int temp = keys[i];
		keys.push_back(temp);
	}

	string s;
	cin >> s;
	for(int i = 0; i < (int)s.size(); i++){
			char c;
			if(islower(s[i])){
				c = sml['z' - s[i] + keys[i]];
				cout << c;
			}

			else if(isupper(s[i])){
				c = big['Z' - s[i] + keys[i]];
				cout << c;
			}
	}
	cout << endl;

}//end

	return 0;
}



Measured memory_bytes: 3204
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		sc.fill(a);

		Arrays.sort(a);

		System.out.println(a[0] + a[1]);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

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

const int dh[] = {1, 0, -1, 0};
const int dw[] = {0, 1, 0, -1};

void dfs(int h, int w, vector<string>& s, vector<vector<bool>>& v) {
  v[h][w] = true;

  int size_h = s.size(), size_w = s.front().size();
  int cnt = 0, hh, ww;
  rep(k, 4) {
    int nh = h + dh[k], nw = w + dw[k];
    if ((nh < 0 || size_h <= nh || nw < 0 || size_w <= nw) || v[nh][nw])
      continue;
    if (s[nh][nw] == '#') {
      if (k < 2)
        ++cnt, hh = nh, ww = nw;
      else
        return;
    }
  }
  if (cnt == 1)
    dfs(hh, ww, s, v);
}

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  rep(i, h) cin >> s[i];

  string dummy = string(w - 1, '.');
  dummy.push_back('#');
  s.push_back(dummy);
  ++h;

  vector<vector<bool>> v(h, vector<bool>(w));
  dfs(0, 0, s, v);

  if (v[h - 1][w - 1])
    puts("Possible");
  else
    puts("Impossible");
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
d = deque()
move = deque()
memo = {0:0}
for i in range(N):
    tmp = 6**i
    if tmp > N:
        break
    else:
        move.append(tmp)
for i in range(N):
    tmp = 9**i
    if tmp > N:
        break
    else:
        move.append(tmp)

move.reverse()
d.append((0,0))
flag = True
while(flag):
    tmp = d.pop()
    for i in move:
        tmp2 = (tmp[0] + i,tmp[1] + 1)
        if tmp2[0] < N:
            if not tmp2[0] in memo:
                d.appendleft(tmp2)
                memo[tmp2[0]] = tmp2[1]
            elif tmp2[1] < memo[tmp2[0]]:
                d.appendleft((tmp2, tmp[1] + 1))
                memo[tmp2] = tmp[1] + 1
        elif tmp2[0] == N:
            print(tmp2[1])
            flag = False
            break

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


char str[100],*p,s[60][60];
int d[60][60];

int queue(int H,int W);

typedef struct{
  int xx;
  int yy;
} coordinate;

int main(void){
  int H,W,i,j,distance,count,ans;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  H=atoi(p);
  p=strtok(NULL," \n");
  W=atoi(p);
  
  for(i=0;i<H;i++){
    fgets(str,sizeof(str),stdin);
    p=strtok(str," \n");
    strcpy(s[i],p);
  }
  
  for(i=0,count=0;i<H;i++){
    for(j=0;j<W;j++){
      if(s[i][j]=='#'){
        count++;
      }
    }
  }
  distance=queue(H,W);
  if(distance==-1){
    printf("%d\n",distance);
    return 0;
  }
  ans=H*W-count-distance-1;
  printf("%d\n",ans);
  
  return 0; 
}

int queue(int H,int W){
  int top,bottom,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1},nx,ny,i,j,num=100000,x,y;
  coordinate q[100000];
  
  d[0][0]=0;
  top=0;bottom=0;
  q[0].xx=0,q[0].yy=0;
  
  while(top!=bottom-1){
    x=q[bottom].xx, y=q[bottom].yy,bottom=(bottom+1)%num;
    if(x==W-1 && y==H-1){
      break;
    }
    for(i=0;i<4;i++){
      nx=x+dx[i],ny=y+dy[i];
      if(nx>=0 && nx<W && ny>=0 && ny<H && s[ny][nx]=='.'){
        top=(top+1)%num;
        q[top].xx=nx,q[top].yy=ny;
        d[ny][nx]=d[y][x]+1;
        s[ny][nx]='$';
      }
    }
  }
  
  if(x!=W-1 && y!=H-1){;
    return -1;
    
  }
   
  return d[H-1][W-1];
  
}

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

typedef long long ll;

#define reg register 
#define rep(a,b,c) for(reg int a=b,a##end=c;a<=a##end;++a)
#define drep(a,b,c) for(reg int a=b,a##end=c;a>=a##end;--a)

char IO;
int rd(){
	int s=0,f=0;
	while(IO=getchar(),IO<'0'||IO>'9')if(IO=='-')f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(IO=getchar(),IO>='0'&&IO<='9');
	return f?-s:s;
}

const int N=200100;

int n;

struct node{
	int x,y;
	bool operator < (const node __) const{
		return y<__.y;
	}
}a[N];


int main(){
	n=rd();
	rep(i,1,n) a[i].x=rd(),a[i].y=rd();
	sort(a+1,a+n+1);
	ll now=0;
	for(int i=1;i<=n;i++){
		if((now+=a[i].x)>a[i].y) return puts("No"),0;
	}
	puts("Yes");
}







Measured memory_bytes: 1792
//#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n+1];
    for (int i=1;i<=n;i++)
    	cin>>a[i];
    int dp[n+1];
    
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
    {
    	dp[i]=min((abs(a[i]-a[i-1])+dp[i-1]),(abs(a[i]-a[i-2])+dp[i-2]));
    }
    cout<<dp[n];
	return 0;

}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define m(a,b) memset(a,b,sizeof a)
#define en '\n'
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int l=1,r=1,tmp=0;ll sum=0;
    while(r<=n)
    {
        while((a[r]^tmp)==(a[r]+tmp)&&r<=n)
            tmp^=a[r],r++;
        if(r!=n+1)
            sum+=r-l;
        else
            sum+=(ll)(r-l)*(ll)(r-l+1)/(ll)2;
        tmp^=a[l],l++;
    }
    printf("%lld\n",sum);
}

Measured memory_bytes: 1024
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> uft;

ll search(ll where){
    if(uft[where]==where){return where;}
    else{return uft[where]=search(uft[where]);}
}

void add(ll a,ll b){
    uft[search(a)]=search(b);
}


int main(){
    ll n;
    cin>>n;
    priority_queue<vector<ll>,vector<vector<ll>>,greater<vector<ll>>> E;
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            ll a;
            cin>>a;
            if(a!=-1){
                E.push({a,i,t});
            }
        }
    }
    uft.resize(n);
    for(int i=0;i<n;i++){
        uft[i]=i;
    }
    ll cost=0;
    while(!E.empty()){
        vector<ll> e=E.top();
        E.pop();
        if(search(e[1])!=search(e[2])){
            cost+=e[0];
            add(e[1],e[2]);
        }
    }
    cout<<cost<<endl;
    
    
    return 0;
}




Measured memory_bytes: 3376