akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  k = int(input())
  a = 0
  for i in range(k):
    a = (10 * a + 7) % k
    if a == 0:
      print(i+1)
      return 
  print(-1)
  
if __name__=='__main__':
  main()


Measured memory_bytes: 8872
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int x1,x2,y1,y2,temp1,temp2;
  cin >> x1 >> y1 >> x2 >> y2;
  temp1 = y2 - y1;
  temp2 = x2 - x1;
  cout << x2-temp1 << " " << y2+temp2 << " " << x2-temp1-temp2 << " " << y2+temp2-temp1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll k;cin>>s>>k;
  bool fl=true;
  if(s.size()!=1)
  for(int i=0;i<s.size()-1;i++){
    if(s[i]!=s[i+1])fl=false;
  }
  if(s.size()==1){
    cout<<k/2<<endl;
  }else if(fl){
    cout<<(s.size()*k)/2<<endl;
  }else if(k==1){
     map<ll,ll>cnt;
      ll ans=0;
      ll n=s.size();
      ll cntt=1;
      for(int i=1;i<n;i++){
	if(s[i-1]==s[i]){
	  cntt++;
	}else{
	  cnt[cntt]++;
	  cntt=1;
	}
      }
      ll one=0;
      cnt[cntt]++;
      for(auto a:cnt){
	one+=(a.F/2)*a.S;
      }
      cout<<one<<endl;
  }else if(k<110){
    for(int i=0;i<k-1;i++)
      s+=s;
    map<ll,ll>cnt;
    ll ans=0;
    ll n=s.size();
    ll cntt=1;
    for(int i=1;i<n;i++){
      if(s[i-1]==s[i]){
	cntt++;
      }else{
	cnt[cntt]++;
	cntt=1;
      }
    }
    ll one=0;
    cnt[cntt]++;
    for(auto a:cnt){
      one+=(a.F/2)*a.S;
    }
    cout<<one<<endl;
  }else{
    string ss="";
    vi num(110);
    for(int j=0;j<3;j++){
      ss+=s;
      map<ll,ll>cnt;
      ll ans=0;
      ll n=ss.size();
      ll cntt=1;
      for(int i=1;i<n;i++){
	if(ss[i-1]==ss[i]){
	  cntt++;
	}else{
	  cnt[cntt]++;
	  cntt=1;
	}
      }
      ll one=0;
      cnt[cntt]++;
      for(auto a:cnt){
	one+=(a.F/2)*a.S;
      }
      num[j]=one;
    }
    // cout<<"!"<<endl;
    ll plus=0;
    //cout<<num[0]<<" "<<num[2]-num[1]<<endl;
    if(s.back()==s[0]){
      ll hoge=1;
      for(int i=s.size()-2;i>=0;i--){
	if(s[i]==s[i+1])hoge++;
	else break;
      }
      if(hoge%2){
	s=s[0]+s;
      }

    }
    map<ll,ll>cnt;
    ll ans=0;
    ll n=s.size();
    ll cntt=1;
    for(int i=1;i<n;i++){
      if(s[i-1]==s[i]){
	cntt++;
      }else{
	cnt[cntt]++;
	cntt=1;
      }
    }
    ll one=0;
    cnt[cntt]++;
    for(auto a:cnt){
      one+=(a.F/2)*a.S;
    }
    plus+=one;
    cout<<(ll)(num[0]+(num[2]-num[1])*(k-2)+plus)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val h = sc.nextInt()
    val w = sc.nextInt()
    val k = sc.nextInt()
    val s = Array(h) { Array(w) { '.' } }
    for (i in 0 until h) {
        val _s = sc.nextLine()
        for (j in 0 until w) {
            s[i][j] = _s[j]
        }
    }
    var ans = 0L
    for (i in 0 until 1.shl(h)) {
        for (j in 0 until 1.shl(w)) {
            val r = Array(h) { false }
            val c = Array(w) { false }
            for (x in 0 until h) {
                if ((1.shl(x) and i) != 0) {
                    r[x] = true
                }
            }
            for (y in 0 until w) {
                if ((1.shl(y) and j) != 0) {
                    c[y] = true
                }
            }
            var count = 0
            for (a in 0 until h) {
                for (b in 0 until w) {
                    if (s[a][b] == '#' && !r[a] && !c[b]) {
                        count++
                    }
                }
            }
            if (count == k) {
                ans++
            }
        }
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 36672
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
ll ans=0;
 for(ll i=1;i<=N;i++) {
ll A=N/i;
   if(N%i==0) {
A--;
   }
   ans+=A;
 }
  cout<<ans<<endl;
}
        
        
        
        


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int N,l;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>l; mp[l]++;
    }
    bool flag=true;
    if(N&1){
        if(mp[0]!=1)flag=false;
        for(int i=1;2*i+1<=N;i++){
            if(mp[2*i]!=2)flag=false;
        }
        
    }else{
        for(int i=0;2*i+1<=N;i++){
            if(mp[2*i+1]!=2)flag=false;
        }
    }
    if(!flag){
        cout<<0<<"\n";
        return 0;
    }
    ll ans=1;
    if(N&1){
        for(int i=0;i<(N-1)/2;i++)ans=(ans*2)%MOD;
    }else{
        for(int i=0;i<N/2;i++)ans=(ans*2)%MOD;
    }
    
    cout<<ans<<"\n";
    
    return 0;
}


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

