akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;
	for(int i=0;i<1000000;i++){
		if(i*i==n){
			cout << n << endl;
			break;
		} 
		if(i*i>n){
			cout << (i-1)*(i-1) << endl;
			break;
		} 
	}
	return 0;
}

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int t, l, r;
        std::cin >> t >> l >> r;
        if (t == 0) {
            std::cout << *std::min_element(v.begin() + l, v.begin() + r) << std::endl;
        } else {
            std::cout << *std::max_element(v.begin() + l, v.begin() + r) << std::endl;
        }
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 101
#define INF 100000001
typedef long long ll;

struct edge { ll to, cost; };
typedef pair<ll, ll> P; // firstは最短距離、secondは頂点の番号
vector<edge> G[MAX_V];
ll d[MAX_V], prv[MAX_V], res[MAX_V][MAX_V];

void dijkstra(ll s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	fill(prv, prv + MAX_V, 0);
	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 (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				prv[e.to] = v;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	for (int i = 0; i < MAX_V; i++) {
		res[i][prv[i]] = 1;
		res[prv[i]][i] = 1;
	}
}

int main(){	
	long long N;
	long long M;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<long long> c(M-1+1);
	vector<long long> a(M-1+1);
	vector<long long> b(M-1+1);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
		scanf("%lld",&c[i]);
		edge e1 = {b[i],c[i]};
        G[a[i]].push_back(e1);
		edge e2 = {a[i],c[i]};
        G[b[i]].push_back(e2);
	}
	for(int i = 1 ; i <= N ; i++) {
		dijkstra(i);
		// for(int i = 1 ; i <= N ; i++) {
		// 	for(int j = i+1 ; j <= N ; j++) {
		// 		cout << res[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }
	}
	int r = M;
	for(int i = 1 ; i <= N ; i++) {
		for(int j = i+1 ; j <= N ; j++) {
			r -= res[i][j];
		}
	}
	cout << r << endl;

	return 0;
}



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

namespace ITP1_9_A
{
    class Program
    {
        static void Main(string[] args)
        {
            //一つの単語W、文章Tが与えられるとき、Tの中にあるWの数を出力するプログラム

            int count = 0;
            string w = Console.ReadLine();
            while (true)
            {
                string[] t = Console.ReadLine().Split(' ');

                if (t[0]=="END_OF_TEXT")
                {
                    break;
                }

                for (int i = 0; i < t.Length; i++)
                    
                    if (t[i].ToLower().Equals(w))
                    {
                        count += 1;
                    }
                    else
                    {
                    }
            }
            Console.WriteLine(count);
        }
    }
}



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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

