akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int in1 = Integer.parseInt(scanner.next()), in2 = Integer.parseInt(scanner.next());
		scanner.close();
		int x = (in1>in2)? in2: in1;
		int y = (in2==x)? in1%in2: in2%in1;

		int init = y;
		if(y==0) init = x;
		for(int i=init; i>0; i--) {
			if(x%i==0 && y%i==0) {
				System.out.println(i);
				break;
			}
		}

	}

}



Measured memory_bytes: 26352
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 1
p = a[0]
while True:
    if p == 2:
        print(ans)
        break
    elif (p == a[p-1]) | (ans > n):
        print(-1)
        break
    else:
        p = a[p-1]
        ans += 1

Measured memory_bytes: 13028
N = int(input())
S = [0 if a == 'E' else 1 for a in input()]
Sp = [S[0]]
for i in range(1, N):
    Sp.append(Sp[-1]+S[i])

max = Sp[-1]
ans = N - max
for i in range(1, N):
    ans = min(abs(Sp[i-1]) + abs(N-(i+1)-max+Sp[i]), ans)

print(ans)

Measured memory_bytes: 19572
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
 
int n, a, b;
ll x[112345], y[112345];
bool done[112345];
 
int main() {
	cin >> n >> a >> b;
	a--; b--;
	REP(i, n) scanf("%lld %lld", x + i, y + i);
	
	REP(i, n) {
		ll tx = x[i] + y[i], ty = x[i] - y[i];
		x[i] = tx; y[i] = ty;
	}
	
	map<ll, set<pll> > ss[2];
	map<ll, vector<ll> > mv[2];
	
	REP(i, 2) {
		REP(j, n) {
			if (i == 0) {
				ss[i][x[j]].insert(pll(y[j], j));
				mv[i][x[j]].push_back(y[j]);
			}
			else {
				ss[i][y[j]].insert(pll(x[j], j));
				mv[i][y[j]].push_back(x[j]);
			}
		}
	}
	
	REP(i, 2) {
		map<ll, vector<ll> > tmp;
		
		for (map<ll, vector<ll> >::iterator it = mv[i].begin(); it != mv[i].end(); ++it) {
			vector<ll> v = it->second;
			sort(ALL(v));
			tmp[it->first] = v;
		}
		
		mv[i] = tmp;
	}

	ll ans = 0;
	ll d = max(abs(x[a] - x[b]), abs(y[a] - y[b]));
	
	queue<int> que;
	que.push(a);
	
	while (!que.empty()) {
		int pos = que.front(); que.pop();
		
		if (done[pos]) continue;
		done[pos] = true;
		
		REP(i, 2) {
			ll num = x[pos] + d * (i == 0 ? 1 : -1);
			
			vector<ll> &v = mv[0][num];
			ans += lower_bound(ALL(v), y[pos] + d) - upper_bound(ALL(v), y[pos] - d);
			
			set<pll> &s = ss[0][num];
			
			set<pll>::iterator it = s.upper_bound(pll(y[pos] - d, 0));
			
			while (it != s.end()) {
				if (it->first >= y[pos] + d) break;
				if (!done[it->second]) que.push(it->second);
				it = s.erase(it);
			}
			
		}
		
		REP(i, 2) {
			ll num = y[pos] + d * (i == 0 ? 1 : -1);
			
			vector<ll> &v = mv[1][num];
			ans += upper_bound(ALL(v), x[pos] + d) - lower_bound(ALL(v), x[pos] - d);
			
			set<pll> &s = ss[1][num];
			
			set<pll>::iterator it = s.lower_bound(pll(x[pos] - d, 0));
			
			while (it != s.end()) {
				if (it->first > x[pos] + d) break;
				if (!done[it->second]) que.push(it->second);
				it = s.erase(it);
			}
			
		}
	}
	
	cout << ans / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 83712
#include<bits/stdc++.h>
using namespace std;
#define inf          0x3f3f3f3f
#define go(a,b,c)    for(int a=b;a<=c;a++)
#define gov(a,b)     for(int a=0;a<b.size();a++)
#define rgo(a,b,c)   for(int a=b;a>=c;a--)
#define sf(a)        scanf("%d",&a)
#define sff(a,b)     scanf("%d%d",&a,&b)
#define sfff(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define eps          1e-9
#define ft           first
#define sd           second
#define prt(a)       printf("%d\n",a)
#define prn(i,n,a)   printf("%d%c",a,i==n?'\n':' ')
#define pb           push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef double db;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int maxn=3005;
const LL mod=1e9+7;
int read()
{
	int f=0,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
//=======================================================
LL dp[maxn][maxn][2];
void ini()
{
	memset(dp,0,sizeof(dp));
}
int n,m; 
void ad(LL &a,LL b)
{
	a+=b%mod;
	a%=mod;
}
void work()
{
	ini();
	go(i,0,n)dp[0][i][i==0]=1;
	go(i,0,m)
	go(j,0,n)
	go(c,0,1)
	{
		LL tp=dp[i][j][c];
		if(j>0)
		{
			ad(dp[i+1][j][c|j==1],tp);
			ad(dp[i+1][j-1][c|j==1],tp);
		}
		if(j<n)
		{
			ad(dp[i+1][j][c],tp);
			ad(dp[i+1][j+1][c],tp);
		}
	}
	LL ans=0;
	go(i,0,n)ans+=dp[m][i][1]%mod;
	cout<<ans%mod<<endl;
}
int main()
{
	while(~sff(n,m))
	{
		work();
	}
	return 0;
}

Measured memory_bytes: 141312
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define pri 1000000007
#define nonod 1000001
#define pr pair <ll,ll>
#define mnx  1000001
#define inf 100000000000000001
#define prin(x) cout<<setprecision(9)<<fixed<<x<<endl;
using namespace std;





void masterstroke(ll ta){
ll h,w;
cin>>h>>w;
ll dp[h][w];
string a[h];

vector <ll> col[w],row[h];
for(ll i=0;i<w;i++){col[i].PB(-1);}
for(ll i=0;i<h;i++){row[i].PB(-1);}

for(ll i=0;i<h;i++){
	cin>>a[i];
	for(ll j=0;j<w;j++){
     if(a[i][j]=='#'){row[i].PB(j);col[j].PB(i);}
     //if(a[i][j]=='.')row[j]
	}
}
for(ll i=0;i<w;i++){col[i].PB(h);}
for(ll i=0;i<h;i++){row[i].PB(w);}
ll mx=0;

for(ll i=0;i<h;i++){
	for(ll j=0;j<w;j++){
     if(a[i][j]=='.'){
     	//cout<<i<<j<<endl;
     	auto ze=upper_bound(all(row[i]),j);
     	ll x1=*ze;
     	ze--;
     	ll x2=*ze;
     	auto zee=upper_bound(all(col[j]),i);
     
     	ll y1=*zee;
     	zee--;
     	ll y2=*zee;
     	//cout<<x2<<x1<<y1<<y2<<endl;
     	ll ans=abs(y2-y1)-1+abs(x2-x1)-1-1;
     	mx=max(mx,ans);
     	
     	
     	
     }
	}
}
cout<<mx<<endl;



}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)masterstroke(i);
}

