akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string expr;
int pos, p;
bool valid;
int exprression();
int term();
int factor();
int power(int x, int n){
  if ( n == 0 ) return 1;
  int res = power(x*x%p, n/2);
  if ( n & 1 ) res = res*x%p;
  return res;
}

int exprression(){
    int value = term();
    while( expr[pos] == '+' || expr[pos] == '-' ){
    if ( expr[pos] == '+' ) {
        pos++; value = (value + term())%p;
    } else {
        pos++;
        int m = p - term();
        value = (value + m)%p;
    }
    }
    return value;
}

int term(){
    int value = factor();
    while( expr[pos] == '*' || expr[pos] == '/' ){
    if ( expr[pos] == '*' ) {
        pos++;
        value = (value*factor())%p;
    } else {
        pos++;
        int f = factor();
        if ( f == 0 ) { valid = false; return 0;}
        int d = power(f, p-2);
        value = (value*d)%p;
    }
    }
    return value;
}

int factor(){
    int value = 0;
    if ( expr[pos] == '(' ){
    pos++; value = exprression(); pos++;
    } else {
    while( isdigit(expr[pos]) ) { value = value*10 + expr[pos] - '0'; pos++;}
    }
    return value;
}


int main(){
    char ch;
    while(1){
    cin >> p >> ch;
    if ( p == 0 ) break;
    expr = "";
    while(1) {
      scanf("%c", &ch);
      if ( ch == ' ' ) continue;
      if ( ch == '\n' ) break;
      expr += ch;
    }
    pos = 0;
    valid = true;
    int ans = exprression();
    if ( !valid ) {
        cout << "NG" << endl;
    } else {
        cout << expr << " = " << ans << " (mod " << p << ")" << endl;
    }
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[100010];
  int m1[100010] = {};
  int m2[100010] = {};

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


  for(int i = 0;i < n;i++){
    if(i % 2 == 0){
      m1[a[i]]++;
    }else{
      m2[a[i]]++;
    }
  }


  int m1max_cnt = 0;
  int m1max_num;
  int m1max2_cnt = 0;
  for(int i = 1;i < 100010;i++){
    if(m1max_cnt < m1[i]){
      m1max2_cnt = m1max_cnt;
      m1max_cnt = m1[i];
      m1max_num = i;
    }else if(m1max2_cnt < m1[i]){
      m1max2_cnt = m1[i];
    }
  }

  int m2max_cnt = 0;
  int m2max_num;
  int m2max2_cnt = 0;
  for(int i = 1;i < 100010;i++){
    if(m2max_cnt < m2[i]){
      m2max2_cnt = m2max_cnt;
      m2max_cnt = m2[i];
      m2max_num = i;
    }else if(m2max2_cnt < m2[i]){
      m2max2_cnt = m2[i];
    }
  }

  if(m1max_num != m2max_num){
    cout << n/2-m1max_cnt + n/2-m2max_cnt << endl;
  }else{
    if(m1max_cnt > m2max_cnt){
      cout << n/2-m1max_cnt + n/2-m2max2_cnt << endl;
    }else if(m1max_cnt < m2max_cnt){
      cout << n/2-m2max_cnt + n/2-m1max2_cnt << endl;
    }else{
      cout << n/2-m1max_cnt + n/2-max(m1max2_cnt,m2max2_cnt) << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 1408
#define _USE_MATH_DEFINES // M_PIなどの定義を使用するのに必要
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

int main()
{
  int64_t N, K;
  vector<bool> having_flag_table;

  cin >> N >> K;

  having_flag_table.resize(N, false);

  for (int64_t i = 0; i < K; i++) {
    int64_t d;
    cin >> d;
    for (int64_t k = 0; k < d; k++) {
      int64_t a;
      cin >> a;
      having_flag_table[a - 1] = true;
    }
  }

  int64_t ans = 0;
  for (auto &&i : having_flag_table) {
    if (!i) ans++;
  }

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


Measured memory_bytes: 3632
s = input()
sa = s[::2]
sb = s[1::2]

sa1, sb1 = sa.count('0'), sb.count('1')
ty1 = sa1 + sb1
ty2 = len(s) - sa1 - sb1
if ty1 > ty2:
  print(ty2)
else:
  print(ty1)

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>


int min(int a, int b) {
    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int mins(int start[], int len) {
    int res = start[0];
    for (int i = 1; i < len; ++i) {
        if (start[i] < res) {
            res = start[i];
        }
    }
    return res;
}

int main() {
    int n,k;
    scanf("%d %d\n", &n, &k);

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

    int dp[n];
    dp[0] = 0;
    int step[k];
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < k && j < i; ++j) {
            step[j] = dp[i-j-1] + abs(h[i]-h[i-j-1]);
        }
        dp[i] = mins(step, min(i,k));
    }

    printf("%d\n", dp[n-1]);
}

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

using namespace std;

using ll = long long;

ll calc(ll x, int i) {
    string s = to_string(x);
    ll y = s[i] - '0' + s[i + 1] - '0';
    string res = "";
    for (int j = 0; j < s.size(); j++) {
        if (j == i + 1) continue;
        if (j == i) {
            res += to_string(y);
            continue;
        }
        res += s[j];
    }
    return stoll(res);
}

int memo[10] = {0, 10, 10, 4, 10, 10, 4, 10, 10, 2};
int cnt[10] = {0, 10, 11, 4, 13, 14, 5, 16, 17, 2};

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

    int n;
    cin >> n;
    vector<int> d(n);
    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i] >> c[i];
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (d[i] == 0) {
            ans += c[i];
            continue;
        }

        while (c[i] >= memo[d[i]]) {
            ans += c[i] / memo[d[i]] * cnt[d[i]];
            c[i] = c[i] / memo[d[i]] + c[i] % memo[d[i]];
        }

        c[i] = stoll(string(c[i], (char)('0' + d[i])));
        while (c[i] >= 10) {
            c[i] = calc(c[i], 0);
            ans++;
        }
    }

    string big = "";
    for (int i = 0; i < n; i++) {
        if (d[i] == 0) continue;
        big += (char)('0' + c[i]);
    }

    while (big.size() > 1) {
        char c1 = big.back();
        big.pop_back();
        char c2 = big.back();
        big.pop_back();
        int val = c1 - '0' + c2 - '0';
        ans++;
        big += to_string(val);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2948
a,b,c = input().split()
a = int(a)
b= int(b)
c = int(c)

if 1 <= a <= 100:
    if 1 <= b<= 100:
        if 1 <= c <= 100:
            p = a + b
            q = b + c
            r = c + a

            lista = [p,q,r]
            print(min(lista))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 110;
const int MAX_W = 100100;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    ll v[N + 1], w[W + 1];
    for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
    ll dp[N + 1][W + 1] = {};
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j <= W; j++)
        {
            if(j - w[i] < 0) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}



Measured memory_bytes: 79232
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fr first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FILL(x) memset(x,0,sizeof(x))
#define prv(v) for(auto sss:v) cout<<sss<<"   "
#define dbg(x) cout<<"Debug   "<<x << endl


class Node
{
public:
	Node * left;
	Node* right;
	int data;
	Node(int x) {
		data = x;
		left = right = NULL;
	}
	~Node();
};

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int cnt = 0;
	for(int i=0 ; i<s.size()/2 ; i++){
		if(s[i] != s[s.size()-i-1]){
			cnt++;
		}
	}
	cout << cnt << "\n";


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
  double a,b,c;
  scanf("%lf",&a);
  scanf("%lf",&b);
  scanf("%lf",&c);
  double result;
  result = a / c;
  if(result <= b){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}
  


Measured memory_bytes: 2184
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      d: i64,
      xy: [(i64, i64); n]
   }
   let mut ans = 0;
   for (x, y) in xy {
      if d*d >= x*x+y*y {
         ans += 1;
      }
   }
   println!("{}", ans);
}


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

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

  int nsize = (int)s.size();

  char sarry[nsize];
  char ans[nsize];
  for(int i = 0; i < s.size(); ++i){
    sarry[i] = s[i];
    ans[i] = s[i];
  }
  
  int mid;
  if(nsize%2==0){
    mid = nsize/2;
  }else{
    mid = (nsize-1)/2;
  }

  int flag = 0;  
  for(int i = 0; i < mid; ++i){
    if(ans[i] == sarry[nsize-1-i]){
      continue;
    }else{
      ans[i] = sarry[nsize-1-i];
      flag++;
    }
  }

  cout << flag << endl;

}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1): #AだとA-1までループされないの気をつけてね
    for b in range(B+1):
        for c in range(C+1):
            if(a*500 + b*100 + c*50 == X):
                ans = ans + 1
                
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const int MOD=1000000007;

