akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline


def main():
    K = int(input().rstrip())
    a, b = map(int, input().split())
    f = 0
    for i in range(a, b+1):
        if i % K == 0:
            f = 1
            break

    print(['NG', 'OK'][f])

if __name__  == '__main__':
    main()

Measured memory_bytes: 9164
#include<iostream>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    char str[3];
    cin >> str;

    if (str[0]=='S' && str[1]=='U' && str[2]=='N')
    {
        cout << "7" <<endl;
    }else if (str[0]=='S' && str[1]=='A' && str[2]=='T')
    {
        cout << "1" <<endl;
    }else if (str[0]=='F' && str[1]=='R' && str[2]=='I')
    {
        cout << "2" <<endl;
    }else if (str[0]=='T' && str[1]=='H' && str[2]=='U')
    {
        cout << "3" <<endl;
    }else if (str[0]=='W' && str[1]=='E' && str[2]=='D')
    {
        cout << "4" <<endl;
    }else if (str[0]=='T' && str[1]=='U' && str[2]=='E')
    {
        cout << "5" <<endl;
    }else if (str[0]=='M' && str[1]=='O' && str[2]=='N')
    {
        cout << "6" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int dams[] = new int[n];

        for(int i=0;i<n;i++) {
            dams[i] = sc.nextInt();
        }

        int t = 0;
        for(int i=0;i<n;i++) {
            if (i%2 == 1) {
                t-=dams[i];
            } else {
                t+=dams[i];
            }
        }

        StringBuilder builder = new StringBuilder();
        builder.append(t);
        for(int i=1;i<n;i++) {
            t = 2 * (dams[i-1] - (t/2));
            builder.append(" ").append(t);
        }
        
        // 出力
        System.out.println(builder.toString());
    }
}

Measured memory_bytes: 56244
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)

ll sq(ll x){
	return x*x;
}