//---main---------------------------------------------
int main(){
    //main
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll ans = a*c;
    //chmax(ans,a*c);
    chmax(ans,a*d);
    chmax(ans,b*c);
    chmax(ans,b*d);

    cout << ans << endl;

    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  REP(i,m){
    int32 a;
    cin >> a;
    n -= a;
  }
  ANS(max<int32>(-1,n));
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,a;
 a=0;
 string s;
 cin >> s;
 for(i=0;i<3;i++)
 {
  if(s[i]=='A')
  a++;
 }
 if(a!=0 && (3-a)!=0)
 cout << "Yes";
 else
 cout << "No";
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

//int a[1001][1001] //aise global me hi

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string
//memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find()    // sort(v.begin(),v.end(),compare)

void solve()
{
    int n,ma;cin>>n>>ma;
   unordered_map<int,int> m;
    while(ma--)
    {
int a,b;cin>>a>>b;



if(m.count(a)>0) 
	{
		if(m[a]!=b) 
		{cout<<"-1";return;}
	}
m[a]=b;
	}

	string s="";

	if(n>1) 
	{
		if(m.count(1)>0&&m[1]==0) {cout<<"-1";return;}
	}

	for(int i=1;i<=n;i++)
	{
		if(m.count(i)==0) s=s+"0";
		else s=s+(char)(48+m[i]);
	}


	if(s[0]=='0'&&n>1)
		s[0]='1';
	cout<<s;
    
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 256
D,G = map(int,input().split())

pc = [ list(map(int,input().split())) for _ in range(D)]

#中途半端に解く配点は一種類以下であり、それ以外の配点は冠山に解くか全く解かない
#中途半端に解く配点があるなら、それは完全に解く配点以外の配点の中で最も高い配点である
ans = 10000
#完全に解く配点がある場合
for i in range(2**D+1):
    ok = []
    s = 0
    solve = 0
    for j in range(D):
        a = (i >> j) & 1
        ok.append(a)
    for j in range(D):
        s += ok[j]*pc[j][0]*100*(j+1)
        solve += ok[j]*pc[j][0]
        s += ok[j]*pc[j][1]
    if G<=s:
        #完全に解く配点のみ
        ans = min(ans,solve)
    else:
        #完全に解く配点＋中途半端に解く配点
        for j in range(D):
            sum1 = s
            solve1 = solve
            for k in range(pc[j][0]):
                sum1 += 100*(j+1)*(1-ok[j])
                solve1 += 1*(1-ok[j])
                if G<= sum1:
                    ans = min(ans,solve1)
#完全に解く配点がない場合
for i in range(D):
    s = 0
    solve = 0
    for j in range(pc[i][0]):
        s += 100*(i+1)
        solve += 1
        if G<=s:
            ans = min(ans,solve)
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	long long N;
	vector<string> s_A;
	vector<string> s_B;
	vector<string> s_AB;
	vector<string> s;
	cin >> N;
	long long countAB = 0;
	for (long long i = 0; i < N; ++i) {
		string buf;
		cin >> buf;
		if (buf[0] == 'B' && buf[buf.length() - 1] == 'A')
		{
			s_AB.push_back(buf);
		}
		else if (buf[0] == 'B')
		{
			s_B.push_back(buf);
		}
		else if (buf[buf.length() - 1] == 'A') {
			s_A.push_back(buf);
		}
		else
		{
			s.push_back(buf);
		}


		for (long long i = 0; i < buf.length() - 1; ++i) {
			if (buf[i] == 'A' && buf[i + 1] == 'B') {
				++countAB;
			}
		}
	}

	long long ab_size = s_AB.size();
	long long a_size = s_A.size();
	long long b_size = s_B.size();
	if (a_size != 0 && b_size != 0) {
		--a_size;
		--b_size;
		if (s_AB.size() != 0) {
			countAB += (ab_size + 1) + min(a_size, b_size);
		}
		else {
			countAB += 1 + min(a_size, b_size);
		}
	}
	if (a_size == 0 && b_size == 0) {
		if (ab_size >= 2) {
			countAB += ab_size - 1;
		}
	}
	else if (a_size == 0 || b_size == 0) {
		countAB += ab_size;
	}
	

	cout << countAB << endl;


	return 0;
}

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

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

  switch(X%7){
  case 0:
    cout << "thu" << endl;
    break;

  case 1:
    cout << "fri" << endl;
    break;

  case 2:
    cout << "sat" << endl;
    break;

  case 3:
    cout << "sun" << endl;
    break;

  case 4:
    cout << "mon" << endl;
    break;

  case 5:
    cout << "tue" << endl;
    break;

  default:
    cout << "wed" << endl;
    break;
  }

  return 0;
}



Measured memory_bytes: 3116
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(aa: Vec<i64>) -> i64 {
    let n = aa.len();

    let mut acc = vec![0;n];

    let mut total = 0;

    for i in 0..n {
        total += aa[i];
        acc[i] = total;
    }

    let mut min = std::i64::MAX;

    for i in 0..n-1 {
        let d = ((total - acc[i]) - acc[i]).abs();
        if d < min {
            min = d;
        }
    }

    min
}

fn main() {
    read_line!();
    let aa = parse_vec!(i64);
    println!("{}", solve(aa));
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![1,2,3,4,5,6]), 1);
    assert_eq!(solve(vec![10, -10]), 20);
}


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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
};
signed main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> as(m);
    int bigger = 0;
    int smaller = 0;
    REP(i, m) {
        cin >> as[i];
        if (as[i] < x) {
            smaller++;
        }
        if (as[i] > x) {
            bigger++;
        }
    }
    cout << min(bigger, smaller) << endl;
}