using namespace std;

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long q, h, s, d;
	cin>>q>>h>>s>>d;
	
	long n;
	cin>>n;
	
	long long one, two;
	
	one = min(s, 2*min(2*q, h));
	two = min(d, 2*one);
	
	long long ans = (n/2)*two;
	n %= 2;
	ans += n*one;
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
 
const int MX = 200005;
int in[MX], out[MX], t[MX], k;
vector<int> to[MX];
int dfs(int v, int p=-1) {
  in[v] = k++;
  t[v] = 1;
  for (int u : to[v]) {
    if (u == p) continue;
    t[v] += dfs(u,v);
  }
  out[v] = k;
  return t[v];
}
 
vector<int> vs[MX];
 
ll c2(ll n) { return n*(n+1)/2;}
 
int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  rep(i,n) cin >> c[i];
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  rep(i,n) vs[c[i]-1].push_back(i);
  ll tot = c2(n);
  BIT<int> d(n);
  rep(i,n) d.add(i,1);
  rep(i,n) {
    ll ans = tot;
    vector<int>& nvs = vs[i];
    sort(nvs.begin(), nvs.end(), [&](int a, int b) {
      return in[a] > in[b];
    });
    vector<P> history;
    for (int v : nvs) {
      int cnt = 1;
      for (int u : to[v]) {
        if (in[u] < in[v]) continue;
        int num = d.sum(in[u], out[u]);
        ans -= c2(num);
        // printf("u, v, num: %d %d %d\n", u,v,num);
        cnt += num;
      }
      d.add(in[v], -cnt);
      history.emplace_back(in[v], cnt);
    }
    ans -= c2(d.sum(0,n));
    for (auto p : history) {
      d.add(p.first, p.second);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 39096
#include<stdio.h>
#define N 100

int main(){
  int i,j,k,n,v,a[N+1][N+1];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=0;
    }
  }
      
    
  for(i=0;i<n;i++){
    scanf("%d%d",&i,&k);
    i--;
    for(j=0;j<k;j++){
    scanf("%d",&v);
    a[i][v-1]=1;
    
  }
    
  }
  
    
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=n-1)printf("%d ",a[i][j]);
      else printf("%d\n",a[i][j]);
    }
  }
  return 0;
}




Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;

int main(){
    int x, y, z;
    cin>>x>>y>>z;
    swap(x, y);
    swap(x, z);
    cout<<x<<" "<<y<<" "<<z<<endl;
    return 0;
}














Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <ctime>
#include <fstream>
#include <cmath>
#include <unordered_map>

using namespace std;

#ifndef LOCAL
#define cerr if(0)cerr
#endif

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC);

typedef long long ll;
typedef long double ld;

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

#define FILE "palindrome"