int main(){
    ll n;cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    ll ans=0;
    for(int i=0; i<60; i++){
        ll m=0;
        for(int j=0; j<n; j++){
            if(a[j]>>i&1) m++;
        }
        ll sum=m*(n-m)%MOD;
        for(int j=0; j<i; j++) sum=sum*2%MOD;
        ans+=sum;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
#define max 1000
#define inf 1000000
#define b 2
#define w 0
#define true 1
int vertex_num,admat[max][max];

void Dijkstra(){
  int vertex,min_vertex;
  struct d{
  int distance,parent,color;
  }dijk[max];
  
  int i,j;
  //初期化
  for(i=0;i<vertex_num;i++){
    dijk[i].distance=inf;
    dijk[i].color=w;
  }
  
  dijk[0].distance=0;
  dijk[0].color=1;
  
  while(true){
    min_vertex=inf;
    vertex=-1;
    for(i=0;i<vertex_num;i++){
      if(dijk[i].distance<min_vertex && dijk[i].color!=b){
        vertex=i;
        min_vertex=dijk[i].distance;
      }
    }
    if(vertex==-1){
      break;
    }
    dijk[vertex].color=b;
    for(i=0;i<vertex_num;i++){
      if(dijk[i].color!=b && admat[vertex][i]!=inf){
        if(dijk[vertex].distance+admat[vertex][i]<dijk[i].distance){
          dijk[i].distance=dijk[vertex].distance+admat[vertex][i];
          dijk[i].color=1;
        }
      }
    }
  }
  for(i=0;i<vertex_num;i++){
    printf("%d ",i);
    if(dijk[i].distance==inf){
      printf("-1\n");
    }else{
      printf("%d\n",dijk[i].distance);
    }
  }
}




int main(){
  int i,j;
  int vertex,num,min_ver;

  scanf("%d",&vertex_num);
  for(i=0;i<vertex_num;i++){
    for(j=0;j<vertex_num;j++){
    admat[i][j]=inf;
    }
  }
  
  for(i=0;i<vertex_num;i++){
    scanf("%d",&vertex);
    scanf("%d",&num);
    for(j=0;j<num;j++){
      scanf("%d",&min_ver);
      scanf("%d",&admat[vertex][min_ver]);
    }
  }
  Dijkstra();
  return 0;
}

/*この問題はダイクストラ法、単一始点最短経路に関する問題
入力
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
出力
0 0
1 2
2 2
3 1
4 3
*/



Measured memory_bytes: 2132
l, r = gets.split.map &:to_i
l %= 2019 * 2
r %= 2019 * 2
if l > r
  puts 0
  exit 0
end
 
res = 2019
 
 
l.upto(r) do |i| 
    r.downto(l) do|j|
        break if i >= j
        break if res == 0
        res = [res, (i * j) % 2019].min
    end
end
 
puts res

Measured memory_bytes: 1788
// 問題の URL を書いておく
// https://atcoder.jp/contests/agc031/tasks/agc031_a

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

const int M = 1000000007;
#if 1
int main(int, const char**)
{
    map<char, int> counts;
    int n;
    cin >> n;
    ll ans = 1;
    string s;
    cin >> s;
    for(auto c : s)
    {
        if(counts.find(c) == counts.end())
        {
            counts[c] = 0;
        }
        counts[c]++;
    }

    for(auto c : counts)
    {
        ans *= (c.second + 1);
        ans %= M;
    }
    cout << (ans - 1 + M) % M << endl;

    return 0;
}
#else
int main(int, const char**)
{
    set<char> dup;
    int n;
    cin >> n;
    int prev = 0;
    int ans = 0;
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    for(auto c : s)
    {
        if(dup.find(c) == dup.end())
        {
            prev = ans;
            ans = ans * 2 % M + 1;
            ans %= M;
            dup.insert(c);
        }
        else
        {
            ans = (ans + prev + 1) % M;
        }
    }
    cout << ans << endl;

    return 0;
}
#endif

Measured memory_bytes: 3724
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

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

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> city;

const int MAXN = 1e5 + 5;
const ll INF = 1e15;

int N, M, S, T;
vector <pii> E1[MAXN], E2[MAXN];
ll distS[MAXN], distT[MAXN];
ll ans[MAXN];

void load() {
	scanf("%d%d%d%d", &N, &M, &S, &T);
	while (M--) {
		int u, v, a, b;
		scanf("%d%d%d%d", &u, &v, &a, &b);
		E1[u].push_back({v, a});
		E1[v].push_back({u, a});
		E2[u].push_back({v, b});
		E2[v].push_back({u, b});
	}
}

void dijkstra(int src, ll dist[MAXN], vector <pii> E[MAXN]) {
	for (int i = 1; i <= N; i++)
		dist[i] = INF;
	dist[src] = 0;
	
	set <city> curr;
	for (int i = 1; i <= N; i++)
		curr.insert({dist[i], i});
	
	while (!curr.empty()) {
		int x = curr.begin() -> second;
		curr.erase(curr.begin());
		for (auto it : E[x]) {
			ll tmp = dist[x] + it.second;
			if (tmp < dist[it.first]) {
				curr.erase({dist[it.first], it.first});
				dist[it.first] = tmp;
				curr.insert({dist[it.first], it.first});
			}
		}
	}
}

void solve() {
	dijkstra(S, distS, E1);
	dijkstra(T, distT, E2);
		
	for (int i = N; i; i--) {
		ans[i] = distS[i] + distT[i];
		if (i < N)
			ans[i] = min(ans[i], ans[i + 1]);
	}
	
	for (int i = 1; i <= N; i++)
		printf("%lld\n", INF - ans[i]);
}

int main() {
	load();
	solve();
	return 0;
}

Measured memory_bytes: 22400
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        long x = in.nextLong();
        long[]candies = new long[n];
        long s=0;long total;long over;
        candies[0] = in.nextLong();
        for(int i=1;i<n;i++){
            candies[i] = in.nextLong();
            total= candies[i]+candies[i-1];
            over = total-x;
            if (over>0){
                long remove = Math.min(candies[i],over);
                candies[i]-=remove;
                over-=remove;
                s+=remove;
            }
            if (over>0){
                long remove = Math.min(candies[i-1],over);
                candies[i-1]-=remove;
                over-=remove;
                s+=remove;
            }
        }
        System.out.println(s);

    }
}

