akhauriyash/Code-Regression huggingface dataset:
// Created by bisuk on 2014/09/18.
//

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws java.io.IOException {
		//int[] ls = new int[10];
		Integer[] ls = new Integer[10];

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for (int i = 0; i < 10; i++) {
			String s = in.readLine();
			ls[i] = Integer.valueOf(s);
		}

		//System.out.println("ls: " + Arrays.toString(ls));
		//Arrays.sort(ls);
		Arrays.sort(ls, Collections.reverseOrder());

		//System.out.println("ls: " + Arrays.toString(ls));

		//for(int h : ls){
		for (int i = 0; i < 3; i++) {
			System.out.println(ls[i]);
		}
	}
}

/*
	> javac xxx.java
	> java xxx
*/

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

#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";

ll mod = 1000000007;

using namespace std;

int main()
{
	
	 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	 int n;
	 cin>>n;
	 int arr[n];
	 int a,b;
	 cin>>a>>b;
	 for (int i = 0; i < n; ++i)
	 {
	 	cin>>arr[i];
	 }

	 

	 int cnt1= 0,cnt2=0,cnt3=0;

	 for (int i = 0; i < n; ++i)
	 {
	 	if(arr[i] <= a)
	 		cnt1++;
	 	else if(arr[i] >= a+1 && arr[i] <= b)
	 		cnt2++;
	 	else if(arr[i] >= b+1)
	 		cnt3++;
	 }

	 cout<<min(cnt1,min(cnt3,cnt2))<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];
        for (int i = 0; i < N; ++i) a[i] = Integer.parseInt(sc.next());
        for (int i = 0; i < N; ++i) b[i] = Integer.parseInt(sc.next());
        for (int i = 0; i < N; ++i) c[i] = Integer.parseInt(sc.next());
        Arrays.sort(a);
        Arrays.sort(c);

        long res = 0;
        for (int i = 0; i < N; ++i) {
            int key = b[i];
            int left = -1;
            int right = N;
            while (right - left > 1) {
                int mid = (right + left) / 2;
                if (key <= a[mid]) right = mid;
                else left = mid;
            }
            long tmpA = right;

            left = -1;
            right = N;
            while (right - left > 1) {
                int mid = (right + left) / 2;
                if (key < c[mid]) right = mid;
                else left = mid;
            }
            long tmpB = N - right;

            res += tmpA * tmpB;
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 63652
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a;
	cin>>a;
	if(a=='T'){
		cout<<'A'<<endl;
	}else if(a=='A'){
		cout<<'T'<<endl;
	}else if(a=='G'){
		cout<<'C'<<endl;
	}else if(a=='C'){
		cout<<'G'<<endl;
	}	
	return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1e9 + 10;
const ll INFL = 1LL << 60;

class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(N), B(N);
        rep(i, N) cin >> A[i] >> B[i];

        ll sum = 0;
        for(int i = N - 1; i >= 0; i--) {
            ll a = (A[i] + sum) % B[i];
            a = (B[i] - a) % B[i];
            sum += a;
        }
        cout << sum << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1024
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents

main = do
    argMatrix <- getIntMatrix
    print $ solve argMatrix


solve :: [[Integer]] -> Integer
solve ll =  n^2 - a
    where 
        n = head $ head ll
        a = head $ last ll 

Measured memory_bytes: 380
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
XYZ = [[int(_) for _ in input().split()] for n in range(N)]

ary0 = [x + y + z for x, y, z in XYZ]
ary1 = [x + y - z for x, y, z in XYZ]
ary2 = [x - y + z for x, y, z in XYZ]
ary3 = [-x + y + z for x, y, z in XYZ]
ary4 = [x - y - z for x, y, z in XYZ]
ary5 = [-x + y - z for x, y, z in XYZ]
ary6 = [-x - y + z for x, y, z in XYZ]
ary7 = [-x - y - z for x, y, z in XYZ]

sum0 = sum(sorted(ary0, reverse=True)[:M])
sum1 = sum(sorted(ary1, reverse=True)[:M])
sum2 = sum(sorted(ary2, reverse=True)[:M])
sum3 = sum(sorted(ary3, reverse=True)[:M])
sum4 = sum(sorted(ary4, reverse=True)[:M])
sum5 = sum(sorted(ary5, reverse=True)[:M])
sum6 = sum(sorted(ary6, reverse=True)[:M])
sum7 = sum(sorted(ary7, reverse=True)[:M])

print(max(sum0, sum1, sum2, sum3, sum4, sum5, sum6, sum7))


Measured memory_bytes: 3572
//
// Created by miyoshi on 2019/05/23.
//

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


static const int N = 1000;

int lcs(string X, string Y) {
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();

    int maxl = 0;
    X = " " + X;
    Y = " " + Y;

    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; j <= n; j++) c[0][j] = 0;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    int number_of_pair;
    string X, Y;

    cin >> number_of_pair;

    for (int i=0; i < number_of_pair; i++){
        cin >> X;
        cin >> Y;
        cout << lcs(X, Y) << endl;
    }
    return 0;
}


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

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

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> xv(n);
	for (auto& i : xv) {
		cin >> i;
	}
	xv.push_back(x);

	sort(xv.begin(), xv.end());

	int ret = xv[1] - xv[0];
	for (int i = 2; i <= n; ++i) {
		ret = gcd(ret, xv[i] - xv[i - 1]);
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll M=max_element(all(a))-a.begin();
    ll m=min_element(all(a))-a.begin();
    ll count=0;
    if((a[m]<=0&&abs(a[M])>=abs(a[m]))||a[m]>=0){
        cout<<n*2<<endl;
        cout<<M+1<<" "<<n<<endl;
        rep(i,n){
            cout<<M+1<<" "<<i+1<<endl;
            if(i!=0)cout<<i<<" "<<i+1<<endl;
        }
    }else{
        cout<<n*2<<endl;
        cout<<m+1<<" "<<1<<endl;
        repm(i,n-1,-1){
            cout<<m+1<<" "<<i+1<<endl;
            if(i!=n-1)cout<<i+2<<" "<<i+1<<endl;
        }
    }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

string s;

int main(){

cin >> s;
rep(i, 0, s.size()-2){
if(s[i]==s[i+1])return 0*printf("%d %d", i+1, i+2);
if(s[i]==s[i+2])return 0*printf("%d %d", i+1, i+3);
}
cout << "-1 -1";


return 0;}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    s = input().strip()
    ans = 0
    pre = ""
    for i in range(N):
        if s[i] != pre:
            ans += 1
        pre = s[i]
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[200010], B[200010];
ll maA = 0, miA = INF;

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

  rep( i, N )
    std::cin >> A[i] >> B[i];

  std::sort( A, A+N );
  std::sort( B, B+N );

  if( N&1 )
    std::cout << B[(N+1)/2-1]-A[(N+1)/2-1]+1 << std::endl;
  else
    std::cout << B[(N+1)/2]+B[(N+1)/2-1]-A[(N+1)/2-1]-A[(N+1)/2]+1 << std::endl;

  return 0;
}

