akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve()
{
  int N, M;
  cin >> N >> M;
  vector<P> w;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    w.emplace_back(b, a);
  }
  sort(w.begin(), w.end(), greater<P>());
  dump(w);
  set<int> st;
  for (int i = 0; i < M; i++) {
    st.insert(i + 1);
  }
  dump(st);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    auto it = st.lower_bound(w[i].second);
    if (it == st.end())
      continue;
    ans += w[i].first;
    st.erase(it);
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 5748
#include<cstdio>
typedef long long ll;

ll gcd(ll a,ll b)
{
	return !b?a:gcd(b,a%b);
}

int fpow(int a,ll b,int c)
{
	ll w=1,o=a;
	while(b) {
		if(b&1) w=w*o%c;
		o=o*o%c;
		b>>=1;
	}
	return w;
}

int Phi(int n)
{
	int r=n;
	for(int i=2; i*i<=n; i++)
		if(n%i==0)
		{
			r=r/i*(i-1);
			while(n%i==0)n/=i;
		}
	if(n>1)r=r/n*(n-1);
	return r;
}

ll exgcd(ll a,ll b,ll&x,ll&y)
{
	if(!b)
	{
		x=1;
		y=0;
		return a;
	}
	ll c=exgcd(b,a%b,x,y);
	ll t=x;
	x=y;
	y=t-a/b*y;
	return c;
}

ll Inv(ll a,ll b)
{
	ll x,y;
	exgcd(a,b,x,y);
	return(x+b)%b;
}

ll now,M;

void excrt(ll a,ll b)
{
	ll c=((a-now)%b+b)%b;
	ll x,y;
	ll d=exgcd(M,b,x,y);
	if(c%d!=0) throw -1;
	c/=d;
	b/=d;
	x=(x%b+b)%b;
	x=(__int128)x*c%b;
	now+=x*M;
	M*=b;
}

int T,n,m;
ll k;

