akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    a = LI()

    x = collections.defaultdict(int)
    t = [0] * n
    for i in range(n-1,-1,-1):
        t[i] = x[a[i]]
        x[a[i]] = i

    for i in range(n-1,-1,-1):
        t[i] = x[a[i]]
        x[a[i]] = i

    e = n * k
    ei = 0
    i = 0
    while ei < e - n*2:
        j = t[i]
        if j <= i:
            ei += j - i + n + 1
        else:
            ei += j - i + 1
        i = (j + 1) % n
        if i % n == 0:
            ei = e // ei * ei

    r = [0] * n
    ri = 0
    b = {}
    while ei < e:
        c = a[ei%n]
        ei += 1
        if c in b and b[c] < ri and r[b[c]] == c:
            ri = b[c]
            del b[c]
        else:
            r[ri] = c
            b[c] = ri
            ri += 1


    return JA(r[:ri], " ")

print(main())





Measured memory_bytes: 83848
#include<stdio.h>
#include<stdlib.h>
#define N 500000
int cnt=0;
void merge(int *,int,int,int);
void mergesort(int *,int,int);
int main(){
  int n,num[N],i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&num[i]);

  mergesort(num,0,n);
  for(i=0;i<n;i++){
    if(i!=0)
      printf(" ");
    printf("%d",num[i]);
  }
  printf("\n%d\n",cnt);
}
void merge(int num[],int l,int m,int r){
  int i,j,k,n1,n2,*L,*R;
  n1=m-l;
  n2=r-m;
  L=(int *)malloc((n1+1)*sizeof(int));
  R=(int *)malloc((n2+1)*sizeof(int));
  for(i=0;i<n1;i++){
    L[i]=num[l+i];
  }
  for(i=0;i<n2;i++){
    R[i]=num[m+i];
  }
  L[n1]=1000000001;
  R[n2]=1000000001;
  i=0;j=0;
  for(k=l;k<r;k++){
    cnt++;
    if(L[i]<=R[j])
      num[k]=L[i++];
    else
      num[k]=R[j++];
  }
  
}
void mergesort(int num[],int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(num,l,m);
    mergesort(num,m,r);
    merge(num,l,m,r);
  }
}



Measured memory_bytes: 64540
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll POW3(ll x,ll n,ll m){
  x%=m;
  if(n==0)return 1;
  if(n%2==0)return POW3(x*x,n/2,m)%m;
  return x*POW3(x,n-1,m)%m;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)//xのm進数でのx^nの位の値
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)//xのn進数での桁数
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)//x!のnで割り切れる回数
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)//xのnで割り切れる回数
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

ll SGS(ll x,ll y, ll m)//1+x+…+x^(y-1)をmで割った余り
{
  if(y==0)return 0;
  if(y%2==0){
    return (1+POW3(x,y/2,m))*SGS(x,y/2,m)%m;
  }
  return (1+x*SGS(x,y-1,m))%m;
}

ll SSGS(ll x,ll y,ll m)//Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り
{
  if(y==0)return 0;
  if(y==1)return 1;
  if(y%2==0){
    return (SSGS(x,y/2,m)*(POW3(x,y/2,m)+1)%m+SGS(x,y/2,m)*y/2%m)%m;
  }
  return (SSGS(x,y-1,m)*x%m+y)%m;
}

int main()
{
  string s;
  cin >> s;
  ll ans=0;
  rep(i,3)if(s[i]==s[i+1])ans++;
  if(ans==0)printf("Good");
  else printf("Bad");
}

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

const int INF = 1001001001;
    