Measured memory_bytes: 6288
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, m; cin >> n >> m;
    vector<ll> x(m);
    REP(i, m) cin >> x[i];
    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    sort(ALL(x));

    vector<ll> dist(m-1);
    REP(i, m-1) dist[i] = x[i+1] - x[i];
    sort(ALL(dist));
    ll count = 0;
    REP(i, dist.size()-n+1) {
        count += dist[i];
    }
    cout << count << endl;

    return 0;   
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;

    cout << "A" << t[0] << "C" << endl;
    return 0;
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> g[10010];
  rep(i,n-1){
    ll a,b;cin>>a>>b;a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<ll> vec(n);
  priority_queue<ll> pq;
  rep(i,n){
    cin>>vec[i];
    pq.push(vec[i]);
  }
  vector<ll> v(n,-1);
  queue<ll> que;
  que.push(0);
  v[0]=pq.top();
  pq.pop();
  while(!que.empty()){
    auto c=que.front();que.pop();
    for(auto tmp:g[c]){
      if(v[tmp]==-1){
        v[tmp]=pq.top();
        pq.pop();
        que.push(tmp);
      }
    }
  }
  sort(ALL(vec),greater<ll>());
  cout<<Svec(vec)-vec[0]<<endl;
  rep(i,n){
    cout<<v[i]<<' ';
  }
  cout<<endl;
}

Measured memory_bytes: 1408
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

count = 0
if b[0] >= a[0]:
    count = a[0]
    b[0] -= a[0]
else:
    count = b[0]
    b[0] = 0
    
for i in range(1, n):
    if a[i]==0: continue
    if b[i-1] >= a[i]:
        count += a[i]
        continue
    if b[i] >= a[i] - b[i-1]:
        count += a[i]
        b[i] -= (a[i] - b[i-1])
        continue
    count += b[i-1] + b[i]
    b[i] = 0

count += min(a[-1], b[-1])

print(count)


Measured memory_bytes: 19004
N = int(input())
S = [list(input()) for _ in range(N)]
cnt = 0
dic = {}
for s in S:
    s.sort()
    s_ = "".join(s)
    if s_ in dic.keys():
        cnt += dic[s_]
        dic[s_] += 1
    else:
        dic[s_] = 1
print(cnt)