Measured memory_bytes: 3616
using System;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var KN = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (K, N) = (KN[0], KN[1]);
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var diff = new int[N];

        for (int i = 0; i < N; i++)
        {
            if (i < N - 1)
                diff[i] = A[i + 1] - A[i];
            else
                diff[i] = K - A[i] + A[0];
        }

        var ans = K - diff.Max();

        WriteLine(ans);
    }
}


Measured memory_bytes: 44468
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  while(n!=0)
  {
	int r=n%10;
    if(r==7)
    {
	cout<<"Yes";
      return 0;
    }
    n/=10;
  }
  cout<<"No";
}

Measured memory_bytes: 3624
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var X = cin.ReadInt;
            var L = cin.ReadIntArray(N);
            var ans = 1;
            var total = 0;
            while (ans <= N && total + L[ans - 1] <= X)
            {
                total += L[ans - 1];
                ans++;
            }
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
#include <stdio.h>

int main(void)
{
 double M,A[1000];
 int    N,s,count,i;

  scanf("%d%lf",&N,&M);

  for(i=1;i<=N;i++){
   scanf("%lf",&A[i]);
 }
   s=0;
  for(i=1;i<=N;i++){
    s=s+A[i];
  }

   count=0;
  for(i=1;i<=N;i++){
   if(A[i]>=s/(4*M))
      count++;
  }
   if(count>=M)      printf("Yes");
   else
      printf("No");

   return 0;
 }

     


Measured memory_bytes: 128
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = ri()
li = [s]
cnt = 1
while True:
  if s&1 == 1:
    s = 3*s + 1
  else:
    s = s//2
  cnt += 1
  if s not in li:
    li.append(s)
  else:
    print(cnt)
    exit()










