akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int alen = a.length();
            String b = br.readLine();
            int blen = b.length();
            if (alen > blen) {
                System.out.println("GREATER");
            } else if (alen < blen) {
                System.out.println("LESS");
            } else {
                boolean breakFlag = false;
                for (int i = 0; i < alen; i++) {
                    int aNum = Integer.parseInt(a.substring(i, i + 1));
                    int bNum = Integer.parseInt(b.substring(i, i + 1));
                    if (aNum > bNum) {
                        System.out.println("GREATER");
                        breakFlag = true;
                        break;
                    } else if (aNum < bNum) {
                        System.out.println("LESS");
                        breakFlag = true;
                        break;
                    }
                }
                if (!breakFlag) {
                    System.out.println("EQUAL");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
  
  
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 110;
int a[maxN];
int b[maxN];

int n,m,X,Y;
int main()
{
	n = inp();
	m = inp();
	X = inp();
	Y = inp();
	for(int i=1;i<=n;i++)
	{
		a[i] = inp();
	}
	for(int i = 1;i<=m;i++)
	{
		b[i] = inp();
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);

	for(int i=X+1;i<=Y;i++)
	{
		if(i>a[n] && i<=b[1])
		{
			puts("No War");
			return 0;
		}
	}
	puts("War");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define LEN (100001)

void get_diff(int *diff_ab)
{
    int index = 1;
    while(1){
        const char ch = getchar();
        if(ch == 'A') {
            diff_ab[index] = diff_ab[index-1] + 1;
            index++;
        } else if (ch == 'B') {
            diff_ab[index] = diff_ab[index-1] - 1;;
            index++;
        } else {
            break;
        }
    }
}

int main(void)
{
    static int diff_ab_S[LEN] = {0};
    static int diff_ab_T[LEN] = {0};

    get_diff(diff_ab_S);
    get_diff(diff_ab_T);

    int q;
    scanf("%d",&q);

    for (int i = 0; i < q; i++){
        int a,b,c,d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        const int diff_diff_ab_S = diff_ab_S[b] - diff_ab_S[a - 1];
        const int diff_diff_ab_T = diff_ab_T[d] - diff_ab_T[c - 1];
        if((diff_diff_ab_S - diff_diff_ab_T) % 3 == 0) {
            puts("YES");
        } else {
            puts("NO");
        }
    }

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[n / 2] - a[n / 2 - 1] << endl;
}

Measured memory_bytes: 3760
s = input()

def isKaibun(s):
    l = int(len(s)/2)
    #print(l, s[0:l])
    f = True
    
    for i in range(l):
        #print(s[i], s[-(i+1)])
        if s[i] != s[-(i+1)]: f = False
    return f
    
def isStrongKaibun(s):
    #print(s)
    if len(s)==1:
        return True
    else:
        if isKaibun(s):
            return isKaibun(s[0:int(len(s)/2)])
        else:
            return False

print("Yes" if isStrongKaibun(s) else "No")

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


bool isok(string S) {
	int N = S.size();
	REP(i, N) {
		if (S[i] != S[N - i - 1])return false;
	}
	return true;
}
void solve() {
	string S; cin >> S;
	int N = S.size();
	if (isok(S) && isok(S.substr(0, N / 2)) && isok(S.substr(N / 2 + 1, N / 2)))print("Yes");
	else print("No");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



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

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
    int H;
    while (cin >> H) {
	if (H == 0) break;
	
	int b[10][5];
	rep(i, H) {
	    rep(j, 5) {
		cin >> b[i][j];
	    }
	}

	int ret = 0;
	bool change = true;
	while (change) {
	    change = false;
	    rep(y, H) {
		int pt = 0;
		REP(x, 1, 4) {
		    if (b[y][x] == b[y][pt]) continue;
		    if (x - pt >= 3 && b[y][pt] != 0) {
			change = true;
			REP(ax, pt, x - 1) {
			    ret += b[y][ax];
			    b[y][ax] = 0;
			}
		    }
		    pt = x;
		}
		if (5 - pt >= 3 && b[y][pt] != 0) {
		    change = true;
		    REP(ax, pt, 4) {
			ret += b[y][ax];
			b[y][ax] = 0;
		    }
		}
	    }
	    queue<int> q[5];
	    rep(x, 5) {
		for (int y = H - 1; y >= 0; y--) {
		    if (b[y][x] != 0) q[x].push(b[y][x]);
		}
		while (q[x].size() < H) q[x].push(0);
	    }
	    rep(x, 5) {
		for (int y = H - 1; y >= 0; y--) {
		    b[y][x] = q[x].front();
		    q[x].pop();
		}
	    }
	}
	cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 3036
#include<bits/stdc++.h>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define op operator
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
template<typename Q>
void inin(Q &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x=f?-x:x;
}
string s;
int n,l;
const double pi=acos(-1);
string wocao()
{
	cin>>s;
	inin(n),inin(l);
	double an;
	an=pi*(n+240.)/180.;
	long double x=l*cos(an),y=l*sin(an);
	int sumy=0;
	while(y<0)y+=sqrt(3)/2,sumy++;
	sumy--;
	string temp1="A",temp2=s,temp;
	if(s=="CD")temp="BA";
	else if(s=="BC")temp="DA";
	else if(s=="DB")temp="CA";
	temp1=temp1+temp+temp,temp2=temp2+s+s;
	if(sumy&1)swap(temp1,temp2);
	
    long double nima,tt;
	nima=x-y/sqrt(3)+(long double)(sumy+1)/2;
    tt=(y*2)/sqrt(3);
    int bo=-1;
    while(nima>2)nima-=2;
    if(nima>(long double)1.-tt)
    {
    	nima-=(long double)1.-tt;
    	if(nima>tt)nima-=tt; 
		else bo=1;
    }
    else bo=0;
    if(bo==-1)
    {
    	if(nima>(long double)1.-tt)
		{
			nima-=(long double)1.-tt;
			if(nima>tt)nima-=tt;
			else bo=3;
		}
		else bo=2;
    }
    string ret="";
    int bb=bo/2;
	if(bo&1)swap(temp1,temp2);
    ret+=temp2[bb],ret+=temp2[bb+1]; 
	if(bo&1)ret+=temp1[bb+1];
	else ret+=temp1[bb];
//    cout<<bo<<"\n";
    sort(ret.begin(),ret.end());
    return ret;
}
int main()
{
	string ans1,ans2;
	ans1=wocao(),ans2=wocao();
//	cout<<ans1<<" "<<ans2<<"\n";
	if(ans1==ans2)cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}



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

ll solve() {
    ll N, Q, t, a;
    cin >> N >> Q;
    atcoder::fenwick_tree<ll> ft(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        ft.add(i, a);
    }
    vector<ll> ans;
    for ( int q = 0; q < Q; q++ ) {
        cin >> t;
        if ( t == 0 ) {
            ll p, x;
            cin >> p >> x;
            ft.add(p,x);
        } else {
            ll l, r;
            cin >> l >> r;
            ans.push_back(ft.sum(l,r));
        }
    }
    for ( auto a : ans ) {
        cout << a << "\n";
    }
    return 0;
}

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

Measured memory_bytes: 10288
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
 
int a[1002][1002];
int dp[1002][1002];
int main(){
    int h, w, n;
    while(1){
    	//scanf("%d%d%d", &h, &w, &n);
    	cin >> h >> w >> n;
    	if(!h)break;
    	fill((int*)a, (int*)(a+1002), 0);
    	fill((int*)dp, (int*)(dp+1002), 0);
    	for(int i = 1;i <= h;i++)
    	for(int j = 1;j <= w;j++)cin >> a[i][j];
    	n--;dp[1][1] = n;
    	for(int i = 1;i <= h;i++){
       		for(int j = 1;j <= w;j++){
            	dp[i][j] += dp[i][j-1]/2;
            	if(a[i][j-1] == 1)dp[i][j] += dp[i][j-1]%2;
            	dp[i][j] += dp[i-1][j]/2;
            	if(a[i-1][j] == 0)dp[i][j] += dp[i-1][j]%2;
        	}
    	}
     	
    	int y = 1, x = 1, t, f;
    	while(y <= h && x <= w){
        	f = a[y][x];
        	if(dp[y][x]%2)f = !f;
        	if(f == 0)y++;
        	else x++;
   		}
    	//printf("%d %d\n", y, x);
    	cout << y << " " << x << endl;
    }
    return 0;
}

Measured memory_bytes: 10896
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
int n;
int d1[101],d2[101];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	bool f=false;
	rep(i,n){
		cin>>d1[i]>>d2[i];
	}
	rep(i,n-2){
		if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2])
		f=true;
	}
	if(f)
	cout<<"Yes";
	else
	cout<<"No";
	re 0;
}


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

int main()
{
    int h, w;
    cin>>h>>w;
    
    char a[h][w];
    for (int i = 0; i<h; i++)
        for (int j = 0; j<w; j++)
            cin>>a[i][j];
            
    int dp[h][w];
    bool flag = true;
    for (int i = 0; i<h; i++)
    {
        if (a[i][0]=='.' && flag)
            dp[i][0] = 1;
        else
        {
            dp[i][0] = 0;
            flag = false;
        }
    }
    flag = true;
    for (int j = 0; j<w; j++)
    {
        if (a[0][j]=='.' && flag)
            dp[0][j] = 1;
        else
        {
            dp[0][j] = 0;
            flag = false;
        }
    }
    
    for (int i = 1; i<h; i++)
    {
        for (int j = 1; j<w; j++)
        {
            if (a[i][j]=='.')
            {
                dp[i][j] = dp[i-1][j]+dp[i][j-1];
                dp[i][j] = dp[i][j]%1000000007;
            }
            else
                dp[i][j] = 0;
        }
    }
    cout<<dp[h-1][w-1];
    
    return 0;
}


Measured memory_bytes: 5120
X, K, D = map(int,input().split())

if X == 0:
    if (K % 2 == 0):
        print(0)
    else:
        print(D)

    exit()

if X > 0:
    if X % D == 0:
        a = X // D
    else:
        a = X // D + 1

    if a > K:
        print(abs(X-K*D))
        exit()
    
    if K % 2 == 0:
        if a % 2 == 0:
            print(abs(X-a*D))
        else:
            print(abs(X-a*D+D))
    else:
        if a % 2 == 0:
            print(abs(X-a*D+D))
        else:
            print(abs(X-a*D))
        exit()

if X < 0:
    if X % D == 0:
        a = -1 * X // D
    else:
        a = -1 * X // D + 1

    if a > K:
        print(abs(X+K*D))
        exit()
    
    if K % 2 == 0:
        if a % 2 == 0:
            print(abs(X+a*D))
        else:
            print(abs(X+a*D-D))
    else:
        if a % 2 == 0:
            print(abs(X+a*D-D))
        else:
            print(abs(X+a*D))
        exit()

Measured memory_bytes: 9268
N,M = map(int,input().split())
a,b = list(),list()
res = list()
for i in range(N):
  t = input().split()
  a.append(int(t[0]))
  b.append(int(t[1]))
  res.append([0,0])
for n in range(M):
  c,d = map(int,input().split())
  for i in range(N):
    if n == 0:
      res[i][0] = abs(a[i]-c) + abs(b[i]-d) 
    elif res[i][0] > abs(a[i]-c) + abs(b[i]-d):
      res[i][0] = abs(a[i]-c) + abs(b[i]-d)
      res[i][1] = n
for m in range(N):
  print(res[m][1] + 1)

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

int main(){
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;
  return 0;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
s = sorted(list(map(int,input().split())))
cnt = 0
for i in range(len(s)):
    if(x - s[i] >= 0 ):
        if(x < s[i] or (i == len(s)-1 and x != s[i])):
            break
        else:
            cnt += 1
        x = x-s[i]
print(cnt)

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


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  srand((unsigned)time(NULL));
  int d;
  int res = 0;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin >> c[i];
  vector<vector<int>> v(d,vector<int>(26));
  vector<int> contest(d,0);
  vector<int> last(26,0);
  vector<int> satisfy(26,0);
  rep(i,d)rep(j,26){
    int x;cin >> x;
    v[i][j] = x;
  }
  {
    int j = d;
    for(int i = 0;j;i++){
      contest[j-1] = (i%26);
      j--;
    }
  }
  for(int i = 1;i <= d;i++){
    //rep(j,26)if(v[i-1][contest[i-1]] < v[i-1][j])contest[i-1] = j;
    last[contest[i-1]] = i;
    res += v[i-1][contest[i-1]];
    rep(j,26)res -= c[j]*(i-last[j]),satisfy[j] += c[j]*(i-last[j]);
  }
  while(1.0*clock()/CLOCKS_PER_SEC <= 1.7){
    //int now_time = clock();
    //if(1.0*now_time/CLOCKS_PER_SEC > 1.7)break;
    int day = rand()%d,pos = rand()%26;
    vector<int> new_contest = contest;
    int res_ = res;
    int pre = new_contest[day];
    res_ += satisfy[pos];
    res_ += satisfy[pre];
    res_ -= v[day][pre];
    res_ += v[day][pos];
    int pos_satisfy = 0,pre_satisfy = 0;
    last[pos] = last[pre] = 0;
    new_contest[day] = pos;
    for(int i = 1;i <= d;i++)last[pos] = (new_contest[i-1] == pos ? last[pos] = i : last[pos]),pos_satisfy += c[pos]*(i-last[pos]);
    for(int i = 1;i <= d;i++)last[pre] = (new_contest[i-1] == pre ? last[pre] = i : last[pre]),pre_satisfy += c[pre]*(i-last[pre]);
    res_ -= (pos_satisfy+pre_satisfy);
    if(res < res_){
      res = res_;
      contest = new_contest;
      satisfy[pre] = pre_satisfy;
      satisfy[pos] = pos_satisfy;
    }
  }
  rep(i,d)cout << contest[i]+1 << endl;
  


  return 0;
}


Measured memory_bytes: 3708
#include <stdio.h>

int main(void)
{
	long num[10000], sum, max;
	int n, i, j, k;
	
	while (scanf("%d", &n), n != 0){
		sum = 0;
		max = -1000000;
		for (i = 0; i < n; i++)scanf("%ld", &num[i]);
		for (i = 0; i < n; i++){
			sum = 0;
			for (j = i; j < n; j++){
				sum += num[j];
				if (max < sum)max = sum;
			}
		}
		
		printf("%ld\n", max);
	}
	
	return (0);
}

Measured memory_bytes: 628
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
typedef long long ll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

//aとbのうち小さい値をaとして採用する
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false;}

int main(){
    int N_MAX = 1000000;
    int n; cin>>n;

    set<int> money;
    money.insert(1);
    int six= 6;
    while(six<=n){
        money.insert(six);
        six*=6;
    }
    int nine = 9;
    while(nine<=n){
        money.insert(nine);
        nine*=9;
    }

    vector<int> dp(N_MAX,inf);
    dp[0] = 0;
    rep(i,n){
        for(auto x:money){
            chmin(dp[i+x], dp[i]+1);
        }
    }

    cout<<dp[n]<<endl;return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,s=0,i,v[20],c[20];
	
cin>>n;
for(i=0;i<n;i++){
	cin>>v[i];
}
for(i=0;i<n;i++){

cin>>c[i];
	if(v[i]>c[i]) s+=v[i]-c[i];}
cout<<s;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	scanf("%lld",&n);
	ll flag=0;
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		flag^=t%2;
	}
	puts(flag?"NO":"YES");
}

