akhauriyash/Code-Regression huggingface dataset:
import itertools
import math
import sys
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
e = Counter(v[0::2]).most_common()
o = Counter(v[1::2]).most_common()
if len(e) == 1 and len(o) == 1:
    if e[0][0] == o[0][0]:
        print(n // 2)
    else:
        print(0)
elif len(e) == 1:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[0][1], o[1][1]))
elif len(o) == 1:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[0][1], e[1][1]))
else:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[1][1], e[1][1] + o[0][1]))




Measured memory_bytes: 20700
import fractions
from functools import reduce

n = int(input())
l = []
for _ in range(n):
    l.append(int(input()))

def lcm(a:int,b:int):
    return a // fractions.gcd(a, b) * b

def lcm_list(numbers):
    return reduce(lcm, numbers)

print (lcm_list(l))

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

struct Graph
{
    struct Edge { int a, b; };
    int N;
    vector<vector<int>> adjacency_list;
    vector<Edge> edges;

    Graph(int N) : N(N), adjacency_list(vector<vector<int>>(N)), edges(vector<Edge>()) {}

    void add_edge(int a, int b)
    {
        edges.push_back({a, b});
        adjacency_list[a].push_back(b);
        adjacency_list[b].push_back(a);
    }

    vector<int>& neighbors(int v) { return adjacency_list[v]; }
};

vector<int> bfs(int N, Graph& graph, initializer_list<int> sources)
{
    auto distances = vector<int>(N, numeric_limits<int>::max());
    auto queue = std::queue<int>();
    for (auto v : sources)
    {
        distances[v] = 0;
        queue.push(v);
    }

    while (!queue.empty())
    {
        auto v = queue.front(); queue.pop();
        for (auto w : graph.neighbors(v)) if (distances[w] == numeric_limits<int>::max())
        {
            distances[w] = distances[v]+1;
            queue.push(w);
        }
    }
    return distances;
}

int solve(int N, int K, Graph tree)
{
    auto result = numeric_limits<int>::max();
    for (auto v = 0; v < N; v++)
    {
        auto distances = bfs(N, tree, {v});
        auto option = 0;
        for (auto d : distances)
            option += 2*d > K;
        result = min(result, option);
    }
    for (auto edge : tree.edges)
    {
        auto distances = bfs(N, tree, {edge.a, edge.b});
        auto option = 0;
        for (auto d : distances)
            option += 2*d+1 > K;
        result = min(result, option);
    }
    return result;
}

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

    auto tree = Graph(N);
    for (auto i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        tree.add_edge(a, b);
    }

    cout << solve(N, K, tree) << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 1;
        while (true) {
            int x = sc.nextInt();
            if (x == 0){
                break;
            }
            System.out.printf("Case %d: %d\n", i, x);
            i++;
        }
        
    }
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int p[2000];
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    sort(p, p+n);
    int ans = 0;
    for(int i=0; i<k; i++){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<iostream>
#include<queue>
using namespace std;
int m[1002][1002]={0},p[1002][1002]={0};
struct r{
	int g,g2;
	unsigned long long l;
};
int main(){
	int h,w,n,i,j,a,b[2],l2=1;
	b[0]=1;
	b[1]=-1;
	char c[2001];
	r gl;
	queue<r> q;
	cin>>h>>w>>n;
	for(i=0;i<=h+1;i++){
		m[i][0]=-1;
		m[i][w+1]=-1;
	}
	for(i=0;i<=w+1;i++){
		m[0][i]=-1;
		m[h+1][i]=-1;
	}
	for(i=1;i<=h;i++){
		scanf("%s",c);
		for(j=1;j<=w;j++){
			a=c[j-1];
			if(a>=49&&a<=57){m[i][j]=a-48;}
			if(c[j-1]=='X'){m[i][j]=-1;}
			if(c[j-1]=='S'){
				gl.g=i;
				gl.g2=j;
				gl.l=0;
				q.push(gl);
			}
		}
	}
	while(1){
		gl=q.front();
		q.pop();
		if(m[gl.g][gl.g2]==l2){
			l2++;
			if(l2==n+1){break;}
			while(!q.empty()){q.pop();}
		}
		gl.l++;
		p[gl.g][gl.g2]=l2;
		for(i=0;i<2;i++){
			if(m[gl.g+b[i]][gl.g2]!=-1&&p[gl.g+b[i]][gl.g2]!=l2){
				p[gl.g+b[i]][gl.g2]=l2;
				gl.g+=b[i];
				q.push(gl);
				gl.g-=b[i];
			}
			if(m[gl.g][gl.g2+b[i]]!=-1&&p[gl.g][gl.g2+b[i]]!=l2){
				p[gl.g][gl.g2+b[i]]=l2;
				gl.g2+=b[i];
				q.push(gl);
				gl.g2-=b[i];
			}
		}

	}
	cout<<gl.l<<endl;
	return 0;
}

Measured memory_bytes: 10976
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll k = n / (a + b);
  ll nb = a * k;
  ll rest = n - (a + b) * k;
  nb += min(rest, a);
  cout << nb << endl;
  return 0;
}

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

