akhauriyash/Code-Regression huggingface dataset:
from collections import deque

def bfs(s):
    q = deque()
    q.append(s)
    dist[s] = 0
    while q:
        p = q.popleft()
        if dist[a[p]] == -1:
            dist[a[p]] = dist[p] + 1
            q.append(a[p])
        else:
            return [dist[a[p]], dist[p] + 1]

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0, 0)
dist = [-1] * (n + 1)
x = bfs(1)
y = [0, x[1] - x[0], k - x[0]]
l = y[2] % y[1]
ans = l + x[0]
if k <= x[0]:
    ans = k
for i in range(1, n + 1):
    if dist[i] == ans:
        print(i)
        exit()

Measured memory_bytes: 103632
#include<cstdio>
int main(void){
 int n;
  char a[100];
  for(int i=0;i<100;i++)a[i]=0;
  scanf("%d",&n);
  scanf("%s",a);
  if(n<3200)printf("red\n");
  else printf("%s\n",a);
  return 0;  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)(N);i++)
#define p(s) cout<<(s)<<endl;
using namespace std;

const int ctinf=1e5;
double dp[10000][21][21];//num,prev,now = minr

int dot_pro(int x1,int x2,int x3,int y1, int y2, int y3){
	return (x2-x1)*(x3-x2)+(y2-y1)*(y3-y2);
}

