akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
int x;
signed main() {
	cin >> x;
	cout << lcm(360, x) / x << endl;
	ggr
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC104A
{
    class ABC104A
    {
        static void Main(string[] args)
        {
            var dg = Console.ReadLine();
            var n = int.Parse(dg);

            int cnt = 0;
            for (int i = 1; i <= n; ++i)
            {
                if (count(i) == 8)
                {
                    ++cnt;
                }

            }

            Console.WriteLine(cnt);
        }

        static int count(int target)
        {
            int d = 1;
            for (int i = 1; i < target; i += 2)
            {
                if (target % i == 0)
                {
                    ++d;
                }
            }

            return d;
        }
    }
}


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

using namespace std;

int a, b, n;
long long resp = 0;

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

    cin >> n;

    while(n--)
    {
        cin >> a;
        if(a == 0)
            b = 0;

        resp += (a + b) / 2;
        b = (a + b) % 2;
    }

    cout << resp << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int N;
	cin >> N;

	vector<int> vA(N, 0);
	vector<int> vB(N, 0);
	vector<int> vC(N - 1, 0);
	rep(i, N) { int tmp = 0; cin >> tmp; vA[i] = tmp - 1; }
	rep(i, N) {int tmp = 0; cin >> tmp; vB[i] = tmp;}
	rep(i, N - 1) { int tmp = 0; cin >> tmp; vC[i] = tmp; }

	int cnt = 0;
	int prev = -2;
	for (int i = 0; i != N; ++i) {
		cnt += vB[vA[i]];
		if (prev + 1 == vA[i]) {
			cnt += vC[prev];
		}
		prev = vA[i];
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		solve(s);
		s.close();
	}

	public static void solve(Scanner sc) {
		int n = sc.nextInt();
		int[] p = new int[n];

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		int[] a = new int[n];
		int[] b = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = i * n + 1;
			b[n - i - 1] = i * n + 1;
		}

		for (int i = 0; i < n; i++) {
			a[p[i] - 1] += i;
		}

		show(a);
		show(b);
	}

	private static void show(int[] a) {
		for (int i : a) {
			System.out.print(i + " ");
		}
		System.out.println();
	}
}

Measured memory_bytes: 31060
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 2*1e5;

int A[N+5];
int B[N+5];

int main(){
    AC
    int n;
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>A[i]>>B[i];
    }

    sort(B+1, B+1+n);
    sort(A+1, A+1+n);

    if(n%2==0){
        int ma = (A[n/2]+A[n/2+1]);
        int mb = (B[n/2]+B[n/2+1]);
        cout<<(mb-ma)+1<<endl;
    }
    else{
        int ma = A[(n+1)/2];
        int mb = B[(n+1)/2];
        cout<<mb-ma+1<<endl;
    }
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll mod=1e9+7;
 
using namespace std;

