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

/**
 * https://atcoder.jp/contests/abc095/submissions/11235537 を参考に実装
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long c = scanner.nextLong();
			long[] x = new long[n + 1], v = new long[n + 1];
			x[0] = v[0] = 0L;
			long[] sumV = new long[n + 1];
			sumV[0] = 0L;
			IntStream.rangeClosed(1, n).forEach(i -> {
				x[i] = scanner.nextLong();
				v[i] = scanner.nextLong();
				sumV[i] = sumV[i - 1] + v[i];
			});
			long[] left = new long[n + 1], leftBack = new long[n + 1];
			left[0] = leftBack[0] = 0L;
			IntStream.rangeClosed(1, n).forEach(i -> {
				left[i] = Math.max(left[i - 1], sumV[i] - x[i]);
				leftBack[i] = Math.max(leftBack[i - 1], sumV[i] - x[i] * 2);
			});
			long[] right = new long[n + 1], rightBack = new long[n + 1];
			right[0] = rightBack[0] = 0L;
			IntStream.rangeClosed(1, n).forEach(i -> {
				right[i] = Math.max(right[i - 1], (sumV[n] - sumV[n - i]) - (c - x[n + 1 - i]));
				rightBack[i] = Math.max(rightBack[i - 1], (sumV[n] - sumV[n - i]) - (c - x[n + 1 - i]) * 2);
			});
			System.out.println(IntStream.rangeClosed(0, n)
					.mapToLong(i -> Math.max(left[i] + rightBack[n - i], leftBack[i] + right[n - i])).max()
					.getAsLong());
		}
	}
}


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

int main(){
    int x, y;
    cin >> x >> y;
    bool ans = false;

    for (size_t i = 0; i < 100; i++) {
        for (size_t j = 0; j < 100; j++) {
            if(2*i + 4*j == y && i + j == x){
                ans = true;
            }
        }
    }

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


Measured memory_bytes: 3636
import java.lang.Math;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N+1];

        for (int i = 0; i < N; i++) {
            h[i+1] = sc.nextInt();
        }

        int[] dp = new int[N+1];
        dp[N] = 0;

        for (int i = N-1; i >= 1; i--) {
            List<Integer> candidates = new ArrayList<Integer>();
            for (int j = 1; j <= K; j++) {
                if (i+j > N) { break; }
                candidates.add(Math.abs(h[i] - h[i+j]) + dp[i+j]);
            }

            dp[i] = Collections.min(candidates);
        }

        // System.out.println(Arrays.toString(dp));

        System.out.println(dp[1]);
    }
}


Measured memory_bytes: 151072
#include <iostream>
#include<string>
#include<vector>
#include<math.h>

using namespace std;

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}
	return true;
}

int main() {
	vector<bool> flag(100000 + 10, false);
	vector<int> like2017(100000 + 10, 0);
	vector<int> S(100000 + 10, 0);
	int Q, r, l;

	for (int i = 1; i <= 100000; i++) flag[i] = IsPrime(i);

	for (int i = 1; i <= 100000; i++) {
		if (flag[i] && flag[(i + 1) / 2]) like2017[i] = 1;
	}

	for (int i = 1; i <= 100000; i++) {
		S[i] = like2017[i] + S[i - 1];
	}

		cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> l >> r;
		
		int ans = S[r] - S[l-1];

		cout << ans << "\n";
	}


	return 0;
}

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

vector<int> input(int N) {
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    return vec;
}

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

    vector<int> V(N), C(N);
    V = input(N);
    C = input(N);

    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (V.at(i) - C.at(i) > 0) {
            sum += V.at(i) - C.at(i);
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))

s=[]
o=[-1]*(n+1)
i=1
c=1
l=0
while o[i] == -1:
    o[i] = len(s)
    s.append(i)
    i = a[i-1]
    
c=len(s) - o[i]
l=o[i]
if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l+k])


Measured memory_bytes: 32384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

    ll i,j,n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(i=0;i<n;i++) cin>>a[i];
    sort(all(a));
    ll s = 0;
    for(i=0;i<k;i++) s+=a[i];
    cout<<s;
}

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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll no_of_div(ll a)
{
  ll cnt=0,i;
  if (a==2)return 1;
  for(i=2;i*i<a;i++)
  {
if(a%i==0)cnt+=2;
  }
  if(i*i==a)cnt++;
  return cnt;
}

//vl a(1001);

ll powM(ll a,ll b, ll m)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans%m;
}

ll abc(ll x)
{
  ll cnt_f=0,cnt_s=0;
  while(x)
  {
    ll dig=x%10;
    if(dig==4)cnt_f++;
    else cnt_s++;
    x/=10;
  }
  return (cnt_f==cnt_s);
}

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);

ll n,a,b;
cin>>n>>a>>b;
string s;cin>>s;
s.insert(s.begin(),'d');

ll cnt_a=0,cnt_b=0,bb=1;

for(int i=1;i<s.size();i++)
{
  if(s[i]=='c')cout<<"No"<<"\n";
  else if(s[i]=='a')
  {
    if(cnt_a+cnt_b<a+b)
      {
        cout<<"Yes"<<"\n";
        cnt_a++;
      }
    else cout<<"No"<<"\n";
    //cnt_a++;
  }
  else 
    {
      if((cnt_a+cnt_b<a+b)&&(bb<=b))
        {
          cout<<"Yes"<<"\n";
          cnt_b++;
        }
      else cout<<"No"<<"\n";
        bb++;
    }
}

  return 0;



}



Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const int INF = 1001001001;
 
ll gcd(ll a,ll b){
    if(a%b == 0) return b;
    gcd(b,a%b);
}
 
int main(){
    ll A,B;
    cin >> A >> B;
    ll x = gcd(A,B);
 
    set<ll> a;
    ll i = 2;
    while(x >= i*i){
        if(x%i == 0){
            x /= i;
            a.insert(i);
        }
        else{
            i++;
        }
    }
    a.insert(x);
    a.insert(1);
    cout << a.size() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int x,y,tx,ty;
    cin>>x>>y>>tx>>ty;
    int n=abs(x-tx);
    int m=abs(y-ty);
    cout<<string(n,'R')<<string(m,'U');
    cout<<string(n,'L')<<string(m,'D');
    cout<<'L'<<string(m+1,'U')<<string(n+1,'R')<<'D';
    cout<<'R'<<string(m+1,'D')<<string(n+1,'L')<<'U';
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N;
  cin>>N;
  double sum=0;
  for(ll i=0;i<N;i++) {
double A;
    cin>>A;
    sum+=1/A;
  }
  
  cout<<fixed<<setprecision(7);
  cout<<1/sum<<endl;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}
void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  // int n,k;
  // cin>>n>>k;
  // // ll ans=0;
  // // rep(i,1,n/k+1){
  // //   int left=n-i*k;
  // //
  // //   ans=(ans+nCr(left+i-1,i-1))%mod;
  // // }
  // ll dp[n][k];
  // rep(i,0,n) rep(j,0,i+1) dp[i][j]=
  // cout<<ans<<endl;
  // string s;
  // cin>>s;
  // if(s[s.length()-1]!='s') s+="s";
  // else s+="es";
  // cout<<s<<endl;

  int n;
  cin>>n;
  vector<pii> a(n);
  rep(i,0,n) cin>>a[i].f>>a[i].s;
  int flag=0;
  rep(i,2,n){
    if(a[i-1].f==a[i-1].s && a[i-2].f==a[i-2].s &&  a[i].f==a[i].s) flag=1;
  }
  if(flag) cout<<"Yes\n";
  else cout<<"No\n";
}

int main(){
    optimizeIO();
    int r=1;
    // pre();
    {solve();}
}


Measured memory_bytes: 7024
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const ll INF = 1e9;

const int MAX_N = 101;
const int MAX_V = 100001;
int W[MAX_N];
int V[MAX_N];
ll dp[MAX_N][MAX_V]={0};
ll sumV[MAX_N][MAX_V] = {0};

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

    REP(i, MAX_N) {
        cin >> W[i] >> V[i];
        REP(v, MAX_V) dp[i][v] = LINF;
    }
    dp[0][0] = 0;

    REP(i, N) {
        REP(sumV, MAX_V) {
            if(sumV >= V[i]) {
                chmin(dp[i+1][sumV], dp[i][sumV-V[i]] + W[i]);
            }
            chmin(dp[i+1][sumV], dp[i][sumV]);
        }
    }

    int res=0;
    REP(v, MAX_V) {
        if(dp[N][v] <= limW) res=v;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <stack>

int main(){

  std::stack<int> st;

  int N = 0;
  int a;

  while(N <= 100 && std::cin >> a){
    if(a != 0){
      st.push(a);
    }
    else{
      std::cout << st.top() << std::endl;
      st.pop();
	}
    ++N;
  }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,k;
	double x,ans=0.0;
	cin >> n >> k;
	vd v(n+1,0);
	rep(i,n){
		cin >> x;
		v[i+1]=(x+1)/2;
	}
	for(ll i=1;i<=n;i++) v[i]+=v[i-1];
	rep(i,n-k+1){
		ans=max(ans,v[i+k]-v[i]);
	}
	cout << DOUBLE << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstdio>
#include <random>
#include <chrono>
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define int long long
using namespace std;

const int INF = 2e17;
const int MOD = 1e9 + 7;

vector<vector<int>> g;
vector<int> dp;

void dfs(int v) {
	for (int u : g[v]) {
		if (!dp[u]) dfs(u);
		dp[v] = max(dp[v], dp[u]);
	}
	dp[v]++;
}

void solve() {
	int n, m;
	cin >> n >> m;
	g.resize(n);
	for (int i = 0; i < m; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		g[from].pb(to);
	}

	dp.resize(n);
	for (int i = 0; i < n; i++) {
		if (!dp[i]) {
			dfs(i);
		}
	}
	
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << (ans - 1);
}



signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 8576
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

const int NODE_SIZE = 3*1e5;

int N;   //ノード数
int M;  // エッジ
int R;  //制限ステップ
int start;  //開始ノード番号
int goal;  //目的ノード番号

vector<int> ans(NODE_SIZE);
vector<int> edge[NODE_SIZE];    //ノードの接続関係 <エッジの重み, 接続先ノード>
bool visited[NODE_SIZE];  //ノードに訪れたことがあるか

//深さ優先探索 (グラフ: vector, 再帰)
void dfs_vec(int curNode, int cost){  
  if(visited[curNode]) return;
  visited[curNode] = true;
  cost+=ans[curNode];
  ans[curNode]=cost;

  for(int i=0; i<edge[curNode].size(); i++){
    int nextNode = edge[curNode][i];
    if(!visited[nextNode]){
      dfs_vec(nextNode, cost);
    }
  }
}

int main(){
    int k;
    cin >> N >> k;
    M=N-1;
    REP(i,0,M){
        int A,B;
        cin >> A >>B;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    REP(i,0,k){
        int A,B;
        cin >> A >> B;
        ans[A]+=B;
    }
    dfs_vec(1,0);
    REP(i,1,N){
        cout << ans[i] << " ";
    }
    cout << ans[N] << endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m, q;
  cin >> n >> m >> q;

  vector<vector<int>> cnt(n, vector<int>(n, 0));
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    cnt[l][r]++;
  }

  vector<vector<int>> psum(n);
  for (int i = 0; i < n; ++i) {
    psum[i].push_back(0);
    partial_sum(cnt[i].begin(), cnt[i].end(), back_inserter(psum[i]));
  }

  vector<int> ans;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;

    int a = 0;
    for (int j = l; j <= r; ++j) {
      a += psum[j][r + 1] - psum[j][l];
    }

    ans.push_back(a);
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 3456
def main():
    n, *A = map(int, open(0).read().split())
    A.sort()
    n = A[-1]
    isPrime = [True] * (n + 1)
    prep = 0
    for i in A:
        if prep == i:
            isPrime[prep] = False
            continue
        if isPrime[i]:
            for j in range(i * 2, n + 1, i):
                isPrime[j] = False
        prep = i

    prep = res = 0
    for i in A:
        if prep == i:
            continue
        if isPrime[i]:
            res += 1
        prep = i
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33160
main(){float a,b,c,d,e,f;for(;~scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",c/a-b/a*f,f=(f+c/a*-d)/(e+b/a*-d)));}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;


int main(){
    int n,q;
    string s;
    cin>>n>>q>>s;

    vector<int>l(q),r(q);
    rep(i,q)cin>>l[i]>>r[i];


    vector<int>L(n+1);

    rep2(i,2,n){
        if(s[i-2]=='A'&&s[i-1]=='C')L[i]=L[i-1]+1;
        else L[i]=L[i-1];
    }

    rep(i,q)cout<<L[r[i]]-L[l[i]]<<endl;
}


Measured memory_bytes: 2176
// AOJ 2814: Energy Drink
// 2018.1.4 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define INF 0x50505050
#define MAX 200002

typedef struct { int a, b; char f; } T;
T t[MAX]; int n;
int dp[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(T *a, T *b) { if (a->a - b->a) return a->a - b->a; return b->b - a->b; }

int bsch(int x)
{
	int m, l = 0, r = n;

    while (l < r) {
        m = (l + r) >> 1;
        if (dp[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int main()
{
	int i, a, b, f, sz;

	n = in();
	sz = 0;
	for (i = 0; i < n; i++) {
		a = in(), b = in();
		t[sz].a = a, t[sz++].b = b;
		t[sz].a = b, t[sz].b = a, t[sz++].f = 1;
	}
	n <<= 1; qsort(t, n, sizeof(T), cmp);

	memset(dp, INF, sizeof(dp));
	for (i = 0; i < n; i++) {
		b = t[i].b, f = t[i].f;
		a = bsch(b);
		if ((a & 1) == f) dp[a] = b;
	}
	printf("%d\n", bsch(INF));
	return 0;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(int n){
    int d;
    vector<string> name(n);
    cin >> d;
    rep(i,0,n) cin >> name[i];
    sort(name.begin(),name.end());

    function<vector<string>(const string&)> enumerate_neighborhood=[&](const string &s){
        vector<string> st;
        //replace
        {
            string t=s;
            rep(i,0,s.size()){
                rep(j,0,26){
                    t[i]='a'+j;
                    st.push_back(t);
                }
                t[i]=s[i];
            }
        }
        //insert
        {
            string x;
            rep(i,0,s.size()+1){
                string y=s.substr(i);
                rep(j,0,26){
                    x.push_back('a'+j);
                    auto t=x+y;
                    st.push_back(t);
                    x.pop_back();
                }
                x+=s[i];
            }
        }
        //delete
        {
            string x;
            rep(i,0,s.size()){
                string t=x+s.substr(i+1);
                st.push_back(t);
                x+=s[i];
            }
        }
        //swap adjacent
        {
            string t=s;
            rep(i,0,s.size()-1){
                swap(t[i],t[i+1]);
                st.push_back(t);
                swap(t[i],t[i+1]);
            }
        }
        return st;
    };

    vector<vector<string>> us(n);
    rep(i,0,n){
        us[i]=enumerate_neighborhood(name[i]);
        sort(us[i].begin(),us[i].end());
    }

    int count=0;
    rep(i,0,n){
        rep(j,i+1,n){
            if(d==1){
                if(find(us[i].begin(),us[i].end(),name[j])==us[i].end()) continue;
            }else{
                vector<string> v;
                set_intersection(us[i].begin(),us[i].end(),us[j].begin(),us[j].end(),back_inserter(v));
                if(v.empty()) continue;
            }
            cout << name[i] << "," << name[j] << endl;
            ++count;
        }
    }
    cout << count << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int n;
        cin >> n;
        if(!n) break;
        solve(n);
    }
    return 0;
}

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

const double EPS = 1e-8;
const double INF = 1e12;

//point
typedef complex<double> P;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
// line
struct L : public vector<P> {
	L(const P& a, const P& b) {
		push_back(a); push_back(b);
	}
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;								  // a--c--b on line
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P projection(const L &l, const P &p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}
P reflection(const L &l, const P &p) {
	return p + (double)2 * (projection(l, p) - p);
}
double distanceLP(const L &l, const P &p) {
	return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
	return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
	if (intersectLS(l, s)) return 0;
	return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
	const P r = projection(s, p);
	if (intersectSP(s, r)) return abs(r - p);
	return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
	if (intersectSS(s, t)) return 0;
		return min({distanceSP(s, t[0]), distanceSP(s, t[1]), distanceSP(t, s[0]), distanceSP(t, s[1])});
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

int main() {
	int q;
	cin >> q;
	for(int i=0; i<q; ++i) {
		double x[4], y[4];
		for(int j=0; j<4; ++j) cin >> x[j] >> y[j];
		L l1(P{x[0], y[0]}, P{x[1], y[1]}), l2(P{x[2], y[2]}, P{x[3], y[3]}); 
		cout << fixed << setprecision(15) << distanceSS(l1, l2) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int n; sc(n);
    string s;
    set<string> se;
    rep(i, 0, n) cin >> s, se.insert(s);
    cout << se.size() << endl;
    return 0;
}

Measured memory_bytes: 19232
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pll = pair<ll, ll>;
 
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

void solve() {
    int n; cin >> n;
    vi a(n), b(n);
    for (auto &i : a) cin >> i, i--;
    for (auto &i : b) cin >> i, i--;

    set<pair<ll, ll>> flex;
    vi havea(n), haveb(n);
    for (auto &i : a) havea[i]++;
    for (auto &i : b) haveb[i]++;

    for (int i = 0; i < n; i++) {
        if (n-haveb[i] < havea[i]) {
            cout << "No";
            return;
        }
    }
    cout << "Yes\n";

    vi cur(n);
    for (int i = 0; i < n; i++) {
        if (haveb[i] != 0) {
            flex.insert({
            +(n-havea[i]-haveb[i]), i
            });
            cur[i] = +(n-havea[i]-haveb[i]);
        }
    }


    vi c(n);

    for (int i = 0; i < n; i++) {
        auto p = *flex.begin();
        if (p.second == a[i]) p = *(++flex.begin());
        c[i] = p.second;
        flex.erase(p);
        p.first++;
        haveb[p.second]--;
        cur[p.second]++;
        pair<ll, ll> x = {cur[a[i]], a[i]};
        if (haveb[a[i]] > 0) {
            flex.erase(x);
            x.first++;
            cur[a[i]]++;
            flex.insert(x);
        }
        if (haveb[p.second] != 0)
            flex.insert(p);
    }

    for (auto &i : c) cout << i + 1 << ' ';

}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
}

Measured memory_bytes: 25112
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<pair<int,int> > ans;

int tr(int x) {
    return x > 0 ? 1 : -1;
}

int main(void) {
    int k,x,y;
    cin>>k>>x>>y;

    if(k % 2 == 0 && (abs(x)+abs(y)) % 2 == 1) {
        cout<<-1<<endl;

        return 0;
    }
    if(abs(x) + abs(y) == k) {
        cout<<1<<endl;

        cout<<x<<" "<<y<<endl;

        return 0;
    }

    ans.push_back(make_pair(x,y));
    while(abs(x)+abs(y) > 2*k || ((k % 2 == 1) && (abs(x)+abs(y)) % 2 == 1)) {
        if(abs(x) >= k)
            x -= k * tr(x);
        else {
            int t = k - abs(x);
            x = 0;
            y -= t * tr(y);
        }
        ans.push_back(make_pair(x,y));
    }
    int b = x+y;
    int c = k;
    if(b > 0) {
        b  -= k;
    } else {
        b += k;
    }
    if(x > y)
        c = -k;
    y = (b+c)/2;
    x = y - c;
    ans.push_back(make_pair(x, y));
    cout<<ans.size()<<endl;

    for(int i = ans.size()-1;i >= 0;i--) {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }

    return 0;
}


Measured memory_bytes: 3952
K, N = map(int, input().split())
A = list(map(int, input().split()))
distance = [0] * N
for i in range(N):
    if not i == N-1:
        distance[i] =  A[i+1] - A[i]
    else:
        distance[N-1] = A[0] + (K - A[N-1])
distance.sort()
distance.pop()
print(sum(distance))


Measured memory_bytes: 32292
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
#include <complex>
  
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
  
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef complex<double> P;
int n;
  
double cross(P p1,P p2) {
    return (real(p1)*imag(p2) - imag(p1)*real(p2));
}
double calc_S(P p1,P p2,P p3) {
    double ret = 0.0;
    p1 -= p3;
    p2 -= p3;
  
    ret = cross(p1,p2)/2.0;
      
    return abs(ret);
}
  
int main() {
    cin>>n;
    while(n-->0) {
        double x1_,y1_;
        double x2_,y2_;
        double x3_,y3_;
        cin>>x1_>>y1_>>x2_>>y2_>>x3_>>y3_;
        P p1(x1_,y1_);
        P p2(x2_,y2_);
        P p3(x3_,y3_);
        P A = p1-p2;
        P B = p2-p3;
        P C = p1-p3;
        double S = calc_S(p1,p2,p3);
        double R = abs(A)*abs(B)*abs(C)/S;
        R /= 4.0;
          
        P A1 = 2.0*(p2-p1);
        P B1 = 2.0*(p3-p1);
        P C1 = P(norm(p1)-norm(p2),norm(p1)-norm(p3));
        double X = cross(P(imag(A1),imag(B1)),C1)/cross(A1,B1);
        double Y = cross(C1,P(real(A1),real(B1)))/cross(A1,B1);
        printf("%.3lf %.3lf %.3lf\n",X,Y,R);
  
    }
    return 0;
}

Measured memory_bytes: 1248
import sys
import math
N=int(input())
n=math.ceil(N**0.5)
s=0
t=0
for a in range(1,n+1):
    if a*a<N:
        t=t+1
        #print(a,N-a*a)
        for b in range(a+1,N//a+1):
            if a*b<N:
                s=s+1
            #print(a,b,N-a*b)
    else:
        print(t+2*s)
        sys.exit()

Measured memory_bytes: 9444
#![allow(unused_imports)]
use std::io;
use std::cmp;


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


fn main() {
    let (n, y) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut flg = 0;

    'outer: for j in 0..(n + 1) {
        'inner: for k in 0..(n - j + 1) {
            if 10000 * j + 5000 * k + 1000 * (n - j - k) == y {
                println!("{} {} {}", j, k, n - j - k);
                flg = 1;
                break 'outer;
            }
        }
    }
    if flg == 0 {
        println!("-1 -1 -1");
    }
}

Measured memory_bytes: 4352
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {
    var n = readLine.split(" ").map(_.toInt)

    while( n(0) != 0 || n(1) != 0) {
      for(i <- 0 to n(0)-1) {
        val str = if(i%2==0) "#."*n(1) else ".#"*n(1)
        println(str.take(n(1)))
      }
      println()
      n = readLine.split(" ").map(_.toInt)
    }
  }
}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF 1e9

int W, H;

int main() {
    while (cin >> W >> H, W|H) {
        vvi field(H, vi(W, -1));
        int goal = 0;
        REP(y, H) REP(x, W) {
            string s;
            cin >> s;
            if (s == ".") {
            } else if (s == "S") {
                field[y][x] = 0;
            } else if (s == "G") {
                field[y][x] = -2;
            } else {
                int n = stoi(s);
                field[y][x] = n;
                goal = max(goal, n);
            }
        }
        goal++;
        vector<vector<pii>> treasure(goal+1);
        REP(y, H) REP(x, W) {
            if (field[y][x] == -2) {
                field[y][x] = goal;
            }
            int n = field[y][x];
            if (n >= 0) {
                treasure[n].push_back({x, y});
            }
        }

        vvi dp(H, vi(W, INF));
        int x = treasure[0][0].first, y = treasure[0][0].second;
        dp[y][x] = 0;
        FOR(i, 1, goal+1) {
            for (pii from : treasure[i-1]) {
                int x1 = from.first, y1 = from.second;
                for (pii to : treasure[i]) {
                    int x2 = to.first, y2 = to.second;
                    int step = abs(x1-x2) + abs(y1-y2);
                    dp[y2][x2] = min(dp[y2][x2], dp[y1][x1] + step);
                }
            }
        }
        int gx = treasure[goal][0].first, gy = treasure[goal][0].second;
        cout << dp[gy][gx] << endl;
    }
}

Measured memory_bytes: 1400
// AOJ ALDS1_3_C Doubly Linked List
// 2018.5.1 bal4u
  
#include <stdio.h>
  
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
  
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
  
void skip(int k) { while (k--) gc(); }
  
void out(int n)
{
    int i;
    char ob[20];
  
    if (!n) { pc('0'); return; }
    i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
    while (i--) pc(ob[i]); 
}
  
int que[1500005]; int top, end;
  
int main()
{
    int n, i, t;
    char op;
  
    n = in(); top = 0, end = 1;
    while (n--) {
        if (gc() == 'i') {
            skip(6);
            que[end++] = in();
        } else {
            skip(5);
            op = gc();
            if (op == 'L') {
                skip(4);
                top++;
            } else if (op == 'F') {
                skip(5);
                end--;
            } else {
                que[top] = t = in();
                i = end; while (que[--i] != t);
                if (i > top) {
                    if (end - i < i - top) {
                        while (++i < end) que[i-1] = que[i];
                        end--;
                    } else {
                        while (--i > top) que[i+1] = que[i];
                        top++;
                    }
                }
            }
        }
    }
    i = end-1; out(que[i--]);
    while (i > top) pc(' '), out(que[i--]);
    pc('\n');
    return 0;
}


Measured memory_bytes: 5572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;

void ans(bool qus){
    if (qus == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Ans(bool qust){
    if (qust == true)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

////////////////---START---///////////////

//愚直に解くと計算量がエグくなる

/*ll func(ll s){
    if (s < 2){
        return 1;
    }
    else
        return s * func(s - 2);
}

int main(){
    ll n;
    cin >> n;
    int pro = func(n);
    int i = 1;
    while(pro / pow(10, i) == 0.0){
        pro = pro / pow(10, i);
        i++;
    }
    cout << i << endl;
}*/

