akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
template <typename T>
class BIT {
    int sz;
public:
    std::vector<T> node;
    BIT(int sz): sz(sz+1), node(std::vector<T>(sz+1, 0)) {}
    void add(int idx, T val) {
        ++idx;
        assert(0 < idx && idx < sz);
        while(idx < sz) {
            node[idx] += val;
            idx += idx & -idx;
        }
    }
    T sum(int idx) {
        ++idx;
        assert(0 < idx && idx < sz);
        T res = 0;
        while(idx > 0) {
            res += node[idx];
            idx -= idx & -idx;
        }
        return res;
    }
};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<pair<char, int>> v;
  for(int i=0;i<(2*n);++i) {
    char c; int a; cin >> c >> a;
    a--;
    v.push_back({c, a});
  }
  vvi black(n, vi(n+1, 0)), white(n, vi(n+1, 0));
  vi bnum(n, 0), wnum(n, 0);
  for(int k=0;k<(2*n);++k) {
    char c = v[k].first;
    int num = v[k].second;
    vi wsum(n+1, 0), bsum(n+1, 0);
    for(int l=(int)(n);l>=(int)(1);--l) {
      bsum[l-1] = bsum[l] + bnum[l-1];
      wsum[l-1] = wsum[l] + wnum[l-1];
    }
    for(int l=(int)(n+1);l>=(int)(1);--l) {
      if(c == 'B') black[num][l-1] = wsum[l-1] + bsum[num+1];
      else white[num][l-1] = wsum[num+1] + bsum[l-1];
    }
    if(c == 'B') bnum[num]++;
    else wnum[num]++;
  }
  vvi dp(2*n+1, vi(n+1, INF));
  dp[0][0] = 0;
  for(int i=0;i<(2*n);++i) {
    for(int j=0;j<(min(n+1, i+1));++j) {
      if(dp[i][j] == INF) continue;
      int nxtw = j;
      int nxtb = i-j;
      if(nxtw < n) chmin(dp[i+1][j+1], dp[i][j] + black[nxtw][nxtb]);
      if(nxtb < n) chmin(dp[i+1][j], dp[i][j] + white[nxtb][nxtw]);
    }
  }
  cout << dp[2*n][n] << endl;
}


Measured memory_bytes: 63104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define pq priority_queue
#define vt vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e5 + 5;

int n, m, a, b, ans;
int dp[N];
vt<int> v[N];

int f(int x) {
    if(!v[x].size()) return 0;
    int &sol = dp[x];
    if(sol != -1) return sol;
    sol = -INF;
    for(int u : v[x]) {
        sol = max(sol, 1 + f(u));
    }
    return sol;
}

void solve() {
    cin >> n >> m;
    while(m--) {
        cin >> a >> b;
        v[a].pb(b);
    }
    memset(dp, -1, sizeof(dp));
    ans = -INF;
    for(int i = 1; i <= n; i++) {
        ans = max(ans, f(i));
    }
    cout << ans << "\n";
}

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

    solve();
    
}

Measured memory_bytes: 11516
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int[] nums = new int[5];

        for(int i = 0; i < 5; i++){
            nums[i] = sc.nextInt();
        }
        
        Arrays.sort(nums);

        for(int i = 4; i > 0; i--){
            System.out.print(nums[i]);
            System.out.print(" ");
        }
        System.out.println(nums[0]);

    }
}

