akhauriyash/Code-Regression huggingface dataset:
import heapq

def divisor(i):
    s = []
    for j in range(1, int(i ** (1 / 2)) + 1):
        if i % j == 0:
            s.append(i // j)
            s.append(j)
    return sorted(set(s))

n, k = map(int, input().split())
a = list(map(int, input().split()))
suma = sum(a)
s = divisor(suma)
for i in range(1, len(s) + 1):
    x = s[-i]
    y = suma // x
    h = []
    heapq.heapify(h)
    for j in a:
        y -= j // x
        heapq.heappush(h, -(j % x))
    cnt = 0
    for _ in range(y):
        cnt += (heapq.heappop(h) % x)
    if cnt <= k:
        print(x)
        exit()

Measured memory_bytes: 9432
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll N;
string S;

vector<vector<ll>> dp(3010, vector<ll>(3010, -1));
//後ろx個がまだ決めてない、かつ末尾がy番目に入る
ll F(ll x,ll y){
    if(dp[x][y]!=-1)return dp[x][y];
    if(x==0)return dp[x][y]=1;
    if(x==N){
        ll ans=0;
        for(ll i=1;i<=N;i++)ans+=F(N-1,i);
        return dp[x][y]=ans%MOD;
    }
    ll ret=0;
    if(S[N-x-1]=='<'){
        if(y<x)ret+=F(x-1,y)+F(x,y+1);
        else if(y==x)ret+=F(x-1,x);
    }
    else {
        if(y>=3)ret+=F(x,y-1)+F(x-1,y-1);
        else if(y==2)ret+=F(x-1,1);
    }
    return dp[x][y]=ret%MOD;
}


int main(){
    cin >> N;
    cin >> S;
    
    print(F(N,0))

    return 0;
}


Measured memory_bytes: 74544
function Main(input){
  var list = input.split(" ");
  var cnt = 0;
  for(var i=1;i<=list[0];i++){
    var sum = 0;
    for(var j of (i+"").split("")){
      sum+=Number(j);
    }
    if(list[1]<=sum&&sum<=list[2])cnt+=i;
  }
  console.log(cnt);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11424
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull  unsigned long long
#define ll long long int
#define ull unsigned long long 
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector< long long>v(n);
#define mii unordered_map<ll,ll>
double pi = 2*acos(0.0);
#define mod 1000000007

//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}

 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
       while(tst--)
       {
         ll n,m,k;
         cin>>n>>m>>k;
         vector<long long>va;  bool flag=true;va.push_back(0);
         for(int i=1;i<=n;i++)
         {
                   ll u;
                   cin>>u;
                   va.push_back(va.back()+u);
         }
         vector<long long>vb;vb.push_back(0);
         for(int j=1;j<=m;j++)
         {
                   ll v;
                   cin>>v;
                   vb.push_back(vb.back()+v);
         }
         ll j=m;ll ans=0;
         for(int i=0;i<=n;i++)
         {
                   while(j>0&&va[i]+vb[j]>k)
                   {
                             j--;
                   }
                  if(va[i]+vb[j]<=k)
                  {
                            ans=max(ans,i+j);
                  }
         }
         cout<<ans<<endl;
       }
 }


Measured memory_bytes: 7908
# ユニオンファインド
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
input = lambda: sys.stdin.readline().rstrip()

n,m= map(int, input().split())
a= [list(map(int, input().split())) for i in range(m)]

UF=UnionFind(n)

for i,j in a:
    i-=1
    j-=1
    UF.union(i,j)

ans=0
for i in range(n):
    ans=max(ans,UF.size(i))
print(ans)

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

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

using namespace std;

int main(void){
  int N, D;
  int64_t *x, *y, buf;
  int cnt = 0;
  double distance;

  scanf("%d %d", &N, &D);

  x = new int64_t[N];
  y = new int64_t[N];

  rep(i, N){
    cin >> x[i] >> y[i];
    buf = x[i]*x[i] + y[i]*y[i];
    distance = sqrt(double(buf));
    if(distance <= D){
      cnt++;
    }
  }

  cout << cnt;


  return 0;
}

Measured memory_bytes: 6832
import math

def main():
  N = int(input())
  A = list(map(int, input().split()))
  A.sort()
  MAX = A[-1]
  dp = [True] * MAX
  c = [0] * MAX
  ans = 0

  for a in A:
    i = a - 1
    c[i] += 1

    if((not dp[i]) and c[i] > 1):
      continue

    e = a * 2    
    while e <= MAX:
      dp[e-1] = False
      e += a
      
  for v in A:
    i = v - 1
    if dp[i] and c[i] == 1:
      ans += 1

  print(ans)

if __name__ == "__main__":
  main()

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

int main(){
  string s;
  cin >> s;
  bool flag = true;
  for(int i=0;i<s.size();++i){
    if(i%2 == 0 && s[i] == 'L' || i%2 == 1 && s[i] == 'R'){
      flag = false;
      break;
    }
  }
  
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}


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

#define MAX_N 100001

vector<pair<int, int64_t> > adj[MAX_N];
int64_t dis[MAX_N];

void dfs(int v, int64_t d)
{
    if (dis[v]) {
        if (dis[v] != d) {
            printf("No\n");
            exit(0);
        }
        return;
    }
    dis[v] = d;
    for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i].first;
        int64_t w = adj[v][i].second;
        dfs(u, d + w);
    }
}

