akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long sum = in.nextLong();
            long[] a = in.nextLongArray(n);

            Arrays.sort(a);
            int ans = 0;
            for (int i = 0; i < n; i++) {
                if (sum >= a[i]) {
                    ans++;
                    sum -= a[i];
                } else {
                    break;
                }

                if (i == n - 1 && sum > 0) ans--;
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextLong();
            }
            return res;
        }

    }
}



Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int d = a / b;
        int r = a % b;
        double f = 1.0 * a / b;
        System.out.printf("%d %d %.5f", d, r, f);
    }
}


Measured memory_bytes: 26420
N,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
cnt=0
while x>0:
    #print(x)
    if x>=A[cnt]:
        x-=A[cnt]
        cnt+=1
    else:
        break
    if len(A)==cnt:
        if x>0:
            cnt-=1
        break
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define MAXN 100005

char name[MAXN][20];
long long m, a, r, c, h;
long long ans;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%s", name[i]);
	for(int i=1; i<=n; i++)
	{
		if(name[i][0]=='M') m++;
		if(name[i][0]=='A') a++;
		if(name[i][0]=='R') r++;
		if(name[i][0]=='C') c++;
		if(name[i][0]=='H') h++;
	}
	ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
	printf("%lld\n", ans);
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
//#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*
lli power(lli x,lli y)
{
	lli res=1;
	while(y>0)
	{
		if(y%2==1)
			res=(res*x)%mod;
		x=(x*x)%mod;
		y=y/2;
	}
	return res;
}
*/
int main()
{
	//cout.precision(10);
	//cout.setf(ios::fixed,ios::floatfield);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	lli T=1;
	//cin>>T;
	while(T--)
	{
		lli a,b;
		cin>>a>>b;
		cout<<max((lli)0,a-2*b)<<endl;
	}
}


Measured memory_bytes: 256
s = input()
l = 0
r = len(s)-1
res = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x' and s[r] != 'x':
        res += 1
        l += 1
    elif s[l] != 'x' and s[r] == 'x':
        res += 1
        r -= 1
    elif s[l] != s[r] and s[l] != 'x' and s[r] != 'x':
        print(-1)
        exit()
print(res)

Measured memory_bytes: 39792
#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;

  // 1からn-1までの和
  ll res = ((ll) (n - 1) * n) / 2;
  cout << res << endl;

  return 0;
}


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


def solve(N: int, s: "List[str]"):
    s.sort()
    count = 0
    res = 0
    prev = ""
    for string in s:
        if string != prev:
            prev = string
            res += count * (count+1) // 2
            count = 0
        else:
            count += 1
    res += count * (count+1) // 2    
    print(res)
    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()
    N = int(next(tokens))  # type: int
    s = [ sorted(next(tokens)) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


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

int main()
{
    int ans = 1;
    int a, b, c;
    cin >> a >> b >> c;
    if (a != b)
        ans++;
    if (c != b && c != a)
        ans++;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
ST= input().split()
S= str(ST[0])
T= str(ST[1])
AB= input().split()
A= int(AB[0])
B= int(AB[1])
U= input(str(""))

if(U == S):
    A -= 1
if(U == T):
    B -= 1

print(str(A)+" "+str(B))

Measured memory_bytes: 3064
/* Hello darkness my old friend, I've come to visit you again! */

#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;
int a[30],b[30];
int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n,i,j,mx1=0,mx2=0,ans=0,mx=0,mn=89996,k;
    cin>>n;
    string s;
    cin>>s;
    FOR(i,0,n-1)
    {
        FOR(j,0,30)
        a[j]=b[j]=0;
        FOR(j,0,i+1)
        a[s[j]-'a']=1;
        FOR(j,i+1,n)
        b[s[j]-'a']=1;
        int c1=0,c2=0,c=0;
        FOR(j,0,26)
        {
            if(a[j])
                c1++;
            if(b[j])
                c2++;
            if(a[j] && b[j])
                c++;
        }
       // cout<<c1<<" "<<c2<<" "<<c<<"\n";
        /*if(c1>=mx1 && c2>=mx2)
        {
            mx1=c1,mx2=c2;
            ans=max(ans,max(c1,c2));
        }*/
        /*if(abs(c1-c2)<=mn)
        {
            mn=abs(c1-c2);
            mx=max(mx,min(c1,c2));
            cout<<mx<<" "<<c1<<" "<<c2<<"\n";
        }*/
        mx=max(mx,c);
    }
   // mx=max(mx,1);
    cout<<mx;
    return 0;
}

/* This is the end, beautiful friend! */


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <cmath>
#include <tuple>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define all(n)	n.begin(),n.end()
#define each(i,n) for(auto &i : n)
typedef long long ll;

const int INF = 1e9;

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

//unionfind??????????????\??????????????????????????´???
struct UnionFind {
	vector<int> to;
	vector<int> data;
	UnionFind(int size) : to(size, -1),data(size, -1) { }
	
	//??????x?????????y????¶????????????????(data[root(x | y)] = data[root(x)]???????????????)
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		int rootData = data[root(x)];
		if (x != y) {
			if (to[y] < to[x]) swap(x, y);
			to[x] += to[y]; to[y] = x;
		}
		setData(x, rootData);
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return to[x] < 0 ? x : to[x] = root(to[x]);
	}
	int size(int x) {
		return -to[root(x)];
	}

	int findData(int x) {
		return data[root(x)];
	}
	void setData(int x, int d) {
		data[root(x)] = d;
	}
};


