akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
//constexpr int inf = 3e18;

int D;
int C[26];
int A[365][26];
int con[365],con2[365];
set<int>st[26],st2[26];
int score(){
	vector<int>last(26,-1);
	int res=0;
	rep(i,D){
		last[con[i]]=i;
		res+=A[i][con[i]];
		rep(j,26){
			res-=C[j]*(i-last[j]);
		}
	}
	return res;
}
int change(int x,int y){
	int res=A[x][y]-A[x][con[x]];
	auto pre_old=--st[con[x]].lower_bound(x);
	auto next_old=st[con[x]].upper_bound(x);
	res+=(*next_old-x-1)*(*next_old-x)/2*C[con[x]];
	res-=(x-*pre_old+*next_old-*pre_old-1)*(*next_old-x)/2*C[con[x]];
	auto pre_new=--st[y].lower_bound(x);
	auto next_new=st[y].lower_bound(x);
	res+=(x-*pre_new+*next_new-*pre_new-1)*(*next_new-x)/2*C[y];
	res-=(*next_new-x-1)*(*next_new-x)/2*C[y];
	return res;
}
unsigned long xor128() {
  static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
  unsigned long t=(x^(x<<11));
  x=y; y=z; z=w;
  return ( w=(w^(w>>19))^(t^(t>>8)) );
}
double rand_double(){
	return (long double)xor128()/ULONG_MAX;
}
bool rand_bool(double p){
	return rand_double()<=p;
}
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>D;
	rep(i,26){
		cin>>C[i];
	}
	vector<int>last(26,-1);
	int mx_score=-mod;
	REP(_,26){
      	rep(i,26){
            last[i]=-1;
      		st[i].clear();
      		st[i].insert(-1);st[i].insert(D);
      	}
		rep(i,D){
			int mx=-mod,idx;
			rep(j,26){
				cin>>A[i][j];
				int k=i-last[j];
				int l=(k+k+(_-1))*_/2-(_-1)*_/2;
				if(chmax(mx,A[i][j]+C[j]*l))idx=j;
			}
			con[i]=idx;st[idx].insert(i);
			last[idx]=i;
		}
		if(chmax(mx_score,score())){
			rep(i,D)con2[i]=con[i];
            rep(i,26)st2[i]=st[i];
		}
	}
	rep(i,D)con[i]=con2[i];
    rep(i,26)st[i]=st2[i];
	int score_=mx_score;
	cerr<<score_<<endl;
	int TL=1980;
	int cnt=0;
	double t;
	while(1){
		if(cnt%100==0){
			t=1000.*clock()/CLOCKS_PER_SEC/TL;
			if(t>=1.0)break;
		}
		if(xor128()%50){
			int x=xor128()%D,y;
			do{
				y=xor128()%26;
			}while(con[x]==y);
			double diff=change(x,y);
			if(diff>=0.||(((1.-t)/10.)>rand_double()
					&&diff>=-1000-5000*(1.-t))){
				score_+=diff;
				st[con[x]].erase(x);
				st[y].insert(x);
				con[x]=y;
			}
		}else {
			int x,y;
			do{
				x=xor128()%(D-1);y=xor128()%(min(D-x-1,16));
			}while(con[x]==con[x+y]);
			double diff=change(x,con[x+y])+change(x+y,con[x]);
			if(diff>=0.||(((1.-t)/10.)>rand_double()
					&&diff>=-200-400*(1.-t))){
				score_+=diff;
				st[con[x]].erase(x);
				st[con[x]].insert(x+y);
				st[con[x+y]].erase(x+y);
				st[con[x+y]].insert(x);
				swap(con[x],con[x+y]);
			}
		}
		cnt++;
		if(cnt%200000==0){
			cerr<<score_<<" "<<t<<"\n";
		}
	}
	rep(i,D)cout<<con[i]+1<<"\n";
	cerr<<score_<<" "<<cnt<<endl;
}


Measured memory_bytes: 3948
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int h = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
    if(x + r <= w && x - r >= 0 && y + r <= h && y - r >= 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}



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