int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    //    freopen(FILE".in", "r", stdin); freopen(FILE".out", "w", stdout);
    //    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<ll> cnt(n + 10);
    for (int i = 1; i <= n; i++) {
        cin >> cnt[i];
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!cnt[i]) continue;
        ll mn = min(cnt[i - 1], cnt[i]);
        cnt[i] -= mn;
        cnt[i - 1] -= mn;
        ans += mn;
        mn = cnt[i] / 2;
        ans += mn;
        cnt[i] -= mn * 2;
    }
    cout << ans;
    RT;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main(void){
	int h, w; cin >> h >> w;
	string ans; int num;
	rep(i, h) rep(j, w){
		string s; cin >> s;
		if(s == "snuke"){
			ans = 'A' + j;
			num = i + 1;
		}
	}
	cout << ans << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<int> l(26,0);
    rep(i,0,h*w){
        char a;
        cin>>a;
        l[a-'a']++;
        l[a-'a']%=4;
    }
    
    vector<int> mod4(4,0);
    rep(i,0,26) mod4[l[i]]++;
    
    if(h%2==0 && w%2==0){
        cout<<(mod4[0]==26 ? "Yes" : "No")<<endl;
    }
    else if(h%2==1 && w%2==1){
        if(mod4[1]+mod4[3]!=1) cout<<"No"<<endl;
        else{
            if(mod4[1]==3) mod4[2]++;
            
            cout<<(mod4[2]<=(h/2+w/2) ? "Yes" : "No")<<endl;
        }
    }
    else{
        if(mod4[1]+mod4[3]!=0) cout<<"No"<<endl;
        else cout<<(mod4[2]<=(h%2==0 ? h/2 : w/2) ? "Yes" : "No")<<endl;
    }
}



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

struct trip
{
    int fi,se,th;
};

bool operator <(const trip& x, const trip& y) {
        return std::tie(x.fi, x.se, x.th) < std::tie(y.fi, y.se, y.th);
}

struct fenwickTree
{
private:
    int n;
    vector<int> v;
public:
    fenwickTree(int n)
    {
        this -> n = n;
        int i;
        for(i=0;i<n;i++)
            v.push_back(0);
    }
    int query(int r)
    {
        int cur = 0;
        for(;r>=0;r = (r&(r+1))-1)
            cur+=v[r];
        return cur;
    }
    int query(int l, int r)
    {
        return query(r)-query(l-1);
    }
    void add(int idx, int val)
    {
        for(;idx<=n;idx = idx|(idx+1))
            v[idx]+=val;
    }
    void rep(int idx, int val)
    {
        int cha = val - query(idx,idx);
        add(idx,cha);
    }
    void print()
    {
        int i;
        for(i=0;i<n;i++)
            cout<<query(i,i)<<" ";
        cout<<"\n";
    }
};

int main()
{
    int n,q,i,j;
    cin>>n>>q;
    int ans[q];
    int val[n];
    int last[n];
    vector<trip> ve;
    fenwickTree thisTree(n);
    for(i=0;i<n;i++)
    {
        int a;
        cin>>a;
        val[i] = a-1;
        last[i] = -1;
    }
    for(i=0;i<q;i++)
    {
        int a,b;
        cin>>a>>b;
        ve.push_back({b-1,a-1,i});
    }
    sort(ve.begin(),ve.end());
    int pointer = 0;
    for(i=0;i<n;i++)
    {
        int cur = last[val[i]];
        if(cur != -1)
        {
            thisTree.rep(cur,0);
        }
        last[val[i]] = i;
        thisTree.rep(i,1);
        while(pointer < q && ve[pointer].fi <= i)
        {
            int l = ve[pointer].se;
            int r = ve[pointer].fi;
            ans[ve[pointer].th] = thisTree.query(l,r);
            pointer++;
        }
    }
    for(i=0;i<q;i++)
    {
        cout<<ans[i]<<"\n";
    }
}


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

long long ans = 1e18, harga[13];
int algo[13],A[13][13],N,M,X;

void rec(int idx,long long total){
  bool valid = true;
  if(idx > N){
    for(int i = 1;i <= M;i++){
      if(algo[i] < X)
        valid = false;
    }
    if (valid) ans = min(ans, total);
  } else {
    for(int i = 1;i <= M;i++){
      algo[i] += A[idx][i];
    }
    rec(idx + 1,total + harga[idx]);
    for(int i = 1;i <= M;i++){
      algo[i] -= A[idx][i];
    }
    rec(idx + 1,total);
  }
}

