akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=4e18;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
//debug
#ifdef grief
#define IOS
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//}}}
string s;
int cnt[300],las[300],arr[200010],sz;
int ans[200010];
inline int low(int x){return x&-x;}
void mdy (int x,int d){
	while(x<=sz){
		ans[x]+=d;
		x+=low(x);
	}
}
int que(int x){
	int r=0;
	while(x){
		r+=ans[x];
		x-=low(x);
	}
	return r;
}
int main(){
	IOS
	cin>>s;
	if(SZ(s)==1){
		cout<<"0\n";
		return 0;
	}
	for(char c:s){
		cnt[c]++;
	}
	int cc=0;
	for(int i='a';i<='z';i++){
		if(cnt[i]%2)	cc++;
	}
	if(cc>1){
		cout<<"-1\n";
		return 0;
	}
	for(int i='a';i<='z';i++){
		las[i]=cnt[i]/2;
	}
	ll out=0,p=0,p2=SZ(s)/2;
	for(int i=0;i<SZ(s);i++){
		if(las[s[i]]){
			ans[p]=s[i];
			out+=i-p;
			p++;
			las[s[i]]--;
		}
		else{
			ans[p2]=s[i];
			p2++;
		}
	}
	assert(p==SZ(s)/2);
	assert(p2==SZ(s));
	int x=0;
	for(int i='a';i<='z';i++){
		if(cnt[i]%2){
			x=i;
			break;
		}
	}
	if(x){
		if(ans[SZ(s)/2]!=x){
			p=0;
			for(int i=SZ(s)/2+1;i<SZ(s);i++){
				if(ans[i]==x){
					p=i;
					break;
				}
			}
			assert(p);
			while(p>SZ(s)/2){
				swap(ans[p],ans[p-1]);
				out++;
				p--;
			}
		}
		assert(ans[SZ(s)/2]==x);
	}
	debug(out);
//	for(int i=0;i<SZ(s);i++){
//		cout<<ans[i]<< ' ';
//	}
//	cout<< '\n';
	
	vector<int> vec[300];
	for(int i=0;i<SZ(s)/2;i++)	vec[ans[i]].eb(i);
//	for(int i='a';i<='z';i++){
//		if(SZ(vec[i])){
//			debug((char)i);
//			for(int j:vec[i])
//				cout<<j<< ' ';
//			cout<< '\n';
//		}
//	}
	sz=SZ(s)/2;
	x=SZ(s)-sz;
	for(int i=0;i<sz;i++){
		assert(SZ(vec[ans[i+x]]));
		arr[i]=vec[ans[i+x]].back()+1;
		vec[ans[i+x]].pop_back();
	}
//	for(int i=0;i<sz;i++){
//		cout<<arr[i]<< ' ';
//	}
//	cout<< '\n';
	memset(ans,0,sizeof ans);
	for(int i=0;i<sz;i++){
		out+=que(arr[i]);
		mdy(arr[i],1);
	}
	cout<<out<< '\n';
	return 0;
}

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

int main() {

int a,ans=0;
cin >> a ;

ans+=(a/500)*1000;
a= a%500;
ans+= (a/5)*5;

cout << ans << endl;



}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

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

    long long N, K;
    cin >> N >> K;

    long long ans = 0;
    for(long long k = K; k <= N + 1; k++){
        long long a = k * (k - 1) / 2;
        long long b = (2 * N - k + 1) * k / 2;
        long long add = b - a + 1;
        ans = (ans + add) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

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

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

        int[][] student = new int[50][2];
        int[][] point = new int[50][2];

        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            student[i][0] = a;
            student[i][1] = b;
        }

        for (int i = 0; i < m; i++) {
            int c = sc.nextInt();
            int d = sc.nextInt();
            point[i][0] = c;
            point[i][1] = d;
        }

        sc.close();

        for (int i = 0; i < n; i++) {
            int min = Math.abs(student[i][0] - point[0][0]) + Math.abs(student[i][1] - point[0][1]);
            int check = 1;
            for (int j = 0; j < m; j++) {
                int dist = Math.abs(student[i][0] - point[j][0]) + Math.abs(student[i][1] - point[j][1]);
                if (min > dist) {
                    min = dist;
                    check = j + 1;
                }
            }
            System.out.println(check);
        }
    }
}