int main(){
	int r0,w0,c,r;
	while(cin>>r0>>w0>>c>>r and r0>0){
		int roo=r0,water=w0;
		int cnt=0;
		while(c*water>roo){
			roo+=r; cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}



Measured memory_bytes: 3088
N, M = [int(x) for x in input().split()]

if M % 2 == 0:
    k = M // 2
    s1 = 1
    e1 = 2 * k
    s2 = 2 * k + 1
    e2 = 4 * k + 1
else:
    k = (M + 1) // 2
    s1 = 1
    e1 = 2 * k
    s2 = 2 * k + 1
    e2 = 4 * k - 1

n = 0
for _ in range(M):
    if s1 >= e1 or n >= M: break
    print(s1, e1)
    s1 += 1
    e1 -= 1
    n += 1

for _ in range(M):
    if s2 >= e2 or n >= M: break
    print(s2, e2)
    s2 += 1
    e2 -= 1
    n += 1


Measured memory_bytes: 9288
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {
			int n = sc.nextInt();

			if(n == 0) break;

			int[] scores = new int[n];

			int sum = 0;
			for (int i = 0; i < n; i++) {
				scores[i] = sc.nextInt();
				sum += scores[i];
			}
			double ave = (double)sum/n;

			double dev = 0;
			for (int i = 0; i < n; i++) {
				double tmp = scores[i] - ave;
				dev += tmp * tmp;
			}
			dev = Math.pow(dev/n, 0.5);

			System.out.println(dev);
		}
	}
}

Measured memory_bytes: 31592
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	_, a := readLengthAndSlice()

	c := make([]int, 4)
	for i := range a {
		c[a[i]%4]++
	}
	c1 := c[1] + c[3]
	c2 := c[2]
	c4 := c[0]
	if c2 == 0 {
		if c1 <= c4+1 {
			println("Yes")
		} else {
			println("No")
		}
	} else {
		if c2 == 1 && c4 == 0 {
			println("No")
		} else if c1 <= c4 {
			println("Yes")
		} else {
			println("No")
		}
	}
}

// -----------------------------------------------------------------------------

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 2944
#include <cstdio>
#include <iostream>
#include <cctype>
using namespace std;

int ev[128];

int convToNum(string ss){
    int res = 0;
    string::iterator it = ss.begin();
    while(it!=ss.end()){
        //printf("a:%c\n", *s);
        int mul = 1, uni = 1;
        if( isdigit(*it) ){ mul = *(it++) - '0'; }
        res += mul * ev[int(*it++)];
    }
    return res;
}

string convToStr(int num){
    string res = "";
    if(num/1000){
        if(num/2000) res.append(1, num/1000+'0');
        res.append(1, 'm');
    }
    if(num/100%10){
        if(num/100%10/2) res.append(1, num/100%10+'0');
        res.append(1, 'c');
    }
    if(num/10%10){
        if(num/10%10/2) res.append(1, num/10%10+'0');
        res.append(1, 'x');
    }
    if(num%10){
        if(num%10/2) res.append(1, num%10+'0');
        res.append(1, 'i');
    }
    return res;
}