int main(){
    ll n;
    cin >> n;
    if (n % 2 != 0){
        cout << 0 << endl;
    }
    else{
        ll count;
        n /= 2;
        while(n){
            count += n / 5;
            n /= 5;
        }
        cout << count << endl;
    }
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int n, k, q;
	cin >> n >> k >> q;

	vector <int> anser(n,0);
	rep(i, n) {
		anser[i] = k - q;
	}
	vector<int>a(q);
	rep(i, q) {
		cin >> a[i];
	}
	rep(i, q) {
		anser[a[i]-1]++;
	}
	rep(i, n) {
		if (anser[i] > 0) {
			c("Yes");
		}
		else c("No");
	}
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    map<int,int> ma;
    rep(i,n){
        ans += ma[i+1-a[i]];
        //cout << i << " " << i+1-a[i] << " " << ma[i+1-a[i]] << endl;
        ma[i+1+a[i]]++;
        //cout << "push:" << i+1+a[i] << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 26892
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	string s;
	cin >> s;
	int len = s.length();
	VI n(len + 1, 0);
	REP(i, len) { n[i] = s[len - (i + 1)] - '0'; }
	int result = 0;
	bool carry = false;
	REP(i, len + 1) {

		if(carry) {
			if(n[i] + 1 == 5 && i != len) {
				if(n[i + 1] >= 5) {
		
					result += 10 - n[i] - 1;
					carry = true;
				} else {

					result += n[i] + 1;
					carry = false;
				}
			} else if(n[i] + 1 >= 5) {
		
				result += 10 - (n[i] + 1);
				carry = true;
			} else {
			
				result += (n[i] + 1);
				carry = false;
			}
		} else {
			if(n[i] == 5 && i != len) {
				if(n[i + 1] >= 5) {
				
					result += 10 - n[i];
					carry = true;
				} else {
				
					result += n[i];
					carry = false;
				}
			} else if(n[i] >= 5) {
			
				result += 10 - n[i];
				carry = true;
			} else {
			
				result += n[i];
				carry = false;
			}
		}
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int n;cin>>n;
  int a[n+10];
  int b[n+10];
  int c[n+10];
  REP(i,n) cin>>a[i];
  REP(i,n) cin>>b[i];
  REP(i,n-1) cin>>c[i];
  int sum=0;
  int bef_i=n+10;
  REP(i,n) {
    int tar_i = a[i]-1;
    sum += b[tar_i];
    if(bef_i+1==tar_i) {
      sum+=c[tar_i-1];
    } 
    bef_i=tar_i;
  }
  pr(sum);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	int cc=0;
	cin>>a>>b>>c;
	for(int i=1;i<=c;i++)
	{
		if(a*i>c){break;}
		else
		{
			cc+=b;
			
		}
		
	
	}
	cout<<cc;
	
}
	

Measured memory_bytes: 256
n = int(input())

card = list(map(int,input().split()))

card.sort(reverse = True)

a = 0

b = 0

turn  = 0

for i in card:
    if turn == 0:
        a += i
        turn = 1
    else:
        b += i
        turn = 0
        
print(a-b)

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

int main(){
  int a, b;

  while(cin >> a >> b, a || b){
    b -= a;

    int ans1000 = b / 1000;
    b %= 1000;
    int ans500 = b / 500;
    b %= 500;

    cout << b / 100 << " " << ans500 << " " << ans1000 << endl;
  }
}

Measured memory_bytes: 1160
from collections import deque

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

while True:
    w, h = map(int, input().split())

    if w == 0:
        exit()

    wall = [list(map(int, input().split())) for _ in range(2 * h - 1)]

    d = [[0]*w for _ in range(h)]
    d[0][0] = 1

    q = deque()
    q.append((0, 0))

    while q:
        sy, sx = q.popleft()
        for i in range(4):
            ty = sy + dy[i]
            tx = sx + dx[i]
            if 0<=tx<w and 0<=ty<h and d[ty][tx] == 0 and wall[sy + ty][(sx + tx) // 2] != 1:
                d[ty][tx] = d[sy][sx] + 1
                q.append((ty, tx))

    print(d[-1][-1])


Measured memory_bytes: 6036
// たくさんの数式
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
string s;
LL f(int w,LL sum,LL c){
    if(w==s.size()) return (sum*(c==0));
    return f(w+1,sum,c*10+s[w]-'0')+f(w+1,sum+c*10+s[w]-'0',0);
}

int main(){
    cin>>s;
    cout<<f(0,0,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long h,w;
    while(cin>>h>>w){
        if(h==1 || w==1){
            cout<<1<<endl;
        }else if(w%2==0){
            cout<<h*w/2<<endl;
        }else{
            if(h%2==0){
                cout<<h*w/2<<endl;
            }else{
                cout<<h*w/2+1<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int n;
	static int[][] a;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[2][n];
		for(int i = 0 ; i < 2 ; i++) {
			for(int j = 0 ; j < n ; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int ans = dfs(0, 0);
		System.out.println(ans);
	}

	public static int dfs(int x, int y) {
		int ret = 0;
		if(x == 0 && y == 0) {
			ret += a[x][y];
		}
		if(x == 1 && y == n - 1) {
			ret = 0;
		}
		if(0 <= x + 1 && x + 1 < 2 && 0 <= y && y < n && 0 <= x && x < 2 && 0 <= y + 1 && y + 1 < n) {
			ret += Math.max(dfs(x + 1, y) + a[x + 1][y], dfs(x, y + 1) + a[x][y + 1]);
		} else if(0 <= x + 1 && x + 1 < 2 && 0 <= y && y < n) {
			ret += dfs(x + 1, y) + a[x + 1][y];
		} else if(0 <= x && x < 2 && 0 <= y + 1 && y + 1 < n) {
			ret += dfs(x, y + 1) + a[x][y + 1];
		} else {
			ret = 0;
		}
		return ret;
	}

}


Measured memory_bytes: 21844
// Union-Find木のテスト
//  ランクなし版

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

struct UnionFind {
  vector<int> par;
  UnionFind( int n ) {
    par.resize(n);
    init(n);
  }
  void init( int n ) {
    for(int i=0; i<n; ++i )  par[i] = i;
  }
  int root( int a ) {
    int pa = par[a];
    if ( pa == a ) return a;
    return par[a] = root(pa);
  }
  bool merge( int a, int b ) {
    int ra = root(a);
    int rb = root(b);
    if ( ra == rb ) return false;
    par[rb] = ra;
    return true;
  }
  bool isSame( int a, int b) {
    int ra = root(a);
    int rb = root(b);
    if ( ra == rb ) return true;
    else return false;
  }
  int CountRoot( int n ) {
    int cnt = 0;
    for (int i=0; i<n; ++i )
      if ( i == par[i] ) cnt++;
    return cnt;
  }
};

int main() {
  int N,M;
  cin >> N >> M;
  UnionFind uf(N);
  REP(i,M) {
    int x,y,z;
    cin >> x >> y >> z;
    x--; y--;
    uf.merge(x,y);
  }
  
  cout << uf.CountRoot(N) << endl;
  
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int n,m,x,ans;
int a[15][15];
int c[15];
int b[15];
template<class T> inline void chk(T &a,T b){
	if(b<a) a=b;
}
int main()
{
	scanf("%d %d %d",&n,&m,&x);
	ans=INF;
	for(int i=0;i<n;++i){
		scanf("%d",&c[i]);
		for(int j=0;j<m;++j) scanf("%d",&a[i][j]);
	}
	for(int i=0;i<1<<n;++i){
		int tot=0;
		memset(b,0,sizeof b);
		for(int j=0;j<n;++j){
			if((1<<j)&i){
				tot+=c[j];
				for(int k=0;k<m;++k){
					b[k]+=a[j][k];
				}
			}
		}
//		printf("i=%d,tot=%d,",i,tot);
//		for(int j=0;j<m;++j) printf("%d ",b[j]);
//		printf("\n");
		for(int k=0;k<m;++k){
			if(b[k]<x) break;
			if(k==m-1) chk(ans,tot);
		}
	}
	if(ans==INF) printf("-1\n");
	else printf("%d\n",ans);
}

Measured memory_bytes: 3712
/**
 * A - Lucky 7
 * https://atcoder.jp/contests/abc162/tasks/abc162_a
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
    // 3 桁の整数 N が与えられます。N のいずれかの桁に数字の 7は含まれますか？
    // 含まれるなら Yes を、含まれないなら No を出力してください。
    string N;
    cin >> N;
    for (int i = 0; i < N.size(); i++) {
        if (N[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 3624