Measured memory_bytes: 23124
/*Learning is endless*/
#include <bits/stdc++.h>
#define endl "\n";
#define pii pair<int,int>;
using namespace std;
typedef long long ll;
const ll BIG=1000000007;
const double PI=3.141592653589793238;
ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0){
        if(b&1){res=(res*a)%m;}
    b>>=1;a=(a*a)%m;
    }
    return res;
}
template <typename T,typename Q>
T max(T a,Q b)
{
    if(a<b)
        return b;
    return a;
}
template <typename T,typename Q>
T min(T a,Q b)
{
    if(a>b)
        return b;
    return a;
}
long gcd(long a,long b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void solve()
{
    int n;cin>>n;
    vector<int> p(n),q(n);
    for(int i=0;i<n;i++)
    {
        cin>>p[i]>>q[i];
    } 
    int flag=0;
    for(int i=0;i<n-2;i++)
    {
        if(p[i]==q[i]&&p[i+1]==q[i+1]&&p[i+2]==q[i+2])
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}
int main() {
    int t;
    t=1;
    while(t--)
        solve();
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define m 1000000007
long long int power(int a,long long int b)
{
    long long int r=1;
    while(b>0)
    {
        if(b&1)
        r=(r*a)%m;
        a=(a*a)%m;
        b/=2;
    }
    return r;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   int n;
  cin>>n;
  int k;
  cin>>k;
  long long int arr[n],pre[n]={0};
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  sort(arr,arr+n);
  for(int i=0;i<n;i++)
  {
    if(i>=1)
      pre[i]=pre[i-1]+arr[i];
    else
      pre[i]=arr[i];
  }
  if(k>=n)
    cout<<0;
  else
  cout<<pre[n-k-1];
}


Measured memory_bytes: 3328
#include <cstdio>
using namespace std;

int main() {
	double x1, y1, x2, y2, xq, yq, m, n, x, y;
	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) != EOF) {
		if (x2 - x1 == 0) {
			printf("%.6lf %.6lf\n", 2 * x1 - xq, yq);
		} else if(y2 - y1 == 0) {
			printf("%.6lf %.6lf\n", xq, 2 * y2 - yq);
		} else {
			m = (y2 - y1) / (x2 - x1);
			n = -1 / m;

			x = 2 * (((y1 - m * x1) - (yq - n * xq)) / (n - m)) - xq;
			y = 2 * ((n * (y1 - m * x1) - m * (yq - n * xq)) / (n - m)) - yq;

			printf("%.6lf %.6lf\n", x, y);
		}
	}
	return 0;
}

Measured memory_bytes: 2612
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int mod = 1e9+7;//998244353
const int N = 2e5+5;

vector<int>g[N];
int n,m,used[N];
int ans;
int cnt;
void dfs(int x){
	cnt++;
	used[x]=1;
	for(auto i:g[x]){
		if(!used[i])
			dfs(i);
	}
}

void solve(){
	cin>>n>>m;
	rep(i,m){
		int u,v;
		cin>>u>>v;
		--u,--v;
		g[u].pb(v);
		g[v].pb(u);
	}
	rep(i,n){
		if(!used[i]){
			dfs(i);
			umax(ans,cnt);
			cnt=0;
		}
	}
	cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Measured memory_bytes: 21548
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>

using namespace std;

int n, t;
vector<pair<int, int>> menu;

int dp[3001][3001];

int dfs(int now, int time){
    if(now == n || t <= time){
        return 0;
    }
    if(~dp[now][time]) return dp[now][time];
    return dp[now][time] = max(dfs(now + 1, time), dfs(now + 1, time + menu[now].first) - menu[now].second);
}

int main(){
    cin >> n >> t;
    menu.resize(n);
    for(auto&& i : menu){
        cin >> i.first >> i.second;
        i.second *= -1;
    }
    sort(begin(menu), end(menu));
    memset(dp, -1, sizeof dp);
    cout << dfs(0, 0) << "\n";
}

Measured memory_bytes: 35584
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <limits.h>
#include <map>
#define MAXN 100000
#define Amari 1000000007
#define p pair <int,int>
using namespace std;
multimap <int, int> ship;
int n,m,cnt=0;
bool clear = false; 
vector <int> buckets(100004,0);
int main(int argc,char const* argv[])
{
  cin >> n;
  int a;
  long long max=0;
  for(int i=0;i<n;i++)
    {
      cin >> a;
      buckets[a+2]++;
    }
  for(int i=0;i<MAXN+2;i++)
    {
      if((buckets[i]+buckets[i+1]+buckets[i+2])>max) 
	{max=(buckets[i]+buckets[i+1]+buckets[i+2]);}
    }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int N, X;
	cin >> N >> X;
	int m[100];
	for (int i = 0; i < N; i++)
		cin >> m[i];
	int Min = m[0];
	for (int i = 0; i < N; i++)
		Min = min(Min, m[i]);
	int sum = 0;
	for (int i = 0; i < N; i++)
		sum += m[i];
	X -= sum;
	int count = 0;
	count = X / Min + N;
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//exhaustive search
public class Main {
	public static boolean solve(int[] data, int t, int rest) {
		
		//termination conditions
		if(rest == 0) {
			return true;
		}
		
		if(rest < 0) {
			return false;
		}
		
		//otherwise, come to last
		if(t == data.length -1) {
			if(data[t] == rest) return true;
			return false;
		}
		
		return solve(data, t+1, rest) || solve(data, t+1, rest-data[t]);
	}
	
	
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int [] A = new int[n];
		for(int i = 0; i < n; i++) {
			A[i] = cin.nextInt();
		}
		
		n = cin.nextInt();
		for(int j = 0; j < n; j++) {
			if(solve(A, 0, cin.nextInt())) {
				System.out.println("yes");
			}else {
				System.out.println("no");
			}
		}
		
		
		cin.close();
		
	}
	
}

Measured memory_bytes: 26812
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] A = in.ii(N);
        int[] B = in.ii(N);
        int[] C = in.ii(N);
        long ans = solve(N, A, B, C);
        out.println(ans);
    }

    static long solve(int N, int[] A, int[] B, int[] C) {
        Arrays.sort(A);
        Arrays.sort(C);
        long ans = 0;
        for (int j = 0; j < N; j++) {
            int l = -1;
            int r = N - 1;
            while (l < r) {
                int m = (l + r + 1) / 2;
                if (A[m] < B[j]) {
                    l = m;
                } else {
                    r = m - 1;
                }
            }
            long i = l + 1;
            l = 0;
            r = N;
            while (l < r) {
                int m = (l + r) / 2;
                if (B[j] < C[m]) {
                    r = m;
                } else {
                    l = m + 1;
                }
            }
            long k = N - l;
            ans += (long)i * k;
        }
        return ans;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = read(cbuf, 0, cbuf.length);
            } catch (IOException e) {

            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                back();
                break;
            }
        }
    }

    char[] s(final int N) {
        skip();
        char[] s = new char[N];
        for (int i = 0; i < s.length; i++) {
            s[i] = next();
        }
        return s;
    }

    String s() {
        try {
            return readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < N; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 42620
import Data.List
import Data.Ord

takePairs []  = []
takePairs [_] = []
takePairs (a:b:xs)
  | a == b = a : takePairs xs
  | otherwise = takePairs (b:xs)

main :: IO ()
main = do
    n <- readLn :: IO Int
    a <- map read . words <$> getLine :: IO [Int]
    let a' = takePairs . concat
           . filter ((2<=) . length) . group . sortOn Down $ a
    print $ if length a' < 2
               then 0 else product $ take 2 a'


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

int main() {
    string s;
    for (int i = 0; i < 4; i++) {
        char c;
        cin >> c;
        s += c;
    }
    sort(s.begin(), s.end());
    if (s == "1479") cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

void caesar(char *);

int main()
{
	char *pstr, str[128];

	pstr = str;

	while(gets(pstr) != NULL) {
		
		while(1){
			caesar(pstr);
			if((strstr(pstr, "the") != NULL) || (strstr(pstr, "this") != NULL) || (strstr(pstr, "that") != NULL))
				break;
		}
		printf("%s\n", pstr);

	}

	return 0;

}

void caesar(char *p)
{
	int i, len;
	len = strlen(p);
	for(i=0; i<len; i++){
		if(p[i]>='b' && p[i]<='z')
			p[i] -= 1;
		else if(p[i]=='a')
			p[i] = 'z';
	}
	return;
}

Measured memory_bytes: 524
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

#define MAX_N 200000

int par[MAX_N];
int rnk[MAX_N];
long long int sz[MAX_N];
long long int cnt = 0;

// 初期化
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		rnk[i] = 0;
	}
}

// x の親を返す
int find(int x){
	if(par[x] == x){
		return x;
	}
	return par[x] = find(par[x]);
}

// x と y を併合する
void unite(int x, int y){
	int x_par = find(x);
	int y_par = find(y);
	if(x_par == y_par){
		return;
	}
    cnt += 1;
	if(rnk[x_par] < rnk[y_par]){
		sz[y_par] = sz[x_par] + sz[y_par];
		par[x_par] = y_par;
	}else{
		sz[x_par] = sz[x_par] + sz[y_par];
		par[y_par] = x_par;
		if(rnk[x_par] == rnk[y_par]){
			rnk[x_par]++;
		}
	}
}

// x, y が同じグループか判定
bool same(int x, int y){
	return (find(x) == find(y));
}

int main(){
    int N, M;
    cin >> N >> M;
    init(MAX_N);
    for(int i = 0; i < M; i++){
        long long int X, Y, Z;
        cin >> X >> Y >> Z;
        unite(X, Y);
    }
    cout << N - cnt << endl;
    return 0;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0088

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    encoder = {' ':'101', "'":'000000', ',':'000011', '-':'10010001', '.':'010001', '?':'000001', 'A':'100101', 'B':'10011010',
               'C':'0101','D':'0001', 'E':'110', 'F':'01001', 'G':'10011011', 'H':'010000', 'I':'0111','J':'10011000',
               'K':'0110', 'L':'00100', 'M':'10011001', 'N':'10011110', 'O':'00101', 'P':'111', 'Q':'10011111', 'R':'1000',
               'S':'00110', 'T':'00111', 'U':'10011100', 'V':'10011101', 'W':'000010', 'X':'10010010', 'Y':'10010011', 'Z':'10010000'
               }

    decoder = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E', '00101':'F', '00110':'G', '00111':'H',
               '01000':'I', '01001':'J', '01010':'K', '01011':'L', '01100':'M', '01101':'N', '01110':'O', '01111':'P',
               '10000':'Q', '10001':'R', '10010':'S', '10011':'T', '10100':'U', '10101':'V', '10110':'W', '10111':'X',
               '11000':'Y', '11001':'Z', '11010':' ', '11011':'.', '11100':',', '11101':'-', '11110':"'", '11111':'?'
    }

    for line in sys.stdin:
        txt = line.strip('\n')
        ans = ''
        for c in txt:
            ans += encoder[c]

        if len(ans) % 5 != 0:
            ans += '0'*(5-len(ans)%5)

        # print(ans)

        result = ''
        while ans:
            temp = ans[:5]
            result += decoder[temp]
            ans = ans[5:]

        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>
#include <cstring>

using namespace std;

#define DIGITS 50

template<class T> inline void chmax(T& a, const T& b) { if (a < b) { a = b; } }

long long dp[DIGITS+1][2];

int main() {
    int n;
    long long k;
    cin>>n>>k;
    vector<long long> a;
    long long x;
    for (int i=0;i<n;++i){
        cin>>x;
        a.push_back(x);
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0]=0;
    for (int i = 0; i < DIGITS; ++i) {
        long long mask = 1ll << (DIGITS-i-1);
        int cnt = 0;
        for (int j = 0; j < n; ++j) {
            if (mask & a[j])
                ++cnt;
        }
        if (dp[i][1] != -1) {
            chmax(dp[i+1][1], dp[i][1] + mask*max(cnt,n-cnt));
        }
        if (dp[i][0] != -1) {
            if (k & mask) {
                chmax(dp[i+1][1], dp[i][0] + mask*cnt);
            }
            else chmax(dp[i+1][0], dp[i][0]);
        }
        if (dp[i][0] != -1) {
            if (k & mask) chmax(dp[i+1][0], dp[i][0] + mask*(n-cnt));
            else chmax(dp[i+1][0], dp[i][0] + mask*cnt);
        }
    }
    cout << max(dp[DIGITS][0], dp[DIGITS][1]);
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,s;
    cin>>a;
    s=0;
    for(int i=1;i<=a;i++)
    {
        int t=i;
        int cnt=0;
        while(t) cnt++,t/=10;
        if(cnt&1) s++;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <deque>
#include <map>

#define ll long long
#define ull unsigned long long
#define mod 1000000007

using namespace std;

int main() {
	while(true){
		char x[4];
	for (int i = 0; i < 4; ++i) {
		cin >> x[i];
		x[i] -= '0';
	}

	if (x[0] == x[1] && x[1] == x[2] && x[2] == x[3]) {
		if(x[0] == 0) break;
		else cout << "NA" << "\n";
		continue;
	}

	int counter = 0;
	int t = x[0] * 1000 + x[1] * 100 + x[2] * 10 + x[3];
	while (t != 6174) {
		++counter;
		sort(x, x + 4);
		t = x[3] * 999 + x[2] * 90 - x[1] * 90 - x[0] * 999;
		x[0] = t / 1000;
		x[1] = (t / 100) - x[0] * 10;
		x[2] = (t / 10) - x[0] * 100 - x[1] * 10;
		x[3] = t - x[0] * 1000 - x[1] * 100 - x[2] * 10;
	}

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


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

#define ll long long
#define pii pair <int, int>

using namespace std;

ll h;

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

    cin >> h;
    ll rez = 0;
    ll val = 1;
    while (h) {
        rez += val;
        val <<= 1;
        h >>= 1;
    }
    return cout << rez, 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//long long int t;
//cin>>t;
//for(int i=0;i<t;i++)
{
ll a,b,c,k;
cin>>a>>b>>c>>k;
if(a>=b)
{
    while(a>=b)
    {
        k--;
        if(k<0)
        {
            break;
        }
        b=b*2;
    }
}
if(b>=c)
{
    while(b>=c)
    {
        k--;
        if(k<0)
        {
            break;
        }
        c=c*2;
    }
}

if(a<b&&b<c)
{
    cout<<"Yes"<<endl;
}
else
{

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

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

int main() {
  long long N,K;
  cin >> N >> K;
  long long count = 0;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  if (K >= N) {
    cout << 0 << endl;
  }
  if (K < N) {
    for (long long i = 0; i < N - K; i++) {
      count = count + A.at(i);
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL X;
    cin >> X;

    vector<LL> factors;
    factors.push_back(1);
    for (LL f = 2; f * f <= X; ++f) {
        if (X % f == 0) {
            factors.push_back(f);
        }
    }

    bool done = false;
    int i = 0;
    while (!done) {
        for (int f: factors) {
            LL B = i;
            LL A = B+f;
            // cout << "+ " << A << ' ' << B << " => " << (A*A*A*A*A-B*B*B*B*B) <<  endl;
            if (A*A*A*A*A-B*B*B*B*B == X) {
                cout << A << ' ' << B << endl;
                done = true;
            }
            if (!done && i) {
                LL B = -i;
                LL A = B+f;
                // cout << "- " << A << ' ' << B << " => " << (A*A*A*A*A-B*B*B*B*B) <<  endl;
                if (A*A*A*A*A-B*B*B*B*B == X) {
                    cout << A << ' ' << B << endl;
                    done = true;
                }
            }
            if (done) {
                break;
            }
        }
        ++i;
    }

    return 0;
}


Measured memory_bytes: 3656
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    double bunbo=0;
    for(int i=0;i<n;i++){
      bunbo+=1.0/a[i];
    }
    System.out.println(1.0/bunbo);
  }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);

    for (int i = 0; i < n; ++i) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int a = 0, b = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            a += vec.at(i);
        }else {
            b += vec.at(i);
        }
    }
    cout << a - b << endl;
}

Measured memory_bytes: 256
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 {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
    }
    let ans = n*(n+1)/2;
    println!("{}", ans);
}

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

int main(){
    int n;
    cin >> n;
    queue<int> q;
    int ans=0;
    q.push(3);
    q.push(5);
    q.push(7);
    int tmp;
    int i,j,k;
    while(q.front()<=n){
            tmp=q.front();
            q.push(tmp*10+3);
            q.push(tmp*10+5);
            q.push(tmp*10+7);
            q.pop();
            i=0; j=0; k=0;
            while(tmp>0){
                if(tmp%10==3)i++;
                else if(tmp%10==5)j++;
                else if(tmp%10==7)k++;
                tmp/=10;
            }
            if(i>0&&j>0&&k>0)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>

int main()
{
	int r, D, x;
	scanf("%d %d %d", &r, &D, &x);
	int i = 0;
	for (i = 1; i <= 10; i++) {
		x = r * x - D;
		 std::cout << x << "\n"; 
	}

   

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	return c - '0';
}
int keta(int a) {
	return to_string(a).size();
}
int a[100010];
signed main() {
	int n;
	cin >> n;
	int max = 0;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		max += abs(a[i]);
	}
	sort(a, a + n);
	if (a[0] > 0) {
		max -= a[0] * 2;
	}
	if (a[n - 1] < 0) {
		max += a[n - 1] * 2;
	}
	cout << max << endl;
	int sum = a[0];
	loop(i,1,n-1) {
		if (a[i] >= 0) {
			cout << sum <<' '<< a[i] << endl;
			sum -= a[i];
		}
	}
	cout << a[n - 1] << ' ' << sum << endl;
	sum = a[n - 1] - sum;
	loop(i, 1, n - 1) {
		if (a[i] < 0) {
			cout << sum << ' ' << a[i] << endl;
			sum -= a[i];
		}
	}
}


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		int intCount = 0;

		int intScore[][];
        intScore = new int[50][3];

		int intTotal;
		while (true) {

        // 入力されるintM,intF,intRを定義

        int intM = scanner.nextInt();
        int intF = scanner.nextInt();
        int intR = scanner.nextInt();

        if (intM == -1 && intF == -1 && intR == -1) {
        	break;
        }

        intScore[intCount][0] = intM;
        intScore[intCount][1] = intF;
        intScore[intCount][2] = intR;

        intCount++;
		}
		for (int intI = 0; intI < intCount; intI++) {
			if (intScore[intI][0] == -1 || intScore[intI][1] == -1) {
			System.out.println("F");
			} else {
			if (intScore[intI][0] == -1) {
				intScore[intI][0] = 0;
			} else if (intScore[intI][1] == -1) {
				intScore[intI][1] = 0;
			}
			intTotal = intScore[intI][0] + intScore[intI][1];
			if (intTotal >= 80) {
				System.out.println("A");
			} else if (intTotal < 80 && intTotal >= 65) {
				System.out.println("B");
			} else if (intTotal < 65 && intTotal >= 50) {
				System.out.println("C");
			} else if (intScore[intI][2] >= 50) {
				System.out.println("C");
			} else if (intTotal < 50 && intTotal >= 30) {
				System.out.println("D");
			} else {
				System.out.println("F");
			}
			}
		}
	}
}



Measured memory_bytes: 26144
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,m = LI()
    d = collections.defaultdict(int)
    for _ in range(m):
        a,b = LI()
        d[a] += 1
        d[b] += 1
    for c in d.values():
        if c % 2 == 1:
            return 'NO'
    return 'YES'


print(main())


Measured memory_bytes: 14148
import sys
sys.setrecursionlimit(10**6)

def dfs(x,y):
    c[x][y] = 0
    for dx in range(-1,2):
        for dy in range(-1,2):
            nx = x + dx
            ny = y + dy
            
            if 0 <= nx < h and 0 <= ny < w and c[nx][ny] == "1":
                dfs(nx,ny)
                

while 1:
    w,h = map(int,input().split())
    c = [input().split() for _ in range(h)]
    
    if w == 0 and h == 0:
        break
    cnt = 0
    for i in range(h):
        for j in range(w):
            if c[i][j] == "1":
                dfs(i,j)
                cnt += 1

    print(cnt)
    


Measured memory_bytes: 7992
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
vector<vector<int>>edges;
vector<int>dp;
vector<int>degree;
void dfs(int v) {
	for (auto u : edges[v]) {
		dp[u] = max(dp[u], dp[v] + 1);
		degree[u]--;
		if (degree[u] == 0)dfs(u);
	}

}
signed main(void)
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	edges = vector<vector<int>>(n + 1);
	dp = vector<int>(n + 1);
	degree = vector<int>(n + 1, 1);
	dp[0] = 0;
	for (int i = 1; i <= n; i++)edges[0].push_back(i);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		edges[x].push_back(y);
		degree[y]++;
	}
	int mx = 0;
	dfs(0);
	for (auto now : dp)mx = max(mx, now);
	cout << mx - 1;
	return 0;
}