int main(){
    ev[int('m')] = 1000;
    ev[int('c')] = 100;
    ev[int('x')] = 10;
    ev[int('i')] = 1;
    int n;
    string s1, s2;
    for(cin>>n;n--;){
        cin>>s1>>s2;
        cout<<convToStr(convToNum(s1)+convToNum(s2))<<endl;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

vi64 dijkstra(vector<vector<pair<int, int>>> &g) {
  pqasc<pair<i64, int>> q;
  vi64 dist(g.size(), (i64) 1e18);
  q.emplace(0, 0);
  dist[0] = 0;
  while (q.size()) {
    i64 c; int u;
    tie(c, u) = q.top(), q.pop();
    if (dist[u] < c) continue;
    for (auto p : g[u]) {
      int v, cost;
      tie(v, cost) = p;
      if (dist[v] <= c + cost) continue;
      q.emplace(c + cost, v);
      dist[v] = c + cost;
    }    
  }
  return dist;
}

void solve() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> g(N);
  rep(i, N - 1) {
    g[i + 1].emplace_back(i, 0);
  }
  rep(i, M) {
    int l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    g[l].emplace_back(r, c);
  }
  auto dist = dijkstra(g);
  i64 ans = dist[N - 1];
  if (ans == (i64) 1e18) ans = -1;
  cout << ans << endl;
}


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

struct res {
	int no;
	char s[11];
	int p;
	struct res * next;
};

int comp (struct res * r1, struct res * r2) {
	int s = strcmp (r1->s, r2->s);
	if (s!=0)
		return s;
	return r2->p - r1->p;
}

int main () {
	int N;
	struct res * init;
	if ((init=(struct res *)malloc(sizeof (struct res))) == NULL) {
		fprintf (stderr, "malloc error \n");
		return -1;
	}

	scanf ("%d", &N);
	for (int i=0; i<N; i++) {
		struct res * r;
		if ((r=(struct res *) malloc (sizeof (struct res))) == NULL) {
			fprintf (stderr, "malloc error\n");
			return -1;
		}
		
		r->no = i+1;
		scanf ("%s %d", r->s, &(r->p));
		struct res * tmp = init;
		while ((tmp->next != NULL) && (comp (tmp->next, r) < 0))
			tmp = tmp->next;

		if (tmp->next != NULL) {
			struct res * tmp2 = tmp->next;
			tmp->next = r;
			r->next = tmp2;
		} else {
			tmp->next = r;
		}
	}

	struct res * tmp = init;
	while (tmp->next!=NULL ) {
		printf ("%d\n", tmp->next->no);
		struct res * tmp2 = tmp;
		tmp = tmp->next;
		free (tmp2);
	}

	return 0;
}




Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        int C = cin.Int();
        var D = new int[35, 35];
        for (int i = 0; i < C; i++) {
            var tmp = cin.ArrayInt(C);
            for (int j = 0; j < C; j++) {
                D[i, j] = tmp[j];
            }
        }
        var c = new int[5, 35];
        for (int i = 0; i < N; i++) {
            var tmp = cin.ArrayInt(N);
            for (int j = 0; j < N; j++) {
                c[(i + j) % 3, tmp[j] - 1]++; //マスを3で割った余り、色の値を格納
            }
        }

        int ans = int.MaxValue;
        for (int i = 0; i < C; i++) {
            for (int j = 0; j < C; j++) {
                for (int k = 0; k < C; k++) {
                    if(i != j && j != k && k != i) { //色の被りがないようにする
                        int tmp = 0;
                        for (int l = 0; l < C; l++) {
                            tmp += D[l, i] * c[0, l];
                        }
                        for (int l = 0; l < C; l++) {
                            tmp += D[l, j] * c[1, l];
                        }
                        for (int l = 0; l < C; l++) {
                            tmp += D[l, k] * c[2, l];
                        }
                        ans = Math.Min(ans, tmp);
                    }
                }
            }
        }
        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

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

int main(){
    int dp[1000001];
    int odp[1000001];
    rep(i, 1000001){
        dp[i] = odp[i] = i;
    }

    for(int n=3, p=4; p<=1000000; n++){
        for(ll i=0; i+p<=1000000; i++){
            dp[i+p] = min(dp[i+p], dp[i]+1);
        }

        if(p%2 == 1){
            for(int i = 0; i+p <= 1000000; i++){
                odp[i+p] = min(odp[i+p], odp[i] + 1);
            }
        }

        p = n*(n+1)*(n+2)/6;
    }
    while(true){
        ll n; cin>>n;
        if(n == 0) break;
        cout << dp[n] << " " << odp[n] << endl;
    }
}



Measured memory_bytes: 10900
// #Sazaの1日1AC
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9+7;
const long long INF = 9e15;
const double PI = 3.14159265358979323846;

//マクロ
//型エイリアス
using ll = int;
using P = pair<long long, long long>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vP = vector<pair<long long, long long>>;
//ショートカット
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, k, n) for (int i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v, N) for (long long i = 0; i < N; i++) cin >> v.at(i)
#define lin(n)long long n;cin >> n
#define chin(x)char x;cin >> x;
#define sin(s)string s;cin >> s;
#define vlin(v, N)vector<long long> v(N);for (long long i = 0; i < N; i++)cin >> v.at(i)
#define max(a, b) max((ll)a, (ll)b)
#define min(a, b) min((ll)a, (ll)b)