Measured memory_bytes: 39040
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<long long> b(n);
    b[0]=100001;
    long long ans=0;
    for(int i=1;i<n;i++){
        cin>>b[i];
        ans+=min(b[i-1],b[i]);
    }
    ans+=b[n-1];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1e-9
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define MAXN 1005
#define MAXM 40005
#define INF 1e18
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define clr(x,y) memset(x,y,sizeof(x));
using namespace std;
typedef long long LL;
LL i,j,k,n,m,x,y,T,ans,big,cas,num,len;
bool flag;
LL edge,head[1005],mag,s[3],t,mi[3],w;
char ss[20];
double v[100005];
struct edgenode
{
	LL to,next,w;
} G[40005];

void add_edge(LL x,LL y,LL w)
{
	G[edge].to=y;
	G[edge].w=w;
	G[edge].next=head[x];
	head[x]=edge++;
}


LL dis[1005][105],vis[1005][105];
void SPFA(LL st)
{
	LL tim,u,v,ad,w;
	memset(dis,-1,sizeof(dis));
	memset(vis,0,sizeof(vis));
	queue<pair<LL,LL> > q;
	while (!q.empty()) q.pop();
	q.push(MP(st,0));
	dis[st][0]=0;vis[st][0]=1;
	while (!q.empty())
	{
		u=q.front().X;
		tim=q.front().Y;
		q.pop();
		vis[u][tim]=false;
		for (i=head[u];i!=-1;i=G[i].next)
		{
			v=G[i].to;
			w=G[i].w; 
			if (w==-1) ad=1,w=0; else ad=0;
			
			if (tim+ad<=mag && (dis[v][tim+ad]==-1 || dis[v][tim+ad]>dis[u][tim]+w))
			{
				dis[v][tim+ad]=dis[u][tim]+w;
				if (!vis[v][tim+ad])
				{
					vis[v][tim+ad]=true;
					q.push(MP(v,tim+ad));
				}
			}
		}
	}
}


int main()
{
	while (scanf("%lld%lld%lld%lld%lld",&n,&m,&s[1],&s[2],&t),n+m)
	{
		memset(head,-1,sizeof(head));
		edge=0;mag=0;ans=INF;
		for (i=0;i<m;i++)
		{
			scanf("%lld%lld",&x,&y);
			scanf("%s",ss);
			if (strcmp(ss,"x")==0)
			{
				w=-1;
				mag++;
			}else
			{
				sscanf(ss,"%lld",&w);
			}
			add_edge(x,y,w);
			add_edge(y,x,w);
		}
		SPFA(t);
		num=0;
		v[num++]=0;
		
		for (i=1;i<=2;i++)
		{
			for (j=0;j<=mag;j++)
			{
				x=dis[s[i]][j];
				if (x==-1) continue;
				for (k=j+1;k<=mag;k++)
				{
					y=dis[s[i]][k];
					if (y==-1) continue;
					double a=(x-y)*1.0/(k-j);
				 	if (a>0) v[num++]=a;
				}
			}
		}
		
		for (j=0;j<=mag;j++)
		{
			x=dis[s[1]][j];
			if (x==-1) continue;
			for (k=0;k<=mag;k++)
			{
				if (k==j) continue;
				y=dis[s[2]][k];
				if (y==-1) continue;
				double a=(x-y)*1.0/(k-j);
			 	if (a>0) v[num++]=a;
			}
		}
			
		for (i=0;i<num;i++)
		{
			for (j=1;j<=2;j++)
			{
				mi[j]=INF;
				for (k=0;k<=mag;k++)
				{
					if (dis[s[j]][k]!=-1)
					{
						mi[j]=min(mi[j],dis[s[j]][k]+k*(LL)(v[i]+eps));
					}
				}
			}
			ans=min(ans,abs(mi[1]-mi[2]));	
		} 
		for (i=0;i<num;i++)
		{
			for (j=1;j<=2;j++)
			{
				mi[j]=INF;
				for (k=0;k<=mag;k++)
				{
					if (dis[s[j]][k]!=-1)
					{
						mi[j]=min(mi[j],dis[s[j]][k]+k*(LL)(v[i]+eps+1));
					}
				}
			}
			ans=min(ans,abs(mi[1]-mi[2]));	
		} 
		printf("%lld\n",ans); 
		
	}
	return 0;
}

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