double ctcos(int x1,int x2,int x3,int y1,int y2,int y3){
	return dot_pro(x1,x2,x3,y1,y2,y3)/(hypot(x2-x1,y2-y1)*hypot(x3-x2,y3-y2));
}
int main(){
	int n;
	double r,theta;
	cin>>n>>r>>theta;
	REP(i,0,r) REP(j,0,21) REP(k,0,21) dp[i][j][k]=ctinf;
	double co=cos(theta*M_PI/180.0);
	int x[20],y[20];
	REP(i,0,n) cin>>x[i]>>y[i];
	int ans=0;
	vector<int> ok[21][21];
	double len[21][21];
	REP(prev,0,n) REP(now,prev+1,n) len[prev][now]=len[now][prev]=hypot(x[now]-x[prev],y[now]-y[prev]);
	REP(prev,0,n) REP(now,0,n){
		if(prev==now) continue;
		REP(next,0,n){
			if(prev==next||now==next) continue;
			if(ctcos(x[prev],x[now],x[next],y[prev],y[now],y[next])<co)continue;
			ok[prev][now].push_back(next);

		}
	}

	REP(i,1,n) {
		if(len[0][i]<r){
			dp[1][0][i]=len[0][i];
			ans=1;
		}
	}
	REP(i,2,r){
		REP(prev,0,n){
			REP(now,0,n){
				if(prev==now) continue;
				for(auto next:ok[prev][now]){
					if(dp[i-1][prev][now]+len[now][next]<=r){
						dp[i][now][next]=min(dp[i][now][next],dp[i-1][prev][now]+len[now][next]);
						ans=i;
					}
				}
			}
		}
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 37936
#include<stdio.h>
int main() {
  int w, n, m, i, j, a[30][2];
  scanf("%d", &w);
  scanf("%d", &n);
  for (i = 0; i < n; i ++) scanf("%d,%d", &a[i][0], &a[i][1]);
  for (i = 1; i <= w; i ++) {
    m = i;
    for (j = n - 1; j > -1; j --) {
      if (m == a[j][0]) {
	m = a[j][1];
      } else if (m == a[j][1]) {
	m = a[j][0];
      }
    }
    printf("%d\n", m);
  }
  return 0;
}

Measured memory_bytes: 592
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	double a[2],b[2],c[2],angle,dy,r[2];
	for(;;){
		if(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&a[0],&a[1],&b[0],&b[1],&c[0],&c[1]) == EOF){break;}
		if(a[0] == b[0]){r[0] = 2*a[0]-c[0];r[1] = c[1];}
		else{
			angle = (a[1]-b[1])/(a[0]-b[0]);
			dy = a[1]-angle*a[0];
			a[1]-=dy;
			b[1]-=dy;
			c[1]-=dy;
			r[0] = c[0]*(1-angle*angle)/(angle*angle+1)+c[1]*(2*angle)/(angle*angle+1);
			r[1] = c[1]*(angle*angle-1)/(angle*angle+1)+c[0]*(2*angle)/(angle*angle+1);
			r[1]+=dy;
		}
		printf("%.6lf %.6lf\n",r[0],r[1]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>

int main() {
    int a, b;

    scanf("%d %d", &a, &b);

    if(a % 2 != 0 && b % 2 != 0) {
        printf("%s", "Yes\n");
    } else {
        printf("%s", "No\n");
    }
    return 0;
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 2; i < s.size(); i += 2) {
		if (s.substr(0, (s.size() - i) / 2) == s.substr((s.size() - i) / 2, (s.size() - i) / 2)) {
			cout << s.size() - i << endl;
			return 0;
		}
	}
}

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

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

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

typedef long long ll;
const int mod = 1e9 + 7;

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

    string S;
    cin >> S;

    vector<int> nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == (char)('0' + now)) cnt++;
        else {
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    nums.push_back(cnt);

    if (nums.size() % 2 == 0) nums.push_back(0);

    // rep(i, nums.size()) {
    //     cout << nums[i] << endl;
    // }
    // return 0;

    int add = 2 * K + 1;
    int ans = 0;
    for (int i = 0; i < nums.size(); i += 2) {
        int tmp = 0;
        int left = i;
        int right = min(i + add, (int)nums.size());
        for (int j = left; j < right; j++) {
            tmp += nums[j];
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1020
h, n = gets.split.map(&:to_i)

INF = 10 ** 9;

dp = [INF] * (h + 20000)
dp[0] = 0

n.times do
  a, b = gets.split.map(&:to_i)

  h.times do |ch|
    next if dp[ch] == INF
    nh = ch + a
    dp[nh] = dp[ch] + b if dp[nh] > dp[ch] + b
  end
end

puts dp.drop(h).min


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

unsigned long Combination(long n,long r)
{
    unsigned long i = 1;
    long k = r > n - r ? n - r : r, count;
    if(k < 0) return 0;
    for(count = 1; count <= k; ++count)
    {
        i *= n - count + 1;
        i /= count;
    }
    return i;
}

int main(){
  long n;
  long double tmp;
  long a[105000];
  long max = 0;
  long maxX = 0;
  long maxY = 0;

  cin >> n;
  for(long i=0;i<n;++i){
    cin >> a[i];
  }
  sort(a,a+n);
  long minabs = a[n-1];
  for(long i=0;i<n-1;++i){
    tmp = abs((a[n-1]/2)-a[i]);
    if(tmp <= minabs){
      minabs = tmp;
      maxX = a[n-1];
      maxY = a[i];
    }
  }
  cout << maxX << " " << maxY << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);
const int MAX_LEN = 3010;

int main() {
  string s, t; cin >> s >> t;
  int ls = (int)s.length(), lt = (int)t.length();

  vvi dp(MAX_LEN+1, vi(MAX_LEN+1, 0));
  rep(i, ls) {
    rep(j, lt) {
      if (s[i] == t[j]) {
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }
  }

  string ans = "";
  int p = ls, q = lt;
  while (p>0 && q>0) {
    if (s[p-1] == t[q-1]) {
      ans += s[p-1];
      p--; q--;
    } else {
      (dp[p][q-1] > dp[p-1][q]) ? q-- : p--;
    }
  }
  reverse(all(ans));
  cout << ans << endl;
  return 0;
}


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

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

  string S;
  cin >> S;

  if (S.size() <= K) {
    cout << S;
  } else {
    for (int i = 0; i < K; i++)
    {
      cout << S.at(i);
    }
    cout << "...";
  }
}

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

int main()
{
    int a, b, x;
    cin >> a >> b;
    x = a*b;
    if (x%2 == 0) {
        cout << "Even" << endl;
    }
    else {
        cout << "Odd" << endl;
    }
}


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

using namespace std;

int main() {
    int32_t n;

    while (cin >> n, n != 0) {
        vector<double> s(n);

        for (int32_t i = 0; i < n; i++) {
            cin >> s[i];
        }

        double m = accumulate(s.begin(), s.end(), 0.0) / n;
        double v = accumulate(s.begin(), s.end(), 0.0, [m](double sum, double s_i) {
            return sum + (s_i - m) * (s_i - m);
        }) / n;

        cout << fixed << setprecision(5) << sqrt(v) << endl;
    }

    return 0;
}

Measured memory_bytes: 3276
import numpy as np
x1,y1,x2,y2 = map(int, input().split())
ori = np.array([x1,y1])
vec = np.array([x2-x1,y2-y1])
def rotation(pi,a,b):
    rot = np.matrix([[np.cos(pi),-np.sin(pi)],
                     [np.sin(pi),np.cos(pi)]])
    return np.dot(rot, [a,b])

p3 = np.sqrt(2)*(rotation(np.pi/4, vec[0], vec[1])) + ori
p4 = rotation(np.pi/2, vec[0], vec[1]) + ori

x3 = int(round(p3[0,0]))
y3 = int(round(p3[0,1]))
x4 = int(round(p4[0,0]))
y4 = int(round(p4[0,1]))

print(x3,y3,x4,y4)

Measured memory_bytes: 12656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin>>N;
	if(N/100==7||N%10==7||(N/10)%10==7) cout<<"Yes";
	else cout<<"No";
}


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

double calcStdDev(vector<double>);

int main()
{
    int n;

    while (1)
    {
        cin >> n;
        if (n == 0)
            break;

        vector<double> s(n, 0.0);
        for (int i = 0; i < n; i++)
        {
            cin >> s[i];
        }

        cout << fixed << setprecision(cout.precision()) << calcStdDev(s) << endl;
    }

    return 0;
}

double calcStdDev(vector<double> s)
{
    double mean = 0.0;
    for (long unsigned int i = 0; i < s.size(); i++)
    {
        mean += s[i];
    }
    mean /= (double)s.size();

    double res = 0.0;
    for (long unsigned int i = 0; i < s.size(); i++)
    {
        res += pow(abs(s[i] - mean), 2);
    }
    res /= (double)s.size();

    return sqrt(res);
}


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

const int maxn = 200 + 5;
int n, l;
int score[maxn];

void Print()
{
	cout << "show1" << endl;
	for(int i = 0; i < n; i++)
	{
		printf("%d ", score[i]);
	}
	printf("\n");
}

int solve()
{
	int sum = 0;
	int Min = 1000;
	for(int i = 0; i < n; i++)
	{
		score[i] = l+(i+1)-1;
		sum += score[i];
		if(abs(score[i]) < abs(Min)) Min = score[i];
		score[i] = abs(score[i]);
	}
	//sort(score, score+n);
	return sum - Min;
}	

int main()
{
	scanf("%d %d", &n, &l);
	printf("%d\n", solve());
	//Print();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
//#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

const double PI = acos(-1);
const double EPS = 1e-9;

const int MX = 1<<20;
const int MM = 1000000007;

struct Tree{
	struct node{
		pii v;
		int add;
	};
	node t[MX*2];
	void update(int l, int r, int v, int n = 1, int s = 0, int e = MX-1){
		if( r < s || e < l ) return;
		else if( l <= s && e <= r ){
			t[n].v.first += v;
			t[n].add += v;
		}
		else{
			int m = (s+e) / 2;
			update(l, r, v, n*2, s, m);
			update(l, r, v, n*2+1, m+1, e);
			t[n].v = min(t[n*2].v, t[n*2+1].v);
			t[n].v.first += t[n].add;
		}
	}
	pii read(int l, int r, int n = 1, int s = 0, int e = MX-1){
		if( r < s || e < l ) return pii(1e9, -1);
		else if( l <= s && e <= r ) return t[n].v;
		else{
			int m = (s+e) / 2;
			pii res = min(read(l, r, n*2, s, m), read(l, r, n*2+1, m+1, e));
			res.first += t[n].add;
			return res;
		}
	}
} tree;

int A[MX];

int main()
{
	int N;
	vector<int> X;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", A+i), X.push_back(A[i]);
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());

	for(int i = 0; i < X.size(); i++) tree.t[i+MX].v = pii(X[i], i);
	for(int i = MX-1; i >= 1; i--) tree.t[i].v = min(tree.t[i*2].v, tree.t[i*2+1].v);

	ll ans = 0;
	for(int i = 1; i <= N; i++){
		int v = A[i], w = lower_bound(X.begin(), X.end(), A[i]) - X.begin();
		pii t = tree.read(w, X.size()-1);
		ans += t.first - v;
		tree.update(0, t.second-1, 1);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 26488
#include <bits/stdc++.h>
#include <queue>
#define ll long long int
using namespace std;


const int N = 3e5 + 10;
ll n, k, arr[N], a;
bool ok;

int main(int argc, char** argv) {
    cin >> n;
    a = n;
    while (a>0) {
        if (a % 7 == 0) {
            cout << "Yes";
            return 0;
        }
        a -= 4;
    }
    a = n;
    while (a>0) {
        if (a % 4 == 0) {
            cout << "Yes";
            return 0;
        }
        a -=7;
    }
    cout<<"No";
    return 0;
}

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


#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ll long long


string gera_r( char ini, int len ) {
	string r = "";
	r += ini;
	for ( int i = 1; i < len; i++ ) {
		r += r[i - 1] == '0' ? '1' : '0';
	}

	return r;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    string s;
    int trocas = 0;
    cin >> s;
    int n = s.size();
    string r = gera_r(s[0], n);

    for ( int i = 0; i < n; i++ ) {
    	if ( s[i] != r[i] ) {
    		trocas++;
    	}
    }

    cout << trocas << endl;

    return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    string s; cin >> s;
    vector<int> ans;

    int p = n;
    while(p > 0){
        int a = p;
        loop(i,1,m+1){
            if(p-i == 0){ a = 0; break; }
            if(s[p-i] == '0') a = p-i;
        }
        if(a == p){ cout << -1 << endl; return 0; }
        ans.push_back(p-a); p = a;
    }

    int ss = ans.size();
    rep(i,ss) cout << ans[ss-1-i] << " ";
    return 0;
}


Measured memory_bytes: 3904
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	
	int Alice=0,Bob=0;
	for(int i=n-1;i>=0;i--){
		if(i%2==0)
			Alice+=a[i];
		else
			Bob+=a[i];
	}
	int ans=Alice-Bob;
	if(ans>0)
		cout<<ans<<endl;
	else
		cout<<ans*-1<<endl;		
	
}

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

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	string s;
	cin >> s;
	bool isC = false;
	bool isF = false;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'C') isC = true;
		if (isC) {
			if (s[i] == 'F') isF = true;
		}
	}

	if (isF) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int bubble(int *,int);



int main()
{
  int *num;
  int kazu,i,count;

  scanf("%d",&kazu);
 
  num = (int *)malloc(kazu * sizeof(int));

  for(i=0;i<kazu;i++) scanf("%d",&num[i]);

  count = bubble(&num[0],kazu);

  for(i=0;i<kazu;i++)
    {
      printf("%d",num[i]);

      if(i != kazu - 1) printf(" ");
    }

  printf("\n");

  printf("%d\n",count);


  free(num);
  return 0;
}

int bubble(int *num,int kazu)
{
  int i,j,count=0,temp;

  for(i=0;i<kazu-1;i++)
    {
      for(j=kazu-1;j>=i+1;j--)
	{
	  if(num[j]<num[j-1])
	    {
	      temp = num[j];
	      num[j] = num[j-1];
	      num[j-1]= temp;
	      count++;
	    }
	}
    }
  return count;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define mod 1000000007

lli n,w;
lli dp[101][100001];
lli wg[101],val[101];

int main(){
    cin>>n>>w;
    lli i,j,l;
    for(i=0;i<n;i++) cin>>wg[i]>>val[i];
    for(i=0;i<101;i++){
        for(j=0;j<100001;j++){
            dp[i][j]=1000000000000;
        }
    }
    dp[0][val[0]]=wg[0];
    dp[0][0]=0;

    for(i=1;i<n;i++){
        for(j=0;j<100001;j++){
            if(j-val[i]>=0) {
                if(dp[i-1][j-val[i]] + wg[i] <= w)
                dp[i][j]=min(dp[i-1][j-val[i]] + wg[i] , dp[i-1][j]);
                else dp[i][j] = dp[i-1][j];
            }
            else dp[i][j]=dp[i-1][j];
        }
    }

    lli ans=0;
    for(i=100000;i>=0;i--){
        if(dp[n-1][i]<=w && dp[n-1][i]!=0){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 79104
n, k, c = map(int, input().split())
s = input()
i = 0
l = [0] * (n + 1)
r = [0] * (n + 1)
while i < n:
    if s[i] == 'o':
        l[i + 1] = 1
        i += c
    i += 1
i = n - 1
while i >= 0:
    if s[i] == 'o':
        r[i] = 1
        i -= c
    i -= 1
for i in range(n):
    l[i + 1] += l[i]
    r[n - i - 1] += r[n - i]
for i in range(n):
    if l[i] + r[i + 1] < k:
        print(i + 1)


Measured memory_bytes: 51148
while True:
    N, R = map(int, raw_input().split())
    if N == R == 0:
        break
    A = range(N, 0, -1)
    for i in xrange(R):
        p, c = map(int, raw_input().split())
        A = A[p-1:p+c-1] + A[:p-1] + A[p+c-1:]
    print A[0]

Measured memory_bytes: 6424
#include <stdio.h>

int main() {
	int l, r, d;
	scanf("%d %d %d", &l, &r, &d);

	int cnt = 0;
	for(int i = l; i <= r; i++) {
		if(i % d == 0) cnt++;
	}

	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 1684
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //Read the question silly billy
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt()%500;
		int A = I.nextInt();
		O.pln(A>=N?"Yes":"No");
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25588
s=list(input())
k=int(input())
for i in range(len(s)):
    if s[i]=="a":
        continue
    if k>=ord("z")-ord(s[i])+1:
        k-=(ord("z")-ord(s[i])+1)
        s[i]="a"

if k>0:
    k%=26
    s[-1]=chr(ord(s[-1])+k)

print("".join(s))


Measured memory_bytes: 4152
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int a[55],sum=0;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            sum+=a[i]*a[j];
        }
    }
    printf("%d",sum);
    return 0;
}

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

using namespace std;

int n,k;
vector<int> V;

void solve(){
  int ans = V.back()-V[0];
  
  vector<int> Dis;

  for(int i = 1; i < V.size(); i++)
    Dis.push_back(V[i]-V[i-1]);
    
  sort(Dis.begin(),Dis.end());
  reverse(Dis.begin(),Dis.end());

  
 for(int i = 0; i < min(k-1,(int)Dis.size()); i++)
   ans -= Dis[i];
 

  cout << ans << endl;
}
int main(){
  int N;
  cin >> N;
  while(N--){
    V.clear();
    cin >> n >> k;
    for(int i = 0; i < n; i++){
      int in; cin >> in;
      V.push_back(in);
    }
    solve();
  }
  return 0;
}

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

int main() {
	long long int N, count = 0, a[100000], b[100000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = N - 1; i >= 0; i--) {
		count += b[i] - (a[i] + count + b[i] - 1) % b[i] - 1;
	}
	cout << count << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdlib>
#include <iomanip>

using namespace std;
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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100100];

int main() 
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}

	for (int i = 0; i < 100010; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;

	for (int i = 1; i < N; i++) {
		// とりあえず代入しといて後で修正する。
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) {
			chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		}
	}

	cout << dp[N - 1] << endl;
}


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

#define PI acos(-1.0)
#define INF 1e18
#define inf 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)

const int N=12345;
typedef long long LL;
int a[N],b[N];

int main(){
    FAST_IO;
    int n;
    LL c1=0,c2=0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    for(int i=1;i<=n;i++){
        if(a[i]>b[i]) c1=c1+a[i]-b[i];
        else if(a[i]<b[i]){
            if((b[i]-a[i])%2==0) c2=c2+(b[i]-a[i])/2;
            else {c1++;c2=c2+(b[i]-a[i]+1)/2;}
        }
    }
    //次数
    if(c2>=c1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    int a[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &a[i]);
    }
    int min = 100;
    for (int i = 0; i < N; i++){
        int count = 0;
        while(a[i] % 2 == 0){
            count += 1;
            a[i] /= 2;
        }
        if(count < min){
            min = count;
        }   
    }
    printf("%d\n", min);
    return 0; 
}

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

int main(){
	int n,m;
	while(cin >> n >> m)
	{
		if(n==0) break;
		vector<priority_queue<int> > q(m);
		
		for(int i=0;i<n;i++)
		{
			int d,v;
			cin >> d >> v;
			d--;
			q[d].push(v);
		}
		int ans = 0;
		for(int i=0;i<m;i++)
		{
			ans += q[i].top();
		}
		cout << ans << endl;
	}
}


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

using namespace std;

struct bal {
	int x, y;
	bal(int x, int y): x(x), y(y){}
	bool operator < (const bal& other) const {
		return x + other.y > other.x + y;
	}
};

int main() {
	ios_base :: sync_with_stdio(false);
	int n = 0;
	cin >> n;
	int ab = 0;
	int gb = 0;
	vector < pair < int, int > > p1, n1;
	vector < bal > v;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int mn = 0;
		int cb = 0;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == ')') {
				cb--;
			} else {
				cb++;
			}
			mn = min(mn, cb);
		}
		ab += cb;
		if (mn == 0)
			gb += cb;
		else {
			if (cb > 0) {
				p1.push_back(make_pair(-mn, cb));
			}
			if (cb == 0) {
				n1.push_back(make_pair(-mn, cb));
			}
			if (cb < 0) {
				v.push_back(bal(-mn, -cb));
			}
		}
	}
	if (ab != 0) {
		cout << "No";
		return 0;
	}
	sort(p1.begin(), p1.end());
	for (const auto & x: p1) {
		if (gb < x.first) {
			cout << "No";
			return 0;
		}
		gb += x.second;
	}
	sort(n1.begin(), n1.end());
	for (const auto & x: n1) {
		if (gb < x.first) {
			cout << "No";
			return 0;
		}
		gb += x.second;
	}
	sort(v.begin(), v.end());
	for (const auto& x: v) {
		if (gb < x.x) {
			cout << "No";
			return 0;
		}
		gb -= x.y;
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 7784
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{
 int i,l,n;
 cin >> n >> l;
 string a[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 sort(a,a+n);
 for(i=0;i<n;i++)
 cout << a[i];
 return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int n;
struct P { double x, y;};
vector<P> p;

double dist(P a, P b) {
  double dx = a.x-b.x;
  double dy = a.y-b.y;
  return sqrt(dx*dx + dy*dy);
}
double f(double x, double y) {
  double res = 0;
  rep(i,n) {
    res = max(res, dist((P){x,y}, p[i]));
  }
  return res;
}

double g(double x) {
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (f(x,c1) > f(x,c2)) l = c1; else r = c2;
  }
  return f(x,l);
}

int main () {
  cin >> n;
  p = vector<P>(n);
  rep(i,n) cin >> p[i].x >> p[i].y;

  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (g(c1) > g(c2)) l = c1; else r = c2;
  }

  double ans = g(l);
  printf("%.10f\n", ans);
  return 0;
}

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

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n  = 0, m = 0, c = 0;
    cin >> n >> m >> c;

    vector<ll> b(m, 0);
    for(int i = 0; i < m; i++) cin >> b[i];

    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ll sum = 0;
        for(int j = 0; j < m; j++) {
            int temp;
            cin >> temp;
            sum += b[j] * temp;
        }
        if(sum + c > 0) ans++;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
	int n, ans = 0;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		int tmp;
		scanf("%d", &tmp);
		ans += tmp-1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	int a[6];
	for (int i = 0; i < 6; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < 5; i++) {
		if (a[i] - a[0] > a[5]) {
			cout << ":(" << endl;

			return 0;
		}
	}
	cout << "Yay!" << endl;

	return 0;
}

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

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int res[n];
  res[0]=0;
  for(int i=1;i<n;i++){
    int mini = res[i-1]+abs(a[i]-a[i-1]);
    if(i-2>=0){
       mini = min(mini,res[i-2]+abs(a[i]-a[i-2]));
    }
    res[i]=mini;
  }
  cout<<res[n-1]<<"\n";
  return 0;
}
      
  

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
static const int MAX = 200000;
using namespace std;
int main()
{
    int R[MAX], n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> R[i];
    int maxv = -9999999999;
    int minv = R[0];
    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    cout << maxv << endl;
    return 0;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  int ans = 1;
  rep(i,n){
    ans = min(ans*2,ans+k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	int n ,m,k;
	cin>>n>>m>>k;
	int c=0;
	int left[n+1]={0},right[m+1]={0};
	int rptr=m;
	for(int i=1;i<=n;i++){
		cin>>left[i];
		left[i]+=left[i-1];
	}
	for(int j=1;j<=m;j++){
		cin>>right[j];
		right[j]+=right[j-1];
	}
	int ans=0;
	for(int i=0;i<=n;i++){

		int d=k-left[i];
		if(d<0)
            break;
		while(rptr>0 && right[rptr]>d){
			rptr--;
		}
		ans=max(ans,i+rptr);
	}
	cout<<ans;

}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).resize(unique(all(V))-(V).begin())
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef vector<int> vim;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int MX = 100005;

int A, B, M, ans=1e9;
int a[MX], b[MX], x[MX], y[MX], c[MX];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin>>A>>B>>M;
	for (int i=1; i<=A; i++) cin>>a[i];
	for (int i=1; i<=B; i++) cin>>b[i];
	for (int i=1; i<=M; i++) cin>>x[i]>>y[i]>>c[i], ans=min(ans, a[x[i]]+b[y[i]]-c[i]);
	sort(a+1, a+1+A); sort(b+1, b+1+B);
	cout<<min(ans, a[1]+b[1])<<'\n';
	return 0;
}

