akhauriyash/Code-Regression huggingface dataset:
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[110][100010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll a[110];
    rep(i,0,N) cin >> a[i];
    dp[0][0] = 1;
    rep(i,0,N){
        rrep(j,K,0){
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= MOD;
            if(j + a[i] + 1 <= K+1) dp[i+1][j+a[i]+1] = (dp[i+1][j+a[i]+1] - dp[i][j] + MOD) % MOD;
        }
        rep(j,0,K+1) (dp[i+1][j+1] += dp[i+1][j]) %= MOD;
    }
    print(dp[N][K]);
    

}


Measured memory_bytes: 79488
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main() {
  int N;
  string s;
  cin>>N>>s;
  int cnt(1);
  for (int i(1);i<N;i++){
    if (s[i]!=s[i-1]){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

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

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

signed main() {
	int x;
	
	cin >> x;
	for (int i = 1; ; i++) {
		if ((360 * i) % x == 0) {
			cout << (360 * i) / x << endl;
			break;
		}
	}
	return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    int ans;
    rep(i,n) {
        int x; cin >> x;
        ans += min(x, abs(x-k));
    }
    cout << ans*2 << endl;
}

Measured memory_bytes: 3552
//abc123_a.cpp
//Tue Apr  9 08:08:24 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int k;
	int a[5];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;

	for (int i=0;i<4;i++){
		for (int j=i+1;j<5;j++){
			if (a[j]-a[i]>k){
				cout << ":(" << endl;
				return 0;
			}
		}
	}

	cout << "Yay!" << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
a, b, c = STDIN.readline().strip().split(' ').map(&:to_i)
def make_modulo(a, b)
  m = []
  sa = a
  while not m.include?(sa % b) do
    m << sa % b
    sa += a
  end
  # puts "#{m}"
  m
end
def check(m, c)
  m.include?(c)
end
puts "#{check(make_modulo(a, b), c) ? 'YES' : 'NO'}"


Measured memory_bytes: 1788
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,op,b = ism()
if op == '+':
    print(int(a)+int(b))
else:
    print(int(a)-int(b))

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

int main(){
    int a=5, b;
    while(cin >> a >> b){
    a += b;
    b = 0;
    while(a / 10 > 0){
     a /= 10;
     b++;
    }
    cout << b + 1<< endl;
  }
 return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int min = 1000000;
    int max = -1000000;
    long sum = 0;

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

      int tmp = scan.nextInt();
      min = Math.min(min, tmp);
      max = Math.max(max, tmp);
      sum += tmp;

    }
    
    System.out.println(min + " " + max + " " + sum);

  }
}


Measured memory_bytes: 41588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int M = reader.nextInt();
		int C = reader.nextInt();
		int[] B = new int[M];
		int count = 0;
		
		for (int i = 0; i < M; i++) {
			B[i] = reader.nextInt();
		}
		
		for (int i = 0; i < N; i++) {
			int result = C;
			for (int j = 0; j < M; j++) {
				 result += B[j] * reader.nextInt();
			}
			if (result > 0) {
				count++;
			}
		}
		System.out.print(count);
	}
}



Measured memory_bytes: 23252
#include <stdio.h>


int main(void){
  int a,b,data,cn;
  data = 1;
  cn = 0;
  scanf("%d %d",&a,&b );
if(b== 1){
}else{
  do{
    data += (a-1);
    cn++;
  }while(b>data);
}
  printf("%d\n",cn );

  return 0;
}


Measured memory_bytes: 128
# 38

import sys


def lcs(X, Y):
    l_x = len(X)
    l_y = len(Y)
    # dp[i][j] : Xのi文字目、Yのj文字目までから構成される最長部分列数
    dp = [[0] * (l_y+1) for _ in range(l_x+1)]
    for i in range(l_x):
        for j in range(l_y):
            if X[i] == Y[j]:
                dp[i+1][j+1] = dp[i][j]+1
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
    return dp[-1][-1]


def lcs_s(X, Y):
    L = []
    for yk in Y:
        bgn_idx = 0
        for i, cur_idx in enumerate(L):
            chr_idx = X.find(yk, bgn_idx) + 1
            if not chr_idx:
                break
            L[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = X.find(yk, bgn_idx) + 1
            if chr_idx:
                L.append(chr_idx)
    return len(L)


Q = int(input())
for _ in range(Q):
    X = sys.stdin.readline().rstrip()
    Y = sys.stdin.readline().rstrip()
    print(lcs_s(X, Y))



Measured memory_bytes: 5632
/*
      author : nishi5451
      created: 12.08.2020 15:43:34
*/

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


int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());
    rep(i,n) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3624