Measured memory_bytes: 17172
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> inpair;
int main()
{
    /*A
    double n;
    cin>>n;
    if(int(n)%2==0)
    {
        cout<<(n/2)/n<<endl;
    }
    else
    {
        cout<<((n+1)/2)/n<<endl;
    }
    */
    /*B
    int n,k;
    cin>>n>>k;
    int a[n];
    int count=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=k)
        {
            count++;
        }
    }

    cout<<count<<endl;
    */

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

    vector <inpair> b;

    for(int i=0;i<n;i++)
    {
        b.push_back(inpair(a[i],i+1));
    }

    
    sort(b.begin(),b.end());
    
   for(int i=0;i<n;i++)
   {
       cout<<b[i].second<<" ";
   }
    
    return 0;
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{	
	string s;
	getline(cin, s);
	rep(i,sz(s))
	{
		if(islower(s[i]))s[i] = toupper(s[i]);
		else if(isupper(s[i])) s[i] = tolower(s[i]);
	}
	cout << s << endl;
	return;
}

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



Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

const int INF = 1000000000000000;

int n, a[1010];
int ma = -INF, p;
int cnt1, cnt2;
vector<int> vec1, vec2;
vector<int> ans;

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (ma < a[i]) {
			ma = a[i];
			p = i;
		}
	}
	if (ma <= 0) {
		cout << ma << endl;
		cout << n - 1 << endl;
		for (int i = n; i > p; i--)cout << i << endl;
		for (int i = 1; i < p; i++)cout << 1 << endl;
		return 0;
	}
	for (int i = 1; i <= n; i += 2)if (0 < a[i]) {
		cnt1 += a[i];
		vec1.push_back(i);
	}
	for (int i = 2; i <= n; i += 2)if (0 < a[i]) {
		cnt2 += a[i];
		vec2.push_back(i);
	}
	if (cnt1 < cnt2) {
		ma = cnt2;
		for (int i = n; i > vec2.back(); i--)ans.push_back(i);
		for (int i = (int)vec2.size() - 1; i > 0; i--) {
			int x = vec2[i] - vec2[i - 1] - 2;
			while (x) {
				ans.push_back(vec2[i - 1] + 2);
				x -= 2;
			}
		}
		for (int i = 1; i < vec2[0]; i++)ans.push_back(1);
		for (int i = 1; i < (int)vec2.size(); i++)ans.push_back(2);
	}
	else {
		ma = cnt1;
		for (int i = n; i > vec1.back(); i--)ans.push_back(i);
		for (int i = (int)vec1.size() - 1; i > 0; i--) {
			int x = vec1[i] - vec1[i - 1] - 2;
			while (x) {
				ans.push_back(vec1[i - 1] + 2);
				x -= 2;
			}
		}
		for (int i = 1; i < vec1[0]; i++)ans.push_back(1);
		for (int i = 1; i < (int)vec1.size(); i++)ans.push_back(2);
	}
	cout << ma << endl;
	cout << (int)ans.size() << endl;
	for (int i = 0; i < (int)ans.size(); i++)cout << ans[i] << endl;
}

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

int main(){

        string S,T;

        cin >> S >>T;

        int i,j;
        int cnt=0;

        int L=S.size();
        char tmp;

        while(1){
                if(cnt==L+1){
                break;
                }

                tmp=T[L-1];

                for(i=1;i<L;i++){
                T[L-1-i+1]=T[L-1-i];
                }

                T[0]=tmp;

                if(S==T){
                        cout << "Yes";
                        return 0;
                }
                cnt++;
        }
        cout << "No";

        return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int N;


    cin >> N;

  int res = N;
  int cc = 0;

  while(res > 0)
  {
    cc += res % 10;
    res /= 10;
  }


  if(N % cc == 0)
  {
    cout << "Yes";
  }else{
    cout << "No";
  }

  return 0;
}

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(){
    string S;
    cin>>S;
    int N=S.size();
    vector<int>ans(N,0);
    int count=0;
    for(int j=0;j<2;j++){
      for(int i=0;i<N;i++){
            if(S.at(i)=='R'){
                count=count+1;
            }
            else{
                ans.at(i) +=count/2;
                ans.at(i-1) +=(count+1)/2;
                count=0;
            }
        }
        for(int i=0;i<N;i++){
            if(S.at(i)=='R'){
                S.at(i)='L';
            }
            else{
                S.at(i)='R';
            }
        }   
        reverse(S.begin(),S.end());
        reverse(ans.begin(),ans.end());
    }
    for(int i=0;i<N;i++){
        cout<<ans.at(i)<<" ";
    }
}

Measured memory_bytes: 1024
n, m, x = map(int, input().split())

q = set()
q.add(tuple([0] * (m+1)))

for _ in range(n):
    c = list(map(int, input().split()))

    update = set()
    for qq in q:
        l = list(qq)
        l[0] = qq[0] + c[0]
        for i in range(1, m+1):
            l[i] = min(qq[i] + c[i], x)
        update.add(tuple(l))

    q.update(update)

max_ans = 10 ** 5 * 13
ans = max_ans
for qq in q:
    if qq[0] < ans and sum(qq[1:]) == m * x:
        ans = qq[0]

