akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ALDS1_1
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for(int i = 0; i < n; i++)
            {
                int v = a[i], j = i - 1;
                while (j >= 0 && a[j] > v)
                    a[j + 1] = a[j--];
                a[j + 1] = v;
                Console.WriteLine(string.Join(" ", Array.ConvertAll(a, e => e.ToString())));
            }
        }
    }
}

Measured memory_bytes: 9664
import math
N, M = map(int, input().split())
mx = 0
for i in range(1, math.floor(math.sqrt(M))+1):
    if M % i == 0:
        if M // i >= N:
            mx = max(mx, i)
        if i >= N:
            mx = max(mx, M//i)
print(mx)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N;
	cin >> N;
	vector<lint>A(N);
	vector<lint>B(N);
	rep(i, N) {
		cin >> A[i] >> B[i];
	}
	sort(A);
	sort(B);
	if (N % 2 == 0) {
		lint MIDA = (A[N / 2-1] + A[N / 2 + 1-1]);
		lint MIDB = (B[N / 2-1] + B[N / 2 + 1-1]);
		lint ans = (MIDB - MIDA)   + 1;
		cout << ans << endl;
	}
	else {
		lint MIDA = A[(N + 1) / 2-1];
		lint MIDB = B[(N + 1) / 2-1];
		lint ans = MIDB - MIDA + 1;
		cout << ans << enld;
	}
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int five = 0, seven = 0;
  
  if (a == 5) five++;
  if (a == 7) seven++;
  
  if (b == 5) five++;
  if (b == 7) seven++;
  
  if (c == 5) five++;
  if (c == 7) seven++;
    
  if (five == 2 || seven == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  // Rx3
  if (s == "RRR") { ans = 3; }
  // Rx2
  if (s == "RRS") { ans = 2; }
  if (s == "RSR") { ans = 1; }
  if (s == "SRR") { ans = 2; }
  // Rx1
  if (s == "RSS") { ans = 1; }
  if (s == "SRS") { ans = 1; }
  if (s == "SSR") { ans = 1; }
  // Rx0
  if (s == "SSS") { ans = 0; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
import java.util.*;
  
class Main{
  public static void main(String[] args){
    Scanner stdId = new Scanner(System.in);
    long a = stdId.nextLong(); 
    long b = stdId.nextLong(); 
    long d,r;
    double f;
    d = a/b;
    r = a%b;
    f = (double)a/b;
    System.out.printf("%d %d %f\n",d,r,f);
  }
}

Measured memory_bytes: 17188
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.snack", "r", stdin );
	const string species[] = { "A", "B", "NA" };
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
//		cout << "n: " << n << endl;
		if (n == 0 ){
			break;
		} // end if

		int i,j;

		for (i = 0; i < n; ++i){
			string res = species[2];
			getline (cin, str );
			
			if (str.empty() ){
				break;
			} // end if
			int len = str.length();

			if (str[0] == '>'){
				if (str[1] == '\''){		// A species? 
					res = species[0];
				}else if (str[1] == '^'){	// B species?
					res = species[1];
				}else{				// new species.
					res = species[2];
				} // end if
			} // end if
			
			if (res == species[0] || res == species[1]){
				if (res == species[0]){	// A species?
					int prev = 0;
					int after = 0;
					int mid = 0;
					bool flag = false;
					for (j = 2; j < len - 1; ++j){
						if (str[j] == '='){
							if (!flag){
								++prev;
							}else{
								++after;
							} // end if
							continue;
						}else if (str[j] == '#'){
							flag = true;
							++mid;
							continue;
						}else{
							break;
						} // end if
					} // end for

					if (j == len - 1){
						if (str[j] == '~' && flag && mid == 1
						&& prev != 0 && after != 0 && prev == after ){
							res = species[0];
						}else{
							res = species[2];
						} // end if
					}else{
						res = species[2];
					} // end if
				}else{	// if (res == species[1]) // B species?
					bool flag = false;
					for (j = 2; j < len - 2; j += 2){
						if (str[j] == 'Q' && str[j+1] == '='){
							if (!flag ){
								flag = true;
							} // end if
							continue;
						}else{
							break;
						} // end if
					} // end for
					if (j == len - 2 && flag && str[j] == '~' && str[j+1] == '~'){
						res = species[1];
					}else{
						res = species[2];
					} // end if
				} // end if
			} // end if
			cout << res << endl;
		} // end for
	} // end loop
		
	return 0;
}

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

class Main{
	public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
    	int high[]=new int[10];
        for(int i=0; i<10; i++){
    	 high[i]=sc.nextInt();	
    	}
	Arrays.sort(high);
	for(int i=9; i>6; i-- ) System.out.println(high[i]);
	}
	}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int n; cin >> n;
    deque<int> q;
    rep(i,n){
        int a; cin >> a;
        if(i % 2 == n % 2){
            q.push_back(a);
        }else{
            q.push_front(a);
        }
    }
    
    rep(i,n){
        cout << (i ? " " : "") << q.front();
        q.pop_front();
    }
    cout << endl;
}

Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int a,p; cin >>a>>p;
  cout<<(3*a+p)/2<<endl;
  }


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