int main() {
  int N,M,X;
  cin>>N>>M>>X;
  vector<vector<int>> a(N, vector<int>(M));
  vector<int> c(N);
  
  for(int i=0;i<N;i++){
    cin>>c.at(i);
    for(int j=0;j<M;j++){
      cin>>a.at(i).at(j);
    }
  }
  int ans=INF;
  for(int s=0;s<(1<<N);s++){
    bitset<12> d(s);
    vector<int> skill(M);
    int cost=0;
    for (int i = 0; i < N; i++) {
      if (d.test(i)) {
        cost+=c.at(i);
        for(int j=0;j<M;j++){
        skill.at(j)+=a.at(i).at(j);
        }
      }
    }
    bool ok=true;
    for(int j=0;j<M;j++){
      if(skill.at(j)<X) ok=false;
    }
    if(ok) ans=min(ans,cost);
  }
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

template<typename T>
class SegmentTree
{
    private:
        int n;
        vector<T> node, lazy;
    
    public:
        SegmentTree(vector<T> V) {
            int a = V.size();
            n = 1;
            while (n < a) {
                n *= 2;
            }
            node.resize(2 * n - 1);
            lazy.resize(2 * n - 1);

            rep(i, a) {
                node[n - 1 + i] = V[i];
            }
            for (int i = n - 2; i >= 0; i--) {
                node[i] = node[2 * i + 1] + node[2 * i + 2];
            }
        }

        void eval(int k, int l, int r) {
            if (lazy[k] != 0) {
                node[k] += lazy[k];

                if (r - l > 1) {
                    lazy[2 * k + 1] += (lazy[k] / 2);
                    lazy[2 * k + 2] += (lazy[k] / 2);
                }

                lazy[k] = 0;
            }
        }

        void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
            if (r < 0) r = n;
            eval(k, l, r);
            if (r <= a || b <= l) return;
            if (a <= l && r <= b) {
                lazy[k] += (r - l) * x;
                eval(k, l, r);
            }
            else {
                add(a, b, x, 2 * k + 1, l, (l + r) / 2);
                add(a, b, x, 2 * k + 2, (l + r) / 2, r);
                node[k] = node[2 * k + 1] + node[2 * k + 2];
            }
        }

        T get(int a, int b, int k = 0, int l = 0, int r = -1) {
            if (r < 0) r = n;
            if (r <= a || b <= l) return 0; 

            eval(k, l, r);

            if (a <= l && r <= b) return node[k];
            T vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
            return vl + vr;
        }

        void show() {
            cout << "n: " << n << endl;
            rep(i, 2 * n - 1) {
                cout << "i: " << i << ", node[i]: " << node[i] << endl;
            }
        }
};

int main() {
    int N, Q; cin >> N >> Q;
    SegmentTree<ll> sg(vector<ll>(N, 0));

    rep(i, Q) {
        int C;
        cin >> C;

        if (C == 0) {
            int S, T, X;
            cin >> S >> T >> X;
            sg.add(S - 1, T, X);
        } else {
            int S, T;
            cin >> S >> T;
            cout << sg.get(S - 1, T) << endl;
        }
    }
}


Measured memory_bytes: 7556
class FastModComb:

    def __init__(self, n, mod=10 ** 9 + 7):
        f, self.mod = [1], mod
        for i in range(1, n + 1):
            f.append(f[-1] * i % mod)
        rf = [self.modpow(f[-1], mod - 2)]
        for i in range(1, n + 1):
            rf.append(rf[-1] * (n - i + 1) % mod)
        self.f, self.rf = f, list(reversed(rf))

    def modpow(self, a, b):
        ret = 1
        while b > 0:
            if b % 2 == 1:
                ret = ret * a % self.mod
            a = a * a % self.mod
            b //= 2
        return ret

    def modcomb(self, n, c):
        return self.f[n] * self.rf[c] * self.rf[n - c] % self.mod


n, k = map(int, input().split())
mod, mc = 10 ** 9 + 7, FastModComb(n)
print(sum([mc.modcomb(n, m) * mc.modcomb(n - 1, n - m - 1) % mod
           for m in range(min(n - 1, k) + 1)]) % mod)


Measured memory_bytes: 70640
#include <iostream>