int main() {
  vector<int> V(9);
  for (int i = 0; i < 9; i++) {
    cin >> V.at(i);
  }
  int N;
  cin >> N;
  int b;
  while (cin >> b) for (int i = 0; i < 9; i++) {
    if (V.at(i) == b) V.at(i) = -1;
  }
  bool bin = 0;
  if (V.at(0) == -1 && V.at(1) == -1 && V.at(2) == -1) bin = 1;
  if (V.at(3) == -1 && V.at(4) == -1 && V.at(5) == -1) bin = 1;
  if (V.at(6) == -1 && V.at(7) == -1 && V.at(8) == -1) bin = 1;
  if (V.at(0) == -1 && V.at(3) == -1 && V.at(6) == -1) bin = 1;
  if (V.at(1) == -1 && V.at(4) == -1 && V.at(7) == -1) bin = 1;
  if (V.at(2) == -1 && V.at(5) == -1 && V.at(8) == -1) bin = 1;
  if (V.at(0) == -1 && V.at(4) == -1 && V.at(8) == -1) bin = 1;
  if (V.at(2) == -1 && V.at(4) == -1 && V.at(6) == -1) bin = 1;
  cout << ((bin) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
    string s;
    cin >> s;
    map<char, int> mp;
    for(auto a: s){
        auto itr = mp.find(a);
        if( itr != mp.end() )         // キーの要素が存在している場合
            mp[a]++;
        else
            mp[a] = 1;

        if(mp.size() == 3){
            cout << "No";
            return 0;
        }


    }

    if(mp.size() <= 1){
        cout << "No";
        return 0;
    }

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        
        if(itr->second % 2 != 0){
            cout << "No";
            return 0;
        }
    }
        // c;
    
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace myapp
{
    class AtCoder_abc079_c
    {
        public static void Main()
        {
            string lineString = Console.ReadLine();
            int A = int.Parse(lineString.Substring(0, 1));
            int B = int.Parse(lineString.Substring(1, 1));
            int C = int.Parse(lineString.Substring(2, 1));
            int D = int.Parse(lineString.Substring(3, 1));

            if (A + B + C + D == 7)
            {
                Console.WriteLine($"{A}+{B}+{C}+{D}=7");
                return;
            }

            if (A + B + C - D == 7)
            {
                Console.WriteLine($"{A}+{B}+{C}-{D}=7");
                return;
            }

            if (A + B - C + D == 7)
            {
                Console.WriteLine($"{A}+{B}-{C}+{D}=7");
                return;
            }

            if (A + B - C - D == 7)
            {
                Console.WriteLine($"{A}+{B}-{C}-{D}=7");
                return;
            }

            if (A - B + C + D == 7)
            {
                Console.WriteLine($"{A}-{B}+{C}+{D}=7");
                return;
            }

            if (A - B + C - D == 7)
            {
                Console.WriteLine($"{A}-{B}+{C}-{D}=7");
                return;
            }

            if (A - B - C + D == 7)
            {
                Console.WriteLine($"{A}-{B}-{C}+{D}=7");
                return;
            }

            if (A - B - C - D == 7)
            {
                Console.WriteLine($"{A}-{B}-{C}-{D}=7");
                return;
            }
        }
    }
}

Measured memory_bytes: 13268
function main(input) {
  var answer = "Yes";
  var input = input.split('\n');
  var shiritori_length = input[0];
  var shiritori_array = [];

  for (var i = 0; i < shiritori_length; i++) {
  	shiritori_array.push(input[i+1])
  	//末尾チェック
  	if(i > 0){
  		//前の語尾と先頭の文字が一致するか
  		if(shiritori_array[i-1].slice(-1) != shiritori_array[i].slice(0,1) ){
  			answer = "No";
  			break;
  		}
  		//重複チェック
  		for (var j = 0; j < shiritori_array.length - 1; j++) {
  			if(input[i+1] == shiritori_array[j]){
  				answer = "No";
	  			break;
  			}  		
  		}

  	}

  	
  }

  console.log(answer);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
import java.util.Scanner;

// A - Buttons
public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int ans = 0;
	for (int i = 0; i < 2; i++) {
		if (A > B) {
			ans += A;
			A = A - 1;
		} else {
			ans += B;
			B = B - 1;
		}
	}

	System.out.println(ans);

	}
}

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

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

     int N, X, T; cin >> N >> X >> T;
    cout << ((N + X - 1)/X)*T  << '\n';
    


    return 0;
}



Measured memory_bytes: 3600
n = int(input())
h = list(map(int,input().split()))

ans = 0
tmp = 0
for i in range(n-1):
	if h[i] >= h[i+1]:
		tmp += 1
	else:
		ans = max(ans,tmp)
		tmp = 0
ans = max(ans,tmp)
print(ans)


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

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi std::vector<int>
#define vvi std::vector<std::vector<int> >
#define vpi std::vector<pi >
#define pi std::pair<int,int>
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (int var = (from); var <= ((int)(to)); var++)
#define DOWNTO(var, from, to) for (int var = (from); var >= ((int)(to)); var--)
#define FOR(var, to)		  UPTO(var, 0, (to)-1)
#define DOWN(var, from)	   DOWNTO(var, (from)-1, 0)

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
	std::vector<std::vector<s64> > a;
	Comb(int n) { // O(n^2)
		a.resize(n+1);
		FOR(i,n+1) {
			a[i].resize(i+1, 1);
			UPTO(j,1,i-1) a[i][j] = a[i-1][j] + a[i-1][j];
		}
	}
	s64 ncr(int n, int r) {
		assert(n >= 0);
		assert(n <= (int)a.size());
		assert(r >= 0);
		assert(r <= n);
		return a[n][r];
	}
};