signed main() {

	int n, q;
	while (cin >> n >> q && n) {
		struct edge {
			int p, m;
			int count;
			vector<int> t;
		};

		vector<edge> e(n);
		for (int i = 1; i < n;i++) {
			cin >> e[i].p; 
			e[i].p--; 
			e[i].m = -1;
			e[i].count = 0;
			e[e[i].p].t.push_back(i);
		}
		e[0].m = 0; e[0].count = 1;

		vector<int> v(q);
		vector<char> c(q);
		rep(i, q) {
			cin >> c[i] >> v[i]; v[i]--;
			if (c[i] == 'M') {
				e[v[i]].m = v[i];
				e[v[i]].count++;
			}
		}
		function<void(int, int)> dfs = [&](int a, int b) {
			if (e[a].m == -1) {
				e[a].m = b;
			}
			rep(i, e[a].t.size()) {
				dfs(e[a].t[i], e[a].m);
			}
		};
		dfs(0, 0);
		ll ans = 0;
		UnionFind uf(n);
		rep(i, n) {
			uf.setData(i, i);
		}

		for (int i = q - 1; i >= 0; i--) {
			int j = v[i];
			if (c[i] == 'M') {
				e[j].count--;
				if (e[j].count == 0) {
					uf.unionSet(e[e[j].p].m, e[j].m);
				}
			}
			else {
				ans += uf.findData(e[j].m) + 1;
			}
		}

		cout << ans << endl;
	}
	


	return 0;
}

Measured memory_bytes: 15788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<char> S(N);
  bool ans=true;
  for(int i=0;i<N;i++){
    cin>>S.at(i);
    if(S.at(i)=='Y'){
      ans=false;
    }
  }
  if(ans) cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<int32_t, int32_t>;

bool doesnot_have_okashi[100 + 1];

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  for (bool &a : doesnot_have_okashi) {
    a = true;
  }
  int32_t number_of_people, number_of_okashi;
  string S, result;
  std::cin >> number_of_people >> number_of_okashi;
  for (int32_t index_okashi = 1; index_okashi <= number_of_okashi; ++index_okashi) {
    int32_t number_of_people_having_this;
    cin >> number_of_people_having_this;
    for (int32_t i = 1; i <= number_of_people_having_this; ++i) {
      int32_t index_person;
      cin >> index_person;
      doesnot_have_okashi[index_person] = false;
    }
  }
  int32_t count=0;
  for(int32_t index_person=1; index_person<=number_of_people; index_person++) {
    if(doesnot_have_okashi[index_person]) {
      count++;
    }
  }
  cout << count << endl;

  return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int>p(n),q(n);
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    vector<int>a(n);
    rep(i,n)a[i]=i+1;
    map<vector<int>,int>mp;
    do {
        mp[a]=mp.size();

    } while(next_permutation(a.begin(),a.end()));
    int ans=abs(mp[p]-mp[q]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5248
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

template<class T>bool chmax(T &a, const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}

template<class T>bool chmin(T &a, const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	string s,t;
	cin>>s>>t;
	int n = s.size();
	int ans = 0;
	rep(i,n){
		if(s[i]!=t[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
map <ll,ll> bk;
ll arr[maxn];
ll n,k;
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++)
       scanf("%lld",&arr[i]);
    
    arr[0]%=k;
    ll sum=0;
    for(int i=1;i<n;i++)
    {
       arr[i]=(arr[i]+arr[i-1])%k;
    }
    for(int i=0;i<n;i++)
    {
        sum+=(bk[arr[i]]++);
    }
    printf("%lld\n",sum+bk[0]);
    return 0;

}

Measured memory_bytes: 4992
using System;
using System.Linq;

namespace ITP1_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (0 < n && n <= 100)
            {
                int[] data = new int[n];
                data = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
                for (int i = n - 1; i >= 0; i--)
                {
                    Console.Write(data[i]);
                    if (i != 0) Console.Write(" ");
                }                
                Console.WriteLine();                    
            }           
        }
    }
}