/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////
int main(){
  //doubleの桁数
  //std::cout << fixed << setprecision(10);

  lin(N);lin(M);
  vector<string> num(M);
  vector<ll> order(N);
  vector<tuple<ll, ll, ll>> pre(M);
  rep(i,M){
    lin(p);lin(y);
    ll id = i;
    pre[i] = make_tuple(y, p, id);
  }

  sort(all(pre));

  rep(i,M){
    ll y, p, id;
    tie(y, p, id) = pre[i];
    ll ord = order[p] + 1;
    order[p]++;
    num[id] = to_string(ord);
    ll n = 6 - num[id].size();
    rep(j, n) num[id] = '0' + num[id];
    num[id] = to_string(p) + num[id];
    n = 12 - num[id].size();
    rep(j, n) num[id] = '0' + num[id];
  }

  rep(i,M) cout << num[i] << endl;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    ll ans=INF;
    for(int i=0;i<=max(x,y);i++){
        ll tmp=2*c*i;
        if(x>i)tmp+=min(a,2*c)*(x-i);
        if(y>i)tmp+=min(b,2*c)*(y-i);
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
 return 0;   
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n, nn, m;
int D[MAXN];
vector<int> lst[MAXN], gr[MAXN];
vector< pair<int, int> > g[MAXN];
int used[MAXN];

bool read() {
    if (!(cin >> n >> m))
        return false;

    forn (i, m) {
        int u, v, t;
        cin >> u >> v >> t;
        g[u - 1].pb(mp(t, v - 1));
        g[v - 1].pb(mp(t, u - 1));
        lst[t].pb(u - 1);
        lst[t].pb(v - 1);
    }

    return true;
}

void dfs(int v, int t, int ver) {
    used[v] = t;
    gr[ver].pb(v);
    gr[v].pb(ver);

    for (int i = lower_bound(g[v].begin(), g[v].end(), mp(t, -1)) - g[v].begin(); i < sz(g[v]) && g[v][i].f == t; ++i)
        if (used[g[v][i].s] != t)
            dfs(g[v][i].s, t, ver);
}

void solve() {
    forn (i, n)
        sort(g[i].begin(), g[i].end());

    nn = n;

    for (int t = 1; t < MAXN; ++t)
        for (auto v : lst[t])
            if (used[v] != t)
                dfs(v, t, nn++);

    queue<int> Q;
    fill(D, D + nn, INF);

    for (Q.push(D[0] = 0); !Q.empty(); Q.pop()) {
        int v = Q.front();

        for (auto to : gr[v])
            if (D[to] == INF) {
                D[to] = D[v] + 1;
                Q.push(to);
            }
    }

    cout << (D[n - 1] == INF ? -1 : D[n - 1] / 2) << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e3+23;

int a[N], c[N];
int dp[N][(1<<12)+23];
int n, m;

int rek(int pos, int mask) {
  if (pos == m) {
    return (mask != (1 << n)-1) * 1e9;
  }
  int &ret = dp[pos][mask];
  if (ret != -1) return ret;
  ret = rek(pos+1, mask);
  return ret = min(ret, a[pos] + rek(pos+1, mask | c[pos]));
}

void solve() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d", &n, &m);
  for (int b, i = 0; i < m; ++i) {
    scanf("%d%d", a+i, &b);
    for (int x; b--;) {
      scanf("%d", &x);
      c[i] |= 1 << (x-1);
    }
  }
  int ans = rek(0, 0);
  if (ans >= 1e9) printf("-1");
  else printf("%d", ans);
}

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


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

using namespace std;

int n, x;
const int maxn = 55;
int a[maxn];
long long dp[maxn][maxn * maxn][maxn];

long long solve (int p, int s, int k) {
  if (p >= n) {
    return (k > 0 && x * k == s);
  }
  if (dp[p][s][k] != -1) return dp[p][s][k];
  long long tot = 0;
  tot += solve (p + 1, s, k);
  tot += solve (p + 1, s + a[p], k + 1);
  return dp[p][s][k] = tot;
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << solve (0, 0, 0) << '\n';
  return 0;
}

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

int main(void){
    int n;
    string s;
    cin >> n >> s;
    int ns = 0, ew = 0;
    for(int i=0;i<n;i++){
        if(s[i] >= 'A' && s[i] <= 'M') ns++;
        if(s[i] >= 'N' && s[i] <= 'Z') ns--;
        if(s[i] >= 'a' && s[i] <= 'm') ew++;
        if(s[i] >= 'n' && s[i] <= 'z') ew--;
    }
    string ans;
    for(int i=0;i<abs(ns);i++){
        ans.push_back((ns>0?'A':'N'));
    }
    for(int i=0;i<abs(ew);i++){
        ans.push_back((ew>0?'a':'n'));
    }
    cout << ans.size() << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3292
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)*}
    };
}

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)*}
    };
}

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        x: i64,
        y: i64
    }
    if x * y >= 0 {
        if x <= y {
            println!("{}", y - x);
        } else if x * y == 0 {
            println!("{}", x - y + 1);
        } else {
            println!("{}", x - y + 2);
        }
    } else {
        println!("{}", (x.abs() - y.abs()).abs() + 1);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
using namespace std;
char s;
int main(){
	scanf("%c", &s);
	if(s == 'A') puts("T");
	else if(s == 'G') puts("C");
	else if(s =='T') puts("A");
	else if(s == 'C' ) puts("G");
}



Measured memory_bytes: 256
package main

import "fmt"

func gcd(x, y int) int {
    for y > 0 {
        x, y = y, x % y
    }
    return x
}

func max(x, y int) int {
    if x > y {
        return x
    }
    return y
}

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    forward, backword := make([]int, n + 1), make([]int, n + 1)
    forward[0], backword[n] = 0, 0
    for i := 1; i <= n; i++ {
        forward[i] = gcd(forward[i - 1], a[i - 1])
    }
    for i := n; i > 0; i-- {
        backword[i - 1] = gcd(backword[i], a[i - 1])
    }
    ans := 0
    for i := 0; i < n; i++ {
        g := gcd(forward[i], backword[i + 1])
        if g > ans {
            ans = g
        }
    }
    fmt.Println(ans)
}



Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
int main(){
    int N;
    cin >> N;
    bool b = false;
    REP(i,50000){
        float a = i;
        float x = a * 1.08;
        if(abs(x-N)<1){
            if(floor(x)==N){
                cout << i << endl;
                b = true;
                break;
            }
        }
    }
    if(!b) cout << ":(" << endl;
}

