akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;
const int N=200005;
int n,m,x,y,cnt,head[N],vis[N],deg[N][2],q[N],qtd,qtl;
char col[N];
struct edge{
  int to,nex;
}e[N*2];
void add(int x,int y){
  e[++cnt].to=y;e[cnt].nex=head[x];head[x]=cnt;
  e[++cnt].to=x;e[cnt].nex=head[y];head[y]=cnt;
}
int main(){
  scanf("%d%d",&n,&m);
  scanf("%s",col+1);
  for (int i=1;i<=m;i++) {
  scanf("%d%d",&x,&y),add(x,y);
  deg[x][col[y]=='B']++;deg[y][col[x]=='B']++;
  }
  for (int i=1;i<=n;i++)
    if (deg[i][0]==0||deg[i][1]==0) vis[q[qtl++]=i]=1;
  while (qtd!=qtl){
  	int x=q[qtd++];
  	for (int i=head[x];i;i=e[i].nex)
  	  if (!vis[e[i].to]){
  	  	 if (!--deg[e[i].to][col[x]=='B']){
  	  	 	  vis[e[i].to]=1;
  	  	 	  q[qtl++]=e[i].to;
			 }
		}
  }
  if (qtl==n) puts("No");
  else puts("Yes");
  return 0;
}

Measured memory_bytes: 7296
//
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    long in[30];
    long out[30];
    int n = 0;
    long max = 0;
    while(cin >> in[n]){
        if(max < in[n]){
            max = in[n];
        }
        n++;
    }
    //printf("%d", n);
    
    long p[100000];
    p[0] = 2;
    int m = 1;
    for (int i = 3; i <= max; i += 2) {
        bool prime = true;
        for(int j = 0; j < m; j++){
            if (i % p[j] == 0) {
                prime = false;
                break;
            }
            if (i < pow(p[j], 2)) {
                break;
            }
        }
        if (prime) {
            p[m] = i;
            //printf("%ld\n", p[m]);
            m++;
        }
    }
    
    
    for (int i = 0; i < n; i++) {
        int s = 0;
        while (in[i] >= p[s] && p[s] != 0) {
            //printf("in: %ld, p: %ld\n", in[i], p[s]);
            s++;
        }
        out[i] = s;
        printf("%ld\n", out[i]);
    }
    
    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> as(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
  }
  int ans = 0, nax = -1;
  for (int i = 0; i < n; i++) {
    ans += as[i] >= nax;
    nax = max(nax, as[i]);
  }cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(void) {
	// in
	long long x, y;
	std::cin >> x >> y;

	// loop
	long long xx = x;
	int len = 0;
	while(xx <= y) {
		xx *= 2;
		++len;
	}

	std::cout << len << std::endl;

	return 0;
}


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

using namespace std;
//100 10 90
int main(){
    int X;
    int N;
    cin >> X >> N;
    unordered_set<int>s;
    if(N == 0){
        cout << X << endl;
        return 0;
    }
    while(N--){
        int i;
        cin >> i;
        s.insert(i);
    }
    int mn = 110;
    int ans = 0;
    for(int i = 0;i <= 101;i++){
        if(s.count(i)!=0)
            continue;
        int x = abs(X-i);
        if(mn > abs(X-i)){
            mn = abs(X-i);
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
   
using namespace std;
    
void Solution()
{
    int n, x;
  
    while(cin>>n>>x)
    {
        int count = 0;
        
        if(n == 0 && x == 0) break;
        
        for(int a = 1; a <= n; a++)
        {
            for(int b = a + 1; b <= n; b++)
            {
                for(int c = b + 1; c <= n; c++)
                { 
                    if(a + b + c == x) count++;
                }
            }
        }
        
        cout<<count<<endl;
    }

}
   
int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] s = sc.nextLine().split("");
		sc.close();
		String ans = "";
		for(int i = 0; i < s.length; i++) {
			if(s[i].equals("B")) {
				if(!(ans.equals(""))) {
					ans = ans.substring(0,ans.length()-1);
				}
			}else {
				ans += s[i];
			}
		}
		System.out.println(ans);
	}
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

const lli mod = 1e9 + 7;

template<int N = 50>
struct M {
  lli x[N][N];
  M()
  {
    fill(&x[0][0], &x[N - 1][N - 1], 0);
  }
};



template<int N>
M<N> operator * (M<N> a, M<N> b)
{
  M<N> c;
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        (c.x[i][j] += a.x[i][k] * b.x[k][j]) %= mod;
      }
    }
  }
  return c;
}

