akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		long[] p = new long[w];
		long[] q = new long[h];
		long[] psum = new long[w];
		long ans = 0;
		for(int i=0; i<w; i++){
			p[i] = sc.nextLong();
			ans += p[i];
		}
		for(int i=0; i<h; i++){
			q[i] = sc.nextLong();
			ans += q[i];
		}
		sc.close();
		
		Arrays.sort(p);
		long sum = 0;
		for(int i=0; i<w; i++){
			sum += p[i];
			psum[i] = sum;
		}
		
		for(int i=0; i<h; i++){
			int result = Arrays.binarySearch(p, q[i]) + 1;
			int pos = (result >= 0) ? result : -result;
			ans += (w-pos) * q[i];
			if(pos != 0){
				ans += psum[pos-1];
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 69528
#include<cstdio>
#include<vector>

std::vector<int> A;

int solve(int depth,int m){
  if(m==0){return 1;}
  if(depth==A.size()){return 0;}
  
  return solve(depth+1,m)||solve(depth+1,m-A[depth]);
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;++i){
    int tmp;
    scanf("%d",&tmp);
    A.push_back(tmp);
  }
  
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;++i){
    int tmp;
    scanf("%d",&tmp);
    printf("%s\n", solve(0,tmp)? "yes" : "no");
  }
  
  return 0;
}

Measured memory_bytes: 2748
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int solve_testcase() {
  string s, t; cin >> s >> t;
  if(s == "0" and t == "0") return 1;

  int blow = 0, hit = 0;
  vector<bool> seen(4, false);
  vector<bool> A(10), B(10);
  for(int k=0; k<4; k++) {
    if(s[k] == t[k]) {
      hit++;
    }
    else {
      A[ s[k] - '0' ] = true;
      B[ t[k] - '0' ] = true;
    }
  }

  for(int i=0; i<10; i++) {
    if(A[i] and B[i]) blow++;
  }

  cout << hit << " " << blow << endl;
  return 0;
}

int main() {
  while(!solve_testcase());
  return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,d,s=0;
	scanf("%lld%lld",&n,&d);
	for(int i=0;i<n;i++){
		long long x,y;
		scanf("%lld%lld",&x,&y);
		if(x*x+y*y<=d*d)s++;
	}
	printf("%lld",s);
} 

Measured memory_bytes: 3828
sub f{my$p=$h[my$c=$c[$_]-=my$r=$s=$v[++$_]=1];$v[$_--]or$a[$c]-=-$s*(-$s+($s=($r+=&f)-$h[$c]+$p))for@$_;$a[$c]+=($p+$r-$h[$c])*(@a-($h[$c]=$p+$r))+1;$r}@a=(0)x<>;@c=glob<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f;print"@a"

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

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int K;
    cin >> K;

    int A, B;
    cin >> A >> B;

    bool ans = false;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) ans = true;
    }

    cout << (ans ? "OK" : "NG") << endl;

    return 0;
}


Measured memory_bytes: 3648
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    cout<<(1000-a%1000)%1000;
}

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

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
 
#define INF 10e9
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
 
int main() {
    int n, d;
    cin >> n >> d;

    if(n % (2*d+1) == 0){
        cout << n / (2*d+1) << endl;
    }else{
        cout << n / (2*d+1) + 1 << endl;
    }
}

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

using namespace std;

#define MOD 1000000007

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long combi1(long n, long k){  
    if(n < k) return 0;
    static long pre;
    if(k == 0 || n == k){
        pre = 1;
        return 1;
    }
    long next = pre * n;
    next %= MOD;
    next *= modinv((n-k), MOD);
    next %= MOD;
    pre = next;
    return next;
}

int main(){
    int N, K;
    cin >> N >> K;
    long A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A, A+N);
    long ans = 0;
    for(long i=0; i<N; i++){
        long c = combi1(i, K-1);
        ans += A[i] * c;
        ans %= MOD;
        ans -= A[N-1-i] * c;        
        ans %= MOD;
    }
    cout << (ans + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 1024
//author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) begin(x),end(x)

const int N = 1e5 + 10;
const int M = 1e9 + 7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}

void precomp() {

}