Measured memory_bytes: 256
from collections import deque

K = int(input())

Q = deque()

for i in range(9):
    Q.append(i+1)
cnt = 0

while cnt < K:
    q = Q.popleft()

    if q % 10 != 0:
        Q.append(10*q+(q%10)-1)

    Q.append(10*q+(q%10))

    if q % 10 != 9:
        Q.append(10*q+(q %10)+1)

    cnt += 1

print(q)


Measured memory_bytes: 40944
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

ll score(ll a, int t) {
    if(t == 0 || t == 4) return a;
    if(t == 1 || t == 3) {
        if( a == 0) return 2;
        return a%2;
    }
    if(t == 2) return (a+1)%2; 
}

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

  int L; cin >> L;
  ll A[200200]; rep(i, L) {
      cin >> A[i];
  }
  ll dp[200200][5];
  rep1(i, L) {
    rep(j, 5) {
      dp[i][j] = INF;
    }
  }
  rep(i, 5) {
      dp[0][i] = 0;
  }
  rep(i, L + 1) {
    rep(j, 5) {
      if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1]);
      if(i != L)dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + score(A[i], j));
    }
  }
  ll ans = INF;
  rep(j, 5) {
    ans = min(ans, dp[L][j]);
  }

  cout << ans <<"\n";

  return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MOD 1000000007
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;
int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

lli nCr(int n, int r, lli *mem) {
    if(n < r) return 0;
    if(mem[n*2010 + r]!=0) {
        return mem[n*2010 + r];
    } else {
        if(n==r || r==0) {
            mem[n*2010 + r] = 1;
            return 1;
        }
        lli a = nCr(n-1, r-1, mem);
        lli b = nCr(n-1, r, mem);
        mem[n*2010 + r] = (a+b)%MOD;
        return mem[n*2010 + r];
    }
}

int main()
{
    int i, n, k;
    scanf("%d%d",&n,&k);
    lli *mem = (lli*)calloc(2010*2010, sizeof(lli));
    for(i=1; i<=k; i++) {
        lli temp = (nCr(k-1, i-1, mem)*nCr(n-k+1, i, mem))%MOD;
        // printf("%d: %lld\n",i, temp);
        printf("%lld\n",temp);
    }

    return 0;
}


Measured memory_bytes: 31872
x=[]
total=[]
for i in range(5):
  t=list(input())
  if t[-1]=='0':
    total.append(t)
  else:
    x.append(t)
x=sorted(x, key=lambda x: x[-1])
for i in range(1,len(x)):
  total.append(x[i])
if len(x)!=0:
  last=int(''.join(x[0]))

for i in range(4):
  total[i]=int(''.join(total[i]))
  total[i]=-(-total[i]//10)*10
if len(x)==0:
  total[-1]=int(''.join(total[-1]))
  print(sum(total))
else:
  print(sum(total)+last)

Measured memory_bytes: 38384
N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]

diff = [0] * 100002
for k in l :
    diff[k[0] - 1] += 1
    diff[k[1]] -= 1