Measured memory_bytes: 48904
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let r: usize = scan(tokens);
    println!("{}", 3 * r * r);
}


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

int main()
{
    int n;
    cin >> n;
    if(n == 1 || n == 2){
        cout << -1 << endl;
        return 0;
    }
    char ans[1002][1002];
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) ans[i][j] = '.';
    int b = 1;
    while(n % 2 == 0){
        n /= 2;
        b *= 2;
    }
    char c[1002][1002];
    if(n == 1){
        n *= 4;
        c[0][0] = c[0][1] = 'a';
        c[1][0] = c[1][1] = 'b';
        c[3][3] = c[3][2] = 'c';
        c[2][3] = c[2][2] = 'd';
        c[3][0] = c[2][0] = 'e';
        c[3][1] = c[2][1] = 'f';
        c[0][3] = c[1][3] = 'g';
        c[0][2] = c[1][2] = 'h';
        b /= 4;
    }
    else{
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) c[i][j] = '.';
        for(int i = 0; i < (n - 3) / 2; i++){
            c[i][i] = c[i][i + 1] = char('a' + (i % 3));
            c[n - i - 1][i] = c[n - i - 2][i] = char('a' + (i % 3));
            c[n - i - 1][n - i - 1] = c[n - i - 1][n - i - 2] = char('a' + (i % 3));
            c[i][n - i - 1] = c[i + 1][n - i - 1] = char('a' + (i % 3));
        }
        if(n > 3){
            c[0][(n - 3) / 2 + 1] = c[0][(n - 3) / 2 + 2] = 'e';
            c[n - 1][(n - 3) / 2] = c[n - 1][(n - 3) / 2 + 1] = 'f';
            c[(n - 3) / 2][0] = c[(n - 3) / 2 + 1][0] = 'g';
            c[(n - 3) / 2 + 1][n - 1] = c[(n - 3) / 2 + 2][n - 1] = 'h';
        }
        c[(n - 3) / 2][(n - 3) / 2 + 1] = c[(n - 3) / 2][(n - 3) / 2 + 2] = 'i';
        c[(n - 3) / 2 + 1][(n - 3) / 2] = c[(n - 3) / 2 + 2][(n - 3) / 2] = 'j';
    }
    for(int k = 0; k < n * b; k += n){
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) ans[k + i][k + j] = c[i][j];
    }
    for(int i = 0; i < n * b; i++){
        for(int j = 0; j < n * b; j++) cout << ans[i][j];
        cout << endl;
    }
}

