akhauriyash/Code-Regression huggingface dataset:
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            String s=scan.next();
            String tt=scan.next();
            int m=tt.length();
            int n=s.length();
            int ans=m;
            for(int i=0;i+m-1<n;i++){
                int c=0;
                for(int j=0;j<m;j++){
                    if(s.charAt(i+j)!=tt.charAt(j)){
                        c++;
                    }
                }
                ans=Math.min(ans,c);
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


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

#define o cout<<"Hello did you expect this?"<<endl;
#define ll long long
#define pb push_back
#define mp make_pair//with Z
#define F first
#define S second

using namespace std;

const int N = 6e6 + 100;
const int mod = 1e9 + 7;

void hey () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int was[N];
vector<int> g[N];
ll found = 0;
vector<int> b;
ll pid = -1;
vector<int> c;
void dfs(int v) {
	was[v] = 1;
	bool ok = 0;
	for (int i = 0; i < g[v].size(); i++) {
		if (!was[g[v][i]]) {
			ok = 1;
			dfs(g[v][i]);
		}
	}
	if (!ok) {
		pid = g[v][0];
		return;
	}
}
void dfsl(int v, int l) {
	if (v == pid) {
		found = l;
		return;
	}
	b.pb(v);
	was[v] = 1;
	bool ok = 0;
	for (int i = 0; i < g[v].size(); i++) {
		if (!was[g[v][i]]) {
			ok = 1;
			dfsl(g[v][i], l + 1);
		}
	}
}
void dfsw(int v) {
	was[v] = 1;
	c.pb(v);
	for (int i = 0; i < g[v].size(); i++) {
		if (!was[g[v][i]]) {
			dfsw(g[v][i]);
		}
	}
}
int main () {
	hey();
	ll n, k;
	cin >> n >> k;
	ll a[n + 1];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		g[i].pb(a[i]);
	}
	dfs(1);
	memset(was,0,sizeof(was));
	dfsl(1, 1);
	memset(was,0,sizeof(was));
	dfsw(pid);
	if (k < b.size())
	{
		cout << b[k];
	}
	else {
		k -= b.size();
		k %= c.size();
		cout << c[k];
	}
}


Measured memory_bytes: 188208
from operator import itemgetter
import bisect
N, M = map(int, input().split())
data = []
for i in range(M):
    p, y = map(int, input().split())
    data.append([p, y])

database = [[] for i in range(N+1)]
for i in range(M):
    database[data[i][0]].append(data[i][1])
for i in range(1, N+1):
    database[i].sort()

for i in range(M):
    pref = data[i][0]
    number = bisect.bisect_left(database[pref], data[i][1]) + 1
    pref = format(pref, "06")
    number = format(number, "06")
    print(str(pref) + str(number))


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

typedef long long ll;
typedef pair<int, int> ii;

ll n, x, d;

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x >> d;
  if (d == 0) {
    if (x == 0) {
      cout << 1 << endl;
    } else {
      cout << n + 1 << endl;
    }
    exit(0);
  }
  ll g = gcd(x, d);
  x /= g;
  d /= g;
  if (d < 0) {
    x = -x;
    d = -d;
  }
  unordered_map<ll, set<pair<ll, ll>>> ma;
  for (ll k = 0; k <= n; ++k) {
    ll minv = k * (k - 1) / 2;
    ll maxv = ((n - k) + (n - 1)) * k / 2;
    ll kind = k * x % d;
    ll offset = k * x / d;
    // cout << k << ' ' << minv << ' ' << maxv << endl;
    ma[kind].insert(make_pair(minv + offset, maxv + offset));
  }
  ll res = 0;
  for (auto p : ma) {
    auto s = p.second;
    ll pend = LLONG_MIN;
    for (auto pp : s) {
      ll start = pp.first, end = pp.second;
      if (pend < end) {
        if (pend < start) {
          res += end - start + 1;
        } else {
          res += end - pend;
        }
        pend = end;
      }
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 37760
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int age = sc.nextInt();
    if (age == 25) System.out.println("Christmas");
    if (age == 24) System.out.println("Christmas Eve");
    if (age == 23) System.out.println("Christmas Eve Eve");
    if (age == 22) System.out.println("Christmas Eve Eve Eve");    
  }
}