if ans < max_ans:
    print(ans)
else:
    print(-1)



Measured memory_bytes: 11116
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		Stack<Character> stac = new Stack<>();
		while(n > 0){
			if(n%26 == 0){
				stac.add('z');
				n /= 26;
				n--;
			}else{
			stac.add((char)('a'+n%26 - 1));
			n /= 26;
			}

		}
		while(!stac.empty()){
			System.out.print(stac.pop());
		}




	}
}


Measured memory_bytes: 35832
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

S = [-INF] + [int(input()) for _ in range(A)]+[INF]
T = [-INF] + [int(input()) for _ in range(B)]+[INF]

from bisect import bisect_left as bisect_right
from itertools import product


for q in range(Q):  # 各問に答える
    x = int(input())  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


Measured memory_bytes: 13924
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

#define MOD 1000000007
long long N;
string s;
bool ans[100000];

int main() {
    cin >> N >> s;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            ans[0] = (bool)i;
            ans[1] = (bool)j;
            for (int k = 2; k < N; k++) {
                if (s[k-1] == 'o') ans[k] = ans[k-1] ^ ans[k-2];
                else ans[k] = !(ans[k-1] ^ ans[k-2]);
            }
            if (((s[N-1] == 'o' && ans[0] == ans[N-1] ^ ans[N-2]) || (s[N-1] == 'x' && ans[0] == !(ans[N-1] ^ ans[N-2]))) 
            && ((s[0] == 'o' && ans[1] == ans[N-1] ^ ans[0]) || (s[0] == 'x' && ans[1] == !(ans[N-1] ^ ans[0])))) {
                for (int k = 0; k < N; k++) {
                    cout << (ans[k] ? 'W' : 'S');
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 640
# A - Colorful Subsequence
from collections import defaultdict as dd
n=int(input())
s=input()
mod=10**9+7
ans=1
c=dd(int)

for ss in s:
    c[ord(ss)-97]+=1

for i in range(26):
    ans*=c[i]+1
    ans%=mod

print((ans+mod-1)%mod)


Measured memory_bytes: 3444
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

string s,t;

int main(){
    cin>>s>>t;
    cout<<t<<s<<endl;
    
    
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int K = Integer.parseInt(br.readLine());
	String S = br.readLine();

	if (S.length() <= K) {
	    System.out.println(S);
	} else {
	    System.out.println(S.substring(0, K) + "...");
	}
    }
}

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int n ;
int arr[MAX] ;
string s ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	int ans = 1e9 ;
	for(int i = 1 ; i <= 100 ; ++i)
	{
		int now = 0 ;
		for(int j = 0 ; j < n ; ++j)
			now += (arr[j] - i) * (arr[j] - i) ;
		ans = min(ans , now) ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int64_t mod = 1000000007;
vector<int64_t> fact, inv;
 
int64_t power(int64_t n, int64_t k) {
  if (k == 0) return 1;
  int64_t ans = power(n * n % mod, k / 2);
  if (k % 2) ans = ans * n % mod;
  return ans;
}
 
void init(int64_t n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 1; i <= n; i++) {
    fact.push_back(fact.at(i - 1) * i % mod);
    inv.push_back(power(fact.at(i), mod - 2));
  }
}
 
int64_t comb(int64_t n, int64_t r) {
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}
 
int main() {
  int64_t n, k;
  cin >> n >> k;
  if (k >= n) k = n - 1;
  init(2 * n);
  int64_t ans = 0;
  for (int i = 0; i <= k; i++) {
    ans += comb(n, i) * comb(n - 1, i);
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9696
def main():
    n, m = map(int, input().split())
    if n == 1 and m == 1:
        print(1)
    elif n == 1 or m == 1:
        print(max(n, m) - 2)
    else:
        print(n * m - (n + m - 2) * 2)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

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

    ll ans = 0;
    rep(1, i, N + 1)
    {
        rep(1, j, N + 1)
        {
            if (i * j < N)
            {
                ans++;
            }
            else
            {
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void){
	int A,B,X;
	
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&X);
	
	if(A<=X){
		if(A+B>=X){
		printf("YES");
		}else{
		printf("NO");
		}
	}else{
		printf("NO");
	}
	return 0;}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
int a,b,c,k;
int cf2(int x)
{
	int ans=1;
	rep(i,x)
	{
		ans*=2;
	}
	return ans;
}
int main()
{
	cin>>a>>b>>c>>k;
	rep3(i,0,k+1)
	{
		if(a<b*cf2(i)&&b*cf2(i)<c*cf2(k-i))
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Program
{

    static void Main()
    {
        var sc = new Scanner();
        int a = sc.Int();
        int b = sc.Int();
        int h = sc.Int();
        Console.WriteLine((a+b)*h/2);
    }
}
static class Extentions
{
    public static IEnumerable<T> Outpuut<T>(this IEnumerable<T> source)
    {
        foreach (var item in source)
        {
            Console.WriteLine(item);
        }
        return source;
    }
    public static T Print<T>(this T obj)
    {
        Console.WriteLine(obj);
        return obj;
    }
}
public class Scanner
{
    public Scanner()
    {
        byte[] inputBuffer = new byte[1024];
        System.IO.Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
        Console.SetIn(new System.IO.StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
    }
    string[] buffer = new string[0];
    int index = 0;
    public char[] SplitChars { get; set; }
    public string String()
    {
        if (index < buffer.Length) return buffer[index++];
        string line = "";
        while (line == "") line = Console.ReadLine();
        if (line == null) return null;
        buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);
        index = 0;
        return buffer[index++];
    }
    public string[] StringArray(int count) { return NextArray(count, x => x); }
    public void Skip(int count) { for (int i = 0; i < count; i++) String(); }
    public T Next<T>(Func<string, T> parser) { return parser(String()); }
    public T[] NextArray<T>(int count, Func<string, T> parser)
    {
        var arr = new T[count];
        for (int i = 0; i < count; i++) arr[i] = Next(parser);
        return arr;
    }
    public int Int() { return Next(int.Parse); }
    public int[] IntArray(int count) { return NextArray(count, int.Parse); }
    public double Double() { return Next(double.Parse); }
    public double[] DoubleArray(int count) { return NextArray(count, double.Parse); }
}


Measured memory_bytes: 2648
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <functional>
#include <algorithm>
#include <tuple>
#include <string.h>
using namespace std;

const int INF = 1<<30;
int main() {
	int n, k;
	while(cin >> n >> k && (n || k)){
		int card[100001];
		bool flag = false;
		fill(card, card + 100001, INF);
		for(int i = 0; i < k; ++i){
			scanf("%d", &card[i]);
			if(card[i] == 0){
				flag = true;
				card[i] = INF;
			}
		}
		sort(card, card + k);
	
		int fcard = 0, ans = 0, s = 0, t = 0;
		for(;;){
			//int flagc = 0;
			while(fcard == card[t] - 1 && t < k){
				fcard = card[t];
				t++;
			}
			int now = t;
			if(flag){
				int scard = card[t - 1] + 1;
				while(scard == card[t] - 1 && t < k){
					scard = card[t];
					t++;
				}
			}
			ans = max(ans, t - s + flag);
			//cout << t << " " << s << " " << endl;
			fcard = card[now];
			s = now;
			t = now + 1;
			if(s >= k - 1)
				break;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<long long> b(n);
    long long ans=0;
   
    rep(i,n-1) cin >> b[i];
    ans += b[0]+b[n-2];
    rep(i,b.size()-1){
        ans+=min(b[i],b[i+1]);
    
    }
    cout << ans << endl; 

}






Measured memory_bytes: 256
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(3)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#ifdef WindCry1
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#endif
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
#endif
	double h,a;cin>>h>>a;
	cout<<ceil(h/a)<<endl;
	return 0;
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);


int main(){

  int N; cin >> N;
  vector < pair<ll, int> > graph[N];
  for (int i = 0; i < N - 1; i++){
    int u, v; ll w; cin >> u >> v >> w;
    u--; v--;
    graph[u].push_back(make_pair(w, v));
    graph[v].push_back(make_pair(w, u));
  }
  
  vector <bool> visited(N);
  queue <int> que; que.push(0);
  visited[0] = true;

  vector <int> ans(N);
  
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < graph[Q].size(); i++){
      int next = graph[Q][i].second;
      if (visited[next] == false){
        visited[next] = true;
        que.push(next);
        if (graph[Q][i].first % 2 == 0) ans[next] = ans[Q];
        else ans[next] = 1 - ans[Q];
      }
    }
  }
  
  for (int i = 0; i < N; i++){
    cout << ans[i] << endl;
  }
  


  return 0;
}


Measured memory_bytes: 8320
n, q = map(int, input().split())

graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

counter = [0] * (n + 1)

for i in range(q):
    p, x = map(int, input().split())
    counter[p] += x

parents = [0] * (n + 1)

q = [1]
while q:
    y = q.pop()
    for x in graph[y]:
        if x == parents[y]:
            continue
        counter[x] += counter[y]
        q.append(x)
        parents[x] = y

print(*counter[1:])


Measured memory_bytes: 55828
#include<iostream>
using namespace std;
int main() {

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

	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int s;
    cin >> s;
    int h = s/3600;
    s%=3600;
    int m = s/60;
    s%=60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a;
    cin >> a;
    if (a==1){
            cout << "Hello World" << endl;
        return 0;
    }
    ll x,y;
    cin >> x >> y;
    cout << x+y << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)] + [0]
mod = 10 ** 9 + 7

dp = [0] * (n + 1)
dp[0] = 1
b = a[0]
j = 1
for i in range(1, n + 1):
    if i == b:
        b = a[j]
        j += 1
    else:
        tmp = dp[i - 2] + dp[i - 1]
        if tmp >= mod:
            tmp -= mod
        dp[i] = tmp
print(int(dp[-1]))

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

int w,h;
int maze[100][100];

void solve(int x,int y){

  if(x < 0 || y < 0 || x == w || y == h) return;
  if(!maze[y][x]) return;

  maze[y][x] = 0;

  for(int i=-1;i<2;i++){
    for(int j=-1;j<2;j++){
      solve(x+i,y+j);
    }
  }

}
int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++) cin >> maze[i][j];
    }

    int ans = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(maze[i][j] == 1) solve(j,i), ans++;
      }
    }

    cout << ans << endl;

  }
}