import numpy as np
N,L = map(int, input() . split())
x=[]
M = 0
N_list = np.array([])

for i in range(N):
  M += L + (i+1) - 1
  N_list = np.append(N_list, L + (i+1) - 1)
  
m = np.abs(N_list).argmin()

#M - N_list[m]
print(int(M - N_list[m]))
  
  

Measured memory_bytes: 12488
#include <bits/stdc++.h>
using namespace std;
#define N 1100
 
struct point {
	int x,y;
}a[N],b[N];
 
int n,ans;
bool use[N];
 
bool cmp(point a,point b) {
	return a.x<b.x;
}

int mp[105][105];
int visit[105],flag[105];

bool dfs(int a)
{
    for(int i=1; i<=n; i++)
    {
        if(mp[a][i]&&!visit[i])
        {
            visit[i]=1;
            if(flag[i]==0||dfs(flag[i]))
            {
                flag[i]=a;
                return true;
            }
        }
    }
    return false;
}
 
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
	for (int i=1;i<=n;i++) scanf("%d%d",&b[i].x,&b[i].y);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (b[i].x>a[j].x && b[i].y>a[j].y)
				mp[i][j]=1;

    memset(flag,0,sizeof(flag));
    for(int i=1;i<=n;i++)
    {
        memset(visit,0,sizeof(visit));
        if(dfs(i)) ans++;
    }
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
const int IMIN=(1<<31);
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Sort(unsigned *from,unsigned *to,unsigned bit)
{
  if(!bit||to<from+1)return;
  unsigned *left=from,*right=to-1;
  for(;;)
  {
    while(left<right&&!(*left&bit))left++;
    while(left<right&&(*right&bit))right--;
    if(left>=right)break;
    swap(left,right);
  }
  if(!(bit&*left)&&left<to)left++;
  bit>>=1;
  Sort(from,left,bit);
  Sort(left,to,bit);
}
static inline void Radix32(int *array,const int len)
{
  unsigned *x=(unsigned*)array;
  rep(i,len)x[i]^=IMIN;
  Sort(x,x+len,IMIN);
  rep(i,len)x[i]^=IMIN;
}
int main(void)
{
  int N=IN(),c=CH(),i=0,m=0,p=0,z=0,temp,A[N];
  long K=0,low=-1e18,mid,high=-low,count;while(c>47&&c<58){K=K*10+c-48,c=CH();}
  rep(j,N){A[j]=IN();if(A[j]<0)m++;else if(A[j]>0)p++;else z++;}
  Radix32(A,N);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;else temp=0;
  if(K<=1l*m*p)high=1l;else low=-1l;
  while(high-low>1)
  {
    mid=(low+high)/2,count=0;
    if(!mid)count=1l*m*p;
    else if(mid>0)
    {
      count=1l*m*p+1l*z*(m+p)+1l*z*(z-1)/2;temp=N-1;i=m+z;if(count>=K){high=mid;continue;}
      while(i<N){while(1l*A[temp]*A[i]>=mid){temp--;}if(temp>i)count+=1l*temp-i,i++;else break;}
      temp=0;i=m-1;if(count>=K){high=mid;continue;}
      while(i>=0){while(1l*A[temp]*A[i]>=mid){temp++;}if(temp<i)count+=1l*i-temp,i--;else break;}
    }
    else
    {
      temp=m-1;i=N-1;
      while(i>=m+z){while(temp>=0&&1l*A[temp]*A[i]>=mid){temp--;}if(temp>=0){count+=1l*temp+1;}i--;}
    }
    if(count<K)low=mid;else high=mid;
  }
  return OUT(low),0;
}

Measured memory_bytes: 2368
R, G, B, N = gets.split.map(&:to_f)
 
r_max = (N / R).floor
cnt = 0
for r in 0..r_max do
    now = N - (R * r)
    g_max = (now / G).floor
    for g in 0..g_max do
        now_g = now - (G * g)
        if now_g % B == 0 then
            cnt += 1
        end
    end
end
 
puts cnt

Measured memory_bytes: 1788
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m;
LL a, b, c;
vector<pair<int, LL>> v[101010];
LL d[2][101010];
 
void dfs(int id,int cur, LL cost){
	if(d[id][cur] == INF<LL>()){
		d[id][cur] = cost;
		REP(i, (int)v[cur].size())dfs(id^1, v[cur][i].first, v[cur][i].second - cost);
	}
	if(d[id][cur] != cost){
		cout << 0 << endl;
		exit(0);
	}
}
 