template<int N>
M<N> power(M<N> m, lli p)
{
  if (p == 1) return m;
  if (p == 0) {
    M<N> e;
    for (int i = 0; i < N; ++i) {
      e.x[i][i] = 1;
    }
    return e;
  }

  M<N> a = power(m, p / 2);
  if (p % 2) return a * a * m;
  else return a * a;
}

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

  int n;
  lli k;
  while (cin >> n >> k) {
    M<50> m;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> m.x[i][j];
      }
    }
    m = power(m, k);
    lli sum = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        (sum += m.x[i][j]) %= mod;
      }
    }
    cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector<vector<int>> a(3,vector<int>(3));
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			cin >> a[i][j];
		}
	}
	int n; cin >> n; 
	for(int k=0; k<n; ++k){
		int b; cin >> b;
		for(int i=0; i<3; ++i){
			for(int j=0; j<3; ++j){
				if(a[i][j]==b){
					a[i][j]=0;
					goto OUT;
				}
			}
		}
		OUT: ;
	}
	
	string ans="No";
	for(int i=0; i<3; ++i){
		if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0) ans="Yes";
		if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0) ans="Yes";
	}
	if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0) ans="Yes";
	if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0) ans="Yes";
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9 + 7)
#define MAX_N (200000)


ll N, T;
ll X[MAX_N];

void solve() {
  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans += min(T, X[i + 1] - X[i]);
  }
  ans += T;

  cout << ans << endl;
}