Measured memory_bytes: 70016
N = int(input())
A = list(input().split())
B = list(input().split())
C = list(input().split())
S = 0
for j in range(0,N):
  a = int(A[j])
  b = int(B[a-1])
  S = S + b

for i in range(0,N-1):
  a = int(A[i])+1
  b = int(A[i+1])
  if a == b:
    S = S + int(C[a-2])


print(S)
  

Measured memory_bytes: 3064
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  ll A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;

  ll l = abs(A - B);
  if (l == 0) {
    out("YES");
    return 0;
  }
  if (W >= V) {
    out("NO");
    return 0;
  }
  if ((V - W) * T >= l) {
    out("YES");
  } else {
    out("NO");
  }
}


Measured memory_bytes: 3612
use std::io::{stdout, Write, BufWriter};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        k: i32,
        n: usize,
        houses: [i32; n],
    }
    houses.sort();
    let first: i32;
    {first = *(houses.first().unwrap());}
    {houses.push(first + k);}

    println!("{}", k - houses.iter().skip(1)
             .zip(houses.iter())
             .map(|(&next, &previous)| next - previous )
             .max()
             .unwrap()
    );
}


Measured memory_bytes: 8444
from collections import defaultdict

n=int(input())
d=defaultdict(list)

for i in range(n):
    a=int(input())

    for _ in range(a):
        x,y = map(int,input().split())
        d[i].append((x-1,y))

res=0
for i in range(1<<n):
    bf=False
    for j in range(n):

        if (i>>j)&1 == 1:
            for x,y in d[j]:
                if (i>>x)&1 != y: 
                    bf=True
                    break
            if bf:break 

    if not bf:
        # count=0
        # for m in range(n):
        #     if (i & (1 << m)) : count+=1
        #     res=max(res,count)
        res=max(res,bin(i).count("1"))