int main(){
	cin >> n >> m;
	REP(i, m){
		cin >> a >> b >> c;
		a--, b--;
		v[a].emplace_back(make_pair(b, c));
		v[b].emplace_back(make_pair(a, c));
	}
	REP(i, 2)REP(j, 101010)d[i][j] = INF<LL>();
	dfs(0, 0, 0);
	if(d[1][0] != INF<LL>()){
		LL num = abs(d[1][0] - d[0][0]);
		REP(i, 2)REP(j, 101010)d[i][j] = INF<LL>();
		dfs(0, 0, num/2);
		REP(i, n){
			if(min(d[0][i], d[1][i]) <= 0){
				cout << 0 << endl;
				return 0;
			}
		}
		cout << 1 << endl;
	}else{
		LL minl = 1, maxl = INF<LL>();
		REP(i, n){
			LL num = (d[0][i] == INF<LL>());
			if(num == 0)minl = max(minl, -d[num][i] + 1LL);
			else maxl = min(maxl, d[num][i] - 1LL);
		}
		cout << max(0LL, maxl - minl + 1LL) << endl;
	}
}

Measured memory_bytes: 21760
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, "")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()

        spl := strSprit(line)

        ret := 0

        for _, v := range spl {
                if v == "+" {
                        ret++
                } else {
                        ret--
                }
        }

        fmt.Println(ret)
}


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

using namespace std;

int n;
int a[50];
int b[50];

vector<int> g[51];
bool visited[51];

int max_a;

void init_graph()
{
  for (auto &l : g) l.clear();
}

void add_edge(int x, int y)
{
  if (x != y) g[x].push_back(y);
}

bool dfs(int x, int y)
{
  if (x == y) return true;
  if (visited[x]) return false;

  visited[x] = true;
  for (int z : g[x]) {
    if (dfs(z, y)) return true;
  }

  return false;
}

bool is_reachable(int max_k, vector<int> required)
{
  init_graph();
  for (int x = 0; x <= max_a; x++) {
    int is_child[51];
    fill_n(is_child, 51, false);
    for (int r : required) is_child[x % r] = true;
    for (int k = 1; k <= max_k; k++) is_child[x % k] = true;
    for (int i = 0; i <= max_a; i++)
      if (is_child[i]) {
        g[x].push_back(i);
      }
  }

  bool ok = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= max_a; j++) visited[j] = false;
    ok &= dfs(a[i], b[i]);
  }

  return ok;
}

int64_t mod_pow(int64_t a, int64_t b)
{
  if (b == 0) return 1;
  int64_t ret = mod_pow(a, b/2);
  ret = ret * ret;
  if (b % 2 == 1) ret = a * ret;
  return ret;
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];

  max_a = *max_element(a, a+n);

  if (!is_reachable(max_a, {})) {
    cout << -1 << endl;
  } else {
    vector<int> required;
    for (int max_k = max_a; max_k >= 0; max_k--)
      if (!is_reachable(max_k, required))
        required.push_back(max_k+1);

    int64_t cost = 0;
    for (int x : required)
      cost += mod_pow(2LL, x);

    cout << cost << endl;
  }
  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    (a <= c && c <= b) ? OP("Yes") : OP("No");
    return 0;
}

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

const ll INF = 1e18;
struct edge{
	int to;
	int cost;
};