int main() {
  cin >> N >> T;
  for (int i = 0; i < N; i++) cin >> X[i];

  solve();

  return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict as dd
from bisect import bisect_left
N = int(input())

Ps = []
for _ in range(N):
    X, Y, U = input().split()
    Ps.append((int(X), int(Y), U))
Ps.sort()

case1 = dd(list)
case2 = dd(list)
case3 = dd(list)
case4 = dd(list)
case5 = dd(list)
case6 = dd(list)

INF = float('inf')
ans = INF
for x, y, u in Ps:
    if u == 'U':
        case2[y-x].append(y)
        case5[x].append(y)
        if y+x in case1:
            idx = bisect_left(case1[y+x], -y)
            if idx > 0:
                t = (-y - case1[y+x][idx-1]) * 10
                ans = ans if ans < t else t

    elif u == 'R':
        case1[y+x].append(-y)
        case3[y-x].append(y)
        case6[y].append(x)
    elif u == 'D':
        case4[y+x].append(-y)
        if y-x in case3:
            idx = bisect_left(case3[y-x], y)
            if idx > 0:
                t = (y - case3[y-x][idx-1]) * 10
                ans = ans if ans < t else t
        if x in case5:
            idx = bisect_left(case5[x], y)
            if idx > 0:
                t = (y - case5[x][idx-1]) * 5
                ans = ans if ans < t else t
    elif u == 'L':
        if y-x in case2:
            idx = bisect_left(case2[y-x], y)
            if idx > 0:
                t = (y - case2[y-x][idx-1]) * 10
                ans = ans if ans < t else t
        if y+x in case4:
            idx = bisect_left(case4[y+x], -y)
            if idx > 0:
                t = (-y - case4[y+x][idx-1]) * 10
                ans = ans if ans < t else t
        if y in case6:
            idx = bisect_left(case6[y], x)
            if idx > 0:
                t = (x - case6[y][idx-1]) * 5
                ans = ans if ans < t else t
if ans == INF:
    print('SAFE')
else:
    print(ans)


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

int ar[100005];

int main()
{
  ll n, i, ans, cnt=0, sum=0;

  cin>>n;

  for(i=0; i<n; i++)
  {
    cin>>ar[i];
    if(ar[i]<0)
    {
      cnt++;
      ar[i]=ar[i]*-1;
    }
  }
  sort(ar,ar+n);

  if(cnt%2==1)
  {
   ar[0]=ar[0]*-1;
  }

  for(i=0; i<n; i++)
  {
    sum+=ar[i];
  }

  cout<<sum<<endl;
}

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

int main() {
  int N;
  cin >> N;
  
  int sum;
    
  for(int n = N; n != 0; n = n / 10){
    sum += n % 10;
  }
  
  if(N % sum == 0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}





Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi h(n);
  int ans = 0;
  rep(i, n){
    cin >> h[i];
    bool ok = true;
    for(int j = 0; j < i; j++){
      if(h[i] < h[j]) ok = false;
    }
    if(ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;
//string s=bitset<32>(n).to_string();
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    lli k,x;
	cin>>k>>x;
	if(500*k>=x)cout<<"Yes";
	else cout<<"No";        


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define For(i,a,b) for(int i = a;i<=b;i++)
typedef pair<int,int> PII;
const int N = 100000 + 5;
int pre[N];
void init(int l){
    For(i,1,l) pre[i] = i;
}
int Find(int x){
    int p,tmp;
    p = x;
    while(x != pre[x]){
        x = pre[x];
    }
    while(x != p){
        tmp = pre[p];
        pre[p] = x;
        p = tmp;
    }
    return x;
}
void join(int x,int y){
    int q = Find(x);
    int p = Find(y);
    if(q != p) pre[q] = p;
}
bool same(int x,int y){
    return Find(x) == Find(y);
}
int n,m;
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    init(n);
    while(m--){
        int a,b;
        cin>>a>>b;
        join(a,b);
    }
    int cnt = 0;
    For(i,1,n){
        if(i == pre[i]) cnt++;
    }
    cout<<cnt-1<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    string s;
    cin >> s;
    int n;
    n= s.length();
    int gz=0,go=0;
    int kz=0,ko =0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(s[i]=='0'){
                gz++;
            }
            else{
                go++;
            }
        }
        else{
            if(s[i]=='0'){
                kz++;
            }
            else{
                ko++;
            }
        }
    }
    //printf("gz=%d,go=%d,kz=%d,ko=%d\n",gz,go,kz,ko);
    cout << min(gz+ko,go+kz)<<endl;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
const int maxn = 1e5 + 10;
int n, A[maxn];

void solve() {
  int x1, y1, x2, y2, k;
  cin >> x1 >> y1 >> x2 >> y2 >> k;
  int tot = (x2 - x1) * 60 + y2 - y1;
  cout << tot - k << endl;
}

int main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> left(n);
  left[0] = 0;
  for (int i = 1; i < n; i++) {
    left[i] = max(left[i - 1], a[i - 1]);
  }
  vector<int> right(n);
  right[n - 1] = 0;
  for (int i = n - 2; i >= 0; i--) {
    right[i] = max(right[i + 1], a[i + 1]);
  }
  for (int i = 0; i < n; i++) {
    cout << max(left[i], right[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N, K;
	string S;
	cin >> N >> K >> S;
	S[K - 1] = S[K - 1] - 'A' + 'a';
	cout << S;
}

Measured memory_bytes: 256
program example

    implicit none

    integer :: K,N,i
    integer,allocatable :: A(:),wa(:),sa(:)

    read(*,*) K,N

    allocate(A(N),wa(N),sa(N))

    read(*,*) A(:)

    sa(N)=A(1)+K-A(N)

    do i=1,N-1

        sa(i)=A(i+1)-A(i)

    end do

    write(*,*) sum(sa)-maxval(sa)

end program example


Measured memory_bytes: 2432
import java.util.*;

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

        int N = stdin.nextInt();

        Integer a[] = new Integer[N];

        for (int i = 0; i < N; i++) {
            a[i] = stdin.nextInt();
        }

        Arrays.sort(a, Comparator.reverseOrder());

        int Alice = 0;
        int Bob = 0;

        for (int i = 0; i < N; i += 2) {
            Alice += a[i];
        }

        for (int i = 1; i < N; i += 2) {
            Bob += a[i];
        }

        System.out.println(Alice - Bob);

    }
}


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

const int N = 200000 + 10;

int n, m;

std::vector<int> pool[N];

int tag[2 * N], max[2 * N];

inline int pos(int l, int r) { return (l + r) | (l != r); }

void apply(int l, int r, int v) {
  int id = pos(l, r);
  max[id] += v;
  tag[id] += v;
}

void release(int l, int r) {
  int id = pos(l, r), mid = (l + r) >> 1;
  if (tag[id]) {
    apply(l, mid, tag[id]);
    apply(mid + 1, r, tag[id]);
    tag[id] = 0;
  }
}

void update(int l, int r) {
  int id = pos(l, r), mid = (l + r) >> 1;
  int lch = pos(l, mid), rch = pos(mid + 1, r);
  max[id] = std::max(max[lch], max[rch]);
}

void build(int l, int r) {
  int id = pos(l, r);
  max[id] = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid);
  build(mid + 1, r);
}

void add(int l, int r, int p, int q, int v) {
  if (p <= l && r <= q) {
    apply(l, r, v);
    return;
  }
  release(l, r);
  int mid = (l + r) >> 1;
  if (p <= mid) add(l, mid, p, q, v);
  if (q > mid) add(mid + 1, r, p, q, v);
  update(l, r);
}

int query(int l, int r, int p, int q) {
  if (p <= l && r <= q) return max[pos(l, r)];
  release(l, r);
  int mid = (l + r) >> 1, res = 0;
  if (p <= mid) res = query(l, mid, p, q);
  if (q > mid) res = std::max(res, query(mid + 1, r, p, q));
  return res;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (r > 1) pool[l].push_back(r - 1);
  }
  build(1, m);
  int ans = std::max(n, m);
  for (int i = 0; i < m; ++i) {
    for (auto j : pool[i]) add(1, m, 1, j, 1);
    ans = std::max(ans, query(1, m, i + 1, m) - i);
  }
  printf("%d\n", n - (n + m - ans));
  return 0;
}


