akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

/*---------------------------------------------------*/

int prime[150000];
bool is_prime[150000];
vector<ll> v;

void sieve(){
  int p=0;
  rep(i,150000)is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  REP(i,2,150000){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j=2*i;j<150000;j+=i)is_prime[j]=false;
    }
  }
  //rep(i,50)cout<<"DEBUG "<<prime[i]<<endl;
}

void solve(int n,int p){
  v.clear();
  int x=0;
  while(prime[x]<=n){
    //cout<<x<<" "<<prime[x]<<endl;
    x++;
  }
  
  REP(i,x,x+p){
    REP(j,i,x+p){
      v.push_back(prime[i]+prime[j]);
    }
  }
  sort(all(v));
  //rep(i,p)cout<<i+1<<" "<<v[i]<<endl;
  cout<<v[p-1]<<endl;
}

int main(){
  int n,p;
  sieve();
  while(cin>>n>>p){
    if(n==-1&&p==-1)break;
    solve(n,p);
  }
  return 0;
}

Measured memory_bytes: 3400
#ABC52
n = int(input())
s = list(input())

a ,ans_a=0,0

for i in range(n):
  if s[i] =='I':
    a +=1
    if ans_a <a:
      ans_a = a
  elif s[i] =='D':
      a -=1
print(ans_a)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

using namespace std;

long long int MOD = 1000000007;

long long int dp[105][100005], sum[105][100005];

int N, K;
int a[100005];

int main(void) {

	cin >> N >> K;

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

	dp[0][K] = 1;

	for (int i = 1; i <= N; i++) {

		sum[i - 1][0] = dp[i - 1][0];
		for (int j = 1; j <= K; j++) { sum[i - 1][j] = (sum[i - 1][j - 1] + dp[i - 1][j])%MOD; }

		dp[i][0] = sum[i - 1][min(K, 0 + a[i])];
		for (int k = 1; k <= K; k++) {
			dp[i][k] = (sum[i - 1][min(K, k + a[i])] - sum[i - 1][k - 1] + MOD) % MOD;
		}
		
	}

	cout << dp[N][0] << endl;

	return 0;
}

Measured memory_bytes: 159616
#include <bits/stdc++.h>
using namespace std ;
 
int main(){
    int64_t A,B;cin>>A>>B;
    int64_t C,D;cin>>C>>D;
    
    int64_t count1 = B/C + B/D - B/lcm(C,D);
    int64_t count2 = (A-1)/C + (A-1)/D - (A-1)/lcm(C,D);
 
    cout << B-count1-A+1+count2 << endl;
    
}

Measured memory_bytes: 3632
N, M = map(int, input().split())
drink, sumA, sumB = [], 0, 0
for _ in range(N):
    A,B = map(int, input().split())
    drink.append([A, B])
    sumA += A*B
    sumB += B 

if M == sumB:
    print(sumA)
elif M > sumB // 2:
    drink.sort(reverse=True)
    ans, exM = sumA, sumB - M
    while exM > 0:
        AB = drink.pop(0)
        b = min(exM, AB[1])
        ans -= b * AB[0]
        exM -= b
    print(ans)
else:
    drink.sort()
    ans = 0
    while M > 0:
        AB = drink.pop(0)
        b = min(M, AB[1])
        ans += b * AB[0]
        M -= b
    print(ans)

Measured memory_bytes: 20092
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int H,W;
    int i,j;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(i=0;i<H;i++){
            if(i!=0){
                printf("\n");
            }
            for(j=0;j<W;j++){
                printf("#");
            }
        }printf("\n");
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 572
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
    IOS;

    

    clock_t startTime=clock();

    ll k;
    cin>>k;
    ll sum=0;
    rep(i,1,k+1)
    {
        rep(j,1,k+1)
        {
            rep(m,1,k+1)
            {
                sum+=__gcd(i,__gcd(j,m));
            }
        }
    }
    cout<<sum;

    cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 3772
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
	int N;
	cin >> N;
	int ans = 0;
	for(int i=0;i<N;i++){
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n,x;
	cin >> n >> x;
	long long int aux;
	long long int mitad = n/2;	
	long long int mcd;	
	
	mcd = __gcd(n, x);
	
	if (n%2 == 0){
		if (x != mitad){
			aux=3*(n-mcd);
			cout << aux << endl;
		}
		else{
			aux=3*x;
			cout << aux << endl;			
		}
	}
	else{
		aux=3*(n-mcd);
		cout << aux << endl;		
	}
	
	return 0;
}

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

using namespace std;

const int MAX_N = 100000, INDEX = 1;