Measured memory_bytes: 9600
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

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

	let mut count = 0;
	for i in 1..=n {
		if i % 2 == 1 && a[i-1] % 2 == 1 {
			count += 1;
		} 
	}
	println!("{}", count);
}



Measured memory_bytes: 2108
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		double d=sc.nextDouble();
		int c=0;
		for(int i=0;i<n;i++) {
			long x=sc.nextLong();
			long y=sc.nextLong();
			double a=Math.sqrt((x*x)+(y*y));
			if(d>=a)
				c++;
		}
		System.out.println(c);





	}

}

Measured memory_bytes: 59448
x,y = map(int,input().split())
s = [n for n in range(1,13)]
a = [2]
b = [4,6,9,11]
c = set(s) -set(a) -set(b)
if x in a and y in a :
  print("Yes")
elif x in b and y in b :
  print("Yes")
elif x in c and y in c :
  print("Yes")
else :
  print("No")

Measured memory_bytes: 3064
//
//  AOJ 2170 Marked Ancestor
//
//  Created by TaoSama on 2015-03-16
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int n, q, par[N];

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

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(~scanf("%d%d", &n, &q) && n && q) {
		par[1] = 1;
		for(int i = 2; i <= n; ++i) scanf("%d", &par[i]);

		long long ans = 0;
		for(int i = 1; i <= q; ++i) {
			char op[2]; int x;
			scanf("%s%d", op, &x);
			if(op[0] == 'Q') ans += find(x);
			else par[x] = x;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3488
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=200005;
int n,q;
vector<int> a[MAXN];
int cnt[MAXN];
int ans[MAXN];
void dfs(int p,int fa,int add){
	add+=cnt[p];
	ans[p]=add;
	for (int i=0;i<a[p].size();i++){
		int v=a[p][i];
		if (v!=fa)
			dfs(v,p,add);
	}
}

signed main()

{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	for (int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}

	for (int i=1;i<=q;i++){
		int x,c;
		cin>>x>>c;
		cnt[x]+=c;
	}

	dfs(1,0,0);
	for (int i=1;i<=n;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}
//emmm

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

using namespace std;

typedef long long ll;

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

    if (r - l + 1 >= 673) {
        puts("0");
    } else {
        int ans = 98765;
        for (ll i = l; i < r; i++) {
            for (ll j = i + 1; j <= r; j++) {
                if ((i * j) % 2019 < ans) {
                    ans = (i * j) % 2019;
                }
            }
        }
        printf("%d\n", ans);
    }
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N,M,Q;
    scanf("%d%d%d",&N,&M,&Q);

    //map[L][R]は、Lから始まりRで終わる電車の数
    int map[N+1][N+1];
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++) map[i][j]=0;
    }
    //標準入力からmapの情報を入れる
    for(int i=0;i<M;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        map[l][r]++;
    }

    int sum[N+1][N+1];
    //累積和をとる
    for(int i=1;i<=N;i++){
        sum[i][0]=0;
        sum[i][1]=map[i][1];
        for(int j=2;j<=N;j++){
            sum[i][j]=sum[i][j-1]+map[i][j];
        }
    }

    int p[Q];
    int q[Q];
    for(int i=0;i<Q;i++){
        scanf("%d%d",&p[i],&q[i]);
    }

    for(int k=0;k<Q;k++){
        int ans=0;
        for(int i=p[k];i<=q[k];i++){
            ans+=sum[i][q[k]]-sum[i][p[k]-1];
        }
        printf("%d\n",ans);
    }

    return 0;
}

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




}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
void sortASC(int a[],int b[],int n){
	int i, j, min_i, tmp;
	for(i = 0;i < n;i++)
		b[i] = a[i];
	for(i = 0;i < n - 1;i++){
		min_i = i;
		for(j = i + 1;j < n;j++){
			if(b[min_i] > b[j])
				min_i = j;
		}
		if(min_i != i){
			tmp = b[i];
			b[i] = b[min_i];
			b[min_i] = tmp;
		}
	}
	return;
}
void sortDSC(int a[],int b[],int n){
	int i, j, max_i, tmp;
	for(i = 0;i < n;i++)
		b[i] = a[i];
	for(i = 0;i < n - 1;i++){
		max_i = i;
		for(j = i + 1;j < n;j++){
			if(b[max_i] < b[j])
				max_i = j;
		}
		if(max_i != i){
			tmp = b[i];
			b[i] = b[max_i];
			b[max_i] = tmp;
		}
	}
	return;
}
void sub(int a[],int b[],int c[],int n){
	int i;
	for(i = 0;i < n;i++)
		c[i] = a[i];
	for(i = n - 1;i > 0;i--){
		c[i] = c[i] - b[i];
		if(c[i] < 0){
			c[i - 1]--;
			c[i] += 10;
		}
	}
	c[0] -= b[0];
	return;
}	
int main(void){
	int flag, inp, i, j, k, L, count, *a[21],*aA, *aD;
	scanf("%d %d",&inp,&L);
	while(inp != 0 || L != 0){
		for(i = 0;i <= 20;i++)
			a[i] = (int *)malloc(sizeof(int) * L);
		aA = (int *)malloc(sizeof(int) * L);
		aD = (int *)malloc(sizeof(int) * L);
		for(i = L - 1;i >= 0;i--){
			a[0][i] = inp % 10;  /* 入力された値を配列形式にして代入 */
			inp /= 10;
		}
		sortDSC(a[0],aA,L);
		sortASC(a[0],aD,L);
		flag = 0;
		for(i = 1;flag == 0 && i <= 20;i++){
			sub(aA,aD,a[i],L);
			sortDSC(a[i],aA,L);
			sortASC(a[i],aD,L);
			for(j = 0;j < i && flag == 0;j++){
				count = 0;
				for(k = 0;k < L;k++){
					if(a[i][k] == a[j][k])
						count++;        /*一致した配列の数を数える*/
				}
				if(count == L)
					flag = 1;
			}
		}
		i--; j--;
		printf("%d ",j);
		count = 0;
		for(k = 0;k < L;k++){
			if(a[i][k] == 0)/* ０の数を数える */
				count++;
		}
		if(count == L)
			printf("0");
		else{
			for(k = 0;k < L;k++){
				if(a[i][k] != 0){
					while(k < L){
						printf("%d",a[i][k]);
						k++;
					}
				}
			}
					
		}
		printf(" %d\n",i - j);
		scanf("%d %d",&inp,&L);
	}
	return 0;
}