Measured memory_bytes: 11648
s = input()
flag1 = "ng"
flag2 = "ng"
for i in s:
    if flag1 == "ok":
      if i == "C":
        flag2 = "ok"
        break
    if i == "A":
      flag1 = "ok"
    else:
      flag1 = "ng"

if flag2 == "ng":
  print("No")
else:
  print("Yes")

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

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

int main(void) {
    int k, n;
    scanf("%d %d", &k, &n);
    vector<int> a(n+1);
    rep(i, n) scanf("%d", &a[i]);
    a[n] = k + a[0];

    int ans = 0;
    int tmp = 0;
    int dis = 0;
    rep(i, n) {
        dis = a[i + 1] - a[i];
        if(dis > tmp) {
            ans += tmp;
            tmp = dis;
        } else {
            ans += dis;
        }
    }
    
    printf("%d", ans);
    
    return 0;
}


Measured memory_bytes: 1024
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	ll a = 1;
	ll b = 1;
	rep(i,n){
		ll aa,bb;
		cin>>aa>>bb;
		ll x = (a+aa-1)/aa;
		ll y = (b+bb-1)/bb;
		if(x<y){
			b = y*bb;
			a = y*aa;
		}
		else{
			a = x*aa;
			b = x*bb;
		}
	}
	cout<<a+b<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> t(N+1), x(N+1), y(N+1);
    for (int i = 1; i <= N; i++) cin >> t[i] >> x[i] >> y[i];
    bool ans = true;
    for (int i = 1; i <= N; i++) {
        int time = t[i] - t[i-1];
        int dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
        if (time < dist) ans = false;
        else if (time > dist && (time - dist)&1) ans = false;
    }
    
    cout << (ans ? "Yes" : "No") << '\n';
}

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

    solve();

    return 0;
}

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

int calc(int s, int t)
{
	if (s == t) return 0;
	int res = 0;
	if (s & 1) s++, res++;
	if (t & 1) t--, res++;
	return res + calc(s / 2, t / 2);
}

int main()
{
	int n, s, t;
	cin >> n;
	while (n--){
		cin >> s >> t;
		cout << calc(s, t) << endl;
	}
}

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