Measured memory_bytes: 23892
b=input()
 
def f(b):
  if(b!="A" and b!="T" and b!="C" and b!="G"):
    print("error")
  elif(b=="A"):
  	return "T"
  elif(b=="T"):
  	return "A"
  elif(b=="C"):
  	return "G"
  elif(b=="G"):
  	return "C"
  
print(f(b))

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

int main()
{
    int n;
    int a[1001];
    double ans=0;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for (int i = 0; i < n; i++)
    {
        ans+=1./a[i];
    }
    printf("%lf\n",1./ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int h, w, n, x, y;
int in_D, in_U, in_R, in_L;
int go_U, go_D, go_L, go_R;
signed main() {
	cin >> h >> w >> n >> x >> y;
	string s, t;
	cin >> s >> t;
	go_U = x, go_D = x, go_L = y, go_R = y;
	rep(i, n) {
		if (s[i] == 'U') {
			go_U--;
		}
		else if (s[i] == 'D') {
			go_D++;
		}
		else if (s[i] == 'L') {
			go_L--;
		}
		else {
			go_R++;
		}
		if (go_U <= 0 || go_D > h || go_L <= 0 || go_R > w) {
			cout << "NO" << endl;
			return 0;
		}
		if (t[i] == 'U') {
			go_D = max(go_D - 1, 1LL);
		}
		else if (t[i] == 'D') {
			go_U = min(go_U + 1, h);
		}
		else if (t[i] == 'L') {
			go_R = max(1LL, go_R - 1);
		}
		else {
			go_L = min(w, go_L + 1);
		}
	}
	cout << "YES" << endl;
}


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

int dfs(int now, vector<vector<int>>& adj_mat, bool* visited)
{
	bool all_visited = true;
	for(int i = 0; i < adj_mat.size(); i++){
		if(!visited[i]){
			all_visited = false;
			break;
		}
	}
	if(all_visited){
		// cout << "found one!" << endl;
		return 1;
	}
	int ways = 0;
	for(int i = 1; i < adj_mat.size(); i++){
		if(adj_mat[now][i] && !visited[i]){
			// cout << now << " to " << i << endl;
			visited[i] = true;
			ways += dfs(i, adj_mat, visited);
			visited[i] = false;
		}
	}
	return ways;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> adj_mat(N, vector<int>(N));

	for(int i = 0; i < M; i++){
		int a, b;
		cin >> a >> b;
		adj_mat[a - 1][b - 1] = 1;
		adj_mat[b - 1][a - 1] = 1;
	}

	bool visited[N];
	memset(visited, 0, sizeof(visited));
	visited[0] = true;
	int ways = dfs(0, adj_mat, visited);
	cout << ways << endl;
}

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

int main(void) {
	int n, i;
	cin >> n;
	map<string, int> st;
	for (i = 0; i < n; i++) {
		string s;
		cin >> s;
		st[s]++;
	}
	int m;
	cin >> m;
	for (i = 0; i < m; i++) {
		string s;
		cin >> s;
		st[s]--;
	}
	int  A = 0;
	for (pair<string, int> pa : st) {
		A = max(pa.second, A);
	}
	cout << A << endl;
	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	string s;
	cin >> s;
	int len = s.length();
	for(int i = 0; i < len; i++) {
		for(int j = 0; j < len - i; j++) {
			string t = s;
			t.erase(i, j);
			//cerr << t << endl;
			if(t == "keyence") {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;	
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
#define outdicimal out << fixed << setprecision(10)//TODO 小数点以下の桁数の変更
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;


class ASecurity {
public:
	void solve(std::istream& in, std::ostream& out) {
	  string s;
	  in >> s;
	  char now = 'a';
	  REP(i,s.length()){
	    if(now == s[i]){
	      out << "Bad" << endl;
	      return;
	    }
	    else{
	      now = s[i];
	    }
	  }
	  out << "Good" << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	ASecurity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <time.h>
#define INF 100000000

using namespace std;
typedef long long int ll;

int main()
{
	int n, ans=INF;
  scanf("%d", &n);
	for(int i=1; i<n; i++){
		int a=i, b=n-i, ans1=0;
		while(a>0){
			ans1+=(a%10);
			a/=10;
		}
		while(b>0){
			ans1+=(b%10);
			b/=10;
		}
		if(ans>ans1) ans=ans1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int s;
int main()
{
	cin>>s;
       cout<<s/3600<<':'<<(s/60)%60<<':'<<s%60<<endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
long long int arr[100100];
long long int dp[100100];
int main()
{
    int n,i,j,k,x,y,ans=0,curr,last;
    scanf("%d %d",&n,&k);
    for(i=1;i<=n;i++)
        scanf("%lld",&arr[i]);
    if(n == 2)
    {
        printf("%d\n",abs(arr[1]-arr[2]));
    }
    else
    {
        dp[1] = 0;
        for(i=2;i<=n;i++)
        {
            dp[i] = dp[i-1] + abs(arr[i] - arr[i-1]);
            int cnt = k-1;
            for(j=i-2;j>=1 && cnt > 0;j--)
            {
                dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]));
                cnt--;
            }
        }
        printf("%lld\n",dp[n]);
    }
    return 0;
}


Measured memory_bytes: 1792
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

max = A.max
if K > max
  puts 'IMPOSSIBLE'
  exit 0
end

gcd = A.reduce { |acc, a| acc.gcd(a) }
puts(K % gcd == 0 ? 'POSSIBLE' : 'IMPOSSIBLE')

Measured memory_bytes: 8452
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		String[] list = new String[h];
		for (int i = 0; i < list.length; i++) {
			list[i] = sc.next();
		}
		
		char[][] square = new char[h + 2][w + 2];
		for (int i = 0; i < h + 2; i++) {
			for (int j = 0; j < w + 2; j++) {
				if (i == 0 || i == h + 1) {
					square[i][j] = '#';
					continue;
				}
				
				if (j == 0 || j == w + 1) {
					square[i][j] = '#';
					continue;
				}
				
				square[i][j] = list[i - 1].charAt(j - 1);
			}
		}
		
		for (int i = 0; i < h + 2; i++) {
			for (int j = 0; j < w + 2; j++) {
				System.out.print(square[i][j]);
			}
			System.out.println();
		}
		
	}
}

Measured memory_bytes: 24028
#include <stdio.h>

int main() {
  int  a, b;
  
  scanf("%d%d", &a, &b);
  int r = 0 ;
  for(int  i=a; i<= b; i++) {
    int s = i % 10,  t = i / 10000 % 10;
    int u = i / 10 % 10, v = i / 1000 % 10;
    if  (s == t&&u == v) r++;
  }
  
  printf("%d\n", r);
  return 0;
}

Measured memory_bytes: 128
using System;

        public class Program
        {
            public static void Main(string[] args)
            {
            string input = Console.ReadLine();
            string answer = "";

            foreach(char i in input)
            {
                switch (i)
                {
                    case '1':
                        answer += '9';
                        break;
                    case '9':
                        answer += '1';
                        break;
                    default:
                        answer += i;
                        break;
                }
            }

            Console.WriteLine(answer);
            }
        }

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

n = int(input())
A = list(map(int, input().split()))
q = int(input())

from collections import Counter
C = Counter(A)
C = dict(C)
S = sum(A)
for i in range(q):
    b, c = map(int, input().split())
    if b in C:
        vb = C[b]
        C[b] = 0
        S -= b*vb
        S += c*vb
        print(S)
        if c in C:
            C[c] += vb
        else:
            C[c] = vb
    else:
        print(S)


Measured memory_bytes: 92676
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
int x,y;
int a[20010];

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

	cin>>n;
	cin>>x>>y;
	for(int i=1;i<=n;i++)
        cin>>a[i];
    if(n==1)
        cout<<abs(y-a[1]);
    else
        cout<<max(abs(y-a[n]),abs(a[n-1]-a[n]));

	return 0;
}


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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double

int n, m, h[100001], sta[100001];
vector<int> edge[100001];

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

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> h[i];

    int a, b;
    for (int i = 0; i < m; i++)
        cin >> a >> b, edge[a].push_back(b), edge[b].push_back(a);

    for (int i = 1; i <= n; i++)
        if (!sta[i])
        {
            bool fail = false;
            for (int j : edge[i])
                if (h[i] > h[j])
                    sta[j] = -1;
                else
                {
                    fail = true;
                    break;
                }

            if (!fail)
                sta[i] = 1;
        }

    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans += (sta[i] == 1);
    cout << ans << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *


Measured memory_bytes: 9532
while True:
    text = input().split()
    a = int(text[0])
    op = text[1]
    b = int(text[2])

    if op == "?":
        break
    
    elif op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)





Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if(a >= k) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
D = dict()
for i in range(n):
    a, b = map(int, input().split())
    if a in D.keys():
        D[a] += b
    else:
        D[a] = b

D = sorted(D.items(), key=lambda x: x[0])
for d in D:
    if k <= d[1]:
        print(d[0])
        break
    else:
        k -= d[1]

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

constexpr int MOD = 1'000'000'007;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
    using mint = ModInt<MOD>;
    int n, k;
    cin >> n >> k;
    
    vector<mint> ans(k + 1, 0);
    for (int i = k; i > 0; i--) {
        mint d = (k / i);
        mint res = d.pow(n);
        for (int j = i; j <= k; j += i) res -= ans[j];
        ans[i] = res;
    }
    
    mint val = 0;
    for (int i = 1; i <= k; i++) {
        val += (ans[i] * i);
    }
    
    cout << val << '\n';
    return 0;
}

Measured memory_bytes: 3764
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getErr(e error) {
	panic(e)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	var N, K int
	var err error
	answer := 0

	scanner.Scan()
	N, err = strconv.Atoi(scanner.Text())
	if err != nil {
		getErr(err)
	}

	scanner.Scan()
	K, err = strconv.Atoi(scanner.Text())
	if err != nil {
		getErr(err)
	}

	p := make([]int, N)

	for i := 0; i < N; i++ {
		scanner.Scan()
		number := 0
		number, err = strconv.Atoi(scanner.Text())
		if err != nil {
			getErr(err)
		}
		p[i] = number

	}

	sort.Ints(p)

	for i := 0; i < K; i++ {
		answer += p[i]
	}

	fmt.Println(answer)
}


Measured memory_bytes: 1776
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int H, W;
char field[1001][1001];
int dist[1001][1001];
queue<P> que;

void dfs() {
    while(!que.empty()) {
        P now = que.front();
        if (now.first > 0 && dist[now.first - 1][now.second] < 0) {
            dist[now.first - 1][now.second] = dist[now.first][now.second] + 1;
            que.push(make_pair(now.first - 1, now.second));
        }
        if (now.second > 0 && dist[now.first][now.second - 1] < 0) {
            dist[now.first][now.second - 1] = dist[now.first][now.second] + 1;
            que.push(make_pair(now.first, now.second - 1));
        }
        if (now.first < H - 1 && dist[now.first + 1][now.second] < 0) {
            dist[now.first + 1][now.second] = dist[now.first][now.second] + 1;
            que.push(make_pair(now.first + 1, now.second));
        }
        if (now.second < W - 1 && dist[now.first][now.second + 1] < 0) {
            dist[now.first][now.second + 1] = dist[now.first][now.second] + 1;
            que.push(make_pair(now.first, now.second + 1));
        }
        que.pop();
    }
}

int main() {
    cin >> H >> W;

    for (int i = 0; i < H; i++) {
        scanf("%s", field[i]);
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            dist[i][j] = -1;
            if (field[i][j] == '#') {
                dist[i][j] = 0;
                que.push(make_pair(i, j));
            }
        }
    }

    dfs();

    int maximum = -1;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            maximum = max(maximum, dist[i][j]);
        }
    }

    cout << maximum << endl;

    return 0;
}