int main(){
	int q=1;
	//cin>>q;
	while(q--){
		int k,a,b;
		cin>>k>>a>>b;
		int bo=0;
		for(int i=a;i<=b;i++){
			if(i%k==0){
				bo=1;
				break;
			}
		}

		if(bo)
			cout<<"OK"<<endl;
		else
			cout<<"NG"<<endl;

	}   	
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define INF 1ll << 60

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	ll sum = 0, ans = INF;
	cin >> num;
	vector<ll> d(num);
	rep(i, num) {
		cin >> d[i];
		sum += d[i];
	}
	rep(i, num - 1) {
		d[i + 1] += d[i];
		chmin(ans, abs(sum - 2 * d[i]));
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
 
int main(void)
{
  int n,i,j,k;
  int m,f,r;
 
  scanf("%d",&m);
  scanf("%d",&f);
  scanf("%d",&r);
  while (!((m==-1) && (f==-1) && (r==-1))){
    if ((m==-1) || (f==-1)){
      printf("%c\n",'F');
    }else if (m+f>=80){
      printf("%c\n",'A');
    }else if(m+f>=65){
      printf("%c\n",'B');
    }else if(m+f>=50){
      printf("%c\n",'C');
    }else if(m+f>=30){
      if (r>=50){
        printf("%c\n",'C');
      }else{
        printf("%c\n",'D');
      }
    }else{
      printf("%c\n",'F');
    }
    scanf("%d",&m);
    scanf("%d",&f);
    scanf("%d",&r);
  }
 
 
  return 0;
}


Measured memory_bytes: 2112
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long x, y;
    scan(x, y);
    if (x % y)
    {
        writeln(x * (y - 1));
    }
    else
    {
        writeln(-1);
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2688
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

//Flame of Nucleus
public class Main{

	int INF = 1<<29;
	
	public static int maxFlow(int s, int t, int[][] cap) {
		int n = cap.length, INF = Integer.MAX_VALUE;
		int res = 0;
		int[] prev = new int[n];
		boolean[] used = new boolean[n];
		Queue<Integer> q = new LinkedList<Integer>();
		for(;;){
			// use BFS to find argument-path
			Arrays.fill(used, false);
			Arrays.fill(prev, -1);
			q.clear();
			q.add(s);
			used[s] = true;
			while(!q.isEmpty()){
				int v = q.poll();
				if (v==t) break;
				for(int i=0;i<n;i++)if(!used[i] && 0<cap[v][i]){
					q.add(i);
					prev[i] = v;
					used[i] = true;
				}
			}
			if (!used[t]) return res;
			int v = t, f = INF;
			while(prev[v]!=-1){
				int p = prev[v];
				f = Math.min(f, cap[p][v]);
				v = p;
			}
			v = t;
			while(prev[v]!=-1){
				int p = prev[v];
				cap[p][v] -= f;
				cap[v][p] += f;
				v = p;
			}
			res += f;
		}
	}
	
//	int augumentPath(int v, int t, int f, int[][] cap, boolean[] used){
//		if(v==t)return f;
//		used[v] = true;
//		for(int i=0;i<cap[v].length;i++){
//			if(cap[v][i]>0 && !used[i]){
//				int d = augumentPath(i, t, Math.min(f, cap[v][i]), cap, used);
//				if(d>0){
//					cap[v][i] -= d;
//					cap[i][v] += d;
//					return d;
//				}
//			}
//		}
//		return 0;
//	}
//
//	int maxFlow(int s, int t, int[][] cap){
//		int flow = 0;
//		int n = cap.length;
//		boolean[] used = new boolean[n];
//		while(true){
//			Arrays.fill(used, false);
//			int f = augumentPath(s, t, Integer.MAX_VALUE, cap, used);
//			if(f==0)return flow;
//			flow += f;
//		}
//	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt(), m = sc.nextInt(), L = sc.nextInt();
			int[][] wf = new int[n+1][n+1];
			for(int[]a:wf)Arrays.fill(a, INF);
			for(int i=1;i<=n;i++)wf[i][i]=0;
			while(m--!=0){
				int s = sc.nextInt(), t = sc.nextInt(), c = sc.nextInt();
				wf[s][t]=wf[t][s]=c;
			}
			for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)wf[i][j]=Math.min(wf[i][j], wf[i][k]+wf[k][j]);
			int[] p = new int[n+1], k = new int[n+1];
			for(int i=1;i<=n;i++)p[i]=sc.nextInt();
			for(int i=1;i<=n;i++)k[i]=sc.nextInt();
			int[][] cap = new int[n*2+2][n*2+2];
			for(int i=1;i<=n;i++)cap[0][i]=p[i];
			for(int i=1;i<=n;i++)cap[n+i][2*n+1]=k[i];
			for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(wf[i][j]<L)cap[i][n+j]=p[i];
			System.out.println(maxFlow(0, 2*n+1, cap));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 102148
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
int main()
{
	int n;
	cin>>n;
	map<int,int>M;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		M[a]++;
	}
	map<int,int>::iterator it;
	lld sum=0;
	for(it=M.begin();it!=M.end();it++)
	{
		if(it->second < it->first)
			sum+=it->second;
		else if(it->second > it->first)
			sum+=abs(it->second - it->first);
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 4736
"""Boot-camp-for-Beginners_Easy007_B_Bingo_25-August-2020.py"""
import numpy as np
import sys

A = list(list(map(int, input().split())) for i in range(3))
N = int(input())
b = list(int(input()) for i in range(N))

MARK = []
for k in range(N):
    for i in range(3):
        for j in range(3):
            if(A[i][j] == b[k]):
                MARK.append([i-1, j-1])
# print(MARK)
count_row_m1, count_row_0, count_row_p1, count_column_m1, count_column_0, count_column_p1, count_backslash, count_slash = 0, 0, 0, 0, 0, 0, 0, 0
for k in range(len(MARK)):
    if MARK[k][0] == -1:
        count_column_m1 += 1
    elif MARK[k][0] == 0:
        count_column_0 += 1
    else:
        count_column_p1 += 1

    if MARK[k][1] == -1:
        count_row_m1 += 1
    elif MARK[k][1] == 0:
        count_row_0 += 1
    else:
        count_row_p1 += 1

    if MARK[k][0] == MARK[k][1]:
        count_backslash += 1
    if MARK[k][0] == -MARK[k][1]:
        count_slash += 1
bingo = count_row_m1 >= 3 or count_row_0 >= 3 or count_row_p1 >= 3 or count_column_m1 >= 3 or count_column_0 >= 3 or count_column_p1 >= 3 or count_backslash >= 3 or count_slash >= 3
"""
print("count_column_m1", count_column_m1)
print("count_column_0", count_column_0)
print("count_column_p1", count_column_p1)
print("count_row_m1", count_row_m1)
print("count_row_0", count_row_0)
print("count_row_p1", count_row_p1)
print("count_backslash", count_backslash)
print("count_slash", count_slash)
"""
if bingo == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27136
#! /usr/bin/env python3
import itertools
import math
N, P = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in A:
    if i % 2 : cnt += 1
_cnt = len(A) - cnt
if P == 0:
    a = 0
    for i in range(0, cnt + 1, 2):
        a += (math.factorial(cnt) // math.factorial(cnt-i)) // math.factorial(i)
    print(2 ** _cnt * a)
else:
    a = 0
    for i in range(1, cnt + 1, 2):
        a += (math.factorial(cnt) // math.factorial(cnt-i)) // math.factorial(i)
    print(2 ** _cnt * a)


Measured memory_bytes: 3064
n, m = map(int, input().split())
c=[[0 for i in range(2)] for i in range (n)]
for i in range(n):
    c[i][0],c[i][1] = map(int, input().split())
c.sort()
price=0
i=0
while(m>0):
    if(m>c[i][1]):
        price+=c[i][0]*c[i][1]
        m-=c[i][1]
    else:
        price+=c[i][0]*m
        m=0
    i+=1
print(price)

Measured memory_bytes: 21548
from math import sin, cos, pi, sqrt
a,b,d=map(float,input().split())
S = a*b*sin(d*pi/180)/2
c = sqrt(a**2+b**2-2*a*b *cos(d*pi/180))
h = 2*S/a
print(S)
print(a+b+c)
print(h)


Measured memory_bytes: 5696
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
*c, = map(int, input().split())

ans = b[a[0]-1]
for i in range(1, n):
    ans += b[a[i]-1]
    if a[i] - a[i-1] == 1:
        ans += c[a[i-1]-1]

print(ans)


Measured memory_bytes: 3060
import math
import itertools
n=int(input())
k=[[int(j)for j in input().split()]for i in[0]*n]
l=list(itertools.permutations(range(n)))
s=0
for i in l:
    p=0
    i=list(i)
    for j in range(len(i)-1):
        p+=math.sqrt((k[i[j]][0]-k[i[j+1]][0])**2+(k[i[j]][1]-k[i[j+1]][1])**2)
    s+=p
print(s/len(l))

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

int main() {
  int N;
  cin>>N;
  int P[N];
  int tmp;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    tmp--;
    P[tmp] = i;
  }
  int ans = 0;
  tmp = 1;
  for(int i=0;i<N-1;++i) {
    if(P[i]<P[i+1]) tmp++;
    else {
      ans = max(ans, tmp);
      tmp = 1;
    }
  }
  ans = max(ans, tmp);
  cout<<N-ans<<endl;
}



Measured memory_bytes: 4360
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[200001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  int m1 = 0;
  int m2 = 0;
  REP(i, n) {
    cin >> a[i];

    if(m1 <= a[i]) {
      m2 = m1;
      m1 = a[i];
    } else if(m2 < a[i]) {
      m2 = a[i];
    }
  }

  REP(i, n) {
    if(a[i] == m1) cout << m2 << endl;
    else cout << m1 << endl;
  }
}


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

int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<N;i++){
    int v=A[i];
    int j=i-1;
    for(;j>=0 && A[j]>v;j--){
      A[j+1]=A[j];
    }
    A[j+1]=v;
    for(int a=0;a<N;a++){
      cout << A[a];
      if(a!=N-1)cout<<' ';
    }
    cout << endl;
  }
}
    


Measured memory_bytes: 3076
program turtle
  implicit none
  integer :: x, y, i
  read(*,*) x, y
  do i = 0, x
     if ( y == 2*i + 4*(x-i) ) then
        write(*,*) 'Yes'
        stop
     end if
  end do
  write(*,*) 'No'
  stop
end program turtle


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

#define SAFE_DELETE( x ){ if( x ){ delete x; x = NULL; } }

struct tCell{
	tCell() : value( 0 ), weight( 0 ), unitV( 0.0 ), prev( NULL ), next( NULL ){}

	int value, weight;
	double unitV;
	tCell *prev, *next;
};

class MyArray{
public:
	MyArray() : mSize( 0 ), head( NULL ), tail( NULL ){
		head = new tCell;
		tail = new tCell;
		head->next = tail;
		tail->prev = head;
	}
	~MyArray(){
		init();
		SAFE_DELETE( tail );
		SAFE_DELETE( head );
	}

	void init(){
		for ( int i = mSize; i > 0; --i ){
			tCell* cell = tail->prev;
			cell->prev->next = cell->next;
			cell->next->prev = cell->prev;
			SAFE_DELETE( cell );
		}
		mSize = 0;
	}
	void pushBack( int value, int weight ){
		++mSize;
		tCell* cell = new tCell;
		cell->value = value;
		cell->weight = weight;
		cell->unitV = static_cast< double >( value ) / weight;
		cell->prev = tail->prev;
		cell->next = tail;
		cell->prev->next = cell;
		cell->next->prev = cell;
	}
	int size(){ return mSize; }

	tCell operator[]( int index ){
		tCell* cell = head->next;
		for ( int i = 0; i < index; ++i ){
			cell = cell->next;
		}
		return *cell;
	}

private:
	int mSize;
	tCell *head, *tail;
};

int main(){

	MyArray treList;
	int time = 1, c;
	int v = 0, w = 0;
	char d;

	while ( cin >> c ){
		if ( !c ) break;
		int n;
		treList.init();
		cin >> n;
		for ( int i = 0; i < n; ++i ){
			cin >> v >> d >> w;
			treList.pushBack( v, w );
		}

		int maxV = 0, maxW = 0;
		int* table = new int[ ( n+1 ) * ( c+1 ) ];
		for ( int i = 0; i < n+1; ++i ){
			if ( i != 0 ){
			v = treList[ i - 1 ].value;
			w = treList[ i - 1 ].weight;
			}
			for ( int j = 0; j < c+1; ++j ){
				if ( i == 0 || j == 0 ){
					table[ i * ( c+1 ) + j ] = 0;
					continue;
				}
				table[ i * ( c+1 ) + j ] = table[ ( i-1 ) * ( c+1 ) + j ];
				if ( ( j - w >= 0 ) && ( table[ ( i-1 ) * ( c+1 ) + ( j-w ) ] + v > table[ ( i-1 ) * ( c+1 ) + j ] ) ){
					table[ i * ( c+1 ) + j ] = table[ ( i-1 ) * ( c+1 ) + ( j-w ) ] + v;
					if ( table[ i * ( c+1 ) + j ] > maxV ){
						maxV = table[ i * ( c+1 ) + j ];
						maxW = j;
					}else if ( table[ i * ( c+1 ) + j ] == maxV && j < maxW ){
						maxW = j;
					}
				}
			}
		}

		cout << "Case " << time << ":" << endl;
		cout << maxV << endl << maxW << endl;
		++time;

		delete[] table;
	}

	return 0;
}

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

int sum(int,int);

int main(){

    int n,l;
    cin>>n>>l;

    int wa=sum(l,l+n-1);

    if(l+n-1<0) cout<<wa-(l+n-1)<<endl;
    else if(l>0) cout<<wa-l<<endl;
    else cout<<wa<<endl;


    return 0;
}

int sum(int x,int y){

    return (y-x+1)*(x+y)/2;
}

Measured memory_bytes: 256
//shadowlink0122さん解法
//1e+9+7を9e10+7に修正
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
// typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 9e15+7;
ll n,m,l;
string s,t;
ull d[100010],dp[100][100];
ull x[100010],y[100010];

struct edge{ull to,cost;};
typedef pair<ull,ull> P;
vector<edge> g[100010];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d,d+n,INF);
  d[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top();que.pop();
    ull v = p.second;
    if(d[v] < p.first)continue;
    rep(i,0,g[v].sz){
      edge e = g[v][i];
      if(d[e.to] > d[v]+e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){
  cin >> n;
  rep(i,1,n){
    ull a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    g[a].pb((edge){b,c});
    g[b].pb((edge){a,c});
  }
  cin >> m >> l;
  rep(i,0,m)cin >> x[i] >> y[i];
  dijkstra(l-1);
  rep(i,0,m){
    print(d[x[i]-1]+d[y[i]-1]);
  }
  return 0;
}


Measured memory_bytes: 12784
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            cout<<i<<" ";
        }
    }
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;
    
    if(n%2==0 or n%3==0) return false;
    
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        ll q = a / m; 
        ll t = m; 
  
        m = a % m; a = t; 
        t = y; 
  
        y = x - q * y; 
        x = t; 
    } 
  
    if (x < 0) 
       x += m0; 
  
    return x; 
} 

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

