akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int n,d;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>d;
	int ans=0;
	rep(i,1,n){
		int x,y;
		cin>>x>>y;
		if(1ll*x*x+1ll*y*y<=1ll*d*d) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin >> n;
  int xor1 = 0;
    vector<int>A;
  for(int i=0;i<n;i++)
  {
      int x;
      cin >> x;
      A.push_back(x);
  }
for (int i = 0; i < n; i++)
    xor1 ^= A[i];

for (int i = 0; i < n; i++)
        A[i] = xor1 ^ A[i];
for(auto c: A)
{
    cout << c << " ";
}
    return 0;
}

Measured memory_bytes: 4260
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;

	cout << (n * a > b ? b : n * a) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;

int main(void){
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 0; i < 4; i++){
    if(N % 10 == 2){ans++;}
    N = N / 10;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;


int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    vector<ll> a;
    rep(i, n){ ll tmp; cin >> tmp; sum += tmp; a.push_back(sum);}

    ll mindif = 1e10;
    rep(i, n){ mindif = min(mindif, abs(a[i]*2 - sum));}

    printf("%lld\n", mindif);
}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int n;

	cin >> n;
	vector<ll> A(n+1);
	vector<ll> B(n+1);
	for (int i=0; i<n+1; i++)
		cin >> A[i];
	for (int i=0; i<n; i++)
		cin >> B[i];
	B[n] = 0;
	ll sum = 0;
	ll b = 0;
	for (int i=0; i<n+1; i++)
	{
		if (A[i]<=B[i]+b)
		{
			sum += A[i];
			b = B[i] - max((ll)0, A[i] - b);
		}
		else
		{
			sum += B[i] + b;
			b = 0;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
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; }

int main(){
    ll k;cin>>k;
    ll x =7;

    for(int i =1;i<=999982;++i){
        if(x%k==0){
            cout<<i<<endl;
            return 0;
        }
        else x=x%k;
        x*=10;
        x+=7;


    }
    cout<<-1<<endl;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
 int a,b,c;

 scanf("%d", &a);
 scanf("%d", &b);

if(a >= 13) printf("%d\n", b);
else if ((a <= 12 )&&(a >= 6 ) ) printf("%d\n", b / 2);
else  printf("0\n");
 return 0;
}


Measured memory_bytes: 128
N, A = map(int, input().split())

x = -1
y = -1
z = -1
break_flg = False
for Z in range(0, N + 1):
    if break_flg: break
    for Y in range(0, N - Z + 1):
        if 10000*(N - Y - Z) + 5000*Y + 1000*Z == A:
            x = N - Y - Z
            y = Y
            z = Z
            break_flg = True
            break
print(str(x) + " " + str(y) + " " + str(z))


Measured memory_bytes: 40684
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}
int ctoi(char c) {
	if ('0' <= c && c <= '9') {
		return c - '0';
	}
	return 0;
}