Measured memory_bytes: 13328
fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    let n: u8 = n.trim().parse().unwrap();
    let mut h = String::new();
    std::io::stdin().read_line(&mut h).unwrap();
    let hs: Vec<u8> = h.trim().split_whitespace()
            .map(|x| x.parse().unwrap()).collect();
    let mut ans = 1;
    let mut i = 1;

    while ( i < n ) {
        let mut j = 1;
        while ( j <= i && (i-j) >= 0 ) {
            if ( hs[(i-j) as usize] <= hs[i as usize]) {
                j += 1;
            } else {
                break;
            }
            if ( j > i ) {
                ans += 1;
                break;
            }
        }
        i += 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<limits.h>

int main(){
	int i, j, n, r, ans, min;
	min = INT_MAX;
	ans = INT_MIN;

	scanf("%d", &n);	
	
	for(i = 0; i<n; i++){
		scanf("%d", &r);
		if(r - min > ans) 
			ans = r - min;
		if(r < min)
			min = r;
	}


	printf("%d\n", ans);

	return 0;
}

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

const int N = 44;
const int inf = 1e8;

int n, ma, mb, a[N], b[N], c[N];
int cache[44][404][404];
bool ready[44][404][404];

int dp(int k, int x, int y) {
    if (k == n) {
        if (x == 0 and y == 0) return inf;
        int g = __gcd(x, y);
        x /= g;
        y /= g;
        if (ma == x and mb == y) return 0;
        return inf;
    }

    if (ready[k][x][y]) return cache[k][x][y];
    ready[k][x][y] = true;
    int &rv = cache[k][x][y];
    rv = dp(k + 1, x, y);
    rv = min(rv, c[k] + dp(k + 1, x + a[k], y + b[k]));
    return rv;
}

int main() {
    cin >> n >> ma >> mb;
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];
    int res = dp(0, 0, 0);
    printf("%d\n", res >= inf ? -1 : res);
}