Measured memory_bytes: 128
//ALDS1-1-A: Insertion Sort
//2019.05.24

#include <stdio.h>

int main(void){
  int n;
  scanf("%d\n", &n);
  int data[n];


  for (int i = 0; i < n; i++) scanf("%d\n", &data[i]);

  for (int k = 0; k < n; k++) {
    printf("%d", data[k]);
    if (k == n-1) {
      printf("\n");
    }else{
      printf(" ");
    }
  }

  int tmp;
  for (int i = 1; i < n; i++) {
    tmp = data[i];
    int j = i - 1;
    while(data[j] > tmp && j >= 0){
      data[j+1] = data[j];
      j--;
      data[j+1] = tmp;
    }
    for (int k = 0; k < n; k++) {
      printf("%d", data[k]);
      if (k == n-1) {
        printf("\n");
      }else{
        printf(" ");
      }
    }

  }

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll a(n);
  ll X=0;
  rep(i,n){
    cin>>a[i];
    X+=a[i];
  }
  ll ans=INF;
  ll x=0;
  for(int i=0;i<n-1;i++){
    x+=a[i];
    ans=min(ans,abs(X-2*x));
  }
  COUT(ans);
  
}


Measured memory_bytes: 1792
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let a: Vec<i64> = read_vec();
    let mut count_negative = 0i64;
    for i in 0..n {
        if a[i] < 0 {
            count_negative += 1;
        }
    }

    let mut ans = a.iter().map(|&x| x.abs()).sum::<i64>();
    if count_negative % 2 == 1 {
        ans -= 2 * a.iter().map(|&x| x.abs()).min().unwrap();
    }
    println!("{0}", ans);
}


