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

int main(void) {
	using namespace std;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	bool xrev = (x2 < x1);
	bool yrev = (y2 < y1);
	if(xrev) { x1 *= -1; x2 *= -1; }
	if(yrev) { y1 *= -1; y2 *= -1; }
	int N;
	cin >> N;
	vector<pair<int, int>> fountains;
	for(int i = 0; i < N; ++i) {
		int X, Y;
		cin >> X >> Y;
		if(xrev) X *= -1;
		if(yrev) Y *= -1;
		if(!(x1 <= X && X <= x2)) continue;
		if(!(y1 <= Y && Y <= y2)) continue;
		fountains.push_back(make_pair(X, Y));
	}
	if(fountains.size() == 0) {
		printf("%.15f\n", ((x2 - x1) + (y2 - y1)) * 100.0);
	} else {
		sort(fountains.begin(), fountains.end());
		if(x1 == x2 || y1 == y2) {
			printf("%.15f\n", ((x2 - x1) + (y2 - y1)) * 100.0 + (10.0 * M_PI - 20.0));
		} else {
			int len = fountains.size();
			const int INF = 1000000000;
			int dp[200000]; //dp[i] : 長さ(i + 1)の増加部分列における最終要素の最小値
			fill(dp, dp + len, INF);
			for(int i = 0; i < len; ++i) {
				*lower_bound(dp, dp + len, fountains[i].second) = fountains[i].second;
			}
			int m = lower_bound(dp, dp + len, INF) - dp;
			if(m == min(x2 - x1, y2 - y1) + 1) {
				printf("%.15f\n", ((x2 - x1) + (y2 - y1)) * 100.0 - (20.0 - 5.0 * M_PI) * (m - 1) + (10.0 * M_PI - 20.0));
			} else {
				printf("%.15f\n", ((x2 - x1) + (y2 - y1)) * 100.0 - (20.0 - 5.0 * M_PI) * m);
			}
		}
	}
	return 0;
}



Measured memory_bytes: 2800
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <map>
using namespace std;
const int MaxN = 1e5;
const int oo = 1 << 30;
const int mod = 1e9 + 7;
typedef long long LL;

int n;
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		int x = n * 800;
		int cnt = n / 15;
		int ans = x - cnt * 200;
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;

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

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


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

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();
    ll dp[n][13];
    for(int i = 0;i<=n-1;i++) {
        for(int j = 0;j<13;j++) dp[i][j]=0;
    }
    // 初期化
    if (s[n-1]=='?')
    {
        for(int i=0;i<=9;i++){
            dp[0][i]=1;
        }
    } else{
        int a = s[n-1]-'0';
        dp[0][a]=1;
    }
    int pow = 10;

    for(int i=1;i<n;i++){
        char x = s[n-i-1];
        int a = x - '0';
        if (x=='?')
        {
            // j 0~9
            for (int j = 0; j <=9 ; j++)
            {
                // 0~12
                for(int k=0;k<=12;k++)   {
                    int b = (j*pow + k) % 13;
                    dp[i][b]+=dp[i-1][k]%MOD;
                }
            }
        } else {
            for (int j = 0; j<=12;j++){
                int b = (j + a*pow) %13;
                dp[i][b] += dp[i-1][j]%MOD;
            }
        }
        pow *= 10;
        pow %= 13;
    }
    cout << dp[n-1][5]%MOD << endl;
    return 0;
}


Measured memory_bytes: 10704
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int n,u,v,m;
int sum[100010];

int main()
{
	memset(sum,0,sizeof(sum));
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= m;i++) {
		scanf("%d%d",&u,&v);
		sum[u-1]++; sum[v-1]++;
	}
	bool f = true;
	for(int i = 0;i < n;i++)
		if(sum[i] % 2 == 1) {f = false; break;}
	if(f) puts("YES"); else puts("NO");
	return 0;
}

Measured memory_bytes: 512
n, y = map(int, input().split())

def f():
  for a in range(n+1):
    for b in range(n+1-a):
      if a*10000 + b*5000 + (n-a-b)*1000 == y:
        ans = [a, b, n-a-b]
        return(' '.join(map(str, ans)))
  return '-1 -1 -1'