#define gc(c) (c)=getchar()
int ri() {
	int c,s=0,r=0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}
s64 rs64() {
	s64 r=0;
	int c,s=0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}

int int_less(const void *a, const void *b) {
	return (*(const int*)a - *(const int*)b);
}
int int_greater(const void *a, const void *b) {
	return (*(const int*)b - *(const int*)a);
}
std::string operator*(const std::string &s, int n){ std::string res; FOR(i,n) res += s; return res; }

template<class T> std::ostream& operator<<(std::ostream& os, std::vector<T> a) { for (auto i : a) os << i << " "; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, std::set<T> a) { for (auto i : a) os << i << " "; return os; }
template<class A, class B> std::ostream& operator<<(std::ostream&os, std::pair<A,B> a) { os << a.fi << "," << a.se; return os; }


int main() {
	s64 n = rs64();
	s64 min = LINF;
	FOR(i,5) min = std::min(min, rs64());
	
	std::cout << 5 + (n - 1) / min << std::endl;
	
	return 0;
}


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

void printData(int seq[], int n)
{
    int i;

    //数列の中身を表示
    for (i = 0; i < n; i++)
    {
        cout << seq[i];
        if (i != n - 1)
            cout << ' ';
    }
    cout << endl;
}

/**********************************************/

void insertSort(int seq[], int n)
{
    int i;
    int j;
    int v;

    //挿入ソート
    for(i = 1; i <= (n - 1); i++){
        v = seq[i];
        j = i - 1;
        
        while(j >= 0 && seq[j] > v){
            seq[j + 1] = seq[j];
            j--;
        }
        seq[j + 1] = v;
        printData(seq, n);
    }
    
    return;
}
/**********************************************/

int main()
{
    //データ定義
    int sequenceLength; //数列の長さ
    int sequence[100]; //数列
    int i;

    //数列の長さを取得
    cin >> sequenceLength;

    //数列の要素を取得
    for(i = 0; i < sequenceLength; i++){
        cin >> sequence[i];
    }

    //数列を表示
    printData(sequence, sequenceLength);

    //挿入ソート
    insertSort(sequence, sequenceLength);

    return 0;
}


Measured memory_bytes: 3076
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]


n = int(input())
uf = UnionFindTree(n)
ps = list(map(int, input().split()))
k = 0
for i,p in enumerate(ps):
    if p<0:
        k += 1
        continue
    uf.connect(i,p-1)
for i in range(n):
    uf.root(i)
from collections import Counter, defaultdict
M = 10**9+7
ncount = Counter(uf.parent)
mcount = defaultdict(int)
for i,g in enumerate(uf.parent):
    if ps[i]==-1:
        mcount[g] += 1

ans = sum(v-1 for v in ncount.values())
ans *= pow(n-1, k, M)

for kk in ncount.keys():
    ncount[kk] -= mcount[kk]

for kk,mm in mcount.items():
    if mm==0:
        continue
    nn = ncount[kk]
    ans += (n - mm - nn)*pow(n-1, k-1, M)*mm
    ans %= M

nums = [nn+mcount[k] for k,nn in ncount.items() if mcount[k]]
l = len(nums)
dp = [[0] * l for _ in range(l)]
# dp[i][j] : i番目まで使うときの周期j+1の個数
if nums:
    dp[0][0] = nums[0]
    for i in range(1,l):
        dp[i][0] = dp[i-1][0] + nums[i]

    for i in range(1,l):
        for j in range(1,l):
            dp[i][j] += dp[i-1][j-1] * nums[i] * j + dp[i-1][j]
            dp[i][j] %= M

    for j in range(1, l):
        ans -= dp[-1][j]*pow(n-1, l-j-1, M)

print(ans%M)
    

Measured memory_bytes: 266028
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

vector<ll> adj[N];

// can be used for bipartite ,if no odd cycle ->bipartite,0's and 1's;
bool visited[N], color[N]; // initilise visited to false
stack<ll> st;
// uncomment if want the cycle elements
// vector<ll> cycleEl;

