akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict as de
X=de(int)
n=int(input())
a=sorted([list(map(int,input().split()))for i in range(n)])
for i in range(n):
    for j in range(i):
        X[(a[i][0]-a[j][0],a[i][1]-a[j][1])]+=1
print(n-max(X.values(),default=0))

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  if (n==100000)cout <<90909<<endl;
  else if(n>=10000)cout <<n-9999+900+9<<endl;
  else if (n>=1000)cout <<909<<endl;
  else if(n>=100)cout <<n-99+9<<endl;
  else if(n>=10)cout << 9 <<endl;
  else cout << n <<endl;
}

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

int main() {
  string X; cin >> X;
  stack<char> s;
  for (int i = 0; i < X.size(); i++) {
    if (X.at(i) == 'S') s.push('S');
    else {
      if (s.empty() || s.top() == 'T') s.push('T');
      else s.pop();
    }
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int N,M,Q;
    static int[] a, b, c, d;
    static int score;
    static void INPUT()
    {
        N = NextInt();
        M = NextInt();
        Q = NextInt();
        a = new int[Q];
        b = new int[Q];
        c = new int[Q];
        d = new int[Q];
        for (var i = 0; i < Q; i++)
        {
            a[i] = NextInt();
            b[i] = NextInt();
            c[i] = NextInt();
            d[i] = NextInt();
        }
    }

    static void dfs(List<int> list)
    {
        if (list.Count == N + 1)
        {
            var s = 0;
            for (var i = 0; i < Q; i++)
            {
                if (list[b[i]] - list[a[i]] == c[i]) s += d[i];
            }

            score = Math.Max(score, s);
            return;
        }

        var ad = list.Last();
        while (ad <= M)
        {
            var t = new List<int>(list);
            t.Add(ad);
            dfs(t);
            ad++;
        }
    }
    static void OUT()
    {
        var l = new List<int>();
        l.Add(1);
        dfs(l);

        Console.WriteLine(score);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 22980
def main():
    s = list(input())
    last = ''
    count = 0
    for i, day in enumerate(s):
        if day == 'S':
            last = day
            continue
        if i == 0:
            count += 1
        elif last == 'R':
            count += 1
        elif last == 'S':
            count = 1
        last = day

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61696
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

int main(){
  int n;
  cin>>n;
  long long a=0,b=0,aans=90000000000;
  long long num[n];
  for(int i=0;i<n;i++){
    cin>>num[i];
    a+=num[i];
  }
  long long ans[n-1];
  //差 後で絶対値にする//
  for(int i=0;i<n-1;i++){
    if(i>0){
    ans[i]=ans[i-1]-2*num[i];
    }
    if(i==0){
    ans[i]=a-2*num[i];
    }
    aans=min(aans,abs(ans[i]));
  }
  cout<<aans<<endl;
}


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


int main()
{
    int X;
    cin >> X;
    int ans = 0;
    ans += (X / 500) * 1000;
    X %= 500;
    ans += (X / 5) * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <functional>

using namespace std;

void topological_sort(vector<vector<int>> G, vector<int>& ans) {
    vector<bool> seen(G.size());

    function<void(int)> visit;
    visit = [&](auto key) {
        if (seen[key])
            return;
        seen[key] = true;
        for (auto x : G[key]) {
            if (seen[x]) {
                continue;
            }
            visit(x);
        }
        ans.push_back(key);
    };

    for (int i = 0; i < G.size(); ++i) {
        visit(i);
    }
}

int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> G(V);
    for (int i = 0; i < E; ++i) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
    }

    vector<int> ans;
    topological_sort(G, ans);
    for (auto it = ans.rbegin(); it != ans.rend(); ++it) {
        cout << *it << endl;
    }

    return 0;
}

Measured memory_bytes: 4036
// Created by sz
#include <bits/stdc++.h>
using namespace std;

int N;
string A, B, C;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin>>N>>A>>B>>C;
    
    int ans = 0;
    for(int i = 0; i<N; i++){
        set<char> s;
        s.insert(A[i]);
        s.insert(B[i]);
        s.insert(C[i]);
        ans += s.size() -1;
    }
    
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;

int main() {
	int n, d;
	cin >> n >> d;
	if(n % (2 * d + 1)==0)cout << n/ (2 * d + 1) << endl;
	else cout << n / (2 * d + 1) +1<< endl;
}



Measured memory_bytes: 3608
N,K = gets.split.map(&:to_i)
D = gets.strip.split.map(&:to_i)
n = N 
a = 0
while a == 0
    if n.to_s.split('').map{|s| s.to_i}.none?{|x| D.any?{|y| y == x}}
        a += 1
    end
    n += 1
end

puts n-1

Measured memory_bytes: 2044
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BProductMax solver = new BProductMax();
        solver.solve(1, in, out);
        out.close();
    }

    static class BProductMax {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();

            long max1 = Math.max(a, b);
            long max2 = Math.max(c, d);
            long min1 = Math.min(a, b);
            long min2 = Math.min(c, d);

            out.println(Math.max(Math.max(Math.max(max1 * max2, max1 * min2), max2 * min1), min1 * min2));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32536
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i] == l[j] or l[i] == l[k] or l[j]==l[k]:
                continue
            if l[i]+l[j] > l[k] and abs(l[i]-l[j]) < l[k]:
                if l[i]+l[k] > l[j] and abs(l[i]-l[k]) < l[j]:
                    if l[j]+l[k] > l[i] and abs(l[j]-l[k]) < l[i]:
                        cnt+=1
                    
print(cnt)

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


int main(){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i=0;i<n;i++) cin >> a[i];
    ll u=a[0],d=a[0];
    ll res=1000;
    for(ll i=0;i<n;i++){
        if(a[i]>=u) u=a[i];
        else if(a[i]<u){
            res=res+(res/d)*(u-d);
            u=a[i];
            d=a[i];
        }
    }
    res=res+(res/d)*(u-d);
    cout << res << endl;
}