Measured memory_bytes: 3588
N,M = map(int,input().split())

x = 2 ** N

ks = []
for i in range(M):
    ks.append(list(map(int,input().split())))

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

ans = 0

for i in range(x):
    str_i = str(bin(i))[2:].zfill(N)
    flag = True
    for j in range(M):
        ks_j = ks[j]
        on_sum = 0
        for k in range(ks_j[0]):
            if(str_i[ks_j[k+1]-1] == '1'):
                on_sum += 1
        if(on_sum % 2 != p[j]):
            flag = False
            break
    if(flag):
        ans += 1

print(ans)

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

int main(){
  int A,B,C;
  cin >> A >> B;
  if(B<10){
    C = A*10 + B;
  }else if(B<100){
    C = A*100 + B;
  }else{
    C = A*1000 + B;
  }
  bool exist = false;
  for(int i=0;i<350;i++){
    if(i*i == C){
      exist = true;
    }
  }
  if(exist){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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


def main():
    n = int(input())
    abc = [[0 for _ in range(3)] for _ in range(n)]
    dp = [[0 for _ in range(3)] for _ in range(n + 1)]

    for i in range(n):
        ai, bi, ci = map(int, input().split())
        abc[i][0] = ai
        abc[i][1] = bi
        abc[i][2] = ci

    # See:
    # https://qiita.com/drken/items/dc53c683d6de8aeacf5a
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue

                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i][k])

    print(max(dp[n]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 73308
#include <string.h>

#include <algorithm>
#include <iostream>
#include <vector>

#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main(void) {
  string str;
  cin >> str;
  int size = str.length();
  if (str[size - 1] == 's') {
    str += "es";
  } else {
    str += "s";
  }

  cout << str << endl;
  return 0;
}

Measured memory_bytes: 3624
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int cnt = 0;
  for (int i = a; i <= b; i++)
    if (c % i == 0) cnt++;
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 1148
import sys
input = sys.stdin.readline
from collections import *

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]
cnt = defaultdict(lambda: defaultdict(int))

for i in range(N):
    for j in range(N):
        cnt[(i+j)%3][c[i][j]-1] += 1

ans = 10**18

for c1 in range(C):
    for c2 in range(C):
        for c3 in range(C):
            if c1==c2 or c2==c3 or c3==c1:
                continue
            
            cand = 0
            
            for k, v in cnt[0].items():
                cand += v*D[k][c1]
            
            for k, v in cnt[1].items():
                cand += v*D[k][c2]
            
            for k, v in cnt[2].items():
                cand += v*D[k][c3]
            
            ans = min(ans, cand)

print(ans)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> x(n),y(m);

  REP(i,n)cin>>x[i]; 
  REP(i,m)cin>>y[i];

  ll xx=0;
  REP(i,n){
    xx += ((2*i-n+1)*x[i] % MOD);
    xx %= MOD;
  }
  ll yy=0;
  REP(i,m){
    yy += ((2*i-m+1)*y[i] % MOD);
    yy %= MOD;
  }
  cout << (xx*yy)%MOD << endl;


}



Measured memory_bytes: 1792
import sys

class Node:
    def __init__(self, value, p = None, l = None, r = None):
        self.key = value
        self.p = p
        self.left = l
        self.right = r

def getroot(x):
    if x.p != None:
        return getroot(x.p)
    return x

def preorder(x, A):
    if x == None:
        return
    A.append(x.key)
    preorder(x.left, A)
    preorder(x.right, A)

def inorder(x, A):
    if x == None:
        return
    inorder(x.left, A)
    A.append(x.key)
    inorder(x.right, A)

def postorder(x, A):
    if x == None:
        return
    postorder(x.left, A)
    postorder(x.right, A)
    A.append(x.key)

def ptree(root):
    pre = [""]
    ino = [""]
    preorder(root, pre)
    inorder(root, ino)
    print(" ".join(map(str,ino)))
    print(" ".join(map(str,pre)))

def find(value, root):
    if root == None:
        return "no"
    elif value < root.key:
        return find(value,root.left)
    elif value > root.key:
        return find(value,root.right)
    return "yes"