int n, a[MAX_N + INDEX];

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

    cin >> n;

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

    int aMin = *min_element(a + INDEX, a + INDEX + n, less<int>()), aMax = *max_element(a + INDEX, a + INDEX + n, less<int>());

    if (aMax - aMin > 1) {
        cout << "No" << endl;

        return 0;
    }

    if (aMax - aMin == 1) {
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i] == aMax) {
                cnt++;
            }
        }

        if (n - cnt + 1 <= aMax && aMax <= n - cnt + cnt / 2) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }

        return 0;
    }

    if (aMin == aMax) {
        if (aMin == n - 1) {
            cout << "Yes" << endl;

            return 0;
        }

        if (aMax <= n / 2) {
            cout << "Yes" << endl;

            return 0;
        }

        cout << "No" << endl;

        return 0;
    }

    return 0;
}


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

char ch[2][20010];
int dp[2][20010];

int main() {
  int T; cin >> T;
  while(T--) {
    int N; cin >> N;
    
    
    for(int i = 0; i < 2 * N; i++) cin >> ch[0][i];
    for(int i = 0; i < 2 * N; i++) cin >> ch[1][i];    
    ch[0][2 * N] = ch[1][2 * N] = 'N';


    if( ch[1][0] == 'Y' ) {
      dp[0][0] = 3;
      dp[1][0] = 2;
    }
    else if( ch[0][0] == 'Y' ) {
      dp[0][0] = 1;
      dp[1][0] = 1;
    }
    else {
      dp[0][0] = 0;
      dp[1][0] = 1;
    }

    for(int i = 1; i <= N; i++) {
      int a = i * 2 - 1;
      int b = i * 2;
      int x = ch[0][a] == 'Y' || ch[0][b] == 'Y';
      int y = ch[1][a] == 'Y' || ch[1][b] == 'Y';

      if( x && y ) {
        dp[0][i] = min( dp[0][i - 1] + 4, dp[1][i - 1] + 3);
        dp[1][i] = min( dp[0][i - 1] + 3, dp[1][i - 1] + 3);
      } else if( x && !y ) {
        dp[0][i] = min( dp[0][i - 1] + 2, dp[1][i - 1] + 2);
        dp[1][i] = min( dp[0][i - 1] + 2, dp[1][i - 1] + 2);
      } else if( !x && y ) {
        dp[0][i] = min( dp[0][i - 1] + 4, dp[1][i - 1] + 3);
        dp[1][i] = min( dp[0][i - 1] + 3, dp[1][i - 1] + 2);
      } else if( !x && !y ) {
        dp[0][i] = min( dp[0][i - 1] + 1, dp[1][i - 1] + 1);
        dp[1][i] = min( dp[0][i - 1] + 1, dp[1][i - 1] + 1);
      }
    }
    
    int ans = min( dp[0][N], dp[1][N] + 1);
    cout << ans << endl;
  }
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int K = 60;

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) { cin >> A.at(i); }

  vector<vector<char>> mat(K, vector<char>(N));
  vector<char> vecOdd(K);
  for (int j = 0; j < K; j++) {
    char x = 0;
    for (int i = 0; i < N; i++) {
      char b = (A.at(i) >> j) & 1;
      mat.at(j).at(i) = b;
      x ^= b;
    }
    if (x) {
      vecOdd.at(j) = 1;
      for (int i = 0; i < N; i++) mat.at(j).at(i) = 0;
    }
  }
  int idp = 0;
  for (int j = K-1; j >= 0 && idp < N; j--) {
    if (vecOdd.at(j)) continue;
    int i0;
    for (i0 = idp ; i0 < N && mat.at(j).at(i0) == 0; i0++);
    if (i0 == N) continue;
    if (i0 > idp) {
      for (int jj = j; jj >= 0; jj--) {
	swap(mat.at(jj).at(i0), mat.at(jj).at(idp));
      }
    }
    for (int i = 0; i < N; i++) {
      if (i == idp) continue;
      if (mat.at(j).at(i) == 0) continue;
      for (int jj = j; jj >= 0; jj--) mat.at(jj).at(i) ^= mat.at(jj).at(idp);
    }
    idp++;
  }
  ll ans = 0;
  for (int i = 0; i < idp; i++) {
    ll x = 0;
    for (int j = K-1; j >= 0; j--) {
      if (mat.at(j).at(i)) x += (1LL << j);
    }
    ans ^= x;
  }
  ll xo = 0;
  for (int j = K-1; j >= 0; j--) {
    if (vecOdd.at(j)) xo += (1LL << j);
  }
  cout << 2 * ans + xo << endl;

  return 0;
}



Measured memory_bytes: 7040
N = int(input())
L = input().split()
a = [ int(x) for x in L ]
a.sort(reverse=True)

Alice = 0
Bob = 0

for i in range(0,len(a)):
    if i % 2 == 0:
        Alice = Alice + a[i]
    else:
        Bob = Bob + a[i]
print(Alice - Bob)

Measured memory_bytes: 3060
<?php
  declare(strict_types=1);

  fscanf(STDIN, "%i %i", $n, $m);

  if ($m < ($n * 2))
  {
      $scc = (int)($m / 2);
  }
  else
  {
      $scc = $n;
      $scc += (int)(($m - $n * 2) / 4);
  }
  
  echo $scc,PHP_EOL;