int main()
{
  int n;
  std::cin >> n;
  for(auto i=0; i<n; ++i)
  {
    char color;
    std::cin >> color;
    if(color == 'Y')
    {
      std::cout << "Four\n";
      return 0;
    }
  }
  std::cout << "Three\n";
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let x: i32 = read();
    println!("{}", if x < 1200 { "ABC" } else { "ARC" });
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    use std::io::prelude::*;

    let stdin = std::io::stdin();
    let s: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<double> saikoro(n);
  vector<double> s(n + 1);
  s[0] = 0;
  for(int i = 0; i < n; ++i){
    cin >> saikoro[i];
    saikoro[i] = (saikoro[i] + 1) / 2.0;
    s[i + 1] = s[i] + saikoro[i];
  }
  double max_pre = 0;
  for(int i = 0; i <= n - k; ++i){
    max_pre = max(max_pre, s[i+k] - s[i]);
  }
  printf("%.12f\n", max_pre);
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cout<<"LINE ("<< __LINE__ << ") : [" << #__VA_ARGS__ << "] -> ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> a ; 
    string s ;
    cin >> s ;
    int n = (int)s.size() ; 
    for(int i = 0 ; i <= n - 3 ; ++i){
        int number = 0; 
        for (int j = i; j < i + 3; j++){
            number *= 10;
            number += s[j] - '0'; 
        }
        a.push_back(number); 
    }
    int ans = INT_MAX; 
    for (auto &x : a){
        ans = min(ans, abs(x - 753)); 
    }
    cout << ans; 

    return 0;
}




Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
int n, a[maxn];
LL cnt[maxn], ans;
int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        cnt[a[i]]++;
    }
    ans = 0;
    for(int i = 1; i <= n; i++)
        ans += cnt[i]*(cnt[i]-1)/2;
    for(int i = 1; i <= n; i++)
        printf("%lld\n", ans - cnt[a[i]]*(cnt[a[i]]-1)/2 + (cnt[a[i]]-1)*(cnt[a[i]]-2)/2);
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	cin >> n >> k;
	cin >> s;
	if (s[k - 1] == 'A') {
		s[k - 1] = 'a';
	}
	else if (s[k - 1] == 'B') {
		s[k - 1] = 'b';
	}
	else if (s[k - 1] == 'C') {
		s[k - 1] = 'c';
	}
	cout << s << endl;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

  
int main() {

string S;
cin >> S;
vector<bool> flag(3);

for(int i = 0; i < (1 << 3); i++){ 
    int sum = S[0] - '0';
         for(int j = 0; j < 3; j++){ 
            if(i & (1 << j)) {
                sum += S[j + 1] - '0';
                flag[j] = true;
            }else{
                 sum -= S[j + 1] - '0';
                 flag[j] = false;
            }
            } 

    if(sum == 7) {
        for(int i = 0; i <= 4; i++){ 
             if(i < 4)cout << S[i];
             if(i < 3 && flag[i]) cout << '+';
             else if(i < 3 && flag[i] == false) cout << '-';
             if(i == 4) cout << "=7" << endl;
        }
    return 0;    
    }
}



}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long int bound = 1e18;
int main(){
    int n;
    cin >> n;
    vector <long long int> v(n);
    for (int i=0;i<n;++i){
        cin >> v[i];
        if (v[i]==0){
            cout << "0" << endl;
            return 0;
        }
    }
    long long int res = 1;
    for (const auto &k: v){
        if (res > (bound/k)){
            cout << "-1" << endl;
            return 0;
        }
        res *= k;
    }
    cout << res << endl;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;

    char old = s[0];

    long long count = 0;
    bool flag = false;

    long long temp_count = 1;

    for (int i = 1; i < s.size(); i++) {
        if (old == s[i]) {
            temp_count++;
        } else {
            count += temp_count / 3 * 2;
            int mod = temp_count % 3;

            if (mod > 0) {
                count++;
            } 

            if (! flag && mod == 2) {
                flag = true;
            } else if (flag && mod == 2) {
                count++;
                flag = false;
            } else if (mod == 1) {
                flag = false;
            }

            temp_count = 1;
        }
        old = s[i];
    }

    count += temp_count / 3 * 2;
    int mod = temp_count % 3;
    if (mod > 0) {
        count++;
    }
    if (mod > 1) {
        if (flag) {
            count++;
        } 
    }

    cout << count;
}

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

int N, K, dots[2001][2001], best;

int count(int x1, int y1, int x2, int y2) {
    return dots[x2][y2] - dots[x2][y1] - dots[x1][y2] + dots[x1][y1];
}