Measured memory_bytes: 7928
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final long x = fs.nextLong();
        final long[] size = new long[n];
        final long[] patty = new long[n];
        size[0] = 1L;
        patty[0] = 1L;
        for (int i = 1; i < n; i++) {
            size[i] = size[i - 1] * 2 + 3;
            patty[i] = patty[i - 1] * 2 + 1;
        }
        System.out.println(f(n, x, size, patty));
    }

    private static long f(int n, long x, long[] size, long[] patty) {
        if (n == 0) {
            return x <= 0 ? 0 : 1;
        }
        if (x <= 1 + size[n - 1]) {
            return f(n - 1, x - 1, size, patty);
        }
        return patty[n - 1] + 1 + f(n - 1, x - 2 - size[n - 1], size, patty);
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 32708
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  string s;
  cin>>s;
  if((s[0] == s[1]) && (s[0] == s[2])) puts("Yes");
  else if((s[1] == s[2]) && (s[1] == s[3])) puts("Yes");
  else puts("No");
}


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

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    int A[2][N];
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < N; ++j) cin >> A[i][j];
    }

    int dp[2][N];
    dp[0][0] = A[0][0];
    dp[1][0] = A[0][0] + A[1][0];
    for (int i = 1; i < N; ++i) {
        dp[0][i] = dp[0][i - 1] + A[0][i];
        dp[1][i] = max(dp[0][i], dp[1][i - 1]) + A[1][i];
    }
    cout << dp[1][N - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
n = input()
a = input().split()
a = map(int, a)
tmp = sorted(a, reverse=True)

al = 0
bo = 0

for i in range(len(tmp)):
  if i %2 == 0:
    al = al + int(tmp[i])

  else:
    bo = bo + int(tmp[i])

print(al - bo)

Measured memory_bytes: 3064
program poor
    integer(4):: a,b,c
    read*, a,b,c

    if (((a/=b) .and. (a/=c) .and. (b/=c)) .or. ((a==b) .and.(a==c))) then
        print*, "No"
    else
        print*, "Yes"
    end if
end program poor

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

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

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;
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;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I "; else cout << A[i] << " ";}}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int s, w;
  cin >> s >> w;
  if (w >= s) cout << "unsafe";
  else cout << "safe";

  return 0;
}


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