print(res)

Measured memory_bytes: 3316
N, C = gets.split.map(&:to_i)
dboard = C.times.map { gets.split.map(&:to_i) }
board = N.times.map { gets.split.map(&:to_i) }
group = {}
(0...N).each do |i|
  (0...N).each do |j|
    c = board[i][j] - 1
    n = (i + 1 + j + 1) % 3
    group[n] ||= []
    group[n].push(c)
  end
end
group_sums = {}
group.each do |g, l|
  sums = []
  (0...C).each do |c|
    sum = 0
    l.each do |prev_c|
      sum += dboard[prev_c][c]
    end
    sums.push([c, sum])
  end
  sorted = sums.sort_by { |(_, sum)| sum }
  group_sums[g] = sorted
end
ans = 1 << 60
(group_sums[0] || [[-1, 0]]).take(3).each do |(zero_c, zero_sum)|
  (group_sums[1] || [[-2, 0]]).take(3).each do |(one_c, one_sum)|
    next if zero_c == one_c
    (group_sums[2] || [[-3, 0]]).take(3).each do |(two_c, two_sum)|
      next if zero_c == two_c || one_c == two_c
      sum = zero_sum + one_sum + two_sum
      ans = sum if sum < ans
    end
  end
end
puts ans


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

template<class T> struct Seg { 
	const T ID = 0; // comb(ID,b) must equal b
	T combine(T a, T b) { return a+b; } 
	int n; vector<T> seg;
	void init(int _n) { n = _n; seg.assign(2*n,ID);}

	void update(int p, T value) {	// set value at position p
		seg[p += n] = value;
		for (p /= 2; p; p /= 2) combine(seg[2*p], seg[2*p+1]);
	}
    
	T query(int l, int r) {	 // sum on interval [l, r]
		T ra = ID, rb = ID; 
		for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
			if (l&1) ra = combine(ra,seg[l++]);
			if (r&1) rb = combine(seg[--r],rb);
		}
		return combine(ra,rb);
	}
};

vi arr;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int N; cin >> N;
	Seg<int> seg; seg.init(N);

	arr.resize(N);
	vi perm (N);

	F0R(i, N) {
		cin >> arr[i];
		perm[i] = i;
	}

	sort(perm.begin(), perm.end(), [] (int lhs, int rhs) {
		return arr[lhs] > arr[rhs];
	});

	int total = 0;
	bool parity = false;
	for (int i = 0; i < N; ++i) {
		int pos = perm[i];
		int ideal = N - i - 1;
		if (ideal % 2 != pos % 2) {
			if (!parity) ++total;
			parity = !parity;
		}

		seg.update(perm[i], 1);
	}

	print(total);
}

Measured memory_bytes: 1792
#[allow(unused_imports)]
use std::cmp::{min,max};
use std::io::stdin;
 
#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let (mut ans, mut cur) = (0, 0);
    let mut prev: Option<usize> = None;
    let n: usize = scan.next();
    for _ in 0..n {
        let h: usize = scan.next();
        if let Some(p) = prev {
            if h <= p {
                cur += 1;
            } else {
                cur = 0;
            }
            ans = max(ans, cur);
        }
        prev = Some(h);
    }
    println!("{}", ans);
}


Measured memory_bytes: 11640
// https://atcoder.jp/contests/abc173/tasks/abc173_a

#include <stdio.h>

int main(void) {
    
    int n;
    scanf("%d", &n);
    if(n%1000==0)
        printf("%d", 0);
    else
        printf("%d", 1000-(n%1000));

    return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

long long fac[1000010], finv[1000010], inv[1000010];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000010; 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;
    }
}

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

int main(){
    ll x,y;
    cin>>x>>y;
    if((2*x-y)%3!=0 || (-x+2*y)%3!=0){
        cout<<0<<endl;
        return 0;
    }

    ll a=(2*x-y)/3,b=(-x+2*y)/3;
    if(a<0 || b<0){
        cout<<0<<endl;
        return 0;
    }

    COMinit();

    cout<<COM(a+b,a)<<endl;
}

Measured memory_bytes: 27028
from enum import Enum