int cnt_digits(ll N){
  int digits=0;
  while(N>0){
    N/=10;
    digits++;
  }
  return digits;
}

int main(){
  ll n;
  cin>>n;
  int ans=cnt_digits(n);
  for(ll a=1LL;a*a<=n;++a){
    if(n%a!=0)continue;
    const ll b=n/a;
    
    const int cur=max(cnt_digits(a),cnt_digits(b));
    
    if(ans>cur){
      ans=cur;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007


int main()
{
   int n,m;
   cin>>n>>m;
   string str[n];
   for(int i=0;i<n;i++)
      cin>>str[i];

   int left[n][m]{};
   int right[n][m]{};
   int up[n][m]{};
   int down[n][m]{};

   for(int i=0;i<n;i++)
   {
      int count = 0;
      for(int j=0;j<m;j++)
      {
         if(str[i][j] == '.')
         {
            count++;
            left[i][j] = count;
         }
         else
            count = 0;
      }
   }
   for(int i=0;i<n;i++)
   {
      int count = 0;
      for(int j=m-1;j>=0;j--)
      {
         if(str[i][j] == '.')
         {
            count++;
            right[i][j] = count;
         }
         else
            count = 0;
      }
   }

   for(int i=0;i<m;i++)
   {
      int count = 0;
      for(int j=0;j<n;j++)
      {
         if(str[j][i] == '.')
         {
            count++;
            down[j][i] = count;
         }
         else
            count = 0;
      }
   }

   for(int i=0;i<m;i++)
   {
      int count = 0;
      for(int j=n-1;j>=0;j--)
      {
         if(str[j][i] == '.')
         {
            count++;
            up[j][i] = count;
         }
         else
            count = 0;
      }
   }

   int ans{};
   for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
         if(str[i][j] == '.')
            ans = max(ans,left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3);
   
   cout<<ans;
   return 0;
}


Measured memory_bytes: 73708
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    ret.pb(n);
    return ret;
}

int main(void) {

    ll n,m;
    cin>>n>>m;
    vll v=enum_div(m);
    ll ans=1;
    for(int i=v.size()-1;i>=0;i--){
        ll mid=v[i];
        if(v[i]*n<=m) {
            chmax(ans,v[i]);
        }
    }
    fin(ans);
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

const ull MOD = 1000000007;
const ull MAX = 510000;
ull fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

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

	COMinit();

	for (int ii = 1; ii <= K; ++ii){
		ull ans = (COM(N-K+1, ii) * COM(K-1, ii-1) ) % MOD;
		cout << ans << "\n";
	}

	return 0;
}


Measured memory_bytes: 12160
#include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n && n != 0) {
		int A=0, B=0, a, b;
		for (int i=0; i<n; i++) {
			cin >> a >> b;
			if (a > b) {
				A += a+b;
			} else if (a < b) {
				B += a+b;
			} else {
				A += a;
				B += b;
			}
		}
		cout << A << " " << B << endl;
	}
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

class UnionFind {
public:
  UnionFind(int size) : size(size) {

    par = vector<int>(size, -1);
  }

  int GetRoot(int v) {
    int root = v;
    while (par[root] >= 0) {
      root = par[root];
    }
    if (root != v) {
      par[v] = root;
    }
    return root;
  }

  bool IsUnion(int a, int b) {
    int ra = GetRoot(a), rb = GetRoot(b);

    return ra == rb && ra >= 0;
  }

  int GetUnionSize(int a) {
    return -par[GetRoot(a)];
  }

  void Unite(int a, int b) {
    int ra = GetRoot(a), rb = GetRoot(b);

    if (ra == rb) return;

    if (GetUnionSize(ra) > GetUnionSize(rb)) {
      par[ra] += par[rb];
      par[rb] = ra;
    }
    else {
      par[rb] += par[ra];
      par[ra] = rb;
    }
  }

protected:

  // 親がいれば、親のindexを入れる
  // 親がいなければ、グループのサイズを負にして入れておく（一人なら-1）
  vector<int> par;

  int size;
};

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  F0R(i, M) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.Unite(a, b);
  }
  int r = 0;
  F0R(i, N) {
    chmax(r, uf.GetUnionSize(i));
  }
  cout << r;
}
#endif


Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    int m;
    cin >> m;
    rep(i, m) {
        int x;
        cin >> x;
        if(std::binary_search(all(a), x)) ++ans; 
    } 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define vs vector<string>