hist = [0,0]
for i in range(2, N + 2) :
    hist.append(hist[-1] + diff[i-1])

print(max([0] + [y - 1 for (x,y) in zip(hist, range(N + 2)) if x + 1 >= y]))

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n, t;
    cin >> n >> t;
    vector<int> c(n), time(n);
    rep(i, n) cin >> c[i] >> time[i];

    int res = 1001001001;
    rep(i, n)
    {
        if (time[i] <= t)
        {
            res = min(res, c[i]);
        }
    }

    if (res == 1001001001)
    {
        cout << "TLE" << '\n';
    }
    else
    {
        cout << res << '\n';
    }
    return 0;
}


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

d = []
A = []
flag = 0
count = 0
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int,input().split())))

for i in range(1,N+1):
    for j in range(K):
        if A[j].count(i) == 0:
            flag += 1
    if flag == K:
        count += 1
        flag = 0
    else:
        flag = 0

print(count)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
int main () {
  int MAX = 0 , sum = 0 , n;
	char s;
	cin >> n;
	while(n--){
		cin >> s;
		s == 'I' ? (sum++) : (sum--);
		MAX = max (MAX , sum);
	} 
  cout << MAX << endl;
	return 0;
}


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

using pii = pair<int, int>;

template<typename T>
std::vector<T> table(int n, T v) { return std::vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return std::vector<decltype(val)>(n, std::move(val));
}