Measured memory_bytes: 2176
def main():
    n = int(input())
    P = list(map(int, input().split()))
    ans = 0
    next = 0
    on = False
    for i in range(n):
        if P[i] == i + 1:
            ans += 1
            if on:
                next += 1
                on = False
            else:
                on = True
        else:
            on = False
    print(ans - next)

if __name__ == '__main__':
    main()


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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

typedef pair<int,int> pii;
typedef vector<int> vi;

char g[50][51];

const int dx[] = {-1,0,1,1,1,0,-1,-1};
const int dy[] = {1,1,1,0,-1,-1,-1,0};

void solve(){
    int h,w;
    cin>>h>>w;
    auto valid = [=](int i, int j){
        return i>=0 && i<h && j>=0 && j<w;
    };
    REP(i,h)
        cin>>g[i];
    REP(i,h)
        REP(j,w){
            if(g[i][j] != '.') continue;
            g[i][j] = '0';
            REP(k,8)
                if(valid(i+dx[k],j+dy[k])
                   && g[i+dx[k]][j+dy[k]] == '#')
                    g[i][j]++;
        }
    REP(i,h)
        cout<<g[i]<<'\n';
}

int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    set<long long int>S;
    int n;
    long p1,p2,p3;
    cin>>n;
    for(int i=0;i<n;i++){
        vector<long long int>p(3);
        for(int i=0;i<3;i++)cin>>p[i];
        sort(p.begin(),p.end());
        S.insert(p[0]+p[1]*1001+p[2]*1001*1001);
    }
    cout<<n-S.size()<<endl;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>