Measured memory_bytes: 31232
#include<stdio.h>
 
int main(void){
  int i;
  int n;
  int m;
  int a[10010];
  scanf("%d%d",&n, &m);
  for(i = 0; i < m; i++){
    scanf("%d", &a[i]);
    n -= a[i];
  }
  if (n < -1)
    n=-1;
  printf("%d",n);
}

Measured memory_bytes: 1736
import cmath
import sys

INF=10**18
MOD=998244353
MAX=10**5+7

def main():
    N=int(input())
    D=list(map(int, input().split()))
    cnt=[0]*(N+1)

    if D[0]:
        print(0)
        exit()

    if 0 in D[1:]:
        print(0)
        exit()

    for d in D:
        cnt[d]+=1

    ans=1
    for  i in range(1, max(D)+1):
        ans=ans*pow(cnt[i-1], cnt[i], MOD)%MOD
    print(ans)

if __name__=='__main__':
    main()


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

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

int main(){
  int64_t H;
  cin >> H;

  int64_t ans = 0;
  while(H!=1){
    H=H/2;
    ans++;
  }
  
  int64_t a=pow(2, ans+1)-1;
  cout << a;
  
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int a[110000], LIS[110000];

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < N; i++){
		LIS[i] = INF;
	}
	
	bool flag = false;
	
	for(int i = 0; i < N; i++){
		int pos = lower_bound(LIS, LIS + N, a[i]) - LIS;
		LIS[pos] = a[i];
	}
	
	int num = (int)(lower_bound(LIS, LIS + N, INF) - LIS);
	
	cout << num << endl;
	
	return 0;
}