int main() {
    cin >> N >> K;

    for (int i = 1; i <= N; ++i) {
        char c;
        int x, y;
        cin >> x >> y >> c;

        if (c == 'W') {  // (x, y, 'W') == (x, y + K, 'B')
            y += K;
        }

        // (x, y) == (x, y + 2 * K) == (x + 2 * K, y)
        dots[x % (2 * K) + 1][y % (2 * K) + 1] += 1;
        // Now, 1 <= x, y <= 2 * K.
    }

    // accumulation
    for (int x = 1; x <= 2 * K; ++x) {
        for (int y = 1; y <= 2 * K; ++y) {
            dots[x][y] += dots[x - 1][y] + dots[x][y - 1] - dots[x - 1][y - 1];
        }
    }

    // For each painting.
    for (int x = 1; x <= K; ++x) {
        for (int y = 1; y <= K; ++y) {
            int sum = 0;
            sum += count(0, 0, x, y);
            sum += count(x, y, K + x, K + y);
            sum += count(K + x, K + y, 2 * K, 2 * K);
            sum += count(K + x, 0, 2 * K, y);
            sum += count(0, K + y, x, 2 * K);
            sum = max(N - sum, sum);
            best = max(best, sum);
        }
    }

    cout << best << endl;
}


Measured memory_bytes: 15872
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    putchar_unlocked(x[i]);
  }
}
template<class T> int runLength(int N, T *arr, T *val = NULL, int *len = NULL){
  int i;
  int rN;
  if(N==0){
    return 0;
  }
  if(val==NULL || len==NULL){
    void *mem = wmem;
    walloc1d(&val, N, &mem);
    walloc1d(&len, N, &mem);
  }
  rN = 1;
  val[0] = arr[0];
  len[0] = 1;
  for(i=(1);i<(N);i++){
    if(val[rN-1] == arr[i]){
      len[rN-1]++;
    }
    else{
      val[rN] = arr[i];
      len[rN] = 1;
      rN++;
    }
  }
  return rN;
}
int N;
char S[100001];
int main(){
  wmem = memarr;
  rd(N);
  rd(S);
  wt_L(runLength(N,S));
  wt_L('\n');
  return 0;
}
// cLay varsion 20191027-1

// --- original code ---
// int N; char S[100001];
// {
//   rd(N,S);
//   wt(runLength(N,S));
// }


Measured memory_bytes: 896
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

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

void Main(){
    int N;
    cin >> N;
    vec<long double> A(N);
    long double ans = 0;
    REP(i, N){
        cin >> A[i];
        ans += 1.0/A[i];
    }
    cout << 1.0/ans << el;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
 
long long fac[MAX], finv[MAX], inv[MAX];
 



int main() {
	int N,D; cin >> N >> D;
	int ans = 0;
	int A[N+5][D+5] = {};
	rep(i,N)
	{
		rep(j,D)
		{
			cin >> A[i][j];
		}
	}
	rep(i,N)
	{
		FOR(j,i+1,N)
		{
			int d = 0;
			rep(p,D)
			{
			d += abs(A[i][p]-A[j][p])*abs(A[i][p]-A[j][p]);
			}
			rep(q,50*D){if(q*q == d){ans++; break;}}
		}
	}


	cout << ans << endl;
}



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

int main()
{
  int a,b;
  int sum = 0;
  cin>> a >> b;
  for (int i = a; i <= b; i++){
    if(i % 10 == i/10000 && (i % 100) / 10 == i / 1000 - 10*(i/10000)){
      sum++;
    }
  }
  cout << sum <<endl;
}

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

int N;
int A[201];

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

  while (true) {
    bool flag = false;
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 == 0) {
        A[i] /= 2;
      } else {
        flag = true;
      }
    }
    if (flag) break;
    res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n, m; cin >> n >> m;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  sort(a.rbegin(),a.rend());

  auto ok = [&](int key){
    int res = 0;
    for(int i = 0; i < n; i++){
      int left = -1, right = n;
      while(right - left > 1){
        int mid = (left + right) / 2;
        (a[i] + a[mid] >= key ? left : right) = mid;
      }
      res += right;
    }
    return res >= m;
  };

  int left = -1, right = INF;
  while(right - left > 1){
    int mid = (left + right) / 2;
    (ok(mid) ? left : right) = mid;
  }

  vector<int> imos(n+1, 0);
  for(int i = 0; i < n; i++){
    imos[i+1] = imos[i] + a[i];
  }
  int ans = 0, key = left, cnt = 0;
  for(int i = 0; i < n; i++){
    int left = -1, right = n;
    while(right - left > 1){
      int mid = (left + right) / 2;
      (a[i] + a[mid] >= key ? left : right) = mid;
    }
    ans += imos[right] + a[i] * right;
    cnt += right;
  }
  ans -= key * (cnt - m);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define MAXN 100000