int main(void) {
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll x = lcm(c, d);
	a--;
	cout << b - a - (b / c - a / c + b / d - a / d - b / x + a / x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll dp[5001][5001];
int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			if(s[i]==s[j]){
				if(i+dp[i][j]!=j){
					dp[i+1][j+1]=dp[i][j]+1;
					ans=max(dp[i+1][j+1],ans);
				}
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 194816
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <bits/stdc++.h>
#define ll long long
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> //lower_bound , upper_bound
// using namespace __gnu_pbds;//kth smallest : *pd.find_by_order(k-1) , no. of elem < X : pd.order_of_key(X) , delete X : pd.erase(X).
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fb(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl '\n'
#define pl pair<ll, ll>
#define all(v) v.begin(), v.end()
#define lb lower_bound
#define ub upper_bound
#define nude(a)           \
    for (auto i : a)      \
        cout << i << " "; \
    cout << nl;
#define tc     \
    ll tc;     \
    cin >> tc; \
    while (tc--)
const ll mod = (1e9 + 7);
const ll sz = 2e5 + 9;
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll, vector<ll>, greater<ll>>
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
        {
            res = (res * x) % p;
        }
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

vector<vector<ll>> dp(1e5 + 1, vector<ll>(2, -1));

ll dfs(vector<vector<ll>> &adj, ll cur, ll par, ll col)
{
   
    if (dp[cur][col] == -1)
    {
        dp[cur][col] = 1;
        for (ll x : adj[cur])
        {
            if (x != par)
            {

                if (!col)
                {
                    dp[cur][col] *= (dfs(adj, x, cur, col) + dfs(adj, x, cur, col ^ 1)) % mod;
                    dp[cur][col] %= mod;
                }
                else
                {
                    dp[cur][col] *= dfs(adj, x, cur, col ^ 1) % mod;
                    dp[cur][col] %= mod;
                }
            }
        }
    }

    return dp[cur][col];
}

void bring_me_thanos()
{
    ll n;
    cin >> n;
    vector<vector<ll>> adj(n + 1);
    ll x, y;
    f(i, 0, n - 1)
    {
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    dfs(adj, 1, 0, 0);
    dfs(adj, 1, 0, 1);

    cout << (dp[1][0] + dp[1][1]) % mod << nl;
}

void solve()
{
    //init();
    //tc
    bring_me_thanos();
}

int main()
{
#ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t beg = clock();
    solve();
    clock_t end = clock();
    fprintf(stderr, "%.3f sec, Copyright %c 2019 PyThor. \n", double(end - beg) / CLOCKS_PER_SEC, 184);
    return 0;
}

Measured memory_bytes: 22320
fun main(args: Array<String>) {
    val l = readLine()!!.split(" ").map { it.toInt() }.sorted().toMutableList()
    var a = 0
    while(l[0] + 1 < l[2]){
        a += 1
        l[0] += 2
    }
    while(l[1] + 1 < l[2]){
        a += 1
        l[1] += 2
    }
    val al = l.sorted()
    a += when(l.sum()){
        3 * l[2] - 2 -> 1
        3 * l[2] - 1 -> 2
        else -> 0
    }
    println(a)
}

Measured memory_bytes: 37820
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> balls(n, 0);
  vector<int> ans;

  for(int i = n - 1; i >= 0; --i) {
    int num = 0;
    for(int j = i; j < n; j += (i + 1)) {
      num += balls[j];
    }
    if(num % 2 != a[i]) {
      ++balls[i];
      ans.push_back(i + 1);
    }
  }
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i] << endl;
}




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

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			long x = cin.Long();
			int[] ss = cin.ArrayInt(n);
			Array.Sort(ss);
			Array.Reverse(ss);

			int m = Math.Max(ss[0], (int)x) + 1;
			long[] dp = new long[m];
			dp[x] = 1;
			for (int i = 0; i < n; i++) {
				long rate = n - i - 1;
				for (int j = 0; j < m; j++) {
					long pre = dp[j];
					int dst = j % ss[i];
					dp[j] += ((pre * (rate - 1)) % MOD);
					dp[j] %= MOD;
					dp[dst] += pre;
					dp[dst] %= MOD;
				}
			}

			long ans = 0;
			for (int i = 0; i < m; i++) {
				ans = (ans + ((dp[i] * i) % MOD)) % MOD;
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => 
			int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

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

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13256
#include<stdio.h>
        int main()
        {
            int X,A,B;
            scanf("%d %d %d",&X,&A,&B);
            if (B-A <= 0) printf("delicious\n");
            if (1 <= B-A && B-A <= X) printf("safe\n");
            if (X+1 <= B-A) printf("dangerous\n");
            return 0;
        }

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

using namespace std;

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

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 200000 + 5;

int psz;
struct Node {
  int key, siz;
  LL sum;
  Node *ch[2];
  void update() {
    siz = ch[0]->siz + ch[1]->siz + 1;
    sum = ch[0]->sum + ch[1]->sum + key;
  }
} pool[maxn], *null = new Node();

Node *new_node(int k) {
  Node *i = pool + psz++;
  i->key = i->sum = k, i->siz = 1, i->ch[0] = i->ch[1] = null;
  return i;
}

class SBT {
  Node *root;

  void rotate(Node *&u, int d) {
    Node *v = u->ch[d ^ 1];
    u->ch[d ^ 1] = v->ch[d];
    v->siz = u->siz, v->sum = u->sum, v->ch[d] = u;
    u->update();
    u = v;
  }

  void maintain(Node *&u, int d) {
    if (u == null) return;
    if (u->ch[d]->ch[d]->siz > u->ch[d ^ 1]->siz)
      rotate(u, d ^ 1);
    else if (u->ch[d]->ch[d ^ 1]->siz <= u->ch[d ^ 1]->siz)
      return;
    else
      rotate(u->ch[d], d), rotate(u, d ^ 1);
    maintain(u->ch[0], 0);
    maintain(u->ch[1], 1);
    maintain(u, 0);
    maintain(u, 1);
  }

  void insert(Node *&u, int k) {
    if (u == null) {
      u = new_node(k);
      return;
    }
    int d = (k > u->key);
    insert(u->ch[d], k);
    maintain(u, d), u->update();
  }

 public:
  SBT() : root(null) { null->sum = 0, null->ch[0] = null->ch[1] = null; }
  int size() { return root->siz; }
  void insert(int k) { insert(root, k); }
  int select(int k, LL &s) {
    for (Node *u = root; u != null;) {
      int t = u->ch[0]->siz;
      if (k == t) {
        s += u->ch[0]->sum;
        return u->key;
      }
      if (k > t) s += u->ch[0]->sum + u->key;
      u = u->ch[k > t], k -= (k > t ? t + 1 : 0);
    }
    return inf;
  }
};

int main() {
  int n;
  scanf("%d", &n);
  SBT bst;
  LL sum = 0;
  while (n--) {
    int op, a, b;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &a, &b);
      bst.insert(a);
      sum += a + b;
    } else {
      int i = (bst.size() - 1) / 2;
      LL s = 0;
      int x = bst.select(i, s);
      printf("%d %lld\n", x, sum - 2 * s - (LL)x * (bst.size() - 2 * i));
    }
  }

  return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
#include <string.h>

int main() {
	int N, Q, l[100000], r[100000], count[100000], i, flg, cnt;
	char S[100000];
	memset(count, 0, sizeof(count));

	scanf("%d %d", &N, &Q);
	scanf("%s", S);
	for (i = 0; i < Q; i++) {
		scanf("%d %d", &l[i], &r[i]);
		l[i]--;
		r[i]--;
	}

	cnt = 0;
	flg = 0;
	for (i = 0; i < N; i++) {
		if (S[i] == 'A') {
			flg = 1;
		}
		else if (flg == 1 && S[i] == 'C') {
			cnt++;
			flg = 0;
		}
		else {
			flg = 0;
		}
		count[i] = cnt;
	}

	for (i = 0; i < Q; i++) {
		printf("%d\n", count[r[i]] - count[l[i]]);
	}

	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
 
int N,M,C;
int b[100010];
int a[1010][1010];

signed main() {
    IOS();
    cin>>N>>M>>C;
    rep(i,0,M)cin>>b[i];
    rep(i,0,N){
        rep(j,0,M){
            cin>>a[i][j];
        }
    }
    int ans=0;
    rep(i,0,N){
        int tmp=C;
        rep(j,0,M){
            tmp+=a[i][j]*b[j];
        }
        if(tmp>0)ans++;
    }
    std::cout << ans << endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 2432
n = int(input())
x = list(map(int,input().split()))
hp_total = 10**7

for p in range(min(x),max(x)+1):
    hp = []
    for i in x:
        hp.append((i - p)**2)
    if hp_total > sum(hp):
        hp_total = sum(hp)
        
print(hp_total)
        

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> p;
  vector<int> q;
  int temp;
  REP(i, 0, N){
    cin >> temp;
    p.push_back(temp);
    q.push_back(temp);
  }
  sort(p.begin(), p.end());

  int diff = 0;
  REP(i, 0, N) {
    if (p[i] != q[i])
      diff++;
  }

  if ( (diff == 2) or (diff == 0) )
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i;
    int n;
    char s[101];
    char t[101];
    scanf("%d", &n);
    scanf("%s%s", s, t);
    for(i = 0; i < n; i++){
        printf("%c%c", s[i], t[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
 
int main()
{
  long long A,B,C,D;
  int i,j;
  int number;
  char s[10];
  long long  cnt_t=0;
  long long  cnt_b=0;

//    int k=0;
  scanf("%lld ", &A);
    scanf("%lld",  &B);
    scanf("%lld",  &C);
    scanf("%lld",  &D);
 //printf("%lld %lld %lld %lld", A, B, C, D);
//  scanf("%lld", &M);
  if(A<B) cnt_t=A;
  else    cnt_t=B;
  if(C<D) cnt_b=C;
  else    cnt_b=D;
    
  printf("%lld\n",(cnt_t + cnt_b));
//     printf("%c%c%c\n",s[0][0],s[1][1],s[2][2]);

return 0;
}


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

const int inf = 1000000009;

int in(int y, int x, int h, int w) {
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main() {
    int w,h; 
    while (cin >> w >> h, (w!=0&&h!=0)) {
        vector<vector<int>> maze(h*2-1, vector<int>(w*2-1, inf));
        for (int i=0; i<(h*2-1); i++) {
            if (i%2 == 0) { // 横の壁
                for (int l=0; l<w-1; l++) {
                    int kabe; cin >> kabe;
                    maze[i][l*2+1] = -1 * kabe;
                }
            } else {        // 縦の壁
                for (int l=0; l<w; l++) {
                    int kabe; cin >> kabe;
                    maze[i][l*2] = -1 * kabe;
                }
            }
        }

        vector<int> ny = {1, 0, -1, 0};
        vector<int> nx = {0, -1, 0, 1};
        queue<pair<int, int>> q; q.push(make_pair(0, 0));
        maze[0][0] = 1;
        while (!q.empty()) {
            pair<int, int> cur=q.front(); q.pop();
            int cost = maze[cur.first][cur.second]+1;
            for (int i=0; i<4; i++) {
                int y = cur.first  + ny[i] + ny[i];
                int x = cur.second + nx[i] + nx[i];
                if ( in(y, x, h*2, w*2) 
                  && ((i%2==0&&maze[cur.first+ny[i]][cur.second]!=-1)
                    || (i%2==1&&maze[cur.first][cur.second+nx[i]]!=-1))
                  && cost < maze[y][x]) {
                    maze[y][x] = cost;
                    q.push(make_pair(y, x));
                }
            }
        }

        /*
        for (auto line: maze) {
            for (auto block: line) {
                if (block == -1) {
                    cout << "#";
                } else if (block == inf) {
                    cout << "x";
                } else {
                    cout << block;
                }
            }
            cout << endl;
        }
        */

        
        if (maze[h*2-2][w*2-2] != inf) {
            cout << maze[h*2-2][w*2-2] << endl;
        } else {
            cout << "0" << endl;
        }
    }
}


Measured memory_bytes: 3176
#include <stdio.h>

int linersearch(int);

int S[10000],T[500],n1,n2,kakunin[10000];

int main(){

  int i,j,count = 0;

  scanf("%d",&n1);

  for(i = 0; i < n1;i++) scanf("%d",&S[i]);

  scanf("%d",&n2);

  for(i = 0; i < n2 ; i++) scanf("%d",&T[i]);


  for(j = 0;j < n2;j++){
    i = linersearch(T[j]);
    if(i == 1) count++;
  }


  printf("%d\n",count);

}

int linersearch(int key){
  int i = 0;

  S[n1] = key;

  while(S[i] != key){
    i++;

    if(i == n1) return -1;
  }
    return 1;
}



Measured memory_bytes: 2108
//B-Kagami Mochi
#include<iostream>
#include<algorithm>

using namespace std;
int N;
int main()
{
    cin >> N;
    int d[N];
    for(int i=0;i<N;++i) cin >> d[i];

    sort(d,d+N,greater<int>());
    int counter=1;
    int temp=d[0];
    for(int i=1;i<N;++i)
    {
        if(d[i]!=temp)
        {
            ++counter;
            temp = d[i];
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
n = gets.to_i
sum = Array.new(n+1){ Array.new(n+1,0) }
n.times do |i|
  l = gets.split.map(&:to_i)
  n.times do |j|
    sum[i+1][j+1] += sum[i+1][j] + l[j]
  end
end
n.times do |i|
  n.times do |j|
    sum[j+1][i+1] += sum[j][i+1]
  end
end
ret = - 1 << 31
n.downto(1).each do |i|
  n.downto(1).each do |j|
    (0...i).each do |k|
      (0...j).each do |l|
        x = sum[i][j] - sum[i][l] - sum[k][j] + sum[k][l]
        ret = x if x > ret
      end
    end
  end
end
p ret

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	n %= 10;
	if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
		cout << "hon";
	} else if(n == 0 || n == 1 || n == 6 || n == 8){
		cout << "pon";
	} else{
		cout << "bon";
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int d = scanner.nextInt();
		int n = scanner.nextInt();
		if(n == 100) {
			switch (d) {
			case 0:
				System.out.println(101);
				break;

			case 1:
				System.out.println(10100);
				break;
				
			case 2:
				System.out.println(1010000);
				break;
			}
		}else {
			System.out.println(n*(int)Math.pow(100, d));
		}
	}

}

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

int main() {
	long long n;
	cin >> n;
	long long m = pow(n,0.5);
	int mnc = 1000;
	for(int i=1;i<=m;i++)
	{
		if(n % i == 0)
		{
			long long a = n / i;
			int c = 0;
			while(a > 0)
			{
				a /= 10;
				c++;
			}
			mnc = min(c,mnc);
		}
	}
	cout << mnc << endl;
}


Measured memory_bytes: 256
import itertools
n,m=map(int,input().split())
lamp=[]
for _ in range(m):
    lamp_i=list(map(int,input().split()))
    lamp.append(lamp_i[1:])
p=list(map(int,input().split()))
ans=0
for bit in itertools.product([0,1],repeat=n):
    f=True
    for i in range(m):
        s_i=sum(bit[s-1] for s in lamp[i])
        if (s_i-p[i])%2!=0:
            f=False
            break
    if f:
        ans+=1
print(ans)

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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int a[100][100];
  int b[100][100];
  long c[100][100] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
      cout << c[i][j];
      if (j != l - 1) {
        cout << ' ';
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1324
#include <iostream>
#include <map>
#include <string>

using namespace std;

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

    map<char, int> m;
    for (int i = 0; i < static_cast<int>(n.size()); i++) {
        m[n[i]]++;
    }

    cout << m['2'] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

int main(){
    std::string s;
    std::map<char, int> count;
    int flag = 0;
    std::cin >> s;

    for(int i=0;i<=s.length();i++){
        count[s[i]] += 1;
    }

    for(int i=0;i<=s.length();i++){
        if(s[i]){
            if(count[s[i]]%2 != 0) flag = 1;
        }
    }

    if(flag == 1) std::cout << "No" << std::endl;
    else std::cout << "Yes" << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
lli f(lli x,vvi &edge,vi &dp){
    if(dp[x]!=-1){return dp[x];}
    lli res=0;
    if(edge[x].size()==0) return dp[x]=res;
    rep(i,edge[x].size()){
        res=max(res,f(edge[x][i],edge,dp));
    }
    dp[x]=res+1;
    return dp[x];
}
int main(){
    lli n,m,ans=0;
    cin>>n>>m;
    vvi edge(n);
    vi dp(n,-1);
    vector<bool> s(n,true);
    rep(i,m){
        lli x,y;
        cin>>x>>y;
        x--;y--;
        edge[x].push_back(y);
        s[y]=false;
    }
    rep(i,n){
        if(!s[i]) continue;
        else{
            ans=max(ans,f(i,edge,dp));
        }
    }
    out(ans);
}

Measured memory_bytes: 15436
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int main(){
	int a;
  cin >> a;
  double x;
  	if(a % 2 == 0){
        printf("%.7f", 1.0*2/4);
    }
    else{
        
        printf("%.7f", 1.0*(a/2+1)/a);
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define FOR(i,l,r) for(int (i) = (l); (i) <= (r); (i)++)
using namespace std;
const int maxn = 205;
const int oo = 0x3f3f3f3f;
int n,m;
long long dis[maxn][maxn];
int R;
int r[maxn];
int main(){
#ifdef __APPLE__
	freopen("main.in","r",stdin);
#endif
	scanf(" %d%d%d",&n,&m,&R);
	FOR(i,1,R) scanf(" %d", r + i);
	FOR(i,1,n) FOR(j,1,n) dis[i][j] = oo;
	FOR(i,1,m){
		int a,b,w; scanf(" %d%d%d",&a,&b,&w);
		dis[a][b] = dis[b][a] = w;
	}
	FOR(k,1,n) FOR(i,1,n) FOR(j,1,n) 
		dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
	int ans = oo;
	sort(r+1,r+R+1);
	do{
		int cur = 0;
		FOR(i,1,R-1) cur += dis[r[i]][r[i+1]];
		ans = min(ans,cur);
	}while(next_permutation(r+1,r+R+1));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 3;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;

// void solve () {
// 	int n, W; cin >> n >> W;
// 	vector<vector<ll>> dp(n + 1, vector<ll>(W + 1));

// 	for (auto i = 1; i <= n; ++i) {
// 		int cw, v; cin >> cw >> v;
// 		for (int w = W; w >= 0; --w) {
// 			dp[i][w] = dp[i - 1][w];
// 			if(w - cw >= 0)
// 				dp[i][w] = max(dp[i][w], v + dp[i - 1][w - cw]);
// 		} 
// 	}
// 	cout << dp[n][W] << endl;
// }

void solve () {
	int n, W; cin >> n >> W;
	vector<vector<ll>> dp(2, vector<ll>(W + 1));

	for (auto i = 1; i <= n; ++i) {
		int cw, v; cin >> cw >> v;
		auto & cur = dp[i % 2];
		const auto & prev = dp[(i - 1) % 2];
		for (int w = W; w >= 0; --w) {
			cur[w] = prev[w];
			if(w - cw >= 0) {
				cur[w] = max(cur[w], v + prev[w - cw]);
			}
		}
	}

	cout << dp[n % 2][W];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int h=1, w=1;
  while(h != 0 || w != 0){
    cin >> h >> w;
    rep(i, h){  
      rep(j, w){
        if((i + j) % 2 == 0) cout << "#";
        else cout << ".";
      }
      cout << endl;
    }
    if(h == 0 && w == 0) break;
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3116
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    BigInteger b = in.nextBigInteger();
    if(b.isProbablePrime(70)==true)
      System.out.println(b);
    else
      System.out.println(b.nextProbablePrime());
  }
}

Measured memory_bytes: 36552
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int>a(n + 2, 0); for (int i = 1; i <= n; i++)cin >> a[i];

	int sum = 0; for (int i = 1; i < a.size(); i++)sum += abs(a[i] - a[i - 1]);

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = sum + abs(a[i - 1]-a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]));
		cout << ans << endl;
	}

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first 
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int n, m;
vector<vector<int>> g(10,vector<int>(10,0));

int dfs(int v, int bit) {
  int res = 0;
  bit |= (1<<(v-1));

  if(bit==((1<<n)-1)) return 1;

  rep(i, g[v].size()) {
    if(g[v][i]==1) {
      if((bit>>(i-1))&1) continue;  // もしもビットが立っていたらcontinue;
      res += dfs(i, bit);
    }
  }

  return res;
}

int main() {
  cin >> n >> m;
  
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    g[a][b] = 1;
    g[b][a] = 1;
  }

  cout << dfs(1, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=1e6+5;
int fac[N],ifac[N],n,k,res;
inline int C(R int n,R int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
inline int calc(R int n,R int m,R int k){return dec(C(n+m,n),C(n+m,n+1-k));}
void init(int n=1e6){
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d",&n,&k);
	if(k<n)return puts("0"),0;
	init();
	for(R int a=max((k+1)>>1,n),b;a<=k;++a){
		b=k-a;
		R int t=min(a-(n-1),b);
		if(a-(n-1)==t)--t;
		upd(res,calc(a,b-(a==b),-t));
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 8064
#[test]
fn test_solve() {
    assert_eq!(solve("3\n7 12 8\n"), "4\n");
    assert_eq!(solve("2\n11 11\n"), "2\n");
    assert_eq!(solve("1\n0\n"), "0\n");
    assert_eq!(solve("1\n12\n"), "12\n");
    assert_eq!(solve("3\n4 4 4\n"), "0\n");
    assert_eq!(solve("11\n 2 2 4 4 6 6 8 8 10 10 12\n"), "2\n");
    assert_eq!(solve("2\n12 12"), "0\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n = sc.read();
    let d: Vec<usize> = (0..n).map(|_| sc.read()).collect();
    let mut cnt = vec![0; 13];
    for &d in &d {
        cnt[d] += 1;
    }
    let cnt = cnt;

    let mut ext = vec![false; 24];

    if cnt[0] > 0 || cnt[12] > 1 {
        return "0\n".to_string();
    }
    ext[0] = true;
    ext[12] = cnt[12] > 0;

    for i in 1..12 {
        if cnt[i] > 2 {
            return "0\n".to_string();
        }
        ext[i] = cnt[i] > 0;
        ext[24 - i] = cnt[i] > 1;
    }

    let mut ret = 0;
    for s in 0..1 << 11 {
        for k in 1..12 {
            if s&(1<<(k-1)) != 0 && ext[k] && !ext[24-k] {
                ext[k] = false;
                ext[24-k] = true;
            }
            if s&(1<<(k-1)) == 0 && !ext[k] && ext[24-k] {
                ext[k] = true;
                ext[24-k] = false;
            }
        }
        let mut r = 12;
        for dis in (1..12).rev() {
            for i in 0..24 {
                if ext[i] && ext[(i+dis)%24] {
                    r = dis;
                }
            }
        }
        ret = std::cmp::max(ret, r);
    }

    format!("{}\n", ret)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
list_input = [input() for i in range(3)]

S_and_T = list_input[0].split(' ')
S = S_and_T[0]
T = S_and_T[1]

A_and_B = list_input[1].split(' ')
A = int(A_and_B[0])
B = int(A_and_B[1])

U = list_input[2]

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

print(A, B)

Measured memory_bytes: 3064
N, T = map(int, input().split())
a_list = list(map(int, input().split()))

min_num = 0
margin_list = []
for i in range(N):
    if i == 0:
        min_num = a_list[0]
    else:
        if min_num > a_list[i]:
            min_num = a_list[i]
        else:
            margin_list.append(a_list[i]-min_num)
max_num = max(margin_list)
print(margin_list.count(max_num))

Measured memory_bytes: 14244
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


int main(){
 int K;
 string S;
  cin >>K >>S;
  if( S.size() <= K){
   cout <<S<<endl; 
  }else{
    string sub = S.substr(0,K) + "...";
      cout <<sub<<endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long
char s[2][53];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	rep(i, 2)rep(j, n) {
		cin >> s[i][j];
	}
	int ans = 1;
	rep(i, n) {
		if (s[0][i] == s[1][i]) {
			if (!i)ans *= 3;
			else if (s[0][i - 1] == s[1][i - 1])ans *= 2;
		}
		else {
			if (!i)ans *= 6;
			else if (s[0][i - 1] == s[1][i - 1])ans *= 2;
			else ans *= 3;
			i++;
		}
		ans %= MOD;
	}
	COUT(ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int MAX_N=1e5; // 1e8=x, 1e7=? 1e6=o                                                                                     
int n[MAX_N+1]={};
int prime[MAX_N+1];
void eratos_sieve(){
  for(int i=2;i<=MAX_N;i++){
    if(!n[i]){
      prime[i]=1;
      for(int j=i;j<=MAX_N;j+=i) n[j]=1;
    }
  }
}
int main(){
  vector <int> same;
  eratos_sieve();
  for(int i=3;i<100000;i+=2) if(prime[i]&&prime[(i+1)/2]) same.push_back(i);
  //for(int i=0;i<same.size();i++) cout<<same[i]<<" ";                                                                         
  int q,l,r;
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>l>>r;
    int r0=0;
    for(int j=0;j<(int)same.size();j++) if(l<=same[j]&&same[j]<=r) r0++;
    cout<<r0<<endl;
  }
  return 0;
}





Measured memory_bytes: 1408
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using  namespace std;
int main()
{
    int n;

    cin >> n;

    int firstn = n;

    int s=0;
    while (n != 0) {
        s += n % 10;
        n /= 10;
    }

    if (firstn % s == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;

}



Measured memory_bytes: 3624
use std::io::stdin;

fn input_ints() -> Vec<u64> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => {
            st.split_whitespace()
                .map(|s| s.parse().unwrap())
                .collect()
        }
        Err(_) => panic!("err"),
    }
}

fn solve(s: Vec<u64>) -> u64 {
    let all = s.iter().sum();
    if all % 10 != 0 {
        return all;
    } else {
        let mut min = 101;
        for itm in s {
            if itm % 10 == 0 {
                continue;
            }
            if min > itm {
                min = itm;
            }
        }
        if min == 101 {
            return 0;
        }
        return all - min;
    }
}

fn main() {
    let l = input_ints();
    let n = l[0];
    let mut s = Vec::new();
    for _ in 0..n {
        let l = input_ints();
        s.push(l[0]);
    }
    println!("{}", solve(s));
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll n, m;
ll a[10101];

int main(){
	while(cin >> n && n > 0){
		ll ans = 0;
		ll sum = 0;
		REP(i,0,n){
			cin >> a[i];
			sum += a[i];
		}
		REP(i,0,n){
			if(a[i] * n <= sum){
				ans++;
			}
		}
		p(ans);
	}

	return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const ll MAX = 210000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main(){
    COMinit();
    ll n;cin>>n;
    ll m;cin>>m;
    ll k;cin>>k;
    For(i,1,n+1){
        ll cost=i*(n-i)*m%MOD*m%MOD*COM(n*m-2,k-2)%MOD;
        ans=(ans+cost)%MOD;
    }
    For(i,1,m+1){
        ll cost=i*(m-i)*n%MOD*n%MOD*COM(n*m-2,k-2)%MOD;
        ans=(ans+cost)%MOD;
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 5120
import java.io.*;
import java.util.*;


public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    }
}


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

using namespace std;

int main()
{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	 int a,b,i,shi,ans = 1;
	 cin >> a;
	 int arr[a];

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

	 shi = arr[0];

	 for (b = 1; b < a; ++b)
	 {
	 	if (arr[b] >= shi)
	 	{
	 		shi = arr[b];
	 		ans++;
	 	}
	 }

	 cout << ans;

    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static Scanner sc;
    static PrintWriter out;

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        out = new PrintWriter(System.out);
        new Main().solve();
        out.flush();
    }

    public void solve() {
        int n = sc.nextInt();
        int m = sc.nextInt();

        UF uf = new UF(n);
        for(int i=0; i<m; i++) {
            uf.join(sc.nextInt()-1, sc.nextInt()-1);
        }
        Set<Integer> set = new HashSet<>();
        for(int i=0; i<n; i++) {
            set.add(uf.root(i));
        }
        out.println(set.size() -1);

    }

    static class UF {
        int[] p;
        int n;
        UF(int n) {
            this.n = n;
            p = new int[n];
            for(int i=0; i<n; i++){
                p[i] = i;
            }
        }
        int root(int a) {
            if(p[a] == a) {
                return a;
            }
            int res =  root(p[a]);
            p[a] = res;
            return res;
        }
        void join(int a ,int b) {
            p[root(a)] = p[root(b)];
        }
    }

}

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

using ll = long long;

int main()
{
    int n;
    cin>>n;
    ll arr[n+5];
     map<ll,ll>mp;
     set<ll>s;


    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
      mp[arr[i]]++;
    s.insert(arr[i]);
    }

  //  map<int,int>one;
  //  map<int,int>two;

   ll sum=0;

   for(set<ll>::iterator it=s.begin();it!=s.end();it++)
   {
       {
       ll a = mp[*it];
    //  cout<<a<<endl;
     a=a*(a-1);
     sum+=a;
     //  cout<<sum<<endl;
       }
   }
  for(int i=0;i<n;i++)
  {
      ll k=arr[i];
   //   cout<<mp[arr[i]]<<" ";


      {
          ll c = mp[k];
          c=c*(c-1);
          ll sumb=sum-c;
          ll a=mp[k]-1;
          cout<<(sumb+(a*(a-1)))/2<<endl;
      }
  }

}


Measured memory_bytes: 18176
N = input().split()
while True :
    if N[1] == "?" :
        break
    a = int(N[0])
    b = int(N[2])
    if N[1] == "+" :
        print(a+b)
    if N[1] == "-":
        print(a-b)
    if N[1] == "*" :
        print(a*b)
    if N[1] == "/" :
        print(a//b)
    N = input().split()




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

int main(){
    
    int H, W;
    
    while(true){
        
        cin >> H >> W;
        
        if(H == 0 && W == 0) {
            break;
        }
        
        for(int i = 0; i < H; ++i){
            
            for(int k = 0; k < W; ++k){
                
                cout << "#";
            }
            
            cout << endl;
        }
        
        cout << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3124