akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
    #include <algorithm>

    using namespace std;

    int main()
    {
        int n, k, cnt, first = 1;
        long long area, small_area, x[51], y[51], left_m, right_m, up_m, down_m;
        cin >> n >> k;
        for (int i = 1; i <= n; ++i)
            cin >> x[i] >> y[i];

        for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
        for (int o = 1; o <= n; ++o)
        for (int l = 1; l <= n; ++l) {
            left_m = min(x[i], x[j]);
            left_m = min(left_m, x[o]);
            left_m = min(left_m, x[l]);

            right_m = max(x[i], x[j]);
            right_m = max(left_m, x[o]);
            right_m = max(left_m, x[l]);

            up_m = max(y[i], y[j]);
            up_m = max(up_m, y[o]);
            up_m = max(up_m, y[l]);

            down_m = min(y[i], y[j]);
            down_m = min(down_m, y[o]);
            down_m = min(down_m, y[l]);


            cnt = 0;
            for (int p = 1; p <= n; ++p)
                if (x[p] >= left_m && x[p] <= right_m && y[p] <= up_m && y[p] >= down_m)
                    cnt++;
            if (cnt >= k) {
                area = (right_m - left_m) * (up_m - down_m);
                if (first) {
                    small_area = area;
                    first = 0;
                }
                else
                    small_area = min(small_area, area);
            }
        }
        cout << small_area;
        return 0;
    }


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int value(char c);
int main()
{
    char X,Y;
    cin>>X>>Y;
    if (value(X)<value(Y))
        cout<<"<" ;
    else if (value(Y)<value(X))
        cout<<">" ;
    else
        cout<< "=" ;
    return 0;
}
int value(char c){
    switch (c){
    case 'A' :
       return 10 ;
       break ;
    case 'B' :
       return 11 ;
       break ;
    case 'C' :
       return 12 ;
       break ;
    case 'D' :
       return 13 ;
       break ;
    case 'E' :
       return 14 ;
       break ;
    case 'F' :
       return 15 ;
       break ;
    default :
       return 0 ;
    }
}


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

using namespace std;