Measured memory_bytes: 8444
#include <iostream>
#include <string>
#include <algorithm>
int main(){
    int N,M;
    std::cin >>N>>M;
    int* A=new int[M];
    int* B=new int[M];
    int* H=new int[N];
    int* t=new int[N]; //灯台の変数
    //入力処理
    for(int i=0;i<N;i++){
        std::cin>>H[i];
        t[i]=1;
    }
    for(int i=0;i<M;i++){
        std::cin>>A[i]>>B[i];
    }
    //計算
    for(int i=0;i<M;i++){ //M本の道について調べる
        if(H[A[i]-1]>H[B[i]-1]){
            t[B[i]-1]=0;
        }else if(H[A[i]-1]<H[B[i]-1]){
            t[A[i]-1]=0;
        }else{
            t[A[i]-1]=0;
            t[B[i]-1]=0; 
        }
    }
    int sum=0;
    for(int i=0;i<N;i++){
        sum=sum+t[i];
    }
    std::cout<<sum;
    //計算
    delete[] A;
    delete[] B;
    delete[] H;
    delete[] t;
    return 0;
}

Measured memory_bytes: 4780
N, T = map(int,input().split())
ab_list = []
for _ in range(N):
    a, b = map(int,input().split())
    ab_list.append((a,b))

