akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 #define fast() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll  long long
#define f(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define MP make_pair
#define vi vector<int>
#define vll vector<long long>
#define F     first
#define S    second
#define all(x) x.begin(), x.end()
ll dp[101][100001];
map<int, pair<ll, ll>> mp;
int n, w;
ll fun()
{
	for(int i = 1; i <= n; i++)
	{
		ll a = mp[i].F;
		ll b = mp[i].S;
		for(int j = 1; j <= w; j++)
		{
			ll p = 0;
			if(j >= a)
				p = b + dp[i - 1][j - a];
			dp[i][j] = max(p, dp[i-1][j]);
		}
	}
	return dp[n][w];
}

int main()
{
    fast();
 	ll x, y;
 	cin >> n >> w;
 	for(int i = 1 ;i <= n; i++)
 	{
 		cin >> x >> y;
 		mp.insert({i, {x, y}});
 	}
 	cout << fun() ;
 	
}

Measured memory_bytes: 78464
#include <stdio.h>
int main(){
  int flag=1, i,j,n,a[100],work,count=0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  
  while(flag){
    flag=0;
    for(j=n-1; j>=1; j--){
      if(a[j] < a[j-1]){
	work=a[j];
	a[j]=a[j-1];
	a[j-1]=work;
	count++;
	flag=1;
      }     
    }
  }
  
  if(n==1) printf("%d",a[0]);
  else{
    for(i=0; i<n; i++){
      if(i==n-1) printf("%d", a[i]);
      else printf("%d ",a[i]);
    }
  }
  printf("\n%d\n",count);
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans = (s[0] - '0') + 9 * (int)(s.size()-1);
    for(int i = 1; i < s.size(); i++){
        if(s[i] != '9'){
            ans--;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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


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

	int l = s.size();
	int ans = 0;

	for(int i=0;i<l/2;i++){
		if(s[i]!=s[l-i-1]){
			ans++;

		}
	}

	cout << ans << endl;
	


}

Measured memory_bytes: 256
found = False
def solve(N, Y):
    global found
    for i in range(N + 1):
        if i * 10000 > Y: continue
        for j in range(N - i + 1):
            k = N - i - j
            if i * 10000 + j * 5000 + k * 1000 == Y:
                print(i, j, k)
                found = True
                return
            else:
                continue

N, Y = [ int(val) for val in input().split() ]
solve(N,Y)
if not found:
    print("-1 -1 -1")


Measured memory_bytes: 3060
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n,a[100000],l,mem;
bool flag;
int main(){
	cin>>n>>l;
	cin>>a[0];
	flag=true;
	lp(n-1){
		cin>>a[i+1];
		if(a[i]+a[i+1]>=l){
			mem=i+1;
			flag=false;
		}
	}
	if(flag)
		cout<<"Impossible"<<endl;
	else{
		cout<<"Possible"<<endl;
		for(int i=1;i<mem;i++)
			cout<<i<<endl;
		for(int i=n-1;i>=mem;i--)
			cout<<i<<endl;
	}
	return 0;
}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int[]C = new int[N];
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			C[i] = int.Parse(str2[i]);
		}
		int cta = 0;
		int ctb = 0;
		int ctc = 0;
		for(var i=0;i<N;i++){
			if(C[i]<=A){
				cta++;
			} else if(C[i]<=B){
				ctb++;
			} else {
				ctc++;
			}
		}
		long ans = Math.Min(Math.Min(cta,ctb),ctc);
		Console.WriteLine(ans);
	}
}

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

int main() {
  int N,M,i,m=0;
  map<string,int> s,t;
  string x;

  cin >> N;
  for(i=0; i<N; i++) {
    cin >> x;
    if(s.count(x))
      s.at(x)++;
    else
      s[x] = 1;
  }
  cin >> M;
  for(i=0; i<M; i++) {
    cin >> x;
    if(t.count(x))
      t.at(x)++;
    else
      t[x] = 1;
  }

  for(auto p : s)
    if(t.count(p.first)) {
      if(p.second-t.at(p.first)>m)
        m = p.second-t.at(p.first);
    } else {
      if(p.second > m)
        m = p.second;
    }

  cout << m << endl;
}

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

ll N, M;
vector<ll> E[100000];
ll dp[100000], ans[100000];

void dfs(ll v, ll p) {
  dp[v] = 1;

  for (ll u : E[v]) if (u != p) {
    dfs(u, v);

    dp[v] *= (dp[u] + 1) % M;
    dp[v] %= M;
  }
}

