akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    int ans=0;
    if(s[0]=='1'){
        ans++;
    }
    if(s[1]=='1'){
        ans++;
    }
    if(s[2]=='1'){
        ans++;
    }
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, n, m);
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
    return 0;
}

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

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

bool comp(const p_ll &x,const p_ll &y){
  if (x.second>y.second)return true;
  if (x.second<y.second)return false;
  if (x.first>y.first)return true;
  if (x.first<y.first)return false;
  return false;
}


ll N,M;
vp_ll A;
v_ll B;
int main(){
  cin >> N >> M;
  A.assign(N+10,pair<ll,ll>(0,0));
  for (ll i=1;i<=N;i++){
    ll x,y; cin >> x >> y;
    A[i] = pair<ll,ll>(x,y);
  }
  ll ans=0;
  priority_queue <ll> que;
  sort(A.begin()+1,A.begin()+N+1);
  ll idx=1;
  ll day = M-1;
  while (day>=0){
    while (idx <=N && A[idx].first+day<=M){
      que.push(A[idx].second);idx++;
    }
    if (!que.empty()){ans+=que.top();que.pop();show(ans,true);}
    day--;
  }
  cout << ans << endl;
}


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

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

    bool can = true;
    
   for (int i = 0; i < s.size(); i++) {
        if (s[i] == t[i]) ;
        else {
            can = false;

            //cout << "NOOOOOOOOO" << endl;
            break;
        }
    }

    if ((s.size() + 1== t.size()) && can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

const int MAXW = 310;
const int MAXH = 310;

char s[MAXW][MAXH];
int ans[MAXW][MAXH];
int h, w, k;

bool hasStrawbery(int y) {
  if (y >= h) {
    return true;
  }
  for (int x=0;x<w;x++) {
    if (s[x][y] == '#') {
      return true;
    }
  }
  return false;
}

void solve() {
  int cnt = 1;
  for (int i=0;i<h;i++) {
    if (hasStrawbery(i)) {
      bool found = false;
      for (int j=0;j<w;j++) {
        if (s[j][i] == '#') {
          if (found) {
            cnt++;
          } else {
            found = true;
          }
        }
        ans[j][i] = cnt;
      }
      cnt++;
    }
  }
  for (int i=1;i<h;i++) {
    for (int j=0;j<w;j++) {
      if (ans[j][i] == 0) {
        ans[j][i] = ans[j][i-1];
      }
    }
  }
  for (int i=h-1;i>=0;i--) {
    for (int j=0;j<w;j++) {
      if (ans[j][i] == 0) {
        ans[j][i] = ans[j][i+1];
      }
    }
  }
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      cout << (j == 0 ? "" : " ") << ans[j][i];
    }
    cout << endl;
  }
}

int main() {
  cin >> h >> w >> k;
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      cin >> s[j][i];
    }
  }
  solve();
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


ll dp[100010][3];