Measured memory_bytes: 4856
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>

using namespace std;

#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque



#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>

#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>

#define vi vector<ll>
#define vs vector<string>

#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator


#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second
#define pi 2*acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT_ count()
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT_ getline
#define NL_   "\n"

#define for(i, n) for(i = 0; i < n; i++)
#define fe(i, n) for(i = 1; i <= n; i++)

#define ul unsigned long long int
#define ll long long int
#define  MAX 250000

ll N, T, tC = 0, i, j, k;







int main()
{
    FAST;

    cin >> N;
    double m;
    cin >> m;
    double arr[N+1];
    double sum = 0;
    for(i,N) {cin >> arr[i];sum += arr[i];}

    sum = (sum)/(4.00*m);
    double t = 0;
    for(i, N)
    {
        if(arr[i]>= sum) t++;
    }
    if(t>=m) cout <<"Yes";
    else cout <<"No";


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#define M 20000
using namespace std;
string s;
int x, y, z, c;
bitset<M*2> bs[2];
int main() {
	cin>>s>>x>>y;
	s += "T";
	c = s.find("T");
	s = string(s.begin()+c, s.end());
	x -= c;
	bs[0][M] = bs[1][M] = 1;
	for(int i=c=0; s[i]; i++) {
		if(s[i]=='F') c++;
		else {
			bs[z] = (bs[z]<<c) | (bs[z]>>c);
			z = !z;
			c = 0;
		}
	}
	cout<<((bs[0][x+M] && bs[1][y+M]) ? "Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <time.h>
#include<string>
using namespace std;
int main(){
	int sumperson=0,n,out=0,score=0;
	string str;
	cin>>n;
	for(int i=0;i<n;i++){
		while(1){
			cin>>str;
			if(str=="OUT"){
				out++;
				if(out==3){
					break;
				}
			}
			else if(str=="HIT"){
				sumperson++;
				if(sumperson==4){
					sumperson=3;
					score++;
				}
			}
			else if(str=="HOMERUN"){
				score+=sumperson+1;
				sumperson=0;	
			}
		}
		cout<<score<<endl;
		sumperson=0;
		out=0;
		score=0;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
    int b = A * N;
  if (b >= B) {
    cout << B << endl;
  }
  if (B > b) {
    cout << b << endl;
  }
}

Measured memory_bytes: 256
#import time
#t = time.time()
inf = float('inf')

n, m, r = map(int, input().split())
rs = [r-1 for r in list(map(int, input().split()))]


ds = [[inf] * n for _ in range(n)]
for i in range(n):
  ds[i][i] = 0

for mm in range(m):
  a, b, c = map(int, input().split())
  a, b = a-1, b-1
  ds[a][b] = c
  ds[b][a] = c

## warshall floyd
for k in range(n):
  for i in range(n):
    for j in range(n):
      ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j])

#print(f'wf finished {time.time() - t}')
#t = time.time()

#def dfs(dist, before, remain, ds):
#  print(f'dfs({dist}, {before}, {remain})')
#  if remain == []:
#    return dist
#  dd = []
#  for r in remain:
#    if before is not None:
#      dist += ds[before][r]
#    dd.append(dfs(dist, r, list(set(remain) - set([r])), ds))
#  return min(dd)    
#
#print(dfs(0, None, rs, ds))


import itertools
dds = []
for i in itertools.permutations(rs, len(rs)):
  d = 0
  for j in range(len(rs)-1):
    dd = ds[i[j]][i[j+1]]
    d += dd
    #print(f'added {dd}')
  dds.append(d)
print(min(dds))

#print(f'search finished {time.time() - t}')
#t = time.time()


Measured memory_bytes: 73816
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  long long int c = 0, i;
  cin>>s>>t;
  for (i = 0; i < s.size(); i++)
    if (s[i] != t[i])
      c++;
  cout<<c;
  return 0;
}

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

int main(){
	int n, k, b, T = 0;
	
	cin>>n>>k;
	
	for(int i = 0; i < (1<<n); i++){
		int count = 0;
		for(int t = i; t; t &= t-1) count++;
		if(count != k)continue;
		
		cout<<i<<":";
		for(int j = 0, k = i; k; j++){
			if(k&(1<<j)){
				cout<<" "<<j;
				k &= ~(1<<j);
			}
		}
		cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3088
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
    }
    println!("{}", 180 * (n-2));
}


Measured memory_bytes: 4352
N = int(input())
T,A = map(int,input().split())
H = list(input().split())
T_best = 2000

for i in range(N):
    dt = abs(T - int(H[i])*0.006 - A)
    T_best = min(dt,T_best)
    if dt == T_best:
        i_best = i


print(i_best+1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

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

	// 整数列Aの入力
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];

		// あらかじめ i を引いておく
		A[i] -= (i + 1);
	}

	// ソートしてAの中央値を求める
	sort(A.begin(), A.end());
	int m = A[N / 2];

	// 答えを求める
	long long ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += abs(A[i] - m);
	}

	// 答えを出力
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
num_list = list(map(int, input().split(' ')))
N = num_list[0]
Y = num_list[1]
total = 0
ans = '-1 -1 -1'
for n in range(N+1):
  rest = N - n
  a = n*10000
  if rest == 0:
    if a == Y:
      ans = str(int(a/10000)) + ' 0 0'
      break
  for i in range(rest+1):
    rest_2 = rest - i
    b = i*5000
    c = rest_2*1000
    if rest == 0:
      if a+b == Y:
        ans = str(int(a/10000)) + ' ' + str(int(b/5000)) + ' 0'
        break
    elif a+b+c == Y:
      ans = str(int(a/10000)) + ' ' + str(int(b/5000)) + ' ' + str(int(c/1000))