void dfs2(ll v, ll p, ll x) {
  ans[v] = (dp[v] * x) % M;

  vector<ll> l, r;
  l.push_back(1);
  REP(i, 0, E[v].size()) {
    ll u = E[v][i];
    if (u == p) {
      l.push_back(1);
      r.push_back(1);
    } else {
      l.push_back(dp[u] + 1);
      r.push_back(dp[u] + 1);
    }
  }
  r.push_back(1);

  REP(i, 1, l.size()) {
    l[i] *= l[i - 1];
    l[i] %= M;
  }

  for (ll i = (ll) r.size() - 2; i >= 0; i--) {
    r[i] *= r[i + 1];
    r[i] %= M;
  }

  REP(i, 0, E[v].size()) {
    ll u = E[v][i];
    if (u == p) continue;
    ll y = l[i] * r[i + 1] % M;
    ll z = ((x * y % M) + 1) % M;
    dfs2(u, v, z);
  }
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, N - 1) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }

  dfs(0, -1);
  dfs2(0, -1, 1);

  REP(i, 0, N) cout << ans[i] << endl;
}

Measured memory_bytes: 26496
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    //check;
    int dif1=c[0][1]-c[0][0];
    int dif2=c[0][2]-c[0][1];
    for(int i=1;i<3;i++){
        if(c[i][1]-c[i][0]!=dif1){
            cout<<"No"<<"\n";
            return 0;
        }
        if(c[i][2]-c[i][1]!=dif2){
            cout<<"No"<<"\n";
            return 0;
        }
    }

    int diff1=c[1][0]-c[0][0];
    int diff2=c[2][0]-c[1][0];
    for(int i=1;i<3;i++){
        if(c[1][i]-c[0][i]!=diff1){
            cout<<"No"<<"\n";
            return 0;
        }
        if(c[2][i]-c[1][i]!=diff2){
            cout<<"No"<<"\n";
            return 0;
        }
    }
    cout<<"Yes"<<"\n";





    return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
typedef long long ll;
 
ll a[5001][5001];
ll b[5001][5001];
 
int main() {
  ll n,sum=0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[0][i],sum+=a[0][i];
  for (int i = 1; i < n; i++)
    for (int j = 0; j < n - i; j++) {
      ll t = a[0][j] + a[i - 1][j + 1] + b[i - 1][j + 1];
      a[i][j] = max(a[0][j] + b[i - 1][j + 1], a[0][j + i] + b[i - 1][j]);
      b[i][j] = t - a[i][j];
    }
  cout << -sum+2*a[n - 1][0] << endl;
}

Measured memory_bytes: 237312
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long 
int main()
{
	ll n;
	cin>>n;
	ll a[n+10];
	for(ll i=1;i<=n;i++) cin>>a[i];
	ll m;
	cin>>m;
	for(int i=0;i<m;i++)
	{
		ll aa,b;
		cin>>aa>>b;
		ll sum=0;
		for(ll j=1;j<=n;j++)
		{
			if(j==aa)
			{
				sum+=b;
			}
			else
			{
				sum+=a[j];
			}
		}
		cout<<sum<<endl;
	}
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	vector<int64> a(N);
	REP(i, N) cin >> a[i];

	int64 res = 0;
	REP(i, N) {
	  if ((i+1) % 2 && a[i]%2) {
	    res++;
	  }
	}
	cout << res << endl;
}


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

//グローバル変数
//vector<int>L[200005]; 
vector<vector<int>>L(200005);
map<int, int>score;

void dfs(int p, int bp=-1){
    for(auto c :L[p]){
        if(c !=bp){
            score[c]+=score[p];
            dfs(c, p);
        } 
        
    }
}

int main(void){
    int N, Q, a, b;
    cin >> N >> Q;
    
    rep(i, N-1){
        cin >> a >> b;
        L[a].push_back(b);
        L[b].push_back(a);
    }
    
    int x, y;
    rep(i, Q){
        cin >> x >> y;
        score[x] +=y;
    }
    
    dfs(1);
    
    for(int i=1; i<=score.size(); i++) cout << score[i] << endl;

}

Measured memory_bytes: 44544
# coding:utf-8

from fractions import gcd 

n, y = map(int, input().split())

dist_list = [abs(x-y) for x in map(int, input().split())]

if n == 1:
    d = dist_list[0]
else:
    d = gcd(dist_list[1], dist_list[0])
    for i in range(n-2):
        d = gcd(d, dist_list[i+1])

print(d)