class Dfs(object):
    """ Depth First Search """
    class Status(Enum):
        white = 1
        gray = 2
        black = 3

    def __init__(self, data):
        self.time = 0
        num_of_nodes = len(data)+1
        self.color = [Dfs.Status.white] * (num_of_nodes+1)
        self.S = []
        self.M = self._make_matrix(data)
        self.s_time = [0] * (len(data) + 1)
        self.f_time = [0] * (len(data) + 1)

    def _make_matrix(self, data):
        """ ??£??\??????????????? (M[i][j]?????¢??§??????????????????+1??????????????????????????????) """
        num = len(data)
        graph_table = [[0] * (num+1) for _ in range(num+1)]
        for d in data:
            node_id = d[0]
            num_of_e = d[1]
            for e in d[2:]:
                graph_table[node_id][e] = 1
        return graph_table

    def search(self, start):
        self.time += 1
        self.s_time[start] = self.time
        self.S.append(start)
        self.color[start] = Dfs.Status.gray

        while self.S:
            u = self.S[-1]
            v = self.next(u)
            if v != None:
                if self.color[v] == Dfs.Status.white:
                    self.color[v] = Dfs.Status.gray
                    self.time += 1
                    self.s_time[v] = self.time
                    self.S.append((v))
            else:
                self.S = self.S[:-1]
                self.color[u] = Dfs.Status.black
                self.time += 1
                self.f_time[u] = self.time

    def next(self, node):
        """ ?¬?????¨???????????±???????????????????????????????????????????????¨??????????????????????????????? """
        edges = self.M[node]
        for i in range(1, len(edges)):
            if edges[i] == 1:
                if self.color[i] == Dfs.Status.white:
                    return i
        return None

    def print(self):
        for r in self.M:
            print(*r)


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = []
    for _ in range(num):
        data.append(list(map(int, input().split(' '))))

    # ???????????????
    d = Dfs(data)
    for i in range(1, num+1):
        if d.color[i] == Dfs.Status.white:
            d.search(i)

    # ???????????????
    for i in range(1, num+1):
        print('{0} {1} {2}'.format(i, d.s_time[i], d.f_time[i]))

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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N;
    vector<int> A, B, C;
    int satisfaction = 0;

    cin >> N;


    rep(i, N) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    for (int i = 1; i < N; i++) {
        if(A[i-1] == A[i] - 1) {
            B.push_back(A[i-1] - 1);
        }
    }

    rep(i, N) {
        int b; 
        cin >> b;
        satisfaction += b;
    }

    rep(i, N - 1) {
        int c;
        cin >> c;
        C.push_back(c);
    }

    B.resize(B.size());
    rep(i, B.size()) {
        satisfaction += C[B[i]];
    }

    cout << satisfaction << endl;
}

Measured memory_bytes: 256
const MAX: usize = 100000;

fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let (_, is_prime) = sieve(MAX);
    let mut like_number = vec![false;MAX+1];
    for i in 0..MAX+1 {
        if i % 2 == 1 {
            like_number[i] = is_prime[i] && is_prime[(i+1)/2];
        }
    }
    let mut sum = vec![0;MAX+2];
    for i in 0..MAX {
        sum[i+1] = sum[i] + (if like_number[i] {1} else {0});
    }

    let q: usize = iter.next().unwrap().parse().unwrap();
    for _ in 0..q {
        let l: usize = iter.next().unwrap().parse().unwrap();
        let r: usize = iter.next().unwrap().parse().unwrap();
        println!("{}", sum[r+1] - sum[l]);
    }
}

#[doc = " return: (primes, is_prime)"]
#[allow(dead_code)]
fn sieve(n: usize) -> (Vec<usize>, Vec<bool>) {
    let mut primes = vec![];
    let mut is_prime = vec![true; n + 1];
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..n + 1 {
        if is_prime[i] {
            primes.push(i);
            for j in (2..).map(|j| j * i).take_while(|&j| j <= n) {
                is_prime[j] = false;
            }
        }
    }
    (primes, is_prime)
}


Measured memory_bytes: 6780
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    int sum = 0;
    cin >> s;
    for(int i=0; i<4; i++)
    {
        if(s[i] == '+') sum++;
        else if(s[i] == '-') sum--;
    }

    cout << sum;
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int c[n];
  int a[n][m];
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }
  int under[m];
  int ans = 1e7;
  int memo;
  for(int i = 0; i < (1<<n); i++){
    rep(j,m) under[j] = 0;
    memo = 0;
    rep(j,n){
      if(i & (1 << j)){
        memo += c[j];
        rep(k,m){
          under[k] += a[j][k];
        }
      }
    }
    bool flag = true;
    rep(j,m){
      // printf("%d %d\n",j, under[j]);
      if(under[j] < x) flag = false;
    }
    if(flag) ans = min(ans,memo);
  }

  if(ans == 1e7){
    printf("-1\n");
  }else{
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vll a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    ll now = 0;
    for (int i = n-1; i >= 0; --i) {
        ll m = a[i] + now;
        now += (b[i] - (m % b[i])) % b[i];
    }
    cout << now << endl;
}

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