print(f())


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

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i=0; i<(ll)v.size(); i++){os << " [" << i << "]" << v[i];if (i%10 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string s;
  std::cin >> s;
  ll N = s.size();
  std::map<char, ll> mc;

  bool judge = true;

  if (s[0] != 'A') judge = false;
  for (ll i = 1; i < N; i++) {
    char c = s[i];
    mc[c]++;
    if (c < 'a' || c > 'z') {
      if (s[i] != 'C') judge = false;
      if ((i < 2 || i == N - 1) && s[i] == 'C') judge = false;
    }
  }


  judge = mc['C'] == 1 ? judge : false;

  if (judge) print("AC");
  else print("WA");

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    
    int d = n;
    while (n >= 10) {
        d = n % 10;
        n = d;
    }
    if (d == 2 || d == 4 || d == 5 || d == 7 || d == 9) cout << "hon" << endl;
    if (d == 0 || d == 1 || d == 6 || d == 8) cout << "pon" << endl;
    if (d == 3) cout << "bon" << endl;
}


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

int main(){
	int m,f,r;
	cin >> m >> f >> r;
	while(m>=0||f>=0||r>=0){
		if(m<0||f<0||m+f<30){
			cout << "F" << endl;
		}else if(m+f>=80){
			cout << "A" << endl;
		}else if(m+f>=65){
			cout << "B" << endl;
		}else if(m+f>=50||r>=50){
			cout << "C" << endl;
		}else{
			cout << "D" << endl;
		}
		cin >> m >> f >> r;
	}
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll n, k;
    cin>>n>>k;
    vl a(n);
    forr(i, n)
    {
    	cin>>a[i];
    }
    vector<bool> dp(k+1, false);
    forr1(i, k)
    {
    	forr(j, n)
    	{
    		if(a[j]>i)
    			break;
    		dp[i]=dp[i]||(!dp[i-a[j]]);
    	}
    }
    if(dp[k])
    	cout<<"First\n";
    else
    	cout<<"Second\n";
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

int main() {
  string a, b;
  cin >> a >> b;
  
  int m, n;
  m = a.size();
  n = b.size();
  bool same = true;
  if(m > n){
    cout << "GREATER" << endl;
    return 0;
  }
  if(m < n){
    cout << "LESS" << endl;
    return 0;
  }
  if(m == n){
    for(int i = 0; i < n; i++){
      if(a.at(i) < b.at(i)){
        cout << "LESS" << endl;
        return 0;
      }
      if(a.at(i) > b.at(i)){
        cout << "GREATER" << endl;
        return 0;
      }
    }
  }
  cout << "EQUAL" << endl;
}

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

int main() {
  int s,s1,s2,s3;
  cin >> s;
  s1 = s%10;
  s2 = (s-s1)%100;
  s3 = (s-s1-s2)%1000;
  cout << s1 + s2/10 + s3/100 << endl;
}

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

int main(void) {
    int N;cin>>N;
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int a;cin>>a;
        if (mp.find(a) != mp.end()) mp[a] += 1;
        else mp[a] = 1;
    }
    int ma = -1;
    for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
        int cur = 0;
        int index = it->first;
        if (mp.find(index-1) != mp.end()) cur += mp[index-1];
        if (mp.find(index+1) != mp.end()) cur += mp[index+1];
        cur += it->second;
        if (ma < cur) ma = cur;
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();

        boolean flag = false;
        for (int i = A; i <= B; i++) {
            if (i % K == 0) {
                flag = true;
                break;
            }
        }

        System.out.println(flag ? "OK" : "NG");


    }
}


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

int a[1000],sum[1000];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
   	for(int i=1;i<=n;i++)
   		sum[i]=sum[i-1]+a[i];

   	int ans=1e9;
   	for(int i=1;i<n;i++){
   		ans=min(ans,abs(sum[n]-sum[i]*2));
   	}
   	cout<<ans<<endl;
}



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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 100005;
int x[N], y[N], par[N], sz[N], vis[N];
vector <int> v[N];
set <int> st[N];

int find(int u) {
	if (u == par[u]) return u;
	return par[u] = find(par[u]);
}

void join(int u1, int u2) {
	u1 = find(u1);
	u2 = find(u2);
	if (u1 == u2) return;
	if (sz[u1] > sz[u2]) {
		swap(u1, u2);
	}
	sz[u2] += sz[u1];
	par[u1] = u2;
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
		scanf("%d %d", &x[i], &y[i]);
		v[x[i]].pb(y[i]);
	}
	for (int i = 1; i < N; i++) {
		par[i] = i;
		sz[i] = 1;
		for (int j : v[i]) {
			if (!vis[j]) {
				vis[j] = i;
			}
			join(i, vis[j]);
		}
	}
	for (int i = 0; i < n; i++) {
		st[find(x[i])].insert(y[i]);
	}
	ll res = 0;
	for (int i = 1; i < N; i++) {
		res += (ll)sz[i] * st[i].size();
	}
	printf("%lld", res - n);
    return 0;
}

/*
3
1 1
5 1
5 5
*/


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

typedef long long ll;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

const ll md = 1000000007LL;
ll dp[3][3][52];