ll power(ll A, ll B) 
{ 
    if (A == 0) 
        return 0; 
    if (B == 0) 
        return 1; 
  
    ll y; 
    if (B % 2 == 0) { 
        y = power(A, B / 2); 
        y = (y * y) % mod; 
    } 
  
    else { 
        y = A % mod; 
        y = (y * power(A, B - 1) % mod) % mod; 
    } 
  
    return (ll)((y + mod) % mod); 
} 

int main() 
{
    ios_base::sync_with_stdio(false);
    map<char,char>m;
    m['C']='G';
    m['G']='C';
    m['A']='T';
    m['T']='A';
    char s;
    cin>>s;
    cout<<m[s];
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)



def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
	def __init__(self, orig, func, unit):
		_len = len(orig)
		self.func = func
		self.size = 1 << (_len - 1).bit_length()
		self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
		self.unit = unit

		for i in range(self.size - 1, 0, -1):
			self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])

	def update(self, i, v):
		i += self.size
		self.tree[i] = v
		while i:
			i //= 2
			self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

	def find(self, l, r):
		l += self.size
		r += self.size
		ret = self.unit
		while l < r:
			if l & 1:
				ret = self.func(ret, self.tree[l])
				l += 1
			if r & 1:
				r -= 1
				ret = self.func(ret, self.tree[r])
			l //= 2
			r //= 2
		return ret