Measured memory_bytes: 1328
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut testimonies: Vec<(usize, usize, usize)> = Vec::new();
    for i in 0..n {
        let a: usize = scan(tokens);
        for _ in 0..a {
            let x: usize = scan(tokens);
            let y: usize = scan(tokens);
            testimonies.push((i, x - 1, y))
        }
    }
    let mut max = 0;
    for bits in 0..1 << n {
        let mut ok = true;
        for &(i, j, t) in &testimonies {
            if bits & (1 << i) != 0 && bits & (1 << j) != t << j {
                ok = false;
                break;
            }
        }
        if ok {
            max = std::cmp::max(max, bits.count_ones());
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 4352
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import sys
sys.setrecursionlimit(10**6)
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
od=998244353
n,k,x=list(map(int,input().split()))

n_c_i=[1]
pow_k=pow(k-1,n,od)
inv_k=pow(k-1,od-2,od)
each_cal=[]
zenpou=[1]
kouhou=[]
for i in range(1,x+1):
    n_c_i.append((n_c_i[-1]*(n-i)*pow(i,od-2,od))%od)
for i in range(n-1):    
    zenpou.append(zenpou[-1]*(k-1)%od)
for i in range(x+1):
    pow_k=pow_k*inv_k%od
    kouhou.append(pow_k)
    each_cal.append(pow(k-1,n-i-1,od))

zenpou.reverse()
ans=0
for i in range(x+1):
    #each_calのみAC
    #zenpouとkouhouはWA
    #なぜ？
    ans+=(n_c_i[i]*k*each_cal[i])%od
    ans%=od

print(ans)



Measured memory_bytes: 58452
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec)
    is >> x;  // for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  cin >> a;

  vector<pair<ll, ll>> ans(n);

  for (ll i = 0; i < n; i++) {
    ans[i] = make_pair(i + 1, a[i]);
  }

  sort(ans.begin(), ans.end(),
       [](const pair<long, long>& l, const pair<long, long>& r) {
         return l.second < r.second;
       });

  for (ll i = 0; i < n; i++) {
      cout << ans[i].first;
      if (i < n-1)cout << " ";
  }
}


