akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
int main(){
    char s[27];
    int a[26]={};
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++)a[s[i]-'a']++;
    for(int i=0;i<26;i++){
        if(a[i]>1){
            printf("no");
            return 0;
        }
    }
    printf("yes");
    return 0;
}

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

public class Main {	
	private static void solve(){
		//Implement solution here.
		double A = nd();
		double B = nd();
		double H = nd();
		double M = nd();
		double ang = 30D * H + 0.5D * M - 6D * M;
		double asin = A * Math.sin(Math.toRadians(ang));
		double acos = A * Math.cos(Math.toRadians(ang));
		
		double height = asin;
		double width = B - acos;
		
		System.out.println(Math.sqrt(height * height + width * width));

	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25556
#include<stdio.h>
int main()
{
    unsigned long long int x,a,b,c,d;
    scanf("%llu",&x);
    a=x/500;
    b=x%500;
    c=b/5;
    d=(a*1000)+c*5;
    printf("%llu\n",d);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    // Your code here!
    char b;
    scanf("%c",&b);
    
    switch(b)
    {
        case 'A':
            printf("T\n");
            break;
            
        case 'C':
            printf("G\n");
            break;
        
        case 'G':
            printf("C\n");
            break;
            
        case 'T':
            printf("A\n");
            break;
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <map>
#include <numeric>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define len(str) (int)(str.length())
int main() {
	int N, Y;
	cin >> N >> Y;
	bool f = false;
	string ans = "-1 -1 -1";
	for (int a = 0; a <= N; a++)
	{
		for (int b = 0; b <= N-a; b++)
		{
			if (10000 * a + 5000 * b + 1000 * (N-a-b)==Y) {
				f = true;
				ans = to_string(a) + " " + to_string(b) + " " + to_string(N - a - b);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long a,b,c=1,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
int main()
{
	cin>>a>>b;
	if((a<0)&&(b<0))
	{
		if((b-a)%2==0)
		c=-1;
		else c=1;
	}
	if((a>0)&&(b>0))
	{
		c=1;
	}
	if((a<=0)&&(b>=0))
	{
		c=0;
	}
	if(c>0)
	cout<<"Positive";
	if(c==0)
	cout<<"Zero";
	if(c<0)
	cout<<"Negative";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int A, B, C;
  int K;
  cin >> A >> B >> C >> K;
  int count=0;
  while (A>=B) {
    B*=2;
    count++;
  }
  while (B>=C) {
    C*=2;
    count++;
  }
  if (count<=K) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3572
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	exNums := make([]int, 3)
	for _, v := range as {
		ex := exOf(v, 2)
		exNums[min(2, ex)]++
	}
	if exNums[0]+exNums[1]%2 > exNums[2]+1 {
		fmt.Println("No")
		return
	}
	fmt.Println("Yes")
	return
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func exOf(n, p int) (ex int) {
	c := n
	for c%p == 0 {
		ex++
		c /= p
	}
	return ex
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4248
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i,x,flg;
	scanf("%d",&n);
	flg=0;
	for(i=1;i<=9;i++)	{
		if(n%i==0)	{
			x=n/i;
			if(x<=9)	{
				flg=1;
				break;
			}
		}
	}
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int maxkey (map<int,int> mp){
	int maxkey, maxvalue = 0;
	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		if(maxvalue <= itr->second){
			maxvalue = itr->second;
			maxkey = itr->first;
		}
	}
	return maxkey;
}

int maxvalue (map<int,int> mp){
	int maxvalue = 0;
	for(auto itr = mp.begin(); itr != mp.end(); itr++)
		maxvalue = max(maxvalue,itr->second);
	return maxvalue;
}

int ANS(int o, int e, int n){
	return n-o-e;
}

int main(){
	int n, ans;
	map<int,int> mpo, mpe;
	cin >> n;
	for(int i = 0; i < n/2; i++){
		int o, e;
		cin >> o >> e;
		mpo[o]++;
		mpe[e]++;
	}
	int ok = maxkey(mpo);
	int ek = maxkey(mpe);
	int ov1 = maxvalue(mpo);
	int ev1 = maxvalue(mpe);
	//cout << ok << "," << ek <<endl;
	//cout << ov1 << "," << ev1 <<endl;
	ans = ANS(ov1,ev1,n);
	if(ok == ek){
		mpo.erase(ok);
		mpe.erase(ek);
		int ov2 = maxvalue(mpo);
		int ev2 = maxvalue(mpe);
		//cout << ov2 << "," << ev2 << endl;
		ans = min(ANS(ov1,ev2,n),ANS(ov2,ev1,n));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7296
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
char s[N];

bool match(char* s, int n, char *t, int m) {
  if (n < m) return false;
  for (int i = 0; i < m; ++i) {
    if (s[i] != t[i]) return false;
  }
  return true;
}

char t[4][20] = {"dreamer", "dream", "eraser", "erase"};

int main() {
  scanf("%s", s);
  int n = strlen(s);
  vector<int> len(4);
  for (int i = 0; i < 4; ++i) {
    len[i] = strlen(t[i]);
  }
  vector<bool> dp(n + 1, false);
  dp[n] = true;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < 4; ++j) {
      if (match(s + i, n - i, t[j], len[j])) {
        dp[i] = dp[i] | dp[i + len[j]];
      }
    }
  }
  puts(dp[0] ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 384
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

//二分累乗法 xのe乗
ll binpow(ll x, ll e, ll mo=MOD) {
  ll a = 1, p = x;
  while(e > 0) {
    if(e%2 == 0) {p = (p*p) % mo; e /= 2;}
    else {a = (a*p) % mo; e--;}
  }
  return a;
}

ll combi(ll N_, ll C_, ll mo=MOD) {
  const int NUM_=1e5+10;
  static ll fact[NUM_+1]={},factr[NUM_+1]={},inv[NUM_+1]={};
  auto binpow = [&](ll x, ll e) -> ll{
    ll a = 1, p = x;
    while(e > 0) {
      if(e%2 == 0) {p = (p*p) % mo; e /= 2;}
      else {a = (a*p) % mo; e--;}
    }
    return a;
  };
  if (fact[0]==0) {
    fact[0] = factr[0] = inv[0] = 1;
    FOR(i, 1, NUM_+1) fact[i] = fact[i-1] * i % MOD;
    factr[NUM_] = binpow(fact[NUM_], mo-2);
    for(int i=NUM_-1; i>=0; --i) factr[i] = factr[i+1] * (i+1) % MOD;
  }
  if(C_<0 || C_>N_) return 0;
  // 前計算 O(max(N,K)log(mod)) クエリ O(1)
  return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;
}

int dp1[3010], dp2[3010][3010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n >> MOD;

  REP(i, n+1) {
    dp2[i][0] = 1;
    FOR(j, 1, i+1) {
      dp2[i][j] = (dp2[i-1][j]*(j+1) + dp2[i-1][j-1]) % MOD;
    }
  }
  // REP(i, n+1) {
  //   REP(j, i+1) cout << dp2[i][j] << " ";
  //   cout << endl;
  // }

  REP(i, n+1) {
    REP(j, i+1) {
      (dp1[i] += dp2[i][j] * binpow(2, (n-i)*j)) %= MOD;
    }
    (dp1[i] *= binpow(2, binpow(2, n-i, MOD-1))) %= MOD;
  }
  // REP(i, n+1) cout << dp1[i] << " ";
  // cout << endl;

  int ans = 0;
  REP(i, n+1) {
    (ans += (i%2?-1:1) * combi(n, i) * dp1[i]) %= MOD;
    // cout << combi(n, i) << " " << ans << endl;
  }
  cout << (ans%MOD+MOD)%MOD << endl;

  return 0;
}


Measured memory_bytes: 71040
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 100005
using namespace std;
ull A[MAX];
int main() {
  int n,i;
  cin >> n;
  bool x = true;
  for(i=0;i<n;i++) {
    cin >> A[i];
    if(A[i]%2 != 0) {
      x=false;
      break;
    }
  }
  if(x) {
    cout << "second" << endl;
  } else {
    cout << "first" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}
int main (void)
{
  int n;//配列のサイズ
  scanf("%d",&n);
  int v[n];
  double d[n];
  for(int i=0;i<n;i++){
    scanf("%d",&v[i]);
  }

  qsort(v,n,sizeof(int),compare_int);
  for(int i=0;i<n;i++){
    d[i]=v[i];
  }
  for(int i=1;i<n;i++){
    d[i]=(d[i]+d[i-1])/2;
  }
  printf("%f",d[n-1]);
  return 0;
}


Measured memory_bytes: 128
def main():
    """ ????????? """
    num = int(input())
    for i in range(num):
        m = list(map(int,input().split()))
        m.sort()
        a = (m[0] ** 2) + (m[1] ** 2)
        b = (m[2] ** 2)
        if a == b:
            print("YES")
        else:
            print("NO")

if __name__ == '__main__':
    main()

Measured memory_bytes: 7568
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0; i<N; i++) {
        cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    cout << d.at(N/2) - d.at(N/2-1) << endl;
    return 0;
}

Measured memory_bytes: 768
import sys
import heapq


class Edge:
    def __init__(self, vertex_to, weight):
        self.vertex_to = vertex_to
        self.weight = weight


class Vertex:
    def __init__(self):
        self.distance = sys.maxsize
        self.fixed: bool = False
        self.edges_from_this_vertex = []


class DijkstraAlgorithm:
    def __init__(self, number_of_vertices):
        self._number_of_vertices = number_of_vertices
        self._number_of_edges = 0
        self._vertices = [Vertex() for _ in range(number_of_vertices)]
        self._priority_queue = []
        heapq.heapify(self._priority_queue)

    def add_vertex(self, from_index, to_index, weight):
        self._vertices[from_index].edges_from_this_vertex.append(Edge(to_index, weight))

    def calculate_shortest_paths(self, start_vertex_index):
        self._vertices[start_vertex_index].distance = 0
        heapq.heappush(self._priority_queue, (self._vertices[start_vertex_index].distance, start_vertex_index))
        while len(self._priority_queue) > 0:
            shortest_vertex_distance, shortest_vertex_index = heapq.heappop(self._priority_queue)
            self._vertices[shortest_vertex_index].fixed = True
            for c_edge in self._vertices[shortest_vertex_index].edges_from_this_vertex:
                if not self._vertices[c_edge.vertex_to].fixed:
                    distance_candidate = shortest_vertex_distance + c_edge.weight
                    if distance_candidate < self._vertices[c_edge.vertex_to].distance:
                        self._vertices[c_edge.vertex_to].distance = distance_candidate
                        heapq.heappush(self._priority_queue, (distance_candidate, c_edge.vertex_to))

    def print(self):
        for c_vertex in self._vertices:
            if c_vertex.distance == sys.maxsize:
                print('INF')
            else:
                print(c_vertex.distance)


def call_dijkstra_algorithm():
    inputs = list(map(int, input().strip().split(' ')))
    number_of_vertices = inputs[0]
    number_of_edges = inputs[1]
    start_vertex_index = inputs[2]
    dijkstra = DijkstraAlgorithm(number_of_vertices)

    for _ in range(number_of_edges):
        inputs = list(map(int, input().strip().split(" ")))
        from_index = inputs[0]
        to_index = inputs[1]
        weight = inputs[2]
        dijkstra.add_vertex(from_index, to_index, weight)

    dijkstra.calculate_shortest_paths(start_vertex_index)
    dijkstra.print()


if __name__ == '__main__':
    call_dijkstra_algorithm()



Measured memory_bytes: 155200
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        H = set()
        for x, y, h in xyh:
            if h != 0:
                H.add(h + abs(x - cx) + abs(y - cy))
        if len(H) == 1:
            H = list(H)[0]
            flag = True
            for x, y, h in xyh:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    flag = False
                    break
            if flag:
                print(cx, cy, H)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
double D[3005][3005];
 
int main() {
    ios::sync_with_stdio(false);
    
    cout.precision(10);
    cout << fixed;
    
    int n;
    cin >> n;
    
    vector<double> p(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    
    D[1][0] = 1.0 - p[1];
    D[1][1] = p[1];
    
    for (int i = 2; i <= n; ++i) {
        D[i][0] = D[i-1][0] * (1.0 - p[i]);
        for (int j = 1; j <= i; ++j) {
            D[i][j] = D[i-1][j-1] * p[i] + D[i-1][j] * (1.0 - p[i]);
        }
    }
    
    
    double sum = 0.0;
    
    for (int i = n / 2 + 1; i <= n; ++i)
        sum += D[n][i];
    
    cout << sum;
    
    return 0;
}

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  if ((A/K+1) * K <= B || A % K == 0) {
    cout << "OK";
  }
  else {
    cout << "NG";
  }
  
 
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x; cin >> x;
    if(x>=400 && x<=599)cout<<"8"<<endl;
    else if(x>=600 && x<=799)cout<<"7"<<endl;
    else if(x>=800 && x<=999)cout<<"6"<<endl;
    else if(x>=1000 && x<=1199)cout<<"5"<<endl;
    else if(x>=1200 && x<=1399)cout<<"4"<<endl;
    else if(x>=1400 && x<=1599)cout<<"3"<<endl;
    else if(x>=1600 && x<=1799)cout<<"2"<<endl;
    else if(x>=1800 && x<=1999)cout<<"1"<<endl;

    return 0;
}



Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;


int main(){
  int N,K;
  string S;
  while(cin >> N >> K >> S){
    int ans = 0;
   
    FOR(i,1,N){
      if(S[i-1] == S[i] and S[i] == 'L') ++ans;
    }

    REP(i,N-1){
      if(S[i+1] == S[i] and S[i] == 'R') ++ans;
    }

    vector<string> p;
    REP(i,N-1){
      if(S[i] != S[i+1]){
        p.push_back((string){S[i],S[i+1]});
      }
    }
    dump(p);

    stack<string> st;
    REP(i,(int)p.size()){
      if(st.empty()){
        st.push(p[i]);
      }else{
        if(st.top() != p[i]){
          if(K){
            st.pop();
            ans += 2;
            --K;
          }
        }else{
          st.push(p[i]);
        }
      }
    }

    if(K and st.size()) ++ans;


    cout << ans << endl;    
  }

  


  return 0;
}


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

int main(){
  string s;
  cin >> s;
  int count = 0;
  rep(i,s.size()-2){
    count++;
  }
  cout << s[0] << count << s[s.size()-1] << endl;
  return 0;
}

Measured memory_bytes: 256
N, Y =  map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        k = N- i - j
        if  2000 >= k >= 0 and 10000*i + 5000*j + 1000*k == Y:
            print(i, j, k)
            exit()
print('-1 -1 -1')


Measured memory_bytes: 9180
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline int read(){int r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e6+100;
const int MAXM = 1e5;
string a,b,c;
int main(){
	int n;
	cin>>n>>a>>b>>c;
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]==b[i]&&b[i]==c[i]) continue;
		else if(a[i]!=b[i]&&a[i]!=c[i]&&b[i]!=c[i]) ans+=2;
		else ans++;
	}
	cout<<ans<<endl;
	return 0;
}



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

int main() {
    int N, K; cin >> N >> K;
    vector<int> candy(N, 0);
    for(int i=0; i<K; ++i) {
        int d; cin >> d;
        while(d--) {
            int a; cin >> a;
            candy[a - 1] += 1;
        }
    }
    cout << count(begin(candy), end(candy), 0) << '\n';
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, X, D;
  cin>>N>>X>>D;
  if(D<0) {
    X = X + (N-1) * D;
    D = -D;
  }
  ll tmpmin, tmpmax;
  ll ans = 0;
  if(D==0) {
    if(X==0) cout<<1<<endl;
    else cout<<N+1<<endl;
    return 0;
  }
  map<ll, ll> amap1, amap2, bmap;
  for(ll k=0;k<=N;++k) {
    tmpmin = k*X + k*(k-1)/2*D;
    tmpmax = k*X + (N-1)*N/2*D - (N-k-1)*(N-k)/2*D;
    if(bmap[(k*X%D+D)%D]==0) {
      ans += (tmpmax - tmpmin)/D + 1;
      amap1[(k*X%D+D)%D] =  tmpmax;
      amap2[(k*X%D+D)%D] =  tmpmin;
      bmap[(k*X%D+D)%D]++;
    }
    else {
      ans += (tmpmax - tmpmin)/D + 1;
      if(tmpmin<=amap1[(k*X%D+D)%D] && amap2[(k*X%D+D)%D]<=tmpmax) {
        ans -= (min(amap1[(k*X%D+D)%D], tmpmax) - max(amap2[(k*X%D+D)%D], tmpmin))/D + 1;
      }
      amap1[(k*X%D+D)%D] = max(amap1[(k*X%D+D)%D], tmpmax);
      amap2[(k*X%D+D)%D] = min(amap2[(k*X%D+D)%D], tmpmin);
    }
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 41048
#include<iostream>

using namespace std;

int gcd(int a,int b)
{
	int t;
	while(b){
		a%=b;
		t=a,a=b,b=t;
	}
	return a;
}

long long lcm(int a,int b)
{
	return 1LL*a*b/gcd(a,b);
}

long long lcm(int a,int b,int c)
{
	return lcm(lcm(a,b),c);
}

int main()
{
	int a[3],m[3];

	while(cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2],a[0]){
		int period[3];
		for(int i=0;i<3;i++){
			int cnt=0;
			for(int j=1;;){
				j=(a[i]*j)%m[i];
				cnt++;
				if(j==1)	break;
			}
			period[i]=cnt;
		}
		cout<<lcm(period[0],period[1],period[2])<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**9)

N, P = list(map(int, input().split()))
S = input()

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    sys.exit()

num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)


Measured memory_bytes: 41308
mod = 1000000007
def f(i):
    return i * (i + 1) // 2
def solve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    now = other = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                if A[i] > A[j]:
                    now += 1
            else:
                if A[i] > A[j]:
                    other += 1
    print((now * f(k) + other * f(k - 1)) % mod)
solve()


Measured memory_bytes: 3188
#include <stdio.h>
int main()
{
    int i, a[26] = {};
    char w;
    while (scanf("%c", &w) != EOF)
    {
        if (w >= 'a' && w <= 'z')
            a[w - 'a']++;
        else if (w >= 'A' && w <= 'Z')
            a[w - 'A']++;
    }
    for (i = 0; i < 26; i++)
        printf("%c : %d\n", i + 'a', a[i]);
    return 0;
}



Measured memory_bytes: 2096
const int LG = 21;
const int FN = 400005;
const long long MOD = 998244353;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

const int N = 1100000;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for (int i = 0; i <= k; i++)
    {
        ll g = cnk(n - 1, i);
        ll fi = m * inq(m - 1, n - i - 1) % MOD;
        ans = (ans + g * fi) % MOD;
    }
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 12716
#include <stdio.h>

int main(void)
{
	int a,b,c,d,p;
	int X,Y;
	
	scanf("%d",&a);	
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&p);
	
	X = a * p;
	
	if(p <= c){
		Y = b;
	}
	else {
		Y = b + ((p - c) * d);
	}
	if(X < Y){
		printf("%d\n",X);
	}
	else if(X >= Y){
		printf("%d\n",Y);
	}
	
	return(0);
}

Measured memory_bytes: 1828
#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 d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
    }
    vector<int> t(d);
    rep(i, d) {
        int s_max = 0;
        rep(j, 26) {
            if (s_max < s[i][j]) {
                s_max = s[i][j];
                t[i] = j+1;
            }
        }
        
    }
    rep(i, d) {
        cout << i%26+1 << endl;
    }
    return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll a,b;
    cin >> a >> b;
    if(a+b>=10){
        cout << "error" << "\n";
    }else{
        cout << a+b << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;

  vector <ll> num(100001);  //値がiの要素が出てきた回数
  rep(i,N){
    int A;
    cin >> A;
    num[A] ++;
  }
  ll total = 0;
  rep(i,100001) total += i * num[i];
  int Q;
  cin >> Q;

  rep(i,Q){
    int B, C;
    cin >> B >> C;
    total += num[B] * (C - B);
    //B_i全てをC_iに置き換える
    num[C] += num[B];
    num[B] = 0;
    cout << total << endl;
  }
}


Measured memory_bytes: 3996
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int LCM(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return (a / dummy1) * (b / dummy1) * dummy1;
}

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	long long int A, B;
	cin >> A >> B;
	cout << LCM(A, B) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,m,c,b[20],k=0;
    cin>>n>>m>>c;
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        int u=c;
        for(int j=0;j<m;j++){
            int a;
            cin>>a;
            u+=a*b[j];
        }

        if(u>0)k++;
    }
    cout<<k<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=0;
    bool d[101]={0};
    cin>>n;
    while(n--)
    {
        int dm;
        cin>>dm;
        if(!d[dm])
        {
            c++;
            d[dm]=1;
        }
    }
    cout<<c<<endl;
     return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int A,B;//A:年齢、B:料金
  
  scanf("%d%d",&A,&B);
  
  if(A>=13)
    printf("%d",B);
  else if(6<=A && A<=12)
    printf("%d",B/2);
  else
    printf("0");
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> vec(2 * N);
    rep(i,2 * N){
        cin >> vec[i];
    }
    int ans = 0;
    sort(all(vec));
    for (int i = 0; i < 2 * N; i += 2){
        ans += vec[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}
const int N = 105,Vmax = 1e5+5;
int dp[Vmax];
int W[N],V[N];

signed main(){
	IOS
	int n,w;	cin >> n >> w;
	int sum = 0;
	rep(i,n)	cin >> W[i] >> V[i],sum += V[i];
	fill(dp,dp+sum+1,1e9+7);
	dp[0] = 0;
	rep(i,n){
		for(int j = sum;j > 0; j--){
			if(j >= V[i])	dp[j] = min(dp[j],dp[j-V[i]] + W[i]);
		}
	}
	for(int i = sum;i>0;i--){
		if(dp[i] <= w){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main(){
    ll n, res = 0;
    cin >> n;
    if(n%2 == 0){
        n /= 10;
        res += n;
        while(n > 0){
            n /= 5;
            res += n;
        }
    }
  cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30

int MOD = 1000000007;


int main(){
    std::ios_base::sync_with_stdio(false);

    int n,m; cin >> n >> m;
    std::vector<bool> red(n, false);
    std::vector<int> ball_cnt(n,1);
    red[0] = true;

    REP(_, m){
        int x,y; cin >> x >> y;

        if(red[x-1]) red[y-1] = true;

        if(ball_cnt[x-1]==1 && red[x-1]){
            red[x-1] = false;
        }

        ball_cnt[y-1]++;
        ball_cnt[x-1]--;
    }

    int ans=0;
    REP(i,n){
        ans += red[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#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() {
	string S;
	cin >> S;
	S[3] = '8';
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define override_rep(i, l, r, rep_, ...) rep_
#define rep2(i, n) for (int i = 0; i < n; i++)
#define rep3(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define int long long
#ifdef DEBUG
std::ostream& dout=std::cout;
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
template <typename T, typename U>
istream &operator>>(istream &in, pair<T, U> &p) {
  in >> p.first >> p.second;
  return in;
}
signed main() {
  int n,ans=1;
  cin>>n;
  vector<int> memo(200001,0);
  int b;
  cin>>b;
  memo[b]=1;
  rep(i,n-1){
    int c;
    cin>>c;
    ans=(ans+memo[c]*(b!=c))%1000000007;
    memo[c]=ans;
    b=c;
  }
  cout<<ans<<endl;
}

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

using namespace std;

const int MAXN = 2005;
const int MAXK = 10005;

int n, k, br;
string s[MAXN], curr;
int z[MAXK*2];
bool dp[MAXN][MAXK], ok[MAXK];

void precompute () {
    dp[n][0] = 1;
    for (int i = n-1; i >= 0; i--) {
        int len = s[i].size();
        for (int j = 0; j <= k; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j - len >= 0) dp[i][j] |= dp[i + 1][j - len];
        }
    }
}

void z_algo (int ind) {
    int org = s[ind].size();
    s[ind] += '.'; s[ind] += curr;
    int l = 0, r = 0, len = s[ind].size();
    for (int i = 1; i < len; i++) {
        if (r < i) {
            l = r = i;
            while (r < len && s[ind][r - l] == s[ind][r]) r++;
            z[i] = r - l; r--;
        } else {
            int k = i - l;
            if (z[k] < r - i + 1) {
                z[i] = z[k];
            } else {
                l = i;
                while (r < len && s[ind][r - l] == s[ind][r]) r++;
                z[i] = r - l; r--;
            }
        }
    }
    for (int i=0; i<k; i++) {
        z[i] = z[i + org + 1];
    }
}

void calc () {
    for (int i=0; i<k; i++) curr += '{';
    ok[0] = 1;
    for (int i=0; i<n; i++) {
        int len = s[i].size(), ind = -1, d = -1;
        z_algo(i);
        for (int j = 0; j + len <= k; j++) {
            if (!ok[j] || !dp[i+1][k - (j+len)]) continue;
            //if (j + z[j] < k && s[i][j + z[j]] < curr[j + z[j]]) {
            if (s[i] < curr.substr(j, len)) {
                ind = j;
                break;
            }
        }
        if (ind == -1) continue;
        br = ind + len;
        for (int j=0; j<len; j++) {
            if (d == -1 && curr[ind + j] != s[i][j]) d = ind + j;
            curr[ind + j] = s[i][j];
        }
        for (int j=br; j<k; j++) {
            curr[j] = '{';
        }
        for (int j = d + 1; j <= k; j++) {
            ok[j] = 0;
        }
        ok[br] = 1;
        //cout << curr << endl;
        //for (int j=0; j<=k; j++) cout << ok[j]; cout << endl;
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i=0; i<n; i++) {
        cin >> s[i];
    }
    precompute();
    calc();
    cout << curr;
    return 0;
}


Measured memory_bytes: 44160
import java.io.InputStream;
import java.util.Scanner;

/**
 * Created on 2017/10/29.
 */
public class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray(); //?,t,c,?,?,?,?
        char[] t = sc.nextLine().toCharArray(); //c,o,d,e,r
        int SLength = s.length;
        int TLength = t.length;
        boolean b = false;
        outer:
        for (int i = SLength - TLength; i >= 0; i--) {
            for (int j = 0; j < TLength; j++) {
                if (s[i + j] != '?' && s[i + j] != t[j]) {
                    continue outer;
                }
            }
            for (int j = 0; j < TLength; j++) {
                s[i + j] = t[j];
            }
            b = true;
            break;
        }

        if (b) {
            for (int i = 0; i < SLength; i++) {
                if (s[i] == '?')
                    s[i] = 'a';
            }
            System.out.println(s);
        } else {

            System.out.println("UNRESTORABLE");
        }
    }
}



Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
   
#define Length 1000

int main(){  
  int i, n, match;
  char X[Length];
  char Y[Length];
     
  scanf("%d",&n);
   
  for(i = 0; i < n; i++){
    scanf("%s %s", X+1, Y+1);
         
    match = LSCLength(X ,Y);
    printf("%d\n",match);
  }
   
  return 0;
}

int LSCLength(char *X, char *Y){
  int i, j, m, n;
  int c[Length+1][Length+1];
   
  m = strlen(X+1);
  n = strlen(Y+1);
     
  for(i = 1; i <= m; i++){
    c[i][0] = 0;
  }
   
  for(j = 0; j <= n; j++){
    c[0][j] = 0;
  }
   
  for(i = 1; i <= m; i++){
    for(j = 1; j <= n; j++){
      if(X[i] == Y[j]){
	c[i][j] = c[i-1][j-1] + 1;
      }
      else if(c[i-1][j] >= c[i][j-1] ){
	c[i][j] = c[i-1][j];
      }
      else{
	c[i][j] = c[i][j-1];
      }
         
    }
  }
     
  return c[m][n];
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    string S=s.substr(k-1,1);
    if(S=="A")S="a";
    else if(S=="B")S="b";
    else S="c";
    cout<<s.substr(0,k-1)+S+s.substr(k,n-k)<<endl;
    
}


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

const int N = 2020, M = N * N;
const int MOD = 1e9 + 7;
int f[N][N], fra[M], inv[M];

int qpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1ll * a * a % MOD)
		if (b & 1) res = 1ll * res * a % MOD;
	return res;
}
 
void init(int n) {
	fra[0] = 1;
	for (int i = 1; i <= n; i++) fra[i] = 1ll * fra[i - 1] * i % MOD;
	inv[n] = qpow(fra[n], MOD - 2);
	for (int i = n - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
}

int C(int n, int m) {
	if (m > n) return 0;
	return 1ll * fra[n] * inv[n - m] % MOD * inv[m] % MOD;
}

int main() {
	init(2000 * 2000);
	int n, k;
	scanf("%d%d", &n, &k);
	if (k == 1) {
		printf("1\n");
		return 0;
	}
	for (int i = 0; i <= n; i++) f[i][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++)
			f[i][j] = (f[i - 1][j] + (long long)f[i][j - 1] * C(n * k - i - 1- (k - 1) * (j - 1), k - 2) % MOD) % MOD;
//	for (int i = 1; i <= n; i++)
//		for (int j = 0; j <= i; j++)
//			printf("%d%c", f[i][j], " \n"[j == i]);
	int ans = 1ll * f[n][n] * fra[n] % MOD;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 48880
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
a.sort()
m = a[-1]  # m = max(a)
s = [0]*(m+1)  # インデックスを合わせる
ans = 0
for i in a:
    if s[i] <= 1:  # 2以上なら計算しても意味ない
        for j in range(i, m+1, i):
            s[j] += 1  # sのiの倍数の部分を増やす
# ここで、s[i] == 1なら、自分自身で一度だけ+1されてることと同値なので他の数字と互いに素。
# 逆に2以上なら自分自身と自分の倍数で+1されてるから互いに素ではない。
for k in a:
    if s[k] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 32948
let n = Scanf.scanf " %d" @@ (+) 0
let ss = Array.init n @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let substr_count sub s =
  let rec loop acc i r n m =
    if i >= n then acc
    else try let j = Str.search_forward r s i + m in loop (acc + 1) j r n m with _ -> acc
  in loop 0 0 (Str.regexp sub) (String.length s) (String.length sub)
let b_a = Array.fold_left (fun acc s -> acc + if s.[0] = 'B' && s.[String.length s - 1] = 'A' then 1 else 0) 0 ss
let x_a = Array.fold_left (fun acc s -> acc + if s.[0] <> 'B' && s.[String.length s - 1] = 'A' then 1 else 0) 0 ss
let b_x = Array.fold_left (fun acc s -> acc + if s.[0] = 'B' && s.[String.length s - 1] <> 'A' then 1 else 0) 0 ss
let ab = Array.fold_left (fun acc s -> acc + substr_count "AB" s) 0 ss
let _ = Printf.printf "%d\n" @@ ab + min x_a b_x + if max x_a b_x = 0 then max 0 @@ b_a - 1 else b_a

Measured memory_bytes: 4992
MOD = 1000000007
n = int(input())
a = list(map(int, input().split()))
zero = a.count(0)

if zero == 1:
	ans = 3
elif 2 <= zero <= 3:
	ans = 6
else:
	ans = 0

cnt = [0 for _ in range(n)]
for x in a:
	cnt[x] += 1
	if cnt[x] > 3:
		ans = 0
	if x > 0:
		ans *= cnt[x-1]
		ans %= MOD
		cnt[x-1] -= 1

print(ans)

Measured memory_bytes: 14396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		

		if (A > 8 || B > 8) {

			System.out.println(":(");
			
		}else {

			System.out.println("Yay!");

		}
	}
}


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

#define int long long

struct coins {
        int a, b, c;
        bool operator < (const coins &r) const { return a < r.a; }
};

signed main() {
        int x, y, z;
        cin >> x >> y >> z;
        int n = x + y + z;
        vector<pair<int, coins>> p;
        for (int i = 0; i < n; i ++) {
                int a, b, c;
                cin >> a >> b >> c;
                p.emplace_back(a - b, (coins) { a, b, c });
        }
        sort(p.begin(), p.end());
        priority_queue<pair<int, coins>, vector<pair<int, coins>>, greater<pair<int, coins>>> pq_left;
        int ans_l_silver = 0;
        for (int i = 0; i < y; i ++) { 
                pq_left.push(make_pair(p[i].second.b - p[i].second.c, p[i].second));
                ans_l_silver += p[i].second.b;
        }
        vector<int> ans_left(z + 1);
        ans_left[0] = ans_l_silver;
        int ans_l_bronze = 0;
        for (int k = y; k < n - x; k ++) {
                pq_left.push(make_pair(p[k].second.b - p[k].second.c, p[k].second));
                pair<int, coins> mi = pq_left.top(); pq_left.pop();
                ans_l_silver += p[k].second.b - mi.second.b;
                ans_l_bronze += mi.second.c;
                ans_left[k - y + 1] = ans_l_silver + ans_l_bronze;
        }
        priority_queue<pair<int, coins>, vector<pair<int, coins>>, greater<pair<int, coins>>> pq_right;
        int ans_r_gold = 0;
        for (int i = n - 1; i > n - 1 - x; i --) {
                pq_right.push(make_pair(p[i].second.a - p[i].second.c, p[i].second));
                ans_r_gold += p[i].second.a;
        }
        vector<int> ans_right(z + 1);
        ans_right[z] = ans_r_gold;
        int ans_r_bronze = 0;
        for (int k = n - x - 1; k >= y; k --) {
                pq_right.push(make_pair(p[k].second.a - p[k].second.c, p[k].second));
                pair<int, coins> mi = pq_right.top(); pq_right.pop();
                ans_r_gold += p[k].second.a - mi.second.a;
                ans_r_bronze += mi.second.c;
                ans_right[k - y] = ans_r_gold + ans_r_bronze;
        }
        int ans = -1;
        for (int i = 0; i < ans_right.size(); i ++){
                ans = max(ans, ans_right[i] + ans_left[i]);
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 12396
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int a, b, g, l;

    for(;sc.hasNext();){
      a = sc.nextInt();
      b = sc.nextInt();

      g = gcd(a, b);
      l = (a / g) * b;

      System.out.println(g + " " + l);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static int gcd(int a, int b){
    if(a % b == 0){
      return b;
    }else{
      return gcd(b, (a % b));
    }
  }
}

Measured memory_bytes: 15368
//Andrew Yang
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>	
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>
using namespace std;
#define FOR(index, start, end) for(int index = start; index < end; ++index)
#define RFOR(index, start, end) for(int index = start; index > end; --index)
#define FOREACH(itr, b) for(auto itr = b.begin(); itr != b.end(); ++itr)
#define RFOREACH(itr, b) for(auto itr = b.rbegin(); itr != b.rend(); ++itr)
#define INF 1000000000
#define M 1000000007
typedef long long ll;
typedef pair<int, int> pii;
int cnt[100001];
int main(void)
{
	int n, m;
	scanf("%d%d", &n, &m);
	FOR(i, 0, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		cnt[a]++;
		cnt[b]++;
	}
	FOR(i, 0, n) {
		if (cnt[i] % 2 == 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 640