@mt
def slv(N, S, Q):
    st = SegmentTree([1 << (ord(c) - ord('a')) for c in S], or_, 0)

    for q in Q:
        if q[0] == '1':
            i = int(q[1]) - 1
            c = q[2]
            st.update(i, 1 << (ord(c) - ord('a')))
        if q[0] == '2':
            i = int(q[1]) - 1
            j = int(q[2]) - 1
            ans = 0
            v = st.find(i, j+1)
            for k in range(26):
                if (1 << k) & v:
                    ans += 1
            print(ans)
    # return ans


def main():
    N = read_int()
    S = read_str()
    Q = [read_str_n() for _ in range(read_int())]
    (slv(N, S, Q))

if __name__ == '__main__':
    main()


Measured memory_bytes: 55668
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  vector<vector<int>> a(H, vector<int>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> a[i][j];
    }
  }

  int ans = 0;
  vector<string> yx;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(a[i][j]%2 == 0) continue;
      
      if(j!= W-1){
        a[i][j]--;
        a[i][j+1]++;
        string s = to_string(i+1) + " " + to_string(j+1) + " " + to_string(i+1) + " " + to_string(j+2);
        yx.push_back(s);
        ans++;
        continue;
      }

      if(i != H-1){
        a[i][j]--;
        a[i+1][j]++;
        string s = to_string(i+1) + " " + to_string(j+1) + " " + to_string(i+2) + " " + to_string(j+1);
        yx.push_back(s);
        ans++;
        continue;
      } else {
        continue;
      }
    }
  }


  cout << ans << endl;
  for(int i = 0; i < ans; i++) cout << yx[i] << endl;

  return 0;
}