Measured memory_bytes: 656
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < static_cast<ll>(n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= static_cast<ll>(n); ++i)
#define RRANGE(i, m, n) for(ll i = static_cast<ll>(m); i >= static_cast<ll>(n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    string N;
    in >> N;
    ll total = 0;
    REP(i, N.size()) {
        total += N[i] - '0';
    }

    out << ((total % 9 == 0) ? "Yes" : "No")<< endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x)-1;i>=0;i--)
#define RFOR(i,c) for(auto i=(c).rbegin();i!=(c).rend();++i)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int n;
main(){
	vector<int> vp;
	int z = 0;
	vi one;
	cin >> n;
	REP(i, n){
		int x;
		cin >> x;
		if(!x) z++;
		else if(x == 1) one.push_back(x);
		else vp.emplace_back(x);
	}
	sort(ALL(vp));
	if((z & 1) && one.empty() && !vp.empty()){
		int mini = 0;
		one.push_back(vp[0]);
		vp.erase(vp.begin());
	}
	if(vp.size() > 1 && vp[vp.size()-1] == 3 && vp[vp.size()-2] == 2){
		swap(vp[vp.size()-1], vp[vp.size()-2]);
	}
	REP(i, vp.size()) cout << vp[i] << endl;
	REP(i, z-(z&1)) cout << 0 << endl;
	if(!one.empty()) cout << one[0] << endl;
	if(z&1) cout << 0 << endl;
	REP(i, (int)one.size()-1) cout << one[i+1] << endl;
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const ll mod=1e9+7;
const int maxn=2e5;
string s;
int main()
{
    //freopen("ce.in","r",stdin);
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    bool flag=true;
    if(s.length()%2!=0) flag=false;
    for(int i=0;i<s.length();++i)
        if(i%2==0&&s[i]!='h') flag=false;
        else
            if(i%2==1&&s[i]!='i') flag=false;
    if(flag) puts("Yes");else puts("No");
        
    return 0;
}

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

#define int long long
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 a[1000010] = {};
signed main(){
	int k;
	cin >> k;

	int cnt = 0;
	int now = 0;
	while(1){
		cnt++;
		now = (now*10+7) % k;
		if(now == 0){
			cout << cnt << endl;
			return 0;
		}
		if(a[now] != 0){
			cout << -1 << endl;
			return 0;
		}
		a[now] = 1;
	}

	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = ReadInt();
            int[] a = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
            WriteLine(a[k - 1]);
        }

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


Measured memory_bytes: 13140
s = input()
n = int(len(s))
list = list(s)
lists = list[::-1]
list2 = list[0:(int((n-1)/2))]
list2s = list2[::-1]
list3 = list[int((n + 3)/2)-1:n+1]
list3s = list3[::-1]
count = 0

if list == lists:
    count = count + 1
if list2 == list2s:
    count = count + 1
if list3 == list3s:
    count = count + 1
if count == 3:
    print("Yes")
else:
    print("No")

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll solve(vector<ll> A){
    ll N = A.size();
    ll ans = 0;
    ll left_ind = 0, right_ind = N - 2;
    ll left = A.at(N - 1), right = A.at(N - 1);
    bool from_left = true;

    while (left_ind <= right_ind){
        if (from_left){
            if (right_ind - left_ind >= 1){
                ans += abs(A.at(left_ind) - left); left = A.at(left_ind);
                ans += abs(A.at(left_ind + 1) - right); right = A.at(left_ind + 1);
                left_ind += 2;
            } else {
                ans += max(abs(A.at(left_ind) - left), abs(A.at(left_ind) - right));
                left_ind += 1;
            }
        } else {
            if (right_ind - left_ind >= 1){
                ans += abs(A.at(right_ind) - left); left = A.at(right_ind);
                ans += abs(A.at(right_ind - 1) - right); right = A.at(right_ind - 1);
                right_ind -= 2;
            } else {
                ans += max(abs(A.at(right_ind) - left), abs(A.at(right_ind) - right));
                right_ind -= 1;
            }
        }
        from_left = !from_left;
        // cout << left << " " << right << " " << ans << " " << left_ind << " " << right_ind << endl;
    }
    return ans;
}

void Main() {
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i, N){cin >> A.at(i);}

    sort(A.begin(), A.end());
    ll ans1 = solve(A);
    sort(A.begin(), A.end(), greater<ll>());
    ll ans2 = solve(A);

    cout << max(ans1, ans2) << endl;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4788
import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;


public class Main {
	
	public static void main(String args[]) throws IOException{

		Scanner sc=new Scanner(System.in);
		
		BigInteger TWO=new BigInteger("2");

		int n=sc.nextInt();
		BigInteger x=new BigInteger(sc.next());
		BigInteger y=new BigInteger(sc.next());		

		for(int i=0;i<n-1;i++){

			BigInteger t=new BigInteger(sc.next());
			BigInteger a=new BigInteger(sc.next());
			BigInteger X=x,Y=y;

			BigInteger A=t.multiply(y);
			BigInteger B=a.multiply(x);
			BigInteger g=A.gcd(B);
			A=A.divide(g);
			B=B.divide(g);

			x=x.multiply(A);
			y=y.multiply(B);
			g=x.gcd(y);
			x=x.divide(g); y=y.divide(g);

			if(x.compareTo(X)<0 || y.compareTo(Y)<0){
				BigInteger l=BigInteger.ZERO;
				BigInteger r=X.divide(x).max(Y.divide(y)).add(BigInteger.TEN);

				while(r.subtract(l).compareTo(BigInteger.ONE)>0){
					BigInteger mid=l.add(r).divide(TWO);
					if(x.multiply(mid).compareTo(X)>=0 && y.multiply(mid).compareTo(Y)>=0){
						r=mid;
					}else{
						l=mid;
					}
				}
				x=x.multiply(r);
				y=y.multiply(r);
			}
		}

		System.out.println(x.add(y));

	}
	
	
	
}

Measured memory_bytes: 27908
import sys
from collections import deque

sys.setrecursionlimit(10000)
INF = float('inf')

N, L = list(map(int, input().split()))
S = set()
for _ in range(N):
    S.add(input())


# 追加できるのが 01... だけで
# L が 4 とすると
# 01: 次はない
# 010: 011 がある
# 011: 010 がある
# 0100: 011, 0101 がある
# 0101: 011, 0100
# 0110: 010, 0111
# 0111: 010, 0110
# 候補の長さと L だけによって次の候補の長さと数が決まる
def grundy(size):
    """
    :param int size: 候補の長さ
    :return:
    """
    # gs = {0}
    # g = 0
    # for sz in range(size + 1, L + 1):
    #     g ^= grundy(sz)
    #     gs.add(g)
    #
    # i = 0
    # while i in gs:
    #     i += 1
    # return i
    i = 1
    while (L - size + 1) % i == 0:
        i *= 2
    return i // 2


# S の各要素からトライ木つくる
trie = {}
for s in S:
    t = trie
    for c in s:
        if c not in t:
            t[c] = {}
        t = t[c]

# 候補文字列の長さのリスト
ok_size_list = []
children = deque()
children.append((trie, 0))
while len(children) > 0:
    node, size = children.popleft()
    # 0 か 1 か片方しか行けなかったら、行けない方は S の prefix にならない
    # 両方行けない場合はどう追加しても S のいずれかが prefix になってしまうからダメ
    if len(node) == 1:
        ok_size_list.append(size + 1)
    for c, child in node.items():
        children.append((child, size + 1))

g = 0
for size in ok_size_list:
    g ^= grundy(size)
if g != 0:
    print('Alice')
else:
    print('Bob')

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

using namespace std;
using ll = long long;

int main() {
    int n,x,t;
    cin >> n >> x >> t;
    if(n % x == 0){
        cout << (n / x) * t << endl;
    }else{
        cout << (n / x + 1) * t << endl;
    }

    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
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 first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


const int N = 2e5 + 5;

char S[N], T[N];


bool solve(char* S, char* T, int fr, int to, int pos, int edge, char add, char sub) {
    int l = 1; int r = edge;

    for(int i = to; i >= fr; --i) {
        // printf("%d %c %c %c: ", i, T[i], S[i], add);
        if(T[i] == add) { 
            l --;
        } else if(T[i] == sub) {
            r ++;
        }

        l = max(l, 1);
        r = min(r, edge);

        if(S[i] == add) {
            r --;
        } else if(S[i] == sub) {
            l ++;
        }
        
        if(l > r) return false;
    }
    if(l <= pos && pos <= r) return true;
    else return false;
}
int main() {
    int H, W, N;
    int sr, sc;
    while(~scanf("%d %d %d", &H, &W, &N)) {
        scanf("%d %d", &sr, &sc);
        scanf("%s %s", S, T);

        bool flag = solve(S, T, 0, N - 1, sc, W, 'R', 'L');
        
        if(flag) flag = solve(S, T, 0, N - 1, sr, H, 'D', 'U'); 
        
        // cout << flag << endl;
        printf("%s\n", flag ? "YES" : "NO");

    }
    return 0;
}

/*
2 3 3
2 2
RRL
LUD
4 3 5
2 2
UDRRR
LLDUD
5 6 11
2 1
RLDRRUDDLRL
URRDRLLDLRD



*/

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for (auto&& d_ : d)
    cin >> d_;
  
  sort(d.begin(), d.end());
  int sidx = n/2-1, lidx = n/2;
  
  int lower = d[sidx] + 1, upper = d[lidx];
  cout << upper - lower + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
INF = 10**100
r = range

class infix(object):
    def __init__(self, function):
        self.function = function

    def __ror__(self, other):
        self.left = other
        return self

    def __or__(self, other):
        return self.function(self.left, other)

    def __call__(self, value1, value2):
        return self.function(value1, value2)

@infix
def c(f_t_u, f_u_r): return lambda t: f_u_r(f_t_u(t))

class _Ap(object):
    def __rlshift__(self, other):
        self.value = other
        return self

    def __rshift__(self, other):
        return other(self.value)
Ap = _Ap()
ap = Ap

#d = {1:2, 3:5, 6:10, 1000043:3814}
#zip(d.keys(), d.values())<<ap>>(list |c| sorted |c| reversed |c| list |c| print)

s=input()
ret=[]
for c in s:
    if c == '0':
        ret.append('0')
    elif c == '1':
        ret.append('1')
    else:
        if ret<<ap>>len:
            ret.pop();

print(''.join(ret));


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

void dfs(int u, int d, vector<vector<int>>& adj,
         vector<int>& visited, vector<int>& dist)
{
  visited[u] = 1;
  dist[u] = d;
  for (int v : adj[u]) {
    if (visited[v]) { continue; }
    dfs(v, d + 1, adj, visited, dist);
  }
}

int main()
{
  int N; scanf("%d", &N);
  vector<vector<int> > adj(N + 5, vector<int>());
  int a, b;
  for (int i = 0; i < N - 1; ++i) {
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  vector<int> d_fen(N + 5, INF), d_snuke(N + 5, INF);
  vector<int> visited(N + 5, 0);
  dfs(1, 0, adj, visited, d_fen);
  fill(visited.begin(), visited.end(), 0);
  dfs(N, 0, adj, visited, d_snuke);
  int snuke = 0, fen = 0;
  for (int i = 1; i <= N; ++i) {
    if (d_fen[i] <= d_snuke[i]) { ++fen; }
    else { ++snuke; }
  }

  printf("%s\n", fen > snuke ? "Fennec" : "Snuke");
  return 0;
}


Measured memory_bytes: 13184
#include<cstdio>
#include<algorithm>
#define INF 50001
using namespace std;
int dp[50001];
int c[200];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++) scanf("%d",c+i);
    fill(dp,dp+n+1,INF);
    for(int i=0;i*c[0]<=n;i++) dp[i*c[0]]=i;
    for(int i=1;i<m;i++){
        for(int j=0;j<=n;j++){
            if(j-c[i]>=0) dp[j]=min(dp[j-c[i]]+1,dp[j]);
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <string.h>
#include <algorithm>
#include <set>
#include <vector>
#include <climits>
#include <map>
#include <queue>
#include <math.h>
#include <iomanip>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e2;
ll dp[N][2], a[N], n, p;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> p;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	dp[0][0] = 2 - (a[0] % 2);
	dp[0][1] = (a[0] % 2);
	for (int i = 1; i < n; i++) {
		dp[i][0] = dp[i - 1][0];
		dp[i][1] = dp[i - 1][1];
		if (a[i] % 2) {
			dp[i][0] += dp[i - 1][1];
			dp[i][1] += dp[i - 1][0];
		}
		else {
			dp[i][0] += dp[i - 1][0];
			dp[i][1] += dp[i - 1][1];
		}
	}
	cout << dp[n - 1][p] << endl;
}































Measured memory_bytes: 256
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        String s = sc.next();

        // 処理
        String out = "Yes";

        if (s.charAt(2) != s.charAt(3)) {
            out = "No";
        } else if (s.charAt(4) != s.charAt(5)) {
            out = "No";
        }

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 21844
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	b=abs(b-a);
	c=abs(c-a);
	if(b>c)
	cout<<"B";
	else
	cout<<"A"; 
	return 0;
}

Measured memory_bytes: 256
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x=gi
d=x/500
x2=x-d*500
d2=x2/5

puts d*1000+d2*5

Measured memory_bytes: 1916
#include <bits/stdc++.h>
     
using namespace std;
#define ll long long 
#define ld long double

int main()
{   int n;
    int w; 
    cin>>n>>w;
    ll wrr[n];
    ll vrr[n];
    ll crr[w+1]={};
    ll m=0;
    for (int i=0;i<n;i++){
        cin>>wrr[i]>>vrr[i];
    }
    for (int j=0;j<n;j++){
        for (int i=w;i>=0;i--){
            if (i+wrr[j]<=w){
                crr[i+wrr[j]]=max(crr[i+wrr[j]],crr[i]+vrr[j]);
                m=max(m,crr[i+wrr[j]]);
            }
        }
    }
    cout<<m<<endl;
    
    
    return 0;
}


Measured memory_bytes: 4320
import sys
n = int(input())
a = list(map(int, input().split()))
if n%2 == 0:
	dp = [[-10**20 for _ in range(2)] for _ in range(n)]
	dp[0][0] = a[0]
	dp[0][1] = 0
	dp[1][1] = a[1]
	for i in range(1, n):
		if i%2 == 0:
			dp[i][0] = dp[i-2][0] + a[i]
			dp[i][1] = max(dp[i-1][0], dp[i-1][1])
		else:
			dp[i][0] = dp[i-1][0]
			if i > 1:
				dp[i][1] = max(dp[i-2][1] + a[i], dp[i-3][0] + a[i])

else:
	dp = [[-10**20 for _ in range(3)] for _ in range(n)]
	dp[0][0] = a[0]
	dp[0][1] = 0
	dp[1][1] = a[1]
	dp[0][2] = 0
	dp[1][2] = 0
	dp[2][2] = a[2]

	for i in range(1, n):
		if i%2 == 0:
			if i < n-1:
				dp[i][0] = dp[i-2][0] + a[i]
			else:
				dp[i][0] = dp[i-1][0]
			dp[i][1] = max(dp[i-1][1], dp[i-2][0])
			if i > 2:
				dp[i][2] = max(dp[i-2][2] + a[i], dp[i-4][0] + a[i], dp[i-3][1] + a[i])
		else:
			dp[i][0] = dp[i-1][0]
			if i > 1:
				dp[i][1] = max(dp[i-2][0] + a[i], dp[i-2][1] + a[i])
				dp[i][2] = max(dp[i-1][2], dp[i-2][1], dp[i-3][0])

print(max(dp[n-1]))

Measured memory_bytes: 119260
n, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i != 0:
        y = A[i-1]+A[i]
    else:
        y = A[i]
    if y <= x:
        continue
    ans += y-min(x, y)
    A[i] -= y-min(x, y)
print(ans)


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

typedef long long ll;
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(int i = int(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

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>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const long long INF = 1LL << 60;

// 降順ソート
// std::sort(data.begin(),data.end(),std::greater<int>());
// 昇順ソート
// std::sort(data.begin(),data.end());

// ここから開始だよ！
ll N, M;
std::vector<ll> v, m;
ll ans;

int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了
  
  cin >> N >> M;
  rep(i, M) {
    ll tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  std::sort(v.begin(),v.end());
  
  if(N >= M) {
    cout << 0 << endl;
    return 0;
  }
  
  m.push_back(0);
  rep(i, v.size()-1) {
    ll tmp = v[i+1] - v[i];
    m.push_back(tmp);
  }
  
  if(N == 1) {
    rep(i, m.size()) {
      ans += m[i];
    }
    cout << ans << endl;
    return 0;
  }
  
  std::sort(m.begin(),m.end());
  rep(i, N-1) {
    m.pop_back();
  }
  //cout << m << endl;
  rep(i, m.size()) {
    ans += m[i];
  }
  cout << ans << endl;
  
	return 0;
}


Measured memory_bytes: 2548
#-*-coding:utf-8-*-

import sys

def distance(ashiba,i,j):
    return abs(ashiba[i]-ashiba[j])    

def main():
    N = int(input())
    ashiba = list([int(i) for i in input().split()])
    cost_list=[]
    cost1=0
    cost2=0

    for i in range(N):
        if i==0:
            cost_list.append(0)
        elif i==1:
            cost1 = distance(ashiba,i,i-1)
            cost_list.append(cost1)
        else:
            cost1=distance(ashiba,i,i-1)
            cost2=distance(ashiba,i,i-2)
            cost=min(cost1+cost_list[i-1],cost2+cost_list[i-2])
            cost_list.append(cost)
    print(cost_list[-1])

if __name__ == "__main__":
    main()

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

int main(){
  int H,W; cin >> H >> W;
  const int INF = H+W+5;
  const int dx[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
  string str;
  vector<vector<int>> table(H+2,vector<int>(W+2,INF));
  queue<tuple<int,int>> q;
  reps(i,1,H+1){
    cin >> str;
    reps(j,1,W+1){
      if(str[j-1]=='#'){
        q.push(make_tuple(i,j));
        table[i][j] = 0;
      }else{
        table[i][j]--;
      }
    }
  }
  int m = 0;
  while(!q.empty()){
    int i = get<0>(q.front()),
        j = get<1>(q.front()),
        c = table[i][j] + 1;
    rep(k,4){
      int f = table[i+dx[k][0]][j+dx[k][1]];
      if(f<INF&&f>c){
        table[i+dx[k][0]][j+dx[k][1]] = c;
        q.push(make_tuple(i+dx[k][0],j+dx[k][1]));
      }
    }
    q.pop();
    m = c-1;
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 12432
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}


const int dm = 1400000;
char dn[dm], * di = dn;
const int MAX = 20000;
class unko {
public:
	char C[MAX * 7 + 10], *K[MAX + 10];
	constexpr unko() : C(), K() {
		auto di = C + 3;
		C[0] = '0';
		C[0] = ' ';
		C[0] = '\n';
		K[0] = C;
		K[1] = di;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			*di++ = ' ';
			*di++ = '\n';
			K[i + 1] = di;
		}
	}
};
constexpr unko f;
inline void putint(int X) {
	if (X > 20000) {
		int ue = X / 10;
		for (auto i = f.K[ue]; *i != ' '; i++) *di++ = *i;
		*di++ = '0' + X % 10;
		*di++ = ' ';
	}
	else for (auto i = f.K[X]; *i != '\n'; i++)* di++ = *i;
}

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


	int N = getint(), K = getint();

	int A[200001];
	rep(i, N) A[i] = getint();
	ll owa = ll(N) * N;

	rep(p, K) {
		int B[200001] = {};
		rep(i, N) {
			B[max(0, i - A[i])]++;
			B[min(N, i + A[i] + 1)]--;
		}
		ll kei = B[0];
		A[0] = B[0];
		rep1(i, N - 1) {
			kei += (A[i] = A[i - 1] + B[i]);
		}
		if (kei == owa) break;
	}

	rep(i, N) putint(A[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 6204