int main(void)
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);
        adj[l].push_back(make_pair(r, d));
        adj[r].push_back(make_pair(l, -d));
    }
    for (int i = 1; i <= n; i++)
        if (!dis[i]) dfs(i, 0xffff);
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 16512
#include <iostream>
#include <cstdio>
#define N 55
using namespace std;

int n, m, ans, c[N];
bool v[N][N];

void f(int p) {
	int i;
	if (c[p] != 1) return;
	for (i = 1; !v[p][i]; i++);
	v[p][i] = v[i][p] = 0;
	c[i]--, c[p]--;
	ans++;
	f(i);
}

int main()
{
	int i, t1, t2;
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		scanf("%d %d", &t1, &t2);
		c[t1]++; c[t2]++;
		v[t1][t2] = v[t2][t1] = 1;
	}
	for (i = 1; i <= n; i++) f(i);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define ll long long
ll dp[20];
int main()
{
    ll n , cnt = 0 , p = 10;
    cin >> n;
    if(n&1){
        cout << 0;
        return 0;
    }
    while(p <= n) {
        cnt += n / p;
        p *= 5;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
const double pi=acos(-1.0);
int main(){
	double a,b,h,m,t,tm,th,q;
	cin>>a>>b>>h>>m;
	tm=m*6.0;th=h*30.0+(m/2.0);
	if(abs(tm-th)>180) t=360-abs(tm-th);
	else t=abs(tm-th);
	q=sqrt(a*a+b*b-2*a*b*cos(t*pi/180));
	cout<<fixed<<setprecision(20)<<q<<endl;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int k, a, b;
    cin >> k >> a >> b;

    if(b - b % k >= a)
        cout << "OK";
    else cout << "NG";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(ll i = (ll)j;i <= (ll)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<ll,ll> pi;
const ll MAXN = (ll)1e6+7;
const ll MOD = (ll)1e9+7;

ll a[MAXN],n;

void check() {
    ll ans = 0;
    rep(i,1,n)rep(j,i+1,n) ans += a[i]^a[j];
    ans %= 1000000007;
    cout << ans << endl;
}

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

    cin >> n;

    rep(i,1,n) cin >> a[i];
    ll eve,odd,ans=0;
    rep(j,0,59) {
        eve = 0,odd = 0;
        rep(i,1,n) {
            if ((a[i]>>j)&1) odd++;
            else           eve++;
        }
        ll tmpAns = odd*eve%MOD*((1LL<<j)%MOD)%MOD;
        ans += tmpAns;
        debug(tmpAns);
        ans %= MOD;
    }
    //check();

    cout << ans << endl;
    //debug(9375105820%MOD);
}

/*
6 7 8 9
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820
*/


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		String A=scan.next();
		String B=scan.next();
		String C=scan.next();
		int ac=0,bc=0,cc=0,c=0;
		for(;;) {
			if(c==0) {
				ac++;
				if(ac==A.length()+1) {
					System.out.println("A");
					break;
				}
				switch(A.charAt(ac-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				}
			}if(c==1) {
				bc++;
				if(bc==B.length()+1) {
					System.out.println("B");
					break;
				}
				switch(B.charAt(bc-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				}
			}if(c==2) {
				cc++;
				if(cc==C.length()+1) {
					System.out.println("C");
					break;
				}
				switch(C.charAt(cc-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				}
			}
		}
	}
}


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

int main()
{
  int N;cin>>N;
  int count=0;
  for (int i=0;i<N;i++)
  {
    int l,r;cin>>l>>r;
    count += r-l+1;
  }
  cout<<count<<endl;
}

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

#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define init(x) memset(x,0,sizeof(x))
#define abs(x) (x<0?(-x):x)
#define lcm(x,y) ((1ll)*x*y)/__gcd(x,y)
#define maxv(v) *max_element(v.begin(),v.end())
#define minv(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define tie() ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);




void solve(){
     int n,w;
     cin>>n>>w;
     vector<pair<int,int>> items;

     for(int i=0;i<n;i++){
        int wet,val;
        cin>>wet>>val;
        items.pb({wet,val});
     }

     vector<ll> dp(w+1,0);
     dp[0]=0;
    for(auto p : items){
        //cout<< "when item of weight --------------> "<< p.ff<<endl ;
     for(int i=w;i>=0;i--){


            if(p.ff<=i){
                dp[i]=max(dp[i],dp[i-p.ff]+p.ss);
                //cout<<"dp["<<i<<"]="<<dp[i]<<endl;
            }
        }
     }
     cout<<dp[w];
}
int32_t main()
{
    //clock_t st = clock();
    tie();
    int t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
   // clog<<(long double)((clock() - st)/CLOCKS_PER_SEC)<<endl;
    return 0;
}


Measured memory_bytes: 3972
#include <iostream> 
#include <vector>
#include <array> 

using namespace std; 

int main() { 
  int N; 
  cin>> N;
  vector <array<int, 3> >v(N); 
  for(int i = 0 ;i < N ; i++){ 
    cin >> v[i][0] >> v[i][1] >> v[i][2]; 
  } 

  for (int i = 1 ; i < N; i++){ 
    for (int  j = 0 ; j < 3; j++){
      int q = -1; 
      for (int k = 0 ; k < 3;  k++){
        if (j == k)  continue; 
        q =  max(q,  v[i][j] + v[i-1][k]); 
      }
      v[i][j] = q; 
    }
  //  cout << "i:: "  << i << " " << v[i][0] << " " << v[i][1]  << " " << v[i][2] << endl;
  }

  int ans = max(v[N-1][0], max(v[N-1][1], v[N-1][2]));
  cout << ans << endl; 
  return 0; 
} 


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#include<bitset>

using namespace std;



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

int n=s.length();

for(int i=0;i<n;i++){
  if(i%2==0 ){
    if(!(s[i]=='R' || s[i]=='U' || s[i]=='D')) {cout<<"No"<<endl; return 0;}
  }
  else{
    if(!(s[i]=='L' || s[i]=='U' || s[i]=='D')){cout<<"No"<<endl; return 0;}
  }}
cout<<"Yes"<<endl;

}


Measured memory_bytes: 384
from sys import stdin
data = stdin.readline().strip()

a = int(data.split()[0])
b = int(data.split()[1])
c = int(data.split()[2])
k = int(data.split()[3])

if k <= a:
    print(k)
else:
    if k <= a + b:
        print(a)
    else:
        print(2*a+b-k)

Measured memory_bytes: 9080
h,w=map(int,input().split())
s=[input()+"." if i!=h else "."*(w+1) for i in range(h+1)]
def count_8(i,j):
    global h,w,s
    cnt=str((s[i-1][j-1]=="#")+(s[i-1][j+1]=="#")+(s[i+1][j-1]=="#")+(s[i+1][j+1]=="#") \
        +(s[i-1][j]=="#")+(s[i][j-1]=="#")+(s[i+1][j]=="#")+(s[i][j+1]=="#"))
    return cnt
for i in range(h):
    s_sub=""
    for j in range(w):
        if s[i][j]=="#":
            s_sub+="#"
        else:
            s_sub+=count_8(i,j)
    print(s_sub)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	bool a;
	bool b;
} P;
int main( void ){
	int N, T; scanf("%d%d", &N, &T);
	ll sum = 0;
	int time_prev; scanf("%d", &time_prev);
	rep(i,1,N){
		int time; scanf("%d", &time);
		if (time - time_prev >= T)
			sum += T;
		else
			sum += time - time_prev;
		time_prev = time;
	}
	cout << sum +T << endl;

}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define forr(i,a,n) for (int i = (a); i < (n); ++i)
#define rforr(i,a,n) for (int i = (a); i > (n); --i)
#define ALL(x) (x.begin(),x.end())
#define LEN(X) ((int)(X).size())
#define CASET int _T; cin >> _T; forr(caset,0,_T)
 
int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
 
    int n; cin >> n; n-=1;
    vi b(n); forr(i,0,n) cin >> b[i];
    vi a(n+1); a[0] = b[0];
    forr(i,0,n) {
        if (a[i]>b[i]) a[i] = b[i];
        a[i+1]=b[i];
    }
    cout << accumulate(a.begin(), a.end(), 0) << '\n';

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

//flagを用いたバブルソート
int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    for(int i=0; flag; i++){
        flag = 0;
        for(int j=N-1; j>=i+1; j--){
            if(A[j] < A[j-1]){
                //隣接要素を交換する
                swap(A[j], A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int A[100],N,sw;
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];

    sw = bubbleSort(A, N);

    for( int i=0; i<N; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
void solve()
{
	ll n;
	cin>>n;
	string s,t;
	cin>>s;
	cin>>t;
	for(ll i=0;i<n;i++)
	cout<<s[i]<<t[i];
}
int main()
{
	solve();
}

Measured memory_bytes: 256
//0030 Sum of Integers
//0 ©ç 9 Ì©çÙÈé n ÂÌðæèoµÄvª s ÆÈégÝí¹ÌðoÍµÄI¹·évOðì¬µÄ­¾³¢B
//n ÂÌÍ¨Ì¨Ì 0 ©ç 9 ÜÅÆµAPÂÌgÝí¹É¯¶Íg¦Ü¹ñ

#include<iostream>
using namespace std;

static const int N = 10;
int n, s;
bool isUse[N];

int Calc(int d, int useNum, int sum)
{
	if(sum > s || useNum > n || useNum+(N-d) < n)
		return 0;
	if(d == 10)
	{
		if(sum == s)
			return 1;
		else
			return 0;
	}
	
	int result = 0;
	isUse[d] = true;
	result += Calc(d+1, useNum+1, sum+d);
	isUse[d] = false;
	result += Calc(d+1, useNum, sum);

	return result;
}

int main(void)
{
	while(cin >> n >> s, n)
	{
		fill(isUse, isUse+N, false);
		cout << Calc(0, 0, 0) << endl;
	}
	return  0;
}

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

int a[502][502];

int main(void){
    int Y,X;
    cin >> Y >> X;
    rep1(y,Y)rep1(x,X){
        cin >> a[y][x];
    }
    vector<vector<int>> res;
    rep1(y,Y)rep1(x,X){
        if (y==Y && x==X) continue;
        if (a[y][x]&1) {
            if (x < X) {
                a[y][x+1] ++;
                res.push_back(vector<int>{y,x,y,x+1});
            } else {
                a[y+1][x] ++;
                res.push_back(vector<int>{y,x,y+1,x});
            }
        }
    }
    cout<<res.size()<<endl;
    rep(i,res.size()){
        rep(j,4){
            cout<<res[i][j]<<(j<3 ? " " : "\n");
        }
    }

    return 0;
}


Measured memory_bytes: 10032
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [u64; n],
        b: [u64; n],
    }

    let mut ans = 0;
    let mut surplus = 0;
    let mut shortage = 0;
    let mut surplus_per_i = vec![];
    for i in 0..n {
        if a[i] > b[i] {
            surplus += a[i] - b[i];
            surplus_per_i.push(a[i] - b[i]);
        } else if a[i] < b[i] {
            shortage += b[i] - a[i];
            ans += 1;
        }
    }
    if surplus < shortage {
        println!("-1");
        return;
    }

    let mut current = 0;
    surplus_per_i.sort();
    surplus_per_i.reverse();
    let mut idx = 0;
    while current < shortage {
        ans += 1;
        current += surplus_per_i[idx];
        idx += 1;
    }
    println!("{}", ans);
}


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

#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	ll n,w;
	cin>>n>>w;
	ll a[n+1][w+1];
	ll value[n+1];
	ll weight[n+1];
	for(ll i=1;i<=n;i++) cin>>weight[i]>>value[i];
	for(ll i=0;i<=n;i++) a[i][0]=0;
	for(ll i=0;i<=w;i++) a[0][i]=0;
	ll ima,nema;
	for(ll i=1;i<=w;i++)
	{
		for(ll j=1;j<=n;j++)
		{
			nema=a[j-1][i];
			if(weight[j]<=i)
			{
				ima=a[j-1][i-weight[j]]+value[j];
			}
			else
			{
				ima=-1;
			}
			a[j][i]=max(ima,nema);
		}
	}
	cout<<a[n][w]<<endl;
	
 	return 0;
}

Measured memory_bytes: 79232
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=1e9;
const int magic=348;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n,k,m;
LL dp[348][348],sum[348][348],c[348][348];

int main ()
{
	int i,j,p;
	n=getint();k=getint();m=getint();
	c[0][0]=1;
	for (i=1;i<=n;i++)
	{
		c[i][0]=c[i][i]=1;
		for (j=1;j<=i-1;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%m;
	}
	for (i=0;i<=k;i++) dp[1][i]=1,sum[1][i]=k-i+1;
	for (i=2;i<=n+1;i++)
		for (j=k;j>=0;j--)
		{
			dp[i][j]=0;
			for (p=1;p<=i-1;p++)
				dp[i][j]=(dp[i][j]+((dp[i-p][j]*sum[p][j+1])%m*c[i-2][p-1])%m)%m;
			sum[i][j]=(sum[i][j+1]+dp[i][j])%m;
		}
	printf("%lld\n",dp[n+1][0]);
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <fstream>
#include <stdlib.h>
#include <ctime>
using namespace std;
typedef long long ll;
int n=0;
string s;
ll a[26];
ll p=1e9+7;
int main(){
    //ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);
    cin>>n>>s;
    for(int i=0;i<n;i++){
        a[s[i]-'a']++;
    }
    ll ans=1;
    for(int i=0;i<26;i++){
        ans*=a[i]+1;
        ans%=p;
    }
    ans--;
    ans+=p;
    ans%=p;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 512
import heapq
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
A = map(int, input().split())
A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)

for _ in range(m):
    max_price = -heapq.heappop(A) // 2
    heapq.heappush(A, -max_price)

total = -sum(A)
print(total)


Measured memory_bytes: 14204
A,B,C,X,Y = map(int,input().split())

cost = []
##AとBを独立して買う
cost.append(A*X + B*Y)
##X<Yのとき,ABピザを買う
cost.append(2*C*X+abs(X-Y)*B)
##X>Y
cost.append(2*C*Y+abs(X-Y)*A)
##あまりを作るケース
cost.append(2*C*max(X,Y))

print(min(cost))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	ll ans = 0LL;
	for(int i = 1; i <= n; ++i) {
		if( i % 3 != 0 && i % 5 != 0 ) ans += i;
	}		
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		List<String> klist = new ArrayList<String>();

		while (true) {
			String line = sc.nextLine();
			klist.add(line);
			if (line.equals("-")) {
				break;
			}
		}
		List<String> mozilist = new ArrayList<String>();
		List<Integer> kazulist = new ArrayList<Integer>();

		for (String string : klist) {
			if (string.matches("^[0-9]*$")) {
				kazulist.add(Integer.parseInt(string));
			} else {
				mozilist.add(string);
			}
		}

		int i = 0;
		int count = i;
		int nannkai = 0;
		for (String string : mozilist) {

			if (string.equals("-")) {
				break;
			}
			;
			for (int j = 1; j <= kazulist.get(i); j++) {

				StringBuilder r = new StringBuilder();
				r.append(string.substring( kazulist.get(j+i)));
				r.append(string.substring(0,kazulist.get(j+i)));
				string = r.toString();
				count++;
			}
			nannkai++;
			i = count+nannkai;
			System.out.println(string);
		}
	}
}

Measured memory_bytes: 26448
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int S = sc.nextInt();
		int W = sc.nextInt();
		if( W>=S ){
			System.out.println("unsafe");
		}else{
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 35736
#include <iostream>

using namespace std;

int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  int n=0;
  if(a<b) n+=a;
  else n+=b;
  if(c<d) n+=c;
  else n+=d;
  cout << n << endl;
  return 0;
}


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

int main(){
 
  string S,ans="";
  cin >> S;
  
  bool f = false;
  
  if (S == "zyxwvutsrqponmlkjihgfedcba") ans = "-1";
  else{
    if (S.length()<26){
      for(int i='a';i<'z'+1;i++){
      for(auto &v:S){
        if(i==v){
         break;
        }
        if (v==S[S.length()-1]){
          f = true;
          ans = S + (char)i;
        }
      } 
      if (f) break;
      }
      }else{
          int pos = -1;
          int min_str = 1 + 'z';
        for(int i=24;i>=0;i--){
            if(S[i] < S[i+1]){
                for(int j = i + 1;j<26;j++){
                 if(S[i] < S[j])min_str = min(min_str,(int)S[j]); 
                }
                pos = i;
                S[i] = (char)min_str;
                break;
            }
        }
        for(int i=0;i<pos+1;i++){
            ans += S[i];
        }
    }
    }  
  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
while 1 :
    x = input().split()
    n = int(x[0])
    m = int(x[1])
    if n == 0 and m == 0: break
    a = input().split()
    mx = -1
    for i in range(n-1):
        for j in range(i+1,n):
            tmp = int(a[i]) + int(a[j])
            if tmp > mx and tmp <= m: mx = tmp
    if mx == -1: print("NONE")
    else: print(mx)





Measured memory_bytes: 5624
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define X first
#define Y second
#define fw(i, start, end) for (ll i = start; i < end; ++i)
#define fe(i, start, end) for (ll i = start; i <= end; ++i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define endl "\n"
int main()
{
    FASTIO
    ll k;
    cin >> k;
    char s[200];
    cin >> s;
    ll l = strlen(s);
    if (l <= k)
        cout << s;
    else
    {
        fw(i, 0, k)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }

    return 0;
}

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

int main(void)
{
  int n, i;
  double sum = 0.0;
  double x;
  char u[10];
  
  scanf("%d", &n);
  
  for (i = 0; i < n; i++){
    scanf("%lf %s", &x, u);
    if (strcmp(u, "JPY") == 0){
      sum += x;
    } else {
      sum += (380000.0 * x);
    }
  }
  
  printf("%lf", sum);
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d)
{
  if(u==NIL) return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}
int setHeight(int u)
{
  int h1=0;
  int h2=0;
  if(T[u].left!=NIL) h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2 ? h1:h2);
}

int getSibling(int u)
{
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u)
{
  int deg;
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,getSibling(u));
  deg=0;
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
  if(T[u].parent==NIL){
    printf("root\n");
  }
  else if(T[u].left==NIL && T[u].right==NIL){
    printf("leaf\n");
  }
  else printf("internal node\n");
}

int main()
{
  int v,l,r,i,root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].parent=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL) T[l].parent=v;
    if(r!=NIL) T[r].parent=v;
  }
  for(i=0;i<n;i++) {
    if(T[i].parent==NIL) root=i;
  }
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define PUTS(x) cout << (x) << endl;