Measured memory_bytes: 11892
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,d,a;
    cin>>n>>k;
    std::deque<int> deq(n,0);
    for (int i=0;i<k;i++) {
        cin>>d;
        for (int j=0;j<d;j++) {
            cin>>a;
            deq[a-1]++;
        }
    }
    int count=0;
    for (int k=0;k<n;k++) {
        if (deq[k]==0) {
            count++;
        }
    }
    cout<<count<<endl;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
char s[125252][12];

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%s",s[i]);
    map<string,int> M;
    REP(i,n){
        string ss(s[i]);
        sort(ALL(ss));
        M[ss]++;
    }
    ll ans = 0;
    for(auto P : M){
        ans += (ll)P.second * (P.second - 1) / 2;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 12416
N = [int(i) for i in input().split()][0]
An = [int(i) for i in input().split()]

counts = [0 for _ in range(N)]
for a in An:
  counts[a-1] += 1
  
total = 0
for c in counts:
  if c >= 2:
    total += c * (c - 1) // 2

for a in An:
  c = counts[a-1]
  if c >= 2:
    minus = c * (c-1)//2  - (c-1)*(c-2)//2
  else:
    minus = 0
  print(total - minus)

  



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

int main() {
  int N;
  cin >> N;
  int thousand = N / 1000;
  N = N % 1000;
  int hundred = N / 100;
  N = N % 100;
  int ten = N / 10;
  int one = N;
  
  if (hundred != ten){
    cout << "No" << endl;
  }
  else if (thousand == hundred || one == hundred){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
    ll n;
    std::cin >> n;
    string s;
    std::cin >> s;
    ll q;
    std::cin >> q;
    
    vector<ll> dp(n+1,0);
    vector<ll> cc(n+1,0),cm(n+1,0);
    vector<ll> dd;
    ll mc = 0;
    for (int i = 0; i < n; i++) {
        cc[i+1] = cc[i];
        cm[i+1] = cm[i];
        dp[i+1] = dp[i];
        if(s[i]=='C'){
            cc[i+1]++;
            dp[i+1]+=mc;
        }else if(s[i]=='M'){
            cm[i+1]++;
            mc++;
        }else if(s[i]=='D'){
            dd.push_back(i);
        }
    }

    for (int iiii = 0; iiii < q; iiii++) {
        ll k;
        std::cin >> k;
        
        ll ans = 0;
        
        for (auto e : dd) {
            ans += dp[min(n,e+k)]-dp[e+1]-cm[e+1]*(cc[min(n,e+k)]-cc[e+1]);
        }
        std::cout << ans << std::endl;
    }
}



Measured memory_bytes: 35320
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA(My_College_Sucks)
*/
#include <bits/stdc++.h>
using namespace std;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define nl printf("\n")
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005

#define bs binary_search
#define lb lower_bound
#define ub upper_bound

lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;
    lli n;
    cin>>n;
    lli mini=inf,maxi=-inf;
    while(n--)
    {
        lli a;
        cin>>a;
        maxi=max(maxi,a);
        mini=min(mini,a);
    }
    cout<<maxi-mini;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();

    let mut a: Vec<i32> = buf.split_whitespace()
        .map(|v| v.parse().unwrap())
        .collect();
    a.sort();
    let s = a.iter()
        .map(|v| v.to_string())
        .collect::<Vec<String>>()
        .join(" ");

    println!("{}", s);
}



Measured memory_bytes: 5040
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
#define x1 _____x1
#define x2 _____x2
#define y1 _____y1
#define y2 _____y2
Int n;

class Compressor{
public:
  vector<Int> dict;
  Compressor(){}
  void add(Int x){
    dict.push_back(x);
  }
  void compress(){
    sort(dict.begin(), dict.end());
    dict.erase(unique(dict.begin(), dict.end()), dict.end());
  }
  int convert(Int x){
    return lower_bound(dict.begin(), dict.end(), x) - dict.begin();
  }
  Int& operator[](int index)
  {
    return dict[index];
  }
};

void add(vector<int> &bit, int ind, int val){
  ind++;
  while(ind < bit.size()){
    bit[ind] += val;
    ind += ind & -ind;
  }
}

Int sum(vector<int> &bit, int ind){
  ind++;
  Int res = 0;
  while(ind){
    res += bit[ind];
    ind -= ind & -ind;
  }
  return res;
}

Compressor comp;
vector<P> cnt[324000], query[324000];
Int x1[108000], x2[108000], y1[108000], y2[108000];
int main(){
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    comp.add(x1[i]);
    comp.add(y1[i]);
    comp.add(x2[i]);
    comp.add(y2[i]);
  }
  comp.add(-INF);
  comp.compress();
  for(int i = 0;i < n;i++){
    x1[i] = comp.convert(x1[i]);
    x2[i] = comp.convert(x2[i]);
    y1[i] = comp.convert(y1[i]);
    y2[i] = comp.convert(y2[i]);
    if(x1[i] == x2[i]){
      if(y1[i] > y2[i])swap(y1[i], y2[i]);
      query[y1[i]].push_back(P(x1[i], 1));
      query[y2[i]].push_back(P(x1[i], -1));
    }
    if(y1[i] == y2[i]){
      if(x1[i] > x2[i])swap(x1[i], x2[i]);
      cnt[y1[i]].push_back(P(x1[i], x2[i]));
    }
  }
  vector<int> bit(n*3, 0);
  Int res = 0;
  for(int i = 0;i < n*3;i++){
    for(auto q:query[i]){
      if(q.second == 1)add(bit, q.first, 1);
    }
    for(auto q:cnt[i]){
      res += sum(bit, q.second) - sum(bit, q.first - 1);
    }
    for(auto q:query[i]){
      if(q.second == -1)add(bit, q.first, -1);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 29624
/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    int a , b ;
    cin >> a >> b;
    if(a >= 13)cout << b;
    else if(a >= 6)cout << b/2 ;
    else cout << 0 ;




























return 0 ;
}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(), (x).end()
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using P = pair<ll, ll>;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, p, q; cin >> n >> p >> q;
    vll c(n); rep(i, c.size()) cin >> c[i];

    vll a(n); rep(i, a.size()) a[i] = c[i] + p * i;
    sort(all(a));

    vll sa(n+1); rep(i, n) sa[i+1] = sa[i] + a[i]; 

    ll sumr = accumulate(all(c), 0ll), ret = sumr;
    rep (k, n+1) 
        chmax(ret, sumr + p * k * (q + k - 1) - sa[k]);

    cout << ret << endl;

    return 0;
}

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

#define F first
#define S second

using ll = long long;
using pii = pair <int, int>;

const int oo = 1e9 + 4;
const int SZ = 2e5 + 4;

int n;
string s;

void read() {
    cin >> s;
    n = s.size();
}

bool pal(int l, int r) {
    l--; r--;
    while (l < r) {
        if (s[l] != s[r]) return 0;
        l++; r--;
    }
    return 1;
}

void solve() {
    cout << (pal(1, n) && pal(1, (n - 1) / 2) && pal((n + 3) / 2, n) ? "Yes" : "No");
}

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

    read();
    solve();
}


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