// uncomment if want the cycle elements
// vector<ll> cycleEl;
bool dfs(ll curr, bool val = true) {
  st.push(curr);
  visited[curr] = true;
  color[curr] = val;

  for (ll x : adj[curr]) {
    if (!visited[x]) {
      bool done = dfs(x, !val);
      if (done)
        return true;
    } else if (color[x] == val) {
      // uncomment if want the cycle elements
      /*
      while(true)
      {
          ll curr=st.top();
          st.pop();
          cycleEl.push_back(curr);
          if(curr==x)
              break;
      }
      */
      return true;
    }
  }
  st.pop();
  return false;
}

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

  ll n;
  cin >> n;

  ll dp[n + 5][n + 5];

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++)
      dp[i][j] = inf;
  }
  for (ll i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (ll j = 1; j <= n; j++) {
      if (s[j - 1] == '1') {
        adj[i].push_back(j);
        dp[i][j] = 1;
      }
    }
    dp[i][i] = 0;
  }

  memset(visited, false, sizeof(visited));

  bool check = dfs(1);
  if (check) {
    cout << -1 << en;
    return 0;
  }

  for (ll k = 1; k <= n; k++) {
    for (ll i = 1; i <= n; i++) {
      for (ll j = 1; j <= n; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n; j++)
      ans = max(ans, dp[i][j]);
  }

  cout << ans + 1 << en;

  return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int j,n,m,po,no,flag=0,cnt,cnt2,ans=0,ar[100000],x,y,i,co[100000];
    string str,ptr,sr,tr,rtr,rt;
    vector<long long int>v(100000,0);
    set<string>s;
    queue<long long int>qu;
    set<string>::iterator it;
    cin>>str;
    for(i=0;i<str.length();i++)
    {
        if(str[i]=='7')
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;




}


Measured memory_bytes: 3880
import numpy as np
I=input
N = int(I())
S = np.fromiter('-'+I(),dtype='U1')
Q = int(I())
query = map(int,I().split())

isD = S == 'D'
isM = S == 'M'
isC = S == 'C'

cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)

for K in query:
    x = cumD.copy(); x[K:] -= cumD[:-K]
    x *= isM
    x[K+1:] -= isD[1:-K] * (cumM[K:-1] - cumM[:-K-1])
    print((x.cumsum() * isC).sum())


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

int main(){
  int n,kekka = 0;
  string a,b,c;
  int d[30];
  cin >> n >> a >> b >> c;
  for(int i = 0;i < n;i++){
    for(int i = 0;i < 30;i++){
      d[i] = 0;
    }
    d[a.at(i) - 'a']++;
    d[b.at(i) - 'a']++;
    d[c.at(i) - 'a']++;
    int k = 0;
    for(int i = 0;i < 30;i++){
      k = max(d[i],k);
    }
    kekka += 3-k;
  }
  cout << kekka << endl;
}

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

int main()
{
    int H, W;
    cin >> H >> W;

    vector<string> C(H);
    for (int i = 0; i < H; i++)
    {
        cin >> C[i];
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cout << C[i] << endl;
        }
    }

    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int n;
    cin>>n;
    vector<vector<int>>g(n);
    int x,y;
    cin>>x>>y;
    x--;y--;
    g.at(x).push_back(y);
    g.at(y).push_back(x);
    rep(i,0,n-1){
        g.at(i).push_back(i+1);
        g.at(i+1).push_back(i);
    }
    vector<int>d(n,-1);
    queue<int>q;
    vector<int>ad(n,0);
    rep(i,0,n){
        rep(j,0,n){
            d.at(j)=-1;
        }
        d.at(i)=0;
        q.push(i);
        while(!q.empty()){
            int now=q.front();
            q.pop();
            for(auto next:g.at(now)){
                if(d.at(next)!=-1)continue;
                d.at(next)=d.at(now)+1;
                q.push(next);
                ad.at(d.at(next))++;
            }
        }
    }
    rep(i,1,n){
        cout<<ad.at(i)/2<<endl;
    }