ab_list.sort(key=lambda x: x[0])
    
dp = [[0 for _ in range(T+1+3000)] for _ in range(N+1)]

for i in range(N):
    a, b = ab_list[i]
    for j in range(T+1):
        if j-a >= 0:
            dp[i+1][j] = max(dp[i][j-a] + b, dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
    for k in range(T+1,T+1+3000):
        # T-1分までなら最後の一品注文可能
        if k-a >= 0 and k-a <= T-1:
            dp[i+1][k] = max(dp[i][k-a] + b, dp[i][k])
        else: 
            dp[i+1][k] = dp[i][k]
            
print(max(dp[-1]))

Measured memory_bytes: 180356
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000
#define ll long long
using namespace std;
int main()
{
    int a, b;
    int c[3] = {3, 2, 1};
    cin >> a >> b;
    int ans = 0;
    if (a < 4)
        ans += c[a - 1];
    if (b < 4)
        ans += c[b - 1];
    if (a == 1 && b == 1)
        ans += 4;
    cout << ans * 100000 << "\n";
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int k = stdin.nextInt();
        int[] d = new int[k];
        for (int i = 0; i < k; i++) d[i] = stdin.nextInt();
        
        while (true) {
            int x = n;
            Set<Integer> digits = new HashSet<>();
            while (x > 0) {
                digits.add(x % 10);
                x /= 10;
            }
            
            if (Arrays.stream(d).noneMatch(digits::contains)) {
                System.out.println(n);
                System.exit(0);
            }
            
            n++;
        }
    }

}