int main() {
    int h, w, r, c;
    while(cin >> h >> w >> r >> c, h) {
        r--; c--;
        vector<vector<int>> horz(h + 1, vector<int>(w)), vert(h, vector<int>(w + 1));
        for(int i = 0; i < 2 * h + 1; ++i) {
            if(i & 1) {
                for(int j = 0; j < w + 1; ++j) {
                    cin >> vert[i / 2][j];
                }
            } else {
                for(int j = 0; j < w; ++j) {
                    cin >> horz[i / 2][j];
                }
            }
        }
        auto win = table(h, w, 2, -1); // 1: alice, 0: bob, -1: ?
        queue<tuple<int, int, int>> que;
        for(int i = 0; i < h; ++i) {
            win[i][0][vert[i][0]] = win[i][w - 1][vert[i][w]] = 1;
        }
        for(int i = 0; i < w; ++i) {
            win[0][i][horz[0][i]] = win[h - 1][i][horz[h][i]] = 1;
        }
        for(int i = 0; i < h; ++i) {
            if(win[i][0][0] == 1 && win[i][0][1] == 1) {
                que.emplace(i, 0, 0);
                que.emplace(i, 0, 1);
            }
        }
        for(int i = 0; i < w; ++i) {
            if(win[0][i][0] == 1 && win[0][i][1] == 1) {
                que.emplace(0, i, 0);
                que.emplace(0, i, 1);
            }
        }

        constexpr int dx[4] = {0, 1, 0, -1};
        constexpr int dy[4] = {1, 0, -1, 0};
        auto in_range = [&] (int y, int x) {
            return 0 <= y && y < h && 0 <= x && x < w;
        };
        auto check_wall = [&] (int y, int x, int dir, int f) {
            if(dir & 1) { // move x
                return vert[y][x + (dir == 1)] == f;
            } else {
                return horz[y + (dir == 0)][x] == f;
            }
        };
        while(!que.empty()) {
            int y, x, f;
            tie(y, x, f) = que.front();
            que.pop();
            for(int i = 0; i < 4; ++i) {
                int ny = y + dy[i], nx = x + dx[i];
                if(!in_range(ny, nx)) continue;
                if(check_wall(y, x, i, f) && win[ny][nx][f] == -1) {
                    win[ny][nx][f] = 1;
                    if(win[ny][nx][!f] == 1) {
                        que.emplace(ny, nx, 0);
                        que.emplace(ny, nx, 1);
                    }
                }
                if(check_wall(y, x, i, !f) && win[ny][nx][!f] == -1) {
                    win[ny][nx][!f] = 1;
                    if(win[ny][nx][f] == 1) {
                        que.emplace(ny, nx, 0);
                        que.emplace(ny, nx, 1);
                    }
                }
            }
        }

        if(win[r][c][0] == 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 18672
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        PriorityQueue<Integer> q=new PriorityQueue<>();
        
//        int n=sc.nextInt();
        char c[]=sc.getCharSet();
        long d[]=new long[c.length+1];

        for (int i = 0; i < c.length; i++) {
			if(c[i]=='<')d[i+1]=d[i]+1;
		}
        for (int i = c.length-1; -1<i; i--) {
			if(c[i]=='>')d[i]=max(d[i],d[i+1]+1);
		}
        
        for (int i = 1; i < d.length; i++) {
			d[0]+=d[i];
		}

        out.println(d[0]);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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


int main(void){
  int n; cin >> n;
  int a[n-1];
  rep(i,n-1){
    cin >> a[i];
  }
  int b[n];
  rep(i,n){
    b[i] = 0;
  }
  rep(i,n-1){
    b[a[i] - 1]++;
  }
  rep(i,n){
    cout << b[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5180
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int loop_num;
		char buf[12];
	while (1){
		int up = 1, down = 6, South = 2, West = 4, North = 5, East = 3;
		long long ans = 0;
		scanf("%d", &loop_num);
		if (loop_num == 0) return 0;
		for (int a = 0; a < loop_num; a++){
			scanf("%s", buf);
			switch (buf[0])
			{
			case 'N':
				swap(up, South);
				swap(South, down);
				swap(down, North);
				break;
			case 'E':
				swap(up, West);
				swap(West, down);
				swap(down, East);
				break;
			case 'W':
				swap(up, East);
				swap(East, down);
				swap(down, West);
				break;
			case 'S':
				swap(up, North);
				swap(North, down);
				swap(down, South);
				break;
			case 'R':
				swap(North, West);
				swap(West, South);
				swap(South, East);
				break;
			case 'L':
				swap(North, East);
				swap(East, South);
				swap(South, West);
				break;
			default:
				break;
			}
			ans+=up;
		}
		printf("%lld\n", ans + 1);
	}
}

Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int dp_solve(const int n, const string& s){
    //x : s.size()
    //y : use cnt
    //z ; lucky number
    // vector<vector<vector<bool>>> dp(n + 1, vector<vector<bool>>(4, vector<bool>(1000, false)));
    vector<vector<bool>> dp(4, vector<bool>(1000, false));
    // dp[0][0][0] = true;
    dp[0][0] = true;
    for (auto i = 0; i < n; i++) {
        for (auto j = 2; j >= 0; j--) {
            for (auto k = 0; k <= 99; k++) {
                int index = k * 10 + (s[i] - '0');
                // dp[i + 1][j][k] = dp[i][j][k] or dp[i + 1][j][k];
                //if(index <= 999) {
//                    if(dp[j + 1][index] or dp[j][k])
//                        cout << i << " " << j << " " << k << " " << index << endl;
                    // dp[i + 1][j + 1][index] = dp[i][j][k] or dp[i + 1][j + 1][index];
                    dp[j + 1][index] = dp[j][k] or dp[j + 1][index];
                //}
            }
        }
    }

//    // for (auto i = 0; i <= n; i++) {
//        for (auto j = 0; j <= 3; j++) {
//            for (auto k = 0; k <= 30; k++) {
//                cout << dp[j][k] << " ";
//            }
//            cout << endl;
//        }
//    //     cout << endl;
//    // }

    int cnt = 0;
    for (auto i = 0; i <= 999; i++) if(dp[3][i]) cnt++;

    return cnt;
}

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

//    int ans = 0;
//    for (auto i = 0; i <= 999; i++) {
//        vector<int> number(3);
//        int tmp = i;
//        for (auto j = 0; j < 3; j++) {
//            number[j] = tmp % 10;
//            tmp /= 10;
//        }
//        int cnt = 0;
//        for (auto k = 0; k < (int)s.size(); k++) {
//            if(s[k] - '0' == number[cnt]) cnt++;
//            if(cnt == 3) {
//                ans++;
//                break;
//            }
//        }
//    }
//
//    cout << ans << endl;

    cout << dp_solve(n, s) << endl;
    return 0;
}

Measured memory_bytes: 384
/*
    Author : zzugzx
    Lang : C++
    Blog : blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
#define mem(a, b) memset(a, b, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int mod = 1e9 + 7;
//const int mod = 998244353;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int maxn = 2e6 + 10;
const int N = 2e4 + 5;
const ll inf = 0x3f3f3f3f;
const int dir[][2]={{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
    int k;
    cin >> k;
    int tmp = 0;
    for (int i = 1; i <= 10000000; i++) {
        tmp = (tmp * 10 + 7) % k;
        if (!tmp) {cout << i << endl; return 0;}
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 3648
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()
	k := sc.ReadInt()

	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = sc.ReadInt()
	}
	bs := make([]int, m)
	for i := 0; i < m; i++ {
		bs[i] = sc.ReadInt()
	}

	kRest := k
	infoes := make([]readInfo, 1, n+1)
	infoes[0] = readInfo{0, kRest}
	for i, a := range as {
		kRest -= a
		if kRest < 0 {
			break
		}
		info := readInfo{i + 1, kRest}
		infoes = append(infoes, info)
	}

	infoesAsc := make([]readInfo, len(infoes))
	for i, info := range infoes {
		infoesAsc[len(infoes)-1-i] = info
	}

	maxCount := infoesAsc[0].bookCount
	readBMinutes := 0
	curInfoIndex := 0
	for i, b := range bs {
		readBMinutes += b
		if readBMinutes > k {
			break
		}
		for infoesAsc[curInfoIndex].restMinutes < readBMinutes {
			curInfoIndex++
		}
		readACount := infoesAsc[curInfoIndex].bookCount
		readBCount := i + 1
		readCount := readACount + readBCount
		if readCount > maxCount {
			maxCount = readCount
		}
	}

	fmt.Println(maxCount)
}

type readInfo struct {
	bookCount   int
	restMinutes int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 12356
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    long ans;
    foreach (i, a; A)
    {
        if (((i + 1) & 1) && (a & 1))
            ans++;
    }
    writeln(ans);
}


Measured memory_bytes: 3640
<?php
$S = fgets(STDIN);
$first = intval(substr($S,0,2));
$second = intval(substr($S,2,2));
if(1<=$first && $first<=12){
  $firstMJudge = true;
}else{
  $firstMJudge = false;
}
if(1<=$second && $second<=12){
  $secondMJudge = true;
}else{
  $secondMJudge = false;
}
if($firstMJudge && $secondMJudge){
  echo 'AMBIGUOUS';
}elseif($firstMJudge){
  echo 'MMYY';
}elseif($secondMJudge){
  echo 'YYMM';
}else{
  echo 'NA';
}


Measured memory_bytes: 3576
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i, a in enumerate(A):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= MOD
        if j + a <= S:
            dp[i + 1][j + a] += dp[i][j]
            dp[i + 1][j + a] %= MOD

print(dp[-1][-1] % MOD)


Measured memory_bytes: 139492
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

int main(){
	LL h1,m1,h2,m2,tot,k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	tot = (h2 - h1) * 60 + (m2 - m1);
	cout << tot - k << '\n'; 
	return 0;
}

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

namespace ABC144B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            bool hantei = false;
            for(int i=1;i<10; i++)
            {
                for(int j = 1; j < 10; j++)
                {
                    if (i * j == N)
                    {
                        hantei = true;
                    }
                }
            }
            if (hantei == true)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 27516
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0042

??\?£?
"""

class Knapack(object):
    def __init__(self, data, limit):
        self.limit = limit
        data_size = len(data)
        self.C = [[0]*(limit+1) for _ in range(data_size+1)]
        self.data = data[:]

    def solve(self):
        for i in range(1, len(self.data)+1):
            i_value = self.data[i-1][0]
            i_weight = self.data[i-1][1]
            for w in range(1, self.limit+1):
                if i_weight <= w:
                    if i_value + self.C[i-1][w-i_weight] > self.C[i-1][w]:
                        self.C[i][w] = i_value + self.C[i-1][w-i_weight]
                    else:
                        self.C[i][w] = self.C[i-1][w]
                else:
                    self.C[i][w] = self.C[i-1][w]


if __name__ == '__main__':
    # ??????????????\???
    # limit = 50
    # data = [[60, 10], [100, 20], [120, 30], [210, 45], [10, 4]]
    case_no = 1
    while True:
        limit = int(input())
        if limit == 0:
            break
        num_of_items = int(input())
        data = []
        for i in range(num_of_items):
            data.append(list(map(int, input().split(','))))

        # ????????????????????????????§£???
        ks = Knapack(data, limit)
        ks.solve()

        # ???????????¨???
        target = ks.C[len(data)][limit]
        weight = limit
        for w in range(limit, 0, -1):
            if ks.C[len(data)][w] == target:
                weight = w
        print('Case {0}:'.format(case_no))
        print('{0}\n{1}'.format(target, weight))
        case_no += 1

Measured memory_bytes: 19124