return 0;
}

Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        final Map<Character, Integer> m = new HashMap<>();
        final String str = scanner.next();
        for (char c: str.toCharArray()) {
            if (!m.containsKey(c)) {
                m.put(c, 0);
            }

            m.put(c, m.get(c) + 1);
        }

        final int size = m.entrySet().stream().filter(e -> e.getValue() == 2).collect(Collectors.toList()).size();

        System.out.println(size == 2 ? "Yes" : "No");
    }
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const double EPS = 1e-9;

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    ll a,b,c,ax,bx,cx = 0;
    cin >> a >> b >> c >> ax >> bx;

    ll ans = a*ax+b*bx;
    while(ax > 0 || bx > 0){
        if(ax > 0) ax--;
        if(bx > 0) bx--;
        cx += 2;
        ans = min(ans, a*ax+b*bx+c*cx);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
numbers = [list(map(int, input().split())) for i in range(3)]

answer = "No"
for a1 in range(101):
    b1 = numbers[0][0] - a1
    b2 = numbers[1][0] - a1
    b3 = numbers[2][0] - a1
    a2 = numbers[0][1] - b1
    a3 = numbers[0][2] - b1
    if a2 + b2 == numbers[1][1] and a3 + b2 == numbers[1][2] and a2 + b3 == numbers[2][1] and a3 + b3 == numbers[2][2] and a1 >= 0 and a2 >= 0 and a3 >= 0 and b1 >= 0 and b2 >= 0 and b3 >= 0:
        answer = "Yes"

print(answer)

Measured memory_bytes: 3064
#include <stdio.h>
int A[999999],W[999999];
long long M(int l,int r){
	if(l+1>=r)return 0;
	if(l+2==r){
		if(A[l]<=A[l+1])return 0;
		int z=A[l];A[l]=A[l+1];A[l+1]=z;
		return 1;
	}
	int m = (l+r)/2,i=l, j=m, k=l;
	long long cl=M(l, m),cr=M(m,r),c=0;
	while(i<m&&j<r){
		if(A[i]<=A[j])W[k++]=A[i++];
		else{
			W[k++]=A[j++];
			c+=m-i;
		}
	}
	while(i<m)W[k++]=A[i++];
	while(j<r)W[k++]=A[j++];
	for(i=l;i<r;i++)A[i]=W[i];
	return cl+cr+c;
}
int main(){
	int T,i,N;
	//PKU2299,aizu0167
	//for(;scanf("%d",&N),N;printf("%lld\n",M(0,N)))for(i=0;i<N;i++)scanf("%d",A+i);
	//hackerrank~runningtime,aizuALDS1~5D
	scanf("%d",&N);for(i=0;i<N;i++)scanf("%d",A+i);printf("%lld\n",M(0,N));
	//spojINVCNT,hackerrank~insertionsort
	//for(scanf("%d",&T);T--;printf("%lld\n",M(0,N)))for(scanf("%d",&N),i=0;i<N;++i)scanf("%d",A+i);
	//codeiq432
	//for(N=0;~scanf("%d",A+N);N++);printf("%lld\n",M(0,N));
	//kcs1009K
	//for(i=0;~(N=getchar());)if('0'<N&&N<'9')A[i++]=N-'0';
	//puts(M(0,i)%2?"lmpossible":"Possible"); //"l"? lol!
	return 0;
}

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

#define pb push_back

void solution(int n, int k, std::vector<int>& heights);
void solution1(int n, int k, std::vector<int>& heights);
void solution2();

int main(void){

	int n, k;
	cin >> n >> k;
	std::vector<int> heights(n);
	for(int i = 0;i < n;i++)
		cin >> heights[i];

	// solution(n, k, heights);
	solution1(n, k, heights);
}

// iterative
void solution(int n, int k, std::vector<int>& heights){
	std::vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for(int j = 1;j < n;j++){
		for(int i = 1;i <= k && j >= i;i++){
			dp[j] = min(dp[j], dp[j-i] + abs(heights[j]-heights[j-i]));
		}
	}
	cout << dp[n-1] << endl;
	return;
}

int helper(int n, int k, std::vector<int>& heights, int x, std::vector<int>& dp){
	if(dp[x] != -1)
		return dp[x];
	if(x == 0){
		dp[x] = 0;
		return dp[x];
	}
	dp[x] = INT_MAX;
	for(int i = 1;i <= k && i <= x;i++){
		dp[x] = min(dp[x], helper(n, k, heights, x-i, dp) + abs(heights[x] - heights[x-i]));
	}
	return dp[x];
}

// recursive
void solution1(int n, int k, std::vector<int>& heights){
	std::vector<int> dp(n, -1);
	int ans = helper(n, k, heights, n-1, dp);
	cout << ans << endl;
	return;
}

Measured memory_bytes: 8832
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                count += 1
print(count)

Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A;
  cin >> N;
  cin >> A;
  
  if  ( A >= N % 500 ) {
    cout << "Yes" <<endl;
  }
  
  else {
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>



int main(void){
    int Q;
    scanf("%d",&Q);
    for(int unko=0;unko<Q;unko++){
        long long int A,B;
        scanf("%lld %lld",&A,&B);
        if(A>B){long long int po=A;A=B;B=po;}
        long long int ans=A-1;
        long long int left=0;
        long long int right=B+1;
        while(1){
            long long int mid=(left+right)/2;
            if(A<mid){long long int buri=(A+1+mid)/2;if(buri*(A+1+mid-buri)<A*B)left=mid;else right=mid;}
            else if(mid*(A+1)<A*B)left=mid;else right=mid;
            if(right-left<=1)break;
           // else printf("%lld %lld\n",right,left);
        }
        ans+=left;
        printf("%lld\n",ans);
    }
    
    return 0;
}


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

int main() {
  int n,j;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    j = i;
    if (i % 3 == 0) {
      cout <<" "<<i;
    } else {
      while (j > 0) {
	if (j % 10 == 3) {
	  cout << " " <<i;
	  break;
	} else {
	  j = j / 10;
	}
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;
int n,i,pct,pct2, a[105];
long long s,ans,ans2;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    pct=s/n;
    pct2=s/n+1;
    for(i=1;i<=n;i++)
        ans+=(a[i]-pct)*(a[i]-pct);
    for(i=1;i<=n;i++)
        ans2+=(a[i]-pct2)*(a[i]-pct2);
    cout<<min(ans, ans2);
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

N = int(input())

D = defaultdict(list)
for i in range(N):
    s,p = input().split()
    D[s].append((i+1,int(p)))
    
for k in sorted(D.keys()):
    for v in sorted(D[k],key=lambda x:x[1],reverse=True):
        print(v[0])

Measured memory_bytes: 3444
// ABC001C.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>

using namespace std;




int main()
{
	int N,M;
	cin>>N>>M;
	int *num = new int[M];
	//initializing
	for(int i = 0; i < M; i++){
		num[i] = 0;
	}
	int count = 0;

	for(int i = 0; i < N; i++){
		int K;
		cin>>K;
		for(int j = 0; j < K; j++){
			int index;
			cin>>index;
			num[index-1]++;
		}
	}
	for(int i = 0; i < M; i++){
		if( num[i] == N){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

#define rep0(n) for(int i=0;i<n;i++)
#define rep(n) for(int i=1;i<=n;i++)

double const pi = 3.1415926535;
int const mod = 1000000007;
int const inf = 2147483647;

int yesno(bool f, string yes, string no) {
	if (f)cout << yes << endl;
	else cout << no << endl;
	return 0;
}

int ans;

bool isd(string s) {
	bool a = true;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != s[s.size() - i - 1])a = false;
	}
	return a;
}

int main() {

	int a, b;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (isd(to_string(i)))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll N; cin>>N;
	vector<ll> A(N);
	rep(i,N)cin>>A[i];
	ll ans = 0;
	rep(i,N-1){
		if(A[i] % 2 == 1 && A[i+1]>0){
			++ans;
			--A[i];
			--A[i+1];
		}
	}
	rep(i,N){
		ans += A[i]/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
s0 = input()
def convert(n, m):
  ans = ""
  while n > 0:
    amari = n % m
    ans += str(amari)
    n //= m
  return ans
n = len(s0) - 1
SUM = int(s0)
for i in range(1, 2**n):
  s1 = " ".join(list(s0))
  i = convert(i, 2)
  list_index = []
  for j in range(len(i)):
    list_index.append(i.find("1", j))
  list_index = list(set([x for x in list_index if x != -1]))
  for k in list_index:
    s1 = s1[:2*k+1] + "+" + s1[2*(k+1):]
  s1 = s1.replace(" ", "")
  sum_list = list(map(int, s1.split("+")))
  SUM += sum(sum_list)
print(SUM)

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;
void solve(int,vector<int>);
int main(){
  int n;
  while(cin >> n && n)
    solve(n,vector<int>(0));
}
void solve(int cnt,vector<int> v){
  if(cnt < 0) return;
  if(cnt == 0){
    for(int i=0,l=v.size();i<l;i++){
      cout << (i?" ":"") << v[i];
    }
    cout << endl;
  }
  for(int i=cnt;i>0;i--){
    vector<int> tmp = v;
    if(tmp.size()>0 && i > tmp[tmp.size()-1]) continue;
    tmp.push_back(i);
    solve(cnt-i,tmp);
  }
}

Measured memory_bytes: 1232
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	ll b[n];
	b[n-1]=0;
	for(ll i=n-2;i>=0;i--){
		b[i]=b[i+1];
		b[i]+=a[i+1];
		b[i]%=mod;
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		a[i]*=b[i];
		a[i]%=mod;
		ans+=a[i];
		ans%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6692
#include<stdio.h>
int main()
{
    int X;
    scanf("%d",&X);
    if(X==7){
        printf("YES\n");
    }
    else if(X==5){
        printf("YES\n");
    }
    else if(X==3){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;


}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
	char w[1000];
	scanf("%s", w);
	int alp[26];
	for(int i=0; i<26; i++){
		alp[i]=0;
	}
	for(int i=0; w[i]!='\0'; i++){
		for(int j=97; j<123; j++){
			if(w[i]==j)
				alp[j-97]++;
		}
	}
	for(int i=0; i<26; i++){
		if(alp[i]%2!=0){
			printf("No\n");	return 0;
		}
	}

	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 128