Measured memory_bytes: 45396
#include<bits/stdc++.h>
#include <sys/stat.h>
using namespace std;
using ll = int64_t;

int main(int , char **)
{
#ifdef LOCAL_DEBUG
	struct stat sb;
	ifstream in("/dev/shm/input.txt");
	if (stat("/dev/shm/input.txt",&sb)==0){ cin.rdbuf(in.rdbuf()); }
#endif

	int N;
	cin >> N;
	vector<int> D(N);
	for(int i=0;i<N;i++){
		cin >> D[i];
	}

	int M;
	cin >> M;
	vector<int> T(M);
	for(int i=0;i<M;i++){
		cin >> T[i];
	}

	stable_sort(D.begin(),D.end());
	stable_sort(T.begin(),T.end());

	int DSize = D.size();
	int TSize = T.size();
	int t=0;
	for(int d=0;d<DSize;d++){
		if (D[d]==T[t]){
			t++;
			if(TSize <= t){printf("YES\n");return 0;}
		}
	}
	printf("NO\n");
	return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  string s1, s2;
  cin >> s1 >> s2;

  ll cur = 0;
  ll ans = 1;
  while(cur < n){
    if(cur == 0){
      if(s1[cur] == s2[cur])
        ans *= 3;
      else
        ans *= 3*2;
    }
    else{

      if(s1[cur-1] == s2[cur-1]){
        if(s1[cur] == s2[cur])
          ans *= 2;
        else
          ans *= 2;

      }
      else{
        if(s1[cur] == s2[cur])
          ans *= 1;
        else
          ans *= 3;

      }
    }

    if(s1[cur] == s2[cur])
      cur++;
    else
      cur+=2;

    ans %= MOD;
  }

  cout << ans << endl;
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")

typedef long long ll;
typedef unsigned long long ull;
// typedef __int128_t lll;
#define fatnet ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll MOD1 = 1e9 + 7;
const ll MOD2 = 2000003983; // 3571 1e9 + 97
const ll MOD3 = 1e9 + 9;
const ll p1 = 1e6 + 3;
const ll p2 = 2017; // 131 37
const ll p3 = 37;
const ll INF = 5e18;

int main() {
    fatnet;

    ll n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << "\n";

    return 0;
}


Measured memory_bytes: 256
/*
      author : nishi5451
      created: 12.08.2020 14:54:46
*/

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


int main(){
    int k;
    cin >> k;
    vector<int> a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k-1] << endl;
    return 0;
}   

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