Measured memory_bytes: 4660
{-# OPTIONS_GHC -O2 #-}

main = do
  n <- getLine 
  s <- getContents
  putStr $ sUnlines $ map judge $ mReadSD $ linesWords s

linesWords s = map words $ lines s
mReadSD    s = map (map (read :: String -> Double)) s
sUnlines   s = unlines $ map show s

judge [xa,ya,ra,xb,yb,rb] 
  | x_b >  (ra + rb)      =  0
  | x_b >= abs (ra - rb)  =  1
  | ra > rb               =  2
  | otherwise             = (-2)
  where 
    x_b = sqrt ((xa-xb)^2 + (ya-yb)^2)

Measured memory_bytes: 4212
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int c[1010], t[1010];
signed main() {
    int N, T; cin >> N >> T;

    int ans = INF;
    for(int i=0; i<N; i++) {
        cin >> c[i] >> t[i];
        if(t[i] <= T) chmin(ans, c[i]);
    }

    if(ans == INF) cout << "TLE" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		long mon = 100_000;
		for(int i = 0; i < n; i++){
			mon = (long) Math.ceil(mon * 1.05 / 1000) * 1000;
		}
		System.out.printf("%d\n", mon);
	}
}

Measured memory_bytes: 26084
#include <iostream>
#include <cmath>
#include <cstdio>
#include  <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long lint;
#define SZ(x) ((int)(x).size())
int main()
{
	int n;
	cin >> n;
	if (n <= 999) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    ll n;
    cin >> n;
    ll i = 1;
    int ans = 1 << 30;
    int aux = 0;
    for(; i * i < n; i++){
        if(n % i == 0){
            int d1 = (int)log10(n / i) + 1;
            int d2 = (int)log10(i) + 1;
            aux = max(d1,d2);
        }
        ans = min(ans,aux);
    }
    if(i * i == n){
        int d2 = (int)log10(i) + 1;
        ans = min(d2,ans);
    }
    cout << ans << '\n';
    return 0;
}   

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int n,m,i,j,w = 0,s = 0;
    int cards[210] = {0},k[1010] = {0},copy[210] = {0};
    scanf("%d",&n);
    scanf("%d",&m);
    for(i = 1;i <= m;i++){
        scanf("%d",&k[i]);
    }
    for(i = 1;i <= 2 * n;i++){
        cards[i] = i;
    }