#define MAXM 200005
#define INF 0x3f3f3f3f
#define LL long long
int n,m;
/*struct node{
	int v,w;
};*/
vector<pair<int,int> >G[MAXN*5+5];
map<int,int> no[MAXN+5];
int dist[MAXN*5+5];
bool vis[MAXN*5+5];
void sp()
{
	fill(dist,dist+MAXN*5+5,INF);
	dist[1]=0;
	vis[1]=0;
	queue<int> que;
	que.push(1);
	while(!que.empty())
	{
		int u=que.front();
		que.pop();
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].first,w=G[u][i].second;
			if(dist[v]>dist[u]+w)
			{
				dist[v]=dist[u]+w;
				if(!vis[v])
				{
					vis[v]=1;
					que.push(v);
				}
			}
		}
		vis[u]=0;
	}
}
int main()
{
	//freopen("trip.in","r",stdin);
	//freopen("trip.out","w",stdout);
	scanf("%d %d",&n,&m);
	int uu,vv,c,cnt=n;
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d %d",&uu,&vv,&c);
		if(!no[uu].count(c)) no[uu][c]=++cnt;
		if(!no[vv].count(c)) no[vv][c]=++cnt;
		int nu=no[uu][c],nv=no[vv][c];
		G[uu].push_back(make_pair(nu,1));
		G[nu].push_back(make_pair(uu,1));
		G[vv].push_back(make_pair(nv,1));
		G[nv].push_back(make_pair(vv,1));
		G[nu].push_back(make_pair(nv,0));
		G[nv].push_back(make_pair(nu,0));
	}
	sp();
	if(dist[n]==INF)
		dist[n]=-1;
	else dist[n]/=2;
	printf("%d\n",dist[n]);
	return 0;
}


Measured memory_bytes: 56320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;