def insert(Tree, root, z):
    y = None # x ??????
    x = root  # 'T ??????'
    while x != None:
        y = x # ???????¨????
        if z.key < x.key:
            x = x.left # ?????????????§????
        else:
            x = x.right # ?????????????§????
    z.p = y

    Tree.append(z)
    if y == None: # T ???????????´???
        return z
    elif z.key < y.key:
        y.left = z # z ??? y ?????????????????????
    else:
        y.right = z # z ??? y ?????????????????????
    return root

def main():

    """ ????????? """
    num = int(input().strip())
    istr = sys.stdin.read()
    cmds = list(istr.splitlines())
    Tree = []
    root = None
    for i in range(num):
        cmd = cmds[i][0]
        if cmd == "i":
            n = Node(int(cmds[i][7:]))
            root = insert(Tree, root, n)
        elif cmd == "f":
            print(find(int(cmds[i][5:]),root))
        elif cmd == "p":
            ptree(root)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 210048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N =3030;
ll a[N],vis[N][N],ans[N][N],n;

void solve(ll l, ll r)
{
	if(vis[l][r])return;
	vis[l][r]=1;
	ll k = r-l+1;k=n-k;

	if(l==r)
	{
		ans[l][r]=a[l];
		if(k%2==1)ans[l][r]*=-1;
		return;
	}

	solve(l+1,r);
	solve(l,r-1);
	if(k%2==0)ans[l][r]=max(a[l]+ans[l+1][r],a[r]+ans[l][r-1]);
	else ans[l][r]=min(ans[l+1][r]-a[l],ans[l][r-1]-a[r]);
}

int main()
{
    ios_base::sync_with_stdio(false);

	clr(vis);
	cin>>n;forn(i,n)cin>>a[i];
	solve(0,n-1);
	cout<<ans[0][n-1]<<endl;

}


Measured memory_bytes: 144000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		int cnt = 0;
		for(int i = 1 ; i <= 10000000 ; i++) {
			if(func(i) == d) cnt++;
			if(cnt == n) {
				System.out.println(i);
				return;
			}
		}
	}

	static int func(int x) {
		int ret = 0;
		while(x % 100 == 0) {
			ret++;
			x /= 100;
		}
		return ret;
	}

}


Measured memory_bytes: 23764
N,K=list(map(int,input().split()))
A=sorted(list(map(int,input().split())))
F=sorted(list(map(int,input().split())),reverse=True)

ok=10**12
ng=0

while abs(ok-ng)>0:
    center=(ok+ng)//2
    cnt=0

    for i in range(N):
        ap=center//F[i]
        cnt+=max(0,A[i]-ap)
        if K<cnt:
            ng=center+1
            break
    else:
        ok=center

print(ok)

Measured memory_bytes: 117664
N, W = map(int, input().split())  # N<=100, W<=10**9
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())  # すべての i=2,3,…,N について、w1 ≦ wi ≦ w1+3

#

def kaihou():
    monos_by_omosa = [[] for _ in range(4)]
    w0 = w[0]
    for i in range(N):
        monos_by_omosa[w[i] - w0].append(v[i])
    for i in range(4):
        monos_by_omosa[i].sort()
        monos_by_omosa[i].reverse()
    # print(monos_by_omosa)
    ans = 0
    for i in range(N + 1):
        if i > len(monos_by_omosa[0]):
            break
        w0i = (w0) * i
        if w0i > W:
            break

        for j in range(N + 1 - i):
            if j > len(monos_by_omosa[1]):
                break
            w1j = (w0 + 1) * j
            if w0i + w1j > W:
                break

            for k in range(N + 1 - i - j):
                if k > len(monos_by_omosa[2]):
                    break
                w2k  = (w0 + 2) * k
                if w0i + w1j + w2k > W:
                    break

                for l in range(N + 1 - i - j - k):
                    if l > len(monos_by_omosa[3]):
                        break
                    w3l = (w0 + 3) * l
                    if w0i + w1j + w2k + w3l > W:
                        break

                    val = sum(monos_by_omosa[0][:i])
                    val += sum(monos_by_omosa[1][:j])
                    val += sum(monos_by_omosa[2][:k])
                    val += sum(monos_by_omosa[3][:l])
                    ans = max(ans, val)
    return ans