//??\????????????------------------------------------------

    for(i = 1;i <= m;i++){

//??????????????£?????????------------------------------------

        if(k[i] == 0){
            for(j = 1;j <= 2 * n;j++){
                if(j % 2 == 0){
                    copy[j] = cards[n + j / 2];
                    w++;
                }
                else {
                    copy[j] = cards[j - w];
                }
            }
            for(j = 1;j <= 2 * n;j++){
                cards[j] = copy[j];
            }
            w = 0;
        }

//??????????????????----------------------------------------

//??´??°?????§?????????--------------------------------------

    else if(1 <= k[i] && k[i] <= 2 * n - 1){
        for(j = 1;j <= 2 * n;j++){
            if(k[i] + j <= 2 * n){
                copy[j] = cards[k[i] + j];
            }
            else if(k[i] + j > 2 * n){
                copy[j] = cards[++s];
                //printf("s %d cards s %d copy j %d\n",s,cards[s],copy[j]);
            }
            //printf("copy j %d\n",copy[j]);
        }
        for(j = 1;j <= 2 * n;j++){
            cards[j] = copy[j];
        }
        s = 0;
    }

//??????????????????

    }

    for(j = 1;j <= 2 * n;j++){
        printf("%d\n",cards[j]);
    }






    return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch PluralForm | diff PluralForm.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address PluralForm.cpp && ./a.out

/*

 9/19/2020

 5:00-

 */

string S;

void solve() {
  cout<<(S.back()=='s'?(S+"es"):(S+"s"))<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>S;
  solve();

  return 0;
}


Measured memory_bytes: 3652
x,n=map(int,input().split())
if n!=0:
  p=list(int(i) for i in input().split())

  for i in range(100):
    kouho1=x+i
    kouho2=x-i
    if kouho2 not in p:
      print(kouho2)
      break
    elif kouho1 not in p:
      print(kouho1)
      break
else:
  print(x)

Measured memory_bytes: 61840
#include <iostream>
#include <vector>
#include <math.h>
 