// sを始点とした全頂点の最短経路長（ダイクストラ）
// sからtに到達不可ならば d[t] = INF
vector<ll> dijkstra(int s, vector<vector<edge>> &to){
	// <最短距離、頂点番号>
	typedef pair<ll,int> P;
	
	priority_queue<P, vector<P>, greater<P>> que;
	vector<ll> d(to.size(), INF);
	
	d[s] = 0;
	que.push(P(0,s));
	
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		
		for(edge e : to[v]){
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	
	return d;
}

int main(){
	
	int n,m;
	cin >> n >> m;
	
	vector<vector<edge>> to(n);
	rep(i,m){
		int l,r,c;
		cin >> l >> r >> c;
		--l; --r;
		to[l].push_back(edge{r,c});
		// for(int i = r; i > l; i--) to[i].push_back(edge{i-1,0});
	}
	
	rep(i,n-1) to[i+1].push_back(edge{i,0});
	
	vector<ll> d = dijkstra(0,to);
	
	if(d[n-1]==INF) cout << -1 << endl;
	else cout << d[n-1] << endl;
	return 0;
}


Measured memory_bytes: 7928
#include <stdio.h>
int main()
{
  int N;
  int M;
  int A[10000];
  int index;
  int total = 0;
  
  scanf("%d %d", &N, &M);
  for(index = 0; index < M; ++index){
    scanf("%d", &A[index]);
    total += A[index];
  }
  
  if(total > N)
    printf("-1\n");
  else
    printf("%d\n", (N - total));
  return 0;
}

Measured memory_bytes: 1740
#include<stdio.h>
#include<math.h>
#include<float.h>
#include<algorithm>
int main()
{
	int n,i,j,k;
	double x[100],y[100],vx,vy,dx,dy,s,t;
	while(scanf("%d",&n),n)
	{
		int a=n,f[100]={};
		for(i=0;i<n;++i)scanf("%lf,%lf",x+i,y+i);
		k=std::min_element(y,y+n)-y;
		vx=1,vy=0;
		for(;;)
		{
			if(f[k]++)break;
			--a;
			for(s=-DBL_MAX,i=0;i<n;++i)
			{
				if(k-i)	
				{
					dx=x[i]-x[k];
					dy=y[i]-y[k];
					t=(vx*dx+vy*dy)/hypot(dx,dy);
					if(s<t)s=t,j=i;
				}
			}
			vx=x[j]-x[k];
			vy=y[j]-y[k];
			k=j;
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
m_list = list()
for _ in range(n):
    a, b = map(int, input().split())
    m_list.append([b, a])
m_list.sort()
c = 0
for x in m_list:
    c += x[1]
    if x[0] < c:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 35608
#abc107b

h,w=map(int,input().split())
a=[]
for i in range(h):
 t=input()
 if t=='.'*w:
  continue
 a.append(list(t))
b=list(map(list, zip(*a)))
c=[]
for i in range(len(b)):
 if all(x=='.' for x in b[i]):
  continue
 c.append(b[i])
l=list(map(list, zip(*c)))
for i in range(len(l)):
 print(''.join(l[i]))


Measured memory_bytes: 39408
#include<stdio.h>

int main(void)
{
  int num;
  scanf("%d",&num);

  int i;
  double a[num];
  for(i=0;i<num;i++)
    scanf("%lf",&a[i]);

  double tmp=(1/a[0]);
  for(i=1;i<num;i++)
    tmp+=(1/a[i]);

  printf("%f\n",1/tmp);
  return 0;
}


Measured memory_bytes: 128
function main(input) {
  const s = input.trim();
  let pattern1 = 0;
  let pattern2 = 0;
  for (let i = 0; i < s.length; i++) {
    const char = s[i];
    if (i%2 === 0 && s[i] === "0") {
      pattern2++;
    } else if (i%2 === 0 && s[i] === "1") {
      pattern1++;
    } else if (i%2 === 1 && s[i] === "0") {
      pattern1++;
    } else if (i%2 === 1 && s[i] === "1") {
      pattern2++;
    }
  }
  const result = Math.min(pattern1, pattern2);
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> k;
   if (k >= (1 << n) || (n == 1 && k == 1)) cout << -1, exit (0);
   if (k == 0) {
      for (int i = 0; i < (1 << n); i ++)
         cout << i << ' ' << i << ' ';
      exit (0);
   }
   cout << "0 " << k << " 0 ";
   for (int i = 1; i < (1 << n); i ++)
      if (i != k)
         cout << i << ' ';
   cout << k << ' ';
   for (int i = (1 << n) - 1; i >= 1; i --)
      if (i != k)
         cout << i << ' ';
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func print(msg string) {
	fmt.Println(msg)
}

func printi(msg int) {
	fmt.Println(msg)
}

func main() {
	var (
		a     string
		count = 0
	)
	fmt.Scan(&a)

	for i := 0; i < len(a); i++ {
		if a[i] == '1' {
			count++
		}
	}

	printi(count)
}


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

int N, M, K;
map<int, long long> cnt[2];

int main(){
	while(cin >> N >> M >> K, N){
		cnt[0].clear();
		cnt[0][0] = 1;
		for(int i = 0; i < N; i++){
			cnt[(i+1)%2].clear();
			for(auto e : cnt[i % 2]){
				for(int k = 1; k <= M; k++){
					cnt[(i+1)%2][e.first+k] += e.second;	
				}
			}
		}
		
		long long sum = 0;
		for(auto e : cnt[N%2]) sum += e.second;
		double ans = 0;
		for(auto e : cnt[N%2]){
			if(e.first <= K) ans += (double)e.second / sum; 
			else ans += (double)e.second * (e.first - K) / sum; 
		}
		printf("%.10lf\n", ans);

	}
}

Measured memory_bytes: 3772
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int n,c=0,T=0;
char a[505][505];
pii u[2][505][505];
inline pii operator + (pii a,pii b)
{return pii(min(a.fi,b.fi),max(a.se,b.se));}
int vis[505][505];
void dfs(int x,int y)
{
	if(vis[x][y]==T||!isdigit(a[x][y]))
		return;
	vis[x][y]=T; dfs(x,y+1); dfs(x+1,y);
}
ll su[505][505];
int main()
{
	scanf("%d",&n);
	ll aa=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%s",a[i]+1);
		for(int j=1;j<=n;++j)
		{
			if(isdigit(a[i][j]))
			{
				int u=a[i][j]-'0';
				aa-=u*u;
			}
		}
	}
	pii GG(2e9,-2e9);
	for(int i=0;i<=n+1;++i)
	for(int j=0;j<=n+1;++j)
		u[0][i][j]=u[1][j][i]=GG;
	for(int i=n;i>=1;--i)
	{
		T=i; c^=1;
		for(int j=1;j<=n;++j) dfs(i,j);
		for(int k=i;k<=n;++k)
			for(int w=1;w<=n;++w)
				if(vis[k][w]==T)
					su[k][w]=su[k][w-1]+a[k][w]-'0';
				else su[k][w]=su[k][w-1];
		for(int j=n;j>=1;--j)
		{
			pii*ucj=u[c][j],*ucp=u[c][j+1],*rcj=u[c^1][j];
			if(!isdigit(a[i][j]))
			{
				for(int k=i;k<=n;++k)
					ucj[k]=GG;
				continue;
			}
			ucj[i]=pii(j,j)+ucp[i];
			ll ap=0;
			if(ucj[i].fi<=ucj[i].se)
				ap+=su[i][ucj[i].se]-su[i][ucj[i].fi-1];
			for(int k=i+1;k<=n;++k)
			{
				ucj[k]=rcj[k]+ucp[k];
				if(ucj[k].fi<=ucj[k].se)
				ap+=su[k][ucj[k].se]-su[k][ucj[k].fi-1];
			}
			aa+=ap*(a[i][j]-'0');
		}
	}
	cout<<aa<<"\n";
}


Measured memory_bytes: 7424
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            if (nm.All(i => i == 1)) Console.WriteLine(1);
            else if (nm.Any(i => i == 1)) Console.WriteLine(nm.Max() - 2);
            else Console.WriteLine(nm[0] * nm[1] - 2 * (nm.Sum()) + 4);
        }
    }
}

Measured memory_bytes: 13268
import math
 
def calculate_length(A,B,theta):
    radian=math.radians(theta)
    length=(A**2)+(B**2)-(2*A*B*math.cos(radian))
    return  math.sqrt(length)

def main():
    A,B,H,M = map(int,input().split())
    thetaA=H*30+M*0.5
    thetaB=M*6
    if thetaA == thetaB:
        print(abs(A-B))
    else:
        if thetaA > thetaB:
            theta=thetaA-thetaB
        elif thetaA < thetaB:
            theta = thetaB-thetaA
        length=calculate_length(A,B,theta)
        print(length)

if __name__=="__main__":
    main()

Measured memory_bytes: 9352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST
{

    static void Main()
    {


        var n = long.Parse(Console.ReadLine());
        long[] div = new long[n+1];
        long sum = 0;
        for(int i=0;i<=n;i++)
        {
            div[i] = 1;
        }
        for (int i = 2; i <= n; i++)
        {
            for (int j = i; j <=n; j = j + i)
            {
                div[j]++;
            }

        }

        for(long i=1;i<=n;i++)
        {
            sum = sum + (i * div[i]);
        }

        Console.Write(sum);

    }

}


Measured memory_bytes: 94836
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
static const int MAX = 1000;
static const int VMAX = 10000;
int n, A[MAX], s;// n???????´???°???A?????\??????s?????\??????????°????
int B[MAX], T[VMAX + 1];
int solve() {
	int ans(0);
	bool V[MAX];
	for (int i = 0; i < n; i++) {
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B + n);
	for (int i = 0; i < n; i++)T[B[i]] = i;
	for (int i = 0; i < n; i++) {
		if (V[i])continue;
		int cur = i;
		int S = 0;// sum of values in a cycle
		int m = VMAX;//minimum value in a cycle
		int an = 0;// number of values in a cycle
		while (1) {
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if (V[cur])break;
		}
		ans += min(S + (an - 2)*m, m + S + (an + 1)*s);
	}
	return ans;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	s = VMAX;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		s = min(s, A[i]);
	}
	cout << solve() << endl;
	return 0;
}

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