int main()
{
  char s[100],t[100];
  cin >> s >> t;

  for(int i=0; s[i]!='\0'; i++){
    if(s[i]!=t[i]){
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    double x;
    rep(i, 0, n) {
        double a;
        cin >> a;
        x += 1.0 / a;
    }
    cout.precision(10);
    cout << 1.0 / x << endl;
}

Measured memory_bytes: 256
N = int(input())
F = []
P = []

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  #list = [0,0, ... ~ 0] ~ [1,1, ... ~ 1]
  if con == 10:
    #1がない = 出店していない場合は何も返さない
    if list.count(1) == 0:
      return
    value = 0
    #インデックス番号とF[i] = 店の出店リストを取得
    for n,shop in enumerate(F):
      con = 0
      for j in range(10):
          #j日に自店が出店し、かつ他店nも出店するならば、カウントする
          if list[j] == 1 and shop[j] == 1:
              con += 1
      #出店リストlistのパターンに応じた店nごとの利益を
      #同時出店日数conから算出し足し合わせる
      value += P[n][con]
 
    global ans
  
    ans = max(ans, value)
    
  else:
    #出店しない
    recur(list + [0])
    #出店する
    recur(list + [1])
    
recur([])
    
print(ans)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
	int N, p[100000];
	int num = 0;
	bool flag = false;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> p[i];
		if(p[i] == i + 1){
			num++;
			if(flag == false){
				flag = true;
			}else{
				num--;
				flag = false;
			}
		}else{
			flag = false;
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
n=15*10**4
p=[True]*n
p[0],p[1]=False,False
for i in xrange(2,int(n**0.5)+1):
    if p[i]==True:
        for j in xrange(i**2,n,i):
            p[j]=False
s=[i for i in xrange(n) if p[i]]
while True:
    n=input()
    if n==0:break
    print sum(s[0:n])

Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  i64 n, m, l;
  cin >> n >> m >> l;

  vector<vector<i64>> dist(n, vector<i64>(n, 1e18));

  rep(i,0,n) dist[i][i] = 0;

  rep(i,0,m) {
    i64 a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    dist[a][b] = min(dist[a][b], c);
    dist[b][a] = min(dist[b][a], c);
  }

  rep(k,0,n) rep(i,0,n) rep(j,0,n) 
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  vector<vector<i64>> able(n);

  rep(i,0,n) {
    rep(j,0,n) {
      if(dist[i][j] <= l) {
        able[i].push_back(j);
      }
    }
  }

  vector<vector<i64>> cost(n, vector<i64>(n, -1));

  rep(i,0,n) {
    queue<i64> que;
    que.push(i);
    cost[i][i] = 0;

    while(!que.empty()) {
      i64 v = que.front();
      que.pop();
      for(auto to: able[v]) {
        if(cost[i][to] == -1) {
          cost[i][to] = cost[i][v] + 1;
          que.push(to);
        }
      }
    }
  }

  i64 q;
  cin >> q;
  rep(qq, 0, q) {
    i64 s, t;
    cin >> s >> t;
    s--;
    t--;
    if(cost[s][t] == -1) {
      cout << -1 << endl;
    }
    else
      cout << cost[s][t] - 1 << endl;
  }
}


Measured memory_bytes: 3072
#include <iostream>
#include <cmath>

using ll = long long;

int main(){
    int x;
    std::cin >> x;
    for(ll a = 0; a < 6208; a++){
        for(ll b = -6208; b < a; b++){
            if(x == std::pow(a,5)-std::pow(b,5)){
                std::cout << a << " " << b << std::endl;
                return 0;
            }
        }
    }
}


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

int main(){
  
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  
  int count=0,ans=0,dif=0;
  for(int i=0;i<n-1;i++){
    count++;
  	if(s[i]!=s[i+1]){
      dif++;
      ans+=(count-1);
      count=0;
    }
  }
  ans+=count;

  if(dif%2==0){
    dif=(dif+1)/2;
    if(dif<k) ans+=dif*2;
    else ans+=k*2;
  }
  else {
  	dif=(dif+1)/2;
    if(dif<k) ans+=dif*2;
    else ans+=k*2;
  }
  if(k>=dif) ans=n-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

int cnt, n, m;
set <vector <set <int>>> ans;
void f(vector <string> d, vector <set <int>> deleted, int r, int c, int k){
	if(k < 0)
		return;
		
	if(k == 0){
		if(!ans.count(deleted))
			cnt++;		
		ans.insert(deleted);
	}

	for(int i = r; i < n; i++){
		vector <string> cp = d;
		vector <set <int>> cp_del = deleted;
		
		int tmp = 0;
		for(int j = 0; j < m; j++)
			if(cp[i][j] == '#'){
				cp[i][j] = '.';
				tmp++;
			}
		cp_del[0].insert(i);
		f(cp, cp_del, i+1, c, k - tmp);
	}
	
	for(int j = c; j < m; j++){
		vector <string> cp = d;
		vector <set <int>> cp_del = deleted;

		int tmp = 0;
		for(int i = 0; i < n; i++)
			if(cp[i][j] == '#'){
				cp[i][j] = '.';
				tmp++;
			}
		cp_del[1].insert(j);
		f(cp, cp_del, r, j+1, k - tmp);
	}
}

int main(){
	int k;
	cin >> n >> m >> k;
	
	vector <string> d(n);
	int calc = 0;
	for(int i = 0; i < n; i++){
		cin >> d[i];
		for(int j = 0; j < m; j++)
			if(d[i][j] == '#')
				calc++;
	}
	
	cnt = 0;
	f(d, vector <set <int>> (2), 0, 0, calc - k);
	
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 4200
import sys
l = 10**18
n = int(input())
A = list(map(int,input().split()))
S = 1
if 0 in A:
    print(0)
    sys.exit()
for i in range(n):
    S = S * A[i]
    if S > l:
        print(-1)
        break
if S <= l:
    print(S)

Measured memory_bytes: 21792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const int mod=998244353;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,ans = 1; cin >> n;
    int d[100010];
    map<int,int> mp;
    rep(i,n){
        cin >> d[i];
        mp[d[i]]++;
    }
    if(d[0] != 0 || mp[0] != 1){
        OUT(0);
        return 0;
    }
    FOR(i,1,n) (ans *= mp[d[i]-1]) %= mod;
    ANS;

    return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N];
int main(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	ll ans=0;int flag=1;
	if(a[1]!=0) {flag=0;printf("-1\n");return 0;}
	for(int i=n;i-1>=1;i--){
		if(a[i]==0) continue;
		if(a[i]>=i||a[i]>a[i-1]+1) {flag=0;printf("-1\n");return 0;}
		if(a[i]==a[i-1]+1) ans++;
		if(a[i]<=a[i-1]){ans+=a[i];}
	}
	printf("%lld\n",ans);	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int x, y, vis[1111111];
int main() {
	while (cin >> x >> y, x) {
		fill(vis, vis + y, -1);
		for (int i = 0; ; i++) {
			if (vis[x] != -1) {
				cout << vis[x] << ' ' << (x ? i - vis[x] : 0) << endl;
				break;
			}
			vis[x] = i;
			x = x * 10 % y;
		}
	}
}

Measured memory_bytes: 6996
#include<stdio.h>

int sosu(int a){
  int i = 2 , flag = 1;
  while(i*i <= a){
    if(a%i == 0){
      flag = 0;
      i += 10000000;
    }
    i ++;
  }

  return flag;
}

int main(void){
  int q;
  scanf("%d",&q);
  
  int l[q] , r[q];
  for(int i = 0;i < q;i ++){
    scanf("%d %d",&l[i] ,&r[i]);
  }

  int k[100010] = {0};
  for(int i = 3;i <= 100000;i += 2){
    int a = sosu(i);
    int b = sosu((i+1)/2);
    if(a == 1 && b == 1){
      //printf("%d\n",i);
      k[i] ++;
    }
  }

  for(int i = 1;i <= 100000;i ++){
    k[i+1] += k[i];
  }

  int count = 0;
  for(int i = 0;i < q;i ++){
   //printf("%d %d\n",k[r[i]] ,k[l[i]-1]);
    printf("%d\n",k[r[i]+1] - k[l[i]-1]);
  }

  return 0;
}

Measured memory_bytes: 2856
N = int(input())

ps = []
for n in range(N):
        ps.append( (n, int(input())) )

maxed = max(ps, key=lambda x:x[1])
maxed_index = maxed[0]
ps.pop(maxed_index)

b = maxed[1]/2
for p in ps:
        b += p[1]
print(int(b))

Measured memory_bytes: 3064
n,m = map(int,input().split())
raw = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  raw[a-1].append(b-1)
  raw[b-1].append(a-1)
#print(raw)
already = [0]
goal = [i for i in range(n)]
ans = 0
now = 0
last = 0
while True:
  try:
    if raw[now][last] not in already:
      now = raw[now][last]
      already.append(now)
      last = 0
    else:
      last += 1
  except:
    try:
      now = already[-2]
      last = raw[now].index(already[-1])+1
      already = already[:-1]
    except:
      print(ans)
      break
  if sorted(already) == goal:
    ans += 1
    now = already[-2]
    last = raw[now].index(already[-1])+1
    already = already[:-1]
  #print(now,already,last)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  string a,b;
  cin>>a>>b;
  int ans=0;
  rep(i,a.size())
  {
    if(a[i]!=b[i])
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


Measured memory_bytes: 3892
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string in;
	cin >> in;
	vector<vector<int>> buf;
	int last=-1;
	int j = -1;
	for (int i = 0; i < in.size();) {
		int now = in[i] == 'e' ? 0 : 1;
		if (last == now||last==-1) {
			j++;
			vector<int> a;
			buf.push_back(a);
		}
		buf[j].push_back(now);
		last = now;
		i += last ? 7 : 3;
	}
	int max = 0;
	for (auto a : buf) {
		max = std::max(max,(int) a.size());
	}
	for (auto a : buf) {
		if (max == a.size()) {
			cout << (a[a.size() - 1] ? "chicken" : "egg")<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3260
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(max(0, i-K), i):
    c[i] = min(c[j] + abs(h[i] - h[j]), c[i])
print(c[-1])

Measured memory_bytes: 52448
#!/usr/bin/env python3
import numpy as np

n,k = map(int, input().split())
p_list = np.fromstring(input(), int, sep=' ')

Cumulative_sum = np.zeros(n+1)
Cumulative_sum[1:] = p_list.cumsum()

length_k_sum_list = Cumulative_sum[k:] - Cumulative_sum[0:-k]

print((length_k_sum_list.max()+k)/2)


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

int main()
{
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;

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

	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
typedef long long lint;
const int N=3005;
int n,mod,S[N][N],C[N][N];

namespace utils{
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int fpow(int x,int t,const int mod=::mod){
	int ans=1;
	for(; t; x=(lint)x*x%mod,t>>=1){
		if(t&1) ans=(lint)ans*x%mod;
	}
	return ans;
}

int main(){
	n=nxi(),mod=nxi();
	S[0][0]=1;
	for(int i=0; i<=n+1; ++i){
		C[i][0]=1;
		for(int j=1; j<=i; ++j){
			S[i][j]=((lint)S[i-1][j]*j+S[i-1][j-1])%mod;
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		}
	}
	int ans=0;
	for(int i=0; i<=n; ++i){//内定不合法个数
		int bs=fpow(2,n-i);
		int ri=0,rv=fpow(2,fpow(2,n-i,mod-1));
		for(int j=0,st=1; j<=i; ++j,st=(lint)st*bs%mod)
			ri=(ri+(lint)S[i+1][j+1]*st)%mod;
		int res=(lint)rv*ri%mod*C[n][i]%mod;
		ans=(ans+(i&1?mod-res:res))%mod;
	}
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
const int N = 2e5+5 ; 
pll a[N] ; 
int main(){
int n ; 
cin >> n ; 
for(int i=0;i<n;i++){
	cin >> a[i].se >> a[i].fi ; 
}
ll s=0 ; 
sort(a,a+n) ; 
for(int i = 0 ; i < n ; i++ ){
	s += a[i].se ; 
	if( s > a[i].fi ){
		cout << "No" << endl; 
		return 0 ; 
	}
}
cout << "Yes" << endl ; 
}


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

int main(){
  int A,B,T;
  cin >> A >> B >> T;
  
  int sum = 0;
  for(int i=A; i<T+0.5; i=i+A){
    sum += B;
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	//
  int H, W;
  cin >> H >> W;
  for(int i=0; i<W+2; i++)
    cout << "#";
  cout << endl;
  
  for(int i=0; i<H; i++){
    cout << "#";
    
    vector<char> pic(W);
     for(int i=0; i<W; i++){
      cin >> pic. at(i);
      cout << pic. at(i);
    }
    cout << "#" << endl;
  }
  
    for(int i=0; i<W+2; i++)
    cout << "#";
  cout << endl;
 }

Measured memory_bytes: 3580
import java.util.*;
import java.math.*;

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

		for (int i = 0; i < h; i++) {
			String aLine = sc.next();
			String[] aArray = aLine.split("");
			for (int j = 0; j < w; j++) {
				String a = aArray[j];
				table[i][j] = a.equals("#") ? 0 : h * w;
			}
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int leftValue = j > 0 ? table[i][j - 1] + 1 : table[i][j];
				int topValue = i > 0 ? table[i - 1][j] + 1 : table[i][j];
				table[i][j] = Math.min(Math.min(leftValue, topValue), table[i][j]);
			}
			for (int j = w - 1; j >= 0; j--) {
				int rightValue = j < w - 1 ? table[i][j + 1] + 1 : table[i][j];
				table[i][j] = Math.min(rightValue, table[i][j]);
			}
			// System.out.println();
		}
		for (int i = h - 1; i >= 0; i--) {
			for (int j = 0; j < w; j++) {
				int leftValue = j > 0 ? table[i][j - 1] + 1 : table[i][j];
				int bottomValue = i < h - 1 ? table[i + 1][j] + 1 : table[i][j];
				table[i][j] = Math.min(Math.min(leftValue, bottomValue), table[i][j]);
			}
			for (int j = w - 1; j >= 0; j--) {
				int rightValue = j < w - 1 ? table[i][j + 1] + 1 : table[i][j];
				table[i][j] = Math.min(rightValue, table[i][j]);
			}
			// System.out.println();
		}

		int count = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				count = Math.max(count, table[i][j]);
			}
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 65120
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	ll n;
	cin >> n;
	string s;
	ll cnt[5];
	ll ans=0;
	REP(i, 5){
		cnt[i] = 0;
	}
	REP(i, n){
		cin >> s;
		if (s[0] == 'M'){
			cnt[0]++;
		}
		else if (s[0] == 'A'){
			cnt[1]++;
		}
		else if (s[0] == 'R'){
			cnt[2]++;
		}
		else if (s[0] == 'C'){
			cnt[3]++;
		}
		else if (s[0] == 'H'){
			cnt[4]++;
		}
	}
	REP(i, 5){
		for (int j = i + 1; j < 5; j++){
			for (int k = j + 1; k < 5; k++){
				ans += cnt[i] * cnt[j] * cnt[k];

			}

		}


	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    int n; cin>>n;
    vector<int> a(n+1,0);
    for(int i = 1; i <= n; i++) cin>>a[i];
    int sum = 0;
    for(int i = 1; i <= n; i++){
        if(a[a[i]] == i) sum++;
    }
    cout << sum/2<<endl;
    return 0;
    
}


Measured memory_bytes: 640
N = int(input())
S = str(input())
R,G,B = 0,0,0
for i in range(N):
    if S[i] == 'R':
        R += 1
    elif S[i] == 'B':
        B += 1
    else:
        G += 1

exc = 0
for j in range(1,N-1):
    num = 1
    while 0 <= j-num and j+num < N:
        if S[j-num] != S[j+num] and  S[j-num] != S[j] and  S[j] != S[j+num]:
            exc += 1
        num += 1

print(int(R*B*G - exc))

Measured memory_bytes: 9220
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    s = list(map(int, readline().split()))
    t = list(map(int, readline().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]

    for i, val_s in enumerate(s, 1):
        for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

    print(dp[n][m] + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72156
s = input()
t = input()
n = len(s)
memo = {}
for i in range(n):
    if s[i] not in memo:
        memo[s[i]] = t[i]
    else:
        if memo[s[i]] != t[i]:
            print("No")
            exit()
s, t = t, s 
memo = {}
for i in range(n):
    if s[i] not in memo:
        memo[s[i]] = t[i]
    else:
        if memo[s[i]] != t[i]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 41712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n;
    cin >> n;
    VI a(n), index(n);
    FOR(i, 0, n) {
        cin >> a[i];
        index[--a[i]] = i;
    }

    ll ans = 0;
    set<int> set = { -1,n };
    FOR(i, 0, n) {
        ll b = index[i];
        auto itr = set.lower_bound(b);
        ll c = *itr, a = *--itr;
        ans += (b - a) * (c - b) * (i + 1LL);
        set.insert(b);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 11264
import sys
from operator import itemgetter
from heapq import heapify, heappush, heappop

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
queue = []

for i, (S, T, X) in enumerate(zip(*[iter(STX)] * 3), 1):
    queue.append((S - X - 0.5, X, i))
    queue.append((T - X - 0.5, -X, i))

for D in STXD[3 * N:]:
    queue.append((D, 0, 0))

queue.sort(key=itemgetter(0), reverse=True)
heap = []
heapify(heap)
stop, construction = -1, 0
not_available = set()
while queue:
    _, x, n = queue.pop()
    if x == 0:
        print(stop)
    elif x < 0:
        not_available.add(n)
        if n == construction:
            while heap:
                stop, construction = heappop(heap)
                if construction not in not_available:
                    break
            else:
                stop, construction = -1, 0
    else:
        if stop != -1:
            if stop <= x:
                heappush(heap, (x, n))
            else:
                heappush(heap, (stop, construction))
                stop, construction = x, n
        else:
            stop, construction = x, n


Measured memory_bytes: 132396
#include <bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
 
 
typedef long long ll;
typedef long double ld;
 
using namespace std;
 
const int MX = 1200;
const ll MOD = 1e9 + 7;
 
ll fc[MX];
ll bfc[MX];
ll dp[MX];
ll dp2[MX];
 
ll pw(ll a, ll b) {
	ll ans = 1;
	while (b) {
		while(!(b & 1))
			b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD;
		--b;
	}
	return ans;
}
 
void init() {
	fc[0] = 1;
	for (int i = 1; i < MX; ++i)
		fc[i] = (fc[i - 1] * i) % MOD;
	for (int i = 0; i < MX; ++i)
		bfc[i] = pw(fc[i], MOD - 2);
}
 
ll cnk(int n, int k) {
	if (n < k)
		return 0;
	return fc[n] * bfc[k] % MOD * bfc[n - k] % MOD;
}
 
int n;
int a, b, c, d;
int main() {
	init();
	cin >> n >> a >> b >> c >> d;
	dp[0] = 1;
	for (int i = a; i <= b; ++i) {
		for (int j = 0; j <= n; ++j)
			dp2[j] = dp[j];
		ll bf = 1;
		ll b1 = bfc[i];
		for (int k = 1; k < c; ++k)
			bf = (bf * b1) % MOD;
		for (int k = c; k <= d; ++k) {
			bf = (bf * b1) % MOD;
			ll bk = (bf * bfc[k]) % MOD;
			int cnt = k * i;
			if (cnt > n)
				break;
			for (int j = 0; j + cnt <= n; ++j)
				dp2[j + cnt] = (dp2[j + cnt] + dp[j] * cnk(n - j, cnt) % MOD * fc[cnt] % MOD * bk) % MOD;
		}
		for (int j = 0; j <= n; ++j)
			dp[j] = dp2[j];
	}
	cout << dp[n] << "\n";
	return 0;
}
 

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<i64>();
    let (x, t) = (line[0], line[1]);

    println!("{}", cmp::max(0, x-t));
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
#define maxn 1e6;
int main()
{
	int n;
	char s[110];
	int ls, t;
	int i, j;
	int a[110];
	int max;
	scanf("%d", &n);
		scanf("%s", &s);
		ls = strlen(s);

		memset(a, 0, sizeof(a));
		a[0] = 0;
		for(i = 0; i < ls; i++)
		{
			if(s[i] == 'D')
				a[i + 1] = a[i] - 1;
				else
					a[i + 1] = a[i] + 1;
		}
		max = a[0];
	
		for(i = 1; i <=ls; i++)
		{
			
			if(max < a[i])
			{
				t = max;
				max = a[i];
				a[i] = t;
			}
		}
		printf("%d\n", max);
		//for(i = 0; i < ls; i++)
		//	printf("%c\n", s[i]);
		//	printf("%d\n", ls); 
}

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

int main() {
	int X = 0;
	cin >> X;

	int p = 0;
	int q = 0;

	p = X / 100;
	q = X % 100;

	vector<int> r(5, 0);

	for (int i = 5; i > 0; i--) {
		r[i - 1] = q / i;
		q = q % i;
	}

	int sum = accumulate(r.begin(), r.end(), 0);

	if (p >= sum) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define PI 3.14159265358979323846

int main(void) {
	char b;
	scanf("%c", &b);

	if (b == 'A') {
		printf("T");
	}
	else if (b == 'T') {
		printf("A");
	}
	else if (b == 'C') {
		printf("G");
	}
	else {
		printf("C");
	}



	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] n = new int[sc.nextInt()];
		int count = 0;
		
		for (int i = 0; i < n.length; i++) {
			n[i] = sc.nextInt();
		}
		
		while (true) {
			for (int i = 0; i < n.length; i++) {
				if (n[i] % 2 == 0) {
					n[i] /= 2;
				} else {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
		
	}
}

Measured memory_bytes: 21588
h,w = map(int, input().split())
al = [input() for _ in range(h)]

for hi in range(h-1):
    for wi in range(w-1):
        if al[hi][wi]==al[hi+1][wi]==al[hi][wi+1]=="#":
            print("Impossible")
            exit()
        if al[hi+1][wi]==al[hi+1][wi+1]==al[hi][wi+1]=="#":
            print("Impossible")
            exit()
print("Possible")

Measured memory_bytes: 3064
def saiki(s,le)
  if(le == $len)
    s += $a[le]
    ansp = s.split(" ").map(&:to_i)
    $ans += ansp.inject(:+)
    return 
  end
  s += $a[le]
  saiki(s,le+1)
  s += " "
  saiki(s,le+1)
end
$ans = 0
$a = gets.chomp
$len = $a.size - 1
saiki("",0)
puts $ans



Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  string s;
  cin >> s;
  vector<int> v(26);
  rep (i, s.size()) {
    v[s[i] - 'a']++;
  }
  char ans = 'a';
  rep (i, 26) {
    if (v[i] == 0) {
      P(ans);
      return 0;
    }
    ans++;
  }
  P("None");
  return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (2e5);
    static List<Integer>[] edges;
  
	public static void main(String[] args) {
	   
	    int n = sc.nextInt();
	    long k = sc.nextLong();
	    int[] a = new int[n+1];
	    boolean[] vis = new boolean[n+1];
	    for(int i=1;i<=n;++i) {
	    	a[i] = sc.nextInt();
	    }
	    int[] dis = new int[n+1];
	    int d = 1,cycle = 0;
	    int node = 1;
	    dis[node] = 1;
	    vis[node] = true;
	    int st = 1;
	    List<Integer> list = new ArrayList<Integer>();
	    list.add(1);
	    while(true) {
	    	node = a[node];
	    	if(vis[node]) {
	    		st = node;
	    		cycle = d-dis[node]+1;
	    		break;
	    	}else {
	    		++d;
	    		vis[node] = true;
	    		dis[node] = d;
	    		list.add(node);
	    	}
	    }
	  //  System.out.println(cycle+" "+d+" "+st+" "+list+" "+Arrays.toString(dis));
	 
	    int ans = 0;
	    if(k+1 <= d) {
	    	 ans = list.get((int) k);
	    }else {
	    	k-=d;
	    	k%=cycle;
	    	boolean found = false;
	    	for(int i=0;i<list.size();++i) {
	    		if(list.get(i) == st)  found = true;
	    		if(found) {
	    		
	    			if(k == 0) {
	    				ans = list.get(i);
	    				break;
	    			}
	    			--k;
	    		}
	    	}
	    }
	    out.print(ans);
		out.close();
   }
	
	
}



Measured memory_bytes: 56468
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

void transforms(const string& s1,set<string>& s){
    string tmp;
    for(int i = 0; i < s1.length();i++){
        tmp = s1;
        tmp.erase(tmp.begin() + i);
        s.insert(tmp);
    }
    for(int i = 0; i <=s1.length();i++){
        for(int j = 0; j < 26;j++){
            tmp = s1;
            char c = 'a' + j;
            tmp.insert(i,string(1,c));
            s.insert(tmp);
        }
    }
    for(int i = 0; i < s1.length();i++){
        for(int j = 0; j < 26;j++){
            tmp = s1;
            char c = 'a' + j;
            tmp.replace(i,1,string(1,c));
            s.insert(tmp);
        }
    }
    for(int i = 0; i < s1.length() - 1;i++){
        tmp = s1;
        swap(tmp[i],tmp[i+1]);
        s.insert(tmp);
    }
}

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,d;
    vector<pii> res;
    vector<string> name;
    set<string> s[201];
    while(cin >> n, n){
        cin >> d;
        res.clear();
        name.clear();
        name.resize(n);
        for(int i = 0; i < n;i++){
            cin >> name[i];
        }
        sort(name.begin(),name.end());
        
        for(int i = 0; i < n;i++){
            s[i].clear();
            transforms(name[i],s[i]);
        }
        
        if(d == 1){
            for(int i = 0; i < n - 1;i++){
                for(int j = i + 1; j < n;j++){
                    if(s[i].find(name[j]) != s[i].end()){
                        res.push_back({i,j});
                    }
                }
            }
        }else{
            for(int i = 0; i < n-1;i++){
                for(int j = i + 1; j < n;j++){
                    for(auto tmp_s:s[i]){
                        if(s[j].find(tmp_s) != s[j].end()){
                            res.push_back({i,j});
                            break;
                        }
                    }
                }
            }
        }
        
        for(auto ans:res){
            cout << name[ans.first] << "," <<name[ans.second]<<endl;
        }
        cout << res.size() << endl;
    }
    return 0;
}

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

const int MN = 200005;
const ll M = ll(1e9) + 7;

struct E{ int x, i; };

int n, ln, vis[MN], cyc[MN], as[MN], nas[MN], vc, ec, sz[MN], oth[MN], hp[MN], fnd;
vector<E> e[MN];
vector<int> vl, cv, tv, ch[MN];
ll fc[MN], ifc[MN], ans = 1;

void T_T(){
	puts("0");
	exit(0);
}

ll pw(ll x, ll k){
	if(k == 1) return x;
	return pw(x * x % M, k / 2) * (k % 2 ? x : 1) % M;
}

ll cm(int n, int r){
	return fc[n] * ifc[r] % M * ifc[n - r] % M;
}

void g(int x){
	vis[x] = 1;
	vc++;
	ec += e[x].size();
	tv.push_back(x);
	for(auto &i : e[x]) if(!vis[i.x]) g(i.x);
}

void h(int x, int p){
	//printf("%d\n", x);
	if(vis[x] == 2){
		//puts("CYCLE");
		cyc[x] = 1;
		cv.push_back(x);
		for(int i = int(vl.size()) - 1; vl[i] != x; i--){
			//printf("%d\n", vl[i]);
			cyc[vl[i]] = 1;
			cv.push_back(vl[i]);
		}
		//puts("--");
		fnd = 1;
		return;
	}
	vis[x] = 2;
	vl.push_back(x);
	for(auto &i : e[x]){
		if(i.x != p){
			//printf("%d -> %d\n", x, i.x);
			h(i.x, x);
		}
		if(fnd) return;
	}
	vl.pop_back();
}

void af(int x, int p){
	for(auto &i : e[x]){
		if(i.x != p && !cyc[i.x]){
			as[i.x] = nas[i.x] = i.i;
			af(i.x, x);
		}
	}
}

void cf(){
	int cs = int(cv.size());
	for(int i = 0; i < cs; i++){
		for(auto &j : e[cv[i]]){
			if(j.x == cv[(i + 1) % cs]){
				//printf("%d : %d - %d (%d)\n", i, cv[i], j.x, j.i);
				as[cv[i]] = nas[j.x] = j.i;
			}
		}
	}
}

int sf(int x){
	sz[x] = 1;
	vc++;
	for(auto &i : ch[x]) sz[x] += sf(i);
	return sz[x];
}

ll tf(int x){
	ll ret = 1;
	int cs = sz[x] - 1;
	for(auto &i : ch[x]){
		ret = ret * cm(cs, sz[i]) % M;
		ret = ret * tf(i) % M;
		cs -= sz[i];
	}
	//printf("tf %d : %lld\n", x, ret);
	return ret;
}

ll get(){
	//puts("GET");
	for(auto &i : tv){
		int to = oth[as[i]] - i;
		for(auto &j : e[i]){
			if(j.x < to){
				//printf("%d - %d\n", j.x, i);
				ch[i].push_back(j.x);
				hp[j.x]++;
			}
		}
	}
	ll ret = 1;
	int tln = int(tv.size());
	for(auto &i : tv){
		if(!hp[i]){
			vc = 0;
			sf(i);
			ret = ret * cm(tln, vc) % M;
			ret = ret * tf(i) % M;
			tln -= vc;
		}
	}
	for(auto &i : tv){
		for(auto &j : ch[i]){
			hp[j]--;
		}
		ch[i].clear();
	}
	return ret;
}

ll f(int x){
	vl.clear();
	cv.clear();
	fnd = 0;
	h(x, x);
	for(auto &i : cv) af(i, i);
	cf();
	//for(auto &i : cv) printf("%d : %d %d\n", i, as[i], nas[i]);
	ll t = get();
	for(auto &i : cv) as[i] = nas[i];
	t += get();
	return t % M;
}

int main(){
	scanf("%d", &n);
	for(int i = 1, x, y; i <= 2 * n; i++){
		scanf("%d%d", &x, &y);
		y += n;
		e[x].push_back({y, i});
		e[y].push_back({x, i});
		oth[i] = x + y;
	}
	fc[0] = ifc[0] = 1;
	for(int i = 1; i <= 2 * n; i++){
		fc[i] = fc[i - 1] * i % M;
		ifc[i] = pw(fc[i], M - 2);
	}
	ln = 2 * n;
	for(int i = 1; i <= 2 * n; i++){
		if(!vis[i]){
			vc = ec = 0;
			tv.clear();
			g(i);
			if(ec != 2 * vc) T_T();
			//printf("%d %d\n", ln, vc);
			ans = ans * cm(ln, vc) % M;
			ln -= vc;
			//printf("%lld\n", ans);
			ans = ans * f(i) % M;
			//printf("////// %lld\n", ans);
		}
	}
	printf("%lld\n", ans);
}

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

int main() {

  string w;
  cin >> w;

  vector<int> count(26);
  
  for (int i = 0; i < w.size(); i++) {
    count[w[i] - 'a']++;
  }

  string answer = "Yes";

  for (int i = 0; i < 26; i++) {
    if (count[i] % 2 == 1) {
      answer = "No";
      break;
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <math.h>
#include <algorithm>


//My Answer；
using namespace std;

int main()
{
    char A[10], B[10], C[10];
    int a, b;
    
    cin >> A >> B;
    cout << endl;
    cin >> a >> b;
    cout << endl;
    cin >> C;
    
    if (strcmp(C, A) == 0)
    {
        cout << (a - 1) << " " << b;
    }
    else if (strcmp(C, B) == 0)
    {
        cout << a << " " << (b - 1);
    }
}


Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X = lr()
M = [ir() for _ in range(N)]
M.sort()
answer = N
X -= sum(M)
answer += X // M[0]
print(answer)


Measured memory_bytes: 3060
#include <stdio.h>
#define MAX_N 100
#define MAX_A 1000

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

	for(i = 0; i < n;i++){
		scanf("%d",&a[i]);
	}

printf("%d",a[0]);
    	for(k = 1; k< n;k++){
    		printf(" %d", a[k]);
    	}
    	printf("\n");

    for(i = 1; i< n; i++){
    	v = a[i];
    	j = i-1;
    	while(j >= 0 && a[j] > v){
    		a[j+1] = a[j];
    		j--;
    	}
    	a[j+1] = v;
    	printf("%d",a[0]);
    	for(k = 1; k< n;k++){
    		printf(" %d", a[k]);
    	}
    	printf("\n");
    }

   return 0;
}

Measured memory_bytes: 1852
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm> // sort
#include <iomanip>
#include <queue>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
typedef pair<int,int> pint;

const int MOD = 1000000007;

//A[i] を B[i]の倍数にする
//操作1項目から i項目を+1 できる
// 末尾から、B[i]になるように修正する

int main(){

#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll n;
    cin >> n;
    vector <ll> a(n);
    vector <ll> b(n);
    REP(i,n)
    {
        cin >> a[i] >> b[i];
    }
    ll res = 0;

    for(ll i = n-1; i >= 0; --i)
    {
        a[i] += res;
        ll tmp = a[i] % b[i];
        if(tmp != 0)tmp = b[i] - tmp;
        res += tmp;
    }


    cout << res << endl;

    return 0;     
}



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

long double a,b,x,p;
long double angle;

int main()
{
	cin >> a >> b >> x;
	if(0.5*a*a*b==x) angle=atan((double)b/a);
	else if(0.5*a*a*b>x)
	{
		a=x*2/b/a;
		angle=atan((double)b/a);
	}
	else
	{
		p=2*x/a/a-b;
		angle=atan((double)(b-p)/a);
	}
	cout << fixed << setprecision(10) << angle/M_PI*180 << endl;
	return 0;
}


Measured memory_bytes: 256