using namespace std;

const int Maxn = 100010;
int n , m;
int f[Maxn];
bool b[Maxn];

int main() {
	
	scanf("%d%d",&n,&m);
	for(register int i=1; i<=n; i++)
		f[i] = 1;
	b[1] = true;
	for(register int x,y; m--; ) {
		scanf("%d%d",&x,&y);
		f[x] -- , f[y] ++;
		if(!b[x])	b[x] = false;
		else {
			b[y] = true;
			if(!f[x])	b[x] = false;
		}
	}
	
	register int ans = 0;
	for(register int i=1; i<=n; i++)
		if(b[i])
			ans ++;
	printf("%d\n",ans);
	
	return 0;
	
}

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

int main()
{
    long long a,n;
    cin >> a >> n;
    for(int i=0;i<n;i++){
            long long num;
        cin >> num;
        a-=num;
    }
    if(a<=0){
        cout << "Yes\n";
    }
    else
        cout << "No\n";
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int ans = (n + 110) / 111 * 111;
    cout << ans << endl;
    return 0;
}

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

const int x[4] = {0, 1, 0, -1}, y[4] = {1, 0, -1, 0};

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    rep(i, H) rep(j, W) cin >> s[i][j];

    bool res = true;
    rep(i, H) rep(j, W) {
        bool temp = false;
        if(s[i][j] == '#') {
            rep(m, 4) {
                if(i+y[m]>=0&&i+y[m]<H&&j+x[m]>=0&&j+x[m]<W)
                    if(s[i+y[m]][j+x[m]] == '#') temp = true;
            }
        }
        if(s[i][j]=='#' && !temp) {
            res = false;
            break;
        }
    }

    if(res) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