Measured memory_bytes: 3632
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn solve(n: usize, k: usize) -> usize {
    let mut m = 1;

    let mut ans = 0;
    while m * m <= n {
        if n % m == 0 {
            // m
            let a = m;
            let b = n/m;

            if a >= k {
                ans = max(ans, b);
            }
            if b >= k {
                ans = max(ans, a);
            }


            // n/m
        }
        m += 1;
    }
    ans
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
    }

    let ans = solve(m, n);
    puts!("{}\n", ans);

}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
  int n,a,b;
  if(scanf("%d",&n)==1);
  if(scanf("%d",&a)==1);
  if(scanf("%d",&b)==1);
 
  int sum=0;
  int i,j;
  int tmp;
  int tmpsum;
  int ntmp;
  for(i=1;i<=n;i++){
    tmp = 0;
    tmpsum = 0;
    ntmp = i;
    for(j=1;j<=5;j++){
      tmp = ntmp%10;
      ntmp = ntmp/10;
      tmpsum = tmpsum + tmp;
    }
    if(a<=tmpsum && tmpsum<=b)sum+=i;
  }
  printf("%d",sum);
  return 0;
}
      


Measured memory_bytes: 128
from collections import deque
S = input()
Q = int(input())

st = True
deq = deque(S)
for _ in range(Q):
    Query = input().split()
    if Query[0] == '1':
        st = not st
    else:
        if (Query[1] == '1') ^ st:
            deq.append(Query[2])
        else:
            deq.appendleft(Query[2])
if st:
    print(''.join(deq))