print(ans)

Measured memory_bytes: 9136
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] h = new int[N];
            for (int i = 0; i < N; i++) {
                h[i] = in.nextInt();
            }

            int count = 0;
            for (int l = 0; l < N; l++) {
                while (h[l] > 0) {
                    int r;
                    for (r = l; r < N; r++) {
                        if (h[r] == 0) {
                            break;
                        }
                    }
                    for (int i = l; i < r; i++) {
                        h[i]--;
                    }
                    count++;
                }
            }
            out.println(count);
        }

    }
}



Measured memory_bytes: 23764
/*
    Washief Hossain Mugdho
    20 September 2020
    Educational DP Flowers
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
#define N 200005
using namespace std;
int n, h[N], a[N];

ull t[2 * N];

void modify(int p, ull value)
{
    for (t[p += n] = value; p > 1; p >>= 1)
        t[p >> 1] = max(t[p], t[p ^ 1]);
}

ull query(int l, int r)
{
    ull res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1)
            res = max(res, t[l++]);
        if (r & 1)
            res = max(res, t[--r]);
    }
    return res;
}

int main()
{
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 0; i < n; i++)
    {
        ull prev = query(1, h[i]);
        ull cur = query(h[i], h[i] + 1);
        if (cur < prev + a[i])
            modify(h[i], prev + a[i]);
    }
    cout << query(0, N + 1) << endl;
}


Measured memory_bytes: 8276
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Main {
	Scanner in = new Scanner(System.in);
	
	int n, m;
	
	int[][] edge;
	double[][][] minCost;
	int[][] maxSpeed;	
	
	double INF = 100000000;
	
	class State implements Comparable<State> {
		int n, speed, prev;

		State(int n, int speed, int prev) {
			this.n = n;
			this.speed = speed;
			this.prev = prev;
		}
		
		@Override
		public int compareTo(State arg0) {
			double c1 = minCost[n][prev][speed], c2 = minCost[arg0.n][arg0.prev][arg0.speed];
			if (c1 > c2) return 1;
			else if (c1 < c2) return -1;
			else return 0;
		}
	}
	
	void dijkstra(int start) {
		minCost = new double[n][n][31];
		for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)
			Arrays.fill(minCost[i][j], INF);
		
		minCost[start][start][0] = 0;
		PriorityQueue<State> pq = new PriorityQueue<State>();
		pq.add(new State(start, 0, start));
		
		while (!pq.isEmpty()) {
			State s = pq.poll();
			for (int i = 0; i < n; i++) {
				if (edge[s.n][i] == INF) continue;
				if (s.prev == i) continue;
				int c = s.speed;
				for (int v = -1; v <= 1; v++) {
					if (c+v > 0 && c+v <= maxSpeed[i][s.n] && minCost[i][s.n][c+v] > minCost[s.n][s.prev][c] + (double)edge[i][s.n] / (c+v)) {
						minCost[i][s.n][c+v] = minCost[s.n][s.prev][c] + (double)edge[i][s.n] / (c+v);
						pq.add(new State(i, c+v, s.n));
					}
				}
			}
		}
		
		
	}
	
	void run() {
		while (true) {
			n = in.nextInt(); m = in.nextInt();
			if (n == 0) break;
			
			int s = in.nextInt() - 1, g = in.nextInt() - 1;

			maxSpeed = new int[n][n];
			edge = new int[n][n];
			
			for (int i = 0; i < m; i++) {
				int x = in.nextInt() - 1, y = in.nextInt() - 1, d = in.nextInt(), c = in.nextInt();
				edge[x][y] = edge[y][x] = d;
				maxSpeed[x][y] = maxSpeed[y][x] = c;
			}
			
			dijkstra(s);
			
			double res = INF;
			for (int i = 0; i < n; i++)
				res = Math.min(minCost[g][i][1], res);
			
			/*
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < 5; j++)
					System.out.print(minCost[i][j] + " ");
				System.out.println();
			}
			*/
			
			System.out.println(res == INF ? "unreachable" : res);
		}
	}
	
	public static void main(String args[]) {
		new Main().run();
	}
}