int n;
vector<double> prob;

vector< vector<double> > memo;

double dp (int i, int numOfHeads) {
	if (numOfHeads > (n - i) ) {
	//	memo[i][numOfHeads] = 0;
		return 0;
	}
	if (memo[i][numOfHeads] != -1) return memo[i][numOfHeads];
	memo[i][numOfHeads] = ((dp(i + 1, numOfHeads) * (1 - prob[i])) + (dp(i + 1, numOfHeads - 1) * prob[i]));
	return memo[i][numOfHeads];
}

int main () {
//	cout << 
	cin >> n;
	prob.assign(n,0);
	memo.assign(n,vector<double>(n+1,-1));
	for (int i = 0; i < n; i++)
		cin >> prob[i];
	/*for (int i = 0; i < n; i++)
		for (int j = 0; j <= n; j++)
			memo[i][j] =-1 */
	memo[n - 1][0] = 1 - prob[n - 1];
	memo[n - 1][1] = prob[n - 1];
	double ans = 0;
	for (int i=n/2+1;i<=n;i++)
		ans += dp(0, i);
	cout << fixed << setprecision(9) << ans << "\n";
	return 0;
}

Measured memory_bytes: 71040
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1e9


ll f(ll n){
    ll ans;
    if (n%2){
        ans=3*n+1;
    }
    else {
        ans=n/2;
    }
    return ans;
}