else:
    print(''.join(reversed(deq)))

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n, a;
  cin >> n >> a;
  cout << (n % 500 <= a ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {

	ll n, m;
	scanf("%lld%lld", &n, &m);
	if (m < 2*n){
		return cout << m/(2) , 0;
	}
	ll ans = n;
	m -= 2 * n;
	ans += m / 4;
	cout << ans;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int X, Y;

void _main() {
    cin >> X >> Y;
    int sum = 0;
    if (X == 1) sum += 300000;
    if (X == 2) sum += 200000;
    if (X == 3) sum += 100000;
    if (Y == 1) sum += 300000;
    if (Y == 2) sum += 200000;
    if (Y == 3) sum += 100000;
    if (X == 1 && Y == 1) sum += 400000;
    cout << sum << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
let m = 1039999
let t = Array.make m "\000"

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let to_x = Array.make 128 0

let to_key s =
  let ret = ref 0 in
  let p = ref 1 in
  for i = 0 to String.length s - 1 do
    ret := !ret + !p * (to_x.(Char.code s.[i]));
    p := 5 * !p;
  done;
  !ret

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if find s then "yes" else "no")
    | [_; s] -> insert s
    | _ -> assert false
  done

Measured memory_bytes: 20704
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {

        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        while (true)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (nm[0] == 0) break;
            var a = Enumerable.Repeat(0, nm[0]).Select(_ => int.Parse(Console.ReadLine())).ToArray();
            var b = Enumerable.Repeat(0, nm[1]).Select(_ => int.Parse(Console.ReadLine())).ToArray();
            var asum = a.Sum();
            var bsum = b.Sum();
            int min = int.MaxValue;
            var resA = 0;
            var resB = 0;
            for (int i = 0; i < a.Length; i++)
            {
                for (int j = 0; j < b.Length; j++)
                {
                    if ((asum - a[i] + b[j]) == (bsum - b[j] + a[i]))
                    {
                        var sum = a[i] + b[j];
                        if (sum < min)
                        {
                            min = sum;
                            resA = a[i];
                            resB = b[j];
                        }
                    }
                }
            }
            Console.WriteLine(min == int.MaxValue ? "-1" : $"{resA} {resB}");
        }
        Console.Out.Flush();
    }
}


Measured memory_bytes: 18404
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int main(void){
    int n;
    scanf("%d",&n);
    if(n%2==0)printf("%d\n",n);
    else printf("%d\n",2*n);
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int c[510], s[510], f[510];
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	long long ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ans += s[i] + c[i];
		for (int j = i + 1; j < n - 1; j++) {
			if (ans < s[j]) {
				ans = s[j];
			}
			else if (ans > s[j]) {
				if (ans % f[j] != 0) {
					ans += f[j] - ans % f[j];
				}
			}
			ans += c[j];
		}
		cout << ans << endl;
		ans = 0;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define MAX_V 500
#define INF (1<<29)
  
struct edge{ int to,cap,rev; };
  
vector<edge> G[MAX_V];
bool used[MAX_V];
  
void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,G[to].size()});
    G[to].push_back((edge){from,0,G[from].size()-1});
}
  
int dfs(int v,int t,int f){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0 ; i < (int)G[v].size() ; i++){
	edge &e = G[v][i];
	if(!used[e.to] && e.cap > 0){
	    int d = dfs(e.to,t,min(f,e.cap));
	    if(d > 0){
		e.cap -= d;
		G[e.to][e.rev].cap += d;
		return d;
	    }
	}
    }
    return 0;
}
  
int max_flow(int s,int t){
    int flow = 0;
    for(;;){
	memset(used,0,sizeof(used));
	int f = dfs(s,t,INF);
	if(f == 0) return flow;
	flow += f;
    }
}
  
void init(){
    for(int i = 0 ; i < MAX_V ; i++){
	G[i].clear();
    }
}
  