int main() {
    int h, w;
    cin >> h >> w;
    auto v = vector<vector<int>>(h, vector<int>(w));
    char c;
    rep(i, h) {
        rep(j, w) {
            cin >> c;
            if (c == '.') {
                if (j > 0) {
                    v[i][j] = v[i][j - 1] + 1;
                } else {
                    v[i][j] = 1;
                }
            } else {
                v[i][j] = 0;
            }
        }
        for (int j = w - 1; j >= 0; j--) {
            if (v[i][j] > 0 && j < w - 1 && v[i][j + 1] > 0) {
                v[i][j] = v[i][j + 1];
            }
        }
    }
    auto u = vector<vector<int>>(h, vector<int>(w));
    rep(j, w) {
        rep(i, h) {
            if (v[i][j] > 0) {
                if (i > 0) {
                    u[i][j] = u[i - 1][j] + 1;
                } else {
                    u[i][j] = 1;
                }
            } else {
                u[i][j] = 0;
            }
        }
        for (int i = h - 1; i >= 0; i--) {
            if (u[i][j] > 0 && i < h - 1 && u[i + 1][j] > 0) {
                u[i][j] = u[i + 1][j];
            }
        }
    }
    auto ans = 0;
    rep(i, h) {
        rep(j, w) {
            ans = max(ans, v[i][j] + u[i][j] - 1);
        }
    }
    PUTS(ans);
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

int N, Q;
string S;
vector<set<int>> st;
int main(int argc, char const *argv[])
{
  cin >> N >> S >> Q;
  st.assign(26, set<int>());
  REP(i, N) st[S[i] - 'a'].insert(i);
  REP(i, Q) {
    int ty; cin >> ty;
    if (ty == 1) {
      int j; cin >> j; j--;
      char c; cin >> c;

      st[S[j] - 'a'].erase(j);
      st[c - 'a'].insert(j);
      S[j] = c;
    } else {
      int l, r; cin >> l >> r; l--;
      int cnt = 0;
      REP(j, 26) {
        auto lower = st[j].lower_bound(l);
        cnt += lower != st[j].end() && *lower < r;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 24196
# time complexity: O(lg(max{a, b}))
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a // g * b // g * g


N, M = [int(elem) for elem in input().split()]
S = input()
T = input()

L = lcm(N, M)
m, n = L // N, L // M

for i in range(N):
    if i % n == 0:
        S_idx = i
        T_idx = m * i // n
        if S[S_idx] != T[T_idx]:
            print(-1)
            exit(0)

for i in range(M):
    if i % m == 0:
        S_idx = n * i // m
        T_idx = i
        if S[S_idx] != T[T_idx]:
            print(-1)
            exit(0)
else:
    print(L)


Measured memory_bytes: 3444
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
long long x[5100];
int C[5100][210];
int segtree[210][16384];
int query(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c)return 0;
	if(c<=a&&b<=d)return segtree[f][e];
	return max(query(a,(a+b)/2,c,d,e*2,f),query((a+b)/2+1,b,c,d,e*2+1,f));
}

int n;
int m;
long long ans[5100];
int tmp[210];
void solve(int a,int b,int c,int d){
	if(b<=a)return;
	int M=(a+b)/2;
	int lm=max(M,c);
	for(int i=0;i<m;i++){
		tmp[i]=query(0,8191,M,lm,1,i);
	}
	int at=c;
	long long best=-inf;
	for(int i=c;i<=d;i++){
		if(lm>i)continue;
		long long cur=x[M]-x[i];
		for(int j=0;j<m;j++)cur+=tmp[j];
		if(best<cur){
			best=cur;
			at=i;
		}
		if(i<d){
			for(int j=0;j<m;j++)tmp[j]=max(tmp[j],C[i+1][j]);
		}
	}
	ans[M]=best;
//	printf("%d: %d %lld\n",M,at,best);
	solve(a,M,c,at);
	solve(M+1,b,at,d);
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	n=a;m=b;
	for(int i=0;i<a-1;i++)scanf("%lld",x+i+1);
	for(int i=1;i<a;i++){
		x[i]+=x[i-1];
	}
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		scanf("%d",&C[i][j]);
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<a;j++)segtree[i][j+8192]=C[j][i];
		for(int j=8191;j>0;j--)segtree[i][j]=max(segtree[i][j*2],segtree[i][j*2+1]);
	}

	solve(0,n,0,n-1);
	long long ret=-inf;
	for(int i=0;i<a;i++)ret=max(ret,ans[i]);
		printf("%lld\n",ret);
}

Measured memory_bytes: 15616
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void C_task();

int main()
{
	C_task();
	fflush(stdout);
	return 0;
}

static void C_task()
{
	int N;
	get1int(N);

	auto Ai = new LLONG[N + 1];
	auto Bi = new LLONG[N];

	for (int i = 0; i <= N; i++) {
		get1int<LLONG>(Ai[i]);
	}
	for (int i = 0; i < N; i++) {
		get1int<LLONG>(Bi[i]);
	}

	LLONG defeat = 0;
	LLONG surplus = 0;
	for (int i = 0; i < N; i++) {
		if (Ai[i] >= surplus) {
			defeat += surplus;
			Ai[i] -= surplus;
		}
		else {
			defeat += Ai[i];
			Ai[i] = 0;
		}

		if (Ai[i] >= Bi[i]) {
			defeat += Bi[i];
			surplus = 0;
		}
		else {
			defeat += Ai[i];
			surplus = Bi[i] - Ai[i];
		}
	}

	if (Ai[N] >= surplus) {
		defeat += surplus;
	}
	else {
		defeat += Ai[N];
	}

	printf("%lld\n", defeat);

	delete[] Ai;
	delete[] Bi;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;


int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> ac(n);
    vi pe(n);
    int ac_cnt = 0;
    int pe_cnt = 0;
    rep(i, m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if (ac[p] == false){
            if (s == "AC"){
                ac[p] = true;
                ac_cnt++;
                pe_cnt += pe[p];
            }else{
                pe[p]++;
            }
        }
    }
    cout << ac_cnt << " " << pe_cnt << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int calc(int d) {
  if (d == 0) {
    return 1;
  } else {
    return calc(d % bitset<32>(d).count()) + 1;
  }
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> v1(n), v2(n);
  bitset<2 * (int) pow(10, 5)> b(s);
  int a = b.count(), a1 = a - 1, a2 = a + 1, b1 = 0, b2 = 0;
  v1[0] = 1, v2[0] = 1;
  if (b.test(0)) {
    b1 = 1, b2 = 1;
  }
  rep(i,n-1)
  {
    if (a > 1)
      v1[i + 1] = v1[i] * 2 % a1;
    v2[i + 1] = v2[i] * 2 % a2;
    if (b.test(i + 1)) {
      if (a > 1)
        b1 = (b1 + v1[i + 1]) % a1;
      b2 = (b2 + v2[i + 1]) % a2;
    }
  }
  for (int i = n - 1; i >= 0; i--)
    if (b.test(i))
      if (a > 1)
        cout << calc((b1 + a1 - v1[i]) % a1) << endl;
      else
        cout << 0 << endl;
    else
      cout << calc((b2 + a2 + v2[i]) % a2) << endl;
  return 0;
}


Measured memory_bytes: 5252
N=int(input())
a=input().split()
A=list(map(int,a))
#print(A)

tmp=0
spring_high=0
for i in range(N):
  if(i==0):
    tmp=A[0]
  if(tmp<=A[i]):
    #print(A[i])
    tmp=A[i]
  else:
   	spring_high+=tmp-A[i]

print(spring_high)

Measured memory_bytes: 32372
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# D - Line++

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

ndist = [0] * n  # ndist[k] = 距離kの頂点対の個数
for p in range(1, n):
    for q in range(p + 1, n + 1):
        # p,q間の距離
        d = min(q - p, abs(x - p) + 1 + abs(y - q))
        ndist[d] += 1

for k in range(1, n):
    print(ndist[k])


Measured memory_bytes: 46556
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include<vector>
#include<tuple>

using namespace std;
int main(){
  int a,b,c,count = 0;
  cin >> a >> b >> c;
  count = b / a;
  if(count >= c){
    cout << c;
    return 0;
  }
  cout << count << endl;

}


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#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 REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

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

int N;
vector<int> v[6];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  int orgN = N;
  int sum = 0;
  set<int> st;
  for (int i = 2; i <= 30000; i++) {
    if (i % 2 == 0 || i % 3 == 0) {
      if (N > 0) {
        sum += i;
        st.EMP(i);
        N--;
      } else {
        v[i % 6].PB(i);
      }
    }
  }
  if (orgN == 3) {
    cout << "2 5 63" << endl;
  } else if (orgN == 4) {
    cout << "2 5 20 63" << endl;
  } else if (orgN == 5) {
    cout << "2 3 4 6 9" << endl;
  } else {
    if (sum % 6 == 2) {
      st.erase(8);
      st.EMP(v[0][0]);
    } else if (sum % 6 == 3) {
      st.erase(9);
      st.EMP(v[0][0]);
    } else if (sum % 6 == 5) {
      st.erase(8);
      st.EMP(v[3][0]);
    }
    for (auto it = st.begin(); it != st.end(); it++) {
      if (it != st.begin()) cout << " ";
      cout << *it;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}

void solve(){
	string s,t;
	cin>>s>>t;
	int n=s.length(),m=t.length(),ans=m;
	for(int i=0;(i+m-1) <n;i++){
		int	cnt=0;
		for(int j=i,k=0;j<(i+m);k++,j++){
				if(s[j]!=t[k]){
					cnt++;
				}
			}
		ans=min(ans,cnt);
	}
	cout<<ans<<'\n';
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc=1;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	// cin>>tc;
    while(tc--)solve();
}


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

#define ll long long
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
#define vi vector < int >
#define pii pair < int, int >

const int N = 1e5 + 7;
const int INF = 1e18 + 7;

int a[107], dp[N];
int n, k;

main(){
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    for (int i = a[0]; i <= k; i++){
        for (int j = 0; j < n && i - a[j] >= 0; j++){
            if (dp[i - a[j]] == 0){
                dp[i] = 1;
                break;
            }
        }
    }
    if (dp[k])
        puts("First");
    else
        puts("Second");
}


Measured memory_bytes: 640
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let vec: Vec<&str> = s.trim().split(' ').collect();
	let nm: i32 = vec[0].parse().unwrap();
	let nd: i32 = vec[1].parse().unwrap();
	let c = if nm <= nd {
		nm
	} else {
		nm - 1
	};
	println!("{}", c);
}



Measured memory_bytes: 4352
import java.util.*;

public class Main{
        public static void main(String[] args){
                try(Scanner sc = new Scanner(System.in)){
                        int N = sc.nextInt();
                        long W = sc.nextLong();
                        long[] dp = new long[N*100+1];
                        for(int i = 0; i < N*100+1; i++){
                                dp[i] = Long.MAX_VALUE / 6;
                        }
                        dp[0] = 0;
                        for(int i = 0; i < N; i++){
                                int v = sc.nextInt();
                                long w = sc.nextLong();
                                for(int j = N * 100 - v; j >= 0; j--){
                                        if(dp[j] + w <= Math.min(dp[j+v], W)){
                                                dp[j+v] = dp[j] + w;
                                        }
                                }
                        }
                        int ans = 0;
                        for(int i = 0; i < N*100+1; i++){
                                if(dp[i] != Long.MAX_VALUE / 6){
                                        ans = i;
                                }
                        }
                        System.out.println(ans);
                }
        }
}

Measured memory_bytes: 27384
#include<bits/stdc++.h>
#define N 10009
using namespace std;
struct Q
{
    int a,b;
}p[100010];
int cmp(Q u,Q v)
{
    return u.a<v.a;
}
int main()
{
    int n;
    long long k;
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&p[i].a,&p[i].b);
    }
    sort(p,p+n,cmp);
    int i=0;
    while(k>p[i].b)
        k-=p[i++].b;
    printf("%d\n",p[i].a);
    return 0;
}



Measured memory_bytes: 1024