long L(long a, long b){ //  a<b
    long q,r;
    if(a==0){
        return -b;
    }else{
        q=b/a, r=b%a;
        return 2*q*a+L(r,a);
    }
}

int main(){
    long N,X;
    cin >> N >> X;
    if(X<N-X){
        cout << L(X,N-X)+N << endl;
    }else{
        cout << L(N-X,X)+N << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s, k, t = input(), int(input()), ""
for q in s:
    if (p := (123 - ord(q)) % 26) <= k:
        k -= p
        t += "a"
    else:
        t += q
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))

Measured memory_bytes: 9404
using System;
using System.Linq;

namespace testes
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);

            int C = A - 2 * B;
            if (C < 0) C = 0;
            Console.WriteLine(C);

           
        }

        static bool AAABBB(long target, long N,long K, long[] F, long[] A)
        {
            long count = 0, need;
            for (long i = 0; i < N; i++)
            {
                need = target / F[i];
                count += Math.Max(0, A[i] - need);
            }
            return count <= K;
        }
        public static long LIS(long[] c)
        {
            // 部分数列和
            long count = 1;
            long N = c.Length;
            long[] array = new long[N];
            array[0] = c[0];

            for (long i = 1; i < N; i++)
            {
                //for (long p = 0; p < N; p++) Console.Write($"{array[p]},");
                // Console.WriteLine("");
                if (array[count - 1] < c[i])
                {
                    array[count] = c[i];
                    count++;
                    continue;
                }
                for (long j = count - 2; j >= 0; j--)
                {
                    if (array[j] < c[i])
                    {
                        array[j + 1] = c[i];
                        break;
                    }
                }
                if(array[0] > c[i])array[0] = c[i];
            }
            return count;
        }
        public static void Rotation(char[] array, long l, long r)
        {          
        }      
    }   
}