Measured memory_bytes: 3200
/**
 *     author: qodjf
 *     created: 04.18.2020 01:01:31
 */
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  ll N;
  cin >> N;
  if (N % 2) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  N /= 2;
  while (N) {
    N /= 5;
    ans += N;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int dp[3003][3003],ar[3003];
long long int rec(long long int l,long long int r)
{
    if(l>r)
    return 0;
    if(dp[l][r]!=-1)
    return dp[l][r];
    long long int a=ar[l]-rec(l+1,r);
    long long int b=ar[r]-rec(l,r-1);
    return dp[l][r]=max(a,b);
}
int main()
{
    long long int n,i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    for(i=0;i<=3001;i++)
    {
        for(j=0;j<=3001;j++)
        {
            dp[i][j]=-1;
        }
    }
    cout<<rec(1,n);
}

Measured memory_bytes: 70912
def chck(s, t)
  for i in 0..s.size-1
    for j in 0..s.size-1
      if (s[i] == s[j] && t[i] != t[j]) || (s[i] != s[j] && t[i] == t[j])
        return false
      end
    end
  end
  return true
end
n = gets.to_i
chrs = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]

l = ["a"]

for i in 1..n-1
  tmp = []
  l.each do |ll|
    for k in 0..ll.split("").uniq.size
        tmp << ll + chrs[k]
    end
  end
  tmp << l[-1] + chrs[i]
  l = tmp.dup