print(kaihou())


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

using lli = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<lli, lli> > ab(n), cd(m);
  for(auto& pii : ab) cin >> pii.first >> pii.second;
  for(auto& pii : cd) cin >> pii.first >> pii.second;

  for(auto pab : ab) {
    lli check = 1000000000;
    lli res;

    rep(i, m) {
      lli dx = abs(pab.first - cd.at(i).first);
      lli dy = abs(pab.second - cd.at(i).second);
      
      if(check > dx+dy) {
        check = dx+dy;
        res = i+1;
      }
    }

    cout << res << endl;
  }
  return 0;
}


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

long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 1e6+100;
typedef long long int lld;
typedef long long ll;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}

ll findGcd(ll a, ll b){
    while(a != 0) { ll temp = b % a; b = a; a = temp; }
    return b;
}

vector<ll> Adj[lim], Set, Query[lim];
ll Array[lim], BArray[lim], dp[lim];
map<ll,ll> M, InverseMap, Map;

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,temp,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B,C;
    A = "Yes", B="No";
    // cin>>T;
    // rep(tt,1,T) {
    // }
    cin>>n;
    ans=0;

    rep(i,1,n-1) {
        for(ll j=i;j<n;j+=i) ans++;
    } 
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 50500
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (_, _, _, K) = read!(usize, usize, usize, usize);
    let mut A = read![[i64]];
    let mut B = read![[i64]];
    let mut C = read![[i64]];

    A.sort_by(|l, r| r.cmp(l));
    B.sort_by(|l, r| r.cmp(l));
    C.sort_by(|l, r| r.cmp(l));

    let mut S = vec![];

    for a in 0..A.len() {
        for b in 0..B.len() {
            if (a + 1) * (b + 1) - 1 >= K {
                // このとき (a, b, c) の組み合わせのうち a, b の値がいまの a, b より小さいようなものが K 個以上ある。
                // そのような組み合わせはいずれもいまの (a, b, _) 以上の和になる。 (c として最大値を選べばいい)
                // だからいまの a, b を使った組み合わせ (a, b, _) は上位 K 個に入らないと考えていい。
                break;
            }

            for c in 0..C.len() {
                if (a + 1) * (b + 1) * (c + 1) - 1 >= K {
                    break;
                }

                let sum = A[a] + B[b] + C[c];
                S.push(sum);
            }
        }
    }

    S.sort_by(|l, r| r.cmp(l));
    debug!(S);

    for s in S.into_iter().take(K) {
        println!("{}", s);
    }
}


Measured memory_bytes: 6396
N, *A = open(0).read().split()


class BIT():
    def __init__(self, n, x=1):
        self.n = n
        self.T = [[0]*20 for _ in [0]*20]

    def add(self, i, y, x):
        i += 1
        y += 1
        while i <= self.n:
            j = y
            while j <= self.n:
                self.T[i][j] += x
                j += j & -j
            i += i & -i

    def _sum(self, i, y):
        i += 1
        y += 1
        ret = 0
        while i > 0:
            j = y
            while j > 0:
                ret += self.T[i][j]
                j ^= j & -j
            i ^= i & -i
        return ret

    def sum(self, i, j):
        return self._sum(18, 18) - self._sum(i-1, 18) - self._sum(18, j-1) + self._sum(i-1, j-1)


ans = 0
B = BIT(19)


def fact(n):
    cnt2 = cnt5 = 0
    for _ in range(18):
        if n % 2:
            break
        n //= 2
        cnt2 += 1
    for _ in range(18):
        if n % 5:
            break
        n //= 5
        cnt5 += 1
    return cnt2, cnt5