#define vve vector<vector<int>>
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vs s(h);
  ve c;
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  vve a(h,vector<int>(w));
  int cara=1;
  for(int i=0;i<h;i++){
    int check,made;
    check=-1;
    for(int j=0;j<w;j++){
      if(s.at(i).at(j)=='#'){

        made=check+1;
        check=j;
        for(int m=0;made<=check;made++){
          a.at(i).at(made)=cara;
        }
                if(made==1) a.at(i).at(0)=cara;
        cara++;
      }
      if(check!=w-1){
        for(int l=check+1;l<w;l++){
          a.at(i).at(l)=cara-1;
        }
      }
    }
    if(check==-1){
      c.push_back(i);
    }
  }
  if(c.size()!=0){
    int L=c.size();
    int check=-1;
    for(int i=0;i<L;i++){
      if(i==c[i]) check++;
    }
    for(int i=check;i>=0;i--){
      for(int j=0;j<w;j++){
        a.at(i).at(j)=a.at(i+1).at(j);
      }
    }
    for(int i=check+1;i<L;i++){
      for(int j=0;j<w;j++){
        a.at(c[i]).at(j)=a.at(c[i]-1).at(j);
      }
    }
    
  }
  for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cout<<a.at(i).at(j)<<' ';
      }
      cout<<endl;
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



	int a, b,c;
	cin >> a >> b>>c;

	if (a == b)
		cout << c << endl;
	else if (b == c)
		cout << a << endl;
	else
		cout << b << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
char num[100005];
int main(){
	int n;
	cin>>n;
	cin>>num;
	int sum=0;
	for(int i=1;i<n;i++){
		if(num[i]!=num[i-1]){
			sum++;
		}
	}
	cout<<sum+1;
	return 0;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin>>a>>b;
  int x = (a+b)/2;
    
    if((a+b)%2 == 0){
    cout<< x <<endl;
    }
  else{
  cout<< (a+b+1)/2 <<endl;
  }
  
  
  
  
}


Measured memory_bytes: 256
X,N=map(int,input().split())
if N == 0:
    print(X)
else:
    S=set(map(int,input().split()))
    L=list(S)
    L.sort()
    S0= set( [i for i in range(L[0]-1,L[N-1]+2)] )
    S1=list(S0-S)
    S1.sort()
    D=100
    for i in S1:
        if abs(i-X) < D:
            D=abs(i-X)
            ans = i
    print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int y = 700;

  for (int i = 0; i < 3; i++) {
    if ( S.at(i) == 'o' ) {
      y = y + 100; 
    }
  }
  
  cout << y << endl;
  
}
  
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;
    
#define EPS (1e-7)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<n;++i){
        ans+=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