using namespace std;
typedef long long ll;

int main(void)
{
string S;
cin>>S;

if(S=="Sunny")
{
    cout<<"Cloudy"<<endl;
}
if(S=="Cloudy")
{
    cout<<"Rainy"<<endl;
}
if(S=="Rainy")
{
    cout<<"Sunny"<<endl;
}



}


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

#define int long long

int N;
int a[200010];
map<int,int> mp;

main()
{
	ios::sync_with_stdio(false);
	
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	sort(a+1,a+1+N);
	
	int ans=0;
	for(int i=N;i>=1;i--)
	{
		if(mp[a[i]]<1) continue; 
		mp[a[i]]--;
		
		int t=1;
		while(t<=a[i]) t*=2;
		if(mp[t-a[i]]>=1)
		{
			ans++;
			mp[t-a[i]]--;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 26880
#include <iostream>
using namespace std;
int main(void){
  int n;
  int a=1;
  cin >> n;
  if(n==1){
    cout << '1' << endl;
    return 0;
  }else{
    while(a*2<=n){
      a*=2;
    }
    cout << a << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#pragma region Template
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}
#pragma endregion Template

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

    ll N;
    scan(N);
    vector<ll> a(N);
    scan(a);

    sort_(a);
    deque<ll> plus, minus;
    for (auto &&i : a) {
        if (i < 0)
            minus.push_front(i);
        else
            plus.push_back(i);
    }

    if (minus.empty()) {
        minus.push_front(plus.front());
        plus.pop_front();
    }
    if (plus.empty()) {
        plus.push_front(minus.front());
        minus.pop_front();
    }

    ll now = minus.front();
    minus.pop_front();
    vector<pair<ll, ll>> ans;
    int size = plus.size() - 1;
    rep(_, size) {
        ll to = plus.front();
        ans.emplace_back(now, to);
        now -= to;
        plus.pop_front();
    }
    ans.emplace_back(plus.front(), now);
    now = plus.front() - now;

    size = minus.size();
    rep(_, size) {
        ll to = minus.front();
        ans.emplace_back(now, to);
        now -= to;
        minus.pop_front();
    }
    print(now);
    for (auto &&i : ans) {
        print(i.first, i.second);
    }

    return 0;
}

Measured memory_bytes: 5240
#include <iostream>
using namespace std;
typedef long long ll;
ll h,w,dp[10][10],a,ans;
int main(void){
    cin>>h>>w;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>dp[i][j];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a;
            if(a!=-1)ans+=dp[a][1];
        }
    }
    cout<<ans<<endl;
}


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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto a = load<int>();
	auto b = load<int>();
	auto c = load<int>();
	auto score = 0;
	auto r1 = min(c, a);
	score += r1;
	a -= r1;
	c -= r1;
	auto r2 = min(b, c);
	score += 2 * r2;
	b -= r2;
	c -= r2;
	auto r3 = min(c, 1);
	score += r3;
	c -= r3;
	auto r4 = b;
	score += r4;
	b -= r4;
	cout << score << '\n';
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, readline().split())

    print((A - 1) * (B - 1))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9068
while True:
	n = int(input())
	if n == 0: break
	ans = [0 for _ in range(7)]
	for _ in range(n):
		age = int(input())
		if age < 10:
			ans[0] += 1
		elif age < 20:
			ans[1] += 1
		elif age < 30:
			ans[2] += 1
		elif age < 40:
			ans[3] += 1
		elif age < 50:
			ans[4] += 1
		elif age < 60:
			ans[5] += 1
		else:
			ans[6] += 1
	for a in ans:
		print(a)

Measured memory_bytes: 7660
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long
int inf = (1LL <<  62);
using namespace std;