for a in A:
    if '.' in a:
        a, b = a.split('.')
        cnt2 = cnt5 = 9 - len(b)

        a = int(a) * (10**len(b)) + int(b)
        c2, c5 = fact(a)
        cnt2 += c2
        cnt5 += c5
    else:
        cnt2 = 9
        cnt5 = 9

        a = int(a)
        c2, c5 = fact(a)
        cnt2 += c2
        cnt5 += c5

    cnt2 = min(18, cnt2)
    cnt5 = min(18, cnt5)

    ans += B.sum(18-cnt2, 18-cnt5)
    B.add(cnt2, cnt5, 1)

print(ans)


Measured memory_bytes: 114572
char s[1<<20];m[1<<20],n;main(t){t=--*m;for(gets(s);s[n];m[++n]=++t)for(;~t&&s[t]-s[n];t=m[t]);t=n-t;n=!printf(t*2<n?"Love %.*s!\n":"mitomerarenaiWA\n",t*=n/3/t+1,s);}

Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int match[]={2, 5, 5, 4, 5, 6, 3, 7, 6};

int main(){
    int n, m; cin>>n>>m;
    vector<int> a(m);
    vector<bool> canuse(m, false);
    for(int i=0; i<m; i++){
        cin>>a[i];
        a[i]--;
        canuse[a[i]]=true;
    }

    vector<int> dp(n+10, -1);
    dp[0]=0;
    for(int i=0; i<10; i++){
        if(!canuse[i]) continue;
        for(int j=0; j+match[i]<=n; j++){
            dp[j+match[i]]=max(dp[j+match[i]], dp[j]+1);
        }
    }

    string ans;
    int rem=n;
    while(rem){
        for(int i=8; i>=0; i--){
            if(!canuse[i]) continue;
            if(rem<match[i]) continue;

            if(dp[rem-match[i]]==dp[rem]-1){
                rem-=match[i];
                ans+=(char)('0'+i+1);
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int r;
	cin >> r;

	cout << r * r * 3;

	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    string S;
    cin >> S;
    for (size_t i = 0; i < S.size(); i++)
    {
        cout << 'x';
    }
    cout << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [[0 for i in range(2)] for j in range(M)]
s = set()
ispossible = False
for i in range(M):
	ab[i] = list(map(int, input().split()))
	if ab[i][0] == 1:
		s.add(ab[i][1])
for i in range(M):
	if ab[i][0] in s and ab[i][1] == N:
		ispossible = True
		break
if ispossible:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')


Measured memory_bytes: 52328
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}

string A, B;
int main() {
  cin >> A>> B;
  if (A.size() > B.size()) {
    printf("GREATER\n");
  } else if (A.size() < B.size()) {
    printf("LESS\n");
  } else {
    FORN(i, A.size()) {
      int a, b;
      a = A[i] - '0';
      b = B[i] - '0';
      if (a < b) {
        printf("LESS\n");
        return 0;
      } else if (a > b) {
        printf("GREATER\n");
        return 0;
      }
    }
    printf("EQUAL\n");
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int n, k;
  cin>>n>>k;
  vi v(n);
  for(int i=0;i<n;++i) cin>>v[i];
  sort(all(v));
  ll sum = 0;
  for(int i=0;i<k;i++)
    sum+=v[i];
  cout<<sum<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3604
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(W, H, N, inputs):
    actions = list(map(string_to_int, inputs))
    white_x1 = 0
    white_x2 = W
    white_y1 = 0
    white_y2 = H

    for a in actions:
        if a[2] == 1:
            if white_x1 < a[0]:
                white_x1 = a[0]
        elif a[2] == 2:
            if white_x2 > a[0]:
                white_x2 = a[0]
        elif a[2] == 3:
            if white_y1 < a[1]:
                white_y1 = a[1]
        elif a[2] == 4:
            if white_y2 > a[1]:
                white_y2 = a[1]

    if white_x1 >= white_x2 or white_y1 >= white_y2:
        return 0
    return (white_x2 - white_x1) * (white_y2 - white_y1)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [W, H, N] = string_to_int(input())
    ret = solve(W, H, N, inputs(N))
    print(ret)


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

mid = sum(a)//len(a)
ans1 = 0
ans2 = 0

for i in a:
  ans1 += pow(abs(i - mid),2)
  ans2 += pow(abs(i - (mid+1)),2)
print(min(ans1, ans2))
           
  


Measured memory_bytes: 3060