using namespace std;
int main(void){
    int N;
    long long a;
    long long sum = 0;
    cin >> N;
    vector<long long> vec(N);
    vector<long long> vec_sum(N, 0);
    for(int i = 0; i < N; i++)
    {
        cin >> a;
        vec[i] = a;
        sum += a;
        vec_sum[i] = sum;
        
    }
    
    long long min;
    if(abs(sum - 2*vec_sum[0]) <=  abs(sum - 2*vec_sum[N - 2]))
    {
        min = abs(sum - 2*vec_sum[0]);
    }else{
        min = abs(sum - 2*vec_sum[N - 2]);
    }
    if(N == 2){
        cout << abs(sum - 2*vec_sum[0]) << endl;
        return 0;
    }
    
    for(int i = 1; i < N - 1; i++)
    {
        if(abs(sum - 2*vec_sum[i]) == 0)
        {
            cout << abs(sum - 2*vec_sum[i]) << endl;
            return 0;
        }
        if(abs(sum - 2*vec_sum[i]) < min)
        {
            min = abs(sum - 2*vec_sum[i]) ;
        }
    }
    
    // for(int i = 0; i < N ; i++)
    // {
    //     cout << vec_sum[i] << " "  ;

    // }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3328
def papers(numbers)
  checks = []
  numbers.each do |num|
    if num % 2 == 0
      checks.push(num)
    end
  end

  checks.each do |num|
    unless num % 3 == 0 || num % 5 == 0
      puts "DENIED"
      exit
    end 
  end
  puts "APPROVED"
end

n = gets.chomp
numbers = gets.chomp.split(" ").map(&:to_i)
papers(numbers)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long
    #define int long long 
    #define ull unsigned long long 
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define mn3(a, b, c) min(min(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define SP(n) cout.precision(n)
    const ld PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
    const ll MD = 998244353;
    
    int32_t main() {
        fio;
        SP(10);
        int a,b,n;
        cin>>a>>b>>n;
        int x = n%b;
        int x1= floor((a*n)/b) - a*floor(n/b);
        n-= (x+1);
        int x2= floor((a*n)/b) - a*floor(n/b);
        cout<<max(x1,x2)<<el;
        return 0;
    }


Measured memory_bytes: 3652
#include <iostream>
#include<algorithm>

using namespace std;

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

	int t;
	if (a > b) {
		t = a;
		a = b;
		b = t;
	}
	if (b > c) {
		t = b;
		b = c;
		c = t;
	}
	if (a > b) {
		t = a;
		a = b;
		b = t;
	}

	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.close();

        if (n % k == 0) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
    }

}


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

int main() {
    int n, k;
    cin >> n >> k;

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

    int mx = 0;
    int s = 0;
    queue<int> q;

    for(int i=0; i<n; i++) {
        s += p[i];
        q.push(p[i]);

        if (q.size() > k) {
            s -= q.front(); q.pop();
        }

        if (q.size() == k) {
            mx = max(mx, s);
        }
    }

    double ans = mx;
    ans /= 2;

    printf("%.10f\n", ans);
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<string, pair<int, int>>> T(N);
    for (int i = 0; i < N; i++)
    {
        string S;
        int P;
        cin >> S >> P;
        T[i] = make_pair(S, make_pair(-P, i + 1));
    }
    sort(T.begin(), T.end());
    for (int i = 0; i < N; i++)
    {
        cout << T[i].second.second << endl;
    }
    
  return 0;
}


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

int main()
{
  int n;
  cin>>n;
  int a[n],i,j=0;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=1;i<=n-2;i++){
    if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i-1]>a[i]&&a[i]>a[i+1])){
      j++;
    }
  }
  cout<<j<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int K;
    cin >> K;
    cout << (K/2)*((K+1)/2) << endl;
    return 0;
}


Measured memory_bytes: 256
// AOJ 1161: Verbal Arithmetic
// 2018.1.9 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int m, sz;
char str[13][11]; int len[13];
char tr['Z'+1], assign['Z'+1];
char idx[10], not0[10], used[10];
int ans;

void calc()
{
	int i, a, s;
	char *p;

	// 下一桁の合計で枝刈りしてみる
	s = 0; for (i = 0; i < m; i++) s += assign[str[i][len[i]]];
	a = assign[str[m][len[m]]];
	if (s % 10 != a) return;

	s = 0;
	for (i = 0; i < m; i++) {
		a = 0, p = str[i];
		while (*p >= 0) a = (a<<3) + (a<<1) + assign[*p++];
		s += a;
	}

	a = 0, p = str[m];
	while (*p >= 0) a = (a<<3) + (a<<1) + assign[*p++];
	if (a == s) ans++;
}

void rec(int k)
{
	int i;

	if (k == sz) { calc(); return; }
	if (!used[0]) {
		if (!not0[k]) used[0] = 1, assign[idx[k]] = 0, rec(k+1), used[0] = 0;
	}
	for (i = 1; i < 10; i++) {
		if (used[i]) continue;
		used[i] = 1, assign[idx[k]] = i, rec(k+1), used[i] = 0;
	}
}

int main()
{
	int n, i;
	char buf[10], *p;

	while (fgets(buf, 10, stdin) && *buf != '0') {
		sz = 0, memset(tr, -1, sizeof(tr));
		memset(not0, 0, sizeof(not0));
		n = atoi(buf), m = n - 1;
		for (i = 0; i < n; i++) {
			fgets(str[i], 15, stdin);
			for (p = str[i]; *p > ' '; p++) {
				if (tr[*p] < 0) tr[*p] = sz, idx[sz++] = *p;
			}
			*p = -1; len[i] = p-str[i]-1;
			if (len[i] > 0) not0[tr[*str[i]]] = 1;
		}
		ans = 0;
		memset(used, 0, sizeof(used));
		rec(0);
		printf("%d\n", ans);
	}
	return 0;
}


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