int main() {
    string s;
    cin >> s;

    set<char> a;
    for (int i = 0; i < (int)s.size(); ++i) {
        a.insert(s[i]);
    }
    if ((int)a.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;
typedef long long ll;
vector<ll> vec;



int main()
{
    ll a, b;
    int n;
    cin >> n;
    ll ans = 0LL;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        ans -= b;
        vec.push_back(a + b);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    for(int i = 0; i < n; i++){
        if (i % 2 == 1){
            continue;
        } else {
            ans += vec[i];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

using namespace std;

int f(string s, char c, int ans) {
	string ss;
	bool b = false;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == c || s[i + 1] == c) {
			ss.push_back(c);
		}
		else {
			ss.push_back('A');
			b = true;
		}
	}
	if (b) {
		ans++;
		return f(ss, c, ans);
	}
	return ans + 1;
}

int main() {
	string s;
	int ans = 100;
	vector<int> b;
	b.resize(26);
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		b[s[i] - 'a']++;
	int cnt = 0;
	for (int i = 0; i < 26; i++) {
		if (b[i] == 0) {
			cnt++;
			continue;
		}
		int a = f(s, 'a' + i, 0);
		if (a < ans) {
			ans = a;
		}
	}
	if (cnt == 25) {
		cout << 0 << endl;
	}else 
		cout << ans << endl;
//	cin >> s;
	return 0;
}


Measured memory_bytes: 256
"""
 // Author : snape_here - Susanta Mukherjee
 // Date : 27/07/2019

"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()

    
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
from math import ceil,floor,log,sqrt,factorial,pow,pi
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading


# For getting input from input.txt file 
#sys.stdin = open('input.txt', 'r')  
  
# Printing the Output to output.txt file 
#sys.stdout = open('output.txt', 'w') 

def ii(): return int(input())
def fi(): return float(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())

def main():
    
    a,b=mi()
    if (a+b)%2==0:
        print((a+b)//2)
    else:
        print("IMPOSSIBLE")

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 29036
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

map< int , int > mp[nax];
int main()
{
	int n , m;
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++){
		int u , v;
		cin >> u >> v;
		mp[u][v] = 1;
		mp[v][u] = 1;
	}
	for(int i = 2 ; i <= n - 1 ; i++){
			if(mp[1][i] == 1 && mp[i][n] == 1)
			{
				cout << "POSSIBLE" << endl;
				return 0;
			}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
} 




Measured memory_bytes: 122112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 0;
        while(i++ < 1000) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;
            else if(m == -1 || f == -1) System.out.println("F");
            else if((m + f) >= 80) System.out.println("A");
            else if((m + f) >= 65) System.out.println("B");
            else if((m + f) >= 50) System.out.println("C");
            else if((m + f) >= 30) {
                if(r >= 50) System.out.println("C");
                else System.out.println("D");
            } else System.out.println("F");
        }
    }
}



Measured memory_bytes: 26372
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int T;
ll a,b;
ll cnt,ans;
int main(){
    cin>>T;
    for (int i=1;i<=T;i++){
        read(a),read(b);
        if (a>ans){
            ans=a;
            cnt=a+b;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

int top;
int a[10000];

void init() {
  top = 0;
}

bool isEmpty() {
  return top == 0;
}

bool isFull() {
  return top == 9999;
}

int pop() {
  if (isEmpty()) return -1;
  else {
    top --;
    return a[top+1];
  }
}

int push(int x) {
  if (isFull()) return -1;
  else {
    top ++;
    a[top] = x;
    return 1;
  }
}

int main() {
  char c[100];

  init();

  while (scanf("%s", &c) != EOF) {
    if (c[0] == '+') {
      int x = pop();
      int y = pop();
      push(y+x);
    } else if (c[0] == '-') {
      int x = pop();
      int y = pop();
      push(y-x);
    } else if (c[0] == '*') {
      int x = pop();
      int y = pop();
      push(y*x);
    } else {
      push(stoi(c));
    }
  }
  cout << pop() << endl;
}


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

int res[101] = {
0,
0,
0,
61,
230,
865,
3247,
12185,
45719,
171531,
643550,
2414454,
9058467,
33985227,
127504505,
478366600,
794717734,
733354121,
261943303,
776803305,
580025381,
51688048,
44657419,
737209731,
604119499,
159693437,
858533109,
639056669,
549054109,
996291083,
531294469,
23314687,
783022045,
855462856,
649970414,
68697295,
409213624,
604356692,
88638656,
978442997,
534833116,
763737161,
785892908,
123883652,
639213333,
181836645,
998121103,
124885216,
501575626,
39816123,
113468411,
799008836,
775465589,
256852905,
664630886,
971550783,
751629411,
51018086,
702530485,
725438992,
696683714,
792638194,
221791721,
149602322,
414054379,
986519078,
981760191,
305799096,
515140586,
406959393,
975058685,
245601370,
324759692,
673385295,
191483611,
570246669,
427196161,
781042769,
569725155,
842176273,
25328739,
847501730,
206282374,
353770801,
323137024,
371653459,
940737264,
123820509,
915711339,
847205021,
252858375,
718889563,
866398347,
738390145,
133009077,
333099663,
170591295,
329869205,
616680192,
597534442,
388130742
};

int main() {
    int N; cin >> N;
    cout << res[N] << endl;
}

Measured memory_bytes: 256
def euclid(a, b):
    if a < b:
        b, a = a, b
    if b == 0:
        return a

    return euclid(b, a % b)

if __name__ == "__main__":
    N = int(input())
    a_list = list(map(int, input().split()))

    l_list = [0] * (N + 1)
    r_list = [0] * (N + 1)

    for i in range(N):
        l_list[i + 1] = euclid(l_list[i], a_list[i])
    for i in reversed(range(N)):
        r_list[i] = euclid(r_list[i + 1], a_list[i])

    max_m = 0
    for i in range(N):
        m = euclid(l_list[i], r_list[i + 1])
        max_m = max(m, max_m)
    print(max_m)


Measured memory_bytes: 14428
import sys
import bisect

input = sys.stdin.readline


def main():
    N = int(input())
    C = [int(input()) for _ in range(N)]

    x = []
    for c in C:
        if x:
            if x[-1] < c:
                x.append(c)
            else:
                y = bisect.bisect_left(x, c)
                x[y] = c
        else:
            x.append(c)

    print(len(x))

if __name__ == '__main__':
    main()



Measured memory_bytes: 10356
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = 2 * sc.nextLong();
        }
        long offset = 0;
        for (int i = 0; i < n; i++) {
            offset = a[i] - offset;
        }
        long x0 = offset / 2;

        long cur = x0;
        StringJoiner sj = new StringJoiner(" ");
        for (int i = 0; i < n; i++) {
            sj.add(String.valueOf(cur));
            cur = a[i] - cur;
        }
        System.out.println(sj.toString());
    }

}


Measured memory_bytes: 61164
from heapq import*
N,M,*t=map(int,open(0).read().split())
v=[[]for _ in range(M)]
for i in range(N):
	if t[2*i]<=M:v[t[2*i]-1].append(t[2*i+1])
z=0
q=[]
for i in range(M):
	for j in v[i]:heappush(q,-j)
	z-=len(q)and heappop(q)
print(z)

Measured memory_bytes: 24932
/**
 *    Creator :  bizarre
 *    Date : 4/2020
 *    Problem Number : 494
**/
#include <bits/stdc++.h>
using namespace std;
#define bizarre  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define ll long long
#define ld long double
/*
vector<int> prime_Numbers;
int primes[1000005];
void prime(int n)
{
    primes[1]=primes[0]=0;
    for(int i=2; i<=n; i++)
        primes[i]=true;
    for(int i=2; i<=n; i++)
    {
        if(primes[i]==true)
        {
            prime_Numbers.push_back(i);
            for(int j=i+i; j<=n; j+=i)
                primes[j]=false;
        }
    }
    for(int i=2; i<=n; i++)
        primes[i]+=primes[i-1];
}
void move1step(long long& a, long long& b, long long q)
{
    long long c= a-q*b;
    a=b;
    b=c;
}
long long egcd(long long r0,long long r1,long long& x0,long long& y0)
{
    long long x1=0,y1=1;
    x0=1;
    y0=0;
    while(r1)
    {
        long long q=r0/r1;
        move1step(r0,r1,q);
        move1step(x0,x1,q);
        move1step(y0,y1,q);
    }
    return r0;
}
bool  solve (long long a, long long b, long long c,long long&x, long long& y)
{
    long long g=egcd(a,b,x,y);
    int m=c/g;
    x*=m;
    y*=m;
    return c%g==0;
}
int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
void PrimeFactorization(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        int c=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
            }

        }
    }

}
long long ncrtane(long long n, long long r)
{
    long long ans=1,cntr=1;
    for(int i=n; i>n-r; i--)
    {
        ans*=i;
        ans/=cntr;
        cntr++;
    }
    return ans;
}
const int N = 1e6 + 5, inf = 2e9, mod = 1e9 + 7;
long long fact[N], inv[N];
long long fp(long long base, long long exp)
{
    if (exp == 0)
        return 1;
    long long ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}
void pre(long long n)
{
    fact[0] = 1;
    inv[0] = 1;
    for (long long i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
int ncr(long long n, long long r)
{
    return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}

int npr(long long n, long long r)
{
    return (fact[n] * inv[n - r]) % mod;
}

*/
int main()
{
   bizarre
  ll n,k,r,s,p,ans=0;
  cin>>n>>k>>r>>s>>p;
  string t;
  cin>>t;
  for(int i=0;i<k;i++)
  {
      int l3b=k;
      while(l3b+i<n)
      {
          if(t[l3b+i]==t[(l3b+i)-k])
            t[l3b+i]='z';
          l3b+=k;
      }
  }
  for(int i=0;i<n;i++)
  {
      if(t[i]=='r')
        ans+=p;
      else if(t[i]=='s')
        ans+=r;
      else if(t[i]=='p')
        ans+=s;
      else continue;
  }
  cout << ans;
    return 0;
}


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

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

    int a[2][N];

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

    int max = 0;
    for(int i=0; i<N; ++i) {
        int sum1 = 0;
        int sum2 = 0;
        for(int j=0; j<=i; ++j) {
            sum1 += a[0][j];
        }
        for(int k=i; k<N; ++k) {
            sum2 += a[1][k];
        }
        int sum = sum1 + sum2;
        if(sum > max) {
            max = sum;
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 384
N = int(input())
A = [int(_) for _ in input().split()]
A_c = [0 for i in range(10 ** 5 + 1)]
for a in A:
  A_c[a] += 1
S = sum(A)
Q = int(input())
for i in range(Q):
  B, C = [int(_) for _ in input().split()]
  B_c = A_c[B]
  A_c[B] = 0
  A_c[C] += B_c
  S = (S - B_c * B + B_c * C)
  print(S)




Measured memory_bytes: 83684
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0

for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    ans+=bisect_left(L,a+b)-(j+1)
print(ans)


Measured memory_bytes: 9376
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

import numpy as np

if __name__ == '__main__':
    # Input
    N = int(input())
    route = np.zeros([2, N], dtype=int)

    # HACK: More smarter.
    for i in range(2):
        line = [int(i) for i in input().split(" ")]
        for j in range(N):
            route[i][j] = line[j]

    candy_count_max = 0

    # See: https://img.atcoder.jp/arc090/editorial.pdf
    # p.7
    # HACK: Not beautiful.
    for i in range(N):
        candy_count = 0

        for j in range(i + 1):
            candy_count += route[0][j]

        candy_count += route[1][i]

        for j in range(i + 1, N):
            candy_count += route[1][j]

        if candy_count > candy_count_max:
            candy_count_max = candy_count
    
    print(candy_count_max)

Measured memory_bytes: 12472
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)

// https://drken1215.hatenablog.com/entry/2019/12/14/171657

// 1 つの証言を表す構造体
using pint = pair<int,int>; // 「人」と「0 or 1」

// 入力
int N;
vector<vector<pint> > v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
    
    // i 人目の証言を検証する
    rep(i, N) {
        
        // i 人目が「不親切」だったら、証言はすべて無意味
        if ( !(bit & (1 << i)) ) continue;

        // それぞれ確認
        for (pint xy : v[i]) {
            int x = xy.first; // x が
            int y = xy.second; // y = 1: 正直、y = 0: 不親切

            // y = 1 なのに「不親切」だったらダメ
            if (y == 1 && !(bit & (1 << x))) return false;

            // y = 0 なのに「正直者」だったらダメ
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}


int main() {
    cin >> N;
    v.resize(N); // 大きさをNにする
    int A; 
    rep(i, N) {
        cin >> A;
        v[i].resize(A);
        rep(j, A) {
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }

    int res = 0;
    rep(bit, 1 << N) {
        
        // 矛盾 check
        if (judge(bit)) {
            
            // bit に含まれる人数を数える
            int count = 0;
            rep(i, N) {
                if (bit & (1 << i)) count++;
            }
            res = max(res, count);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int D = sc.nextInt();
int s = D+D+1;
int p = N % s;
int f = N - p;
if(p==0){
System.out.println(f/s);
}else{
System.out.println(f/s+1);
}
}
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    int sum=0;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        sum += s[i];
    }
    if(sum%10!=0){
        cout << sum << endl;
        return 0;
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++)
    {
        if(s[i]%10!=0){
            sum -= s[i];
            cout << sum << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long int ll;

int main() {
  int n;
  cin >> n;
  vector<int> A(n), B(n), C(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  for (int i = 0; i < n; i++) cin >> B[i];
  for (int i = 0; i < n; i++) cin >> C[i];
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());

  ll ans = 0;
  for (int i = 0; i < B.size(); i++)
    ans += (lower_bound(ALL(A), B[i]) - A.begin()) *
           (C.end() - upper_bound(ALL(C), B[i]));

  cout << ans << endl;
}


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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
int N,A,B;
int main() {
	cin>>N>>A>>B;
	int C=0;
	int R=0;
	for(int i=1;i<N+1;i++){
		if(i<10)C=i;
		if(i>9 && i<100)C=(i/10)+(i%10);
		if(i>99 && i<1000)C=(i/100)+((i%100)/10)+((i%100)%10);
		if(i>999 && i<10000)C=(i/1000)+((i%1000)/100)+((i%100)/10)+(i%10);
		if(i>9999 && i<100000)C=(i/10000)+((i%10000)/1000)+((i%1000)/100)+((i%100)/10)+(i%10);
		if(A<=C && C<=B)R+=i;
	}

	cout<<R<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

void trace(int data[], int n) {
  cout << data[0];
  for (int i = 1; i < n; i++) {
    //cout << " " << data[i];
    printf("%2d ", data[i]);
  }
  cout << endl;
}

int bsearch(int data[], int target, int left, int right) {
  // target in [left, ... ,right]
  int mid;
  while (left <= right) {
    mid = (left + right) / 2;
    if (data[mid] == target) {
      return mid;
    } else if (data[mid] < target) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  return -1;
}

int main() {
  int n;
  int data[MAX];
  int sorted[MAX];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> data[i];
    sorted[i] = data[i];
  }
  sort(sorted, sorted + n);
  int allmin = sorted[0];
  int total = 0;
  for (int i = 0; i < n; i++) {
    int ans = sorted[i];
    int x = data[i];
    if (ans == x)
      continue;

    int count = 0;
    int cyclemin = x;
    int sum = x;
    while (ans != x) {
      int j = bsearch(sorted, x, 0, n - 1);
      swap(x, data[j]);
      sum += x;
      cyclemin = min(x, cyclemin);
      count++;
    }
    data[i] = x;
    int cost1 = sum + (count - 1) * cyclemin;
    int cost2 = cost1 + 2*(cyclemin+allmin) - count*(cyclemin - allmin);
    total += min(cost1, cost2);
  }

  cout << total << endl;
}

Measured memory_bytes: 3168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>

int main (int argc, char **argv)
{
  char b = 0;
  char a = 0;

  scanf("%c", &b);

  switch(b)
  {
    case 'A': a = 'T'; break;
    case 'C': a = 'G'; break;
    case 'G': a = 'C'; break;
    case 'T': a = 'A'; break;
    defaut: break;
  }

  putchar(a);

  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define vll vector<ll>
#define nloop(i,n) for(int i=0;i<n;i++)
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define fill(i,n) memset(i,n,sizeof i)
#define all(a) a.begin(),a.end()
#define pb(x) push_back(x)
#define sz() size()
#define T(n) while(n--)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define endl '\n'
#define nfs  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll bin_expo(ll a, ll b, ll m){ll res = 1LL;while (b > 0){if(b % 2 == 1){res = (res * a) % m;}a = (a * a) % m; b = b/ 2;}return res;}

const  int MAXn= 3e5+5;
const  long long INF= 1e18;

int main(){
    int t=1;
    //cin>>t;
    T(t){
        ll a,b,c; cin>>a>>b>>c;
				ll x= min(a-b,c);
				ll ans=c-x;
				cout<<ans;
    }
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())
CA = [tuple(map(int, input().split())) for _ in range(N)]

from itertools import product

ans = -1
for bools in product((True, False), repeat=N):
  M_list = [0] * M
  t = 0
  for i in range(len(bools)):
    if bools[i]:
      for j in range(1, len(CA[i])):
        M_list[j-1] += CA[i][j]
      t += CA[i][0]
  for e in M_list:
    if e < X:
      break
  else:
    if ans < 0:
      ans = t
    else:
      ans = min(ans, t)

print(ans)


Measured memory_bytes: 9228
import java.io.FileNotFoundException;
import java.util.Scanner;

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

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long N = sc.nextInt();
    	long D = sc.nextInt();

    	int ans = 0;
    	for(int i=0;i<N;i++) {
    		long x = sc.nextInt();
    		long y = sc.nextInt();
    		if(x*x+y*y<=D*D) {
    			ans++;
    		}
    	}
    	System.out.println(ans);

    }
}

Measured memory_bytes: 59148
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll a, b, c, ans = 0;
  scanf("%lld%lld%lld", &a, &b, &c);
  for (int i = 0; i < 100; i++)
  {
    ans = a * i;
    if (ans % b == c)
    {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Hmax = 500;
int H, W;
int A[Hmax][Hmax];

int main(){
	cin >> H >> W;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			cin >> A[i][j];
		}
	}

	vector<pair<pair<int, int>, pair<int, int> > > ans;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(A[i][j]%2==0) continue;
			if(j+1<W){
				ans.push_back(make_pair(
							make_pair(i, j),
							make_pair(i, j+1)));
				A[i][j]--; A[i][j+1]++;
			} else if(i+1<H){
				ans.push_back(make_pair(
							make_pair(i, j),
							make_pair(i+1, j)));
				A[i][j]--; A[i+1][j]++;
			}
		}
	}

	cout << ans.size() << endl;
	for(auto p: ans){
		cout << p.first.first+1 << " " << p.first.second+1 << " ";
		cout << p.second.first+1 << " " << p.second.second+1 << endl;
	}

	return 0;
}


Measured memory_bytes: 5232
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< string, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int C[3][3];
bool ans = true;

int main(){
    
    REP( i, 3 ) REP( j, 3 ) cin>>C[i][j];
    
    REP( i, 2 ){
        if( C[i+1][0]-C[i][0] != C[i+1][1]-C[i][1] || C[i+1][2]-C[i][2] != C[i+1][1]-C[i][1] ) ans = false;
    }
    
    if( ans ){
        puts("Yes");
    }
    else{
        puts("No");
    }
    
    return 0;
}


Measured memory_bytes: 3128
n = int(input())
s = [input() for i in range(n)]
sdict = {}

for i in range(n):
    sortedstr = ''.join(sorted(s[i]))
    if sortedstr in sdict:
        sdict[sortedstr] = sdict[sortedstr] + 1
    else:
        sdict[sortedstr] = 1

ans = 0
for key in sdict.keys():
    cnt = sdict[key]
    ans += int(cnt * (cnt-1) / 2)
print(ans)


Measured memory_bytes: 29172
module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  (a:bc) <- sortOn Down . map read . words <$> getLine
  k <- readLn
  print $ ((2 ** k) * a) + sum bc
  where (**) a k | k < 2 = a
                 | otherwise = a * (**) a (k - 1)


Measured memory_bytes: 508
package main

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

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

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

	s := make([]string, n)
	for x := int64(0); x < n; x++ {
		s[x] = strconv.FormatInt(a[x], 10)
	}
	fmt.Println(strings.Join(s, " "))

	for i := int64(1); i < n; i++ {
		v := a[i]
		j := i - 1
		for j >= 0 && a[j] > v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v

		for x := int64(0); x < n; x++ {
			s[x] = strconv.FormatInt(a[x], 10)
		}
		fmt.Println(strings.Join(s, " "))
	}
}

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

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1260
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

string getReverse(string str);
bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	int e;
	
	while (cin >> e, e)
	{
		int res = 1e8;
		for (int i=0; i*i*i<=e; i++)
		{
			for (int j=0; j*j<=e-i*i*i; j++)
			{
				res = min(res, i + j + e-i*i*i - j*j);
			}
		}
		
		cout << res << endl;
	}
	
	return 0;
}


string getReverse(string str)
{
	string ret = "";
	for (int i=str.length()-1; i>=0; i--)
	{
		ret += str.substr(i, 1);
	}
	return ret;
}

bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

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

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

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int i, j, k;
	int N;
	scanf("%d", &N);
	int s[N][11];
	for (i = 0; i < N; i++)
		scanf("%s", s[i]);
	int M;
	scanf("%d", &M);
	int t[M][11];
	for (i = 0; i < M; i++)
		scanf("%s", t[i]);

	int max = 0, tmp = 1;
	for (i = 0; i < N; i++, tmp = 1) {
		for (j = i + 1; j < N; j++) {
			if (strcmp(s[i], s[j]) == 0)
				tmp += 1;
		}
		for (j = 0; j < M; j++) {
			if (strcmp(s[i], t[j]) == 0)
				tmp -= 1;
		}
		if (max < tmp)
			max = tmp;
	}

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

	return 0;
}


Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

CNT = [0] * 10010
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            f = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if f > N:
                continue

            CNT[f] += 1

for i in range(1, N + 1):
    print(CNT[i])


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

using namespace std;

typedef long long ll;

const int MAX_N = 401;
const ll INF = LLONG_MAX;

int N;
ll a[MAX_N], dp[MAX_N][MAX_N];

int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; ++i) {
    scanf("%lld", &a[i]);
    dp[i][i] = a[i];
    if(i) a[i] += a[i - 1];
  }

  for(int i = 1; i < N; ++i) dp[i - 1][i] = dp[i - 1][i - 1] + dp[i][i];
  for(int d = 2; d < N; ++d) {
    for(int i = 0; i + d < N; ++i) {
      int j = i + d;
      ll cost = i ? a[j] - a[i - 1] : a[j];
      ll mn = min(dp[i + 1][j], dp[i][j - 1]);
      for(int k = i + 1; k + 1 < j; ++k) {
        mn = min(mn, dp[i][k] + dp[k + 1][j]);
      }
      dp[i][j] = mn + cost;
    }
  }
  
  printf("%lld\n", dp[0][N - 1]);
  return 0;
}

Measured memory_bytes: 5084
#include <iostream>
using namespace std;
int main(void){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if((x >= r && x <= W-r) && (y >= r && y <= H-r)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3116
#include <iostream>
#include <list>
#include <algorithm>
#include <vector>
#include <memory>
#include <string>

int main()
{
    std::string s;
    std::getline(std::cin, s);

    size_t defeats = 0;
    for (char c : s) {
        if (c == 'x') {
            defeats++;
        }
    }

    if (defeats <= 7) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void) {
  int N;
  cin>> N;
  for(int i = 0; i < N ;i++){
    string S;
    cin>>S;
    if(S == "Y"){
      cout<<"Four"<<endl;
      return 0;
    }
  }
  cout<<"Three"<<endl;
  return 0;
  }


Measured memory_bytes: 3096
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=0;
    rep(i,3){
        if(s[i]=='1'){
            ans++;
        }
    }
    cout<<ans<<endl;
  
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
const long long gosentyou = 5000000000000000;

int main() {
	string s; cin >> s;
	long long k; cin >> k;
	long long i = 0;
	int ans;
	while(i<k){
		ans = s[i] - 48;
		if (ans == 1) i++;
		else break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i, tmp, x, y;
    for(i = 0;i < 3000;i ++){
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0) break;
        if(x > y){
            tmp = x;
            x = y;
            y = tmp;
        }
        printf("%d %d\n", x, y);
    }
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;
const int mod = 1e9 + 7;
vector<ll>prime(1001,1);

/*vector<ll>isprime;
void calc_prime()
{
    //cout<<"in1";
    ll i,j;
    prime[0]=prime[1]=0;
    for(i=2;i*i<=1000;i++)
    {
        if(prime[i]==1)
        {
            isprime.push_back(i);
            for(j=i*i;j<=1000;j+=i)
            {
                prime[j]=0;
            }
        }
    }
}
vector<ll>dp(100001);*/
ll maxi(ll a,ll b,ll c)
{
    ll m1=max(a,b);
    ll m2=max(a,c);
    return max(m1,m2);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int n;
    cin>>n;
    int i=1;
    if(n<1000)
    {
        cout<<1000-n;return 0;
    }
    while(i*1000<n)
    {
        i++;
    }
    cout<<i*1000-n<<endl;


}

////////////////////// bit masking ///////////
/*
ll total=long (pow(2,n));
    ll mask,j,cnt=0,ans=0,maxi,mini;
    for(mask=0;mask<total;mask++)
    {
        if(mask==0||mask==1||mask==2||mask==4||mask==8)
                continue;
        cnt=0;maxi=-1000000000000;mini=1000000000000;
        for(i=0;i<n;i++)
        {

            ll f=1<<i;
            if(mask&f)
            {
                maxi=max(maxi,a[i]);
                mini=min(mini,a[i]);
                cnt+=a[i];
            }
        }
        if(cnt>=l&&cnt<=r&&(maxi-mini>=x))
            ans++;


    }
    cout<<ans;
*/
///////////////////////////////////////////////////////


Measured memory_bytes: 3672
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        String str = sc.next();

        int[] s = new int[N+1];
        for (int i = 0; i < N; ++i) {
            if (i != N-1 && str.charAt(i) == 'A' && str.charAt(i+1) == 'C') {
                s[i+1] = s[i] + 1;
            } else {
                s[i+1] = s[i];
            }
        }

        for (int i = 0; i < Q; ++i) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            System.out.println(s[r-1] - s[l-1]);
        }
    }
}

Measured memory_bytes: 48816
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int gcd(int i, int j) {
	int num, r, shori[3];

	if (i > j) {
		shori[0] = i;
		shori[1] = j;
		shori[2] = i % j;
	}
	else {
		shori[0] = j;
		shori[1] = i;
		shori[2] = j % i;
	}
	while (shori[2]) {
		shori[0] = shori[1];
		shori[1] = shori[2];
		shori[2] = shori[0] % shori[1];
	}

	return shori[1];
}

int main() {
	int k, num = 0;

	cin >> k;

	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				num += gcd(gcd(i, j), l);
			}
		}
	}

	cout << num << endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int length = scan.nextInt();
    int[] arr = new int[length];
    fillArray(arr,scan);
    int dp[] = new int[length];
    dp[0]=0;
    dp[1]=Math.abs(arr[1]-arr[0]);
    for(int i=2; i<dp.length; i++) {
      dp[i]=Math.min(dp[i-1]+Math.abs( (arr[i]-arr[i-1]) ),dp[i-2]+Math.abs( (arr[i]-arr[i-2]) ));
    }
    System.out.println(dp[length-1]);
    scan.close();
  }
  
  public static void fillArray(int[] arr,Scanner scan) {
    for(int i=0; i<arr.length; i++) {
      arr[i]=scan.nextInt();
    }
  }
}

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


public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line;
		while ((line = br.readLine()) != null) {
			String[] params = line.split(",");
			int v1 = Integer.parseInt(params[10]), v2 = Integer.parseInt(params[11]);
			int sum = 0;
			for (int i = 0 ; i < 10 ; i++) sum += Integer.parseInt(params[i]);
			double l = v1 * (double)sum / (v1+v2);
			int dist = 0;
			for (int i = 0 ; i < 10 ; i++) {
				dist += Integer.parseInt(params[i]);
				if (dist >= l) {
					System.out.println(i+1); break;
				}
			}
		}

	}
}

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

int main() {
    string s;
    cin >> s;
    if (s.substr(0, 4) == "YAKI") {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define INF 100000
int min(int a,int b){return a<b?a:b;}
int getk(int a){
	int res=0;
	while(a>0){
		res++;
		a/=10;
	}
	return res;
}
int pow(int a,int b){
	int l;
	int rt=1;
	for(l=0;l<b;l++)rt*=10;
	return rt;
}
int card[10];
int pos[10000];
int cpos;
int main(){
	int i,j;
	int n,k;
	while(1){
	scanf("%d",&n);
	scanf("%d",&k);
	if(n==0&&k==0)return 0;
	for(i=0;i<n;i++)scanf("%d",&card[i]);
	cpos=0;
	int max=1;
	int ket;
	int next;
	int ni;
	int num;
	int ans=0;
	bool used[10];
	for(i=0;i<k;i++)max*=n;
	for(i=0;i<max;i++){
cont:		
		for(j=0;j<n;j++)used[j]=false;
		ket=1;
		ni=i;
		num=0;
		for(j=0;j<k;j++){
			next=ni%n;
			ni/=n;
			if(used[next]){
				i++;
				if(i==max)goto end;
				goto cont;
			}
			else used[next]=true;
			num+=card[next]*ket;
			ket*=pow(10,getk(card[next]));
		}
		for(j=0;j<cpos;j++){
			if(num==pos[j])break;
		}
		if(j==cpos){
			pos[cpos++]=num;
			ans++;
		}
	}
end:
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 1040
//************************
//*  Date: 2018.9.28     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(LL i=0;i<n;i++)
#define repn(i,n) for(LL i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n;
LL x[110],y[110],h[110];

int main()
{
	cin>>n;
	rep(i,n) cin>>x[i]>>y[i]>>h[i];
	rep(i,101)
	{
		rep(j,101)
		{
			LL cx=i,cy=j,hh=-1;
			bool can=true;
			rep(k,n)
			{
				if(h[k]!=0)
				{
					if(hh==-1)
					{
						hh=h[k]+abs(cx-x[k])+abs(cy-y[k]);
						continue;
					}
					LL p=h[k]+abs(cx-x[k])+abs(cy-y[k]);
					if(hh!=p) 
					{
						can=false;
						break;
					}
				}
			}
			rep(k,n)
			{
				if(h[k]==0)
				{
					LL p=max(hh-abs(cx-x[k])-abs(cy-y[k]),(LL)0);
					if(p!=0)
					{
						can=false;
						break;
					}
				}
			}
			if(can&&hh>0)
			{
				cout<<i<<' '<<j<<' '<<hh<<endl;
				rt0;
			}
		}
	}
	rt0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a,b;
  while(cin >> a >> b){
    if(a == "0" && b == "0") break;
    ll hit = 0,blow = 0;
    map<char,int> m;
    rep(i,4){
      if(a[i] == b[i]) ++hit;
      m[a[i]]++;
      m[b[i]]++;
    }
    rep(i,10){
      if(m['0'+i] > 1) ++blow;
    }
    cout << hit << " " << blow - hit<<endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
using namespace std;
int N,M,T;
vector<pair<pair<int,int>,int> >ti;
int main()
{
	scanf("%d%d%d",&N,&M,&T);
	map<int,int>A;
	for(int i=0;i<M;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(c==1)
		{
			A[b]=a;
		}
		else
		{
			int t=A[b];
			A.erase(A.find(b));
			for(map<int,int>::iterator it=A.begin();it!=A.end();it++)
			{
				int id=it->first,x=a-max(t,it->second);
				ti.push_back(make_pair(make_pair(b,id),x));
				ti.push_back(make_pair(make_pair(id,b),x));
			}
		}
	}
	for(map<int,int>::iterator it=A.begin();it!=A.end();)
	{
		int id=it->first,x=it->second;
		it++;
		for(map<int,int>::iterator itt=it;itt!=A.end();itt++)
		{
			int jd=itt->first,ttt=T-max(x,itt->second);
			ti.push_back(make_pair(make_pair(id,jd),ttt));
			ti.push_back(make_pair(make_pair(jd,id),ttt));
		}
	}
	int id=0;
	sort(ti.begin(),ti.end());
	for(int i=1;i<=N;i++)
	{
		int ans=i==1?2:1;
		int anstime=0;
		if(id==ti.size()||ti[id].first.first!=i)
		{
			printf("%d\n",ans);
			continue;
		}
		int now=ti[id].second;
		id++;
		while(id<ti.size()&&ti[id].first.first==i)
		{
			if(ti[id-1].first.second==ti[id].first.second)
			{
				now+=ti[id].second;
			}
			else
			{
				if(anstime<now)
				{
					anstime=now;
					ans=ti[id-1].first.second;
				}
				now=ti[id].second;
			}
			id++;
		}
		if(anstime<now)
		{
			anstime=now;
			ans=ti[id-1].first.second;
		}
		printf("%d\n",ans);
	}
}



Measured memory_bytes: 101316