void main()
{
    long a, b;
    rdVals(a, b);

    max(0, a-2*b).writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int a[12][12];

const int INF = 1001001001;

using namespace std;

int main() {
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> c(n);
  for(int i = 0; i < n; ++i){
    cin >> c[i];

    for(int j = 0; j < m; ++j){
      cin >> a[i][j];
    }
  }

  int ans = INF;
  for(int s = 0; s < 1 << n; ++s){
    int cost = 0;
    vector<int> d(m);

    for(int i = 0; i < n; ++i){
      if(s >> i & 1){
        cost += c[i];

        for(int j = 0; j < m; ++j){
          d[j] += a[i][j];
        }
      }
    }
    bool ok = true;
    for(int j = 0; j < m; ++j){
      if(d[j] < x)  ok = false;
    }

    if(ok)  ans = min(ans, cost);
  }

  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3608
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

//cerrはコメントアウトしなくても通る

int main(){
    string s;
    cin >> s;
    int n=s.size();
    rep(i,n){
        if(i%2==0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
                continue;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
                continue;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll, ll>
#define pb push_back
#define rep0(i, n) for(ll i = 0;i<n;i++)
#define rep1(i, n) for(ll i = 1;i<n;i++)
#define all(v) v.begin(),v.end()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
const int MOD = 1e9+7;
const int N = 1e5 + 5;
void solve(){
    int n;
    cin >> n;
    vector<ll> arr(n);
    rep0(i, n){
        cin >> arr[i];
    }
    vector<ll> arr1 = arr;
    for(int i=n-2; i>=0; i--){
        arr1[i] += arr1[i+1];
        arr1[i] = arr1[i]%MOD;
    }
    ll ans = 0;
    for(int i=0; i<n-1; i++){
        ans += (arr[i]*arr1[i+1])%MOD;
        ans = ans%MOD;
    }
    cout << ans;
}

int main()
{
    fast;
    solve();
    // int t;
    // cin >> t;
    // while(t--){
    //     solve();
    // }
    return 0;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  i64 c, k;
  cin >> n >> c >> k;
  vector<i64> t(n);
  rep(i, 0, n) cin >> t[i];
  sort(all(t));

  int ans = 0;
  int i = 0;
  while(i < n) {
    int j = i + 1;
    i64 limit = t[i] + k;
    while(j < n && limit >= t[j] && j - i + 1 <= c) ++j;
    ans++;
    i = j;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
n = int(input())
robots = []
for i in range(n):
    x, l = map(int, input().split())
    robots.append((x, l))
robots.sort()

mx = -(10 ** 9)
n = 0
for x, l in robots:
    if x - l >= mx:
        n += 1
        mx = x + l
    else:
        mx = min(mx, x + l)

print(n)

Measured memory_bytes: 16988
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int A,B,C,N,X,ans = 0,dp[HMAX][WMAX];
char H,D;
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	int num = 1,sum = 0;
	while(num){
		sum += num;
		if(sum >= X){
			num = 0;
		}else{
			num++;
		}
		ans++;
	}
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> X;
	
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-12-3 12:53:19
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  int H, W;
  cin >> H >> W;
  for (auto i = 0; i < H; i++)
  {
    string S;
    cin >> S;
    cout << S << endl;
    cout << S << endl;
  }
}

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

int main(){
	int N,ans=0;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
      cin >> a[i];
      int s = a[i];
      while(s%2==0){
        s /= 2;
        ans++;
      }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
from collections import Counter
N = int(input())


def f(n):
    temp = n
    c = Counter()
    for i in range(2, n):
        if temp == 1:
            break
        while temp%i == 0:
            temp = temp//i
            c.update([i])
    else:
        c.update([temp])
    return c

c = Counter()
for i in range(2, N+1):
    c.update(f(i))

ans = 1
for _, x in c.items():
    ans = ans*(x+1) % 1000000007

print(ans)

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

bool solve() {
    int a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    int dist = abs(b-a);
    int dv = (v-w);
    if (dv <= 0) return false;
    int steps = dist/dv;
    if (dist%dv) ++steps;
    if (steps <= t) return true;
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    if (solve()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
x1,y1,x2,y2 = map(int, input().split())

difx = x2 - x1
dify = y2 - y1
dif = difx + dify

x3 = x2 - dify
x4 = x3 - difx
y3 = y2 + difx
y4 = y3 - dify

ans = list(map(str, [x3,y3,x4,y4]))
print(' '.join(ans))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int cnt=0;
    for(int i=0; i<n; i++){
        if((double)a[i] >= (double)sum/(4*m)){
            cnt++;
        }
    }
    if(cnt >= m ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	rep(i,n){
		if(s[i] == '7'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 3600
/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define tr cout<<"\n" 
#define br break
#define N 100005 
#define inf 10000000000000009
#define br break
/*  I know I have that Ability, I can do anything, 
I'll be The _Candidate Master_ 
(Patience and Practice)  */
 
//* ************************************************* Think Simple **********************************************************//
//************************************************HINTS******************************************************//
/* 
1. If we have to make Xor of 3 elements -> X, 3 elements will be Unique, ans->    (z^x^y)^y^z;  this will give us X
2. 
*/

void Waheguru()
{
  
int n;
cin>>n;
if(n==0)cout<<"1";
else cout<<"0";
tr;
}
 
 
int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;
map<int, int> mp;

int main(void){
    
    scanf("%d", &N);
    for(int i = 0; i < N; ++i){
        int a; scanf("%d", &a);
        ++mp[a];
    }
    
    int odd = 0, even = 0;
    for(auto m : mp){
        if(m.second % 2) ++odd;
        else ++even;
    }
    
    printf("%d\n", (even % 2) ? (even - 1) + odd : even + odd);
    
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n, x;
    cin >> n >> x;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int64_t r = 0;
    for (int i = 1; i < n; i++) {
        int d = a[i] + a[i - 1] - x;
        if (d > 0) {
            r += d;
            if (a[i] >= d) {
                a[i] -= d;
            } else {
                a[i - 1] -= d - a[i];
                a[i] = 0;
            }
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 768
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)
#define int long long

using namespace std;
typedef pair<int, int> pii;

string s,t;
int dp[2][3010][3010]={0},a[3010]={0};

signed main() {
	cin>>s>>t;

    rep(i,s.length()){
        rep(j,t.length()){
            dp[0][i+1][j+1]=dp[0][i][j+1];
            if(dp[0][i+1][j+1]<dp[0][i+1][j]){
                dp[0][i+1][j+1]=dp[0][i+1][j];
                dp[1][i+1][j+1]=2;
            }

            if(s[i]==t[j]){
                if(dp[0][i+1][j+1]<dp[0][i][j]+1){
                    dp[0][i+1][j+1]=dp[0][i][j]+1;
                    dp[1][i+1][j+1]=1;
                }
            }
        }
    }

    /*
    rep(i,s.length()+1){
        rep(j,t.length()+1){
            cout<<dp[0][i][j]<<" ";
        }
        cout<<'\n';
    }
    */

    int h=s.length(),w=t.length();
    stack<int> stc;
    while(h>0&&w>0){
        if(dp[1][h][w]==2){
            w--;
        }
        else if(dp[1][h][w]==1){
            stc.push(h);
            h--;
            w--;
        }
        else{
            h--;
        }
    }

    while(!stc.empty()){
        printf("%c",s[stc.top()-1]);
        stc.pop();
    }
    cout<<'\n';

    //cout<<dp[0][s.length()][t.length()]<<endl;
	
    
	
	return 0;
}


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

using namespace std;

using ll = long long;

int main(){
    int N;cin >> N;
    vector<int> vec;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        vec.push_back(b);
    }
    vector<int> ans(N);
    for(int i = N-2;i >= 0;i--){
        if(vec.at(i) >= vec.at(i+1)){
            ans[i] += ans.at(i+1) + 1;
        }
    }
    cout<<*max_element(ans.begin(), ans.end())<<std::endl;
}


Measured memory_bytes: 1144
//2019年5月19日
#include <stdio.h>
#include<math.h>
int main(int argc, char const *argv[]) {
  int N,K;
  int n,i;
  double value=0;
  int flag ;

  scanf("%d %d",&N,&K );

  for(i=1;i<=N;i++){
    flag = 1;
    for(n=0;flag!=0;n++){
      if(i*pow(2,n)>=K){
        value = value +(pow(0.5,n) / N );
        flag = 0;
      }
    }
  }

  printf("%1.10f\n",value);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#define MAX(a,b) ((a)>(b) ? (a) : (b))
int main(void){
  char S[500005];
  scanf("%s",S);
  int N = strlen(S)+1;
  long long int L[N],R[N];
  int i;
  long long int ans;
  for(i=0;i<N;i++){
    L[i]=0;
    R[i]=0;
  }
  for(i=0;i<N;i++){
    if(S[i]=='<')L[i+1] = L[i]+1;
  }
  for(i=N;i>=0;i--){
    if(S[i]=='>')R[i] = R[i+1]+1;
  }
  for(i=0;i<N;i++){
    ans += MAX(R[i],L[i]);
  }
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;

ll gcd(ll a, ll b)  {
    while (true) {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}

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

int main() {
    int N;
    cin >> N;
    ll T[N], ans = 1;
    for (int i = 0; i < N; i++) {
        cin >> T[i];
        ans = lcm(ans, T[i]);
    }
    cout<< ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    double a,b,c,d,e,f,x,y,work1,work2;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
        work1=c*e-b*f;work2=a*e-b*d;
        x=work1/work2;
        work1=c*d-a*f;work2=b*d-a*e;
        y=work1/work2;
        if(x<=0 && x>-0.0001)x=0;
        if(y<=0 && y>-0.0001)y=0;
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath> 
#define ll long long

ll MOD=1e9+7;
ll a[100005];
using namespace std;

int main(){
    ll n;
    cin>>n;
    
    ll flag=1;//flag 
    ll ans=1;
    
    if(n%2==0){ // even number 
    
        for(ll i=0;i<n;i++){
            ll x;
            cin>>x;
            a[x]++;//a[7]++
            
        
            if(x>=n || x%2==0 || a[x]>2){ 
                flag=0;
                cout<<"0"<<endl;
                break;
            }
            
            //The correct situation 
            if(a[x]==1)
                ans=ans*2%MOD; // a * b %c == a%c * b%c 
        }
    } 
    
    else{ //odd 
    
        for(ll i=0;i<n;i++){
            ll x;
            cin>>x;
            a[x]++;
            
            if(x>=n || x%2==1 || a[0]>1 ||a[x]>2){
                flag=0;
                cout<<"0"<<endl;
                break;
            }
            
            //The correct situation
            if(x!=0 && a[x]==1)
                ans=ans*2%MOD;
        }
    }
    
    if(flag)
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<cstdio>
#define pa pair<int,int>
#define MN 300000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}pa s[MN+5];
long long ans=0;
int w,h,n,num,L[MN+5],ql[MN+5],qr[MN+5],sl[MN+5],sr[MN+5],topl,topr,Mx[MN+5],Mn[MN+5];
struct Tree{int l,r,val,mx;}T[MN*4+5];
inline void Mark(int x,int v){T[x].mx+=v;T[x].val+=v;}
inline void pushdown(int x){Mark(x<<1,T[x].val);Mark(x<<1|1,T[x].val);T[x].val=0;} 
void Build(int x,int l,int r)
{
	if(T[x].val=0,(T[x].l=l)==(T[x].r=r)){T[x].mx=w-L[l];return;}
	int mid=l+r>>1;
	Build(x<<1,l,mid);Build(x<<1|1,mid+1,r); 
	T[x].mx=max(T[x<<1].mx,T[x<<1|1].mx);
}
void Modify(int x,int l,int r,int v)
{
	if(l>r) return;
	if(T[x].l==l&&T[x].r==r) return Mark(x,v);
	int mid=T[x].l+T[x].r>>1;
	if(T[x].val) pushdown(x); 
	if(r<=mid) Modify(x<<1,l,r,v);
	else if(l>mid) Modify(x<<1|1,l,r,v);
	else Modify(x<<1,l,mid,v),Modify(x<<1|1,mid+1,r,v);
	T[x].mx=max(T[x<<1].mx,T[x<<1|1].mx);
}	
int Query(int x,int l,int r)
{
	if(l>r) return -2e9;
	if(T[x].l==l&&T[x].r==r) return T[x].mx;
	if(T[x].val) pushdown(x);
	int mid=T[x].l+T[x].r>>1;
	if(r<=mid) return Query(x<<1,l,r);
	else if(l>mid) return Query(x<<1|1,l,r);
	else return max(Query(x<<1,l,mid),Query(x<<1|1,mid+1,r));
}
void Solve()
{
	L[num=1]=topr=topl=0;L[++num]=h;
	for(int i=1;i<=n;++i) L[++num]=s[i].second;
	sort(L+1,L+num+1);num=unique(L+1,L+num+1)-L-1;
	Build(1,1,num);
	for(int i=1;i<=num;++i) Mx[i]=w,Mn[i]=0; 
	for(int i=1;i<=n;++i)
	{
		int y=lower_bound(L+1,L+num+1,s[i].second)-L;
		if(s[i].first<=w/2) Mn[y-1]=max(Mn[y-1],s[i].first);
		if(s[i].first>=w/2) Mx[y-1]=min(Mx[y-1],s[i].first); 
	}
	for(int i=2;i<=num;++i)
	{
		ans=max(ans,2LL*Query(1,1,i-1)+2*L[i]);
		Modify(1,i-1,i-1,-w);
		while(topr&&Mx[i-1]<=sr[topr]) 
			Modify(1,qr[topr-1]+1,qr[topr],w/2-sr[topr]),--topr;
		Modify(1,qr[topr]+1,i-1,Mx[i-1]-w/2);qr[++topr]=i-1;sr[topr]=Mx[i-1];
		while(topl&&Mn[i-1]>=sl[topl])
			Modify(1,ql[topl-1]+1,ql[topl],sl[topl]-w/2),--topl;
		Modify(1,ql[topl]+1,i-1,w/2-Mn[i-1]);ql[++topl]=i-1;sl[topl]=Mn[i-1];
	}
}
int main()
{
	w=read();h=read();n=read();ans=max(w,h)*2+2;
	for(int i=1;i<=n;++i) s[i].first=read(),s[i].second=read();
	Solve();
	swap(w,h);
	for(int i=1;i<=n;++i) swap(s[i].first,s[i].second);
	Solve();
	printf("%lld\n",ans);
	return 0;
}



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

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [r, d, x] <- getIntList
    mapM print $ take 10 $ iterate (solve r d) (solve r d x)

solve r d x = r * x - d

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> tbl(h,vector<char>(w));
  vector<int> rf(h,1);
  vector<int> cf(w,1);
  char tmp;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin >> tbl.at(i).at(j);
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(tbl.at(i).at(j)!='.')
        rf.at(i) = 0;
  for(int i=0;i<w;i++)
    for(int j=0;j<h;j++)
      if(tbl.at(j).at(i)!='.')
        cf.at(i) = 0;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(cf.at(j)==0&&rf.at(i)==0){
        cout << tbl.at(i).at(j);
      }
    }
    if(rf.at(i)==0)
      cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <functional>

using namespace std;

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

    vector<long> A(N+1),B(N);
    for (size_t i = 0; i < N+1; i++)
    {
        cin >> A[i];
    }

    for (size_t i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    
    long cnt=0,p=0;

    for (size_t i = N; i >0; i--)
    {
        if(A[i]<=p){
            cnt += A[i];
            p = B[i-1];
            continue;
        }
        cnt+=p;
        A[i]-=p;

        if(B[i-1]<=A[i]){
            cnt+=B[i-1];
            p=0;
            continue;
        }
        cnt+=A[i];
        B[i-1]-=A[i];
        p = B[i-1];        
    }
    cnt += (A[0]>=p) ? p : A[0];
    cout << cnt << endl;

    return 0;
}

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

six_list = [6 ** i for i in range(7)]
nine_list = [9 ** i for i in range(6)]

import bisect

def six_nine(n):
  if n == 0:
    return 0
  else:
    six = six_list[bisect.bisect_right(six_list, n) - 1]
    nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
    return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))


print(six_nine(n))

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

int main() {
    int N;
    cin >> N;
  	int Alice = 0;
  	int Bob = 0;
    int a;
    vector<int> Card(N);
    //全てのカードをCardに登録する
  	for(int i = 0; i < N; i++){
        cin >> a;
        Card.at(i) = a;
    }
  	for(int i = 0; i < N; i++){
      	int MAX = 0;
      	int MAX_index = 0;
        //Cardの中で最も大きい数を見つけて変数MAXに記録し、その数の要素数をMAX_indexに記録する
       	for(int j = 0; j < N; j++){
           	if(Card.at(j) > MAX){
               	MAX = Card.at(j);
              	MAX_index = j;
            }
        }
      	Card.at(MAX_index) = 0; //Cardの中の最も大きな数を0に置き換える
        //順番が偶数だったらMAXの数をAliceに足し、奇数だったらBobに足す
		if(i % 2 == 0){
        	Alice += MAX;
        }else{
        	Bob += MAX;
        }
    }
  	cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r0 = sc.nextInt();
    int r = sc.nextInt();
    int max = r - r0;
    int min = Math.min(r, r0);
    for(int i = 2; i < n; i++) {
      r = sc.nextInt();
      max = Math.max(max, r - min);
      min = Math.min(min, r);
    }
    System.out.println(max);
  }
}



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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n;
	while(cin >> n, n){
		vector<int> v(n);
		rep(i, n) cin >> v[i];
		int ret = 0;
		while(true){
			vector<int> vv(n);
			rep(i, n){
				int c = 0;
				rep(j, n) if(v[i] == v[j]) c++;
				vv[i] = c;
			}

			bool possible = true;
			rep(i, n) if(v[i] != vv[i]) possible = false;
			if(possible) break;
			rep(i, n) v[i] = vv[i];
			ret++;
		}
		cout << ret << endl;
		rep(i, n) cout << (i == 0 ? "" : " ") << v[i];
		cout << endl;
	}
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1e9 + 7;
int main() {
    llint N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    llint sum = 0, k = 0;
    for(int i = 0; i < N; i++) {
        if(i != N - 1) {
            if(s[i] == 'L' && s[i + 1] == 'R') {
                k++;
                for(int j = i + 1; j < N; j++) {
                    if(s[j] == 'L') {
                        i = j - 1;
                        break;
                    }
                    else
                        s[j] = 'L';
                }
            }
            else if(s[i] == 'R' && s[i + 1] == 'L') {
                k++;
                for(int j = i + 1; j < N; j++) {
                    if(s[j] == 'R') {
                        i = j - 1;
                        break;
                    }
                    else
                        s[j] = 'R';
                }
            }
        }
        if(k == K)
            break;
    }
    for(int i = 0; i < N; i++) {
        if(s[i] == 'L' && i != 0 && s[i - 1] == 'L')
            sum++;
        else if(s[i] == 'R' && i != N - 1 && s[i + 1] == 'R')
            sum++;
    }
    cout << sum;
}

Measured memory_bytes: 512
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int H, W;
char mp[1010][1010];
ll dp[1010][1010];

int main(void){
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> mp[i][j];
		}
	}
	dp[0][0] = 1;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(i+1 < H && mp[i+1][j] != '#'){
				dp[i+1][j] += dp[i][j];
				dp[i+1][j] %= MOD;
			}
			if(j+1 < W && mp[i][j+1] != '#'){
				dp[i][j+1] += dp[i][j];
				dp[i][j+1] %= MOD;
			}
		}
	}
	cout << dp[H-1][W-1] << endl;
	
}


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

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a1 = 0, b1 = 0, c1 = 0;
  int a, b, c;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    a +=  max(b1, c1);
    b += max(a1, c1);
    c += max(b1, a1);
    a1 = a;
    b1 = b;
    c1 = c;
  }
  cout << max(max(a1, b1), c1);
  return 0;
}


Measured memory_bytes: 3192
// clang-format off

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

// clang-format on

int main() {
  int N, M, d, r, ans, key, A[60], B[60], C[60], D[60];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> C[i] >> D[i];
  }
  for (int i = 0; i < N; i++) {
    key = 1000000000;
    for (int j = 0; j < M; j++) {
      d = abs(A[i] - C[j]);
      r = abs(B[i] - D[j]);
      if (d + r < key) {
        key = d + r;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256