void solve() {
	ll x; cin >> x;
	ll c = 100LL, a = 0LL;
	while (c < x) {
		c += c / 100L;
		a += 1LL;
	}
	cout << a << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	precomp();
	int t = 1; // cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}



Measured memory_bytes: 3600
from collections import Counter

N=int(input())
dic={}

ans=0

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in dic:
        ans+=dic[sorted_s]
        dic[sorted_s]+=1
    else:
        dic[sorted_s]=1
print(ans)

Measured memory_bytes: 22348
N = int(input())
Q = sorted([[int(input()), i//N] for i in range(2*N)])

mod = 10**9 + 7
ans = 1
S = [0, 0]

for i in Q:
    if S[1-i[1]] == 0:
        S[i[1]] += 1
    else:
        ans = (ans*S[1-i[1]]) % mod
        S[1-i[1]] -= 1

print(ans)

Measured memory_bytes: 32304
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1,inf);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]=min(date[k],x);
		while(k>0){
			k=(k-1)/2;
			date[k]=min(date[k*2+1],date[k*2+2]);
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=inf;
		while(a<b){
			if(a%2==0) m=min(m,date[a++]);
			if(b%2==0) m=min(m,date[--b]);
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

int n,m;
string s;
vi dp;

int main(){
	cin>>n>>m>>s;
	Segment_Tree st(n+1);
	st.Update(n,0);
	for(int i=n-1;i>=0;i--) if(s[i]=='0'){
		st.Update(i,st.Query(i+1,min(n+1,i+m+1))+1);
	}
	int k=st.Open(0),I=0;
	vi a;
	if(k==inf){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++) if(st.Open(i)==k-1){
		a.push_back(i-I);
		I=i;k--;
	}
	int N=a.size();
	for(int i=0;i<N;i++) cout<<a[i]<<" \n"[i==N-1];
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n;
    cin >> n;
    int ans = 1;
    cout << n * n * n << '\n';

    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

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

int main() {
	list <char> ls;
	string s, right, left;	cin >> s;
	int n = s.length();
	loop (i, n) {
		ls.push_back(s[i]);
	}
	int q;	cin >> q;
	bool rev = 0;
	for (int i = 0; i < q; i++) {
		int x, y;	char temp;
		cin >> x;	--x;
		if (!x) {
			rev = rev ^ 1;
		}
		else {
			cin >> y;	--y;	cin >> temp;
			if (!(y ^ rev)) {
				ls.push_front(temp);
			}	else {
				ls.push_back(temp);
			}
		}
	}
	if (rev) {
		reverse(ls.begin(), ls.end());
	}
	for (auto i: ls) {
		cout << i;
	}
	cout << endl;


	return 0;
}

Measured memory_bytes: 9984
c = str(input())
if c == "a":
    print("b")
elif c == "b":
    print("c")
elif c == "c":
    print("d")
elif c == "d":
        print("e")
elif c == "e":
    print("f")
elif c == "f":
    print("g")

elif c == "g":
    print("h")
elif c == "h":
    print("i")
elif c == "i":
        print("j")
elif c == "j":
    print("k")
elif c == "k":
    print("l")

elif c == "l":
    print("m")
elif c == "m":
    print("n")
elif c == "n":
        print("o")
elif c == "o":
    print("p")
elif c == "p":
    print("q")
elif c == "q":
    print("r")

elif c == "r":
    print("s")
elif c == "s":
    print("t")
elif c == "t":
        print("u")
elif c == "u":
    print("v")
elif c == "v":
    print("w")

elif c == "w":
    print("x")
elif c == "x":
    print("y")
elif c == "y":
        print("z")


Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> b(n - 1);
  bool has_one = false;
  for (int i = 0; i < n - 1; ++i) {
    b[i] = abs(s[i + 1] - s[i]);
    if (b[i] == 1)
      has_one = true;
  }
  int factor = 1;
  if (!has_one) {
    factor = 2;
    for (int i = 0; i < n - 1; ++i)
      b[i] >>= 1;
  }
  int sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (((n - 2) & i) == i)
      sum = (sum + b[i]) % 2;
  }
  cout << sum * factor;
}

Measured memory_bytes: 5252
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto ST = readln.split.to!(string[]);
  auto AB = readln.split.to!(ulong[]);
  auto U = readln.chomp.to!(string);

  if (U == ST[0]) AB[0]--;
  if (U == ST[1]) AB[1]--;

  writefln("%s %s", AB[0], AB[1]);
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    var  a = Long.MAX_VALUE
    for (i in 1 .. Math.sqrt(n.toDouble() + 1).toInt()) {
        if (n % i == 0L){
            a = (n / i) + i - 2
        }
    }
    println(a)
}

Measured memory_bytes: 31788
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#define int long long
#define vi vector<int>
#define scan(a,n) for(int i = 0; i < n ; i++) cin>>a[i]
#define loop(i,a,b) for (int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
using namespace std;

int32_t main()
{
	int k,n;
	cin>>k>>n;
	vi arr(n);
	scan(arr,n);
	int sum = 0;
	int maxd = k - arr[n-1] + arr[0];
	loop(i,0,n-1)
	{
		int d = arr[i+1] - arr[i];
		if(d>maxd)
			maxd = d;
	}
	cout<<k - maxd<<endl;
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=105;
//i_am_noob
int a,b,c;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> a >> b >> b >> b >> b >> c;
	print1(c<b-a?":(":"Yay!");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair <int, int>
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 100005;
const int mod = 1e9 + 7;
int main() {
    io;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d));
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long

int main(){
	int H,W,A,B;
	cin>>H>>W>>A>>B;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int tmp=1;
			if(j<A)tmp^=1;
			if(i<B)tmp^=1;
			cout<<tmp;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;
int const MAX_N = 2505;

vector<int> G[MAX_N];
vector<int> rG[MAX_N];
bool ok[MAX_N];
bool rok[MAX_N];
bool use[MAX_N];

void dfs(int v) {
    if(ok[v]) return;
    ok[v] = true;
    for(int nv : G[v]) {
        dfs(nv);
    }
}

void rdfs(int v) {
    if(rok[v]) return;
    rok[v] = true;
    for(int nv : rG[v]) {
        rdfs(nv);
    }
}

bool bellman_ford(vector<tuple<int,int,int>> &Es, int V, int s, vector<ll> &dist) {
    dist.resize(V,INF);
    dist[s] = 0;
    int cnt = 0;
    while(cnt < V) {
        bool end = true;
        for(auto e : Es) {
            int a,b,c;
            tie(a,b,c) = e;
            if(!use[a]) continue;
            if(!use[b]) continue;
            if(dist[a] != INF && dist[b] > dist[a] + c) {
                dist[b] = dist[a] + c;
                end = false;
            };
        }
        if(end) break;
        cnt++;
    }
    return (cnt == V);
}

int main()
{
    int n, m, p;
    cin >> n >> m >> p;

    vector<tuple<int,int,int>> edges;
    rep(i,m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--; c -= p; c *= -1;
        edges.emplace_back(a,b,c);
        G[a].push_back(b);
        rG[b].push_back(a);
    }

    dfs(0); rdfs(n-1);
    rep(i,n) use[i] = ok[i] & rok[i];

    vector<ll> dist;
    if(bellman_ford(edges, n, 0, dist)) cout << -1 << endl;
    else cout << max(0LL,-dist[n-1]) << endl;
    return 0;
}

Measured memory_bytes: 4020
#include<stdio.h>
int main(){
int a,b,d,r;
double f,g,h;
scanf("%d %d",&a,&b);
g=a;
h=b;
d=a/b;
r=a%b;
f=g/h;
printf("%d %d %.6lf\n",d,r,f);
return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r=0,b=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='R')r++;
    else b++;
  } 
  if(r>b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
int main(){
    int n,k;cin >> n >> k;
    string s;cin >> s;
    int score=0;
    for(int i=0; i<n-1; i++){
        if(s[i]==s[i+1]) score++;
    }
    score=min(score+2*k,n-1);
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 512
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
if abs(b-a)%2 == 0:
    print(abs(b-a)//2)
else:
    print(min(a + (abs(b-a)-1)//2, n-b+1+(abs(b-a)-1)//2))


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

using namespace std;

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

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    v.erase(unique(v.begin(), v.end()), v.end());
    rep(i, v.size()) {
        if (i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}



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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int R,C,N;cin>>R>>C>>N;
  typedef pair<int,int> P;
  vector<P> v;
  for(int i=0;i<N;i++){
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(a!=0&&a!=R&&b!=0&&b!=C)continue;
    if(c!=0&&c!=R&&d!=0&&d!=C)continue;
    int A,B;
    if(a==0)A=b;
    if(a==R)A=C+R+C-b;
    if(b==0)A=C+R+C+R-a;
    if(b==C)A=C+a;
    v.push_back(P(A,i));
    if(c==0)B=d;
    if(c==R)B=C+R+C-d;
    if(d==0)B=C+R+C+R-c;
    if(d==C)B=C+c;
    v.push_back(P(B,i));
  }
  int V=v.size();
  if(V==0)fin("YES");
  sort(v.begin(),v.end());
  stack<int> s;
  vector<int> used(N,-1);
  for(int i=0;i<3*N;i++){
    int T=v[i%V].second;
    if(used[T]==-1){
      used[T]=i;
      s.push(i);
    }
    else{
      if(s.top()>used[T])fin("NO");
      s.pop();
      used[T]=-1;
    }
  }
  fin("YES");
}
  //円周上に２点のペアがたくさんある　一点が他のペアの中にあるような状態が存在するかを判定


Measured memory_bytes: 2544
from math import sqrt, floor
N, K = map(int, input().split())
mod = 10**9+7

sn = floor(sqrt(N))
t = N//(sn + 1)

dp1 = [0] + [1]*sn + [0]
dp2 = [0] + [N//j - N//(j+1) for j in range(1, t+1)]
dp2 += [0]*(len(dp1) - len(dp2))
C = dp2[:]
for _ in range(K-1):
    d1 = [0]*(sn + 2)
    d2 = [0]*(sn + 2)
    
    sumd1 = 0
    for d in dp1[1:]:
        sumd1 = (sumd1 + d) % mod
    
    d1[1] = sumd1
    
    for i in range(1, sn+1):
        d2[i] = (d2[i] + dp1[i]) % mod
        d1[1] = (d1[1] + dp2[i]) % mod
        d1[i+1] = (d1[i+1] - dp2[i]) % mod
    
    for i in range(1, sn+2):
        dp1[i] = (d1[i] + dp1[i-1])%mod
        dp2[i] = (d2[i] + dp2[i-1])%mod
    dp1[-1] = 0
    
    dp2 = [d*c%mod for d, c in zip(dp2, C)]
ans = 0
for d in dp1:
   ans = (ans + d)%mod
for d in dp2:
    ans = (ans + d)%mod
print(ans)

Measured memory_bytes: 74460
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A, B, C, D): (i64, i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    fn gcd(a: i64, b: i64) -> i64 {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }

    let f = |x| x - (x / C + x / D - x / (C / gcd(C, D) * D));
    let ans = f(B) - f(A - 1);

    println!("{}", ans);
}


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

// U, R, D, L
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

struct State { int currDistance, prevDir, x, y; };
struct StateComparator{
    bool operator()(State const& s1,State const& s2 ){
        return s1.currDistance > s2.currDistance;
    }
};
    int main() {
        int H,W,K ;
        scanf("%d%d%d",&H,&W, &K);
        int x1, y1, x2, y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        x1--;
        y1--;
        y2--;
        x2--;
        vector<vector<char> > board(H, vector<char>(W, '.'));
        vector<vector<int> > dist(H, vector<int>(W, -1));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                scanf(" %c", &board[i][j]);
            }
        }
        // we start at (x1,y1) and want to go to (x2,y2)
        dist[x1][y1] = 0;
        priority_queue<State, vector<State>, StateComparator> pq;
        pq.push(State{0, -1 ,x1,y1});
        while(pq.size() > 0){
           State s = pq.top();
           pq.pop();
            if (s.currDistance != dist[s.x][s.y]){
                continue; // if it`s been already processed
            }
            if (s.x == x2 && s.y == y2){
                break;
            }
            for(int i = 0; i< 4; i++){
                if ((i + 2) % 4 == s.prevDir || i == s.prevDir) {
                    continue;
                }
                for(int k = 1 ; k <= max(H, W); k++){
                    int newx = s.x + dx[i] * k;
                    int newy = s.y + dy[i] * k;
                    if (newx < 0 || newy < 0 || newx >= H || newy >= W){
                        break;
                    }
                    if (board[newx][newy] == '@') break;
                    int new_d = s.currDistance + (k + K - 1) / K;
                    if (dist[newx][newy] == -1 || dist[newx][newy] > new_d) {
                        dist[newx][newy] = new_d;
                        pq.push(State{new_d, i, newx, newy});
                    }
                }
            }
        }
        printf("%d\n", dist[x2][y2]);

}

Measured memory_bytes: 28444
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;
vll adj[MAXN];
bool vis[MAXN];
ll cnt=0;
void dfs(ll cur){
	++cnt;
	vis[cur]=1;
	for(auto e:adj[cur]){
		if(!vis[e]){
			dfs(e);
		}
	}
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    set<pair<ll,ll> > st;
    for (int i = 0; i < m; ++i)
    {
    	ll x,y;
    	cin>>x>>y;
    	if(x>y)swap(x,y);
    	st.insert({x,y});
    }
    for(auto e:st){
    	ll x=e.F,y=e.S;
    	adj[x].pb(y);
    	adj[y].pb(x);
    }
    ll ans=0;
    for (int i = 1; i <= n; ++i)
    {
    	if(!vis[i]){
    		cnt=0;
    		dfs(i);
    		ans=max(ans,cnt);
    	}
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 33556
N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

ans = 0
while A:
    a = A.pop()
    b = B.pop()
    a += ans
    c = a % b
    if c != 0: ans += b-c
print(ans)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

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

  int N;
  cin >> N;
  map<int, int> mp;
  int a;
  rep(i, 0, N) {
    cin >> a;
    mp[a]++;
  }

  int ans = 0;
  int even_cnt = 0;
  for (auto pi: mp) {
    if (pi.second % 2 == 1) ans++;
    if (pi.second % 2 == 0) even_cnt++;
  }

  ans += 2*(even_cnt / 2);

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N);
    for(auto& x:A) cin >> x;
    sort(A.begin(),A.end());
    int ans = 0;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) for(int k=j+1;k<N;k++){
        if(A[i]==A[j] || A[j]==A[k] || A[k]==A[i]) continue;
        ans += A[k]<A[i]+A[j];
    }
    cout << ans << "\n";
}

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
//#define INF             1000000000
//#define INF             100000000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a, b, k;
	cin >> a;
	lpi(i, 1, 5)
		cin >> b;
	cin >> k;
	cout << ( (b-a) <= k ? "Yay!" : ":(");
	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false); cin.tie(NULL);
  int n;
  string s;
  cin >> n >> s;
  int l = 1, r = n / 2, ans = 0;
  while (l <= r) {
    map<string, int> m;
    int mid = l + r >> 1;
    bool check = false;
    for (int i = 0; i + mid - 1 < n; i++) {
      auto itr = m.find(s.substr(i, mid));
      if (itr != m.end()) {
        if (itr->second + mid <= i) {
          check = true;
          break;
        }
      } else {
        m.emplace(s.substr(i, mid), i);
      }
    }
    if (check) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6708
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > edges(n);
    vector<int> cnt(n, 0);
    for(int i=0; i<n+m-1; ++i){
        int a, b;
        cin >> a >> b;
        -- a;
        -- b;
        edges[a].push_back(b);
        ++ cnt[b];
    }

    int root = find(cnt.begin(), cnt.end(), 0) - cnt.begin();
    vector<int> parent(n, -1);
    queue<int> q;
    q.push(root);
    while(!q.empty()){
        int curr = q.front();
        q.pop();
        for(int next : edges[curr]){
            -- cnt[next];
            if(cnt[next] == 0){
                parent[next] = curr;
                q.push(next);
            }
        }
    }
    for(int i=0; i<n; ++i)
        cout << (parent[i] + 1) << endl;

    return 0;
}


Measured memory_bytes: 7040
A, B, C = input().split()
A, B, C = int(A), int(B), int(C)

container1 = B
container2 = C

if A-B > C:
    container1 += C
    container2 = 0
else:
    container1 += A-B
    container2 -= A-B
print(container2)

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

int main() {
    int n, h;
    cin >> n >> h;
    int a[n], b[n];
    for(int i = 0; i < n; i++)cin >> a[i] >> b[i];

    int amax = *max_element(a, a + n);
    sort(b, b + n);
    reverse(b, b + n);

    int damage = 0;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(amax < b[i] && damage < h) {
            damage += b[i];
            ans++;
        }
        else break;
    }

    if(damage < h) ans += (h - damage + amax - 1) / amax;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[500001],ans;
int big(int l,int r,int x){
	return a[l]>x&&a[r]>x;
}
int small(int l,int r,int x){
	return a[l]<=x&&a[r]<=x;
}
int pd(int x){
	int i;
	for(i=0;i<n-1;i++){
		if(big(n+i,n+i+1,x)||big(n-i,n-i-1,x))return 0;
		if(small(n+i,n+i+1,x)||small(n-i,n-i-1,x))return 1;
	}
	return small(1,1,x);
}
int main(){
	int i,j,l,r,mid;
	scanf("%d",&n);
	for(i=1;i<=n*2-1;i++)scanf("%d",&a[i]);
	l=1;r=n*2-1;ans=n*2-1;
	while(l<=r){
		mid=(l+r)/2;
		if(pd(mid))ans=mid,r=mid-1;
		 else l=mid+1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll a[100005] , b[100005] , c[100005];
int main()
{
    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
    	cin >> a[i];
    }
    b[0] = a[0];
    for(int i = 1 ; i < n ; i++){
    	b[i] = __gcd(b[i - 1] , a[i]);
    }
    c[n -1] = a[n - 1];
    for(int i = n - 2; i >= 0 ; i--)
    {
    	c[i] = __gcd(c[i + 1] , a[i]);
    }
    ll mm = -1;
    for(int i = 1 ; i < n - 1; i++){
    	mm = max(mm , __gcd(b[i - 1],c[i + 1]));
    }
    mm = max(mm , c[1]);
    mm = max(mm , c[0]);
    mm = max(mm , b[n - 2]);
    cout << mm << endl;


}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(x,y,z) for (int x=y; x<=z; x++)
#define downrep(x,y,z) for (int x=y; x>=z; x--)
#define ms(x,y,z) memset(x,y,sizeof(z))
#define LL long long
#define repedge(x,y) for (int x=hed[y]; ~x; x=edge[x].nex)
inline int read(){
	int x=0; int w=0; char ch=0;
	while (ch<'0' || ch>'9') w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w? -x:x;
}
int a,b,ans;
int main(){
	a=read(); b=read();
	rep(i,1,3) if ((a*b*i)&1) ans=1;
	if (ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long a,b,i,n;

  while(scanf("%ld",&n),n!=0){
    a=0;
    for(i=5;i<=n;i++){
      b=i;
      while(b>0){
        if(b%5!=0) break;
        a++;
        b=b/5;
      }
    }
    printf("%ld\n",a);
  }
  return 0;
}

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

int main(){
  ll n;
  ll a[81];
  cin >> n;
  rep(i,n) cin >> a[i];

  ll m = 1000;
  rep(i,n-1) {
    ll s = 0;
    if(a[i] < a[i+1]) {
      s = m/a[i];
      m += (a[i+1]-a[i])*s;
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 3588
def p_d():
    n, k = map(int, input().split())
    *s, = map(int, input())
    ans = 0
    l, r = 0, 0
    count = 0
    while r < n:
        while r < n and count < k:
            if s[r] == 0:
                count += 1
                while r < n and s[r] == 0:
                    r += 1
            else:
                while r < n and s[r] == 1:
                    r += 1
        while r < n and s[r] == 1:
            r += 1
        ans = max(ans, r - l)
        while l < r and s[l] == 1:
            l += 1
        while l < r and s[l] == 0:
            l += 1
        count -= 1

    print(ans)


if __name__ == '__main__':
    p_d()


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

using namespace std;

long long n, x;

vector<long long> p(1, 1), a(1, 1);

long long cnt(long long n, long long x)
{
	if (n == 0)
		return 1;
	else if (x == 1)
		return 0;
	else if (x <= a[n - 1] + 1)
		return cnt(n - 1, x - 1);
	else if (x == a[n - 1] + 2)
		return p[n - 1] + 1;
	else if (x <= 2 * a[n - 1] + 2)
		return p[n - 1] + 1 + cnt(n - 1, x - a[n - 1] - 2);
	return 2 * p[n - 1] + 1;
}

int main()
{
	cin >> n >> x;
	for (int i = 0; i <= 50; i++)
	{
		p.push_back(p[i] * 2 + 1);
		a.push_back(a[i] * 2 + 3);
	}
	cout << cnt(n, x) << endl;

	return 0;
}


Measured memory_bytes: 256
def prison(n,m,security):
    l = 0
    r = 1
    through = [False]*(n+1)
    gate = [1,n]
    for i in range(m):
        if security[i][r] < gate[r]:
            gate[r] = security[i][r]

        if  gate[l] < security[i][l]:
            gate[l] = security[i][l]


    for i in range(1,n+1):
        if gate[l] <= i and i <= gate[r]:
            through[i] = True
        else:
            through[i] = False


#        print("i=%d, %s" %(i,through[i]))

    sucess = filter(lambda x:x == True, through)
    return len(sucess)

if __name__ == '__main__':
    n,m = map(int,raw_input().split())

    security = [list(map(int,raw_input().split())) for _ in range(m)]

    print prison(n,m,security)

Measured memory_bytes: 24436
#--81

N = int(input())

kuku = [0] * 81

k = 0
for i in range(1,10):
  for j in range(1,10):
    k = k + 1
    kuku[k-1] = i * j
    if (i*j == N):
      print("Yes")
      exit()
    else:
      pass

print("No")



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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[55];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int mx=0; int idx=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(abs(a[i])>=mx)
		{
			mx=abs(a[i]); idx=i;
		}
	}
	vector<ii> moves;
	for(int i=0;i<n;i++)
	{
		if(i!=idx)
		{
			moves.pb(mp(idx,i));
		}
	}
	if(a[idx]>=0)
	{
		for(int i=0;i<n-1;i++)
		{
			moves.pb(mp(i,i+1));
		}
	}
	else
	{
		for(int i=n-1;i>0;i--)
		{
			moves.pb(mp(i,i-1));
		}
	}
	cout<<moves.size()<<'\n';
	for(int i=0;i<moves.size();i++)
	{
		cout<<moves[i].fi+1<<' '<<moves[i].se+1<<'\n';
	}
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (1..2).map { (1..n).map { sc.nextInt() } }
    val dp = Array(2) {Array(n) {0} }

    dp[0][0] = a[0][0]
    for (i in 0 until 2) {
        for (j in 0 until n) {
            if (i == 0) {
                dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + a[i + 1][j])
            }
            if (j < n - 1) {
                dp[i][j + 1] = Math.max(dp[i][j + 1], dp[i][j] + a[i][j + 1])
            }
        }
    }
    println(dp[1][n - 1])
}

Measured memory_bytes: 31520
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
P = zz()
change_lis = []
ans = 0
for i in range(N-1):
    if (P[i] == (i + 1)):
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1
if (P[-1] == N):
    ans += 1
print(ans)


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

using ll = long long;
const int maxn = 2e3 + 3;

int n, a[maxn], o[maxn];
ll d[maxn][maxn];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    std::iota(o + 1, o + n + 1, 1);
    std::sort(o + 1, o + n + 1, [] (int i, int j) {
        return a[i] > a[j];
    });
    for(int t = 1; t <= n; ++t) {
        int i = o[t];
        ll u = a[i];
        for(int j = 0; j <= t; ++j) {
            int k = n - (t - j) + 1;
            if(j < t)
                d[t][j] = std::max(d[t][j], d[t - 1][j] + std::abs(i - k) * u);
            if(j)
                d[t][j] = std::max(d[t][j], d[t - 1][j - 1] + std::abs(i - j) * u);
        }
    }
    printf("%lld\n", *std::max_element(d[n], d[n] + n + 1));
    return 0;
}

Measured memory_bytes: 26412
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(void){
	int a[100001];
	int n,k,sum,t;
	for(;;){
		scanf("%d%d",&n,&k);
		if(n==0&&k==0)return 0;
		sum=t=0;
		for(int i=0;i<n;i++){
			scanf("%d",a+i);
			t+=a[i];
			if(i>=k){
				t-=a[i-k];
				sum=max(sum,t);
			}
			//printf("t %d\n",t);
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 1416
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

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

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

  int ans = 0;
  for (int i = 0; i < N; i++){
    int H; cin >> H;
    if (H >= K){
      ans ++;
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;

int a, b, c, d, e, f, ta = -1, tb = 1;
bool x[2][3005];

int main() {
	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
	a *= 100;
	b *= 100;
	x[0][0] = x[1][0] = 1;
	for (int i = 0; i < f; i++) {
		if (x[0][i]) {
			if (i + a <= f)
				x[0][i + a] = 1;
			if (i + b <= f)
				x[0][i + b] = 1;
		}
		if (x[1][i]) {
			if (i + c <= f)
				x[1][i + c] = 1;
			if (i + d <= f)
				x[1][i + d] = 1;
		}
	}
	for (int i = 100; i <= f; i += 100)
		if (x[0][i])
			for (int j = 0; i + j <= f && j <= e * i / 100; j++)
				if (x[1][j])
					if (j * tb > ta * (i + j))
						ta = j, tb = i + j;
	printf("%d %d\n", tb, ta);
	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let t = read_vec::<i64>();
    let n = t[0];
    let d = t[1];
    let mut ans = 0;
    for _ in 0..n {
        let t = read_vec::<i64>();
        let x = t[0];
        let y = t[1];
        if x * x + y * y <= d * d {
            ans += 1;
        }
    }
    println!("{}", ans);
}

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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;


const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

ll ans = 0;

void solve(std::string S) {
    S[3] = '8';
    cout << S << endl;
}
signed main() {
    std::string S;
    std::cin >> S;
    solve(S);

    return 0;
}


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

def solve():
    N, Q = list(map(int, input().split(" ")))
    S = input()
    L, R = [], []
    for i in range(Q):
        l, r = list(map(int, input().split(" ")))
        L.append(l)
        R.append(r)
    
    # 累積話で解く
    accumulations = [0] * N

    for i in range(1, N):
        if S[i-1]+S[i] == "AC":
            accumulations[i] = accumulations[i-1] + 1
        else:
            accumulations[i] = accumulations[i-1]

    for i in range(Q):
        if L[i]-1 == 0:
            print(accumulations[R[i]-1])
            continue
        else:
            print(accumulations[R[i]-1] - accumulations[L[i]-1])
            continue


if __name__ == "__main__":
    solve()

Measured memory_bytes: 14256
import collections

s = input()
t = input()
mod = len(s)
s_idx = dict([])
for i, key in enumerate(s):
    try:
        s_idx[key].append(i + 1)
    except KeyError:
        s_idx[key] = [i + 1]

def binary_search(li, tmp, ng, ok):
    mid = (ng + ok) // 2
    if ok - ng < 2:
        if ok == len(li):
            return mod + li[0]
        else:
            return li[ok]
    if li[mid] <= tmp: return binary_search(li, tmp, mid, ok)
    else: return binary_search(li, tmp, ng, mid)

ans = 0
tmp = 0
for key in t:
    try:
        i = binary_search(s_idx[key], tmp, -1, len(s_idx[key]))
        ans += i - tmp
        tmp = i % mod
    except KeyError:
        ans = -1
        break
print(ans)

Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	
}
int main(){
  
  ll N,K;
  cin>>N>>K;
  vector<ll>x(N);
  
  rep(i,N){
    cin>>x[i];
  }
  
  ll min2=INF;
  rep(i,N-K+1){//iは範囲の最初
    ll sum=min(abs(x[i])+abs(x[i+K-1]-x[i]),abs(x[i+K-1])+abs(x[i]-x[i+K-1]));
if(min2>sum){
  min2=sum;
}
    
}
cout<<min2<<endl;
}
    

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

int main() {
	int n,count=0;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	sort(arr,arr+n);
	count=0-arr[(n/2)-1]+arr[(n/2)];
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

struct Card{
  char suit;
  char value;
};

void bubble(struct Card A[], int n){
  int i, j;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j].value < A[j-1].value ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int n){
  int i, j, mini;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j].value < A[mini].value ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

void print(struct Card A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i ) printf(" ");
    printf("%c%c", A[i].suit, A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[], struct Card C2[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( C1[i].suit != C2[i].suit ) return 0;
  }
  return 1;
}

int main(){
  struct Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c ", &C1[i].suit, &C1[i].value);
  }

  for ( i = 0; i < n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  print(C1, n);
  printf("Stable\n");
  print(C2, n);
  if ( isStable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2100