b=1
for a in range(1,N+1):
    b*=a
numbers=[2]
for c in range(3,N+1):
    count=0
    for d in numbers:
        if not c%d==0:
            count+=1
        else:
            pass
    if count==len(numbers):
        numbers.append(c)
    else:
        pass
answers=[]
while b>1:
    for e in numbers:
        kazu=0
        while b%e==0:
            b=b//e
            kazu+=1
        answers.append(kazu)
kotae=1
for f in answers:
    kotae*=(f+1)
print(kotae%(10**9+7))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S >> T;
    int ans = 0;
    rep(i, 0, 3) if(S[i] == T[i]) ans++;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

int a[N];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	LL ans=0;
	for(int i=2;i<=n;i++){
		if(a[i]<a[i-1]) ans+=(LL)a[i-1]-a[i],a[i]=a[i-1];
	}
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    ll ans = 0;
    for(i = 0;i < n;++i){
        ll a;
        cin >> a;
        if(i%2 == 0 && a%2 == 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

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

	int x;
	cin >> x;
	cout << 1 - x;
}

Measured memory_bytes: 3612
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
score = [0] * m
for i in range(n):
    A = LI_()
    for a in A[1:]:
        score[a] += 1

print(score.count(n))

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(void){
    int N,i,sum=0,ians,index,power=0;
    double ans;
    cin>>N;
    vector<int> data(N);
    rep(i,0,N)cin>>data.at(i);
    rep(i,0,N)sum+=data.at(i);
    ans=(double)sum/N;
    ians=sum/N;
    if(((ians+1)-ans)>=(ans-ians))index=ians;
    else index=ians+1;
    rep(i,0,N)power+=pow((data.at(i)-index),2);
    cout<<power<<endl;
}

Measured memory_bytes: 256
# 「先手と後手が最善を尽くす」とあるけど、実は最善も最悪も存在しない
# 先手と後手がどのような手を出しても、勝者は変わらない……と、予想
# 以上より、両者とも「取れる最初の文字を取り去る」

str = gets.chomp

c = 0
fl = 0
while true do
	
	0.upto(str.length - 3) do |i|
		if str[i] != str[i+2]
			str.slice!(i+1)
			c += 1
#			puts str
			break
		end
		
		if i == str.length - 3
			# 文字を削除できない
			fl = 1
			break
		end
	end
	
	break if fl == 1
	break if str.length == 2
end

if c % 2 == 0
	puts "Second"
else
	puts "First"
end


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()

void uniqueVector(vector< int >& vec) {
	sort(allof(vec));
	vec.erase(unique(allof(vec)), vec.end());
}

void solve(
	int n, int m,
	const vector< int >& tx, const vector< int >& ty,
	const vector< int >& lft, const vector< int >& bot,
	const vector< int >& rgt, const vector< int >& top
	) {
	vector< int > x_sort = tx, y_sort = ty;
	uniqueVector(x_sort);
	uniqueVector(y_sort);
	
	vector< vector< int > > imos(n + 1, vector< int >(n + 1, 0));
	for_(i,0,n) {
		int x = lower_bound(allof(x_sort), tx[i]) - x_sort.begin() + 1;
		int y = lower_bound(allof(y_sort), ty[i]) - y_sort.begin() + 1;
		++imos[y][x];
	}
	
	for_(y,0,n+1) for_(x,0,n) imos[y][x + 1] += imos[y][x];
	for_(x,0,n+1) for_(y,0,n) imos[y + 1][x] += imos[y][x];
	
	for_(i,0,m) {
		int lx = lower_bound(allof(x_sort), lft[i]) - x_sort.begin() + 1;
		int by = lower_bound(allof(y_sort), bot[i]) - y_sort.begin() + 1;
		int rx = upper_bound(allof(x_sort), rgt[i]) - x_sort.begin();
		int ty = upper_bound(allof(y_sort), top[i]) - y_sort.begin();
		
		printf("%d\n", imos[ty][rx] - imos[ty][lx - 1] - imos[by - 1][rx] + imos[by - 1][lx - 1]);
	}
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	
	vector< int > tx(n), ty(n);
	for_(i,0,n) scanf("%d %d", &tx[i], &ty[i]);
	
	vector< int > lft(m), bot(m), rgt(m), top(m);
	for_(i,0,m) scanf("%d %d %d %d", &lft[i], &bot[i], &rgt[i], &top[i]);
	
	solve(n, m, tx, ty, lft, bot, rgt, top);
}

Measured memory_bytes: 108692
A, B, K = map(int, input().split())
if (B - A + 1) > K * 2:
    for i in range(A, A+K):
        print(i)
    for i in range(B - K+1, B+1):
        print(i)
else:
    for i in range(A, B+1):
        print(i)

Measured memory_bytes: 3060
#!/usr/bin/env python3
import numpy as np
import math
import re

n = input()
n = re.split(" ",n)
n = list(map(int,n))
N = n[0]
X = n[1]

list = []
for i in range(N):
    m = int(input())
    list.append(m)
mi = min(list)
su = sum(list)
d = (X - su) // mi

print(d + N)

Measured memory_bytes: 12392
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//数値の入力
		int x = sc.nextInt();
		int y = sc.nextInt();
        
      	if((x == 4 || x ==6 || x== 9 || x ==11) && (y == 4 || y ==6 || y== 9 || y ==11)) {
        	System.out.println("Yes");
	    }else if((x == 1 || x ==3 || x== 5 || x ==7 || x ==8 || x ==10 || x ==12) &&
        		(y == 1 || y ==3 || y== 5 || y ==7 || y ==8 || y ==10 || y ==12)){
  			System.out.println("Yes");
          //考慮忘れ。修正
		}else if(x == 2 && y ==2){
         	System.out.println("Yes");
        }else{
          	System.out.println("No");
        }
}
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a*n,b) <<endl;
    return 0;
}

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


def solve(A: int, B: int):
    if A >= 13:
        print(B)
    elif A <= 5:
        print(0)
    else:
        print(B//2)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060