Measured memory_bytes: 3200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            //int[] arr = IntStream.range(0,n).map(i -> in.nextInt()).toArray();
            TreeSet<Integer> set = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                set.add(x);
            }
            int a = set.last();
            Integer lo = set.floor(a / 2);
            Integer hi = set.ceiling(a / 2);
            int r = -1;
            if (lo == null && hi == a) {
                r = -1;
            } else if (hi == a) {
                r = lo;
            } else if (lo == null) {
                r = hi;
            } else {
                if (hi < (a - lo)) {
                    r = hi;
                } else {
                    r = lo;
                }
            }
            out.println(a + " " + r);
        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



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

const int N = 100005;

int cont[N], n, q, k;

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n >> k >> q;

	memset(cont, 0, sizeof cont);

	for(int i=0; i<q; i++) {
		int x; cin >> x;
		cont[x]++;
	}

	for(int i=1; i<=n; i++) {
		if(k-q+cont[i] > 0) cout << "Yes\n";
		else cout << "No\n";
	}
}

Measured memory_bytes: 1024
import math
n=int(input())
x=list(map(int, input().split()))

s = sum(x)
N = len(x)
mean = s / N
a = math.floor(mean)
b = math.ceil(mean)
ra = 0
rb = 0

for i in range(n):
    ra = ra + (x[i] - a) * (x[i] - a)