Measured memory_bytes: 27064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve()
{
  string s,t;
  cin >> s >> t;
  int ans=0;
  f(i,t.length())
  {
      if(s[i]!=t[i])
        ans++;
  }
  cout << ans << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3772
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int main(){
	int a,b, num;
	a = 0, b = 0;
	while(cin >> num && num){
		a += num;
		rep(i, 3){
			cin >> num;
			a += num;
		}
		rep(i, 4) {
			cin >> num;
			b += num;
		}
		cout << max(a, b) << endl;
		a = 0, b = 0;
	}
	return 0;
}

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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve(){
	deque<pair<int,int>> v;
	int n, cnt = 0;
	cin >> n;
	bool ok = false;
	for(int i = 0;i < n;i++){
		int x,y;
		cin >> x >> y;
		v.emplace_back(x,y);
		if(x==y) cnt++;
		if(i>=3){
			if(v[0].first==v[0].second) cnt--;
			v.pop_front();
		}
		if(cnt==3){
			ok = true;
		}
	}
	cout << (ok ? "Yes\n" : "No\n");
}

signed main(){
	fastio
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = 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(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;

static const int MAX=3005;

ll MOD;
ll fact[MAX], fact_inv[MAX];

ll comb(ll n, ll r){
    return (fact[n] * fact_inv[r]) % MOD * fact_inv[n-r] % MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}//mod mでの逆元aを計算

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    iosetup;
    int p; IN(p);
    MOD = p;
    vector<int> a(p);
    rep(i, 0, p) cin >> a[i];

    fact[0] = 1;
    for(int i = 0; i < MOD - 1; i++) fact[i+1] = fact[i] * (i+1) % MOD;
    fact_inv[MOD-1] = modpow(fact[MOD-1], MOD - 2, MOD);
    for(int i = MOD - 2; i >= 0; i--) fact_inv[i] = fact_inv[i+1]*(i+1) % MOD;

    cout << a[0];
    rep(i, 1, p){
        ll ans = 0;
        rep(j, 0, p) if(a[j] == 1){
            if(((p-1-i)&1) == 0) ans -=(comb(p-1, i) * modpow(j,p-1-i, p)) % p;
            else ans += comb(p-1, i) * modpow(j, p-1-i, p) % p;
        }
        // cerr << ans << endl;
        ans %= p;
        if(ans < 0) ans += p;
        cout << " ";
        cout << ans;
    }
    cout << endl;
    
    return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;

  int cnt=0;
  for(int i=A; i<=B; i++){
    string s = to_string(i);
    bool isSame = true;
    for(int j=0; j<s.length()/2; j++){
      if(s[j] != s[s.length()-1-j]) {
        isSame = false;
        break;
      }
    }
    if(isSame) cnt++;
  }
  cout << cnt << endl;
}


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

typedef long long ll;

const int INF = 100000000;

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int>total(N+1);
    vector<int>ans;

    total[0] = 0;
    total[1] = 0;
    int cnt = 0;
    for (int i = 0; i < N-1; i++) { 
        if (S[i] == 'A' && S[i+1] == 'C') {
            cnt++;
        }
        total[i+2] = cnt;
    }
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        ans.push_back(total[r]-total[l]);
    }

    for (int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 1912
import java.util.*;

public class Main {

    public static void main(String args[]) {


        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();

        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;

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

            String s = scan.next();

            switch (s) {
                case "AC":
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }

        String output = String.format("AC x %d\nWA x %d\nTLE x %d\nRE x %d", ac, wa, tle, re);

        System.out.print(output);
    }


}

Measured memory_bytes: 57192
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      char[] s = f.readLine().toCharArray();
      
      int n = s.length;
      
      int[] array = new int[n+1];
      Arrays.fill(array,-1);
      
      HashSet<Integer> hset = new HashSet<Integer>();
      
      if(s[0] == '<'){
         array[0] = 0;
         hset.add(0);
      }
      
      if(s[n-1] == '>'){
         array[n] = 0;
         hset.add(n);
      }
      
      for(int k = 1; k < n; k++){
         if(s[k-1] == '>' && s[k] == '<'){
            array[k] = 0;
            hset.add(k);
         }
      }
      
      
      for(int i : hset){
         int index = i-1;
         //go left
         while(index >= 0 && s[index] == '>'){
            if(array[index] != -1){
               array[index] = Math.max(array[index],i-index);
               break;
            }
            array[index] = i-index;
            index--;
         }
         
         index = i+1;
         while(index <= n && s[index-1] == '<'){
            if(array[index] != -1){
               array[index] = Math.max(array[index],index-i);
               break;
            }
            array[index] = index-i;
            index++;
         }
      }
      
      long answer = 0;
      for(int k = 0; k <= n; k++){
         answer += (long)array[k];
      }
      
      out.println(answer);
      
      
      
      
      
      out.close();
   }
   
      
}

Measured memory_bytes: 38428
#include <stdio.h>
#include <string.h>
char* reverse(char *p,int l)
{ char temp;
    int i;
    for(i=0;i<l/2;i++)
    {
        temp=*(p+i);
        *(p+i)=*(p+l-1-i);
        *(p+l-1-i)=temp;
        
    }
    return(p);
}
int main() {
	char a[100],b[100],c[100],d[100],e[100],f[100];
	scanf("%s",a);
	strcpy(b,a);
	int n=strlen(a);
	reverse(b,n);
	int i;
	for(i=0;i<(n-1)/2;i++)
	c[i]=a[i];
	c[i]='\0';
	strcpy(e,c);
	reverse(e,(n-1)/2);
	
	int j=0;
    for(i=(n+1)/2;i<n;i++)
	{d[j]=a[i];
	j++;}
	d[j]='\0';
	strcpy(f,d);
	reverse(f,(n-1)/2);
	
	if((strcmp(a,b)==0) && (strcmp(c,e)==0) && (strcmp(d,f)==0))
	 printf("Yes");
	else 
	printf("No");
	
	
}
	

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()

A.sort(reverse=1)
B.sort(reverse=1)
C.sort(reverse=1)

que = []
que += A[:X]
que += B[:Y]
heapify(que)

for c in C:
    mn = heappop(que)
    if c > mn:
        heappush(que, c)
    else:
        heappush(que, mn)
ans = sum(que)
print(ans)