enum{
	r,
	g,
	b
};

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

	char data[2][53];
	cin >> data[0];
	cin >> data[1];

	Rep(i, N){
		if(i == 0){
			if(data[0][0] == data[1][0]){
				dp[r][r][0] = 1;
				dp[g][g][0] = 1;
				dp[b][b][0] = 1;
			}else{
				dp[r][g][0] = 1;
				dp[g][b][0] = 1;
				dp[b][r][0] = 1;
				dp[r][b][0] = 1;
				dp[g][r][0] = 1;
				dp[b][g][0] = 1;
			}
		}else{
			if(data[0][i] == data[1][i]){
				dp[r][r][i] = dp[g][b][i-1] + dp[b][g][i-1] + dp[g][g][i-1] + dp[b][b][i-1];
				dp[g][g][i] = dp[r][b][i-1] + dp[b][r][i-1] + dp[b][b][i-1] + dp[r][r][i-1];
				dp[b][b][i] = dp[g][r][i-1] + dp[r][g][i-1] + dp[r][r][i-1] + dp[g][g][i-1];
			}else{
				if(data[0][i] == data[0][i - 1]){
					dp[r][g][i] = dp[r][g][i-1];
					dp[g][b][i] = dp[g][b][i-1];
					dp[b][r][i] = dp[b][r][i-1];
					dp[r][b][i] = dp[r][b][i-1];
					dp[g][r][i] = dp[g][r][i-1];
					dp[b][g][i] = dp[b][g][i-1];
				}else{
					dp[r][g][i] = dp[b][b][i-1] + dp[b][r][i-1] + dp[g][b][i-1] + dp[g][r][i-1];
					dp[g][b][i] = dp[r][r][i-1] + dp[r][g][i-1] + dp[b][r][i-1] + dp[b][g][i-1];
					dp[b][r][i] = dp[g][g][i-1] + dp[g][b][i-1] + dp[r][g][i-1] + dp[r][b][i-1];
					dp[r][b][i] = dp[g][g][i-1] + dp[g][r][i-1] + dp[b][g][i-1] + dp[b][r][i-1];
					dp[g][r][i] = dp[b][b][i-1] + dp[b][g][i-1] + dp[r][b][i-1] + dp[r][g][i-1];
					dp[b][g][i] = dp[r][r][i-1] + dp[r][b][i-1] + dp[g][r][i-1] + dp[g][b][i-1];
				}
			}
		}
		dp[r][r][i] %= md;
		dp[g][g][i] %= md;
		dp[b][b][i] %= md;
		dp[r][g][i] %= md;
		dp[g][b][i] %= md;
		dp[b][r][i] %= md;
		dp[r][b][i] %= md;
		dp[g][r][i] %= md;
		dp[b][g][i] %= md;
	}
	ll ans = 0;
	ans += dp[r][r][N - 1]; ans %= md;
	ans += dp[g][g][N - 1]; ans %= md;
	ans += dp[b][b][N - 1]; ans %= md;
	ans += dp[r][g][N - 1]; ans %= md;
	ans += dp[g][b][N - 1]; ans %= md;
	ans += dp[b][r][N - 1]; ans %= md;
	ans += dp[r][b][N - 1]; ans %= md;
	ans += dp[g][r][N - 1]; ans %= md;
	ans += dp[b][g][N - 1]; ans %= md;

#if 0
	PrintLn(dp[r][r][N - 1]);
	PrintLn(dp[g][g][N - 1]);
	PrintLn(dp[b][b][N - 1]);
	PrintLn(dp[r][g][N - 1]);
	PrintLn(dp[g][b][N - 1]);
	PrintLn(dp[b][r][N - 1]);
	PrintLn(dp[r][b][N - 1]);
	PrintLn(dp[g][r][N - 1]);
	PrintLn(dp[b][g][N - 1]);
#endif
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if b - a > k:
    print(":(")
elif c - a > k:
    print(":(")
elif d - a > k:
    print(":(")
elif e - a > k:
    print(":(")
elif c - b > k:
    print(":(")
elif d - b > k:
    print(":(")
elif e - b > k:
    print(":(")
elif d - c > k:
    print(":(")
elif e - c > k:
    print(":(")
elif e - d > k:
    print(":(")
else :
    print("Yay!")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

  public static void main(String[] args) throws IOException {
	  Scanner in = new Scanner(System.in);
	  int n = in.nextInt();
	  int m = in.nextInt();
	  HashMap<Integer,HashSet<Integer>> pass = new HashMap<Integer,HashSet<Integer>>();
	  int[] sign = new int[n];
	  sign[0]=0;
	  for(int i=0; i<m; i++) {
		  int a = in.nextInt();
		  int b = in.nextInt();
		  if(pass.containsKey(a)) {
			  pass.get(a).add(b);
		  }else {
			  HashSet<Integer> set = new HashSet<Integer>();
			  set.add(b);
			  pass.put(a,set);
		  }
		  if(pass.containsKey(b)) {
			  pass.get(b).add(a);			 
		  }else {
			  HashSet<Integer> set = new HashSet<Integer>();
			  set.add(a);
			  pass.put(b,set);
		  }
	  }
	  Queue<Integer> queue = new LinkedList<Integer>();
	  if(!pass.containsKey(1)) {
		  System.out.println("No");
		  System.exit(0);
	  }
	  Iterator<Integer> it = pass.get(1).iterator();
	  while(it.hasNext()) {
		  int i=it.next();
		  sign[i-1]=1;
		  queue.add(i);
		  
	  }
	  while(!queue.isEmpty()) {
		  int cur = queue.poll();
		  //System.out.println(cur);
		  Iterator<Integer> itr = pass.get(cur).iterator();
		  while(itr.hasNext()) {
			  int i = itr.next();
			  if(sign[i-1]==0) {
				  sign[i-1]=cur;
				  queue.add(i);
			  }
		  }
	  }
	  for(int i=1; i<n; i++) {
		  if(sign[i]==0) {
			  System.out.println("No");
			  System.exit(0);
		  }
	  }
	  System.out.println("Yes");
	  for(int i=1; i<n; i++) {
		  System.out.println(sign[i]);
	  }
	  
  }
}