ll solve(int d)
{
	if(d==1)
		return 1;
	int pd=Phi(d);
	ll y=solve(gcd(d,pd));
	now=y%pd;
	M=pd;
	excrt(fpow(n,y,d),d);
	while(now<=0) now+=(ll)d*pd;
	return now;
}

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		printf("%lld\n",solve(m));
	}
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ.Volume2
{
    public class PopularIcecreamShop
    {
        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                var sales = new int[10];
                for(int i = 0; i <= 9; i++) { sales[i] = 0; }

                for (int i = 0; i < n; i++)
                {
                    int kind = int.Parse(Console.ReadLine());
                    sales[kind]++;
                }

                for(int i = 0; i <= 9; i++)
                {
                    string output = "";
                    if (sales[i] > 0) { output = output.PadRight(sales[i], '*'); }
                    else { output = "-"; }

                    Console.WriteLine(output);
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 8952
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
for i in range(n):
    b = int(input())
    a1 = [0 if i == b else i for i in a1]
    a2 = [0 if i == b else i for i in a2]
    a3 = [0 if i == b else i for i in a3]
    
if a1[0] == a2[0] == a3[0] == 0 or a1[1] == a2[1] == a3[1] == 0 or a1[2] == a2[2] == a3[2] == 0 or a1[0] == a2[1] == a3[2] == 0 or a1[2] == a2[1] == a3[0] == 0 or a1[0] == a1[1] == a1[2] or a2[0] == a2[1] == a2[2] or a3[0] == a3[1] == a3[2]:
    print('Yes') 
else:
    print('No')


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int j,k,n,a,b,x[2];
scanf("%d\n%d\n",&n,&k);
for(j=0;j<k;j++){
scanf("%d %d\n",&a,&b);
if(b>n-b){
b=n-b+1;
}
if(a>n-a){
a=n-a+1;
}
if(a<b){
x[0]=a%3;
}
else{
x[0]=b%3;
}
if(x[0]==0){
printf("3\n");
}
else{
printf("%d\n",x[0]);
}
}
return 0;
}


Measured memory_bytes: 2108
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

void solve(int test)
{
    int n;
    cin >> n;
    VInt v(n);
    int i;
    FOR(i, 0, n) cin >> v[i];
    sort(ALL(v));
    
    vector<PII> w(n);
    VInt s(n);
    
    w[0] = PII(v.back(), v.front());
    int t = v.back() - v.front();
    FOR(i, 1, n - 1) t += abs(v[i]);
    
    int res = t;
    RFOR(i, n - 1, 1)
    {
        if(t > 0)
        {
            if(v[i] > 0)
            {
                w[i] = PII(v[i], v[i] - t);
                t = v[i] - t;
            }
            else
            {
                w[i] = PII(t + v[i], v[i]);
                t = t + v[i];
            }
        }
        else
        {
            if(v[i] < 0)
            {
                w[i] = PII(v[i], v[i] - t);
                t = v[i] - t;
            }
            else
            {
                w[i] = PII(t + v[i], v[i]);
                t = t + v[i];
            }
        }
    }
    
    if(t < 0) swap(w[0].first, w[0].second);
    cout << res << endl;
    FOR(i, 0, n - 1) printf("%d %d\n", w[i].first, w[i].second);
}

int main()
{
    int t, T;
    T = 1;
    //scanf("%d", &T);
    FOR(t, 0, T) solve(t);
    
    return 0;
};



Measured memory_bytes: 3456
n, k = map(int, (input().split()))
w_list = [int(input()) for _ in range(n)]
left = max(w_list)-1
right = sum(w_list)

while (right-left) > 1:
    mid = (left + right)//2
    count = 1
    c = 0
    for w in w_list:
        if mid < c + w:
            ｃ = w
            count += 1
        else:
            c += w
    if count <= k:
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 9660
fun main (args:Array<String>){
    val palindRome = readLine()!!
    val palindRomeLen = palindRome.length
    val left = palindRome.take((palindRomeLen-1)/2)
    val right = palindRome.takeLast((palindRomeLen-1)/2)
    if(left == right) print("Yes")
    else print("No")
}

Measured memory_bytes: 35968
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
const int INF =100100100;
const int MOD = (int)1e9+7;
const double EPS = 1e-9;
typedef long long ll;
typedef long li;
#define pb push_back 
#define mp make_pair

signed main (){	
	int nn;
	cin >> nn;
	vector <int> kushi;
	int temp;
	rep(i,2*nn){
		cin >> temp;
		kushi.pb(temp);
	}
	sort(kushi.rbegin(),kushi.rend());
	ll ans =0;
	rep(i,2*nn){
		if(i%2 == 1) ans += kushi[i];
	}	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int a, b;
  while (cin >> a >> b) {
    string s = string(a, '0' + b);
    string t = string(b, '0' + a);
    cout << min(s, t) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e9+7;
ll INF=1e10;

ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P==1) return N%M;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return (N * RepeatSquaring(N, P-1, M))%M;
}

int main(){
    ll n,a,b; cin>>n>>a>>b;
    a=min(a,n-a);
    b=min(b,n-b);
    ll ans=RepeatSquaring(2,n,mod)-1;
    ll xa=1,ya=1;
    rep(i,a){
        xa*=n-(i);
        xa%=mod;
        ya*=i+1;
        ya%=mod;
    }
    ya=RepeatSquaring(ya,mod-2,mod);
    ll A=xa*ya%mod;
    ll xb=1,yb=1;
    rep(i,b){
        xb*=n-i;
        xb%=mod;
        yb*=i+1;
        yb%=mod;
    }
    yb=RepeatSquaring(yb,mod-2,mod);
    ll B=xb*yb%mod;
    ans-=(A+B);
    ans%=mod;
    if(ans<0)ans+=mod;
    cout<<ans<<endl;


}



























































































Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define MOD 1000000007LL
#define MAXN 22

using namespace std;
using ll = long long;

int n;
int A[MAXN][MAXN];
ll dp[1 << MAXN];

ll solve(int mask) {
  int ind = __builtin_popcount(mask) - 1;
  if (mask == 0) {
    return 1LL;
  }
  ll& res = dp[mask];
  if (res != -1) { return res; }
  res = 0LL;
  for (int i = 0; i < n; i++) {
    if ((mask & (1 << i)) == 0) { continue; }
    if (!A[ind][i]) { continue; }
    int newmask = mask & ~(1 << i);
    res = (res + solve(newmask)) % MOD;
  }
  return res;
}

int main() {
  fill(dp, dp + (1 << MAXN), -1LL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> A[i][j];
    }
  }
  cout << solve((1 << n) - 1) << '\n';
  return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
 struct node{
    long long num;
    long long value;
    bool operator < (const node a)const{
        return value>a.value;
    }
 };
 int cmp(long long a,long long b)
 {
     return a<b;
 }
 node b[100010]={0};
 long long a[100010]={0};
int main()
{
    std::ios::sync_with_stdio(false);
    int n,m;
    cin >>n >> m;
    for(int i=0;i<n;++i){
        cin >> a[i] ;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<m;++i){
        cin >> b[i].num >> b[i].value;
    }
    sort(b,b+m);
    for(int i=0;i<m;++i){
        //cout << b[i].value;
    }
    long long sum=0;
    for(int i=0,j=0;i<n;i++){
        if(a[i]>=b[j].value){
            sum+=a[i];
        }
        else{
            sum+=b[j].value;
            b[j].num--;
            if(b[j].num==0){
                j++;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2560
n=int(input())
h_=list(map(int,input().split()))

flag=True
max_num=h_[0]
for i in range(1,n):
    if max_num > h_[i]:
        if max_num - h_[i] >=2:
            flag=False
            break
        else:
            max_num=max_num
    else:
        max_num=h_[i]

if flag:
    print("Yes")
else:
    print('No')

Measured memory_bytes: 15020
#include <stdio.h>
#include <math.h>
 

long long int f(long long int b,long long int n){
 
  long long int ans=0;
  while(n>=b){
    ans+=(n%b);
    n=n/b;
  }
  return ans+n;
}

int main(){
  long long int n,s;
  long long int i,b;
  scanf("%lld %lld",&n,&s);
 
  if(s==n){
    printf("%lld\n",n+1);
    return 0;
  }
 
  for(i=2;i*i<=n;i++){
    if(f(i,n)==s){
      printf("%lld\n",i);
      return 0;
    }
  }
  i=sqrt(n-s);
  while(i>=1){
    if((n-s)%i==0){
      b=(n-s)/i+1;
      if(f(b,n)==s){
	printf("%lld\n",b);
	return 0;
      }
    }
    i--;
  }
 
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

X=0
for i in range(N):
    if i%2==0:
        X+=A[i]
    else:
        X-=A[i]

#print(X)


ANS=[X]

for i in range(N-1):
    ANS.append((A[i]-ANS[-1]//2)*2)

print(*ANS)


Measured memory_bytes: 14124
N,K = list(map(int,input().split()))
per = 0

def f(x,y):
    count = 0
    while (x < y):
        x = 2*x
        count += 1
    return count

for i in range(N):
    b = int(f(i+1,K))
    per += (1/N)*((1/2)**b)
print(per)

Measured memory_bytes: 3060
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	a := io.NextInts(n)
	cnt := map[int]int{}
	all := 0
	for _, v := range a {
		all += cnt[v]
		cnt[v]++
	}
	for i := range a {
		ans := all - (cnt[a[i]] - 1)
		io.Println(ans)
	}
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 20436
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
lld n,w;
lld arr[150][2];
lld dp[150][100005];
lld what(int n, int w)
{
	if(n==0||w==0)
		return 0ll;
	if(dp[n][w]!=-1)
		return dp[n][w];
	int we = arr[n-1][0];
	int ve = arr[n-1][1];
	if(w-we>=0)
		return(dp[n][w]=max(what(n-1,w),what(n-1,w-we)+ve));
	return(dp[n][w]=what(n-1,w));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> w;
	// memset(dp,-1,sizeof(dp));
	// fill(dp,dp+n+w, -1); 
	for(int i=0;i<150;i++)
	{
		for(int j=0;j<100005;j++)
		{
			dp[i][j]=-1;
		}
	}
	// lld dp[n+1][w+1];
	// for(int i=0;i<w+1;i++)
	// {
	// 	dp[0][i]=0;
	// }
	// for(int i=0;i<n+1;i++)
	// {
	// 	dp[i][0]=0;
	// }
	for(int i=0;i<n;i++)
	{
		cin >> arr[i][0] >> arr[i][1] ;
	}
	// for(int i=1;i<=n;i++)
	// {
	// 	lld we = arr[i-1][0];
	// 	lld va = arr[i-1][1];
	// 	for(int j=1;j<=w;j++)
	// 	{
	// 		if(j-we>=0)
	// 		{
	// 			dp[i][j]=max(dp[i-1][j],dp[i-1][j-we]+va);
	// 		}
	// 		else
	// 		{
	// 			dp[i][j]=dp[i-1][j];
	// 		}
	// 	}
	// }
	lld ans=-1;
	for(int i=0;i<=w;i++)
	{
		what(n,i);
	}
	for(int i=0;i<=w;i++)
	{
		ans=max(ans,dp[n][i]);
	}
	cout << ans;
}

Measured memory_bytes: 117504
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    vector<LL> A(N);rep(i,N)cin >> A[i];

    vector<LL> m;
    bool zero = false;

    int minus = 0;
    rep(i,N){
        m.push_back(abs(A[i]));
        if(A[i] < 0)minus++;
        if(A[i] == 0)zero = true;
    }


    sort(all(m));

    LL ans = 0;
    rep(i,N){
        ans += abs(A[i]);
    }
    if(!zero && minus % 2 != 0){
        ans -= 2*m[0];
    }

    cout << ans << endl;


    

}

Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		double ans = 0.0;

		for (int i = 0; i < n; i++) {
			double x = sc.nextDouble();
			String u = sc.next();
			if (u.equals("JPY")) {
				ans += x;
			} else {
				ans += x * 380000.0;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        if(0 <= a && a <=100 && 0 <= b && b <= 100 && 0 <=c && c <= 100){
            if(a < b && b < c){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }

        }
    }
}



Measured memory_bytes: 26336
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {

	ll a,b;
	char op;
	cin>>a>>op>>b;
	if(op=='+')cout<<a+b<<endl;
	else cout<<a-b<<endl;

	return 0;
}


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

int main(){
    string s;
    cin >> s;
    string ans = "keyence";
    //i個までは前にあるとする
    for (int i = 0; i <= 7; i++){
        bool flag = true;
        for (int j = 0; j < 7; j++){
            if (j < i) {
                if (s[j] != ans[j]) flag = false;
            }
            else {
                if (s[s.size() - 7 + j] != ans[j]) flag = false;
            }
        }
        if (flag) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

for i in range(Q):
    l, r = map(int, input().split())
    question_list.append((l, r))

total_list = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        total_list[i + 1] = total_list[i] + 1
    else:
        total_list[i + 1] = total_list[i]

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = total_list[r - 1] - total_list[l - 1]
    print(num)


Measured memory_bytes: 19740
#include<stdio.h>
#include<string.h>
using namespace std;
char a[105][5];
char  b[105][5];
int q=1;
void squt(char a[],char b[]){
    char s[105];
    strcpy(s,a);
    strcpy(a,b);
    strcpy(b,s);
}

int main(){
int n;
char s;
scanf("%d%c",&n,&s);
for(int i=0;i<n;i++){
    scanf("%s",a[i]);
    strcpy(b[i],a[i]);

}

 for(int i=1 ;i<n;i++){
   for(int j=0;j<n-i;j++){
    if(a[j][1]>a[j+1][1]){
        squt(a[j],a[j+1]);
    }
   }
 }
 for(int i=0;i<n;i++){
    int m=i;
    for(int j=i;j<n;j++){
        if(b[j][1]<b[m][1]){
            m=j;
        }
    }
        squt(b[i],b[m]);

 }

 for(int i=0;q!=0&&i<n;i++){
    if(a[i][0]!=b[i][0]||a[i][1]!=b[i][1]){
        q=0;
    }

 }

for(int i=0;i<n-1;i++){
    printf("%s ",a[i]);
 }
 printf("%s",a[n-1]);
 printf("\nStable\n");
 for(int i=0;i<n-1;i++){
    printf("%s ",b[i]);
 }
 printf("%s",b[n-1]);
 if(q==0){
    printf("\nNot stable\n");
 }
 else {
  printf("\nStable\n");
 }

return 0;
}

Measured memory_bytes: 2844
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
  if(n==1)cout<<1<<endl;
  else{
    vector<pair<long long ,long long > > d(0),d2(0),xy(n);
    for(int i=0;i<n;i++){
        cin >> xy[i].first>>xy[i].second;
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
          if((xy[i].first-xy[j].first)*(xy[i].second-xy[j].second)>=0)
            d.push_back({abs(xy[i].first-xy[j].first),abs(xy[i].second-xy[j].second)});
          else if((xy[i].first-xy[j].first)*(xy[i].second-xy[j].second)<0){
            if(xy[i].second-xy[j].second<0)
              d2.push_back({xy[i].first-xy[j].first,-xy[i].second+xy[j].second});
            else
              d2.push_back({-xy[i].first+xy[j].first,xy[i].second-xy[j].second});
          }
        }
    }
    long long ma=1,ma2=1;
    if(d.size()>0){
      sort(d.begin(),d.end());
      long long a=d[0].first,b=d[0].second,count=1;
      for(int i=1;i<d.size();i++){
        if(a==d[i].first&&b==d[i].second){
            count++;
        }
        else{
            ma=max(ma,count);
            count=1;
            a=d[i].first,b=d[i].second;
        }
      }
    }
    if(d2.size()>0){
      sort(d2.begin(),d2.end());
      long long a=d2[0].first,b=d2[0].second,count=1;
      for(int i=1;i<d2.size();i++){
        if(a==d2[i].first&&b==d2[i].second){
            count++;
        }
        else{
            ma2=max(ma2,count);
            count=1;
            a=d2[i].first,b=d2[i].second;
        }
      }
    }
    cout<<n-max(ma,ma2)<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   string s; cin>>s;
   int ans=0;
   for(int i=0;i<s.length()/2;i++){
      if(s[i]!=s[s.length()-i-1]) ans++;
   }
   cout<<ans<<endl;
   return 0;
}

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

#define INF 100000000

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

    int n;
    cin>>n;

    int ans=INF;

    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;

        int cnt=0;
        for(;a%2==0;cnt++)a/=2;
        ans=min(ans,cnt);
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;
int W[105];

int main(){

	scanf("%d",&N);

	int sum = 0;
	for(int i = 0; i < N; i++){

		scanf("%d",&W[i]);
		sum += W[i];
	}

	int ans = BIG_NUM;
	int work = 0;

	for(int i = 0; i < N; i++){

		work += W[i];
		ans = min(ans,abs(work-(sum-work)));
	}

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

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807



void solve(void)
{

    int n;
    cin>>n;
    int m;
    for (int i = 1; i <= n; i++)
    {
        
        if(i%3 == 0)
        {
        cout<<" "<<i;
        continue;
        }

            // if(i%10 ==3)
            // {
            //             cout<<" "<<i;
            //             break;
            // }
        m = i;
        while(m>0)
        {
            if(m%10 ==3)
            {
                        cout<<" "<<i;
                        break;
            }
            m /=10;
        }
    }
    

    cout<<endl;
    // 3 6 9 12 13 15 18 21 23 24 27 30 31 32 33 34 35 36 37 38 39 42 43 45 48 51 53 54 57 60
    // 3 6 9 12 13 15 18 21 23 24 27 30 33 36 39 42 43 45 48 51 53 54 57 60

  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3096
#include<stdio.h>
/* 素数判定*/
int isPrime(int x)
{
  int i;
  if ( x<2 ) return 0;
  else if ( x==2 ) return 1;
  if ( x%2==0 ) return 0;
  for (i=3; i*i <=x; i+=2)
  {
    if ( x%i==0 ) return 0;
  }
  return 1;
}

int main()
{
  int n, x, i;
  int cnt=0;
  
  scanf("%d", &n);
  for (i = 0; i< n; i++ )
  {
    scanf ("%d", &x);
    if ( isPrime(x) ) cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 2000
import java.util.*;

public class Main {
	static long MOD = 1000000007;

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

		long[][] comb = new long[2010][2010];
		for(int i=0; i<2010; i++) {
			for(int j=0; j<=i; j++) {
				if(j==0 || j==i) {
					comb[i][j] = 1;
				} else {
					comb[i][j] = (comb[i-1][j-1] + comb[i-1][j])%MOD;
				}
			}
		}
		
		long ans = 0;
		
		for(int i=1; i<=S/3; i++) {
			ans = (ans + comb[S-i*2-1][i-1])%MOD;
		}
		
		System.out.println(ans);
		sc.close();
	}
	
}


Measured memory_bytes: 75564
#include<stdio.h>

int same(int *x, int *y, int n){
    int i;
    for(i = 0;i < n;i++){
	if(x[i] != y[i])return 0;
    }
    return 1;
}

void swap(int *x, int *y){
    int p = *x;
    *x = *y;
    *y = p;
}

int main(){
    int i, j, n;
    while(scanf("%d", &n), n){
	int a[n], b[n], res = 0;
	for(i = 0;i < n;i++)scanf("%d", a + i);
	while(1){
	    for(i = 0;i < n;i++){
		b[i] = 0;
		for(j = 0;j < n;j++){
		    if(a[j] == a[i])b[i]++;
		}
	    }
	    if(same(a, b, n))break;
	    for(i = 0;i < n;i++)swap(a + i, b + i);
	    res++;
	}
	printf("%d\n", res);
	for(i = 0;i < n;i++){
	    if(i != 0)printf(" ");
	    printf("%d", a[i]);
	}
	puts("");
    }
    return 0;
}

Measured memory_bytes: 1044
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector <int> v(n);
    for (auto &it : v)
        cin >> it;
    sort(rall(v));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i >= k) {
            ans += v[i];
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
class finite_field {
  const int md;
  const int sz;
  vector<int> fct, fnv;
  void init () {
    if (sz) {
      fct[0] = 1;
      for (int i = 1; i < sz; i++) fct[i] = prod(fct[i - 1], i);
      fnv[sz - 1] = inv(fct[sz - 1]);
      for (int i = sz - 1; i >= 1; i--) fnv[i - 1] = prod(fnv[i], i);
    }
  }
  public:
    finite_field(
        const int md,
        const int init_factorial_size = 0,
        const int init_power_size = 0
      ) :
      md(md), sz(init_factorial_size),
      fct(sz), fnv(sz)
      {
        init();
      }
    inline void add (int& a, const int b) const {
      a += b;
      if (a >= md) a -= md;
    }
    inline void sub (int& a, const int b) const {
      a -= b;
      if (a < 0) a += md;
    }
    template<class... A> inline int sum (A... args) const {
      int ret = 0;
      for (int a : initializer_list<int>{args...}) {
        add(ret, a);
      }
      return ret;
    }
    inline int dif (int a, int b) const {
      sub(a, b);
      return a;
    }
    template<class... A> inline int prod (A... args) const {
      long long ret = 1;
      for (int a : initializer_list<int>{args...}) {
        ret *= a;
        ret %= md;
      }
      return (int)ret;
    }
    void mul (int& a, int b) const {
      a = prod(a, b);
    }
    inline int inv (int a) const {
      a %= md; if (a < 0) a += md;
      int b = md, u = 0, v = 1;
      while (a) {
        int t = b / a;
        b -= a * t; swap(a, b);
        u -= v * t; swap(u, v);
      }
      assert(b == 1);
      if(u < 0) u += md;
      return u;
    }
    inline int quat (int a, int b) const {
      return prod(a, inv(b));
    }
    inline void div (int& a, int b) const {
      a = quat(a, b);
    }
    inline int pow (int a, long long b) {
      int ret = 1;
      for (; b; b >>= 1) {
        if (b & 1) mul(ret, a);
        a = prod(a, a);
      }
      return ret;
    }
    inline int binom (int n, int k) const {
      assert(0 <= n && n < sz);
      if (k < 0 || n < k) return 0;
      return prod(fct[n], fnv[k], fnv[n - k]);
    }
};
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int>> dp(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = a[i] > a[j] ? 1 : 0;
    }
  }
  const int md = 1e9 + 7;
  finite_field fld(1e9 + 7);
  int inv2 = fld.inv(2);
  int coeff = fld.pow(2, q);
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    auto half = [&] (int& a, int& b) -> void {
      a = b = (long long)(a + b) * inv2 % md;
    };
    half(dp[x][y], dp[y][x]);
    for (int z = 0; z < n; z++) if (z != x && z != y) {
      half(dp[x][z], dp[y][z]);
      half(dp[z][x], dp[z][y]);
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      fld.mul(dp[i][j], coeff);
      fld.add(ret, dp[i][j]);
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 37632
#include <stdio.h>
#include <string.h>

char dict[30600000];

char word[26];

long encode(const char *key){
  int n=strlen(key),i;
  long sum=0;
  long keta=1;
  for(i=0;i<n;i++){
    int keyi=key[i];
    sum = sum + keta * word[keyi];
    keta=(keta<<2)+keta;
  }
  return (sum);
}

void insert(const char *key2) {
  long key=encode(key2);
  long keta=key/8;
  dict[keta]=(dict[keta]|(1<<(key%8)));
}

int find_h(const char *key2) {
  long key=encode(key2);
  return (dict[key/8] & 1<<(key%8));
}

int main(void) {
  long n,i;
  word['A'] = 1;
  word['C'] = 2;
  word['G'] = 3;
  word['T'] = 4;
  scanf("%ld\n",&n);
  for(i=0;i<n;i++){
    char cmd[8], str[14]; scanf("%s %s\n",cmd, str);
    if(cmd[0]=='i') {
      insert(str);
    }
    else {
      if(find_h(str)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1432
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct Cake {
  vector<int> ind;
  ll score;
};

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int X, Y, Z, K;
  while (cin >> X >> Y >> Z >> K) {
    vector<ll> A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];
    vector<ll> pairs;
    for (ll a : A) {
      for (ll b : B) {
        pairs.push_back(a + b);
      }
    }
    sort(pairs.begin(), pairs.end());
    ll pass = 0, fail = 1ll << 60;
    while (fail - pass > 1) {
      ll V = (pass + fail) / 2;
      ll cnt = 0;
      for (ll c : C) {
        auto p = lower_bound(pairs.begin(), pairs.end(), V - c);
        cnt += distance(p, pairs.end());
      }
      if (cnt >= K) {
        pass = V;
      } else {
        fail = V;
      }
    }
    ll lastV = pass;
    vector<ll> cand;
    for (ll c : C) {
      auto p = lower_bound(pairs.begin(), pairs.end(), lastV - c);
      while (p < pairs.end()) {
        cand.push_back(c + *p);
        ++p;
      }
    }
    sort(cand.rbegin(), cand.rend());
    for (int i = 0; i < K; i++) cout << cand[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 140256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> x(5);
  
   
  
  for(int i = 0; i < 5; i++){
    cin >> x.at(i);
    if (x.at(i) == 0){
        cout << i + 1 << endl;
    }
  
    
  }
  
  
  
}

Measured memory_bytes: 3552
#include <stdio.h>
#include <math.h>

int main() {

  double d1,d2,d3,d4;
  int i,j,k,l,n;
  double x[1020] = {0};
  double y[1020] = {0};
  double z[1020] = {0};
  double o,p,q,max;
  max = -1;
  o=0;
  p=0;
  q=0;
  d1 = 0;
  d2 = 0;
  d3 = 0;
  d4 = 0;

  scanf("%d",&n);

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

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

  for(i=0; i<n;i++) {

    o = (x[i] - y[i]) * (x[i] - y[i]);
    p = (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
    p = p*p;
    p = sqrt(p);
  
    d3 = d3 + p;
    d2 = d2+o;
    d1 = d1 + sqrt(o); 

    if(max < sqrt(o)) {
      max = sqrt(o);
    }

   
  }

  d2 = pow(d2,1.0/2);
  d3 = pow(d3,1.0/3);
  d4 = max;

  printf("%.11lf\n%.11lf\n%.11lf\n%.11lf\n" ,d1,d2,d3,d4);

  return 0;

}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main(){
  int n;
  cin >> n;
  int ans = 0;

  int k = log10(n);
  vector<vecint > tab(10,vecint(10,0));
  for(int i = 1; i <= 9; i ++){
    if(i <= n){
      tab[i][i] ++;
    }
  }
  if(k >= 1){
    for(int i = 1; i <= 9; i ++){
      for(int j = 1; j <= 9; j ++){
	if(10*i + j <= n){
	  tab[i][j] ++;
	}
      }
    }
  }
  if(k >= 2){
    for(int i = 1; i <= 9; i ++){
      for(int j = 1; j <= 9; j ++){
	for(int k = 0; k <= 9; k ++){
	  if(100*i + k* 10 +  j <= n){
	    tab[i][j] ++;
	  }
	}
      }
    }
  }
  if(k >= 3){
    for(int i = 1; i <= 9; i ++){
      for(int j = 1; j <= 9; j ++){
	for(int k = 0; k <= 99; k ++){
	  if(1000*i + k* 10 +  j <= n){
	    tab[i][j] ++;
	  }
	}
      }
    }
  }
  if(k >= 4){
    for(int i = 1; i <= 9; i ++){
      for(int j = 1; j <= 9; j ++){
	for(int k = 0; k <= 999; k ++){
	  if(10000*i + k* 10 +  j <= n){
	    tab[i][j] ++;
	  }
	}
      }
    }
  }
  if(k >= 5){
    for(int i = 1; i <= 9; i ++){
      for(int j = 1; j <= 9; j ++){
	for(int k = 0; k <= 9999; k ++){
	  if(100000*i + k* 10 +  j <= n){
	    tab[i][j] ++;
	  }
	}
      }
    }
  }

  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      ans += tab[i][j]*tab[j][i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
N, K = map(int, input().split())

d = {}
for i in range(N):
    d[i] = 0

for _ in range(K):
    i = int(input())
    a = list(map(int, input().split()))
    for j in a:
        d[j-1] += 1

c = 0
for i in d:
    if d[i] == 0:
        c += 1
        
print(c)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {
	int r;
	int c;
	int max = 0;
	boolean[] flg = new boolean[10];
	boolean[][] osenbei;
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			r = scan.nextInt();
			c = scan.nextInt();
			if (r == 0 && c == 0) break;
			osenbei = new boolean[r][c];
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					if (scan.nextInt() == 1) {
						osenbei[i][j] = true;
					} else {
						osenbei[i][j] = false;
					}
				}
			}
			solve(0);
			System.out.println(max);
		}
	}

	void solve(int index) {
		if (index == r) {
			int ans = count(flg);
			if (max < ans) {
				max = ans;
			}
			return;
		}

		solve(index + 1);

		flg[index] = false;
		solve(index + 1);
		flg[index] = true;
	}

	int count(boolean[] flg) {
		boolean[][] tmp = new boolean[r][];
		for (int i = 0; i < r; i++)
			tmp[i] = osenbei[i].clone();
		
		int count = 0;
		for (int i = 0; i < r; i++) {
			if (flg[i]) {
				for (int j = 0; j < c; j++) {
					tmp[i][j] = !tmp[i][j];
				}
			}
		}
		for (int i = 0; i < c; i++) {
			int c = 0;
			for (int j = 0; j < r; j++) {
				if (tmp[j][i]) c++;
			}
			if (c < r - c)
				c = r - c;
			count += c;
		}
		
		return count;
	}

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

Measured memory_bytes: 102876
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std;

typedef unsigned long long ull;
typedef vector<char> vchar;
typedef vector<vchar> vvchar;
typedef vector<ull> vull;
typedef vector<vull> vvull;

const ull base1 = 1000000007, base2 = 1000000009;

vvchar input(int w, int h){
	vvchar ret(h, vchar(w));
	string s;
	for(int i = 0; i < h; ++i){
		cin >> s;
		int t = 0;
		for(int j = 0; j < s.size(); ++j){
			int a;
			if(isupper(s[j])){
				a = s[j] - 'A';
			}
			else if(islower(s[j])){
				a = s[j] - 'a' + 26;
			}
			else if(isdigit(s[j])){
				a = s[j] - '0' + 52;
			}
			else if(s[j] == '+'){
				a = 62;
			}
			else{
				a = 63;
			}

			for(int k = 5; k >= 0 && t < w; --k, ++t){
				ret[i][t] = a >> k & 1;
			}
		}
	}
	return ret;
}

vvull calchash(const vvchar &img, int p){
	int h = img.size(), w = img[0].size();
	vvull ret(h - p + 1, vull(w - p + 1));
	vvull tmp(h, vull(w));
	ull t1 = 1, t2 = 1;
	for(int i = 0; i < p; ++i){
		t1 *= base1;
		t2 *= base2;
	}

	for(int i = 0; i < h; ++i){
		ull e = 0;
		for(int j = 0; j < p; ++j){
			e = e * base1 + img[i][j];
		}
		
		for(int j = 0; j + p < w; ++j){
			tmp[i][j] = e;
			e = e * base1 - t1 * img[i][j] + img[i][j + p];
		}
		tmp[i][w - p] = e;
	}

	for(int j = 0; j + p <= w; ++j){
		ull e = 0;
		for(int i = 0; i < p; ++i){
			e = e * base2 + tmp[i][j];
		}
		for(int i = 0; i + p < h; ++i){
			ret[i][j] = e;
			e = e * base2 - t2 * tmp[i][j] + tmp[i + p][j];
		}
		ret[h - p][j] = e;
	}

	return ret;
}

void rotate(vvchar &ptn){
	int p = ptn.size();
	vvchar ret(p, vchar(p));
	for(int i = 0; i < p; ++i)
	for(int j = 0; j < p; ++j){
		ret[i][j] = ptn[p - j - 1][i];
	}
	ptn.swap(ret);
}

int solve(int w, int h, int p){
	vvchar img = input(w, h);
	vvchar ptn = input(p, p);

	if(w < p || h < p) return 0;

	vvull hi = calchash(img, p);
	vull hps;
	for(int i = 0; i < 2; ++i){
		for(int j = 0; j < 4; ++j){
			hps.push_back(calchash(ptn, p)[0][0]);
			rotate(ptn);
		}

		for(int k = 0; k < p; ++k){
			reverse(ptn[k].begin(), ptn[k].end());
		}
	}
	sort(hps.begin(), hps.end());

	int ans = 0;
	for(int i = 0; i < hi.size(); ++i)
	for(int j = 0; j < hi[0].size(); ++j){
		if(binary_search(hps.begin(), hps.end(), hi[i][j])){
			++ans;
		}
	}
	return ans;
}

int main(){
	int w, h, p;

	while(cin >> w >> h >> p, w){
		cout << solve(w, h, p) << '\n';
	}
}

Measured memory_bytes: 16404
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

string cmp(string a,string b){
    if(a.size()==b.size())return a<b?b:a;
    else return a.size()<b.size()?b:a;
}

int main(){
	int n;
	vi d={0,362880,40320,5040,720,120,24,6,2,1,1,};
	while(cin>>n,n){
        vs s(n);
        map<char,int> mp;
        set<char> st;
        rep(i,n) {
            cin>>s[i];
            if(s[i].size()!=1)st.insert(s[i][0]);
            int d=1,pref=(i+1==n)?-1:1;
            for(int j=s[i].size()-1;j>=0;j--){
                if(mp.find(s[i][j])==mp.end()){
                    mp[s[i][j]]=0;
                }
                mp[s[i][j]]+=pref*d;
                d*=10;
            }
        }
        string c="";
        vi x;
        for(auto p:mp){ c+=p.fs; x.pb(p.sc);}
        x.resize(10);
        vi p(10); iota(all(p),0);
        
        int ans=0;
        do{
            if(st.find(c[find(all(p),0)-p.begin()])!=st.end()) continue;
            if(inner_product(all(p),x.begin(),0)==0){
                ans++;
            }
        }while(next_permutation(all(p)));
        cout<<ans/d[mp.size()]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
bool primecheck(int x) {
  bool t = true;
  for (int i = 2; i * i < x; i++) {
    if (x % i == 0) t = false;
  }
  return t;
}
int main() {
  int x;
  cin >> x;
  while (true) {
    if(primecheck(x)){
      cout << x << endl;
      return 0;
    }
    x++;
  }
}

Measured memory_bytes: 256
N = input()

M = int(len(N))
flag = True

for i in range(M):
  if i % 2 == 0:
    if N[i] == "L":
      flag = False
  else:
    if N[i] == "R":
      flag = False
if flag == False:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define mo 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N;
vector<VI>G;
int ans;
int modpow(int a, int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int halfP = p / 2;
		int half = modpow(a, halfP);
		return half * half % mod;
	}
	else {
		return a * modpow(a, p - 1) % mod;
	}
}

long long modinv(long long a) {
	return modpow(a, mo - 2);
}


int dfs(int v, int p) {

	int res = 1;
	VI ts;
	fore(u, G[v]) {
		if (u == p)continue;
		int t = dfs(u, v);
		res += t;
		ts.push_back(t);
	}
	if (p != -1)ts.push_back(N - res);
	int now = modpow(2, N - 1) - 1;

	fore(t, ts) {
		now -= modpow(2, t) - 1;
		now %= mod;
	}


	ans += now;
	ans += mod;
	ans %= mod;
	return res;
}




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

	cin >> N;
	G.resize(N);
	
	REP(i, N - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	dfs(0,-1);
	//cout << ans << endl;

	cout << (ans * modinv(modpow(2, N)))%mod << endl;

	return 0;
}



Measured memory_bytes: 27264
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const int MOD = 1000000007;
const int INF = 1e7;
void dijkstra(map<int, set<int>> adj, int n, int src, vector<int> &p) {
	vi d(n, INF);
	p.assign(n, -1);
	set<pi> s; // <d, index>
	s.insert({0, src});
	d[src] = 0;
	while(!s.empty()) {
		int v = s.begin() -> S;
		s.erase(s.begin());
		for(int to: adj[v]) {
			if(d[to] > d[v]+1) {
				/* deb(to);deb(v); */
				s.erase({d[to], to});
				d[to] = d[v]+1;
				p[to] = v;
				s.insert({d[to], to});
			}
		}
	}
}


int main() {
	fastio();
	int n, m;
	cin >> n >> m;
	map<int, set<int>> adj;
	int u, v;
	for(int i=0;i<m;i++) {
		cin >> u >> v;
		adj[u-1].insert(v-1);
		adj[v-1].insert(u-1);
	}
	vector<int> p;
	dijkstra(adj, n, 0, p);
	p[0] = INF;
	if(*min_element(p.begin(), p.end()) == -1)
		cout << "No\n";
	else {
		cout << "Yes\n";
		for(vi::iterator it=p.begin()+1;it!=p.end();it++)
			cout << *it + 1 << "\n";
	}
	return 0;
}


Measured memory_bytes: 64808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static int N, M;
	public static int[] array;

	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(f.readLine());
		N = Integer.parseInt(st.nextToken());
		M = Integer.parseInt(st.nextToken());
		array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(f.readLine());
		}
		for (int i : array) {
			M -= i;
		}
		Arrays.sort(array);
		int res = array.length;
		res += (M / array[0]);
		System.out.println(res);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
struct team{
	std::string name;
	int point;
	int n;
};

bool tsort(const team& a,const team& b){
	if(a.point - b.point){
		return a.point > b.point;
	}
	return a.n < b.n;
}

int main(){
	int n;
	bool f = false;
	while(std::cin>>n,n){
		if(f)std::cout<<std::endl;
		else{f=true;}
		team all[10];
		for(int i = 0;i < n;i++){
			std::string name;
			int w,d,l;
			std::cin>>name>>w>>l>>d;
			team t = {name,w*3+d,i};
			all[i] = t;
		}
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<all[i].point<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0