signed main(){
    int n;
    int mod = pow(10, 9) + 7;
    cin >> n;
    int x = n - 1;
    map<int, int> mp;
    set<int> st;
    bool ch = false;
    while(1){
        mp[x] = 0;
        st.insert(x);
        x -= 2;
        if(x < 0){
            break;
        }
    }
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        if(mp.find(p) == mp.end()){
            ch = true;
        }
        else if(mp[p] == 2){
            ch = true;
        }
        else if(p == 0 && mp[0] == 1){
            ch = true;
        }
        else{
            mp[p]++;
        }
    }
    
    int ans = 1;
    
    if(ch){
        cout << 0;
    }else{
        for(auto itr = st.begin(); itr != st.end(); ++itr) {
            if(mp[*itr] != 0){
                if(*itr == 0){
                    continue;
                }
                ans = (ans * 2) % mod;
            }
        }
        cout << ans;
    }
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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 (b < a) { a = b; return 1; } return 0; }

map<lli,lli> makePrimeList2(lli n){
    map<lli,lli> m;
    lli a = 2;
    while(n>=a*a){
        if(n%a==0){
            m[a]++;
            n /= a;
        }
        else a++;
    }
    if(n!=1)m[n]++;
    return m;
}

set<lli> use;
void func(long long N){

    lli sum = 0;
    map<lli,lli> prime = makePrimeList2(N);

    for(auto e:prime){
        lli now = 1;
        while(e.second - now>=0){
            LOG2(e.first,e.second);
            sum++;
            e.second-=now;
            now++;
        }
    }

    cout<<sum<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    func(N);
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
//#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;

int n,m,x,y,z,t,tab[1005][1005];
char c[1005][1005];
vector<pair<int,int>>chances;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n >> m >> x >> y >> z >> t;
    chances.insert(chances.end(),{{-2,-2},{-2,-1},{-2,0},{-2,1},{-2,2},{-1,-2},{-1,-1},{-1,1},{-1,2},{0,-2},{0,2},{1,-2},{1,-1},{1,1},{1,2},{2,-2},{2,-1},{2,0},{2,1},{2,2}});
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> c[i][j];
        }
    }
    queue<pair<int,int>>Qsimplu;
    queue<pair<int,int>>Qcost;
    Qsimplu.push({x,y});
    Qcost.push({x,y});
    tab[x][y] = 1;
    while((int)Qsimplu.size() || (int)Qcost.size()){
        if(Qsimplu.empty() == false){
            auto it = Qsimplu.front();
            if(it.fr + 1 <= n && tab[it.fr+1][it.sc] == 0 && c[it.fr+1][it.sc] == '.'){
                tab[it.fr + 1][it.sc] = tab[it.fr][it.sc];
                Qsimplu.push({it.fr+1,it.sc});
                Qcost.push({it.fr+1,it.sc});
            }
            if(it.fr - 1 >= 1 && tab[it.fr-1][it.sc] == 0 && c[it.fr-1][it.sc] == '.'){
                tab[it.fr - 1][it.sc] = tab[it.fr][it.sc];
                Qsimplu.push({it.fr-1,it.sc});
                Qcost.push({it.fr-1,it.sc});
            }
            if(it.sc + 1 <= m && tab[it.fr][it.sc + 1] == 0 && c[it.fr][it.sc + 1] == '.'){
                tab[it.fr][it.sc + 1] = tab[it.fr][it.sc];
                Qsimplu.push({it.fr,it.sc+1});
                Qcost.push({it.fr,it.sc+1});
            }
            if(it.sc - 1 >= 1 && tab[it.fr][it.sc - 1] == 0 && c[it.fr][it.sc - 1] == '.'){
                tab[it.fr][it.sc - 1] = tab[it.fr][it.sc];
                Qsimplu.push({it.fr,it.sc-1});
                Qcost.push({it.fr,it.sc-1});
            }
            Qsimplu.pop();
        }
        else{
            auto it = Qcost.front();
            for(auto it1 : chances){
                if(it.fr + it1.fr >= 1 && it.fr + it1.fr <= n && it.sc + it1.sc >= 1 && it.sc + it1.sc <= m && c[it.fr + it1.fr][it.sc + it1.sc] == '.' && tab[it.fr + it1.fr][it.sc + it1.sc] == 0){
                    tab[it.fr + it1.fr][it.sc + it1.sc] = tab[it.fr][it.sc] + 1;
                    Qsimplu.push({it.fr + it1.fr, it.sc + it1.sc});
                    Qcost.push({it.fr + it1.fr,it.sc + it1.sc});
                }
            }
            Qcost.pop();
        }
    }
    if(tab[z][t] >= 1)cout << tab[z][t] - 1 << '\n';
    else{
        cout << -1 << '\n';
    }
}