/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <set>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    string s,t;

    cin >> s >> t;
    int comp = stoi(s+t);

    for (int i = 1; i <= comp; ++i)
    {
        if(comp==i*i)
        {
            cout << "Yes" << "\n";
            return 0;
        }
        else if(comp < i*i)
        {
            cout << "No" << "\n";
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= a && c <= a+b) cout << "YES";
  else cout << "NO";
    return 0;
}

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

#define Bye return 0
const int MAX = 1e9+7;

void solve(){
    int n, res = 1; cin>>n;
    int a[n+1];
    memset(a, 0, sizeof a);

    for (int i=1; i<=n; i++){ int e; cin>>e; a[e]++;}
    int counter = (n%2^0) ? (n-1)/2 :  n/2;
    for (int i=1; i<=counter; i++) res = (res*2)%MAX;
  
    bool isValid = false;
    for (int i=0; i<n; i+=2) isValid += 
      ((i+2<n && a[i+2]^2 && n%2^0)  || 
      (i+1<=n-1 && a[i+1]^2 && !(n%2^0)));
    
    cout<<((!isValid) ? res : 0)<<endl;
}

int main()
{
    solve();
    Bye;
}


Measured memory_bytes: 3960
import bisect


n = int(input())
dots = []

for _ in range(n):
    a, b = map(int, input().split())
    dots.append([a, b, 0])

for _ in range(n):
    c, d = map(int, input().split())
    dots.append([c, d, 1])

dots.sort(reverse=True)

blues = []
count = 0
for x, y, color in dots:
    if color == 1:
        bisect.insort(blues, y)
    else:
        pair_idx = bisect.bisect_left(blues, y)
        if pair_idx == len(blues):
            continue
        else:
            count += 1
            blues.pop(pair_idx)

print(count)

Measured memory_bytes: 3188
N = int(input())
A = [None] + list(map(int, input().split()))

dp = [None]*(N+1)
for i in range(N, 0, -1):
    a = A[i]
    for j in range(2*i, N+1, i):
        a -= dp[j]
    dp[i] = (a % 2)
dp = dp[1:]
print(sum(dp))
for i in range(N):
    if dp[i]:
        print(i+1)

Measured memory_bytes: 72028
sel='D'
if sel=='D':
    def fact(n,mod):
        ret=1
        for i in range(2,n+1):
            ret=(ret*i)%mod
        return ret

    N,A,B=map(int,input().split())
    MOD=10**9+7
    ANS=(pow(2,N,MOD)-1)%MOD # 全通り
    
    def pCq(p,q,mod):
        pCq=1
        for i in range(q):
            pCq*=p-i
            pCq=pCq%mod
        den=fact(q,mod)
        inv=pow(den,mod-2,mod)
        pCq=(pCq*inv)%mod
        return pCq
    
    ANS-=pCq(N,A,MOD)+pCq(N,B,MOD)
    ANS=ANS%MOD
    print(ANS)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=getInt(),m=getInt(),p[]=new int[m];
		for(int i=0;i<m;i++) {
			p[i]=getInt();
			s.next();
		}
		System.out.println(Arrays.stream(p).map(i->Math.max(0,n-i)).sorted().limit(m-1).sum());
	}
}