Measured memory_bytes: 114864
n = int(input())
INF = 10**9
csum = 0
min_b = INF
for _ in range(n):
    a,b = map(int, input().split())
    csum += a
    if a > b:
        min_b = min(min_b,b)

if min_b == INF:
    print(0)
else:
    ans = csum-min_b
    print(ans)


# a_down_sum = 0
# top_diff = 0
# for _ in range(n):
#     a,b = map(int, input().split())
#     if a < b:
#         a_down_sum += a
#     else:
#         top_diff = max(top_diff,a-b)



Measured memory_bytes: 76520
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int iRes = 0;

		String str = sc.nextLine();
		String[] strArray = str.split("");

		for(String s : strArray) {
			if (s.equals("1")) {
				iRes++;
			}
		}
		System.out.println(iRes);

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 35548
#include <iostream>
using namespace std;
#define MAX 200000
long long A[MAX + 1];

int main(void){
    int N, K;
    
    cin >> N >> K;
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
        
        if(i >= K){
            if(A[i] > A[i - K]) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    
    return 0;
}

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

int main(){
  int N, K, l, i = 0, ans = 0;
  std::vector<int> p;
  
  while(std::cin>>l){
    if(i == 0){N = l;++i;}
    else if(i == 1){K = l;++i;}
    else p.push_back(l);
  }
  std::sort(p.begin(), p.end());
    
  for(int j = 0; j < K; ++j)ans += p[j];
  
  std::cout<<ans;
  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;
vector<int>a,b,p;
int N;
 
int main(void){
  int i,j,k,t,tmp;
  int c,c2;
  a.clear(); b.clear(); p.clear();
  cin>>N;
  a.pb(-1); b.pb(-1); p.pb(-1);
  for(i=1;i<=N;i++){
    cin>>tmp;
    p.pb(tmp);
    a.pb(i*20000);
    b.pb((N-i+1)*20000);
  }
 
  for(i=1;i<=N;i++){
    b[p[i]]+=i;
  }
 
  for(i=1;i<=N;i++){
    cout<<a[i]<<" ";
  }
  cout<<endl;
 
  for(i=1;i<=N;i++){
    cout<<b[i]<<" ";
  }
  cout<<endl;
 
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	vector<int> a(n),dp(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int sum = 0;
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	for(int i=2;i<n;++i){
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}

	cout<<dp[n-1]<<'\n';
	
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
 
int main(){
  	int n, m;
  	cin >> n >> m;
  	vector<pair<int, int>> A(n + 5);
  
  	rep(i, m){
      	int p;
      	string s;
      	cin >> p >> s;
      	
      	if(s == "AC") A[p].second = 1;
      	if(A[p].second == 1) continue;  
      	A[p].first++;
    }
  
  	int ac = 0;
  	int wa = 0;
  	for(int i = 1; i <= n; i++){
    	if(A[i].second)wa += A[i].first;
      	ac += A[i].second;
    }
  
  	cout << ac << " " << wa << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <float.h>
typedef long long ll;

int main()
{
    ll h, w;
    ll x, y;
    double area;
    int f = 0;

    scanf("%lld %lld %lld %lld", &w, &h, &x, &y);

    area = h * w / 2.0;

    if (x == w / 2 && w % 2 == 0 &&
        y == h / 2 && h % 2 == 0) {
        printf("%.*lf 1\n", DBL_DIG, area);
    }
    else {
        printf("%.*lf 0\n", DBL_DIG, area);
    }
    
    return 0;
}


Measured memory_bytes: 128
using System;

namespace Atcoder
{
    class ABC119_A
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            var now = DateTime.Parse(str);
            var dt1 = new DateTime(2019, 04, 30);
            if(now <= dt1)
            {
                Console.Write("Heisei");
            }
            else
            {
                Console.Write("TBD");
            }
        }
     }
}


Measured memory_bytes: 11740
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<climits>
#include<set>
#define ll long long
using namespace std;

int main() {
	ll n,m,sum=0;
	cin >> n >> m;
	vector<ll>x(m),sa(m-1,0);
	for (ll i = 0; i<m; i++) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	for (ll i = 0; i<m-1; i++) {
		sa[i] = abs(x[i] - x[i + 1]);
	}
	sort(sa.begin(), sa.end());
	for (ll i = 0; i < m-n; i++) {
		sum += sa[i];
	}
	cout << sum << endl;

	



}

Measured memory_bytes: 1792
#include <iostream>
 
using namespace std;
 
int main(){
 
    int i, j, n, q, count = 0;
    int dataS[10001],dataT[501];
    cin >> n;
        for (i = 0; i < n; i++){
        cin >> dataS[i];
    }
 
    cin >> q;
    for (i = 0; i < q; i++){
        cin >> dataT[i];
    }
            for (int j = 0; j < q; j++){
                for (int i = 0; i < n; i++){
                if (dataT[j] == dataS[i]){
                    count++;
                    break;
                }
        }
    }
        cout << count << "\n";
 
    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  
  cin>>s>>t;
  int n=s.size();
  if(s==t.substr(0,n))
  cout<<"Yes\n";
  else
  cout<<"No\n";
  
  
return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int i = 0;
  while(s[i]!='\0'){
    s[i]='x';
    i++;
  }

    cout << s << endl;
}



Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0

for i in range(min(a, x//500)+1):
  for j in range(min(b, (x-500*i)//100)+1):
    if x-500*i-100*j <= 50*c:
      ans+=1
print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
      	int k = sc.nextInt();
      	String s = sc.next();
      	s = s.substring(0,k-1) + s.substring(k-1,k).toLowerCase() + s.substring(k, n);
      	System.out.println(s);
    }
}

Measured memory_bytes: 39156
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
string s[214514];
signed main(){
	int n;
	cin>>n;
	int ans=0;
	rep(0,i,n){
		cin>>s[i];
		if(s[i]=="E869120")ans++;
	}
	c(ans)
}			


Measured memory_bytes: 5004
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    char a[2000],b[2000];
    scanf("%d%s%s",&n,a,b);
    for(int i=0;i<n;i++)
        printf("%c%c",a[i],b[i]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  //less_equal
             tree_order_statistics_node_update> oset; 
typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = 1e6 + 5;
const int MOD = 1e9 + 7;
const int MAXK = 2e3 + 2;
#define sz(x) (int)(x).size()
#define f first
#define s second





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

int k,x;
cin >> k >> x;
set<int> se;
--k;
if(x + k <= 1e6)
	 {
	 	for(int i = x ; i <= x + k ; i++)
	 		 se.insert(i);
	 }

if(x - k >= -1e6)
	 {
	 	for(int i = x - k ; i < x ; i++)
	 		 se.insert(i);
	 }

	 for(auto &k : se)
	 	 cout << k << ' ';
   
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int n;cin >> n;
  vector<vector<int>> a(n,vector<int>(n,-1));
  rep(i,n){
    int aaaa;
    cin >> aaaa;
    rep(j,aaaa){
      int k,s;cin >> k >> s;
      k--;
      a[i][k]=s;
    }
  }
  
  int pow2 = (1 << n);
  int cnt=0;
  rep(ai,pow2){
    bitset<15> ans(ai);
    bool answer=true;
    rep(i,n){
      bool ii;bool jj;
      ii=ans.test(i);
      rep(j,n){
        jj=ans.test(j);
        if(a[i][j]==-1)continue;
        if(ii&&jj&&a[i][j]==0)answer=false;
        if(ii&&!jj&&a[i][j]==1)answer=false;
        if(!answer)break;
      }
      if(!answer)break;
    }
    if(answer)cnt=max(cnt,ans.count());
  }
  cout << cnt << endl;
}

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

int main(){
  int n, p[20];
  int count=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  for(int i=0;i<n-2;i++){
    if((p[i]<p[i+1]&&p[i+1]<p[i+2])||(p[i]>p[i+1]&&p[i+1]>p[i+2])){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
# import
import numpy as np
import sys
sys.setrecursionlimit(10**6)

# input
H, W = map(int, input().split())

Mtmp = []
for _ in range(H):
    tmp = list(input())
    Mtmp.append(tmp)

M = np.array(Mtmp)
S = np.array([[0]*W]*H)

#print(M)

digtmp = np.array([[0, 1], [1, 0], [0, -1], [-1, 0]])

def dfs(i, j):
    global ngflag
    global searchflag
    if S[i, j] == 1:
        return
    S[i, j] = 1
    if M[i, j] == '.':
        return
    #print("i:{}, j:{}".format(i, j))
    searchflag = 1
    dig = digtmp + np.array([i, j])
    for d in dig:
        if 0 <= d[0] < H and 0 <= d[1] < W:
            if M[d[0], d[1]] == '#':
                ngflag = 0
                dfs(d[0], d[1])

searchflag = 0
ngflag = 1

while True:
    if 0 not in S:
        if M[target[0], target[1]] == '.':
            ngflag = 0
        break
    target = list(zip(*np.where(S == 0)))[0]
    #print("sf:{}, ng:{}".format(searchflag, ngflag))
    if M[target[0], target[1]] == '#':
        ngflag = 1
    dfs(target[0], target[1])
    if M[target[0], target[1]] == '#' and searchflag == 1 and ngflag == 1:
        break


#print("sf:{}, ng:{}".format(searchflag, ngflag))

if searchflag == 1 and ngflag == 0:
    ans = 'Yes'
elif searchflag == 1 and ngflag == 1:
    ans = 'No'
else:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 14880
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

vector<pair<int,int>> rotation(vector<pair<int,int>> a){
	vector<pair<int,int>> b;
	for(pair<int,int> z: a)
		b.push_back(make_pair(z.second,z.first*-1));
	return b;
}

vector<pair<int,int>> huga(vector<pair<int,int>> a){
	vector<pair<int,int>> b;
	int size = a.size(), x = a[size-1].first , y = a[size-1].second;
	for(int i = size-1; i >= 0; i--)
		b.push_back(make_pair(a[i].first-x,a[i].second-y));
	
	return b;
}

bool foo(vector<pair<int,int>> a, vector<pair<int,int>> b){
	if(a.size() != b.size()) return false;
	for(int i = 0; i < 4; i++){
		if(a==b)      return true;
		if(huga(a)==b)return true;
		a = rotation(a);
	}
	return false;
}

signed main(){
	while(true){
		int n, m, x, y, x0, y0;
		cin>>n;
		vector<pair<int,int>> ve[n+4];
		if(!n)break;
		for(int i = 0; i <= n; i++){
			cin>>m;
			for(int j = 1; j <= m; j++){
				cin>>x>>y;
				if(j==1)x0 = x, y0 = y;
				ve[i].push_back(make_pair(x-x0,y-y0));
			}
			if(i&&foo(ve[0], ve[i]))cout<<i<<endl;
		}
		cout<<"+++++"<<endl;
	}
	return 0;
}


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	ll n ;cin >>n;
	int A[100100] , B[100100];
	rep(i,n) cin >> A[i];
	rep(i,n) cin >> B[i];

	ll sum_a = 0 , sum_b = 0;
	rep(i,n){
		sum_a += A[i];
		sum_b += B[i];
	}

	vector<ll> amari(0);
	ll yowaihito = 0;
	ll need = 0;
	rep(i,n){
		if(A[i] > B[i]){
			amari.push_back(A[i]-B[i]);
		}
		else if ( B[i] > A[i]) {
			yowaihito ++;
			need += B[i] - A[i];
		}

	}

	SORT(amari);
	rSORT(amari);
//	for(auto x : amari){
//		cout << x << " ";
//	}
//	cout << endl;
//	debug(need);
//	debug(yowaihito);
	if(sum_a < sum_b){
		cout << -1 <<endl;
		return 0;
	}
	else{
		//他では、最大でnだね。

		if(yowaihito==0){
			cout << 0 << endl;
			return 0 ;
		}
		ll count = 0;
		ll yasashi = amari[count];
		while(yasashi < need){
			count ++ ;
			yasashi += amari[count];
			//count + 1 個優しい人の力を借りる
			//足りてない人の数を足せば答え
		}
		cout << yowaihito + count+1  << endl;
		return 0 ;
	}
}


Measured memory_bytes: 1660
import * as fs from 'fs'
const reader = (s: string) => s.split('\n')

function Main(input: string) {
  const [n, S] = reader(input)
  const N = parseInt(n, 10)
  let answer = 1

  for (let i = 0; i < N - 1; i++) {
    if (S[i] !== S[i + 1]) {
      answer++
    }
  }

  console.log(answer)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    int block[55][55]={};
    int h,w;
    cin>>h>>w;
    rep2(i,h){
        rep2(k,w){
            char c;
            cin>>c;
            if(c=='#')block[i][k]=1;
        }
    }
    string ans="Yes";
    rep2(i,h){
        rep2(k,w){
            if(block[i][k]){
                if(block[i-1][k]||block[i+1][k]||block[i][k+1]||block[i][k-1]){
                continue;
                }
                else{
                ans="No";
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll N, K; cin >> N >> K;
	ll ok[999999];
	ll R, S, P; cin >> R >> S >> P;
	string T;
	cin >> T;
	ll ans = 0;
	for (int i = 0;i < K;i++) {
		if (T[i] == 'r') ans += P;
		if (T[i] == 'p') ans += S;
		if (T[i] == 's') ans += R;
		ok[i] = 1;
	}
	for (ll i = K;i < N;i++) {
      if(T[i]==T[i-K]){
        if (ok[i-K] == 0) {
			ok[i] = 1;
			if (T[i] == 'r') ans += P;
			if (T[i] == 'p') ans += S;
			if (T[i] == 's') ans += R;
		}
	  }else{
        	if (T[i] == 'r') ans += P;
			if (T[i] == 'p') ans += S;
			if (T[i] == 's') ans += R;
        ok[i]=1;
      }
    }
	cout << ans << endl;
}

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

using namespace std;

int main(){
  int h,w,i,j,n;
  cin >> h >> w;
  n = h*w-1;
  int a[h+1][w+1];
  for(i=1;i<=h;i++)for(j=1;j<=w;j++)cin >> a[i][j];
  for(i=1;i<=h;i++){
    for(j=1;j<w;j++){
      if(a[i][j]%2!=0){
        a[i][j+1]+=a[i][j];
      }else --n;
    }
  }//コインが奇数個なら右方向にコインを移動
  for(i=1;i<h;i++){
    if(a[i][w]%2!=0){
      a[i+1][w]+=a[i][w];
    }else --n;
  }//右端のコインが奇数個なら下に移動
  //output--------------------------------------
  cout << n << endl;
  for(i=1;i<=h;i++){
    for(j=1;j<w;j++){
      if(a[i][j]%2!=0){//(i,j)に奇数個積まれていたなら移動
        cout << i << " " << j << " " << i << " " << j+1 << endl;
      }
    }
  }
  for(i=1;i<h;i++){
    if(a[i][w]%2!=0){//(i,w)に奇数個積まれていたなら移動
      cout << i << " " << w << " " << i+1 << " " << w << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3072
import java.util.Scanner;

class Food{
	String f;
	int w;
	int s;
	Food(String f,int w,int s){
		this.f=f;
		this.w=w;
		this.s=s;
	}
}
public class Main {
	public static void main(String[] args) {
		new Main().run();
		//new AOJ0170().run();
	}
	void run(){
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0) break;

			int sum=0;
			Food food[]=new Food[n];
			for(int i=0;i<n;i++){
				food[i]=new Food(sc.next(), sc.nextInt(), sc.nextInt());
				sum+=food[i].w;
			}
			int max=-1;
			
			for(int j=0;j<n;j++){
				int k=j;
				max=-1;
				for(int i=j;i<n;i++){
					if((sum-food[i].w<=food[i].s) && (max<food[i].w)){
						max=food[i].w;
						k=i;
					}
				}
				//change
				sum-=food[k].w;
				Food temp=food[j];
				food[j]=food[k];
				food[k]=temp;
			}
			for(int i=0;i<n;i++){
				System.out.println(food[i].f);
			}
		}
	}
}

Measured memory_bytes: 20492
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険                                   // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n; cin >> n;
    ll a[n]; rep(i,0,n) cin >> a[i];
    
    ll counter = 1;
    rep(i,0,n){
        if(counter == a[i])
            counter++;
    }

    if(counter == 1) cout << -1 << endl;
    else cout << n - counter + 1 << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<vector>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int a[800010],lazy[800010];
void update(int num){
	a[num]=max(a[num<<1],a[num<<1|1]);
}
void push(int l,int r,int num){
	if(l==r||!lazy[num]) return;
	a[num<<1]+=lazy[num];lazy[num<<1]+=lazy[num];
	a[num<<1|1]+=lazy[num];lazy[num<<1|1]+=lazy[num];
	lazy[num]=0;
}
void build(int l,int r,int num){
	if(l==r){
		a[num]=l;return;
	}
	int mid=(l+r)>>1;
	build(l,mid,num<<1);build(mid+1,r,num<<1|1);
	update(num);
}
void change(int l,int r,int ql,int qr,int num,int val){
	push(l,r,num);
	if(l>=ql&&r<=qr){
		a[num]+=val;lazy[num]+=val;return;
	} 
	int mid=(l+r)>>1;
	if(mid>=ql) change(l,mid,ql,qr,num<<1,val);
	if(mid<qr) change(mid+1,r,ql,qr,num<<1|1,val);
	update(num);
}
int query(int l,int r,int ql,int qr,int num){
	push(l,r,num);
	if(l>=ql&&r<=qr) return a[num];
	int mid=(l+r)>>1,re=0;
	if(mid>=ql) re=max(re,query(l,mid,ql,qr,num<<1));
	if(mid<qr) re=max(re,query(mid+1,r,ql,qr,num<<1|1));
	return re;
}
int n,m;
vector<int>q[200010];
int main(){
	n=read();m=read();int i,j,t1,t2;
	for(i=1;i<=n;i++){
		t1=read();t2=read();
		q[t1].push_back(t2);
	}
	build(1,m+1,1);
	int ans=min(n,m);
	for(i=0;i<=m;i++){
		for(j=0;j<q[i].size();j++) change(1,m+1,1,q[i][j],1,1);
		ans=min(ans,i+m+n+1-query(1,m+1,i+1,m+1,1));
	}
	printf("%d\n",n-ans);
}

Measured memory_bytes: 14080
program folia
  implicit none
  integer :: n, i
  integer(8), dimension(0:100001) :: a = 0, b = 0, s = 0
  read(*,*) n
  read(*,*) a(0:n)
  do i = n, 0, -1
    s(i) = s(i + 1) + a(i)
  end do
  b(0) = 1 - a(0)
  do i = 1, n
    b(i) = min(b(i - 1) * 2 - a(i), s(i + 1))
  end do
  write(*,'(i0)') merge(-1_8, s(0) + sum(b(0:n)), any(b(0:n) < 0))
end program folia

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

int main(){
  string s;cin >> s;
  int ans=0;
  if(s.at(0)!=s.at(1)){
    if(s.at(1)!=s.at(2)){
      if(s.at(2)!=s.at(3)) ans++;
    }
  }
  if(ans!=0) cout << "Good" << endl;
  else cout << "Bad" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N,Q;
	cin >> N >> Q;
	vector<int> v(N),ans(N);
	vector<vector<int>> g(N);
	for(int i=0;i<N-1;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
	}
	for(int i=0;i<Q;i++){
		int p,x;
		cin >> p >> x;
		p--;
		v[p]+=x;
	}
	for(int i=0;i<N;i++){
		ans[i] += v[i];
		if(v[i]>0){
			for(auto x:g[i]){
				v[x] += v[i];
			}
		}
	}
	for(auto x:ans)cout << x <<" ";
	cout << endl;
}

Measured memory_bytes: 14848
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vvi;
typedef vector <ll> vl;
typedef vector <vector <ll>> vvl;
typedef vector <bool> vb;
typedef vector <vector <bool>> vvb;

//const int kINF_int = INT_MAX;
//const long long kINF_long = LONG_LONG_MAX;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

template <typename type1, typename type2>
ostream &operator<<(ostream &out, const pair <type1, type2> &p) {
    out << '[' << p.first << ", " << p.second << ']';
    return out;
}

template <typename type>
ostream &operator<<(ostream &out, const vector <type> &massive) {
    for (const type &i : massive) {
        out << i << ' ';
    }
    return out;
}

template <typename type>
void print(const vector <type> &massive, const string &sep, const string &end) {
    if (!massive.empty()) {
        cout << massive[0];
        for (int i = 1; i < massive.size(); ++i) {
            cout << sep << massive[i];
        }
    }
    cout << end;
}

template <typename type>
void print(const vector <type> &massive) {
    print(massive, " ", "\n");
}

template <typename type>
void print(const type &element, const string &end) {
    cout << element << end;
}

template <typename type>
void print(const type &element) {
    print(element, "\n");
}

void solve() {

}

int main() {
    fast();

    //freopen("../input.txt", "r", stdin);

    int x;
    cin >> x;
    if (x) {
        cout << 0;
    } else {
        cout << 1;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
ll mod                = 1e9 + 7;
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {// テーブルを作る前処理
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long long COM(int n, int k){ // 二項係数:nCk計算
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	int s;
	COMinit();
	ll ans=0LL;
	cin >>s;
	for (int i = 1; i <= s / 3;i++){
		ans += COM(s+i-1-(i)*3,i-1);
		//clog << (s + i - 1 - (i) * 3) << " " << i-1 << endl;
		ans %= mod;
	//	clog << ans << endl;
	} 
	if(s<3){
		ans = 0LL;
	}cout << ans % mod << endl;
}

Measured memory_bytes: 15480
#AGC024-C Sequence Growing Easy
"""
問題：
lst1とlst2がある。
lst1の値が与えられ、lst2の値は最初全て0である。
lst2[i+1] = lst2[i]+1
を繰り返し、lst1と等しくできる場合その最小手数を出力せよ。

考察：
足し合わせる、ではなく、置き換える、なので、
必ずlst2[i+1] <= lst2[i] + 1となる。
左から最大に足し合わせた場合、
0 1 2 3 4...としかならない。
他に
0 0 1 0 0
0 0 1 2 0
0 0 1 2 3
0 1 1 2 3
0 1 2 2 3
0 1 2 3 3 (3+3で6手)
のような遷移も可能
0 0 0 1 0
0 0 0 1 2
0 1 0 1 2
0 1 2 1 2
0 1 2 3 2 (3+2で5手)
解法：
左からリストを見ていった時に、
必ずlst1[i+1] <= lst1[i] + 1となっていることを確認しながら、
正常な遷移でない部分の値を足し合わせることによって答えが求まる
正常でない遷移：↑のシュミレーションの3+3とか3+2の部分
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))
if lst1[0] != 0:
    print(-1)
    exit()
ans = 0
for i in range(n-1):
    if lst1[i]+1 == lst1[i+1]:
        continue
    if lst1[i]+1 < lst1[i+1]:
        print(-1)
        exit()
    if lst1[i] >= lst1[i+1]:
        ans += lst1[i]
print(ans+lst1[-1])

Measured memory_bytes: 46492
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int D, T, S;
  cin >> D >> T >> S;

  if(D <= S*T) Yes;
  else No;

  return 0;
}


Measured memory_bytes: 3644
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()

d = defaultdict(int)

for i in readChars():
	d[i]+=1

d = sorted(d.items(), key=lambda x:x[1],reverse=True)
ans = 0
while len(d)>k:
	ans+=d[-1][1]
	del d[-1]
print(ans)

Measured memory_bytes: 48636