for i in range(n):
    rb = rb + (x[i] - b) * (x[i] - b)

if ra < rb:
    print(ra)
else:
    print(rb)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000007;
//const int mod = 998244353;//1000000007;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

long long f(long long a, long long b, long long x)
{
	long long t1 = a * x / b, t2 = x / b;
	return t1 - a * t2;
}
 
void Solve()
{
	long long a, b, n;
	cin >> a >> b >> n;
	cout << f(a, b, min(n, b - 1));
}
 
int main()
{
	Fastio();
	Solve();
}

Measured memory_bytes: 3648
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	seg := Segment{}
	seg.init(n)
	for i := 0; i < n; i++ {
		seg.maximize(i, getNextInt(scanner))
	}
	for i := 0; i < m; i++ {
		seg.maximize(seg.top(), seg.bucket[seg.h-1][0]>>1)
	}

	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(seg.bucket[0][i])
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 5
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) maximize(index, value int) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		s := index - index%seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		parent := index / seg.chunk
		max := 0
		for i := s; i < t; i++ {
			if max < seg.bucket[seg.i][i] {
				max = seg.bucket[seg.i][i]
			}
		}
		seg.bucket[seg.i+1][parent] = max
		index /= seg.chunk
	}
}

func (seg *Segment) top() int {
	index := 0
	for seg.i = seg.h - 2; seg.i >= 0; seg.i-- {
		s := index * seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		for i := s; i < t; i++ {
			if seg.bucket[seg.i][i] == seg.bucket[seg.i+1][index] {
				index = i
				break
			}
		}
	}

	return index
}


Measured memory_bytes: 3840
#include <iostream>
#include <map>

int main(int argc, char const* argv[]) {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    std::map<std::string, int> redcards;
    for (int i=0; i<N; i++) {
        std::string s;
        std::cin >> s;
        redcards[s]++;
    }

    int M;
    std::cin >> M;
    for (int i=0; i<M; i++) {
        std::string s;
        std::cin >> s;
        redcards[s]--;
    }

    int max = 0;
    for (auto it=redcards.begin(); it!=redcards.end(); it++) {
        if (it->second > max) {
            max = it->second;
        }
    }

    std::cout << max << '\n';
    return 0;
}


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