Measured memory_bytes: 8616
#include<stdlib.h>
#define rp(i,n)for(int i=0;i<n;i++)
up(const int*a,const int*b){return *a-*b;}
n,m,x[100002],a[100002],sum=0;
main(){
scanf("%d%d",&n,&m);
rp(i,m)scanf("%d",&x[i]);qsort(x,m,sizeof(int),up);
rp(i,m-1)a[i]=x[i+1]-x[i];qsort(a,m-1,sizeof(int),up);
rp(i,m-n)sum+=a[i];printf("%d",sum);
}

Measured memory_bytes: 1396
#include <cstdio>
#include <algorithm>
const int MaxN = 1e6 + 10;
int F[MaxN], A[MaxN];	
int N; 
bool Cmp(int A, int B) {
	return A > B;
}
int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
	std::sort(A + 1, A + 1 + N, Cmp);
	/*SG函数 ↓*/
	int P = 0;
	while(P + 1 < N && P + 1 < A[P + 2]) P += 1;
	int C = (A[P + 1] - P) & 1, B = 1;
	for(int i = P + 2; i <= N && A[i] > P; i++) B ^= 1;
	if(B && C) printf("Second");
	else printf("First");
} 


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN=110000, MOD=1e9+7;
int n, m, dp[MAXN];
bool broken[MAXN];
int main()
{
	cin>>n>>m;
	int temp;
	for(int i=0;i<m;i++)
	{
		cin>>temp;
		broken[temp]=true;
	}
	dp[n]=1;
	for(int i=n-1;i>=0;i--)
		if(!broken[i])
			dp[i]=(dp[i+1]+dp[i+2])%MOD;
	cout<<dp[0];
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
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 all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,k;
  cin>>n>>k;
  vll x(n);
  rep(i,n) cin>>x[i];
  sort(all(x));
  ll h=INF;
  for(int i=0;i<=n-k;i++){
    h=min(h,x[i+k-1]-x[i]);
  }
  COUT(h);
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<int> > dist;
vector<vector<int> > vis;
int n,m;
void bfs(vector<vector<char> > &a,int k,int l)
{
  queue<pair<int,int> > q;
  q.push({k,l});
  while(!q.empty()){
    pair<int,int> p=q.front();
   int i=p.first;
    int j=p.second;
    q.pop();
      vis[i][j]=1;
      if(i+1<n && j>=0 && vis[i+1][j]==0 && a[i+1][j]=='.')
      {
        dist[i+1][j]=dist[i][j]+1;
        vis[i+1][j]=1;
        q.push({i+1,j});
        
      }

      if(i>=0 && j+1<m && vis[i][j+1]==0 && a[i][j+1]=='.')
      {
        dist[i][j+1]=dist[i][j]+1;
         vis[i][j+1]=1;
        q.push({i,j+1});
        
      }

      if(i>=0 && j-1>=0 && vis[i][j-1]==0 && a[i][j-1]=='.')
      {
        dist[i][j-1]=dist[i][j]+1;
         vis[i][j-1]=1;
        q.push({i,j-1});
        
      }

      if(i-1>=0 && j>=0 && vis[i-1][j]==0 && a[i-1][j]=='.')
      {
        dist[i-1][j]=dist[i][j]+1;
         vis[i-1][j]=1;
        q.push({i-1,j});
       
      }

    }
      
}



int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
 // freopen("input.txt","r",stdin);
#endif

  cin>>n>>m;
  vector<vector<char> > a(n,vector<char>(m));
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      cin>>a[i][j];
    }
  }


  int optimal=0;

        dist.resize(n,vector<int>(m,0));

        vis.resize(n,vector<int>(m,0));

  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      if(a[i][j]=='.')
      {
               
        for(int k=0;k<n;k++)
        {
          for(int l=0;l<m;l++)
          {
            dist[k][l]=0;
            vis[k][l]=0;
          }
        }
        

        bfs(a,i,j);


     

        for(int k=0;k<n;k++)
        {
          for(int l=0;l<m;l++)
          {
            
            optimal=max(optimal,dist[k][l]);

          }
        }

    


      }
    }
  }


  cout<<optimal<<endl;


  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<bool> vec(n, false);
  map<int, int> mp;
  for(int i=0; i<m; i++){
    int question;
    string res;
    cin >> question >> res;
    question = question - 1;
    if(vec[question]) continue;
    else{
      if(res == "AC"){
        vec[question] = true;
      }else{
        mp[question]++;
      }
    }
  }
  int ac = 0;
  for(int i=0; i<n; i++){
    if(vec[i]) ac++;
  }
  int wa = 0;
  for(int i=0; i<n; i++){
    if(vec[i]) wa += mp[i];
  }
  cout << ac << " " << wa << endl;
  return 0;
}
      
      

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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 n, a, mini = 1e16;
    cin >> n;
    rep1(i, 5){
        cin >> a;
        mini = min(a, mini);
    }
    ll ans;
    if (n%mini==0) ans = n/mini + 4;
    else ans = n/mini + 5;

    cout << ans << endl;
    //printf("%.12f", ans);
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int x, y, z; cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y << endl;
    return 0;
}