int main() {
    cin>>N>>M>>X;
    for(int i = 1;i <= N;i++){
      cin>>harga[i];
      for(int j = 1;j <= M;j++){
        cin>>A[i][j];
      }
    }
    rec(1,0);
    if(ans == 1e18){
      cout<< -1 <<endl;
    }else{
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int ans = 100000;
    rep(i, W+1){
        if(i == W) ans = min(ans, W);
        else{
            int j;
            if(N < i*H) j = 0;
            elif((N-i*H)%(W-i) == 0) j = (N-i*H)/(W-i);
            else j = (N-i*H)/(W-i) + 1; 
            ans = min(ans, i+j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main
import "fmt"
func main(){
    // Your code here!
    var n, k int64
    fmt.Scan(&n, &k)
    n = n - ((n / k) * k)
    var t = n
    for ;;{
        n = abs((n-k))
        if n >= t{
            fmt.Println(t)
            return
        }
        t = n
        
    }
   
}

func abs(v int64) int64{
    if v < 0{
        return -v
    }else{
        return v
    }
}


Measured memory_bytes: 512
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	int32_t A, B;
	char op;

	scanf("%"PRId32" %c %"PRId32, &A, &op, &B);

	printf("%"PRId32, (op == '+' ? A + B : A - B));

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<i32> A(N, 100001);
    Vec<i32> B(N - 1);
    for (i32 i = 0; i < N - 1; i++) cin >> B[i];
    A[0] = A[1] = B[0];
    for (i32 i = 1; i < N - 1; i++) {
        A[i] = min(A[i], B[i]);
        A[i + 1] = B[i];
    }
    i32 sum = 0;
    for (i32 i = 0; i < N; i++) {
        sum += A[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	map<char, int> ms, mt;
	rep(i, s.size()){
		ms[s[i]]++;
	}
	rep(i, t.size()){
		mt[t[i]]++;
	}
	string as, at;
	for(auto p : ms){
		rep(i, p.second){
			as.push_back(p.first);
		}
	}
	deque<char> att;
	for(auto p : mt){
		rep(i, p.second){
			att.push_back(p.first);
		}
	}
	while(!att.empty()){
		at.push_back(att.back());
		att.pop_back();
	}
	// cerr << as << " " << at << endl;
	if(as < at) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main()
{
    int K;
    std::string S;

    scanf("%d", &K );
    std::cin >> S;

    if( S.length() <= K) {
        std::cout << S;
    } else {
        for(int i = 0; i < K; i++){
            printf("%c", S[i]);
        }
    printf("...");
    }

    return 0;
}


Measured memory_bytes: 3228
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
res = [0] * n
def cal(x,y,z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x
for fl in itertools.product(range(1,100),range(1,100),range(1,100)):
    x,y,z = fl
    tmp = cal(x,y,z)
    if n >= tmp:
        res[tmp-1] += 1
print(*res)

Measured memory_bytes: 79580
#[allow(unused_macros)]
macro_rules! debug {
  ($($e:expr), *) => {println!(concat!($(stringify!($e), " = {:?}\n"), *), $($e), *)}
}

fn main() {
  let s = get::val::<String>();
  
  let replace = |c| {
    match c {
      'p' => 'q',
      'q' => 'p',
      'b' => 'd',
      'd' => 'b',
      _ => unreachable!()
    }
  };

  let r = s.chars().rev().map(replace).collect::<String>();
  let ans = if s == r {"Yes"} else {"No"};

  println!("{}", ans)
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
long long int calc(long long int year) {
	long long int val = 100*pow(1.01,year);
	return val;
}
int main() {
	long long int x,val,val1;
	cin >> x;
	int ans = 1;
	val = calc(1);
	while(val<x) {
		ans++;
		val = val*(1.01);
	}
	cout << ans;
}

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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	char left = s.at(n - 1);
	char right = s.at(0);
	int ans_left = 0;
	int ans_right = 0;
	for(int i = n - 2; i >= 0; i--){
		if(s.at(i) != left){
			ans_left += 1;
			left = s.at(i);
		}
	}
	for(int i = 1; i < n; i++){
		if(s.at(i) != right){
			ans_right += 1;
			right = s.at(i);
		}
	}
	cout << min(ans_left, ans_right) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <climits>
#include <cmath>
#include <stdio.h>

using namespace std;

int main()
{
    string n; cin >> n;
    long long ans = 0;
    for (int i = 0; i < n.length(); i++)
    {
        ans += n[i] - '0'; 
    }
    cout << ((ans % 9 == 0) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3728
fun main(args: Array<String>) {
    abc143e()
}

private data class Distance(val from: Int, val to: Int, val cost: Int)
private data class Query(val from: Int, val to: Int)

fun abc143e() {
    val (n, m, l) = readLine()!!.split(" ").map { it.toInt() }
    val lines = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
        .map { Distance(it[0] - 1, it[1] - 1, it[2]) }
    val q = readLine()!!.toInt()
    val queries = (1..q).map { readLine()!!.split(" ").map { it.toInt() - 1 } }
        .map { Query(it[0], it[1]) }

    // 町iから町jへの移動距離
    val distances = Array(n) { IntArray(n) { Int.MAX_VALUE / 2 } }

    lines.forEach { line ->
        distances[line.from][line.to] = line.cost
        distances[line.to][line.from] = line.cost
    }

    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                distances[i][j] = Math.min(distances[i][j], distances[i][k] + distances[k][j])
            }
        }
    }

    // 町iから町jへ移動するための最低燃料補給回数
    val fuelRefills = Array(n) { IntArray(n) { Int.MAX_VALUE / 2 } }

    distances.forEachIndexed { from, tos ->
        tos.forEachIndexed { to, cost ->
            if (cost <= l) fuelRefills[from][to] = 1
        }
    }

    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                fuelRefills[i][j] = Math.min(fuelRefills[i][j], fuelRefills[i][k] + fuelRefills[k][j])
            }
        }
    }

    val answer = queries.map { query ->
        fuelRefills[query.from][query.to].let { if (it == Int.MAX_VALUE / 2) -1 else it - 1 }
    }.joinToString(System.lineSeparator())

    println(answer)
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) A = 14;
  if (B == 1) B = 14;

  if (A > B) cout << "Alice" << endl;
  if (A == B) cout << "Draw" << endl;
  if (A < B) cout << "Bob" << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    class Heap
    {
        public int[] Que = new int[10000];
        public int p = 0;
        public void Add(int _x)
        {
            p++;
            Que[p] = _x;
            if (p == 1) return;
            int _p = p;
            while (Que[_p] > Que[_p / 2])
            {
                int swap = Que[_p];
                Que[_p] = Que[_p / 2];
                Que[_p / 2] = swap;
                _p = _p / 2;
                if (_p == 1) break;
            }
        }
        public void Ans()
        {
            int ans = Que[1] - 1;
            for (int ii = 2; ii <= p; ii++) ans = ans - Que[ii];
            if (ans > 0) Console.WriteLine(ans);
            else Console.WriteLine(0);
        }
    }
    static void Main()
    {
        Heap H = new Heap();
        string[] input = Console.ReadLine().Split(' ');
        int k = int.Parse(input[0]);
        int t = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < t; i++) H.Add(int.Parse(input[i]));
        H.Ans();
    }
}


Measured memory_bytes: 2728
n = int(input())
p = [int(x) for x in input().split()]
k = 0

for i in range(len(p) - 2):
  k += 1 if min(p[i:i+3]) != p[i+1] and max(p[i:i+3]) != p[i+1] else 0
  
print(k)

Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int d, n; cin >> d >> n;
    vector<int> t(d);
    for (int &ti: t) cin >> ti;
    vector<int> a(n), b(n), c(n);
    for (int j = 0; j < n; j++) cin >> a[j] >> b[j] >> c[j];
    vector<vector<int>> dp(d, vector<int>(n, -1));
    #define in(a, b, c) (a <= b && b <= c)
    for (int j = 0; j < n; j++) if (in(a[j], t[0], b[j])) dp[0][j] = 0;
    for (int i = 1; i < d; i++) {
        for (int j = 0; j < n; j++) if (dp[i - 1][j] != -1) {
            for (int nj = 0; nj < n; nj++) if (in(a[nj], t[i], b[nj])) {
                chmax(dp[i][nj], dp[i - 1][j] + abs(c[nj] - c[j]));
            }
        }
    }
    int ma = 0;
    for (int j = 0; j < n; j++) chmax(ma, dp[d - 1][j]);
    cout << ma << endl;
    return 0;
}


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

#define IN inline
#define CO const
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

int main(){
	int n=read<int>(),ans=0;
	for(int i=1;i<=n;++i) ans+=read<int>()%2==1 and i%2==1;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
double dist(double x,double y){
  return sqrt(x*x+y*y);
}

int main(){
  int N;cin>>N;
  vector<double> X(N),Y(N);
  for(int i=0;i<N;i++)cin>>X[i]>>Y[i];
  double ans=0;
  
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      ans+=dist(X[i]-X[j],Y[i]-Y[j]);
    }
    
  }
  cout<<fixed<<setprecision(10)<<ans/N;

  
  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,flag=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]%2==0)
    {
      if(a[i]%3!=0&&a[i]%5!=0)
      {   flag=1;
      break;}
    }
  }
  if(flag==1)
    cout<<"DENIED";
  else
    cout<<"APPROVED";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;