int main(){
    int H,W,C,M,Nw,Nc,Nm;
    while(cin >> H >> W >> C >> M >> Nw >> Nc >> Nm, H != -1){
	int k,a;
	init();
	for(int i = 0 ; i < W ; i++){
	    cin >> k;
	    while(k--){
		cin >> a; a--;
		add_edge(a,H+i,1);
	    }
	}
	for(int i = 0 ; i < W ; i++){
	    add_edge(H+i,H+W+i,1);
	}
     
	for(int i = 0 ; i < C ; i++){
	    cin >> k;
	    while(k--){
		cin >> a; a--;
		add_edge(H+W+a,H+W*2+i,1);
	    }
	}
	for(int i = 0 ; i < C ; i++){
	    add_edge(H+W*2+i,H+W*2+C+i,1);
	}
 
	for(int i = 0 ; i < M ; i++){
	    cin >> k;
	    while(k--){
		cin >> a; a--;
		add_edge(H+W*2+C+a,H+W*2+C*2+i,1);
	    }
	}
     
	int S = H+W*2+C*2+M,T = S+1;
	for(int i = 0 ; i < H ; i++){
	    add_edge(S,i,1);
	}
	for(int i = 0 ; i < M ; i++){
	    add_edge(H+W*2+C*2+i,T,1);
	}
 
	int Wnot = T+1,Wnot2 = Wnot+1;
	for(int i = 0 ; i < H ; i++){
	    add_edge(i,Wnot,1);
	}
	add_edge(Wnot,Wnot2,Nw);
	for(int i = 0 ; i < C ; i++){
	    add_edge(Wnot2,H+W*2+i,1);
	}
 
	int Cnot = Wnot2+1,Cnot2 = Cnot+1;
	for(int i = 0 ; i < W ; i++){
	    add_edge(H+W+i,Cnot,1);
	}
	add_edge(Cnot,Cnot2,Nc);
	for(int i = 0 ; i < M ; i++){
	    add_edge(Cnot2,H+W*2+C*2+i,1);
	}
 
	int Mnot = Cnot2+1;
	for(int i = 0 ; i < C ; i++){
	    add_edge(H+W*2+C+i,Mnot,1);
	}
	add_edge(Mnot,T,Nm);
	cout << max_flow(S,T) << endl;
    }
    return 0;
}

Measured memory_bytes: 1460
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 5999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

bool s[300000];
int main() {
	int n, m;
	bool ans = false;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		if (a == 1) {
			if (s[b])ans = true;
			else s[b] = true;
		}
		if (b == n) {
			if (s[a])ans = true;
			else s[a] = true;
		}
	}
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

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

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

    int now = 0;
    rep(i, n + 1) {
        now += i;

        if (now >= n) {
            int rem = now - n;
            for (int j = 1; j <= i; ++j)
                if (j != rem)
                    cout << j << "\n";
            return 0;
        }
    }

    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  string s;
  int n;
  cin >> s >> n;
  vector<vector<vector<int>>> dp(s.size()+1,vector<vector<int>>(4,vector<int>(2,0)));
  dp[0][0][0] = 1;
  rep(i,s.size())rep(j,4)rep(k,2){
    rep(l,10){
      int ni = i+1,nj = j,nk = k;
      if(l != 0)nj++;
      if(nj > n)continue;
      if(k == 0){
        if(l > s[i]-'0')continue;
        if(l < s[i]-'0')nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  cout << dp[s.size()][n][0]+dp[s.size()][n][1] << endl;




  return 0;
}

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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	long long int a,b;
	long long int tmp[2],gcd;
	cin >> a >> b;

	tmp[0] = a;
	tmp[1] = b;
	while(tmp[0] % tmp[1] != 0){
		gcd = tmp[0] % tmp[1];
		tmp[0] = tmp[1];
		tmp[1] = gcd;
	}
	gcd = tmp[1];

	cout << a*b / gcd << endl;

	return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    int MAX_K = (N - 1) * (N - 2) / 2;
    int P = MAX_K;
    vector<pair<int, int>> ans;
    for (int i = 2; i <= N; i++) {
        ans.push_back(make_pair(1, i));
    }
    
    if (K <= MAX_K) {
        bool skip = false;
        for (int i = 2; i < N; i++) {
            for (int j = i + 1; j <= N; j++) {
                if (P == K) {
                    skip = true;
                    break;
                }
                ans.push_back(make_pair(i, j));
                P--;
            }
            if (skip) {
                break;
            }
        }
        
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
            cout << ans[i].first << " " << ans[i].second << endl;
        }
    } else {
        cout << -1 << endl;
    }
    return 0;
}

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

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