Measured memory_bytes: 44736
package main

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

// fmt.Scan is high cost
func main() {
	var sc = bufio.NewScanner(os.Stdin)
	buf := make([]byte, 1024)
	sc.Buffer(buf, 200202)
	var s string
	sc.Scan()
	s = sc.Text()
	a, z := -1, -1
	for i := 0; i < len(s); i++ {
		if a == -1 && s[i] == 'A' {
			a = i
		}
		if s[i] == 'Z' {
			z = i
		}
	}
	fmt.Println(z - a + 1)
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    ll n2 = n;
    vector<ll> ans;
    if(n == 3)ans = {2,5,63};
    if(n == 4)ans = {2,5,20,63};
    if(n > 4) {
        ans.emplace_back(2);
        ans.emplace_back(4);
        ans.emplace_back(6);
        n -= 3;
        ll tmp = 3;
        while((tmp + 6) <= 30000 && 1 < n){
            ans.emplace_back(tmp);
            ans.emplace_back(tmp + 6);
            n -= 2;
            tmp += 12;
        }
        tmp = 8;
        while(tmp+4 <= 30000 && n > 2){
            ans.emplace_back(tmp);
            ans.emplace_back(tmp+2);
            ans.emplace_back(tmp+4);
            tmp += 6;
            n -= 3;
        }
        
        if(n == 2){
            ans.emplace_back(tmp);
            ans.emplace_back(tmp + 2);
        }
        if(n == 1){
            ans.emplace_back(tmp + 4);
        }
    }
    debug(ans.size());
    assert(ans.size() == n2);
    for(auto i : ans)cout << i << " ";
    cout << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main(){
    fast();
 
/* you get what you work for not what you wish for */
    
    inp(n);
    n = n%26;
    string s;
    cin >> s;
    for(auto i:s){
        ll x = i+n;
        x-='A';
        x%=26;
        char z = x+'A';
        cout << z;
    }
}

Measured memory_bytes: 256
#include <iostream>
#define SQ(X) ((X)*(X))

using namespace std;

int isSquare(int n){
  for (int i=1; i*i<=n; i++){
    if (i*i==n) return 1;
  }
  return 0;
}

int main(void){
  int n,dim,ans;
  int x[20][20];

  cin >> n >> dim;
  for (int i=0; i<n; i++){
    for (int j=0; j<dim; j++) cin >> x[i][j];
  }
  ans = 0;
  for (int i=0; i<n; i++){
    for (int j=i+1; j<n; j++){
      int dist2 = 0;
      for (int k=0; k<dim; k++){
        dist2 += SQ(x[i][k]-x[j][k]);
      }
      ans += isSquare(dist2);
    }
  }
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int n = s.size();
    int sum = 0;
    rep(i,n) if (s[i] == 'o') sum++;
    sum += 15 - n;
    if (sum >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void) {
	int answer[4], correct[4], i, j;
	int hit, blow;
		
	while( scanf("%d",&correct[0]) != EOF ) {
		for( i = 1; i < 4; i++ ) {
			scanf("%d",&correct[i]);
		}
		for( i = 0; i < 4; i++ ) {
			scanf("%d",&answer[i]);
		}
		
//??????????¢????
		hit = 0;
		for( i = 0; i < 4; i++ ) {
			if( correct[i] == answer[i] ) {
				hit++;
			}
		}
//??????????¢????
		blow = 0;
		for( i = 0; i < 4; i++ ) {
			for( j = 0; j < 4; j++ ) {
				if(correct[i] == answer[j]) {
					blow++;
				}
			}
		}
		blow -= hit;
		
//????§????
		printf("%d %d\n",hit ,blow);
	}
	return(0);
}

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

int main() {
  long long N;
  cin >> N;
  
  long long ans=0;
  // A = x_y, B = y_x
  for(int i=0;pow(10,i)<=N;i++){
    for(int j=0;pow(10,j)<=N;j++){
      for(int x=1;x<10;x++){
        for(int y=1;y<10;y++){
          if(i*j==0 && x!=y) continue;
          long long a=0,b=0;
          if(i==0){
            if(x<=N) a=1;
          }
          else if(i==1){
            if(10*x+y<=N) a=1;
          }
          else{
            a = min(pow(10,i-1),(N-(pow(10,i)*x+y))/10+1);
            if(a<0) a=0;
          }
          if(j==0){
            if(y<=N) b=1;
          }
          else if(j==1){
            if(10*y+x<=N) b=1;
          }
          else{
            b = min(pow(10,j-1),(N-(pow(10,j)*y+x))/10+1);
            if(b<0) b=0;
          }
          ans += a*b;
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	
	ll X, Y;
	cin >> X >> Y;

	int kotae = 0;
	while (X <= Y) {
		kotae++;
		Y /= 2;
	}
	co(kotae);

	Would you please return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define SET(arr) memset(arr, -1, sizeof(arr))
#define CLR(arr) memset(arr, 0, sizeof(arr))

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

#define $ vector< int > :: iterator
#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(int i=0; i<(n); i++)
#define forn(i, n) for (int i = 1; i <=(int)(n); ++i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forba(i, b, a) for (int i = (int)(b); i >= (int)(a); --i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<
#define CS(i) cout<<"Case "<<(int)(i)<<": "

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);
const ld E=2.71828182845904523536;

int main() {
Boost;
//READ("in.txt");
//WRITE("out.txt");
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;

return 0;
}


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    double arr[n];
    double ans = 0.0;   
    for (int i=0;i<n;i++){
        cin >> arr[i];
    }

    // for (int i=0;i<n;i++){
    //     cout << arr[i];
    // }



    double dp[n+1][n+1];
    memset(dp, 0.0, sizeof(dp));

    dp[0][0] = 1.0;

    for (int i=1;i<=n;i++){
        for (int j=0;j<=n;j++){
            if (j == 0){
                dp[i][j] = dp[i-1][j]*(1-arr[i-1]);
                // cout <<"check = "<< dp[i-1][j] << endl;
            }else{
                dp[i][j] = dp[i-1][j-1]*arr[i-1] + dp[i-1][j]*(1-arr[i-1]);
            }
        }
    }

    for (int i=(n+1)/2;i<=n;i++){
        ans = ans + dp[n][i];
    }

    cout << fixed << setprecision(10) << ans << "\n";
    // cout << ans << "\n";

    // for (int i = 0; i <=n; i++)
    // {
    //     for (int j = 0; j <= n; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }

    return 0;
}

Measured memory_bytes: 70528
#include <stdio.h>

int main(void){
  int x,a,b;
  int ax,bx;
  int i,j;
  //read input
  scanf("%d %d %d",&x,&a,&b);
  if((a-x)<0)
    ax=-(a-x);
  else if((a-x)>0)
    ax=a-x;
  if((b-x)<0)
    bx=-(b-x);
  else
    bx=b-x;
  if(ax>bx){
    printf("B\n");
    return 0;
  }else{
    printf("A\n");
    return 0;
  }
    
  
  return 0;
}


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

int main() {
	int n; //いくつの文字を変換するか
	int m; //変換するデータ数
	char *before;
	char *after;
	char *output;
	char *all[20000];//最後の出力
	int index = 0;
	while (true) {
		cin >> n;//n個変換
		if(n==0)break;
		before = new char[n];
		after = new char[n];
		for (int i = 0; i < n; i++) {
			cin >> before[i] >> after[i]; //入力
		}
		cin >> m;
		output = new char[m+1];
		for(int i=0; i<m; i++){
			cin >> output[i];
		}
		for(int i=0; i<m; i++){
			for(int j=0; j<n; j++){
				if(output[i]==before[j]){
					//変換する
					output[i]=after[j];
					break;
				}
			}
		}
		output[m]='\0';
		all[index]=output;
		index++;
		delete[] before;
		delete[] after;
	}
	for(int i=0; i<index; i++){
		cout<<all[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1272
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
#include <functional>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back


int main()
{
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	int ans = d[n / 2] - d[n / 2 - 1];
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
const int coin[6] = {1,5,10,50,100,500};
const int sen = 1000;
int main(){
  int n;
  while(cin >> n, n != 0){

    int oturi = sen - n;
    int sum = 0;
    int cnt = 5;
    while(oturi != 0){
      if(oturi/coin[cnt] != 0){
	sum++;
	oturi -= coin[cnt];
      }
      else{
	cnt--;
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>

using namespace std;

void a_dont_be_late(void) {
	int d, t, s;
	cin >> d >> t >> s;

	double time = (d * 1.0) / s;


	if (time > t) cout << "No" << endl;
	else           cout << "Yes" << endl;
}

int main()
{
    a_dont_be_late();

    return 0;
}

Measured memory_bytes: 3632
# Problem https://atcoder.jp/contests/abc082/tasks/abc082_a
a,b = gets.chomp('\n').split(' ').map(&:to_i)
average = (a+b)/2
aveMod2 = (a+b)%2
if aveMod2 == 1
    answer = average+1
else
    answer = average
end
puts(answer)

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	
	private static final int MAX_N = 200002;
    static long dp[] = new long[MAX_N];
    static long bit[] = new long[MAX_N];

	public static void main(String[] args) {
		
		try {
		    
		      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		      String nLine = br.readLine();
		      String hLine = br.readLine();
		      String aLine = br.readLine();
		      int n = Integer.parseInt(nLine);
		      
		      String[] heights = hLine.split(" ");
		      String[] beautyLine = aLine.split(" ");
		      
		      for(int i = 1; i <= n ; i++) {
		    	  int ht = Integer.parseInt(heights[i-1]);
		    	  dp[i] = query(ht-1) + Integer.parseInt(beautyLine[i-1]);
		    	  update(ht, dp[i], n);
		      }
		      
		      long maxBeautySum = 0;
		      
		      for(int i = 1; i <= n ; i++) {
		    	  maxBeautySum = Math.max(maxBeautySum, dp[i]);
		      }

		      System.out.println(maxBeautySum);
		      
		    } catch(Exception ex) {
		    	System.out.println("Error is " + ex);
		    }

	}
	
	private static long query(int ht) {
		long answer = 0;
		while(ht > 0) {
			answer = Math.max(answer, bit[ht]);
			ht -= (ht&(-ht));
		}
		return answer;
	}
	
	private static void update(int ht, long val, int n) {
		while(ht <= n) {
			bit[ht] = Math.max(val, bit[ht]);
			ht += (ht&(-ht));
		}
	}
}

Measured memory_bytes: 88112
N = int(input())
A = [int(a) for a in input().split()]
p = 10 ** 9 + 7

S = [A[0]] * N
for i in range(1, N):
  S[i] = S[i - 1] + A[i]

sum = 0
for i in range(0, N - 1):
	sum += (A[i] * (S[N - 1] - S[i])) % p
print(sum % p)

Measured memory_bytes: 31364
n,k=map(int,input().split())
d=str(input().split())
result=n
#print(len(str(n)))
count=0
while True:
  for j in range(len(str(result))):
    if str(result)[j] in d:
      count=0
      result+=1
      #print(count,result)
      break
    else:
      count+=1
  if count==len(str(result)):
    break
print(result)   

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

int a[22][22];
int w, h;
int dir_x[] = {0, 1, 0, -1};
int dir_y[] = {-1, 0, 1, 0};

int solve(int x, int y, int level)
{
    int i, temp;
    int ret = 11;
    for(i = 0; i < 4; i++){
        int temp_x = x, temp_y = y;
        while((a[temp_y][temp_x] == 0 || a[temp_y][temp_x] == 2) && !(a[temp_y][temp_x] == 3)){
            temp_x += dir_x[i];
            temp_y += dir_y[i];
        }
        if(a[temp_y][temp_x] == 3){
            return 1;
        }
        if(temp_x == 0 || temp_y == 0 || temp_x == w + 1 || temp_y == h + 1)
            continue;
        if(level == 1)
            continue;
        if(temp_x - dir_x[i] == x && temp_y - dir_y[i] == y)
            continue;
        a[temp_y][temp_x] = 0;
        temp_x -= dir_x[i];
        temp_y -= dir_y[i];
        temp = solve(temp_x, temp_y, level - 1);
        a[temp_y + dir_y[i]][temp_x + dir_x[i]] = 1;
        if(temp + 1 < ret)
            ret = temp + 1;
    }

    return ret;
}

int main(void)
{
    while(1){
        scanf("%d %d", &w, &h);
        if(w == 0 && h == 0)
            break;

        int i, j;
        int x, y;
        for(i = 1; i <= h; i++)
            for(j = 1; j <= w; j++){
                scanf("%d", &(a[i][j]));
                if(a[i][j] == 2){
                    x = j;
                    y = i;
                }
            }


        for(i = 0; i <= h + 1; i++)
            a[i][0] = a[i][w + 1] = 1;

        for(i = 0; i <= w + 1; i++)
            a[0][i] = a[h + 1][i] = 1;

        int res = solve(x, y, 10);
        if(res == 11)
            printf("-1\n");
        else
            printf("%d\n", res);
    }

    return 0;
}

Measured memory_bytes: 612
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;

	int pay = 0;

	for (int i = 0; i < 10; i++) {
		if (N - 1000 * (i + 1) <= 0) {
			pay = 1000 * (i + 1);
			break;
		}
	}

	cout << pay - N << endl;
}

Measured memory_bytes: 3604
#include"bits/stdc++.h"
#include"math.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
  int x,y;cin >> x >> y;
  int ans=0;
  
  if(x==1)ans+=300000;
  if(x==2)ans+=200000;
  if(x==3)ans+=100000;
  if(y==1)ans+=300000;
  if(y==2)ans+=200000;
  if(y==3)ans+=100000;
  if(x==1&&y==1)ans+=400000;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <climits>
#include <iostream>
#include <vector>

class Matrix {
  public:
    long long x;
    long long y;
    long long cost;
};

int main()
{
  int n;
  std::cin >> n;
  std::vector<Matrix> matrix(n);
  for (int i = 0; i < (int)matrix.size(); i++) {
    std::cin >> matrix.at(i).x >> matrix.at(i).y;
  }
  std::vector<std::vector<Matrix>> memo(n+1, std::vector<Matrix>(n));
  for (int i = 0; i < (int)matrix.size(); i++) {
    memo.at(1).at(i).x = matrix.at(i).x;
    memo.at(1).at(i).y = matrix.at(i).y;
  }
  for (int block = 2; block <= (int)matrix.size(); block++) {
    for (int i = 0; i + block <= (int)matrix.size(); i++) {
      long long result = LLONG_MAX;
      memo.at(block).at(i).x = matrix.at(i).x;
      memo.at(block).at(i).y = matrix.at(i+block-1).y;
      for (int part = i+1; part < i + block; part++) {
        long long tmp = 0;
        assert(memo.at(part-i).at(i).y == memo.at(block-part+i).at(part).x);
        tmp += memo.at(part-i).at(i).cost + memo.at(block-part+i).at(part).cost;
        tmp += memo.at(part-i).at(i).x * memo.at(part-i).at(i).y * memo.at(block-part+i).at(part).y;
        result = std::min(result, tmp);
      }
      memo.at(block).at(i).cost = result;
    }
  }
  if (matrix.size() == 1) {
    std::cout << "0" << std::endl;
  } else {
    std::cout << memo.at(matrix.size()).at(0).cost << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3256
test = ""
#test = \
"""
redcoder
"""
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
    
    
s = list(input2())
r = list(reversed(s))
c = 0
for i in range(len(s)):
    if s[i] != r[i]:
        c += 1

print(c//2)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main(){
  string nums,text,ch;
  ch = "abcdefghijklmnopqrstuvwxyz.?! ";
  while(cin>>nums){
    text = "";
    if(nums.size()%2){
      cout<<"NA"<<endl;
    }
    else{
      for(int i=0;i<nums.size()/2;i++){
    if('0'<nums[i*2]&&nums[i*2]<'7'&&'0'<nums[i*2+1]&&nums[i*2+1]<'6')
      text=text+ch[5*(nums[i*2]-49)+(nums[i*2+1]-49)];
    else{
      text="NA";
      break;
    }
      }
      cout<<text<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="SUN")
	cout<<7<<endl;
	else if(s=="MON")
	cout<<6<<endl;
	else if(s=="TUE")
	cout<<5<<endl;
	else if(s=="WED")
	cout<<4<<endl;
	else if(s=="THU")
	cout<<3<<endl;
	else if(s=="FRI")
	cout<<2<<endl;
	else
	{
	cout<<1<<endl;
	}
	return 0;
}


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

int main() {
	int x, y, z;
	string s;
	cin >> x >> y >> z;
	if (x+y == z||x+z == y||y+z==x)cout << "Yes" << endl;
	else cout << "No" << endl;	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;  cin>>n;
    if(n%7==0){cout<<"Yes"<<endl;return 0;}
    while(n>0){
        if(n%4==0){cout<<"Yes"<<endl;return 0;}
        n-=7;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define end "\n"
#define fi first
#define se second
#define db double
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) x & (-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = a; i <= (b); i++)
#define Rep(i, a, b) for(int i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const db eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int maxn = (int)3e2 + 5;
using namespace std;

int a[305];
ll dp[305][90005];

int main()
{
	int n; scanf("%d", &n);
	int sum = 0;
	rep(i, 1, n) scanf("%d", a + i), sum += a[i];
	dp[0][0] = 1;
	rep(i, 1, n){
		Rep(j, sum, 0){
			dp[i][j] = dp[i-1][j] * 2 % mod;
			if(j >= a[i]) dp[i][j] = (dp[i][j] + dp[i-1][j-a[i]]) % mod;
		}
	}
	ll ans = 3;
	rep(i, 1, n - 1) ans *= 3ll, ans %= mod;
	rep(i, (sum + 1) / 2, sum) { ans -= dp[n][i] * 3ll; while(ans < 0) ans += mod; }
	if(sum % 2 == 0){
		rep(i, 1, n){
			Rep(j, sum, 0){
				dp[i][j] = dp[i-1][j] % mod;
				if(j >= a[i]) dp[i][j] = (dp[i][j] + dp[i-1][j-a[i]]) % mod;
			}
		}
		ans += dp[n][sum/2] * 3;
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 212480
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    string s;
    cin >> s;

    li n = s.size();
    vector<vector<li>> dp(n + 1, vector<li>(5, 0));

    for (int pos = 1; pos <= s.size(); ++pos) {
        for (int len = 1; len < 5; ++len) {
            int prevpos = pos - len;
            if (prevpos < 0) {
                continue;
            } else if (prevpos == 0) {
                dp[pos][len] = max(dp[pos][len], 1LL);
            } else {
                for (int prevlen = 1; prevlen < 5; ++prevlen) {
                    int prevprevpos = prevpos - prevlen;
                    if (prevprevpos < 0) {
                        continue;
                    }
                    if (prevlen == len && s.substr(prevprevpos, prevlen) == s.substr(prevpos, len)) {
                        continue;
                    }
                    dp[pos][len] = max(dp[pos][len], dp[prevpos][prevlen] + 1);
                }
            }
        }
    }

    cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
    return 0;
}

Measured memory_bytes: 16532