ll xo[201010],sm[201010];

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    rep(i,n) xo[i]=sm[i]=a[i];
    for(int i=1;i<n;i++) xo[i]^=xo[i-1];
    for(int i=1;i<n;i++) sm[i]+=sm[i-1];
    
    ll ans=0;
    rep(l,n){
        int ok=l,ng=n;
        while(ok+1!=ng){
            int md=(ok+ng)/2;

            ll x=xo[md];
            if(l) x^=xo[l-1];

            ll s=sm[md];
            if(l) s-=sm[l-1];

            if(x==s) ok=md;
            else ng=md;
        }

        ans+=ok-l+1;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4096
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <sstream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

const int MAX_N=50100;
int p[(MAX_N+1)/2];
bool isp[MAX_N+1];

int gen_ps(){
    memset(isp,1,sizeof(isp));
    isp[0]=isp[1]=false;
    int idx=0;
    loop(i,2,MAX_N+1){
        if(!isp[i]) continue;
        p[idx++]=i;
        for(int j=i+i; j<=MAX_N; j+=i){
            isp[j]=false;
        }
    }
    return idx;
}

int main(){
    int n;
    int len = gen_ps();
    while(cin>>n){
        int ub=*upper_bound(p,p+len,n);
        int lb=*(lower_bound(p,p+len,n)-1);
        cout << lb << " " << ub << endl;
    }
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
#define INF 1<<30

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int ans = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                cerr << i * 500 + j * 100 + k * 50 << endl;
                if (i * 500 + j * 100 + k * 50 == x) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import fractions
from functools import reduce

N = int(input())
a_list = list(map(int, input().split()))

m1 = [0] * (N + 1)
m2 = [0] * (N + 1)
for i in range(1, N + 1):
  m1[i] = fractions.gcd(m1[i - 1], a_list[i - 1])
  m2[N - i] = fractions.gcd(m2[N - i + 1], a_list[N - i])

m = [0] * N
for i in range(N):
  m[i] = fractions.gcd(m1[i], m2[i + 1])

print(max(m))


Measured memory_bytes: 16144
#include<iostream>
#include<vector>
#include<set>
#include<string>

using namespace std;

int n,m;
vector<int> came;
string str[11];
set<string> ans;

void serch(int loop,string sans)
{
//	cout << "loop:" << loop << endl;
	if(loop==m)
	{
//		cout << "came:" ;
//		for(int i=0;i<came.size();i++)
//			cout <<  came[i] << " " ;
//		cout << endl;
//		cout << sans << endl;;
		ans.insert(sans);
		return ;
	}
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<came.size();j++)
		{
//				cout << "j:" << j << " now:" << came[j] << " size:" << came.size() << " " << i << endl;
			if(i==came[j])
			{
				i++;
				j=-1;
			}
		}
		if(i==n)
			break;
//		cout << "next:" << i << endl;
		came.push_back(i);
		serch(loop+1,sans+str[i]);
		came.pop_back();
	}
	return ;
}