Measured memory_bytes: 896
# なぜかうまくいかない
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_right, bisect_left

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
s = input()

print(s[0:4] + " " + s[4:])

Measured memory_bytes: 5188
X,Y = map(int,input().split())

price = [3*10**5, 2*10**5, 1*10**5]

ans = 0
if X == 1 and Y == 1:
    ans += 4*10**5

X -= 1
Y -= 1

if X < 3:
    ans += price[X]
if Y < 3:
    ans += price[Y]

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, w[5010];
long long D[5010], A, B, S[5010];
int main() {
	int i, j;
	scanf("%d%lld%lld", &n, &A, &B);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		D[i] = 1e18;
	}
	n++;
	w[n] = n;
	D[n] = 1e18;
	for (i = 1; i <= n; i++) {
		D[i] = min(D[i], A * (i - 1));
		long long s = 0;
		for (j = i + 1; j <= n; j++) {
			if (w[j] > w[i]) {
				D[j] = min(D[j], D[i] + s);
			}
			if (w[i] < w[j]) {
				s += A;
			}
			else {
				s += B;
			}
		}
	}
	printf("%lld\n", D[n]);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int MAXN=250005,MOD1=1000000007,MOD2=1000000009,BASE=10007,INV1=820925358,INV2=74148097;

int PowMod(int a,int b,int P)
{
	int ret=1;
	while(b)
	{
		if(b&1)
			ret=(1LL*ret*a)%P;
		b>>=1;
		a=(1LL*a*a)%P;
	}
	return ret;
}

struct Hash
{
	int a,b;
	Hash(){}
	Hash(int a,int b):a(a),b(b){}
	Hash operator + (Hash y)
	{return Hash((a+y.a)%MOD1,(b+y.b)%MOD2);}
	Hash operator - (Hash y)
	{return Hash((a-y.a+MOD1)%MOD1,(b-y.b+MOD2)%MOD2);}
	Hash operator * (Hash y)
	{return Hash((1LL*a*y.a)%MOD1,(1LL*b*y.b)%MOD2);}
	bool operator < (Hash y)const
	{return a<y.a||(a==y.a&&b<y.b);}
};

int N;
char S[MAXN];
Hash P[MAXN],op[MAXN];

map<Hash,int> cnt;

int main()
{
	//printf("%d\n",PowMod(BASE,MOD1-2,MOD1));
	//printf("%d\n",PowMod(BASE,MOD2-2,MOD2));
	scanf("%d%s",&N,S+1);
	P[0]=Hash(1,1);
	for(int i=1;i<=N;i++)
	{
		P[i]=P[i-1];op[i]=op[i-1];
		if(S[i]=='<')
			P[i]=P[i]*Hash(INV1,INV2);
		if(S[i]=='>')
			P[i]=P[i]*Hash(BASE,BASE);
		if(S[i]=='+')
			op[i]=op[i]+P[i];
		if(S[i]=='-')
			op[i]=op[i]-P[i];
	}
	
	long long ans=0;
	for(int i=N;i>=1;i--)
	{
		cnt[op[i]]++;
		ans+=cnt[op[N]*P[i-1]+op[i-1]];
	}
	
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include<bits/stdc++.h>
#include<utility>
#include<vector>
#define ll long long 
#define fast    ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main(void) {
	ll t=0,n;
	cin>>n;
	cout<<(n/500)*1000+((n%500)/5)*5;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 int mod = 1000000007;
struct mint{
	ll x;
	mint(ll 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;
		if(t&1) a *= *this;
		return a;
	}
	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;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	mint sum = 0, ans = 0;
	rep(i,n){
		ll a;
		cin >> a;
		ans += (mint)a * sum;
		sum += a;
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include <cmath>
#include <string>
#include <float.h>
using namespace std;

int main()
{

	string a;
	cin>>a;
	int w;
	cin>>w;
	string o;
	for(int i=0;(i*w)<int(a.length());i++){
		o=o+a[i*w];
	}
	cout<<o;


}

Measured memory_bytes: 256