ll fact(int x){
  ll ans=1;
  for(ll i=1; i<=x; i++) ans = ans*i%MOD;
  return ans;
}
int main(){
  int a, b; cin >> a >> b;
  ll ans=0;
if(abs(a-b)<=1){
    ans = fact(a)*fact(b)%MOD;
    if(a==b) ans = ans*2%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from itertools import product
from collections import defaultdict
n = int(input())
s = input()
sa,sb = s[:n],s[n:][::-1]
a,b,ans = defaultdict(int),defaultdict(int),0
for i in product(range(2),repeat=n):
	wa,wb,wa2,wb2 = "","","",""
	for j in range(n):
		if i[j]: wa,wb = wa+sa[j],wb+sb[j]
		else: wa2,wb2 = wa2+sa[j],wb2+sb[j]
	a[(wa,wa2)]+=1
	b[(wb,wb2)]+=1
while a:
	p,q = a.popitem()
	ans+=q*b[p]
print(ans)

Measured memory_bytes: 150632
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
int arr[100005];
int arr2[100005];
//ll Pow(ll base , ll power)
//void sieve_eratosthenes(int n);
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string a;
cin>>a;
if(a.size()<6)
        {cout<<"NO"<<endl;
        return 0 ;}
if(a[2]==a[3]&&a[4]==a[5])
        cout<<"Yes";
        else
            cout<<"No"<<endl;
        return  0 ;
}

/*
void sieve_eratosthenes(int n)
    {
bool primes[n+2]={false};
for(int i=3;i<=n;i+=2)
    primes[i]=1;
    primes[2]=1;
for(int i=3;i*i<=n;i+=2)
{
    if(primes[i]==1){
    for(int j=i*i;j<=n;j+=i)
        primes[j]=0;
    }
}
for(int i=2;i<=n;i++)
    if(primes[i]==1)
    cout<<i<<endl;
return;
    }
ll Pow(ll base , ll power)
        {
            if(power==0)return 1;
            ll x = Pow(base,power/2);
            x*=x;
            if(power&1)
                return base*x;
            else
                return x;
        }
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)
 
signed main(){
  int N;
  cin>>N;
  int ans=0;
  rep(i,N){
    int M;
    cin>>M;
    ans+=(M-1);
  }
  cout<<ans<<endl;
}

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

int main() {
    int n; cin >> n;
    vector<int> h(n);
    for (int &hi: h) cin >> hi;
    int ans = 0, pt = 0;
    while (pt < n) {
        int cur = pt;
        bool flag = false;
        while (cur < n && h[cur]) {
            h[cur++]--;
            flag = true;
        }
        ans += flag;
        while (pt < n && h[pt] == 0) pt++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long k,n,sum=0;
  long long a[1000005];
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    sum+=a[i];
  }
  sort(a, a+n, greater<int>() );
  for(int i=0;i<k;i++){
    sum-=a[i];
  }
  cout<<sum<<"\n";
  return(0);
}


Measured memory_bytes: 3712
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,x,y,z;
	int ans;
	String[] S;

	Main(){
		n = sc.nextInt();

		a = sc.nextInt();
		x = a;

		for(int i=0;i<n-1;i++)x = x^sc.nextInt();

		// 出力
		System.out.println(x==0?"Yes":"No");
	}

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

Measured memory_bytes: 50272
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main() {
  ll N;
  cin>>N;
  ll maxi=0;
  for (ll i(1);i*i<=N;i++){
    if (N%i==0){
      maxi = max(maxi,i);
    }
  }
  cout << maxi+(N/maxi)-2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

  int W,H,N;
  int x[100],y[100],a[100];

  cin >> W >> H >> N;
  for (int i=0;i<N;i++){
    cin >>x[i] >> y[i] >> a[i];
  }
  
  vector< vector<int> > xy(H, vector<int>(W));
  for (int j=0; j<H;j++){
    for (int i=0; i<W;i++){
      xy.at(j).at(i)=1;
    }
  }
    
  for (int i=0; i<N;i++){
    if(a[i] == 1){
      for(int ix=0; ix < x[i]; ix++){
        for(int iy=0; iy < H; iy++){
          xy.at(iy).at(ix) = 0;
        }
      }
    }else if(a[i] == 2){
      for(int ix=W-1; ix >= x[i]; ix--){
        for(int iy=0; iy < H; iy++){
          xy.at(iy).at(ix) = 0;
        }
      }
    }else if(a[i] == 3){
      for(int iy=0; iy < y[i]; iy++){
        for(int ix=0; ix < W; ix++){
          xy.at(iy).at(ix) = 0;
        }
      }    
    }else{
      for(int iy=H-1; iy >= y[i]; iy--){
        for(int ix=0; ix < W; ix++){
          xy.at(iy).at(ix) = 0;
        }
      }
    }
  }
  
  int result=0;
  for(int iy=0; iy < H; iy++){
    for(int ix=0; ix < W; ix++){
      result += xy.at(iy).at(ix);
    }
  }
  
  cout << result << endl;
  

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


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

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


Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++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 inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}
//priority_queue<int, vector<int>, greater<int> > que; //昇順

using namespace std;

const int mod=1e9+7;

int ans=0;



signed main(){
    SPEED;
    int n;
    cin >> n;
    vector<pair<int,bool>> a(n*2);
    rep(i,n)
    {
        cin >> a[i].fi;
        a[i].se = false;
    }
    int ans = 0;
    int now = 0;
    while(true)
    {
        if(now==1)
        {
            cout << ans << endl;
            return 0;
        }
        if(a[now].se == true)
        {
            cout << -1 << endl;
            return 0;
        }
        a[now].se = true;
        ++ans;
        now = a[now].fi - 1;
    }
}


Measured memory_bytes: 3456
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            int ans = n * a > b ? b : n * a;
            out.println(ans);
        }

    }
}



Measured memory_bytes: 21844
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> tp(N);
  for (int i = 0; i < N; i++) {
    cin >> get<0>(tp[i]) >> get<1>(tp[i]);
    get<2>(tp[i]) = i + 1;
  }
  for (int i = 0; i < N; i++) {
    get<1>(tp[i]) = 100 - get<1>(tp[i]);
  }
  sort(tp.begin(), tp.end());
  for (int i = 0; i < N; i++) {
    cout << get<2>(tp[i]) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(a.begin(),a.end());
  for(int j=0;j<n;++j){
    if(b[j]!=a[n-1]){
      cout<<a[n-1]<<endl;
    }else{
      cout<<a[n-2]<<endl;
    }
  }
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
			
			int N = sc.nextInt();
			String S = sc.next();
			String T = sc.next();

			char[] schar = S.toCharArray();
			char[] tchar = T.toCharArray();
			char[] rchar = new char[N*2];
			
			for(int i=0;i<N;i++) {
				rchar[2*i]= schar[i];
				rchar[2*i+1]=tchar[i];
			}
			
			
			System.out.println(rchar);
	}	

}

Measured memory_bytes: 35744
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

iscanl :: (Int -> a -> b -> a) -> a -> V.Vector b -> V.Vector a
iscanl !k !a !v = V.scanl' (\(!x) (!i, !v) -> k i x v) a (V.indexed v)

iscanlU
  :: (VU.Unbox a, VU.Unbox b)
  => (Int -> a -> b -> a)
  -> a
  -> VU.Vector b
  -> VU.Vector a
iscanlU !k !a !v = VU.scanl' (\(!x) (!i, !v) -> k i x v) a (VU.indexed v)

solve :: Int -> Int -> V.Vector (VU.Vector Bool) -> Int
solve !h !w !ahw = dp V.! h VU.! (w - 1)
 where
  add !x !y = (x + y) `mod` (10 ^ 9 + 7)

  dp :: V.Vector (VU.Vector Int)
  dp = iscanl
    ( \(!i) (!acc) (!row) -> VU.tail $ iscanlU
      (\(!j) (!prev) (!ch) -> if ch then 0 else acc VU.! j `add` prev)
      0
      row
    )
    (VU.generate w (\(!i) -> if i == 0 then 1 else 0))
    ahw

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (h, w) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  ahw <-
    V.replicateM h
    $   VU.unfoldrN w (\bs -> Just (B.head bs == '#', B.tail bs))
    <$> B.getLine
  print $ solve h w ahw


Measured memory_bytes: 5628
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;

int n,m,c;
const int M=100000001; 

void solve(){
	int res=0;
	int dp[100][100];
	int cost[100][100];
	memset(cost,-1,sizeof(cost));
	memset(dp,M,sizeof(dp));
	for(int i=0;i<m;i++){
		int in,out;
		cin>>in>>out;
		in--;out--;
		cin>>cost[in][out];
	}
	bool update=true;
	while(update){
		dp[0][0]=0;
		update=false;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(cost[j][i]<0) continue;
				if(dp[res][i]>dp[res][j]+cost[j][i]){
					update=true;
					dp[res][i]=dp[res][j]+cost[j][i];
				}
			}
		}
	}
	res++;
	while(true){
		for(int i=0;i<n;i++)
			dp[res][i]=dp[0][i];
		dp[res][0]=0;
		update=true;
		while(update){
			update=false;
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					if(cost[j][i]<0) continue;
					if(dp[res][i]>dp[res-1][j]){
						update=true;
						dp[res][i]=dp[res-1][j];
					}
					if(dp[res][i]>dp[res][j]+cost[j][i]){
						update=true;
						dp[res][i]=dp[res][j]+cost[j][i];
					}
				}
			}
		}
		if(dp[res][n-1]<=c){
			cout<<res<<endl;
			return;
		}
		res++;
	}
}
	

int main()
{
	while(cin>>n>>m>>c){
		if(n==0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 940
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#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() {
	string s;
	cin >> s;
	cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}


Measured memory_bytes: 256
A, B, C = [int(s) for s in input().split()]
K = int(input())
cnt = 0
if B <= A:
    while (B <= A):
        B *= 2
        cnt += 1

if C <= B:
    while (C <= B):
        C *= 2
        cnt += 1

print('Yes' if cnt <= K else 'No')


Measured memory_bytes: 61700
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int a, b, c;
	cin >> a >> b >> c;
	
	ll ans = 0;
	int x = a, y = b, z = c; 
	while (true) {
		if (x & 1 || y & 1 || z & 1) {
			cout << ans << endl;
			return 0;
		} else if (x == y && x == z) {
			cout << -1 << endl;
			return 0;
		}
		ans++;
		x = b / 2 + c / 2;
		y = a / 2 + c / 2;
		z = a / 2 + b / 2;
		a = x, b = y, c = z;
	}
}

Measured memory_bytes: 256
import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def main():

    N,K = map(int,input().split())
    R,S,P = map(int,input().split())
    T = input()
    X = []

    def score(s): #相手に勝ったときの手のスコア
        if s == "r":
            return P
        elif s == "s":
            return R
        return S

    for i in range(K):
        X.append(T[i::K])

    ans = 0
    for x in X:
        # print(x)
        dp = [[0] * 2 for _ in range(len(x)+1)]
        dp[0][True] = score(x[0])
        for i in range(1,len(x)):
            if x[i] == x[i-1]:
                dp[i][True] = dp[i-1][False] + score(x[i])
                dp[i][False] = dp[i-1][True]
            else:
                dp[i][True] = max(dp[i-1][True],dp[i-1][False]) + score(x[i]) #ん？？？
                dp[i][False] = max(dp[i-1][True],dp[i-1][False])

        ans += max(dp[len(x)-1][True],dp[len(x)-1][False])
        # print(dp)

    print(ans)


if __name__ == "__main__":
  main()


Measured memory_bytes: 26268
#include <stdio.h>
#include <string.h>
int main (void){
  int ans;
  char S[3];
  scanf("%s",S);
  if(strcmp(S,"SUN")==0){
    ans=7;
  }
  if(strcmp(S,"MON")==0){
    ans=6;
  }
  if(strcmp(S,"TUE")==0){
    ans=5;
  }
  if(strcmp(S,"WED")==0){
    ans=4;
  }
  if(strcmp(S,"THU")==0){
    ans=3;
  }
  if(strcmp(S,"FRI")==0){
    ans=2;
  }
   if(strcmp(S,"SAT")==0){
    ans=1;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}

string S,T,U;
int a,b,c;
vl A,B;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int N;cin>>N;
    ves S(N); vin(S);
    uniq(S);
    cout << S.size()<< endl;
    }

Measured memory_bytes: 9468
N = int(input())
S = input()

dp = [[0 for i in range(2)] for j in range(N+1)]

for i in range(1,N+1) :
    for j in range(2) :
        dp[i][j] = float("inf")

for i in range(N) :
    dp[i+1][0] = dp[i][0] + (S[i] == "#")
    dp[i+1][1] = min(dp[i][0], dp[i][1]) + (S[i] == ".")

ans = min(dp[N][0], dp[N][1])

print(ans)


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

int main(){
	char s[3];
	int i;
	for(i=0; i<3; i++) cin >> s[i];
  
	for(i=0; i<3; i++){
		if(s[i]=='7'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    for (int i = 0 ; i < s.size()-1; ++i) {
        if (i < s.size()-1) {
            if (s[i] == s[i+2]) {
                cout << i+1 << " " << i+3 << "\n";
                return 0;
            }
        }
        if (s[i] == s[i+1]) {
            cout << i+1 << " " << i+2 << "\n";
            return 0;
        }
    }
    cout << "-1 -1\n";
    return 0;
}

Measured memory_bytes: 512
input_list = input().split()
stack = []

for item in input_list:
  try:
    num = int(item)
    stack.append(num)

  except ValueError:
    num2 = stack.pop()
    num1 = stack.pop()

    if item == '+':
      stack.append(num1 + num2)
    elif item == '-':
      stack.append(num1 - num2)
    elif item == '*':
      stack.append(num1 * num2)
    elif item == '/':
      stack.append(num1 / num2)

print(stack.pop())


Measured memory_bytes: 5600
import java.util.Scanner;
         
        public class Main {
          public static void main(String args[]){
            Scanner scan = new Scanner(System.in);
            int K = scan.nextInt();
            String S = scan.next();
            String Dot = ("...");
            if(S.length()>K){
              try {
                  String SuperS=S.substring(0, K);
                  String SSS = SuperS + Dot ;
                  System.out.println(SSS);
                
                } catch(NullPointerException e) {
                    System.out.println();
                } catch(Throwable e) {
                    System.out.println();
                }
            }else{
              System.out.println(S);
            }
          }
        }

Measured memory_bytes: 39040