int main(void){
	int n,i;
	string s;
	bool flag = false;
	cin >> s;
	n = s.length();
	s.push_back('!');
	for(i=1; i<n; ++i){
		if(s[i-1] == s[i]){
			cout << i << " " << i+1 << endl;
			flag = true;
			break;
		}
		if(s[i-1] == s[i+1]){
			cout << i << " " << i+2 << endl;
			flag = true;
			break;
		}
	}
	if(!flag){
		cout << "-1 -1" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;

using pll = pair<ll, ll>;

const ll maxN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

ll func(ll x){
	return (x*(x+1))/2;
}

ll _pow(ll b, ll p){
	if(p == 0) return 1;
	if(p == 1) return b;
	ll exB = b*b;
	if(p&1) return b*_pow(exB, p/2);
	return _pow(exB, p/2);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	cout << max({a*10+b+c,b*10+a+c,c*10+a+b});
	return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
long long a, b, c;

int main() {
    cin >> a >> b >> c;
    int res = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        res++;
        int x = (b + c) / 2, y = (c + a) / 2, z = (a + b) / 2;
        a = x; b = y; c = z;
        if (res > 1e6) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju */
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.xx-b.xx)*(b.yy-c.yy)-(b.xx-c.xx)*(a.yy-b.yy))<0.0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 10000
#define md 1000000007
#define maxp 2050180000

typedef pair<int ,int > P;

////////define value/////
int main()
{

    int n;
    I(n);
    int a[n*2+2];
    for(int i=0;i<2*n;i++)I(a[i]);
    sort(a,a+2*n);
    int res=0;
    for(int i=0;i<2*n;i+=2)res+=a[i];
    PI(res);


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  
  vector<ll> p(A);
  rep(i, A) cin >> p.at(i);
  
  vector<ll> q(B);
  rep(i, B) cin >> q.at(i);
  
  vector<ll> r(C);
  rep(i, C) cin >> r.at(i);
  
  sort(p.begin(), p.end(), greater<int>());
  sort(q.begin(), q.end(), greater<int>());
  sort(r.begin(), r.end(), greater<int>());
  
  ll N;
  if(X+Y < C) N = 2*(X + Y);
  else N = X + Y + C;
  
  vector<ll> all(N);
  rep(i, X) all.at(i) = p.at(i);
  rep(i, Y) all.at(i+X) = q.at(i);
  if(X+Y < C){
    rep(i, X+Y) all.at(i+X+Y) = r.at(i);
  }else{
    rep(i, C) all.at(i+X+Y) = r.at(i);
  }
  
  sort(all.begin(), all.end(), greater<int>());
  ll res = 0;
  rep(i, X+Y) res += all.at(i);
  
  cout << res;
 
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,sum=0;
    cin>>n;
    ll i=1;
    while(n)
    {
        n=n/2;
        sum+=i;
        i*=2;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

int N, K;
VI G[100010];
int cnt[100010];
int ans = 1;

void dfs(int now, int pa) {
	int tmp = 0;
	if (pa != -1) {
		tmp = cnt[pa] + 1;
	}
	//cout << now << " " << tmp << endl;
	if (K - tmp <= 0) {
		ans = 0;
		//cout << "L" << endl;
		return;
	}

	ans *= (K - tmp);
	ans %= mod;
	if (pa != -1)cnt[pa]++;
	fore(to, G[now]) if (to != pa) {
		cnt[to]++;
		dfs(to, now);
	}
}

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


	cin >> N >> K;
	REP(i, N - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0, -1);

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 9984
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int l = str.length();
        String ans = "";
        for(int i = 0; i < l; i++) {
            char c = str.charAt(i);
            if(Character.isUpperCase(c)) {
                ans += String.valueOf(Character.toLowerCase(c));
            } else if(Character.isLowerCase(c)) {
                ans += String.valueOf(Character.toUpperCase(c));
            } else {
                ans += String.valueOf(c);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 31380
#include <iostream>

using namespace std;

int main(){
    ios::sync_with_stdio(false);

    int N, T, a, c, t;
    bool f = false;

    cin >> N >> T;
    cin >> c >> t;
    N--;
    f = t <= T;
    if(f)
    	a = c;
    while(N--){
    	cin >> c >> t;
    	if(t <= T){
    		if(!f){
    			f = true;
    			a = c;
    		}
    		a = c < a ? c : a;
    		
    	}
    }
   	if(!f){
   		cout << "TLE" << endl;
   	}else{
   		cout << a << endl;
   	}
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int R;
    cin >> R;
        if(R<1200){
            cout << "ABC" << endl;
        }else if(1200 <= R && R < 2800){
            cout << "ARC" << endl;
        }else{ 
            cout << "AGC" << endl;
        }
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> fav(m,0);

    int a,k;

    for (int i = 0; i < n; i++){
        cin >> k;
        for (int j = 0; j < k; j++){
            cin >> a;
            fav[a-1]++;
        }
    }
    int ans = 0;

    for (int i = 0; i < m; i++){
        if (fav[i] == n){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var a1 = new List<int>();
            var a2 = new int[5];
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            a1.Add(n);   a2[0] = n;
            for (int i = 0; i < 4; i++)
            {
                var n2 = int.Parse(Console.ReadLine().Trim());
                a1.Add(n2);
                a2[i + 1] = n2;
            }
            var aa1 = a1.Distinct().ToList();
            aa1.Sort();
            if (aa1.Count()==2)
            {
                var jan1 = aa1.First();
                var jan2 = aa1.Last();
                if (jan1 * jan2 == 2)
                    for (int i = 0; i < 5; i++) Console.WriteLine(a2[i]);
                if (jan1 * jan2 == 3)
                    for (int i = 0; i < 5; i++)
                        if (a2[i] == 3) Console.WriteLine(1);
                        else Console.WriteLine(2);
                if (jan1 * jan2 == 6)
                    for (int i = 0; i < 5; i++)
                        if (a2[i] == 2) Console.WriteLine(1);
                        else Console.WriteLine(2);
            }
            else
            {
                for (int i = 0; i < 5; i++)
                    Console.WriteLine(3);
            }
        }
    }
}

Measured memory_bytes: 10164
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ab=[s+t for s in a for t in b]
ab.sort()
ab=ab[-1:-k-1:-1]
abc=[s+t for s in ab for t in c]
abc.sort()
abc=abc[-1:-k-1:-1]
for i in range(len(abc)):
    print(abc[i])


Measured memory_bytes: 137868
from operator import itemgetter


def get_identity():
    return list(range(1, n + 1))


def composition(ppp, qqq):
    return [ppp[q - 1] for q in qqq]


def reverse_composition(ppp, qqq):
    return [ppp[i] for i, q in sorted(enumerate(qqq), key=itemgetter(1))]


def solve(k, ppp, qqq):
    qp = reverse_composition(qqq, ppp)
    qpq = reverse_composition(qp, qqq)
    qpqp = composition(qpq, ppp)

    l, m = divmod(k - 1, 6)
    res = get_identity()
    tmp = qpqp
    while l:
        if l % 2 == 1:
            res = composition(res, tmp)
        tmp = composition(tmp, tmp)
        l >>= 1

    m = (k - 1) % 6
    if m == 0:
        base = ppp
    elif m == 1:
        base = qqq
    elif m == 2:
        base = reverse_composition(qqq, ppp)
    elif m == 3:
        res = composition(res, qqq)
        base = reverse_composition(get_identity(), ppp)
    elif m == 4:
        res = composition(res, qqq)
        res = reverse_composition(res, ppp)
        base = reverse_composition(get_identity(), qqq)
    elif m == 5:
        res = composition(res, qqq)
        res = reverse_composition(res, ppp)
        base = reverse_composition(get_identity(), qqq)
        base = composition(base, ppp)
    else:
        raise NotImplementedError

    ans = composition(res, base)
    ans = reverse_composition(ans, res)
    return ans


n, k = map(int, input().split())
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
print(*solve(k, ppp, qqq))


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

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

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{ 
  ll N;
  cin >> N;
  string s;
  cin >> s;
  ll cnt = 0;
  REP(i, N) {
    if (s[i] == 'R') cnt++;
  }
  ll ind = 0;
  ll ans = 0;
  while(cnt > 0) {
    if (s[ind] == 'W') {
      cnt--;
      ans++;
    } if (s[ind] == 'R') cnt--;
    ind++;
  }
  PRINT(ans);
  return 0;
} 


Measured memory_bytes: 3852
#include<stdio.h>

int main() {
  int antenna[5], k;
  int flag = 0;
  int i, j;

  for(i = 0; i < 5; i++) {
    scanf("%d", &antenna[i]);
  }
  scanf("%d", &k);

  for(i = 0; i < 5 - 1; i++) {
    for(j = i + 1; j < 5; j++) {
      if(antenna[j] - antenna[i] > k) flag = 1;
    }
  }

  if(flag == 0) printf("Yay!\n");
  else          printf(":(\n");

  return 0;
}


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

int main(){
    int N, K;
    int ans = 0;
    cin >> N >> K;
    vector<vector<int> > A(K, vector<int>(N));
    vector<int> S(N, 0);
    rep(i, K){
        int d;
        cin >> d;
        rep(j, d){
            cin >> A.at(i).at(j);
            S.at(A.at(i).at(j) - 1)++;
        }
    }
    rep(i, N){
        if(S.at(i) == 0){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

int main(){
    int n;
    cin >> n;
    string last;
    cin >> last;
    set<string> s;
    s.insert(last);
    bool f = 1;
    for(int i=1;i<n;i++){
        string x;
        cin >> x;
        if(s.find(x)!=s.end() || last[last.length()-1]!=x[0])
            f = 0;
        last = x;
        s.insert(x);
    }
    if(f)
        cout << "Yes";
    else
        cout << "No";
}

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

int dp[3005][3005];

int main()
{
    int i,j,k,sz1,sz2,lcs;
    string s1,s2,ans="";
    cin>>s1>>s2;
    sz1 = (int)s1.size();
    sz2 = (int)s2.size();

    for(int pos1=sz1-1 ; pos1 >= 0 ; pos1--){
        for(int pos2=sz2-1 ; pos2 >= 0 ; pos2--){
            if(s1[pos1] == s2[pos2])
                dp[pos1][pos2] = 1 + dp[pos1+1][pos2+1];
            else
                dp[pos1][pos2] = max(dp[pos1+1][pos2] , dp[pos1][pos2+1]);
        }
    }

    lcs = dp[0][0];
//    cout<<lcs<<endl;

    i = j = 0;
    while(i<sz1 && j<sz2){
        if(s1[i] == s2[j]){
            ans += s1[i];
            i++; j++;
        }
        else{
            if(dp[i+1][j] > dp[i][j+1])
                i++;
            else
                j++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 38804
#include "bits/stdc++.h"
using namespace std;

int n;
vector<int> available;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	for(int i=1;i<=9;i++){
		available.push_back(i*100 + i*10 + i);
	}
	cin>>n;
	for(int i=0;i<available.size();i++){
		if(available[i]>=n){
			n=available[i];
			break;
		}
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]
cl = list(map(int, input().split()))
cl.sort(reverse=True)

e = [set() for _ in range(n)]
for a,b in ab:
    a -= 1
    b -= 1
    e[a].add(b)
    e[b].add(a)

used = [False]*n
q = [0]

res = [0]*n
i = 0
while len(q)>0:
    u = q.pop()
    res[u] = cl[i]
    used[u] = True
    i += 1
    for v in e[u]:
        if not used[v]:
            q.append(v)

r = 0
for a,b in ab:
    r += min(res[a-1], res[b-1])
print(r)
print(*res)

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main()
{
    int n;cin >> n;
    if(n%2==1)
    {
        cout << "No" << endl;
        return 0;
    }
        
    string s;cin >> s;
    rep(i,n/2)
    {
        if(s[i]!=s[i+n/2])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define l1 long long 
const long double PI = acos(-1.0);
int main(){int t; cin >> t; int r=t%10;
 if(r==2 || r==4 ||r==5 ||r==7 ||r==9)cout<<"hon";
 else if(r==3)cout<<"bon";
 else cout<<"pon";
}



Measured memory_bytes: 3636
//
//  AOJ 0121 Seven Puzzle
//
//  Created by TaoSama on 2015-02-20
//  Copyright (c) 2014 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

string s;
typedef pair<string, int> Sta;
map<string, int> dp;
int d[4] = { -1, 1, 4, -4};

void bfs() {
	queue<Sta> q;
	dp["01234567"] = 0; q.push(Sta("01234567", 0));
	while(!q.empty()) {
		string s = q.front().first;
		int cur = q.front().second;
		q.pop();
		for(int i = 0; i < 4; ++i) {
			string ns = s;
			int nxt = cur + d[i];
			if(nxt < 0 || nxt > 7 || cur == 3 && nxt == 4 || cur == 4 && nxt == 3)
				continue;
			swap(ns[cur], ns[nxt]);
			if(!dp.count(ns)) {
				dp[ns] = dp[s] + 1;
				q.push(Sta(ns, nxt));
			}
		}
	}
}
int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	bfs();
	while(cin >> s) {
		for(int i = 1; i <= 7; ++i) {
			char x; cin >> x;
			s += x;
		}
		cout << dp[s] << endl;
	}
	return 0;
}

Measured memory_bytes: 3460
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int N;
int M;
int K;
int t;

// n maisu k menowa
void rec(int n,int k){
  if(n==N){
    t+=(k-K>0)?k-K:1;
    return;
  }
  REP(i,1,M){
    rec(n+1,k+i);
  }
}

void run(){
  while(cin>>N>>M>>K,N){
    t=0;
    rec(0,0);
    double ans=(double)t;
    double p=pow(M,N);
    cout<<ans/p<<endl;
  }
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  Graph G(n, vi(2));
  rep(i,n) rep(j,2) cin >> G[i][j];

  sort(all(G));

  int a = 0, b = -1;
  int a_end = n - 1;
  bool zero = false;

  rep(i,n) {
    if (b == -1) {
      if (G[a][1] < G[i][0]) {
        b = i;
        a_end = i - 1;
      }
      else if (G[i][1] <= G[a][1]) {
        a = i;
      }
    }

    else {
      if (G[i][0] > G[b][1]) {
        zero = true;
        break;
      }
      else if (G[i][1] <= G[b][1]) {
        b = i;
      }
    }
  }

  int ans = 0;
  rep(i,n) ans = max(ans, G[i][1] - G[i][0] + 1);

  if (zero) {
    cout << ans << endl;
    return 0;
  }

  if (b == -1) {
    ans += G[a][1] - G[n-1][0] + 1;
  }

  Graph rest;
  int r = b == -1 ? n-1 : b;
  for (int i=a_end; i>=a; --i) {
    if (G[i][1] <= G[r][1]) rest.push_back(G[i]);
    if (G[i][1] < G[n-1][0]) break;
  }

  int b_right = G[r][1];
  rep(i,rest.size()) {
    ans = max(ans, (G[a][1] - rest[i][0] + 1) + (b_right - G[n-1][0] + 1));
    b_right = min(b_right, rest[i][1]);
  }

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


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

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

    vector<char> colored1(s.size(),'0'), colored2(s.size(),'0');
    for(int i=0;i<s.size();i+=2){
        colored1[i] = '1';
    }
    for(int i=1;i<s.size();i+=2){
        colored2[i] = '1';
    }
    
    int count1 = 0, count2 = 0;
    for(int i=0;i<s.size();i++){
        if(s[i] != colored1[i]) count1 += 1;
    }
    for(int i=0;i<s.size();i++){
        if(s[i] != colored2[i]) count2 += 1;
    }
    cout << min(count1,count2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

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

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    REP(i, 0, N) {
        cin >> w[i] >> v[i];
    }

    auto dp = make_v(N + 1, W + 1, 0LL);
    REP(i, 0, N) {
        REP(j, 0, W + 1) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j + w[i] <= W) {
                dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
            }
        }
    }

    ll ans = 0;
    REP(i, 0, W + 1) {
        ans = max(ans, dp[N][i]);
    }

    cout << ans << endl;

    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(obj) (v.begin(obj),v.end(obj))
#define COUT(x) cout<<(x)<<endl;

int main(){
    ll n,a,b,c,d,e;
    cin >> n;
    cin >> a >> b >> c >> d >> e;
    ll min1 = min({a,b,c,d,e});
    COUT((n+min1-1)/min1+4)
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {

            var str = Console.ReadLine();
            var count = 0;

            var list = new List<string>();
            var bit1 = new List<string>();
            var bit2 = new List<string>();

            for (var x=0; x < str.Length; ++x)
            {
                list.Add(str[x].ToString());
            }

            for (var x=0; x < str.Length; ++x)
            {
                if (x % 2 == 0)
                {
                    bit1.Add("1");
                }
                else
                {
                    bit1.Add("0");
                }
            }

            for (var x = 0; x < str.Length; ++x)
            {
                if (x % 2 == 0)
                {
                    bit2.Add("0");
                }
                else
                {
                    bit2.Add("1");
                }
            }

            for(var x=0; x<str.Length; ++x)
            {
                if (str[0].ToString() == "1")
                {
                    if (list[x] != bit1[x])
                        count++;
                }
                else
                {
                    if (list[x] != bit2[x])
                        count++;
                }
            }

            Console.WriteLine(count);


        }
    }
}


Measured memory_bytes: 27356
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 998244353;

struct bracket{
    ll open,close;
    bool operator<(const bracket& rhs) const{
        if (open-close == rhs.open-rhs.close){
            return open > rhs.open;
        }
        return open-close > rhs.open-rhs.close;
    }
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >> n;
    vector <string> arr(n);
    for (int z=0;z<n;z++){
        cin >> arr[z];
    }
    vector <bracket> lol;
    ll open = 0;
    ll close = 0;
    for (int z=0;z<n;z++){
        ll open1 = 0;
        ll close1 = 0;
        for (int x=0;x<arr[z].size();x++){
            if (arr[z][x] == '(') open1++;
            if (arr[z][x] == ')') {
                if (open1 == 0) close1++;
                else open1--;
            }
        }
        ll open2 = 0;
        ll close2 = 0;
        for (int x=arr[z].size()-1;x>=0;x--){
            if (arr[z][x] == ')') close2++;
            if (arr[z][x] == '('){
                if (close2 == 0) open2++;
                else close2--;
            }
        }
        if (close1 == 0 && open2 == 0) continue;
        else if (close1 == 0){
            open += open2;
        }
        else if (open2 == 0){
            close += close1;
        } else {
            bracket temp;
            temp.open = open2;
            temp.close = close1;
            lol.push_back(temp);
        }
    }
    sort(lol.begin(),lol.end());
    bool ok = true;
    for (int z=0;z<lol.size() && ok;z++){
        open -= lol[z].close;
        if (open < 0) ok = false;
        open += lol[z].open;
    }
    if (open-close != 0) ok = false;
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
} 


Measured memory_bytes: 34200
class Dice(object):
    
    def __init__(self, line):
        self.top = 1
        self.bottom = 6
        self.south = 2
        self.east = 3
        self.west = 4
        self.north = 5
        self.convert = [int(s) for s in line.split()]
    
    def move(self, direction):
        if 'N' == direction:
            self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom
        elif 'S' == direction:
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif 'W' == direction:
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif 'E' == direction:
            self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom
    
    def search(self, line):
        top, south = [int(s) for s in line.split()]
        for direction in 'NNNNWNNNN':
            self.move(direction)
            if self.convert[self.south - 1] == south:
                break
        for direction in 'WWWW':
            self.move(direction)
            if self.convert[self.top - 1] == top:
                break
        return self.result()
        
    def result(self):
        return self.convert[self.east - 1]
    
dice = Dice(input())
for i in range(int(input())):
    print(dice.search(input()))

Measured memory_bytes: 7832
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<s64, s64>;

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

    int n, m;
    cin >> n >> m;
    
    vector< vector< P > > g(n);
    rep (i, m)
    {
        int l, r;
        s64 c;
        cin >> l >> r >> c;
        --l, --r;
        g[l].emplace_back(r, c);
    }

    rep (i, n - 1)
    {
        g[i + 1].emplace_back(i, 0);
    }

    const s64 inf = 1e18;
    s64 d[n];
    rep (i, n) d[i] = inf;
    d[0] = 0;
    priority_queue<P, vector< P >, greater< P > > pq;
    pq.push(P{0, 0});
    while (!pq.empty())
    {
        auto p = pq.top(); pq.pop();
        int from = p.second;
        s64 d1 = p.first;
        
        if (d[from] < d1) continue;
        
        for (auto& e : g[from])
        {
            int to = e.first;
            s64 cost = e.second;
            if (d[to] > d1 + cost)
            {
                d[to] = d1 + cost;
                pq.push(P{d[to], to});
            }
        }
    }

    s64 ans = d[n - 1];
    if (ans == inf) ans = -1;
    
    cout << ans << "\n";
    return 0;
}



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

int main(){
 int N,M;
 cin >> N >> M;
 
 vector <int> A(M);
 
  for(int i=0; i<M; i++){cin >> A.at(i);}
 int x=0;
 for(int i=0; i<M; i++){x+=A.at(i);}
 
 if(N<x){cout << -1 << endl;}
 else{cout << N-x << endl;}
}
 

Measured memory_bytes: 3240
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>

using namespace std; 

int main()
{
	int n;
	cin>>n;
	int ans;
	ans=n%10;
	
	if(ans==3) cout<<"bon";
	else if(ans==0||ans==1||ans==6||ans==8) cout<<"pon";
	else cout<<"hon";
	
	cout<<endl;
	
	return 0;
} 

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

using namespace std;

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

int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int>> edges(N, vector<int>());
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  vector<int> Dv(N, -1);
  vector<int> leaves;
  queue<int> que;
  que.push(v);
  Dv[v] = 0;
  while (!que.empty()) {
    int n = que.front();
    que.pop();
    if (edges[n].size() == 1) {
      leaves.push_back(n);
    }
    for (int e : edges[n]) {
      if (Dv[e] == -1) {
        Dv[e] = Dv[n] + 1;
        que.push(e);
      }
    }
  }

  vector<int> Du(N, -1);
  que.push(u);
  Du[u] = 0;
  while (!que.empty()) {
    int n = que.front();
    que.pop();
    for (int e : edges[n]) {
      if (Du[e] == -1) {
        Du[e] = Du[n] + 1;
        que.push(e);
      }
    }
  }

  int ans = 0;
  for (int l : leaves) {
    if (Du[l] < Dv[l]) {
      chmax(ans, Dv[l] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6908
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    long k =sc.nextLong()-1;
    int st=0;
    while(s.length()>st && s.charAt(st)=='1'){
      st++;
    }
    System.out.println((k<st)?'1':s.charAt(st));
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    ll d=log10(n)+1;
    ll count=0;
    while(d>=3){
        rep(bit,(ll)pow(3,d)){
            ll x=0;
            ll p=bit;
            bool a=0,b=0,c=0;
            rep(i,d){
                if(p%3==0){
                    x+=3*pow(10,i);
                    a=true;
                }
                if(p%3==1){
                    x+=5*pow(10,i);
                    b=true;
                }
                if(p%3==2){
                    x+=7*pow(10,i);
                    c=true;
                }
                p/=3; 
            }
            if(a&&b&&c){
                if(x<=n)count++;
            }
        }
        d--;
    }
    cout << count <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
     
using namespace std;
     
int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
	ll a,b,c;
	cin >> a >> b >> c;
	if(a==b&&a!=c){
		cout << "Yes" << endl;
	}		
	else if(b==c&&b!=a){
		cout << "Yes" << endl;
	}
	else if(a==c&&a!=b){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
  ll S; cin >> S;
  int X1 = 0,Y1 = 0;
  ll X2,X3,Y2,Y3;
  ll m = (ll)sqrt(S);
  if(m*m == S){
      X2 = m;
      Y3 = m;
      X3 = 0;
      Y2 = 0;
  }
  else{
      X2 = m+1;
      Y3 = m+1;
      X3 = X2 * Y3 - S;
      Y2 = 1;
  }
  cout << X1 << " " << Y1 << " " << X2 << " " << Y2 << " " << X3 << " " << Y3 << endl;
    

}


Measured memory_bytes: 256
#幅優先探索
from collections import deque
d=deque()
e=deque()
import sys
sys.setrecursionlimit(1000000000)
n=int(input())
start_node=0
querie=[]
edge={i:[]for i in range(1,n+1)}
for j in range(n-1):
    a,b=map(int,input().split())
    querie.append((a,b))
    edge[a].append(b)
    edge[b].append(a)
    if j==0:
        start_node=a  

d.append((start_node,0))

#はじめにdequeに入れておいて幅優先探索を行うものを決める。そして、塗り分けの結果はans_dictに保存する
#print(edge) 
ans_dict={i:{}for i in range(1,n+1)}
K=0
for some in edge.values():
    K=max(K,len(some))
    
#幅優先探索に使用する すでに訪れたか確認するためのリスト

visited=[False for i in range(n+1)]
visited[start_node]=True

#使う頂点の数を記録した
#nodeをリスト型にしたリストを返す
#start_nodeを記録しておく
def determine_edge_color(node,color):
    new_color=0
    for some in edge[node]:
        if visited[some]==False:
            visited[some]=True
            new_color+=1
            if new_color==color:
                new_color+=1
                ans_dict[node][some]=new_color
                ans_dict[some][node]=new_color
                e.append((some,new_color))
            else:
                ans_dict[node][some]=new_color
                ans_dict[some][node]=new_color
                e.append((some,new_color))
        else:
            pass
            
while d:
    for some in d:
        if visited[some[0]]==True:
            determine_edge_color(some[0],some[1])
        else:
            determine_edge_color(some[1],some[0])
    d=e
    e=deque()
    
#ans_dictの完成
print(K)
#答えの出力
for item in querie:
    a,b=item[0],item[1]
    print(ans_dict[a][b])

Measured memory_bytes: 125284
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI3(X, A, B);
  print((B - A <= 0) ? "delicious" : (B - A > X) ? "dangerous" : "safe");
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        List<Integer> list = new ArrayList<Integer>();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int sum = 0 ;
        for(int i=0;i<n;i++){
            int p = sc.nextInt();
            list.add(p);
        }
        Collections.sort(list);
        for(int i=0;i<k;i++){
            sum+=list.get(i);
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 38776
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    char[] S = scanner.next().toCharArray();
    int c0 = 0;
    int c1 = 0;
    for (char c : S) {
      if (c == '0') c0++;
      else c1++;
    }
    System.out.println(Math.min(c0, c1) * 2);
  }
}


Measured memory_bytes: 26324
#include<iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <iterator>
#include <algorithm>
using namespace std;

int main()
{
	int A, B, C;
	int K;
	int max;
	int ans;

	cin >> A >> B >> C;
	cin >> K;

	vector<int> v;

	v.push_back(A);
	v.push_back(B);
	v.push_back(C);
	sort(v.begin(), v.end());
	max = v[2];
	ans = max;
	for (int i = 0; i < K; ++i)
	{
		ans *= 2;
	}

	ans += v[0] + v[1];

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
def main():
    
    a,b,k = map(int, input().split())

    if a <= k:
        k -= a
        a = 0
        if b <= k:
            b = 0
        else:
            b -= k
    else:
        a -= k
    
    print(a, b)
        


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(k+1)
for i in range(1,k+1):
  for j in range(len(li)):
    if i-li[j]<0:
      continue
    if dp[i-li[j]]==False:
      dp[i]=True
      break
if dp[k]==True:
  print("First")
else:
  print("Second")
  
  


Measured memory_bytes: 42348
import java.util.Scanner;

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

	String t = scan.next();

	int len = 0;
	for(int i = 0; i < t.length(); i++){
	    if(t.charAt(i) == 'A' || t.charAt(i) == 'C' ||
	       t.charAt(i) == 'G' || t.charAt(i) == 'T'){
		int count = 1;
		for(int j = i+1; j < t.length(); j++){
		    if(t.charAt(j) == 'A' || t.charAt(j) == 'C' ||
		       t.charAt(j) == 'G' || t.charAt(j) == 'T'){
			count++;
		    }else{
			break;
		    }
		}
		if(len < count){
		    len = count;
		}
	    }
	}

	System.out.println(len);
    }
}


Measured memory_bytes: 23764
import math

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

sX = sum(X)
kouho1 = math.ceil(sX / N)
kouho2 = sX // N
kouho3 = math.floor(sX / N)


ans1, ans2, ans3 = 0, 0, 0
for p in X:
    ans1 += (p - kouho1) ** 2
    ans2 += (p - kouho2) ** 2
    ans3 += (p - kouho3) ** 2

print(min(ans1, ans2, ans3))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define llrep(i,j,k) for(long long int i=j;i<(long long int)k;i++)
#define Sort(x) sort(x.begin(),x.end()); 
#define vi vector<int>
#define vvi vector<vector<int>> 
#define ll long long
int mod=1e9+7;
const int INF = 1e9;

using namespace std;



int main(void) {
	char a, b;
	cin >> a >> b;
	if ((int)a < (int)b)cout << "<" << endl;
	else if ((int)a > (int)b)cout << ">" << endl;
	else cout << "=" << endl;


	return 0;
}

Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
//RHYTHM_086_NS_01
//ALAN_IS_ON....

#include <bits/stdc++.h>

#define     boost_              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define     iter_(i,n)          for (int i = 0; i < int(n); i++)
#define     for_n(i, n)         for (int i = 1; i <= int(n); i++)
#define     pb                  push_back
#define     mp                  make_pair
#define     itr                 ::iterator
#define     s_sort(s)           sort(s.begin(),s.end())
#define     n_sort(a)           sort(a,a+n)
#define     thank_you           return 0
#define     precise_impact      cout<<setprecision(10)<<fixed;

using namespace std;

typedef long long int ll;
typedef double db;
#define MOD 1000000007

ll bigmod(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll tm=bigmod(a,b/2);
    tm=(tm*tm)%MOD;
    if(b%2==1)
        tm=(tm*a)%MOD;
    return tm;

}
void solve();


int main()
{
    boost_;
    precise_impact;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Here we go...
    solve();

    thank_you;
}


void solve()
{
    string a,b;
    cin>>a>>b;
    int count=0;
    iter_(i,a.size()){
        if(a[i]!=b[i])
            count++;
    }
    cout<<count<<endl;
}



Measured memory_bytes: 3784