int main() {
    ll a[100010][3];
    int N; cin >> N;
    REP(i,N){
        REP(j,3){
            cin >> a[i][j];
        }
    }
    REP(i,N){
        REP(j,3){
            REP(k,3){
                if(j != k){
                    if(dp[i+1][k]<dp[i][j] + a[i][k]){
                        dp[i+1][k] = dp[i][j] + a[i][k];
                    }
                }  
            }
        }
    }
    ll res = 0;
    REP(i,3){
        if(res<dp[N][i]){
            res = dp[N][i];
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[5],i;

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

    sort(a, a+5, greater<int>());

    for(i=0;i<=4;i++)
    {
        cout<<a[i];
        if(i<4)
            cout<<" ";
    }
    cout<<endl;

    return 0;
}



Measured memory_bytes: 3144
N,K,Q=(int(x) for x in input().split())
A=[int(input()) for i in range(Q)]

point=[K-Q]*N

for i in range(Q):
    point[A[i]-1]+=1
for k in range(N):
    if point[k]>0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 10452
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int x;
  cin >> x;
  if(x==3||x==5||x==7){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


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

int Prime_counter(int n){
  
  int cnt=0;
  bool isPrime;
  
  if(n==1)return 1;
  
  REP(i,n+1,2*n+1){
    isPrime=true;
    REP(j,2,sqrt(i)+1){
      if(i%j==0){
	isPrime=false;
	break;
      }    
    }
    if(isPrime)cnt++;
  } 
  
  return cnt;
}
int main(){
  
  int n;
  
  while(1){
    cin >>n;
    if(n==0)break;
    cout <<Prime_counter(n)<<endl;
  }
  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), c(n-1);
  rep(i,n) {
    int x;  cin >> x;
    a[i]=x-1;
  }
  int ans=0;
  rep(i,n) {
    int b; cin >> b;
    ans+=b;
  }
  rep(i,n-1) cin >> c[i];
  rep(i,n-1) {
    if(a[i]+1==a[i+1]) ans+=c[a[i]];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
LL v[maxn];
int cnt, h[maxn];
struct edge
{
	int to, pre;
} e[maxn<<1];
void add(int from, int to)
{
	cnt++;
	e[cnt].pre = h[from];
	e[cnt].to = to;
	h[from] = cnt;
}
int deg[maxn], ok;
LL dfs(int x, int f)
{
	if(deg[x] == 1) return v[x];
	LL ret = v[x] + v[x];
	for(int i = h[x]; i; i = e[i].pre)
	{
		int to = e[i].to;
		if(to == f) continue;
		LL tmp = dfs(to, x);
		if(tmp > v[x]) ok = 0;
		if(tmp > ret) ok = 0;
		ret -= tmp;
	}
	if(ret > v[x]) ok = 0;
	return ret;
}
int N;
int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%lld", v + i);
	for(int i = 1; i < N; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		add(a, b);
		add(b, a);
		deg[a]++;
		deg[b]++;
	}
	if(N == 2)
	{
		if(v[1] == v[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	int rt = 0;
	for(int i = 1; i <= N; i++)
		if(deg[i] != 1)
		{
			rt = i;
			break;
		}
	ok = 1;
	if(dfs(rt, 0) != 0) ok = 0;
	puts(ok ? "YES":"NO");
	return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)
int main(){
    int n;
    cin >> n;
    string s;
    int k = n%10;
    if(k == 3){
        s = "bon";
    }else if(k == 0 || k == 1 || k == 6 || k == 8){
        s = "pon";
    }else{
        s = "hon";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3620
def f1(a):
    if a%10==0:
        return a
    else:
        return (a//10+1)*10

arr=[]
for _ in range(5):
    arr.append(int(input()))

brr = map(f1, arr)
crr = filter(lambda x: x!=0, map(lambda x: x%10,arr))
if len(crr)>0:
    print(sum(brr)-10+min(crr))
else:
    print(sum(brr))




Measured memory_bytes: 2568
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int n;
int a[20];
vector<vector<int>> f;
vector<vector<int>> p;
int INF = 1 << 30;

int ans;

void func(){
  int zeroCheck = 0;
  
  rep(i,10){
    zeroCheck += a[i];
  }
  if (zeroCheck == 0) return;
  
  int score = 0;
  
  rep(i,n){
    int count = 0;
    rep(j,10){
      if(a[j] == 1 && f[i][j] == 1){
        count++;
      }
    }
    score += p[i][count];
  }
  chmax(ans,score);
}

void dfs(int pos){
  //ベースケース
  if(pos == 10){
    func();
    return;
  }
  
  a[pos] = 0; dfs(pos+1);
  a[pos] = 1; dfs(pos+1);
}

int main(){
  cin >> n;
  
  f.resize(n,vector<int>(10,0));
  p.resize(n,vector<int>(11,0));
  
  rep(i,n){
    rep(j,10){
      cin >> f[i][j];
    }
  }
  rep(i,n){
    rep(j,11){
      cin >> p[i][j];
    }
  }
  ans = INF * -1;
  dfs(0);
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 384
package main

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

//scanで一行づつ読み込む
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)

//sort
// array := []int{5, 1, 4, 2, 3}
// sort.Sort(sort.IntSlice(array))

func main() {
	// a := make([]int, n)

	input := strings.Split(nextLine(), " ")
	n, _ := strconv.Atoi(input[0])
	a, _ := strconv.Atoi(input[1])
	b, _ := strconv.Atoi(input[2])

	ansA := 0
	ansB := 0

	ansA = min(a, b)
	ansB = com(n, a+b)

	fmt.Fprintln(wtr, ansA, ansB)
	_ = wtr.Flush()
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func com(a, b int) int {

	if a > b {
		return 0
	}
	return abs(a - b)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	string s[3];
	while(1){
		cin>>s[0];
		if(s[0]=="0") break;
		cin>>s[1]>>s[2];
		string ans="NA";
		rep(i,0,3){
			if(s[i][0]==s[i][1] && s[i][1]==s[i][2] && s[i][0]!='+') ans=s[i][0];
			if(s[0][i]==s[1][i] && s[1][i]==s[2][i] && s[0][i]!='+') ans=s[0][i];
		}
		if(s[0][0]==s[1][1] && s[1][1]==s[2][2] && s[0][0]!='+') ans=s[0][0];
		if(s[0][2]==s[1][1] && s[1][1]==s[2][0] && s[0][2]!='+') ans=s[0][2];
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1188
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

int main(void){
    int n, k;
    cin >> n >> k;
    vector<PL> p(n);
    int z = 0;
    REP(i,n){
        ll x;
        cin >> x;
        if (x == 0) z++;
        p[i] = PL(abs(x), x);
    }
    sort(ALL(p));
    reverse(ALL(p));
    int sgn = 1;
    ll ans = 1;
    REP(i,k){
        ll x = p[i].second;
        if (x == 0){
            cout << 0 << endl;
            return 0;
        }
        ans = (ans * abs(x)) % mod;
        if (x < 0) sgn *= -1;
    }
    if (sgn == 1){
        cout << ans << endl;
        return 0;
    }
    ll posm = mod, negm = mod;
    ll posn = mod, negn = mod;
    FORR(i,k-1,0){
        ll x = p[i].second;
        if (x > 0 && posm == mod) posm = x;
        if (x < 0 && negm == mod) negm = abs(x);
    }
    FOR(i,k,n-1){
        ll x = p[i].second;
        if (x > 0 && posn == mod) posn = x;
        if (x < 0 && negn == mod) negn = abs(x);
    }
    // cout << posm << " " << negm << endl;
    bool n2p = (negm != mod) && (posn != mod);
    bool p2n = (posm != mod) && (negn != mod);
    ll ansn2p = (divll(ans, negm) * posn) % mod;
    ll ansp2n = (divll(ans, posm) * negn) % mod;
    // cout << ans << endl;
    // cout << ansn2p << " " << ansp2n << endl;
    if (n2p && p2n){
        if (posn * posm > negn * negm) ans = ansn2p;
        else ans = ansp2n;
    }else if (n2p){
        ans = ansn2p;
    }else if (p2n){
        ans = ansp2n;
    }else if (z > 0){
        ans = 0;
    }else{
        ans = 1;
        REP(i,k) ans = (ans * p[n - 1 - i].first) % mod;
        ans = (mod - ans) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6404
import java.io._
import scala.io.StdIn.{readLine, readInt}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0

  def toZero(x:Double) = if(x == -0.0) 0.0 else x
  def main(args:Array[String]) = {
   val p = readLine.split(" ").map(_.toDouble)
   val n = readInt
   val (x0,y0,x1,y1) = (p(0),p(1),p(2),p(3))

   val (x,y) = (x1-x0, y1-y0)
   val sqrt = Math.pow(x,2) + Math.pow(y,2)
   val a = 2*x*x/sqrt
   val b = 2*x*y/sqrt
   val c = 2*y*y/sqrt

   for(i<-0 until n) {
     val p1 = readLine.split(" ").map(_.toDouble)
     val (x2,y2) = (p1(0),p1(1))
     val (w,z) = (p1(0)-x0, p1(1)-y0)
     val (xt,yt) = ( a*w+b*z+2*x0-x2, b*w+c*z+2*y0-y2 )

     out.write(toZero(xt).toString)
     out.write(" ")
     out.write(toZero(yt).toString)
     out.write("\n")
     if(count<100) count += 1
     else {
      out.flush
      count = 0
     }
   }
   out.flush
   out.close
  }
}

Measured memory_bytes: 47556
#include <iostream>
using namespace std;
int main(void){
    long n,d;
    long x,y;
    int ans = 0;
    cin >> n >> d;
    for(int i=0;i<n;i++) {
        cin >> x >> y;
        if(x*x+y*y<=d*d) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#! /usr/bin/python
# -*- coding: utf-8 -*-

n=int(input()) # 数列の長さ
A=list(map(int, input().split())) # 空白を区切文字として配列に格納
print(*A)

for i in range(1, n):
    key = A[i]
    # insert A[i] into the sorted sequence A[0,...,j-1]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    print(*A)


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


#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define pb push_back
#define len(x) (int)(x).size()
#define mkp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;


const int maxn = 3e5 + 10 , inf = 1e9;
vector < int > fenwick[maxn];
int get(int pref , int l , int r){
    int ans = 0;
    for(;pref > 0; pref -= (pref & -pref)){
        ans += upper_bound(all(fenwick[pref]) , r) - lower_bound(all(fenwick[pref]) , l);
    }
    return ans;
}
int ask(int l , int r , int l1 , int r1){
    return get(r , l1, r1) - get(l - 1 , l1 , r1);
}
void add(int x , int y){
    for(;x < maxn; x += (-x & x)){
        fenwick[x].pb(y);
    }
}

signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n , m;cin >> n >> m;
    vector < pii > lines(n);
    for(auto &i : lines)cin >> i.fi >> i.se;
    sort(all(lines));

    for(int i = 0 ; i < n; ++i)
        add(i+1 , lines[i].se);
    for(int i = 0 ; i < maxn; ++i)
        sort(all(fenwick[i]));
    for(int i = 1; i <= m; ++i){
        int ans = 0;
        int alr = 0;
        int pos = 0;
        while(pos <= m){
            int prev = alr;
            alr = upper_bound(all(lines) , mkp(pos , inf)) - lines.begin();
            if(prev <= alr - 1){
//                cout << " FOR " << i << ' ' << prev << ' ' << alr - 1 << ' ' << pos << ' ' << m << '\n';
                ans += ask(prev +1 , alr - 1 +1, pos, m);
            }
            pos += i;
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 31224
#include<stdio.h>
int main(){
    int n=0,i=0,x=0;
    scanf("%d",&n);

    for(i=1;i<=n;i++){
        if(i%3==0||i%10==3||i/10==3||i%100/10==3||i%1000/100==3||i%1000%100/10==3||i/100==3||i/1000==3){
            printf(" %d",i);
        }
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;

ll fact[1000010], seg[2097152];

void add(int s, int t, ll v, int k = 1, int l = 0, int r = 1048575) {
	if (t < l || r < s)return;
	if (s <= l && r <= t) {
		seg[k] += v;
		seg[k] %= MOD;
		return;
	}
	add(s, t, v, k * 2, l, (l + r) / 2);
	add(s, t, v, k * 2 + 1, (l + r) / 2 + 1, r);
}

ll gets(int x) {
	ll ans = 0;
	x += 1048576;
	while (x) {
		ans += seg[x];
		ans %= MOD;
		x /= 2;
	}
	return ans;
}

int main() {
	fact[0] = 1;
	ll fr = 0, N, H, D, V;
	for (int i = 0;i < 2097152;i++)seg[i] = 0;
	cin >> N >> H >> D;
	for (ll i = 1;i <= N;i++) {
		fact[i] = fact[i - 1] * i % MOD;
		fr += fact[i];fr %= MOD;
	}
	add(0, 0, fact[N]);
	for (int i = 0;i < H;i++) {
		V = gets(i) * fr % MOD;
		add(i + 1, min(i + D, H), V);
	}
	V = 0;
	for (int i = H - D;i < H;i++)V += gets(i), V %= MOD;
	cout << V << endl;
}

Measured memory_bytes: 24576
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    Int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!(i % 15 == 0 || i % 5 == 0 || i % 3 == 0)) {
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int H, N;
  cin >> H >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    sum += A;
  }
  if (sum >= H) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b&&b==c) cout << 1 << endl;
    else if(a!=b&&b!=c&&c!=a) cout << 3 << endl;
    else cout << 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    int l,c=0;
    string s;
    cin>>s;
    l=s.length();
    for(int i=0;i<s.length()-1;i++){
        if(s[i]!=s[i+1]){
            c++;
        }
        
    }
    cout<<c;
}


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

const int mod=998244353;

bitset<300> d[300],a[300];

int modpow(int x,int p){
	int res=1;
	while(p){
		if(p&1) res=1L*res*x%mod;
		x=1L*x*x%mod;
		p>>=1;
	}
	return res;
}

int main(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int x;
			cin >> x;
			a[j][i]=x;
		}
	}
	
	int r=0;
	for(int i=0;i<m;i++){
		for(int j=n-1;j>=0;j--){
			if(a[i][j]==1){
				if(!d[j][j]) d[j]=a[i],r++;
				a[i]^=d[j];
			}
		}
	}
	cout << 1L*modpow(2,n-1)*(modpow(2,m)-modpow(2,m-r)+mod)%mod << endl;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, X, T = getNM()
time = (N + X - 1) // X
print(time * T)

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

long long a, b, ans=-1;

int main(){
	cin >> a >> b;
	for (int i=1000;i>=1;i--){
		if (((2*i)/25)==a && (i/10)==b) ans=i;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	t := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&t[i])
	}
	//total
	total := 0
	for _, ti := range t {
		total += ti
	}
	totalm := 0
	for _, t2 := range t {
		if float64(total)/float64((4*m)) <= float64(t2) {
			totalm++
		}
	}
	if totalm >= m {
		fmt.Print("Yes")
		return
	}
	fmt.Print("No")
}


Measured memory_bytes: 512
a = [int(x) for x in input()[::-1]] + [0]
n = len(a)
dp = [[0] * 2 for _ in range(n)]
dp[0][0], dp[0][1] = a[0], 10-a[0]
for i in range(n-1):
    dp[i+1][0] = min(a[i+1]+dp[i][0], a[i+1]+dp[i][1]+1)
    dp[i+1][1] = min(10-a[i+1]+dp[i][0], 10-(a[i+1]+1)+dp[i][1])
print(min(dp[n-1]))


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while (x->left != NIL) x = x->left;
  return x;
}

Node find(Node u, int k){
  if(u == NIL || k == u->key) return u;

  if(k < u->key) return find(u->left, k);

  else return find(u->right, k);
}

Node treeSuccessor(Node x){
  Node y;

  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;

    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if(y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);

    printf(" ");
    printf("%d", u->key);

    inorder(u->right);
  }
}

void preorder(Node u){
  if (u != NIL) {
    printf(" ");
    printf("%d", u->key);

    preorder(u->left);
    preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19360
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
int color[101];
int A[101][101];
int d[101];
int f[101];
int time, n;

void visit(int u) {
	int i;
	color[u] = GRAY;
	d[u] = ++time;
	for (i = 1; i <= n; i++) {
		if (A[u][i] == 1) {
			if (color[i] == WHITE) visit(i);
		}
	}
	color[u] = BLACK;
	f[u] = ++time;
}

void dfs() {
	int i, j;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (A[i][j] == 1) {
				if (color[i] == WHITE) visit(i);
			}
		}
	}
}

int main() {
	int i, j, v, u, k;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			A[u][v] = 1;
		}
	}
	dfs();
	for (i = 1; i <= n; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

vector<int> G[1000];
bool G1[1000][1000];
int color[1000];

int num_1, num_2;

bool dp[1000][1000]; //dp[i+1][j]でi個目まででjが作れるか

int color_two(int n){ // -1:アウト;  0:もう塗った;  1:塗ってない,ok;
    if(color[n]!=0) return 0;
    queue<int> que;
    que.push(n);
    color[n]=1;
    num_1=1; num_2=0;
    while(!que.empty()){
        int v =que.front(); que.pop();
        for(auto x : G[v]){
            if(color[x]==0){
                color[x]=3-color[v];
                if(color[x]==1) num_1++;
                if(color[x]==2) num_2++;
                que.push(x);
            }
            else if(color[x]==color[v]){
                return -1;
            }
        }
    }
    return 1;
}

int main(){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y; x--; y--;
        G1[x][y]=true; G1[y][x]=true;
    }
    for(int x=0; x<N; x++){
        for(int y=0; y<N; y++){
            if(!G1[x][y] && x!=y){
                G[x].push_back(y);
            }
        }
    }
    vector<int> a(0),b(0); //
    bool flag1=true;
    for(int i=0; i<N; i++){
        int flag = color_two(i);
        if(flag==-1){flag1=false; break;} 
        if(flag==0) continue;
        if(flag==1){
            a.push_back(num_1);
            b.push_back(num_2);
        }
    }
    if(!flag1){cout << -1 << endl; return 0;}
    int n= a.size();
    dp[0][0]=true;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=N; j++){
            if(j<a.at(i-1) && j<b.at(i-1)){continue;}
            if(j<a.at(i-1) && j>=b.at(i-1)){
                dp[i][j]=dp[i-1][j-b.at(i-1)];
            }
            if(j>=a.at(i-1) && j<b.at(i-1)){
                dp[i][j] =dp[i-1][j-a.at(i-1)];
            }
            if(j>=a.at(i-1) && j>=b.at(i-1)){
                dp[i][j] = (dp[i-1][j-a.at(i-1)] || dp[i-1][j-b.at(i-1)]);
            }
        }
    }
    int res=0;
    for(int i=0; i<=N/2; i++){
        if(dp[n][i]) res=i;
    }
    cout << res*(res-1)/2 + (N-res)*(N-res-1)/2 << endl;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9) {
        cout << -1 << endl;
    } else
    {
        cout << a * b << endl;
    }
    
    return 0;
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    long long a, b, x;
    cin>>a>>b>>x;
    if(a==0){
        cout<<b/x+1<<endl;
    }
    else{
        cout<<b/x-(a-1)/x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "./libb/lib.hpp"
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;
const uint64_t MOD = 1000000007;
const double PI = acos(-1);
 
int main()
{
	uint32_t nn;
	int64_t dd;
	uint32_t sum = 0;
	cin >> nn >> dd;
	dd = dd * dd;

	vector < vector <int64_t> > mm(nn, vector<int64_t>(2, 0));

	for(int i = 0; i < nn; i++){
		cin >> mm.at(i).at(0) >> mm.at(i).at(1);
	}

	for(int i = 0; i < nn; i++){
		if ( ((mm.at(i).at(0) * mm.at(i).at(0)) + (mm.at(i).at(1) * mm.at(i).at(1))) <= dd )
			sum += 1;
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 14028
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n):
    if p[i]==i+1:
        cnt+=1
        x=1
        if i==n-1:
            break
        while True:
            if p[i+x]!=i+1:
                temp_v=p[i+x]
                p[i+x]=p[i]
                p[i]=temp_v
                break
            else:
                x+=1
print(cnt)

Measured memory_bytes: 13880
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	cout<<(n-2)*180;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String meshi = sc.nextLine();
        String tsuru = sc.nextLine();

        int N = Integer.parseInt(meshi.split(" ")[0]);
        int M = Integer.parseInt(tsuru.split(" ")[0]);

        List<String> times = new ArrayList<String>();
        for(int i = 1; i < N*2; i+=2){
            String hour = meshi.split(" ")[i];
            if(Integer.parseInt(hour) < 10){
                hour = "0" + hour;
            }
            String minute = meshi.split(" ")[i+1];
            if(Integer.parseInt(minute) < 10){
                minute = "0" + minute;
            }
            times.add(hour + ":" + minute);
        }

        for(int i = 1; i < M*2; i+=2){
            String hour = tsuru.split(" ")[i];
            if(Integer.parseInt(hour) < 10){
                hour = "0" + hour;
            }
            String minute = tsuru.split(" ")[i+1];
            if(Integer.parseInt(minute) < 10){
                minute = "0" + minute;
            }
            times.add(hour + ":" + minute);
        }

        for(int i = 0; i < times.size()-1; i++){
            for(int j = i+1; j < times.size(); j++){
                if(times.get(j).compareTo(times.get(i)) < 0){
                    String tmp = times.get(j);
                    times.set(j, times.get(i));
                    times.set(i, tmp);
                }
            }
        }

        List<String> unique = new ArrayList<String>();
        for(int i = 0; i < times.size(); i++){
            int hour = Integer.parseInt(times.get(i).split(":")[0]);
            String minute = times.get(i).split(":")[1];
            if(hour < 10){
                times.set(i, hour + ":" + minute);
            }
            if(!unique.contains(times.get(i))){
                unique.add(times.get(i));
            }
        }

        for(int i = 0; i < unique.size()-1; i++){
            System.out.print(unique.get(i) + " ");
        }
        System.out.println(unique.get(unique.size()-1));
    }
}

Measured memory_bytes: 35952
#include<bits/stdc++.h>
using namespace std;
int main(){
 int h,w,n;
  cin>>h>>w>>n;
  int m=max(h,w);
  if(n%m==0){
    cout<<n/m;
  }
  else{
      cout<<n/m +1;
    }
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc084/tasks/abc084_d
AC
"""
import sys
from sys import stdin
from math import ceil, floor
input = stdin.readline


def create_prime_list(limit):
    """ エラトステネスの篩でlimitまでの素数リストを求める
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    #print('x={0}'.format(x))
    nums = [x for x in range(2, limit+1)]
    while nums[0]<=x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x%current_prime != 0]
    primes.extend(nums)
    return primes


def solve(queries):
    primes = set(create_prime_list(10**5)) #  素数のテーブル、inでの判定が速くできるようにリストではなくセットにしておく
    dp = [0] * 100000

    # 1〜99,999までについて、1からのトータルで2017-likeな数字が累計でいくつあるか計算してテーブルにする
    p_num = 0
    for i in range(1, 100000, 2):
        if i in primes and ((i+1)//2) in primes:
            p_num += 1
        dp[i] = p_num

    # l 〜 r までで 2017-like数がいくつあるか求める
    for l, r in queries:
        if l == 1:
            ans = dp[r]         #  1からの場合、rまでの数がそのまま答え
        else:
            ans = dp[r] - dp[l-2] #  1〜rまでの数から 1〜l(エル)までの数を引けば、l〜rでの答えになる
        print(ans)


def main(args):
    queries = []
    Q = int(input())
    # Q = 0
    # for _ in range(100000):
    #     queries.append((1, 99999))
    queries = [map(int,input().split()) for _ in range(Q)]
    solve(queries)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int main(void) {
  char step[101];

  cin >> step;

  string ans = "Yes";
  for (int i = 0; step[i] != '\0'; i++) {
    if ((i+1)%2 == 0) {
      if (not(step[i] == 'L' or step[i] == 'U' or step[i] == 'D'))
	ans = "No";
    } else {
      if (not(step[i] == 'R' or step[i] == 'U' or step[i] == 'D'))
	ans = "No";
    }

    if (ans == "No")
      break;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(){

	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0)){
		int scores[1001];
		vector<int> comb;
		for(int i = 0; i < n; i++){
			cin>>scores[i];
		}
		scores[n]=0;
		for(int i = 0; i < n+1; i++){
			for(int j = 0; j < n+1; j++){
				int sum=scores[i]+scores[j];
				if(sum<=m)
					comb.push_back(sum);
			}
		}
		sort(comb.begin(),comb.end());
		comb.erase(unique(comb.begin(),comb.end()),comb.end());

		int maxNum=0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				int left = (scores[i]+scores[j]);
				if(left<=m&&comb[0]+left<=m){
					vector<int>::iterator it = lower_bound(comb.begin(),comb.end(),m-left);
					if(it==comb.end()){
						maxNum=max(maxNum,comb[comb.size()-1]+left);
					}
					else{
						if(*it==(m-left)){
							maxNum=m;
						}
						else{
							it--;
							maxNum=max(maxNum,*it+left);
						}
					}
				}
			}
		}
		cout<<maxNum<<endl;
	}

	return 0;
}

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

int main() {
  int N;
  cin>>N;
  int x=1;
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
     if(S=="Y"){
       x*=0;
     }
    else{
      x*=1;
    }
  }
  if(x==1){
  cout<<"Three"<<endl;
  }
  else{
    cout<<"Four"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define P pair<int, int>

using namespace std;


int main(){
	int field[50][50];
	int dp[50][50];
	int H, W;
	char temp;
	cin >> H >> W;


	rep(i, H){
		rep(j, W){
			cin >> temp;
			field[i][j] = (int)temp - (int)'0';
		}
	}
	
	/*
	rep(i, H){
		rep(j, W){
			cout << field[i][j];
		}
		cout << endl;
	}
	*/


	dp[0][0] = 0;

	
	rep(i, H){
		rep(j, W){
			if (i == 0 && j == 0)continue;
			if (i == 0){
				dp[i][j] = dp[i][j-1] + field[i][j];
			}
			else if (j == 0){
				dp[i][j] = dp[i-1][j] + field[i][j];
			}
			else{
				dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + field[i][j];
			}
		}
	}

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

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int l[100000],r[100000];
  int maxs = 1000000;
  int mins = 0;
  for(int i=0;i<m;i++){
    cin >> l[i] >> r[i];
    maxs = min(r[i],maxs);
    mins = max(l[i],mins);
  }
  if(mins>maxs){
    cout << 0 << endl;
  } else {
    cout << maxs-mins+1 << endl;
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INT_MAX 0x7FFFFFFF
using namespace std;

int hei[100005];
int main(){
	int t, l;
	cin >> t >> l;
	for(int i = 0; i < t; ++i)
		cin >> hei[i];
	std::sort(hei, hei + t);
	int min = INT_MAX;
	for(int i = 0; i <= t - l; ++i)
		min = std::min(min, hei[i + l - 1] - hei[i]);
	cout << min << endl;
	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	int a[11];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N, greater<int>());
	int sum = a[0] / 2;
	for (int i = 1; i < N; i++) {
		sum += a[i];
	}
	cout << sum << endl;
}

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

int main(){
    int N;
    cin >> N;
    int A[N], C[N-1];
    for(int i =0; i < N; i++){
        cin >> A[i];
    }
    int satisfaction = 0;
    for(int i =0; i < N; i++){
        int B;
        cin >> B;
        satisfaction += B;
    }
    for(int i =0; i < N-1; i++){
        cin >> C[i];
    }
    for(int i =0; i < N-1; i++){
        if(A[i+1]-A[i] == 1) satisfaction += C[A[i] - 1];
    }
    cout << satisfaction << endl;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w, n;
	cin >>h >>w >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	vector<VI> ba(h, VI(w));
	int cr = 0;
	rep(i, n){
		rep(j, a[i]){
			int y=cr/w, x = y%2?  w-1 -cr%w: cr%w;
			ba[y][x] = i+1;
			cr++;
		}
	}
	for(auto xl: ba){for(auto x :xl) cout<<x<<" "; cout<<"\n";}

	return 0;
}


Measured memory_bytes: 384
#include<math.h>
#define EPS (1e-7)
R,N,r[100],v[100],e[100],h;
double a[100],d[100];
hit(double L,int i){
	double ax,ay,cx,cy;
	ax=R*cos(L);
	ay=R*sin(L);
	cx=d[i]*cos(a[i]);
	cy=d[i]*sin(a[i]);
	if(ax*(cx-ax)+ay*(cy-ay)<EPS)
		return hypot(ax-cx,ay-cy)<r[i]+EPS;
	else
		return d[i]*fabs(cos(a[i])*sin(L)-sin(a[i])*cos(L))<r[i]+EPS;
}
main(){
	int i,x,y,m;
	for(;scanf("%d%d",&R,&N),R|N;){
		for(i=0;i<N;i++){
			scanf("%d%d%d%d",&x,&y,r+i,v+i);
			a[i]=atan2(y,x);
			d[i]=hypot(x,y);
			e[i]=1;
		}
		h=0;
		for(;;){
			for(i=0;i<N;i++)
				if(e[i])
					d[i]-=v[i];
			m=-1;
			for(i=0;i<N;i++){
				if(e[i]){
					if(d[i]<=R+EPS)
						e[i]=0;
					else if(m==-1||d[i]<d[m])
						m=i;
				}
			}
			if(m==-1)
				break;
			for(i=0;i<N;i++){
				if(e[i]&&hit(a[m],i)){
					e[i]=0;
					h++;
				}
			}
		}
		printf("%d\n",N-h);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>

int main()
{
    int64_t n, m;
    std::cin >> n >> m;

    int64_t sum = 0;
    if (n >= m / 2)
    {
        sum = m / 2;
    }
    else
    {
        sum = n;

        m -= 2 * n;
        sum += m / 4;
    }

    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int D()
{
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
const int N=2e5+9;

int arr[N],frq[N];
int main(){
    int n =D();
    for(int i=1; i<n;i++)
    {
        int a=D();
        frq[a]++;
    }
    for(int i=1; i<=n;i++)
        printf("%d\n",frq[i]);
}
/**
bool ok(int val){
  int cntm=0,cntp=0;
  for(int i=0;i<n-val;i++)
  {
      cntm=0;cntp=0;
      for(int j=i;j<val;j++)
      {
      (arr[j]==1)?cntp++:cntm++;
      }
      if(cntp==cntm)
        break;
  }
  return cntp==cntm;
}
int binarySearch(){
  int low = 0, med, hi =n;
  while(low<hi){
    med = (low+hi+1)>>1;
    cout<<med<<" "<<hi<<" "<<low<<endl;
    if(ok(med))  low = med;
    else  hi = med-1;
  }
  return low;
}*/



/**
  int power1(int b, int p){               //O(p)
    if(!p)  return 1;
    return b*power1(b, p-1);
  }
  int power2(int b, int p){               //O(Log(p))
    if(!p)  return 1;
    int ret = power2(b, p/2);
    return (p&1 ? ret*ret*b : ret*ret);
  }
   int mul(int a, int b, int m){
      return (a%m * b%m) % m;
  }

*/


/**
void seive()
{
    bitset<N>iscomp;
    iscomp[0]=iscomp[1]=1;
    for(long long i=2; i<=N; ++i)
    {
        if(!iscomp[i])
        {
            a.push_back(i);
            for(long long j=i*i; j<=N; j+=i)
                iscomp[j]=1;
        }
    }
}
3
abc
abc
*/

    /**


    */


Measured memory_bytes: 4604
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    int n,K;
    while(cin>>n>>K){
        long long sum=0;
        long long t=0;
        if(K&1){
            t=n/K;
            sum+=t*t*t;
        }
        else{
            t=n/K;
            sum+=t*t*t;
            t=(n+K/2)/K;
            sum+=t*t*t;
        }
        cout<<sum<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n,y;cin>>n>>y;
    y /= 1000;
    for(int i=0;i<=n;i++) {
        for(int j=0;j<=n-i;j++) {
            int x = (i*10) + (j*5) + (n-i-j);
            if(x == y) {
                cout<<i<<" "<<j<<" "<<n-i-j<<"\n";
                return 0;
            }
        }
    }
    cout <<"-1 -1 -1\n";
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	int q;
	cin >> q;

	char* front_queue = new char[q];
	char* back_queue = new char[q];
	int front_cnt = 0;
	int back_cnt = 0;

	bool reverse = false;

	for (int i = 0; i < q; ++i) {
		int t;
		cin >> t;
		if (t == 1) {
			reverse = !reverse;
		}
		else if (t == 2) {
			int f;
			cin >> f;
			char c;
			cin >> c;

			if (f == 2) {
				if (reverse) {
					front_queue[front_cnt] = c;
					front_cnt++;
				}
				else{
					back_queue[back_cnt] = c;
					back_cnt++;
				}
			}
			else if (f == 1) {
				if (reverse) {
					back_queue[back_cnt] = c;
					back_cnt++;
				}
				else {
					front_queue[front_cnt] = c;
					front_cnt++;
				}
			}
		}
	}

	string front(front_queue, front_cnt);
	string back(back_queue, back_cnt);

	s += back;
	std::reverse(s.begin(), s.end());
	s += front;

	if (!reverse) std::reverse(s.begin(), s.end());

	cout << s << endl;
	return 0;
}


Measured memory_bytes: 1348
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, A, B): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let ans = S.iter().scan((0, 0), |s, &c| {
        let (x, y) = *s;
        if c == 'a' && x < A + B {
            *s = (x + 1, y);
            Some("Yes")
        } else if c == 'b' && x < A + B && y < B {
            *s = (x + 1, y + 1);
            Some("Yes")
        } else {
            Some("No")
        }
    })
    .collect::<Vec<_>>()
    .join("\n");

    println!("{}", ans);
}


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

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

using namespace std;

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

  cout<<( (b-a)%2==0 ? "Alice" : "Borys" );

  return 0;
}

Measured memory_bytes: 256