end

puts l.uniq.sort


Measured memory_bytes: 41388
#include <iostream>

int main()
{
	std::string S;
	std::string T;
	int A;
	int B;
	std::string U;
	std::cin >> S;
	std::cin >> T;
	std::cin >> A;
	std::cin >> B;
	std::cin >> U;
	if (S == U) {
		A -= 1;
	}else{
		B -= 1;
	}
	std::cout << A << " " << B;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	bool ans = true;
	rep(i, n)
	{
		if (a[i] % 2 == 0)
		{
			if (a[i] % 3 != 0 && a[i] % 5 != 0)
			{
				ans = false;
			}
		}
	}
	if (ans) cout << "APPROVED" << "\n";
	else cout << "DENIED" << "\n";
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int n,a[100005],c[200005],maxi;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++){
		a[i]+=10;
		c[a[i]-1]++;
		c[a[i]]++;
		c[a[i]+1]++;
	}
	for (int i=0;i<=200000;i++){
		maxi=max(maxi,c[i]);
	}
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int main(){
	char str[20];
	int a=0;
	scanf("%s",str);
	if(str[0]!='A')
	{
		printf("WA");
		return 0;
	}
	if(str[1]=='C'||str[strlen(str)-1]=='C')
	{
		printf("WA");
		return 0;
	}
	
	for(int i=1;i<strlen(str);i++)
	{
		if(str[i]<'a'&&str[i]!='C')
		{
			
			printf("WA");
			return 0;
		}
		if(str[i]=='C')
		{
			a++;
			if(a>=2)
			{
				
				printf("WA");
				return 0;
			}
		}
		
	}
	if(a==0)
	{
		printf("WA");
		return 0;
	}
	printf("AC");
	}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>

#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

typedef complex<double> point;

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