constexpr long long modulo = 1000000007;

long long mod_pow( const long long& x, const int& m ){
    if(m==0) return 1;
    if(m==1) return x;
    if(m%2==0){
        return mod_pow( (x*x)%modulo, m/2 ); 
    }else{
        return  (x * mod_pow( (x*x)%modulo, m/2 )) % modulo; 
    } 
}

long long gcd_mult_x( const int& x, const int& n, const int& k ){
    long long tmp(1);
    int d(k/x);
    return mod_pow(d,n);
}

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

    long long ans(0);
    vector<long long> num_gcd(K+1,0);
    
    long long tmp;
    for(int i=K;i>0;--i){
        tmp = gcd_mult_x(i, N, K);
        for(int m=2;i*m<=K;++m){
            tmp -= num_gcd[i*m];
            tmp += modulo;
            tmp %= modulo;
        }
        num_gcd[i] = tmp;
        ans += tmp * i;
        ans %= modulo;
    }

    // for(int i=0;i<=K;++i){
    //     printf("gcd[%d] = %lld\n", i, num_gcd[i]);
    // }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,k;
  cin >> n >> k;
  set<int>st;
  rep(i,k){
    int d;
    cin >> d;
    st.insert(d);
  }
  for(int i=n;i<100000;i++){
    string s = to_string(i);
    bool ok = true;
    rep(j,s.size()){
      if(st.count(s[j]-'0')) ok = false;
    }
    if(ok){
      cout <<i << endl;
      return 0;
    }
  }
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N)
{
    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if (to_string(i).size() % 2 != 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 384
#include <string>
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;

void b_distance(void) {
    int n, d;
    int* x;
    int* y;
    cin >> n >> d;
    x = (int*)calloc(n, sizeof(int));
    y = (int*)calloc(n, sizeof(int));
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    };

    int cnt = 0;
    long long dis_pow = (long long)pow(d, 2.0);
    //cout << dis_pow << endl;
    for (int i = 0; i < n; i++) {
        long long r = (long long)pow(x[i], 2.0) + (long long)pow(y[i], 2.0);
        //cout << r << endl;
        if (r <= dis_pow)cnt++;
    }

    cout << cnt << endl;

    free(x);
    free(y);
}

int main()
{
    b_distance();

    return 0;
}


Measured memory_bytes: 4792
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){
	
	fastio;
	int a,b;
	cin >> a >> b;
	for(int i = max(1000*a,800*b); i < min(1000*(a+1),800*(b+1)); ++i){
		if(i % 80 == 0){
			cout << i/80 << endl;
			exit(0);
		}
	}

	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
/*
 * ALDS1_8_B.cpp
 *
 *  Created on: May 3, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cstdlib>

struct Node {
	int key;
	Node *pa, *lc, *rc;
};

Node* root = NULL;

void insert(int k) {
	Node* y = NULL;
	Node* x = root;
	Node* z = new Node;
	while(x != NULL) {
		y = x;
		if(k < y->key) x = y->lc;
		else x = y->rc;
	}
	z->pa = y;
	z->lc = NULL;
	z->rc = NULL;
	z->key = k;
	if(y == NULL) {
		root = z;
	}
	else if(k < y->key) {
		y->lc = z;
	}
	else {
		y->rc = z;
	}
}

void preorder(Node* u) {
	if(u == NULL) return;
	printf(" %d", u->key);
	preorder(u->lc);
	preorder(u->rc);
}

void inorder(Node* u) {
	if(u == NULL) return;
	inorder(u->lc);
	printf(" %d", u->key);
	inorder(u->rc);
}

void print() {
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
}

void find(int k) {
	Node* x = root;
	while(x != NULL) {
		if(x->key == k) {
			printf("yes\n");
			return;
		}
		if(k < x->key) x = x->lc;
		else x = x->rc;
	}
	printf("no\n");
}

int main() {
	int m;
	scanf("%d", &m);
	char s[100];
	int ke;
	for(int i=0; i<m; i++) {
		scanf("%s", s);
		if(s[0] == 'i') {
			scanf("%d", &ke);
			insert(ke);
		}
		else if(s[0] == 'f') {
			scanf("%d", &ke);
			find(ke);
		}
		else {
			print();
		}
	}
}






Measured memory_bytes: 21460
n, k = map(int, input().split())
d_k = set(map(int, input().split()))
ans = n
while ans <= n * 10:
    isOK = True
    for x in range(len(str(ans))):
        if int(str(ans)[x]) in d_k: 
            isOK = False
            break
    if isOK == True: break
    ans += 1
print(ans)

Measured memory_bytes: 3060