int main(void){
    vector<ll> a(1000000+10);
    ll temp;
    cin>>temp;
    a[1]=temp;

    vector<ll> x(1000000+10,0);
    x[temp]++;

    for (ll i=2;i<=1000005;i++){
        a[i]=f(a[i-1]);
        if (x[a[i]]>=1) {
            cout<<i<<endl;
            return 0;
        }
        x[a[i]]++;
    }

    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    string S;
    cin >> N;
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        S[i] += N;
        if(S[i] > 'Z'){
            S[i] -= 26;
        }
    }
    cout << S << endl;
}

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

using namespace std;

int m, k;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> m >> k;
    if (m == 1 && k == 1)
        cout << -1 << endl;
    else if (m == 1 && k == 0)
        cout << "0 1 1 0" << endl;
    else
    {
        if (k >= (1 << m))
        {
            cout << -1 << endl;
            exit(0);
        }
        cout << k << " ";
        for (int i = 0; i < (1 << m); i++)
            if (i != k)
                cout << i << " ";
        cout << k << endl;
        for (int i = (1 << m) - 1; i >= 0; i--)
            if (i != k)
                cout << i << " ";
        cout << endl;
    }
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  std::vector<int> vec(n);
  rep(i,n) cin >> vec.at(i);
  bool ok = true;
  int num = 0;
  rep(i,n-1) {
    num = max(num, vec.at(i)-1);
    if (vec.at(i)-1 > vec.at(i+1)) ok = false;
    else if (num > vec.at(i+1)) ok = false;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3756
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;  
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) 
{
	ll ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

void solve() 
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int red = 0;
	For(i,0,n)
	{
		if (s[i] == 'R') ++red;
	}
	int white = n-red;
	int ans = min(red, white);
	int curr = 0;
	For(i,0,n)
	{
		if (red == 0) break;
		if (s[i] == 'R') 
		{
			ans = min(ans, curr + red-1);
			--red;
		}
		else
		{
			++curr;
			ans = min(ans, curr + red  - 1);
			--red;
		}
	}
	cout << ans << endl;
}

int main() 
{
	fast_io();
	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 3780
#include <stdio.h>

int main(){
  int r,g,b;
  scanf("%d%d%d",&r,&g,&b);
  int n;
  n = 100*r + 10*g + b;
  if(n%4 == 0){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector


int n,dp[N],h[N];

int k;
void solve()
{
    cin>>n>>k;
    forn(i,1,n)cin>>h[i];
    
    dp[1] = 0;
    
    forn(i,2,n)
    {
        dp[i] = MOD*MOD;
        forn(j,max(1LL,i-k),i-1)
        {
            dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n];
    
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }



    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 5120