Measured memory_bytes: 16280
n = int(input())
a_up = list(map(int, input().split()))
a_down = list(map(int, input().split()))
max_sum = 0
for i in range(n):
    tmp_sum = sum(a_up[:i+1])+sum(a_down[i:])
    max_sum = max(max_sum, tmp_sum)
print(max_sum)

Measured memory_bytes: 3060
from collections import deque

S=input()
N=int(input())
inilen=len(S)
d=deque()
for i in range(inilen):
    d.append(S[i])
revflag=False
for i in range(N):
    L=list(map(str,input().split()))
    if L[0]=="1":
        if revflag==False:
            revflag=True
        else:
            revflag=False
    elif L[1]=="1":
        if revflag==False:
            d.appendleft(L[2])
        else:
            d.append(L[2])
        
    elif L[1]=="2":
        if revflag==False:
            d.append(L[2])
        else:
            d.appendleft(L[2])

if revflag==True:
    d.reverse()

Z=list(d)
Z=[str(a) for a in Z]
Z="".join(Z)
print(Z)



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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    string s; cin >> s;
    deque<char> ds;
    rep(i,s.size()) ds.emplace_back(s[i]);
    int q; cin >> q;
    bool inv = false;
    rep(i,q){
        int t; cin >> t;
        if(t == 1){
            inv = !inv;
        }else{
            int f; char c;
            cin >> f >> c;
            bool front = (f == 1) ? true : false;
            if(front^inv) ds.push_front(c);
            else ds.push_back(c);
        }
    }
    if(inv) rrep(i,ds.size()) cout << ds[i];
    else rep(i,ds.size()) cout << ds[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 976
import heapq
import numpy as np

def acinput():
    return list(map(int,input().split(" ")))



N,M=acinput()
A=list(map(lambda x:-int(x),input().split(" ")))

A=sorted(A,reverse=False)
#print(A)
for i in range(M):
    a=heapq.heappop(A)
    heapq.heappush(A,np.ceil(a/2))

res=0
for sa in A:
    res+=sa

print(int(-res))

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

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

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

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

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

ll A, B, K;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> A >> B >> K;
    if (A >= K) {
        A -= K;
        K = 0;
    } else {
        K -= A;
        A = 0;
    }
    B = max(B - K, (ll)0);
    cout << A << " " << B;
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


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

using namespace std;

int A[2000] = {0};
int n, q;

bool knap(int k, int j)
{
  if (k == 0) return true;
  if (j >= n) return false;
  if (k < A[j]) {
    return knap(k, j+1);
  } else {
    return knap(k, j+1) or knap(k-A[j], j+1);
  }
}

int main()
{
  cin >> n;

  for(int i = 0; i<n; ++i) cin >> A[i];

  cin >> q;

  int k;
  for (int i =0; i<q; ++i) {
    cin >> k;
    cout << (knap(k, 0) ? "yes\n" : "no\n");
  }
}


Measured memory_bytes: 3088
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector> 

using namespace std;

int main()
{
    const int INF = 1e9+7;
    int n;
    cin>>n;
    
    vector<vector<int>> inp(n,vector<int>(3)), dp(n,vector<int>(3,0));
    
    
    for(int i=0;i<n;++i){
        cin>>inp[i][0]>>inp[i][1]>>inp[i][2];
    }
    
    dp[0][0] = inp[0][0];
    dp[0][1] = inp[0][1];
    dp[0][2] = inp[0][2];
    
    for(int i=1;i<n;++i){
        dp[i][0] = inp[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = inp[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = inp[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

    return 0;
}


Measured memory_bytes: 13968
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;

#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
const ll mn=1e5+2;
int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n; scanf("%lld",&n);
	vector<pll> v;
	for (ll i=0;i<n;i++) {
		ll a;scanf("%lld",&a);
		v.PB(MP(a,0));
	}
	for (ll i=0;i<n;i++) {
		ll b;scanf("%lld",&b);
		v.PB(MP(b,1));
	}
	sort(v.begin(),v.end());
	ll ans=1;
	ll cnt[2];
	cnt[0]=0,cnt[1]=0;
	for (auto &w:v) {
		ll t=w.second;
		if (cnt[t^1]) {
			ans=(ans*cnt[t^1])%MOD;
			cnt[t^1]--;
		}
		else cnt[t]++;
	}
	printf("%lld\n",ans);
}



Measured memory_bytes: 4464
import java.util.*;

public class Main {
	public static void main(String[] args){
		new Main().calc();
	}

	String[] board;
	boolean[][] dp;
	int h,w;
	int[] vx = new int[]{1,0,-1,0};
	int[] vy = new int[]{0,1,0,-1};
	int ret = 0;

	void calc(){
		Scanner cin = new Scanner(System.in);
		int h = cin.nextInt();
		int w = cin.nextInt();
		int[][] dp = new int[h][w];
		String[] board = new String[h];
		for(int i=0;i<h;i++) board[i] = cin.next();
		for(int i = 0;i < h; i++){
			for(int j=0;j<w; j++){
				dp[i][j] = 99999999;
			}
		}
		dp[0][0] = 0;
		for(int i = 0;i < h; i++){
			for(int j=0;j<w; j++){
				dp[i][j] += board[i].charAt(j) - '0';
				if(i!=h-1) dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j]);
				if(j!=w-1) dp[i][j+1] = Math.min(dp[i][j+1], dp[i][j]);
			}
		}
		System.out.println(dp[h-1][w-1]);
	}

}

Measured memory_bytes: 12000
// ------------------------------------
// Date:2018/ 2/24
// Problem:AGC 002 BoxAndBall b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

#define MOD 1000000007

// box
int dp[100000];
bool ball[100000];

int main()
{
  int N,M,x,y;
  int cnt = 0;
  memset(dp,0,sizeof(dp));
  memset(ball,false,sizeof(ball));
  cin >> N >> M;
  FOR(i,1,N+2) {
    dp[i] = 1;
  }
  ball[1] = true;
  REP(i,M) {
    cin >> x >> y;
    if (ball[x]) {
      if (dp[x] == 1) {
        ball[x] = false;
      }
      ball[y] = true;
    }
    --dp[x];
    ++dp[y];
  }
  FOR(i,1,N+1) {
    //cout << i << "->" << (ball[i]?"Yes":"No") << endl;
    if (ball[i]) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 768
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,h,w,x[100010]={};
  int i,a,b,c,y[100010]={};
  scanf("%d %d %d",&n,&w,&h);
  while(n--){
    scanf("%d %d %d",&a,&b,&c);
    x[MAX(0,a-c)  ]++;
    x[MIN(h+1,a+c)]--;
    y[MAX(0,b-c)  ]++;
    y[MIN(w+1,b+c)]--;
  }
  //for(i=0;i<h+2;i++)printf("%d ",y[i]);printf("\n");
  //for(i=0;i<w+2;i++)printf("%d ",x[i]);printf("\n");
  for(i=0;i<h;i++){
    if(y[i]==0)break;
    y[i+1]+=y[i];
  }
  if(i==h)goto END;
  for(i=0;i<w;i++){
    if(x[i]==0)break;
    x[i+1]+=x[i];
  }
  if(i==w)goto END;
  printf("No\n");
  return 0;
 END:
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 1372
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll DIV = (ll)1e9+7;
// const ll MAXN = (ll)1e5+10;


int main(void) {
   ll N;
   cin>>N;
   map<ll,ll> A;
   ll a;
   rep(i,0,N) {
      cin>>a;
      if (A.count(a)) A[a]++;
      else A[a] = 1;
   }
   ll ans = 0;
   for (auto el: A) {
      if (el.second < el.first) ans += el.second;
      else ans += (el.second - el.first);
   }
   cout<<ans<<endl;

   return 0;
}



Measured memory_bytes: 6272
#include<stdio.h>
int main(){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    if (a >= 0 && a < b && b < c && c <= 100){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
        return 0;
}


Measured memory_bytes: 2052
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        String[] W = new String[N];
        for (int i = 0; i < W.length; ++i) {
            W[i] = sc.next();
        }

        System.out.println(solve(W) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(String[] W) {
        return Arrays.stream(W).distinct().count() == W.length
                && IntStream.range(1, W.length).allMatch(i -> W[i].charAt(0) == W[i - 1].charAt(W[i - 1].length() - 1));
    }
}

Measured memory_bytes: 36164
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
    char atcg; cin >> atcg;
    if(atcg=='A') cout << "T";
    else if(atcg=='T') cout << "A";
    else if(atcg=='C') cout << "G";
    else if(atcg=='G') cout << "C";
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()

struct FastIO
{
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0); 
  }
}fastio;

void dfs(int i, int current, std::vector<std::vector<int> >& from, std::vector<int>& val, std::vector<int>& ans, std::vector<int>& went) {
	went[i] = true;
	current += val[i];
	ans[i] = current;
	for(auto to:from[i]) {
		if(!went[to]) {
			dfs(to,current,from,val,ans,went);
		}
	}
}

signed main() {
	int n,q;
	std::cin >> n >> q;
	std::vector<std::vector<int> > from(n,std::vector<int> ());
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		from[a].emplace_back(b);
		from[b].emplace_back(a);
	}

	std::vector<int> val(n,0);
	rep(i,q) {
		int p,x;
		std::cin >> p >> x;
		p--;
		val[p]+=x;
	}
	std::vector<int> ans(n,0);
	std::vector<int> went(n,false);
	dfs(0,0,from,val,ans,went);

	for(auto i:ans) std::cout << i << ' ';

	return 0;
}


Measured memory_bytes: 33664
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  double x1,y1,x2,y2,x3,y3,x4,y4,ab,cd;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    ab = (y2-y1)/(x2-x1);
    cd = (y4-y3)/(x4-x3);
    if(ab == cd){
      cout << "YES" << endl;
    }else {
      cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 1264
import collections

N=int(input())
l=[]
for i in range(N):
    a=int(input())
    l.append(a)

lc=collections.Counter(l)
L=lc.most_common()
#print(L)
ans=0
for j in range(len(L)):
    if L[j][1]%2==1:
        ans+=1
print(ans)

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

int main(){
  int k;
  cin>>k;
  int a,b;
  cin>>a>>b;
  int count=0;
    for(int i=a;i<=b;i++){
       if(i%k==0){
          cout<<"OK\n";
         count++;
         break;
       }
     }
  if(count!=1){
    cout<<"NG"<<endl;
  }
  return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABM = ReadInts();
            var a = ReadInts();
            var b = ReadInts();

            var anslist = new List<int>();
            var sonomama = a.Min() + b.Min();
            anslist.Add(sonomama);
                
            for (int i = 0; i < ABM[2]; i++)
            {
                var xyc = ReadInts();

                var price = a[xyc[0] - 1] + b[xyc[1] - 1] - xyc[2];
                anslist.Add(price);
            }
            WriteLine(anslist.Min());
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 38620
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define mod 1000000007
#define PI acos(-1)
int main()
{
	IOS
	int l,r,d;
	cin>>l>>r>>d;
	int ans=0;
	for(int i=l;i<=r;i++)
	{
		if(i%d==0)
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int n,a[200],x;
int solve(){
	int l=0,r=n-1,mid,ans=0;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==x)
			return ans+1;
		else
		if(a[mid]<x)
		l=mid+1;
		else r=mid-1;
		ans++;

	}
	return ans;
}
int main(){
	while(cin>>n,n){
		for(int i=0;i<n;i++)
		cin>>a[i];
		cin>>x;
		cout<<solve()<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
class Dice:
    def __init__(self, numbers):
        self.dice = {"上" :numbers[0],
                     "下":numbers[5], 
                     "前":numbers[1],
                     "後":numbers[4],
                     "左":numbers[3],
                     "右":numbers[2]
                    }
    
    def order(self, order_seq):
        self.order_seq = order_seq
        for _, order in enumerate(self.order_seq):
            if order == "N":
                self.north()
            elif order == "E":
                self.east()
            elif order == "W":
                self.west()
            elif order == "S":
                self.south()
        
        return self.dice["上"]

    def north(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = F
        self.dice["前"] = D
        self.dice["下"] = B
        self.dice["後"] = U

    def east(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = L
        self.dice["下"] = R
        self.dice["左"] = D
        self.dice["右"] = U

    def west(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = R
        self.dice["下"] = L
        self.dice["左"] = U
        self.dice["右"] = D

    def south(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = B
        self.dice["前"] = U
        self.dice["下"] = F
        self.dice["後"] = D    
        
numbers = list(map(int, input().split()))
order_seq = list(input())

dice = Dice(numbers)
print(dice.order(order_seq))


Measured memory_bytes: 5608
#include <iostream>
#include <map>

using namespace std;

void solve()
{
	map<int, int> Map;
	int n;
	while(~scanf("%d", &n))
	{
		++Map[n];
	}
	int Max = 0;
	for(map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
	{
		if(Max < Ite->second)
		{
			Max = Ite->second;
		}
	}
	for(map<int, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
	{
		if(Ite->second == Max)
		{
			cout << Ite->first << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap().parse::<usize>().unwrap();
    let k = iter.next().unwrap().parse::<i64>().unwrap();
    let a = (0..n).map(|_| iter.next().unwrap().parse::<i32>().unwrap()).collect::<Vec<_>>();
    let mut res : i64 = 0;
    let m = 1000000007;
    let mul =  (k * (k-1) / 2) % m;
    for i in 0..n {
        let mut cnt0 = 0;
        let mut cnt1 = 0;
        for j in 0..n {
            if a[j] < a[i] {
                cnt0 += 1;
                if i < j { cnt1 += 1; }
            }
        }
        res = (res + k * cnt1) % m;
        res = (res + mul * cnt0) % m;
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLG(obj) (obj).begin(), (obj).end(), greater<long>()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int printYes() {
    cout << "Yes" << endl;
    return 0;
}

int printNo() {
    cout << "No" << endl;
    return 0;
}

int ans;

int printAns() {
    cout << ans << endl;
    return 0;
}


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
    int n,m;
    cin >> n >> m;
    vppl v(n);
    rep(i,n) {
        cin >> v[i].X >> v[i].Y.X >> v[i].Y.Y;
    }
    vl v1(n), v2(n),v3(n),v4(n),v5(n),v6(n), v7(n), v8(n);
    rep(i,n) {
        v1[i] = v[i].X + v[i].Y.X + v[i].Y.Y;
        v2[i] = v[i].X - v[i].Y.X + v[i].Y.Y;
        v3[i] = v[i].X - v[i].Y.X - v[i].Y.Y;
        v4[i] = v[i].X + v[i].Y.X - v[i].Y.Y;
        v5[i] = - v[i].X + v[i].Y.X + v[i].Y.Y;
        v6[i] = - v[i].X - v[i].Y.X + v[i].Y.Y;
        v7[i] = - v[i].X - v[i].Y.X - v[i].Y.Y;
        v8[i] = - v[i].X + v[i].Y.X - v[i].Y.Y;
    }
    sort(ALLG(v1));
    sort(ALLG(v2));
    sort(ALLG(v3));
    sort(ALLG(v4));
    sort(ALLG(v5));
    sort(ALLG(v6));
    sort(ALLG(v7));
    sort(ALLG(v8));
    vl vmax(8);
    rep(i,8) {
        vmax[i] = 0;
    }
    rep(i,m){
        vmax[0] += v1[i];
        vmax[1] += v2[i];
        vmax[2] += v3[i];
        vmax[3] += v4[i];
        vmax[4] += v5[i];
        vmax[5] += v6[i];
        vmax[6] += v7[i];
        vmax[7] += v8[i];
    }
    sort(ALLG(vmax));
    cout << vmax[0] << endl;
    return 0;
}


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

int main(){
    int mass1;
    double a,b,mass2,mass3;
    cin>>a>>b;
    mass2 = (a+b)/2;
    mass1 = (a+b)/2;
    mass3 = mass2-mass1;
    //cout<<mass2-mass1<<endl;
    //cout<<mass1<<endl;
    if(mass3 != 0){
    cout<<mass1 + 1<<endl;
    }
    else
    {
        cout<<mass1<<endl;
    };
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T>
inline void read(T &x) {
	x = 0;
	T f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
inline void d_read(double &x) {
	x = 0.0;
	int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	if (c == '.'){
		double num = 1.0;
		c = getchar();
		for (; isdigit(c); c = getchar()) x = x + (num /= 10) * (c ^ 48);
	}
	x *= f;
}

template <typename T>
inline void w(T x) {
	if (x > 9) w(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
	if (x < 0){
		putchar('-');
		x = -x;
	}
	w(x);
	putchar(c);
}

int main(){
	int n;
	read(n);
	write(n + n * n + n * n * n, '\n');
	return 0;
}


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

typedef pair<int,int> P;
typedef long long ll;

const int INF = 100000000;
const double PI=acos(-1);

ll dp[10010][2][110];

int main(){
    int K,T;
    cin >> K >> T;
    map<int,int> S;
    rep(i,T) {
        int tmp;
        cin >> tmp;
        S[i]=tmp;
    }
    vector<int> A(1,-1);

    rep(i,K) {
        int idx,idx_max;
        int num,num_max;
        idx = idx_max = -1;
        num = num_max = -1;

        rep(j,T) {
            if (S[j]>num && S[j]>0) {
                idx = j;
                num = S[j];
            }
            if (S[j]>num_max && S[j]>0 && A[i]!=j) {
                idx_max = j;
                num_max = S[j];
            }
        }
        if (idx_max!=-1) {
            A.push_back(idx_max);
            S[idx_max]--;
        }
        else {
            A.push_back(idx);
            S[idx]--;           
        }
    }
    int ans = 0;
    rep(i,A.size()-1) {
        if (A[i]==A[i+1]) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    long long n,i,j,money=1000,kabu=0,a[100]={};
    scanf("%lld",&n);
    for(i=1; i<=n; i++){
        scanf("%lld",&a[i]);
    }
    for(i=1; i<=n; i++){
        if(a[i]>=a[i+1]){
            money+=kabu*a[i];
            kabu=0;
        }
        if(a[i]<a[i+1]){
            kabu+=money/a[i];
            money-=(money/a[i])*a[i];
        }
    }
    printf("%lld",money);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)
vi G[space];
ll dp[space][2];
void dfs(int n,int p)
{

    dp[n][0]=dp[n][1]=1;
    
    for(auto z:G[n])
    {
        if(z!=p)
        {
            dfs(z,n);
            dp[n][1]*=dp[z][0];
            dp[n][1]%=mod;
            dp[n][0]*=(dp[z][0]+dp[z][1])%mod;
            dp[n][0]%=mod;
        }
    }
   
    
}
int main()
{
    int n,i,j,t,u,v;
    boost;

    cin>>n;
    rep(i,0,n-1)
    {
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }
    dfs(1,-1);
    cout<<(dp[1][0]+dp[1][1])%mod;
    return 0;
}



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

int main(){
    int n , r ,a;
    cin >> n >> r;
    if(10-n <= 0){
        cout << r << endl;
    }
    else{
        a = 10-n;
        cout << 100*a + r << endl;
    }
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i >= k && t[i] == t[i-k]) {
      t[i] = ' ';
      continue;
    }
    if (t[i] == 'r') ans += p;
    if (t[i] == 's') ans += r;
    if (t[i] == 'p') ans += s;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int n;  cin >> n;
  cout << pow(n,3);
  return 0;
}


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

int main(){
	int n;
	long long a[100005];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=n-1;i>0;i--){
		if(a[i]<a[i-1])a[i-1]--;
	}
	int f=1;
	for(int i=0;i<n-1;i++){
		if(a[i]>a[i+1]){printf("No\n");f=0;break;}
	}
	if(f==1)printf("Yes\n");
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i;
    cin>>n;
    vector <ll> a(n+1);
    vector <ll> b(n+1);
    vector <ll> c(n+1);
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
     for(i=1;i<=n;i++)
    {
        cin>>b[i];
    }
     for(i=1;i<n;i++)
    {
        cin>>c[i];
    }
    ll sum=0;
    sum+=b[a[1]];
    //cout<<sum<<"\n";
    for(i=2;i<=n;i++)
    {
        sum+=b[a[i]];
        if(a[i]-a[i-1]==1)
        {
            sum+=c[a[i-1]];
        }
       // cout<<sum<<"\n";

    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int64_t h;
  cin>>h;
  vector<int64_t> vec(45,1);
  for (int i = 1; i < 45; ++i)
  {
    vec[i]=vec[i-1]*2;
  }
  for (int i = 0; i < 44; ++i)
  {
    if(h>=vec[i] && h<vec[i+1])
    {
      cout<<vec[i+1]-1;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3


def main():
    n = int(input())
    s = input()
    # print("s: " + s)
    # 左に白が存在する赤
    # 右に赤が存在する白 <=> これらは交換しても良い
    # minimumな個数を交換すればいいはず
    # 塗り替えは実はする必要はない
    w = 0
    r = 0
    for i in range(len(s)):
        if s[i] == 'R':
            r += 1
    # print(len(s))
    # print(str(w) + " " + str(r))

    res_min = r
    for i in range(1, len(s) + 1):
        if s[i-1] == 'R':
            r -= 1
        elif s[i-1] == 'W':
            w += 1

        res_min = min(res_min, max(w, r))

    print(res_min)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9504
# PyPy3 test

import itertools

H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cnt = t.count(1)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        if t[h]:
            lst.append(S[h + 1])
        else:
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
    L = len(lst)
    sum_lst = [0] * L
    for w in range(W):
        if max(lst[i][w] for i in range(L)) > K:
            break
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        if max(tmp) > K:
            cnt += 1
            sum_lst = [lst[i][w] for i in range(L)]
        else:
            sum_lst = tmp
    else:
        ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 50268
n = int(input())
a = list(map(int,input().split()))
a[0] -= 1
for i in range(1, n):
    if a[i - 1] <= a[i] - 1:
        a[i] -= 1
if all(a[i] <= a[i + 1] for i in range(n - 1)):
    print('Yes')
else:
    print('No')

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

#define MAX_V (2000)

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v] = true;
  for(int i=0;i<(int)G[v].size();i++){
    int u = G[v][i], w = match[u];
    if( w < 0 ||  !used[w] && dfs(w) ){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching(){
  int res  = 0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<V;v++){
    if( match[v] < 0 ) {
      memset(used,0,sizeof(used));
      if( dfs(v) ) {
	res++;
      }
    }
  }
  return res;
}

int M,N;
int B[555],R[555];

int main(){

  while(cin >> M >> N && (M||N) ){
    for(int i=0;i<M;i++) cin >> B[i];
    for(int i=0;i<N;i++) cin >> R[i];

    V = M + N;

    for(int i=0;i<M;i++){
      for(int j=0;j<N;j++){
	if( __gcd(B[i],R[j]) != 1 ){
	  add_edge(i,j+M);
	}
      }
    }

    cout << bipartite_matching() << endl;
    for(int i=0;i<V;i++) G[i].clear();

  }

}

Measured memory_bytes: 3380
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N, M, R;
  while(cin >> N >> M, N > 0){
	cin >> R;
	int t[1001], n[1001], m[1001], s[1001];
	REP(i,R)
	  cin >> t[i] >> n[i] >> m[i] >> s[i];
	
	int Q; cin >> Q;
	REP(q,Q){
	  int st, et, x; cin >> st >> et >> x;
	  int sum = 0, ans = 0, prv = 0;
	  REP(i,R){
		if(m[i] == x){
		  if(s[i]){
			if(sum == 0) prv = t[i];
			++sum;
		  }
		  else{
			--sum;
			if(sum == 0){
			  if(st <= t[i] && t[i] <= et)
				ans += t[i] - max(st, prv);
			  if(t[i] > et && prv <= et)
				ans += et - max(st, prv);
			}
		  }
		}
	  }
	  cout << ans << endl;
	}
  }
  return 0;
}

Measured memory_bytes: 1204
class UnionFindTree:
    def __init__(self, size: int):
        self.__size = size
        self.__data = [-1] * (size + 1)

    def unite(self, u: int, v: int):
        x, y = self.find(u), self.find(v)
        if x == y:
            return

        self.__data[x] += self.__data[y]
        self.__data[y] = x

    def find(self, u: int) -> int:
        if self.__data[u] < 0:
            return u
        self.__data[u] = self.find(self.__data[u])
        return self.__data[u]

    def same(self, u: int, v: int) -> bool:
        return self.find(u) == self.find(v)


def equals(N: int, M: int, P: list, XY: list) -> int:
    """例えば xi <-> xj かつ xj <-> xk の場合、xi、xj、xk は
    どの二つも交換可能である。したがって、交換可能なインデックス
    の集合をつくり、そのインデックスの集合とインデックスに対応し
    た P の部分集合との一致する部分が正しい位置における数値群と
    なる。
    """
    uft = UnionFindTree(N)
    for x, y in XY:
        uft.unite(x, y)

    return sum(1 for i, p in enumerate(P) if uft.same(i+1, p))


if __name__ == "__main__":
    M = 0
    N, M = map(int, input().split())
    P = [int(s) for s in input().split()]
    XY = [tuple(int(s) for s in input().split()) for _ in range(M)]
    ans = equals(N, M, P, XY)
    print(ans)


Measured memory_bytes: 21472
import numpy as np

N = int(input())

if N < 105:
    print(0)
elif N == 105:
    print(1)
else:
    num = np.array([i for i in range(105, N+1, 2)])
    count = np.zeros(len(num))

    for i in range(1, N+1):
        mask = num % i == 0
        count += mask

    print(list(count).count(8))

Measured memory_bytes: 21668
x=input()
l=len(x)
t=0
for i in range(l):
    if x[i]=="T":
        t+=1
    else:
        break
s=0
for j in range(l):
    if x[l-1-j]=="S":
        s+=1
    else:
        break
x=x[t:l-s]
l=len(x)
if l==0:
    print(s+t)
else:
    ans=l
    bef=x[0]
    cha=1
    for k in range(1,l):
        if bef=="S":
            if x[k]=="S":
                cha+=1
            else:
                bef=x[k]
                cha-=1
                ans-=2
        else:
            if x[k]=="S":
                bef=x[k]
                cha+=1
            else:
                if cha>0:
                    cha-=1
                    ans-=2
    print(ans+s+t)


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y,z;cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
}

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

bool IsPrime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i == 0){return false;}
	}
	return true;
}

int main(void) {
	int count =0;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int p;
		cin >> p;
		if(IsPrime(p)){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3096