int main() {
  int A[9];
  rep(i, 9) cin >> A[i];

  int N;
  cin >> N;
  int B[N];
  rep(i, N) cin >> B[i];

  int ans[9];
  rep(i, 9) ans[i] = 0;

  rep(i, N) {
    rep(j, 9) {
      if (B[i] == A[j]) ans[j] = 1;
    }
  }

  bool lans = false;

  if ((ans[0] == 1 && ans[1] == 1 && ans[2] == 1) ||
      (ans[3] == 1 && ans[4] == 1 && ans[5] == 1) ||
      (ans[6] == 1 && ans[7] == 1 && ans[8] == 1)) {
    lans = true;
  }

  else if ((ans[0] == 1 && ans[3] == 1 && ans[6] == 1) ||
           (ans[1] == 1 && ans[4] == 1 && ans[7] == 1) ||
           (ans[2] == 1 && ans[5] == 1 && ans[8] == 1)) {
    lans = true;
  } else if ((ans[0] == 1 && ans[4] == 1 && ans[8] == 1) ||
             (ans[2] == 1 && ans[4] == 1 && ans[6] == 1)) {
    lans = true;
  }

  if (lans == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 256
//#pragma GCC diagnostic error "-std=c++11"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const ll inf = 0x3f3f3f3f3f;
bool dislike[100];
ll n,k;

bool judge(int n)
{
	while(n)
	{
		if(dislike[n%10]) return false;
		n/=10;
	}
	return true;
}

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

Measured memory_bytes: 256
#include<stdio.h>

void cube(int x)
{
	if((x>=1)&&(x<=100))
	{
		printf("%d\n", x*x*x); 
	}
}


int main(void)
{
	int x;
	scanf("%d", &x);
	cube(x);
	
	return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template<typename T>
void print(vector<T> v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

struct Card { char suit; int num; };

bool operator==(Card lhs, Card rhs) {
  return lhs.suit == rhs.suit && lhs.num == rhs.num;
}

void merge(vector<Card> &A, int left, int mid, int right) {
  auto n1 = mid - left;
  auto n2 = right - mid;
  vector<Card> L(n1 + 1), R(n2 + 1);
  copy(A.begin() + left, A.begin() + mid, L.begin());
  copy(A.begin() + mid, A.begin() + right, R.begin());
  L[n1].num = INF;
  R[n2].num = INF;
  int i = 0, j = 0;
  FOR(k, left, right) {
    A[k] = (L[i].num <= R[j].num) ? L[i++] : R[j++];
  }
}

void merge_sort(vector<Card> &A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    merge_sort(A, left, mid);
    merge_sort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(vector<Card> &A, int p, int r) {
  auto x = A[r].num;
  auto i = p - 1;
  FOR(j, p, r) {
    if (A[j].num <= x) swap(A[++i], A[j]);
  }
  swap(A[i + 1], A[r]);
  return i + 1;
}

void quick_sort(vector<Card> &A, int p, int r) {
  if (p < r) {
    auto q = partition(A, p, r);
    quick_sort(A, p, q - 1);
    quick_sort(A, q + 1, r);
  }
}

int main() {
  int n;
  cin >> n;
  vector<Card> A1(n);
  REP(i, n) cin >> A1[i].suit >> A1[i].num;
  auto A2 = A1;
  quick_sort(A1, 0, n - 1);
  merge_sort(A2, 0, n);
  cout << (equal(ALL(A1), A2.begin()) ? "Stable" : "Not stable") << endl;
  for(auto a : A1) {
    cout << a.suit << " " << a.num << endl;
  }
}



Measured memory_bytes: 5108
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> WA(N,0);
    vector<bool> AC(N,false);
    for (int i = 0; i < M ; i++) {
        int pa;
        string pi;
        cin >> pa >> pi;
        if (pi == "WA")
        {
            if (AC.at(pa-1) == false)
            {
                WA.at(pa-1)++;
            }
        }else
        {
            AC.at(pa-1) = true;
        }
    }
    int AC_N = 0;
    int WA_N = 0;
    for (int i = 0; i < N; i++)
    {
        if (AC.at(i) == true)
        {
            AC_N++;
            WA_N += WA.at(i);
        }
    }
    cout << AC_N << " " << WA_N;
}

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

int main (){
  int a,b,c;
  cin>>a>>b>>c;
  int fiv,sev;
  if(a==5) fiv++;
  if(b==5) fiv++;
  if(c==5) fiv++;
  if(a==7) sev++;
  if(b==7) sev++;
  if(c==7) sev++;
  
  if(fiv==2&&sev==1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }

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

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define int ll
int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


int dp[110][10100];

signed main() {
	ios::sync_with_stdio(false);
	int N, W;
	cin >> N >> W;
	vector<int> w(N,0);
	vector<int> v(N,0);
	rep(i, N) {
		cin >> v[i] >> w[i];
	}

	rep(i, N) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i]) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}



Measured memory_bytes: 11040
#include<stdio.h>

int main()
{
    int a,b,h, area;
    scanf("%d /n", &a);
    scanf("%d /n", &b);
    scanf("%d/n", &h);





    if(a <=100 && b<= 100 && h<=100 && h%2==0)
    {
        area = ((a+b)*h)/2;

    }
    printf("%d", area);

    return 0;
}


Measured memory_bytes: 128
def d_powerful_discount_tickets():
    import heapq
    N, M = [int(i) for i in input().split()]
    A = [-int(i) for i in input().split()]
    heapq.heapify(A)
    for _ in range(M):
        heapq.heappush(A, heapq.heappop(A) / 2)
    return sum(-int(a) for a in A)

print(d_powerful_discount_tickets())

Measured memory_bytes: 14180
const main = (input: string) => {
    const lines: string[] = input.trim().split("\n");
    const N = parseInt(lines[0]);
    const testimonyList: number[][][] = [];

    let i = 1;
    while (i < lines.length - 1) {
        const A = parseInt(lines[i++]);
        const testimony: number[][] = Array(A).fill(0).map(() => lines[i++].split(' ').map(str => parseInt(str)))
        testimonyList.push(testimony)
    }

    let maxHonestNum = 0;
    for (let bit = 0; bit < (1 << N); bit++) {
        const isHonest: number[] = Array(N).fill(0);
        for (let i = 0; i < N; i++) {
            if (bit & (1 << i)) { // i番目が正直者
                isHonest[i] = 1;
            }
        }
        const isConsistent = testimonyList.every((testimony, i) => {
            if (isHonest[i]) {
                return testimony.every(xy => isHonest[xy[0] - 1] === xy[1])
            } else {
                return true;
            }
        })

        if (isConsistent) {
            const honestNum = isHonest.filter(b => b === 1).length;
            maxHonestNum = Math.max(maxHonestNum, honestNum);
        }
    }

    console.log(maxHonestNum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 10540
#include <stdio.h>

int main() {
  int L, R, d, i;
  scanf("%d %d %d", &L, &R, &d);
  
  (L % d == 0) ? printf("%d\n", R / d - L / d + 1) : printf("%d\n", R / d - L / d);
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef long long ll;
int N,K;
int main(){
	cin>>N>>K;
	cout<<(N%K ? 1 : 0)<<endl;
	return 0;
}

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

int main() {
	int a,b; cin>>a>>b;
	if (a==b) {
		cout << "Draw" << endl;
		return 0;
	}
	if (a==1) {
		cout << "Alice" << endl;
		return 0;
	}
	if (b==1) {
		cout << "Bob" << endl;
		return 0;
	}
	if (a>b) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int H1 = sc.nextInt();
		int M1 = sc.nextInt();
		int L1 = H1 * 60 + M1;
		int H2 = sc.nextInt();
		int M2 = sc.nextInt();
		int L2 = H2 * 60 + M2;
		int K = sc.nextInt();
		L2 -= K;
		int ans = L2 - L1;
		System.out.println(ans);
	}
}

Measured memory_bytes: 27088
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 25, M = 1e6 + 25, oo = 1e9, mod = 1e9 + 7;
const long long OO = 1e18+25;

#define par pair<pair<int,int>, int>
#define f first
#define s second

int D, mem[N][100][10][2][2];
char k[N];

int dp(int idx=0, int m=0, int d=0, int b=1, int f=0)
{
    if(!k[idx] && m ==0 && f) return 1;
    if(!k[idx]) return 0;
    int &ret = mem[idx][m][d][b][f];
    if(~ret) return ret;
    ret = 0;
    if(d) f=1;
    int e = 9;
    if(b) e = int(k[idx]-'0');
    int nxtb = 0;
    if(b && d==e) nxtb = 1;
    return ret = (dp(idx+1, (m+(d%D))%D,0, nxtb,f) + (d<e?dp(idx,m,d+1,b,f):0))%mod;
}

int main()
{
    memset(mem, -1, sizeof mem);
    scanf("%s%d",k,&D);
    printf("%d",dp());
    return 0;
}

Measured memory_bytes: 166272
N = int(input())
Dic = {}
for i in range(N):   
    Name = input()
    Dic[Name[0]] = Dic.get(Name[0],0) + 1
    
tmp = [Dic.get("M",0),Dic.get("A",0),Dic.get("R",0),Dic.get("C",0),Dic.get("H",0)]

ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += tmp[i]*tmp[j]*tmp[k]
print(ans)  

Measured memory_bytes: 3064
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = deque(input())
    q = int(input())
    reverse = False
    
    for _ in range(q):
        query = list(input().split())
        if query[0] == '1':
            reverse ^= True
        else:
            if reverse:
                if query[1] == '1':
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if query[1] == '1':
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
                    
    s = ''.join(s)
    if reverse:
        s = s[::-1]
    print(s)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    constexpr int N = 100;
    vector<int> prime;
    vector<bool> erato(N+5);
    FOR(i,2,N+1) {
        if (erato[i]) continue;
        prime.push_back(i);
        for(int j = 1; i * j <= N; j++) erato[i*j] = true;
    }

    int n; cin >> n;
    vector<int> pcount(prime.size());
    REP(i,n) {
        int x = i+1;
        int j = 0;
        while(x != 1) {
            if (x % prime[j] == 0) {
                pcount[j]++;
                x /= prime[j];
            } else j++;
        }
    }
    map<int,int> m;
    REP(i,pcount.size()) {
        if (pcount[i] >= 74) m[74]++;
        if (pcount[i] >= 24) m[24]++;
        if (pcount[i] >= 14) m[14]++;
        if (pcount[i] >= 4) m[4]++;
        if (pcount[i] >= 2) m[2]++;
    }
    int ans = 0;
    ans = m[74] + 
    m[24] * (m[2]-1) + 
    m[14] * (m[4]-1) + 
    m[4] * (m[4]-1) / 2 * (m[2]-2);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

template <typename T>
struct BIT{
    int n;
    vector<T> bit;
    BIT(int n_) : n(n_ + 1), bit(n, 0) {}

    void add(int i, T x){
        for(int idx = i; idx < n; idx += (idx & -idx)){
            bit[idx] += x;
        }
    }
    T sum(int i){
        T s(0);
        for(int idx = i; idx > 0; idx -= (idx & -idx)){
            s += bit[idx];
        }
        return s;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    BIT<int> bit(2e5);
    vector<int> ans;
    rep(i, q){
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) bit.add(x, y);
        else {
            if (x > y) swap(x, y);
            ans.push_back(bit.sum(y) - bit.sum(x-1));
        }
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;
const int N=3e5+100;

int main()
{
   string s;cin>>s;
   if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int K;
int d[100010];
vector<pi> G[100010];

void solve() {
	cin >> K;
	fill(d, d + K, inf);
	rep(i, 0, K) {
		G[i].pb(pi(1, (i + 1) % K));
		G[i].pb(pi(0, (i * 10) % K));
	}
	d[1] = 1;
	priority_queue<pi, vector<pi>, greater<pi>> que;
	que.push(pi(1, 1));
	while(!que.empty()) {
		pi p = que.top(); que.pop();
		int td = p.fst, v = p.sec;
		if(d[v] < td) continue;
		rep(i, 0, sz(G[v])) {
			int cost = G[v][i].fst, to = G[v][i].sec;
			if(d[to] > d[v] + cost) {
				d[to] = d[v] + cost;
				que.push(pi(d[to], to));
			}
		}
	}
	cout << d[0] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 6780
#include<stdio.h>
#define N 100

int main(){
  int M[N][N];
  int i,j,n,u,k,v;

  scanf("%d",&n);
  for(i=0 ; i < n ; i++){
    for(j=0 ; j < n ; j++) M[i][j] = 0 ;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0 ; j < k ; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define endl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

using ll = long long;
using P = pair<ll, ll>;

/*追加部分*/



/*main関数*/

int main() {
FASTIO;
    string s; cin >> s;
    int ar[10];
    for(int i = 0; i < 3; i++){
        ar[i] = s[i] - '0';
    }

    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(ar[i] == 1) ans++;
    }

    cout << ans << endl;
return 0;
}

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

int main(){
	int year;
	int month;
	int day;
	while(cin >> year >> month >> day){
		if((year > 1989) || ((year == 1989) && 
			((month > 1) || ((month == 1) && (day >= 8)))))
		{
			cout << "heisei" << " " << year - 1989 + 1
				<< " " << month << " " << day << endl;
		} else if((year > 1926) || ((year == 1926) &&
			(month == 12) && (day >= 25)))
		{
			cout << "showa" << " " << year - 1926 + 1
				<< " " << month << " " << day << endl;
		} else if((year > 1912) || ((year == 1912) &&
			((month > 7) || ((month == 7) && (day >= 30)))))
		{
			cout << "taisho" << " " << year - 1912 + 1
				<< " " << month << " " << day << endl;
		} else if((year > 1868) || ((year == 1868) &&
			((month >9) || ((month == 9) && (day >= 8)))))
		{
			cout << "meiji" << " " << year - 1868 + 1 
				<< " " << month << " " << day << endl;
		} else{
			cout << "pre-meiji" << endl;
		}
	}
	return 0;
}

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

using namespace std;

template<typename T> class BIT{
public:
	int size;
	vector<T> arr;
	BIT(int n){
		size=n+5;
		arr.resize(size);
	}
	void add(int i,T v){
		for(int x=i+1;x<size;x+=(x&(-x))) arr[x]+=v;
	}
	T sum(int i){
		i=min(i,size-2);
		T res=0;
		for(int x=i+1;x>0;x-=(x&(-x))) res+=arr[x];
		return res;
	}
};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
		
	for(int ii=0;ii<k;ii++){
		BIT<int> bit(5*n+10);
		for(int i=0;i<n;i++){
			int ri=i+a[i];
			int le=i-a[i];
			if(le<0) le=0;
			bit.add(le,1);
			bit.add(ri+1,-1);
		}
		int mn=n+2;
		for(int i=0;i<n;i++){
			a[i]=bit.sum(i);
			mn=min(mn,a[i]);
		}
		if(mn==n) break;
	}
	for(int i=0;i<n;i++) cout << a[i] << " ";
	cout << "\n";
	return 0;
}

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

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

  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;

  int ans = 1;
  if (m1 == m2) {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
 
  var n = parseInt(input[0], 10)
  var p = input.slice(1, n + 1).map(n => parseInt(n, 10))
 
  var top = p.reduce((x, y) => Math.max(x, y))
  var sum = p.reduce((x, y) => x + y)
 
  console.log(sum - (top / 2))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;

int main(){
	while (cin >> n&&n != -1){
		double x = 1, y = 0, angle = 0;
		REP(i, n - 1){
			angle += atan(1.0 / sqrt(pow(x, 2) + pow(y, 2)));
			double px = x, py = y;
			x = (sqrt(1 + pow(px, 2) + pow(py, 2)))*cos(angle);
			y = (sqrt(1 + pow(px, 2) + pow(py, 2)))*sin(angle);
		}
		cout << x << endl;
		cout << y << endl;
	}
}

Measured memory_bytes: 1288
x=int(input())
if 400<=x<600:
    print(8)
elif 600<=x<800:
    print(7)
elif 800<=x<1000:
    print(6)
elif 1000<=x<1200:
    print(5)
elif 1200<=x<1400:
    print(4)
elif 1400<=x<1600:
    print(3)
elif 1600<=x<1800:
    print(2)
elif 1800<=x<2000:
    print(1)

Measured memory_bytes: 9184
Input = list(map(str,input().split()))
S = Input[0]
T = Input[1]

Input = list(map(int,input().split()))
A = Input[0]
B = Input[1]

U = str(input())

if U == S:
  A -= 1
elif U == T :
  B -= 1

print(A,B)

Measured memory_bytes: 3064
n=int(input())
sy,sx=[0,0]
t1=0
ch=0

for _ in range(n):
  t,x,y=map(int,input().split())
  if (abs(sy-y)+abs(sx-x)-abs(t-t1))%2!=0 or abs(sy-y)+abs(sx-x)>abs(t-t1):
    ch+=1
  t1=t
  sy,sx=[y,x]
  
if  ch==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9212