double solve(int64_t R) {
    // TODO: edit here
    return (double) R*M_PI*2;
}

// generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    constexpr char endl = '\n';
    int64_t R;
    cin >> R;
    auto ans = solve(R);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n + 1);
	for(int i = 0; i <= n; ++i){ cin >> a[i]; }
	ll answer = 0, cur = 1, target = accumulate(a.begin(), a.end(), 0ll);
	for(int i = 0; i <= n && answer >= 0; ++i){
		if(cur < a[i]){
			answer = -1;
			break;
		}
		answer += cur;
		cur    -= a[i];
		target -= a[i];
		cur     = min(cur * 2, target);
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 4052
/*	
*  Sachin Mittal
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,j,n) for(int i=j;i<n;i++)
#define F first
#define S second
#define lb lower_bound
#define mem0(dp) memset(dp,0,sizeof(dp))
#define mem1(dp) memset(dp,-1,sizeof(dp))
#define pb push_back
#define sz(s) (int)(s.size())
#define debug(x) cout << #x << " = " << x << '\n';

void solve()
{
    int animals, legs;
    cin >> animals >> legs;
    if(legs % 2 ){
    	cout << "No";
    	return;
    }
    legs /= 2;
    int y = legs - animals;
    int  x = animals - y;
    //cout << x << " " << y << " ";
    if(x >= 0 and y >= 0 and (x + 2 * y == legs)){
    	cout << "Yes";
    }
    else cout << "No";
}

int32_t main(){
ios_base::sync_with_stdio(false); 
cin.tie(0); cout.tie(0);
int tst = 1;
//cin >> tst;
while(tst--)
{
	solve();
}
}

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	
	int n, m;
	cin >> n >> m;
	int a = 1, b = n;

	for (int i = 0; i < m; i++) {

		int x, y;
		cin >> x >> y;
		a = max(x, a);
		b = min(b, y);
	}
	if (b - a+1 > 0)cout << b - a+1 << endl;
	else cout << 0 << endl;


	return 0;



}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from itertools import combinations_with_replacement


def main():
    N, M, Q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for _ in range(Q)]

    result = 0

    for C in combinations_with_replacement(range(1, M + 1), N):
        tmp = sum([d for a, b, c, d in ABCD if C[b - 1] - C[a - 1] == c])
        result = max(result, tmp)
    print(result)


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S;
    cin >> S;
    int cnt = 0;
    int ans = 0;
    REP(i, S.length()) {
        if(S[i] == 'W') {
            ans += i - cnt;
            cnt++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  string n;
  cin >> n;

  cout << (n[0] == n[1] && n[1] == n[2] || n[2] == n[3] && n[1] == n[2] ? "Yes"
                                                                        : "No")
       << "\n";
}

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

int main() {
ll n,a,b;
cin>>n>>a>>b;
if (n%(a+b)<=a)
{
  /* code */
  cout<<a*(n/(a+b))+n%(a+b)<<endl;
}