Measured memory_bytes: 98336
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> v(Q);
    for(int i = 0; i < Q; i++) cin >> v[i];

    vector<ll> point(N);
    for(int i = 0; i < Q; i++){
        point[v[i] - 1] ++;
    }

    ll ans = 0;
    for(int i = 0; i < N; i++){
        if( K - (Q - point[i] ) > 0  ){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    //cout << ans << endl;
}

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

int a[100000];
 
int main() {

    int n,k,R,S,P;
    string t;
    cin>>n>>k>>R>>S>>P>>t;
    int ans=0;
    rep(i,n) {
        if(k<=i) {
            if(t[i-k]!=t[i]||a[i-k]==0) {
                if(t[i]=='r') {
                    ans+=P;
                    a[i]=1;
                }
                else if(t[i]=='s') {
                    ans+=R;
                    a[i]=1;
                }
                else if(t[i]=='p') {
                    ans+=S;
                    a[i]=1;
                }
            }
            
        }
        else {
            if(t[i]=='r') {
                ans+=P;
                a[i]=1;
            }
            else if(t[i]=='s') {
                ans+=R;
                a[i]=1;
            }
            else if(t[i]=='p') {
                ans+=S;
                a[i]=1;
            }
        }
    }

    cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

	ll n, f[100][10], p[100][11];
	cin >> n;
	for(int i=0; i<n; i++){
		for(int j=0; j<10; j++){
			cin >> f[i][j];
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<11; j++){
			cin >> p[i][j];
		}
	}

	int t[10];
	int c, m=-1e9-1;
	for(int i=1; i<1024; i++){
		int u=i;
		for(int j=0; j<10; j++){
			t[j]=u%2;
			u/=2;
		}
		int v=0;
		for(int j=0; j<n; j++){
			c=0;
			for(int k=0; k<10; k++){
				if(t[k]==1 && f[j][k]==1)c++;
			}
			v+=p[j][c];
		}
		m=max(m, v);
	}
	cout << m << endl;

	return 0;
}

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

int main(void){
    // Your code here!
    string str,order,re;
    int p,a,b;
    cin >> str >> p;
    
    for(int i=0; i<p; i++){
        cin >> order;
        if(order == "print"){
            cin >> a >> b;
             for(int i=a; i<=b; i++) cout << str[i];
             cout << endl;
        }
        else if(order == "reverse"){
            cin >> a >> b;
            char tmp[b-a+1];
            for(int i=a; i<=b; i++) tmp[i-a] = str[i];
            for(int i=a; i<=b; i++) str[b+a-i] = tmp[i-a];
        }
        else if(order == "replace"){
            cin >> a >> b >> re;
            for(int i=a; i<=b; i++) str[i] = re[i-a];
        }
    }
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
#define PI 3.14159265358979323846
const long long mod = 1000000007;

int main(){
    //    random_device rnd;
    //    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    LL now = 0;
    LL ans = 0;
    LL bigcount = 0;
    for(LL i = 0;i < S.size();i++){
        if(S[i] == '>'){
            bigcount++;
 //           cout << ans << " in " << i << " and now = " << now << endl;
            continue;
        }
        else{
            if(bigcount > 0){
                ans += (bigcount * (bigcount + 1))/2 + ((now > bigcount) ? now-bigcount : 0);
//                cout << "ans += " << (bigcount * (bigcount + 1))/2 + ((now > bigcount) ? now-bigcount : 0) << endl;
                now = 0;
                bigcount = 0;

//                cout << ans << " in " << i << " and now = " << now << endl;
            }
            if(i == S.size()-1 || S[i+1] == '<'){
                now++;
                ans += now;
//                cout << ans << " in " << i << " and now = " << now << endl;
            }
            else{
                now++;
//                cout << ans << " in " << i << " and now = " << now << endl;
            }
        }
    }
    ans += (bigcount * (bigcount + 1))/2 + ((now > bigcount && bigcount) ? now-bigcount : 0);

    cout << ans << endl;
}


Measured memory_bytes: 1172
#include<iostream>
#include<algorithm>
using namespace std;
int d[1<<15];
int main(){
	for(int i=0;i<(1<<15);i++)d[i]=0;
	for(int i=0;i*i<(1<<15);i++){
		for(int j=0;j<=i;j++){
			if(i*i+j*j>(1<<15))break;
			for(int k=0;k<=j;k++){
				if(i*i+j*j+k*k>(1<<15))break;
				for(int l=0;l<=k;l++){
					if(i*i+j*j+k*k+l*l>(1<<15))break;
					d[i*i+j*j+k*k+l*l]++;
				}
			}
		}
	}
	int n;while(cin>>n&&n)cout<<d[n]<<endl;
	return 0;
}

Measured memory_bytes: 3224
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split(); if (line.length < args.length) return;foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
//------------------------------
//1980-430 = 1550 = 50 + 3 * 500 
//1980 = 3*500 + 3*100 + 3*50 + 3*10
//430 = 3*100 + 2*50 + 3*10
//??¨??????????????´????????£??????????¢????(????¬???????)????????????????????§
//???????????° - ?????£????????° ??? ????????°??????
const coin = [10,50,100,500];
void main(){
	int total;
	for(read(total); total ; read(total), write(total ? "\n":"")){
		auto have = new int[4];
		readArray(have);
		auto all = dotProduct(coin,have) - total;
		auto all_change = new int[4];
		foreach_reverse(i;iota(4)){
			all_change[i] = all/coin[i];
			all %= coin[i];
		}
		foreach(u;zip(have,all_change,coin))
			if(u[0]-u[1]>0) writeln(u[2]," ",u[0]-u[1]);
	}
}

Measured memory_bytes: 2872
#include<iostream>
#include<vector>

bool can_make_triangle(int a, int b, int c)
{
    return (a != b) && (b != c) && (c != a) && (a + b > c) && (b + c > a) && (c + a > b);
}

int main()
{
    std::vector<int> L;
    int N;
    std::cin >> N;
    L.resize(N);
    for(int& val : L){
        std::cin >> val;
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
                if(can_make_triangle(L[i], L[j], L[k])) count++;
            }
        }
    }
    std::cout << count << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> s(H);
  for (int i = 0; i < H; i++)
  {
    std::cin >> s[i];
  }
  int dp[110][110] = {};
  for (int i = 0; i <= H; ++i)
  {
    for (int j = 0; j <= W; ++j)
    {
      dp[i][j] = INF;
    }
  }
  if (s[0][0] == '#')
    dp[0][0] = 1;
  else
    dp[0][0] = 0;
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      if (i + 1 < H)
      {
        if (s[i + 1][j] == s[i][j])
        {
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
        else
        {
          if (s[i + 1][j] == '#')
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
          else
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
      }
      if (j + 1 < W)
      {
        if (s[i][j + 1] == s[i][j])
        {
          dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
        }
        else
        {
          if (s[i][j + 1] == '#')
          {
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
          }
          else
          {
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
          }
        }
      }
    }
  }

  cout << dp[H - 1][W - 1] << endl;

  return 0;
}


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2 3");
            WillReturn.Add("1 32");
            WillReturn.Add("2 63");
            WillReturn.Add("1 12");
            //000001000002
            //000002000001
            //000001000001
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2 3");
            WillReturn.Add("2 55");
            WillReturn.Add("2 77");
            WillReturn.Add("2 99");
            //000002000001
            //000002000002
            //000002000003
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct PairDef
    {
        internal int P;
        internal int M;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        var PairList = new List<PairDef>();
        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            PairDef WillAdd;
            WillAdd.P = wkArr[0];
            WillAdd.M = wkArr[1];
            PairList.Add(WillAdd);
        }

        int CurrP = -1;
        int MCnt = 0;
        var HashDict = new Dictionary<string, string>();
        foreach (PairDef EachPair in PairList.OrderBy(X => X.P).ThenBy(X => X.M)) {
            if (CurrP != EachPair.P) {
                CurrP = EachPair.P;
                MCnt = 1;
            }
            else MCnt++;

            string Hash = string.Format("{0},{1}", EachPair.P, EachPair.M);
            HashDict.Add(Hash, string.Format("{0:D6}{1:D6}", EachPair.P, MCnt));
        }

        foreach (PairDef EachPair in PairList) {
            string Hash = string.Format("{0},{1}", EachPair.P, EachPair.M);
            Console.WriteLine(HashDict[Hash]);
        }
    }
}