int N;
int A[210];
int main(){
  cin >> N;
  for(int i = 0; i < N; i++)
    cin >> A[i];
  int res = 0;
  while(true){
    bool exist_odd = false; //all_even?
    for(int i = 0; i < N; i++){
      if(A[i] % 2 != 0)
        exist_odd = true; //odd_flag
    }
    if(exist_odd)
      break;
    for(int i = 0; i < N; i++)
      A[i] /= 2;
    res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int A,B;
  cin>>A>>B;
  string str;
  cin>>str;
  int N = A+B+1;
  bool check = true;
  for (int i = 0; i < A; i++)
  {
    if(str[i]>'9' || str[i] <'0')check =false;
  }
  

  for (int i = 0; i < B; i++)
  {
    if(str[N-1-i]>'9' || str[N-1-i] <'0')check =false;
  }
  if(str[A] != '-') check = false;

  cout<<(check?"Yes":"No")<<endl;
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#ifndef DEBUG
#pragma GCC optimize("Ofast")
#endif
#include <bits/stdc++.h>

//#define DEBUG
#ifdef DEBUG
#define Debug(...) cerr << "# Debug:" _ __PRETTY_FUNCTION__ _ '-' _ __LINE__ _ '(' _ #__VA_ARGS__ _ (__VA_ARGS__) _ ')' << endl;
#define FAST ((void)0);
#else
#define endl '\n'
#define Debug(x) ((void)0);
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#endif // DEBUG
#define _ << ' ' <<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define CASE int _T;cin >> _T;Fr(tt, 1, _T+1)
#define Eb emplace_back
#define Iter(v) v.begin(),v.end()
#define Lsort(v) sort(Iter(v))
#define Sz(v) ll(v.size())
#define Ft first
#define Sd second

using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr ld PI = acos(-1), eps = 1e-9;
constexpr ll MOD97 = 1e9+7;
constexpr ll MAX = 1e5+5;
constexpr ll INF = 1023456789;
constexpr ll IINF = 1234567890123456789LL;

inline ll getint() {
    ll x=0,s=1;char c=getchar();
    while((c<'0'||c>'9')&&c!='-')c=getchar();
    if(c=='-')c=getchar(),s=-1;
    while('0'<=c&&c<='9')x=x*10+c-'0',c=getchar();
    return x*s;
}

inline ll fpow(ll a, ll b, ll m = MOD97) {
    if (b == 0) return 1%m;
    if (b == 1) return a%m;
    ll r = fpow((a*a)%m, b/2, m);
    return (r*(b&1?a:1))%m;
}

signed main() {
    FAST
    srand(time(NULL));

    constexpr ll MOD = 998244353;
    int n;
    cin >> n;
    vector<int> D(n);
    Fr(i, 0, n) cin >> D[i];
    vector<int> cnt(n);
    Fr(i, 0, n) cnt[D[i]]++;
    int mx = n;
    bool can = cnt[0]==1 && D[0]==0;
    if (can) {
        while (cnt[mx-1] == 0) mx--;
        Fr(i, 0, mx) can = can && cnt[i];
    }
    if (!can)
        cout << "0\n";
    else {
        ll ans = 1;
        Fr(i, 1, mx)
            ans = (ans*fpow(cnt[i-1], cnt[i], MOD))%MOD;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
struct Main {}

#[allow(dead_code)]
impl Main {}

fn main() {
    let n: usize = read();
    let mut a: Vec<Option<usize>> = vec![None; n];
    for i in 1..n {
        let a_one: usize = read();
        a[i] = Some(a_one - 1);
    }
    let mut e: Vec<u32> = vec![0; n];
    for (_, &v) in a.iter().enumerate() {
        match v {
            None => (),
            Some(v) => {
                e[v] += 1;
            }
        }
    }
    for &v in e.iter() {
        println!("{}", v);
    }
}


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

#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back

signed main() {
    int n, m;
    cin >> n >> m;
    if(n == m)  cout << "Yes";
    else    cout << "No";
}


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

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

	int ans = 1;
	for (int i = 1; i < N; i++) {
		int cnt = 0;
		for (int j = i - 1; j >= 0; j--) {
			if (H[i] >= H[j]) {
				cnt++;
			}
		}

		if (cnt == i) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
constexpr bool isDebugMode = false;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b , a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

void solve();

int main(){
    while(testcase--) solve();
    return 0;
}

void solve(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ans = -INF;
    chmax(ans, a * c);
    chmax(ans, a * d);
    chmax(ans, b * c);
    chmax(ans, b * d);
    pt(ans);
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll ar[M],br[M];

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

	ll n,i,m;

	cin >> n;
	for(i=1;i<=n;++i)
		cin >> ar[i] >> br[i];
	if(n%2)
	{
		sort(ar+1,ar+1+n);
		sort(br+1,br+1+n);
		m = (n+1)/2;
		cout << br[m]-ar[m]+1 << "\n";
	}
	else
	{
		sort(ar+1,ar+1+n);
		sort(br+1,br+1+n);
		m = n/2;
		cout << br[m]+br[m+1]-ar[m]-ar[m+1]+1 << "\n";
	}
}

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

namespace ConsoleApp1
{
    class Program
    {
        //
        static void Main(string[] args)
        {
            List<int> Times = new List<int>();
            int A = int.Parse(Console.ReadLine()); Times.Add(A);
            int B = int.Parse(Console.ReadLine()); Times.Add(B);
            int C = int.Parse(Console.ReadLine()); Times.Add(C);
            int D = int.Parse(Console.ReadLine()); Times.Add(D);
            int E = int.Parse(Console.ReadLine()); Times.Add(E);

            int Total = 0;
            int tmp = 10;

            foreach (int tmpTime in Times)
            {
                int T = tmpTime / 10;
                int t = tmpTime % 10;

                if (t != 0)
                {
                    T += 1;
                    tmp = Math.Min(t, tmp);
                }

                Total += T;
            }

            Console.WriteLine(Total * 10 + tmp - 10);
        }

    }
    
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n;
    double sum = 0;
    cin >> n;
    vector<pair<double, string>> a(n);
    for (int i = 0; i < n; i++) {
        double aa;
        string b;
        cin >> aa >> b;
        a.at(i) = make_pair(aa, b);
    }
    for (int i = 0; i < n; i++) {
        if (a.at(i).second == "JPY") {
            sum += a.at(i).first;
        }
        else sum += a.at(i).first * 380000;
    }
    cout << fixed << setprecision(10) << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio> 
int main() 
{ 
    int X; 
    scanf("%d", &X); 
    
    if (X == 7) 
    {
        printf("YES"); 
        
    } 
    
    else if (X == 5) 
    {
        printf ("YES"); 
    
    } 
    else if (X == 3) 
    {
        printf("YES"); 
        
    } 
    
    else
    {
        printf("NO");
    }
    
return 0;
    
}

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

using namespace std;
typedef long long ll;

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

  int a, b, c;
  cin >> a >> b >> c;

  if ((a * 100 + b * 10 + c) % 4 == 0) cout << "YES" << "\n";
  else cout << "NO" << "\n";
}


Measured memory_bytes: 3576
import sys
 
input = sys.stdin.readline
 
 
def main():
    H, W, M = map(int, input().split())
    row = [0] * (H)
    col = [0] * (W)
    bomb = set()
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h, w))
        row[h-1] += 1
        col[w-1] += 1
    row_max = max(row)
    row_index_list = [i for i, v in enumerate(row) if v == row_max]
    col_max = max(col)
    col_index_list = [i for i, v in enumerate(col) if v == col_max]
    ans = row_max + col_max - 1
    c = False
    for x in row_index_list:
        for y in col_index_list:
            if not (x + 1, y + 1) in bomb:
                c = True
                break
        if c:
            break
    if c:
        ans += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 83424
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
const int mod = 1e9+7;
const int maxn = 1e5+5;
const double EPS = 1e-6;
using namespace std;
char s[maxn];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	int i=0,j=len-1;
	int fg=1,ans=0;
	while(i<j){
		if(s[i]==s[j]) {
			i++;j--;
		}else {
			if(s[j]=='x'){
				j--;
				ans++;
			}else if(s[i]=='x'){
				i++;
				ans++;
			}else {
				fg=0;
				break;
			}
		}
	}
	if(fg==0){
		printf("-1\n");
	}else printf("%d",ans);
	return 0;
}



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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;

int n, m;

int main ()
{
  prep();
  
  cin >> n >> m;
  vector<int> graph[n+1];
  vector<int> rev[n+1];
  for (int i=0; i<m; i++){
      int a, b;
      cin >> a >> b;
      graph[a].push_back(b);
      rev[b].push_back(a);
  }
  int shortest = 1000000000;
  int path[1000];
  for (int i=1; i<=n; i++){
      int dists[n+1];
      memset(dists, -1, sizeof(int)*(n+1));
      bool vis[n+1] = {};
      queue<pair<int, int > > q;
      q.emplace(i, 0);
      bool did = false;
      int former = shortest;
      while (!q.empty()){
          pair<int, int > p = q.front();
          q.pop();
          int node = p.first;
          int dist = p.second;
          if (node == i && dist != 0){
              if (shortest > dist){
                  shortest = dist;
                  did = true;
              }
              break;
          }
          if (vis[node]){
              continue;
          }
          vis[node] = true;
          dists[node] = dist;
          for (int j=0; j<graph[node].size(); j++){
              q.emplace(graph[node][j], dist+1);
          }
      }
      if (!did){
          continue;
      }
      int len = 0;
      // recover path
      int curdist = shortest-1;
      int curnode = i;
      while (curdist >= 0){
          for (int j=0; j<rev[curnode].size(); j++){
              if (dists[rev[curnode][j]] == curdist){
                  path[len] = curnode;
                  curnode = rev[curnode][j];
                  curdist--;
                  len++;
                  break;
              }
          }
         
      }
      
  }
 
  if (shortest == 1000000000){
      cout << -1;
  }else{
      cout << shortest << '\n';
      for (int i=0; i<shortest; i++){
          cout << path[i] << '\n';
      }
  }
  return 0; 
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int d[100010];
int p[100010];
int N;

void bfs(int s)
{
    fill_n(d, 100010, inf);
    d[s] = 0;

    queue<int> q;
    q.push(s);

    while (q.size()) {
        int a = q.front();
        q.pop();

        if (p[a] == 0) {
            for (int i = 1; i <= 6; ++i) {
                if (a + i >= N) {
                    chmin(d[a + i], d[a] + 1);
                } else {
                    if (chmin(d[a + i], d[a] + 1)) {
                        q.push(a + i);
                    }
                }
            }
        } else {
            if (d[a] >= d[a + p[a]]) continue;
            d[a + p[a]] = d[a];
            q.push(a + p[a]);
        }
    }
}

signed main()
{
    scanf("%lld", &N);

    for (int i = 1; i <= N; ++i) {
        scanf("%lld", p + i);
    }

    bfs(1);

    printf("%lld\n", *min_element(d + N, d + N + 6));
}

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
const int N = 100010;
int n,x,y;
vector<int> v[N],f[N];

void dfs(int x,int fa){
	int t;
	vector<int> tmp;
	for(int i=0;i<v[x].size();i++) if((t=v[x][i])!=fa){
		dfs(t,x);
		for(int j=0;j<f[t].size();j++){
			if(j>=tmp.size()) tmp.push_back(f[t][j]); 
			else tmp[j] += f[t][j];
		}
	}
	int l = tmp.size();
	for(int i = tmp.size()-1;i>=0;i--){
		if(tmp[i]==0) l = i;
		if(tmp[i]>1) {
			break;
		}
	}
	if(l>=tmp.size()) tmp.push_back(1); else tmp[l]=1;
	for(int i=l-1;i>=0;i--) tmp[i] =0;
	f[x] = tmp;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0);
	printf("%d\n",f[1].size()-1);
	return 0;
}

Measured memory_bytes: 25600
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const LL LINF = 1LL << 60;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ LL to, cost; edge(int t, LL c) :to(t), cost(c){} };

int main()
{
	int n;
	while (cin >> n && n)
	{
		int k; cin >> k;
		set<int> nums;
		vector<int> arr(n);
		rep(i, n)cin >> arr[i];

		function<int(int)> getKeta = [](int num)
		{
			int ret = 10;
			while (num /= 10)
			{
				ret *= 10;
			}
			return ret;
		};

		vector<bool> used(10);
		function<void(int, int, int)> dfs = [&](int idx, int pre, int rem)
		{
			if (used[idx]) return;
			if (rem == 0)
			{
				nums.insert(pre);
				return;
			}
			if (idx == n) return;
			used[idx] = true;
			int next1 = (pre * (arr[idx] >= 10 ? 100 : 10)) + arr[idx];
			for (int i = 0; i < n; i++)
			{
				dfs(i, next1, rem - 1);
			}
			used[idx] = false;
		};
		rep(i, n)dfs(i, 0, k);
		cout << nums.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1312