else
{
  cout<<a*(n/(a+b))+a<<endl;
}

}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

line = input().split(" ")
n = int(line[0])
t = int(line[1])
i = 0
minc= 10000
for j in range(n):
    line2 = input().split(" ")
    linec = int(line2[0])
    linet = int(line2[1])
    if linet <= t:
        if linec < minc:
            minc = linec

if minc == 10000:
    print("TLE")
else:
    print(minc)
  

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <numeric>
using namespace std;
using Int = long long;
#define REP(i, n) for(int i = 0; i < n; i++)
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    int x[3]; REP(i, 3) cin >> x[i];
    int five = 0, seven = 0;
    REP(i, 3) {
        if (x[i] == 5) five++;
        if (x[i] == 7) seven++;
    }
    cout << (five == 2 && seven == 1 ? "YES" : "NO") << endl;
    return 0;
}

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

typedef tuple<double,int64_t,int64_t> T;// ??????/????????????????????°, ??????, ???????????°

int main(){
    int N;
    cin>>N;
    vector<int64_t> H(N+1), A(N+1), D(N+1), S(N+1);
    for(int i=0;i<=N;i++){
        cin>>H[i]>>A[i]>>D[i]>>S[i];
    }
    int64_t damage = 0, firepower = 0;
    vector<T> V;
    for(int i=1;i<=N;i++){
        int64_t fire=max(A[i]-D[0],int64_t(0));
        if(S[i]>S[0])damage+=fire;
        firepower+=fire;
        if(max(A[0]-D[i],int64_t(0))==0&&max(A[i]-D[0],int64_t(0))){
            cout<<-1<<endl;
            return 0;
        }
        int64_t turns=ceil(double(H[i])/(max(A[0]-D[i],int64_t(0))));
        V.emplace_back(double(fire)/turns,fire,turns);
    }
    sort(V.begin(), V.end(),greater<T>());
    for(auto t:V){
        int64_t fire,turns;
        tie(ignore,fire,turns)=t;
        //cout<<fire<<' '<<turns<<endl;
        damage+=firepower*(turns-1);
        firepower-=fire;
        damage+=firepower;
        if(damage>=H[0]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<damage<<endl;
}

Measured memory_bytes: 5696
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long lint;
const int maxn = 1e5+7, mod = 1e9+7;
int n, m, i;
lint v[maxn];
lint fact[maxn], ans;

void dom(int &x) {
    x %= mod;
    if(x < 0) {
        x = mod + (x % mod);
    }
}
void dom(lint &x) {
    x %= mod;
    if(x < 0) {
        x = mod + (x % mod);
    }
}
struct xy {
    lint x, y;
};
xy ee(lint a, lint b) {
    if(b == 0) {
        return {1, 0};
    }
    xy r = ee(b, a % b);
    return {r.y, r.x - (a / b) * r.y};
}

lint im(int x) {
    lint r = ee(x, mod).x;
    dom(r);
    return r;
}

lint comb(lint n, lint k) {
    lint ans = fact[n] * im(fact[k]);
    dom(ans);
    ans *= im(fact[n - k]);
    dom(ans);
    return ans;
}

lint query(lint a, lint b) {
    lint n, k, ans = 1;
    while(a != 0) {
        n = a % mod; k = b % mod;
        if(k > n) { return 0; }
        ans *= comb(n, k); dom(ans);
        a /= mod; b /= mod;
    }
    return ans;
}

int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);

    cin >> n >> m;
    fact[0] = 1;
    for(i = 1; i <= n; i ++) {
        cin >> v[i];
        fact[i] = fact[i-1] * i; dom(fact[i]);
    }
    sort(v+1, v+n+1);
    for(i = n; i >= m; i --) {
        ans += v[i] * query(i - 1, m - 1);
        dom(ans);
    }
    for(i = 1; i <= n - m + 1; i ++) {
        ans -= v[i] * query(n - i, m - 1);
        dom(ans);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict


def readln():
    return list(map(int, input().split()))


N = readln()[0]
S = input()
mod = 10**9+7

dic = defaultdict(lambda: 0)
for s in S:
    dic[s] += 1
ans = 1
for count in dic.values():
    # print(count)
    ans *= (count + 1)
    ans %= mod

# print(ans)
print(ans-1)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int H,W;
  cin >> H >> W;
  vvi d(H,vi(W,INF));
  QP black;
  rep(i,H) {
    string s;
    cin >> s;
    rep(j,W) {
      if(s[j] == '#') {
        black.push(P(i,j));
        d[i][j] = 0;
      }
    }
  }
  int dx[] = {0,0,-1,1};
  int dy[] = {-1,1,0,0};
  int cnt = 0;
  while(!black.empty()) {
    QP black_nxt;
    while(!black.empty()) {
      P p = black.front();
      black.pop();
      int x = p.first;
      int y = p.second;
      rep(i,4) {
        int nx = dx[i] + x;
        int ny = dy[i] + y;
        
        if(nx >= 0 && nx < H && ny >= 0 && ny < W && d[nx][ny] == INF) {
          black_nxt.push(P(nx,ny));
          d[nx][ny] = d[x][y] + 1;
        }
      }
    }
    black = black_nxt;
    cnt++;
  }
  
  cout << cnt - 1 << endl;
  return 0;
}

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

#define si(n) scanf("%d",&n)
#define MAX 200005

deque<int>d;
deque<int>::iterator it;

int arr[MAX],n;

int main()
{
    int i,j;
    bool flag=false;
    si(n);
    for(i=0;i<n;i++)
        si(arr[i]);
    for(i=0;i<n;i++){
        if(flag)d.push_back(arr[i]);
        else d.push_front(arr[i]);
        flag=!flag;
    }
    flag=!flag;
    if(flag){
        it=d.end();
        while(it != d.begin()){
            it--;
            printf("%d ",*it);
        }
    }
    else{
        it=d.begin();
        while(it != d.end()){
            printf("%d ",*it++);
        }
    }
    return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    int ans=0;
    char s[100020];
    scanf("%s",s);
    for (int i=strlen(s)-1; i>=1; i--){
        if (s[i]!=s[i-1]){
            ans++;
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

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


int main(){
    int num;
    stack<int> Train;
    while(cin >> num){
        if(num){
            Train.push(num);
        }else{
            cout << Train.top() << endl;
            Train.pop();
        }
    }

    return 0;
}

Measured memory_bytes: 1200
import itertools
N,M,Q=map(int,input().split())
A=[]
for i in range(Q):
    a=list(map(int,input().split()))
    A.append(a)
ans=0
for i in itertools.combinations_with_replacement(range(1,M+1),N):
    score=0
    for a,b,c,d in A:
        if i[a-1]+c==i[b-1]:
            score=score+d
    ans=max(ans,score)
print(ans)

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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

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

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){
    os << v.first <<" "<<v.second<<endl;
    return os;
}

const int maxn = 55;
const int mod = 1e9+7;

int mult(LL a,LL b){
    return (int)(a*b%mod);
}
int add(LL a,LL b){
    return (int)((a+b)%mod);
}

struct matrix{
    int N;
    vector<vector<LL>> G;
    matrix(){
        G.resize(maxn);
        _for(i,0,maxn) G[i].resize(maxn);
    }

    matrix multm(matrix & o){
        matrix ret;
        ret.N = N;
        _for(i,0,N){
            _for(j,0,N){
                LL ans = 0;
                _for(k,0,N){
                    ans = add(ans,mult(G[i][k],o.G[k][j]));
                }
                ret.G[i][j] = ans;
            }
        }
        return ret;
    }

    int sum(){
        int ans = 0;
        _for(i,0,N){
            _for(j,0,N){
                ans = add(ans,G[i][j]);
            }
        }
        return ans;
    }

};

LL K;
matrix diag;

matrix fpow(matrix &m,LL K){
    if(K == 0) return diag;
    matrix ret = fpow(m,K/2);

    ret = ret.multm(ret);
    if(K&1) ret = ret.multm(m);
    return ret;
}

int main()
{
    matrix m;
    cin >> m.N >> K;
    diag.N = m.N;
    _for(i,0,m.N){
        diag.G[i][i] = 1;
        _for(j,0,m.N){
            cin >> m.G[i][j];
        }
    }
    //cout << (m.multm(m)).sum() << endl;

    matrix p = fpow(m,K);

    cout << p.sum() << endl;
    return 0;
}


Measured memory_bytes: 512
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{  
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String S = I.next();
		int K = I.nextInt();
		int N = S.length();
		StringBuilder ans = new StringBuilder();
		for (int i = 0; i < N-1; i++) { //Always stop at A (operation is only useful when you
			//cycle back to small letters (A being the best)
			//Leftover can be spent on last letter as it weighs the least (optimize important 
			//slots first)
			char cur = S.charAt(i);
			int diff = cur-'a';
			int numBoost = 26-diff; //B takes 25 attempts
			numBoost%=26; //a does not require any operations dummy
			if (numBoost<=K) {
				ans.append('a');
				K-=numBoost;
			}else ans.append(cur); //Keep original
		}
		K%=26; //Taking relevant part if leftover
		int last = S.charAt(N-1)-'a'; //Have to use even if it means worse
		char add = (char)((last+K)%26+'a');
		ans.append(add);
		O.pln(ans);
		
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 29252