using ll = int64_t;

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    int left = 0;
    int right = 0;
    for (int i = 1; i < n; i++){
        if (s[i] == 'E')
            right++;
    }
    int ret = right;

    for (int i = 1; i<n; i++){
        // make i to leader.
        if(s[i-1] == 'W')
            left++;
        if(s[i] == 'E')
            right--;

        ret = min(ret, left + right);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 720
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D = list(map(int,input().split()))
if A%C == 0:
    num_C_bai = (B-(B%C) - A)//C + 1
else:
    num_C_bai = ((B-(B%C) - (A-(A%C)+C)))//C + 1
    
if A%D == 0:
    num_D_bai = (B-(B%D) - A)//D + 1
else:
    num_D_bai = ((B-(B%D) - (A-(A%D)+D)))//D + 1

E = lcm(C,D)

if A%E == 0:
    num_E_bai = (B-(B%E) - A)//E + 1
else:
    num_E_bai = ((B-(B%E) - (A-(A%E)+E)))//E + 1

print(B + 1 - A - num_C_bai - num_D_bai + num_E_bai)


Measured memory_bytes: 9164
//AUTHOR: *Akash Shrivastva*
//Birla Institute of Technology,Mesra,India
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define M 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector< pair <ll,ll> >
#define F first
#define S second
#define PII pair <ll,ll>
ll n,h[100003],dp[100003],k;
ll f(ll i)
{
	if (i>=n)	return 0;
	else if (dp[i]!=-1)	return dp[i];
	else
	{
		dp[i]=INT_MAX;
		ll j;
		for (j=1;j<=k;j++)
		{
			if (i+j<=n)	dp[i]=min(dp[i],abs(h[i]-h[i+j])+f(i+j));
		}
		return dp[i];
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
 
    cin>>n>>k;
    h[n+1],dp[n+1];
    memset(dp,-1,sizeof(dp));
    ll i;
    for (i=1;i<=n;i++)	cin>>h[i];
    cout<<f(1)<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define loop(i,x,n) for(ll i= x;i<n;i++)




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = 0;
    ans+=min(a,k);
    k = k- min(a,k);
    if(k == 0){
        cout<<ans;
        return 0;
    }
    k = k - min(b,k);
    if(k == 0){
        cout<<ans;
        return 0;
    }
    ans = ans-k;
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  std::string s;
  ll k;
  std::cin >> s >> k;

  char num = '1';
  for(ll i = 0; i < k; i++) {
    if(s[i] != '1'){
      num = s[i];
      break;
    }
  }

  std::cout << (num == '1' ? '1' : num) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main(void)
{
	int c=0;
	char a[27];
	int b[26]={0};
	cin >> a;
	for (int i=0;i<strlen(a);i++) {
		b[a[i]-'a']++;
		if (b[a[i]-'a'] > 1) {
			c = 1;break;
		}
	}

	if (c==1) {
		cout << "no";
	} else {
		cout << "yes";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

bool solve(){
  int a,b,c;
  cin>>a>>b>>c;

  return a==b && b==c;
}

int main(){
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    string n;
    cin >> n;
    int divnum = 0;
    int n_num = atoi(n.c_str());
    for(int i=0; i<n.length(); i++){
        divnum += n[i] - '0';
    }

    if(n_num % divnum == 0){
        cout << "Yes" << endl;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define MAX 100002
#define MOD 1000000007
int n;
vector<pair<int,int> > v;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		v.push_back(make_pair(a,0));
	}
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		v.push_back(make_pair(a,1));
	}
	sort(v.begin(),v.end());
	int cnt=0;
	int p=-1;
	long long int way=1;
	for(int i=0;i<v.size();i++){
		if(cnt==0){
			p=v[i].second;
			cnt=1;
			continue;
		}
		if(p!=v[i].second){
			way*=cnt;
			way%=MOD;
			cnt--;
			continue;
		}
		cnt++;
	}
	printf("%lld\n",way);
	return 0;
}


Measured memory_bytes: 2420
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
  int a,b;
  while(cin>>a>>b,a||b){
    rep(i,a){
      rep(j,b){
        if(i==0||j==0||j==b-1||i==a-1) cout<<"#";
        else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1152
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>
#include <bitset>

using namespace std;

int main(int argc, char* argv[]) {
		string s;
		cin >> s;
		int len = (int)s.length();
		bool ans = len % 2 == 0;
		if (ans) {
			for (int i = 0; i < len; i += 2) {
				if (s[i] == 'h' && s[i + 1] == 'i') {

				} else {
					ans = false;
				}
			}
		}
		cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, M, i, j, ans = 0;
	scanf("%d%d", &N, &M);
	if(N == 1){
		printf("%d\n", M);
		return 0;
	}
	for(i = 1; i * i <= M; i++){
		if(M % i == 0){
			j = M / i;
			if(j >= N){
				ans = max(ans, i);
			}
			if(i >= N){
				ans = max(ans, j);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std;
const int N = 27 ;
vector<set<int>> v(N) ;
int main()
{
	int n , q ;
	ios::sync_with_stdio(false) ;cin.tie(0) , cout.tie(0) ;
	string s ;
	cin >> n >> s >> q ;
	s = " " + s ;
	for(int i = 1; i <= 26 ;i ++) v[i].insert(0x3f3f3f3f) ;
	for(int i = 1 ; i < s.size() ;i ++) v[s[i] - 'a' + 1].insert(i) ;
	for(int i = 1; i <= q; i ++)
	 {
		 int k , x ;string p ;
		 cin >> k ;
		 if(k == 1)
		  {
				cin >> x >> p ;
				if(s[x] != p[0])
				 {
					 int t = s[x] - 'a' + 1 ;
					 v[t].erase(x) ;
					 s[x] = p[0] ;
					 v[s[x] - 'a' + 1].insert(x) ;
				 }
			}
		 else
		  {
				int ans = 0 ;
				int l , r ;cin >> l >> r ;
				for(int j = 1; j <= 26 ;j ++)
				 {
					 auto it = v[j].lower_bound(l) ;
					 if(*it <= r) ans ++ ;
				 }
				cout << ans << endl ;
			}
	 }
	return  0;
}


Measured memory_bytes: 24248
import sys
from heapq import heapify, heappushpop
from bisect import bisect_left as bisect

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

X, Y, Z, K = MAP()
x = MAP()
y = MAP()
z = MAP()

if X > Z:
	x, z = z, x
	X, Z = Z, X
if Y > Z:
	y, z = z, y
	Y, Z = Z, Y

x.sort()
y.sort()
z.sort()

nums = [0] * K
heapify(nums)

for i in range(X-1, -1, -1):
	for j in range(Y-1, -1, -1):
		xy = x[i]+y[j]
		z_idx = bisect(z, nums[0]-xy)
		# print(nums)
		# print(xy, z, z_idx)
		for k in range(z_idx, Z):
			heappushpop(nums, xy+z[k])

nums.sort(reverse=True)
for n in nums:
	print(n)

Measured memory_bytes: 55516
#include <stdio.h>
#define MAX_NUM (50030)

void enum_prime(char list[]) {
	int i, j;

	list[0] = list[1] = 0;
	for (i = 2; i < MAX_NUM; i++) {
		list[i] = 1;
	}
	for (i = 2; i < MAX_NUM; i++) {
		if (list[i] == 0)
			continue;
		for (j = i + i; j < MAX_NUM; j += i) {
			list[j] = 0;
		}
		if (MAX_NUM < i * i)
			break;
	}
}

int main() {
	int i, n, under, upper;
	char prime_list[MAX_NUM];

	enum_prime(prime_list);
	while (scanf("%d ", &n) != EOF) {
		for (i = 0; i < MAX_NUM; i++) {
			if (prime_list[i] && n < i) {
				upper = i;
				break;
			}
			if (prime_list[i] && i < n) {
				under = i;
			}
		}
		printf("%d %d\n", under, upper);
	}
	return 0;

}

Measured memory_bytes: 648
N=int(input())
W=[]
for i in range(N):
    W.append(input())
f=1

if len(set(W))!=N:
    f=0

for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        f=0
        break

print('NYoe s'[f::2])

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

int main(){
int H,W;
  cin>>H>>W;
  char a[H][W];
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
    cin>>a[i][j];}}
  
  vector<bool>high(H, false), wide(W, false);
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
    if(a[i][j]=='#'){high[i]=true;}
   }}
  
  for(int i=0; i<W; i++){
   for(int j=0; j<H; j++){
    if(a[j][i]=='#'){wide[i]=true;}
   }}
  
  for(int i=0; i<H; i++){
    bool flag=false; 
   for(int j=0; j<W; j++){
    if(high[i]==true && wide[j]==true){
      cout<<a[i][j];
      flag=true;}
   }
    if(flag){cout<<endl;}
  }
  
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int n;
string s;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    cin >> n;
    cin >> s;
    int i = 0, res = 0;
    while(i < n)
    {
        res++;
        while(s[i] == s[i + 1] && i + 1 < s.size())
            i++;
        i++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  string s;
  int n;
  cin >> s;
  n = s.length();
  int odd, even;
  odd = (n % 2 == 0) ? n/2 : n/2 + 1;
  even = n/2;
  
  int num1, num2;
  num1 = 0;
  num2 = 0;
  
  for (int i = 0; i < odd; i++) {
    num1 += s[2*i] - 48;
    num2 += 49 - s[2*i];
  }
  for (int i = 0; i < even; i++) {
    num1 += 49 - s[2*i + 1];
    num2 += s[2*i + 1] - 48;
  }
  
  cout << min(num1, num2) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];

  sort(A.begin(), A.end());
  
  cout << (A[1] - A[0]) + (A[2] - A[1]) << endl;
 
}

Measured memory_bytes: 256