int a[100500];

int main(){
	int n, b, c, sum = 0, m = 0, l = 0, k = 0;
	cin >> n >> b >> c;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	for(int i = 0;i < n;i++){
		if (a[i] <= b){
			m++;
		}
		else if (a[i] > b && a[i] <= c){
			l++;
		}
		else if(a[i] > c){
			k++;
		}
	}
	
	cout << min(m, min(k, l));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  for(int n,m;cin>>n>>m&&n;){
    int r0=0,r1=0,a[100],b[100],r=1e9,r2,r3;
    for(int i=0;i<n&&cin>>a[i];i++) r0+=a[i];
    for(int i=0;i<m&&cin>>b[i];i++) r1+=b[i];
    for(int i=0;i<n;i++) for(int j=0;j<m;j++){
        if(r0+b[j]-a[i]==r1+a[i]-b[j]&&r>b[j]+a[i]){
          r=b[j]+a[i];
          r2=a[i];
          r3=b[j];
        }
      }
    if(r==1e9) cout<<-1<<endl;
    else cout<<r2<<" "<<r3<<endl;
  }
  return 0;
}

Measured memory_bytes: 2996
#include <iostream>
#include <vector>
#define int long long
using namespace std;

int mod = 1000000007;
vector<int> K(200100);

void prepare() {
  K[0] = 1;
  for (int i = 1; i < K.size(); ++i) {
    K[i] = K[i - 1] * i % mod;
  }
  return;
}

int pow(int a, int b) {
  if (b == 1) return a;
  int ans = pow(a, b / 2);
  if (b % 2 == 0) return ans * ans % mod;
  else return ans * ans % mod * a % mod;
}

int com(int m, int n) {
  int ans = K[m];
  ans *= pow(K[n], mod - 2);
  ans %= mod;
  ans *= pow(K[m - n], mod - 2);
  ans %= mod;
  return ans;
}

int route(int si, int sj, int gi, int gj) {
  int x = gi - si;
  int y = gj - sj;
  return com(x + y, x);
}

signed main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  
  prepare();
  int ans = route(1, 1, H, W);
  int C = H - A;
  for (int i = 1; i <= B; ++i) {
    int a = route(1, 1, C, i);
    a *= route(C + 1, i, H, W);
    a %= mod;
    ans += (mod - a);
    ans %= mod;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
H,W = map(int,input().split())
dp = [[0]*(W+1) for _ in range(H+1)]
Map = []
for _ in range(H):
    line = list(input())
    Map.append(line)
MOD = 10**9+7
dp[1][1]=1
for i in range(H):
    for j in range(W):
        if Map[i][j]=='#':
                dp[i][j]=0
        else:
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD
            
            dp[i+1][j+1]+=(dp[i][j+1]+dp[i+1][j])%MOD
print(dp[-1][-1])

Measured memory_bytes: 56172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  for(int i; i<=N; i++){
    string S;
    cin >> S ;
    if (S=="Y") {
      cout << "Four" << endl;
      break;
    }
    if (i==N){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
s = list(input())
n = len(s)
ans = 0
flag = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)

Measured memory_bytes: 49776
let S = readLine()!.characters.map { String($0) }
let K = Int(readLine()!)!
 
func minReplacement(s: [String]) -> Int {
  var count = 0
  
  var left = 0
 
  while left < s.count {
    var right = left
    while right < s.count && s[left] == s[right] {
      right += 1
    }
    count += (right - left) / 2
    left = right
  }
  return count
}
 
if Set(S).count <= 1 {
  print(Int(Double(S.count) / 2.0 * Double(K)))
} else {
	let first = minReplacement(S)
	let second = minReplacement(S + S)
  	let diff = second - first
  	print(first + diff * (K - 1))
}

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

int main() {
    char c; cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int[] n = new int[100];
 
        int min = Math.min(a, b);
        int cnt = 0;
        for (int i = 1; i <= min; i++) {
            if (a % i == 0 && b % i == 0)
                n[cnt++] = i;
            else
                continue;
        }
        
        System.out.println(n[cnt - k]);
    }
}

Measured memory_bytes: 21716