Measured memory_bytes: 47796
/**
*    author:  Dooloper
*    created: 16.09.2020 23:48:27
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
   long long x;
public:
   mint(long long x=0) : x((x%mod+mod)%mod) {}
   mint operator-() const {
     return mint(-x);
   }
   mint& operator+=(const mint& a) {
       if ((x += a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator-=(const mint& a) {
       if ((x += mod-a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator*=(const  mint& a) {
       (x *= a.x) %= mod;
       return *this;
   }
   mint operator+(const mint& a) const {
       mint res(*this);
       return res+=a;
   }
   mint operator-(const mint& a) const {
       mint res(*this);
       return res-=a;
   }
   mint operator*(const mint& a) const {
       mint res(*this);
       return res*=a;
   }
   mint pow(ll t) const {
       if (!t) return 1;
       mint a = pow(t>>1);
       a *= a;
       return a;
   }
   // for prime mod
   mint inv() const {
       return pow(mod-2);
   }
   mint& operator/=(const mint& a) {
       return (*this) *= a.inv();
   }
   mint operator/(const mint& a) const {
       mint res(*this);
       return res/=a;
   }

   friend ostream& operator<<(ostream& os, const mint& m){
       os << m.x;
       return os;
   }
};
#pragma endregion

int h, w;

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> h >> w;
  int sh,sw,gh,gw;
  cin >> sh >> sw >> gh >> gw;
  sh--;sw--;gh--;gw--;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[sh][sw] = 0;
  q.emplace_back(sh,sw);
  while(!q.empty()){
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if(dist[i][j] != d) continue;
    rep(v,4){
      int ni = i+di[v], nj = j+dj[v];
      if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if(s[ni][nj] == '#') continue;
      if(dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for(int ei = -2; ei <= 2; ei++){
      for(int ej = -2; ej <= 2; ej++){
        int ni = i+ei, nj = j+ej;
        if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if(s[ni][nj] == '#') continue;
        if(dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = (dist[gh][gw]==INF)?-1:dist[gh][gw];
  cout << ans << endl;
  return 0;
}

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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        int N;
        cin >>N;
        vector<ll> A(N, 0);
        Rep0(i, N)
                cin >>A.at(i);
        ll S=1000;
        ll C=0;
        Rep0(i, N-1) {
                if(A.at(i+1)>A.at(i)) {
                        C=S/A.at(i);
                        S -=C*A.at(i);
                        S +=A.at(i+1)*C;
                }
        }
        cout <<S <<endl;
        return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
using namespace std;
int a[1001],b[1001];
int main()
{
	int i,j,n,m,p,q;
	bool yes;
	while(cin>>n>>m)
	{
		if(n==0&&m==0)break;
		p=1;
		for(i=1;i<=n;i++)cin>>a[i];
		for(i=1;i<=m;i++)cin>>b[i];
		for(i=1;i<=m;i++)
		{
			p=p+b[i];
			p=p+a[p];
			if(p>=n)break;
		}
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int Match[] = {0,2,5,5,4,5,6,3,7,6};
int N,M;
void traceback(vector<int> A, vector<int> dp){
    int pos = N;
    int dig = dp[N];
    while(pos != 0){
        for(int i = A.size()-1; i >= 0; i--){
            if(pos - Match[A[i]] < 0) continue;
            if(dp[pos - Match[A[i]]] != (dig - 1)) continue;
            cout << A[i] ;
            dig -=1;
            pos -= Match[A[i]];
            break;
        }
    }
    cout << endl;
    return;
}

void dfs(vector<int> A, vector<int> dp,int dig,int pos){
    //cout <<"pos : " << pos << " dig:  " << dig << endl;
    if(dig == 0) return;
    for(int i = M-1;i>=0;i--){
        //if(dig == 1) cout << i << " " << pos << " " << A[i] << endl;
		if(pos >= Match[A[i]] && dp[pos-Match[A[i]]]==dig-1){
			pos -=Match[A[i]];
			cout<<A[i];
			dfs(A,dp,dig-1,pos);
			return;
		}
    }
}

int main(){
    cin >> N >> M;
    vector<int> A(M);
    vector<int> B;
    vector<int> check(10);
    for(int i= 0;i < M;i++){
        cin >> A[i];
        check[A[i]] = 1;
    }
    sort(A.begin(),A.end());
    vector<int> dp(N+1);  //マッチをn本使った時の最大の桁数を格納dp(n)
    for(int i = 1; i< N+1; i++){
        dp[i] = -1e8;
    }
    for(int i= 0;i<N+1;i++){
        for(int j= 0; j< A.size() ; j++){
            if((i - Match[A[j]]) >= 0){
                dp[i] = max(dp[i],dp[i-Match[A[j]]]+1);
            }
        }
    }
    traceback(A,dp);
    //dfs(A,dp,dp[N],N);
    return 0;
}

Measured memory_bytes: 384
S = input()
set_ = set()

for i in S:
    set_.add(i)

if len(set_) == 4:
    print("Yes")
elif len(set_) == 2:
    if 'N' in set_ and 'S' in set_:
        print("Yes")
    elif 'E' in set_ and 'W' in set_:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9052
#include <iostream>
#include <algorithm>
#include <iomanip>
#include"stdio.h"
#include <cstring>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include"time.h"
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
template<class T>inline void read(T &res){
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=b;i<=c;i++){
        if(i%a==0) {
            cout<<"OK"<<endl;
        return 0;
        }
    }
    cout<<"NG";
	return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
#define ll long long int
//using namespace boost::multiprecision; 
using namespace std;
int main(){
  ll n,k=0;;cin>>n;
  ll i;
  vector<ll> v;
  for( i=2;i*i<=n;i++){
  	//cout<<i<<" ";
  	if(n%i==0){
     	k=0;
     	while(n%i==0){
          n/=i;
		k++;
      	//cout<<i<<" "<<n<<"\n";
		}
	v.push_back(k);
    }
  }
  if(n!=1)v.push_back(1);
  //cout<<endl<<i<<endl;
  ll ans=0;
  for(auto i:v){
	  ll p=sqrt(1+8*i)-1;
	  p/=2;
	  ans+=p;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 3728
#300
K, N = map(int,input().split())
A = list(map(int,input().split()))
maxd = 0
for i in range(N):
    if i != N-1:
        if maxd < A[i+1] - A[i]:
            maxd = A[i+1] - A[i]
    else:
        if maxd < A[0] + K - A[N-1]:
            maxd = A[0] + K - A[N-1]
print(K-maxd)

Measured memory_bytes: 26444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N, K;
int A[5000];
int dp[5001][10001];

// no need
bool noneed(int x){

    // fprintf(stderr, "x:%d A[x]:%d ", x, A[x]);

    if(A[x] >= K) return false;

    // check 5000-10000
    rep(i, N+1){
        rep(j, 10001) dp[i][j] = 0;
    }

    dp[0][0] = 1;
    for(int i = 1; i<=N; i++){
        int a = A[i];
        rep(j, 10001){
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if(i != x && j-a >= 0) {dp[i][j] = max(dp[i][j], dp[i-1][j-a]);}
        }
    }

    for(int j = K-A[x]; j<K; j++){
        // fprintf(stderr, "%d", dp[N][j]);
        if(dp[N][j] == 1) {
            // fprintf(stderr, " F\n");
            return false;
        }
    }

    // fprintf(stderr, "T\n");
    return true;

}

// good most left = bad most right + 1
int binarySearch(){
    int left = 0;
    int right = N;

    if(!noneed(0)) return 0;
    if(noneed(N-1)) return N;

    while (left + 1 < right){
        int mid = (left + right) / 2;
        if(noneed(mid)) {
            left = mid;
        }
        else{
            right = mid;
        }
    }
    return right;
}

int main() {
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    sort(&A[0], &A[N]);

    rep(i, N){
        fprintf(stderr, "%d,", A[i]);
    }
    cerr << endl;

    int ret = binarySearch();
    cout << ret << endl;
}

Measured memory_bytes: 195584