int main()
{
	int i,j;
	for(;;)
	{
		cin >> n >> m ;
		if(n==0 && m==0)
			break;
		
		ans.clear();
		
		for(i=0;i<n;i++)
			cin >> str[i] ;
		
		serch(0,"");
		
		cout << ans.size() << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> A >> B >> C >> D;
	cout << min(A, B) + min(C, D);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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

const int MOD = INF+7;
ll dp[105][10];
int main(){
    int h,w,k;cin>>h>>w>>k;
    k--;
    dp[0][0] = 1;
    rep(i,h){
        for(int bit = 0;bit < (1<<w-1);bit++){
            vector<int>S = bitSearch(bit,w-1);
            const int len = S.size();
            bool flag = true;
            rep(l,len-1){
                if(S[l+1] == S[l]+1)flag = false;
            }
            if(!flag)continue;
            if(S.empty()){
                rep(jj,w){
                    dp[i+1][jj] = (dp[i+1][jj]+dp[i][jj])%MOD;
                    //dp[i+1][j] %= MOD;
                }
            }
            else {
                rep(j,w){
                  S.push_back(INF);
                    if(j == *lower_bound(ALL(S),j)){                
                        dp[i+1][j+1] = (dp[i+1][j+1]+dp[i][j])%MOD;
                        dp[i+1][j] = (dp[i+1][j]+dp[i][j+1])%MOD;
                        j++;
                        if(j >= w)continue;
                    }
                    else{
                        dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
                        //dp[i+1][j] %= MOD;
                    }
                }
            }
        }
    }
    //rep(i,h+1){rep(j,w)cout<<dp[i][j]<<" ";cout<<endl;}
    cout<<dp[h][k]<<endl;;
}

Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		int[] A = new int[3];
		for (int i = 0; i < 3; ++i) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		System.out.println(A[2]-A[0]);
		pw.close();
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		int nextInt() {
			return (int) nextLong();
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S,T; cin>>S>>T;
    cout<< T+S <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

class Dice:

    def __init__(self, diceList):
        self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList

    def diceRoll(self, r):
        if(r == 'N'):
            self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5

        elif(r == 'E'):
            self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3

        elif(r == 'W'):
            self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4

        elif(r == 'S'):
            self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2


def main():

    inputDiceList = list(map(int, input().split()))
    rollList = list(input())

    d = Dice(inputDiceList)

    for i in rollList:
        d.diceRoll(i)

    print(d.d1)

if __name__ == '__main__':
    main()

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

int main() {
  int n;
  bool ad = true;
  string ans = "APPROVED";
  cin >> n;
  vector<int> num(n);
  for (int i = 0; i < n; i++) {
    cin >> num.at(i);
  }
  for (int i = 0; i < n; i++) {
    if (num.at(i) % 2 == 0) {
      if (num.at(i) % 3 == 0 || num.at(i) % 5 == 0) {
        ans = "APPROVED";
      }
      else {
        ans = "DENIED";
        ad = false;
      }
    }
    if (ad == false) {
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,t,a,b,f=1;
int jl(int x,int y)
{
	return x+y;
}
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>t>>a>>b;
		if(t<jl(a,b))
		  f=0;
		if(((a+b)%2==1&&t%2==0)||(a+b)%2==0&&t%2==1)
		  f=0;
	}
	if(!f)
	  cout<<"No"<<'\n';
	else
	  cout<<"Yes"<<'\n';
	return 0; 
}

Measured memory_bytes: 256
s = input()
def calc(s):
  ans = 0
  l = 0
  r = len(s)-1
  for i in range(len(s)):
    if l >= r:
      return ans
    if s[l] == s[r]:
      l += 1
      r -= 1
    elif s[l]=='x' and s[r]!='x':
      l += 1
      ans += 1
    elif s[l]!='x' and s[r]=='x':
      r -= 1
      ans += 1
    else:
      return -1
  return ans

a = calc(s)
print(a)

Measured memory_bytes: 3316
// 17:15
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <tuple>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll (i)=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll (i)=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)
#define STRING(str) #str
#define DEBUG 0
#if DEBUG
    #define dump(var) dump2(STRING(var), var)
#else
    #define dump(var)
#endif

void dump2(const string& name, const ll& value)
{
    cerr << name << ": " << value << endl;
}
void dump2(const string& name, const string& value)
{
    cerr << name << ": " << value << endl;
}
void dump2(const string& name, const tuple<ll,ll,ll>& value)
{
    ll a,b,c;
    tie(a,b,c) = value;
    cerr << name << ": " << a << ", " << b << ", " << c << endl;
}

void solve()
{
    string S;
    cin >> S;
    vector<bool> exist(26, false);
    for (char c : S) {
        exist[c - 'a'] = true;
    }
    if (S.length() < 26) {
        cout << S;
        for1(i,26) {
            if (!exist[i]) {
                string a{(char)('a'+i)};
                cout << a << endl;
                return;
            }
        }
    }
    if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return;
    }
    while (true) {
        char last = S.back();
        last -= 'a';
        S = S.substr(0, S.length() - 1);
        dump(S);
        exist[last] = false;
        for2(i,last+1,26) {
            if (!exist[i]) {
                string a{(char)('a'+i)};
                cout << S << a << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A,B;
  cin>>A>>B;
  long long ans = 3000;
  if((B-A) >= 2029){
    cout << 0 << endl;
  }
  else{
    for(long long i = A;i<B;i++){
      for(long long k = i+1;k<=B;k++){
        ans = min(ans,(i*k%2019));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    set<ll> s;
    for (ll i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        s.insert(temp);
    }
    if (s.size() == n)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 9600
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt() , point =sc.nextInt();
		int[] x=new int[n];
		int hat = 0;
		for(int i=0;i<n;i++){
			int a=sc.nextInt(),b=sc.nextInt();
			if(a>hat)
				hat = a;
			x[i] = b;
		}
		Arrays.sort(x);
		int sum = 0;
		for(int i=n-1;i>=0;i--){
			if(point<=0||x[i]<hat)
				break;
			else if(x[i]>hat){
				sum++;
				point-=x[i];
			}
		}
		if(point>0){
			sum+=Math.ceil((double)point/(double)hat);
		}
		System.out.print(sum);
	}
}


Measured memory_bytes: 64804
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int T,N,K,X[1000000+10],A[1000000+10];
int main(){
    cin>>T;
    for(int t=0;t<T;++t){
        int sum=0;
        cin>>N>>K;
        for(int i=0;i<N;++i){cin>>X[i];}
        for(int i=0;i<N-1;++i){A[i]=X[i+1]-X[i];}
        sort(A,A+N-1);
        for (int j=0;j<N-K;++j){sum=sum+A[j];}
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
// int facctorialMethod(int k){
//     int sum = 1;
//     for (int i = 1; i <= k; ++i)
//     {
//         sum *= i;
//     }
//     return sum;
// }
int main(){
    double N;
    cin >> N;
    // vector<string> vec(N);
    // for(int i=0;i<N;i++){
    //     cin >> vec.at(i);
    // }
    // vector<int> c(N);
    // sort(vec.begin(),vec.end());
    // string tmp = vec.at(0);
    // for(int i=1;i<N;i++){
    //     if(vec.at(i)==tmp){
    //         tmp = vec.at(i)
    //         c(i)
    //     }
    // }
    cout << 2.00000*N*M_PI << endl;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int a1, a2, a3;

int main()
{
	cin >> a1 >> a2 >> a3;	
	int ans = a1 + a2 + a3;
	if(ans >= 22) cout << "bust" << endl;
	else cout << "win" << endl;
}

Measured memory_bytes: 256
N = int(input())
x,y,h = [0]*N,[0]*N,[0]*N

j = -1
for i in range(N):
    x[i],y[i],h[i] = map(int,input().split(" "))
    if h[i] !=  0:
        j = i 
        
H = 1
if j == (-1):
    for cx in range(0,101):
        for cy in range(0,101):
            for i in range(N):
                H = min(H,(abs(x[i]-cx) + abs(y[i]-cy)))

            if H > 0:
                print("{0} {1} {2}".format(cx,cy,H))
                exit(0)

for cx in range(0,101):
    for cy in range(0,101):
        H = h[j] + abs(x[j]-cx) + abs(y[j]-cy)
        flg = True
        for i in range(N):
            if (h[i] == 0 and ((abs(x[i]-cx) + abs(y[i]-cy))) < H):
                flg = False
                break
            if (h[i] != 0 and H != (h[i] + abs(x[i]-cx) + abs(y[i]-cy))):
                flg = False
                break
        if flg:
            print("{0} {1} {2}".format(cx,cy,H))
            exit(0)


Measured memory_bytes: 43248