Measured memory_bytes: 40404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String str = sc.next();
		String ss[] = new String[4];
		sc.close();
		
		for(int i = 0; i < 4; i++) {
			ss[i] = str.substring(i , i + 1); 
		}
		
		String sa = str.replace(ss[0], "");
		if(sa.length() == 0) {
			System.out.println("No");
			return;
		}
		
		int target = 0;
		for(int i = 1; i < 4; i++) {
			if(ss[i].equals(ss[0])) {
				target = i;
				break;
			}
			if(i == 3) {
				System.out.println("No");
				return;
			}
		}
		
		if(target == 1){
		      if(ss[2].equals(ss[3])){
		        System.out.println("Yes");
		      }else{
		        System.out.println("No");
		      }
		    }else if(target == 2){
		      if(ss[1].equals(ss[3])){
		        System.out.println("Yes");
		      }else{
		        System.out.println("No");
		      }
		    }else{
		      if(ss[1].equals(ss[2])){
		        System.out.println("Yes");
		      }else{
		        System.out.println("No");
		      }
		 }
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N,T; cin>>N>>T;
	vector<int> ans;
	for(int i=0;i<N;i++){
		int c,t; cin>>c>>t;
		if(t<=T)ans.push_back(c);
	}
	if(ans.size()==0)cout<<"TLE"<<endl;
	else cout<<*min_element(ans.begin(),ans.end());
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,t,ans=0;
	cin>>a>>b>>c;
	for(int i=0;i<a;i++){
		cin>>t;
		if(t<b||t>=c)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
n, y = [int(e) for e in raw_input().split()]
for i in range(n + 1):
  for j in range(n + 1 - i):
    k = n - i - j
    if 10000 * i + 5000 * j + 1000 * k == y:
      print "%d %d %d" % (i, j, k)
      sys.exit()
print "-1 -1 -1"


Measured memory_bytes: 2692
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as B
import Data.List

solve :: B.ByteString -> B.ByteString -> B.ByteString -> B.ByteString
solve s t acc
    | B.null s = "UNRESTORABLE"
    | lt /= ls = "UNRESTORABLE"
    | res = B.append (conv ds) $ B.append (B.reverse t) (conv acc)
    | otherwise = solve (B.tail s) t (B.snoc acc (B.head s))
    where
        res = and $ B.zipWith search ts t
        ts = B.take lt s
        ds = B.drop lt s
        lt = B.length t
        ls = B.length ts
        search a b
            | a == '?' = True
            | a == b = True
            | otherwise = False
        conv xs = B.foldl' (\acc x -> if x == '?' then B.cons 'a' acc else B.cons x acc) "" xs

main = do
    s <- B.getLine
    t <- B.getLine
    B.putStrLn $ solve (B.reverse s) (B.reverse t) ""


Measured memory_bytes: 508
import java.util.Scanner;

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

class Problem {
	void solve() {
		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();
		
		int right = x + r;
		int left = x - r;
		int top = y + r;
		int bottom = y - r;
		
		if (right <= w 
				&& left >= 0 
				&& top <= h 
				&& bottom >= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main() {
    int h;
    int n;
    int a[100100];

    cin >> h >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    
    for (int i=0; i<n; i++) {
        h -= a[i];
        if (h <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

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

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int N, A, B, C, X;
int y[102];

bool input(){
  cin>>N>>A>>B>>C>>X;
  REP(i, N)cin>>y[i];
  return N|A|B|C|X;
}

void solve(){
  int c=0, f=0;
  REP(i, 10001) {
    if(y[c]==X)c++;
    if(c==N)break;
    X = (A*X+B)%C;
    f++;
  }
  if(c<N)cout<<-1<<endl;
  else cout<<f<<endl;
}

int main(){
  cin.tie(0);
  
  while (input()){
      solve();
  }
  
  return 0;
}

Measured memory_bytes: 2972
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  int N ;
  cin >> N ;
  double ans = 0.0, X[N], Y[N], Xdis, Ydis ;
  for(int i=0;i<N;i++){
    cin >> X[i] >> Y[i] ;
  }
  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      Xdis = X[i] - X[j] ;
      Ydis = Y[i] - Y[j] ;
      ans += 2.0 * sqrt(Xdis * Xdis + Ydis * Ydis) / N ;
    }
  }
  cout << fixed << setprecision(10) << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

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

		String S = in.readLine();

		int win = 0;
		int lose = 0;
		for (int i = 0; i < S.length(); ++i) {
			if (S.charAt(i) == 'o') {
				++win;
			} else {
				++lose;
			}
		}
		if (lose < 8) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21844
from collections import Counter, deque

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
con = Counter(t)
ans = con['r'] * p + con['s'] * r + con['p'] * s
dic = {'r': p, 's': r, 'p': s}
for i in range(k):
    target = deque(list(t[i::k]))
    hp = 0
    count = 1
    while target:
        hn = target.popleft()
        if hp == hn:
            count += 1
        elif count > 1:
            ans -= count // 2 * dic[hp]
            count = 1
        hp = hn
    else:
        ans -= count // 2 * dic[hp]
print(ans)


Measured memory_bytes: 4972
#include<bits/stdc++.h>//万能头文件
using namespace std;
int main()
{
    long long x,a,b,c,ans=0;//long long保险
    cin>>a>>b>>c>>x;//输入这四个数
    for(int i=0;i<=a;i++)//枚举500硬币的个数
        for(int j=0;j<=b;j++)//枚举100硬币的个数
            for(int z=0;z<=c;z++){//枚举50硬币的个数
                int k=i*500+j*100+z*50;//定义k为此时硬币总值
                if(k==x)//如果就是x
                   ans++;//计数器加一
                if(k>x)//这是一个优化，如果k值已经超过了x，后面的z到c时k的值一定大于x，肯定不等于x，所以可以直接退出当前循环
                   break;//退出当前循环
            }
    cout<<ans<<endl;//输出ans的值(AT题都要打换行)
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
using itn = int;
template<class T>
using vec = vector<T>;

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()

int main(){
  itn n,y;
  cin >>n >>y;

  int a=-1,b=-1,c=-1;
  REP(i,n+1){
    REP(j,n+1-i){
      if(10000*i+5000*j+1000*(n-i-j) == y){
        a = i;
        b = j;
        c = n-i-j;
      }
    }
  }

  cout <<a <<" " <<b <<" " <<c <<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int A, B;
    cin >> A >> B;

    print(max(0, A - 2 * B));
    
}


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

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  
  int dx = tx - sx;
  int dy = ty - sy;
  
  for(int i=0; i<dx; i++) cout << "R";
  for(int i=0; i<dy; i++) cout << "U";
  for(int i=0; i<dx; i++) cout << "L";
  for(int i=0; i<dy; i++) cout << "D";

  cout << "D";
  for(int i=0; i<dx+1; i++) cout << "R";
  for(int i=0; i<dy+1; i++) cout << "U";
  cout << "LU";
  for(int i=0; i<dx+1; i++) cout << "L";
  for(int i=0; i<dy+1; i++) cout << "D";
  cout << "R" << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, m;
int x[100000 + 5], md[100000 + 5], nokori[100000 + 5], pa[100000 + 5];
map<int, int> same;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, n) {
        cin >> x[i];
        md[x[i] % m]++;
        same[x[i]]++;
    }
    for (auto p : same) {
        pa[p.fi % m] += p.se / 2;
        if (p.se % 2 == 1) {
            nokori[p.fi % m]++;
        }
    }
    //rep(i, m) cout << nokori[i] << endl;
    int ans = md[0] / 2;
    if (m % 2 == 0) ans += md[m / 2] / 2;
    rep2(i, 1, m) {
        if (m % 2 == 0 && m / 2 == i) continue;
        ans += pa[i];
    }
    rep2(i, 1, m / 2 + 1) {
        if (m % 2 == 0 && i == m / 2) continue;
        if (nokori[i] < nokori[m - i]) {
            swap(nokori[i], nokori[m -i]);
            swap(pa[i], pa[m - i]);
        }
        ans += nokori[m - i];
        //cout << nokori[i] << " " << nokori[m - i] << endl;
        nokori[i] -= nokori[m - i];
        if (pa[m - i] * 2 >= nokori[i]) {
            if (nokori[i] % 2 == 0) {
                ans -= nokori[i] / 2;
                ans += nokori[i];
            }
            else {
                ans -= nokori[i] / 2;
                ans += nokori[i] - 1;
            }
        }
        else {
            ans -= pa[m - i];
            ans += pa[m - i] * 2;
        }

    }

    cout << ans << endl;
}


Measured memory_bytes: 9600