akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

bool in_arr(int* arr, int n, int x){
  for(int i=0; i<n; i++){
    if(arr[i] == x)
      return true;
  }
  return false;
}

int main(){
  int X, x, n;
  int arr[101], dif[101];
  while(cin >> X >> n){
    if(n == 0){
      cout << X << endl;
      continue;
    }
    for(int i=0; i<n; i++)
      cin >> arr[i];
    //sort(arr, arr+n);
    int dif_n = 0, dif_p = 0, x_n = X;
    while(in_arr(arr, n, x_n)){
      x_n = x_n - 1;
      dif_n = abs(X-x_n);
    }
    int x_p = X;
    while(in_arr(arr, n, x_p)){
      x_p = x_p + 1;
      dif_p = abs(X-x_p);
    }
    if(dif_p < dif_n)
      cout << x_p << endl;
    else
      cout << x_n << endl;
  }
}

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

typedef long long int ll;


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

    ll ans = 0;
    for(ll i = 0;i < n - 1;i++){
        for(ll j = i + 1;j < n;j++){
            ans += d[i] * d[j];
        }
    }

    cout << ans;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  bool x = 1;
  for(int i = 0; i < S.size(); i = i + 2){
    if(S.at(i) == 'L'){
      x = 0;
      break;
    }
  }
  for(int i = 1; i < S.size(); i = i + 2){
    if(S.at(i) == 'R'){
      x = 0;
      break;
    }
  }
  if(x){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp;

fn main() {
    input!{
        n: usize,
        aa: [usize; n],
    }
    let mut seen = vec![false; n];
    let mut i = 0;
    let mut cnt = 1;
    loop {
        if seen[i] { break; }
        if aa[i] == 2 {
            println!("{}", cnt);
            return;
        }
        seen[i] = true;
        i = aa[i] - 1;
        cnt += 1;
    }
    println!("{}", -1);
}


Measured memory_bytes: 4352
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < N; i++){
            Narabekae(i,a);
            for(int j = 0; j < N; j++){
                if(j != N-1){
                    System.out.print(a[j]+" ");
                }else{
                    System.out.println(a[j]);
                }
            }
        }
    }
    
    private static void Narabekae(int i, int a[]){
        for(int x = i; x > 0; x--){
            if(a[x-1] > a[x]){
                int a0;
                a0 = a[x-1];
                a[x-1] = a[x];
                a[x] = a0;
            }
        }
    }
}


Measured memory_bytes: 30416
#!/usr/bin/env ruby
N = gets.chomp.to_i
K = N.times.map { gets.split.map(&:to_i) }

res = true
ct = cx = cy = 0
N.times do |n|
  dt   = K[n][0] - ct
  dist = (K[n][1] - cx).abs + (K[n][2] - cy).abs
  if dt < dist || dt % 2 != dist % 2
    res = false
    break
  end
  ct = K[n][0]
  cx = K[n][1]
  cy = K[n][2]
end

puts res ? "Yes" : "No"

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

int main(){
    int N;
    cin >> N;
    int s[2 * N];
    int t = 0;
    for(int i=0; i < 2 * N; i++){
        cin >> s[i];
    }
    sort(s, s + 2 * N);
    for(int i=0; i < 2*N; i++){
        if(i%2 == 0)
            t += s[i];
    }
    cout << t << endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll n,q;
  cin>>n>>q;
  using T = tuple<ll,int,int,ll>;
  vector<T> events;
  rep(i,n){
    int s,t,x;
    cin>>s>>t>>x;
    events.emplace_back(s-x,1,1,x);
    events.emplace_back(t-x,1,2,x);
  }
  rep(i,q){
    int d;
    cin>>d;
    events.emplace_back(d,2,i,0);
  }
  sort(begin(events),end(events));

  vector<ll> ans(q);
  ll state = 0;
  multiset<ll> st;
  for(auto [a,b,c,d]:events){
    dump(a,b,c,d);
    if(state==0&&b==2)ans[c]=-1;
    if(state==1&&b==2)ans[c]=*st.begin();
    if(b==1){
      if(c==1){
        state = 1;
        st.emplace(d);
      }
      if(c==2){
        st.erase(st.find(d));
        if(st.empty())state=0;
      }
    }
  }
  for(auto x:ans)cout<<x<<endl;

}

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

int main() {
    int N;
    cin >> N;
    int x;
    int y;
    x = N * 800;
    N = N - N % 15;
    N = N / 15;
    y = N * 200;
    cout << x - y << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//モンスターのヒットポイント
		int h = sc.nextInt();
		//必殺技の種類
		int n = sc.nextInt();

		//敵の数
		int[] enemy = new int[h];

		for (int i = 0; i < h; i++) {
			enemy[i] = Integer.parseInt(sc.next());

		}
		Arrays.sort(enemy);
		h -= n;
		long num = 0L;

		for (int i = 0; i < h; i++) {
			num += enemy[i];

		}
		System.out.println(num);
		sc.close();

	}

}


Measured memory_bytes: 60916
#include <stdio.h>

int selectionSort(int A[], int N){
  int i,j,t,sw=0,minj;
  for(i=0 ; i<N-1 ; i++){
    minj = i;
    for(j=i ; j<=N-1 ; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    t = A[i];
    A[i] = A[minj];
    A[minj] = t;
    if(i != minj){
      sw++;
    }
  }
  return sw;
}

int main(){
  int A[100],N,i,sw;

  scanf("%d" ,&N);
  for(i=0 ; i<N ; i++)
    scanf("%d", &A[i]);

    sw=selectionSort(A, N);

    for(i=0 ; i<N ; i++){
      if(i>0)
        printf(" ");
      printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
  }



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,int> m;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll s = 0,ans = 0;
    m[0]++;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        s += a;
        ans += m[s]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12800
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x[10000], y[10000];
    int i, n , tmp;
    i=0;
    while (1) {
        scanf("%d %d", &x[i], &y[i]);
        if (x[i]==0 && y[i]==0) {
            break;
        }
        i++;
    }
    for (n=0; n<i; n++) {
        if (x[n]>y[n]) {
            tmp=x[n];
            x[n]=y[n];
            y[n]=tmp;
        }
        printf("%d %d\n", x[n], y[n]);
        
    }
    return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	int n, p[100][2];
	string s[100];
	cin >> n;
	int i,j;
	for (i = 0; i < n; i++) {
		cin >> s[i] >> p[i][0];
		p[i][1] = i + 1;
	}
	for (i = 0; i < n - 1; i++) {
		for (j = i+1; j < n; j++) {
			if (s[i] > s[j]) {
				swap(s[i], s[j]);
				swap(p[i], p[j]);
			}
		}
	}
	for (i = 0; i < n - 1; i++) {
		for (j = i + 1; j < n; j++) {
			if (s[i] == s[j]&&p[i][0]<p[j][0]) {
				swap(s[i], s[j]);
				swap(p[i], p[j]);
			}
		}
	}

	for (i = 0; i < n; i++) {
		cout << p[i][1] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=998244353;

int main(){
    string s;cin>>s;
    int n=s.size();
    int tmp;
    ll res=0;
    rep(i,n){
        tmp=s[i]-'0';
        res+=tmp;
    }
    if(res%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3748
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

void solve(long long N, long long K){
  if(K>(N-1)*(N-2)/2){
    cout << "-1" << endl;
    return;
  }
  vvi g(N);
  REP(i,1,N) g[0].pb(i);
  ll x = (N-1)*(N-2)/2 - K;
  dump(x);
  ll cnt = 0;
    bool no = false;
  
  REP(i,1,N-1){
    REP(j,i+1,N){
      if(x==0) break;
    g[i].pb(j);
    cnt++;
    if(cnt==x) no = true;
    if(no) break;
    }
    if(x==0) break;
    if(no) break;
  }
  int m = 0;
  rep(i,N) for(auto u:g[i]) m++;
  cout << m  << endl;
  rep(i,N) for(auto u:g[i]) cout << i+1 << " " << u+1 << endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  solve(N, K);
  return 0;
}


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

int main()
{
    int n;
    string s;
    int k;
    cin >> n;
    cin >> s;
    cin >> k;
    char c = s[k - 1];
    rep(i, n) {
        if(s[i] != c) s[i] = '*';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>

using namespace std;
#define MAX_N (10010)
#define INF (1000000100)
typedef struct {
    int to;
    int w;
} Edge;

vector<Edge> G[MAX_N];
int n;

int dist[MAX_N];
bool arrived[MAX_N];

void dijkstra(int s)
{
    priority_queue< pair<int, int> > PQ;
    for ( int i = 0; i < n; i++ ) {
	dist[i] = INF;
	arrived[i] = false;
    }

    dist[s] = 0;
    PQ.push(make_pair(0, 0));

    while ( !PQ.empty() ) {
	pair<int, int> f = PQ.top(); PQ.pop();
	int u = f.second;
	
	if ( (-1 * f.first) > dist[u] ) continue;

	arrived[u] = true;
	
	for ( int i = 0; i < G[u].size(); i++ ) {
	    Edge e = G[u][i];
	    if ( !arrived[e.to] && dist[e.to] > (dist[u] + e.w) ) {
		dist[e.to] = dist[u] + e.w;
		PQ.push(make_pair(-1 * dist[e.to], e.to));
	    }
	}
    }

}

int main()
{
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);

	for ( int j = 0; j < k; j++ ) {
	    int v, c;
	    Edge e;
	    scanf("%d %d", &v, &c);
	    e.to = v;
	    e.w = c;
	    G[u].push_back(e);
	}
    }

    dijkstra(0);

    for ( int i = 0; i < n; i++ ) {
	printf("%d %d\n", i, dist[i]);
    }

    return 0;
}

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

int main(){

	int a, b, c;
	cin >> a >> b >> c;
	string ans = "NO";
	for(int i = a; i <= a*b; i+=a)
	{
		if(i % b == c) ans = "YES";
	}
	

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

void show (int* a, int n)
{
	for (int i=0; i<n; i++) {
		std::cout << a[i] << ",";
	}
	std::cout << std::endl;
}

int main()
{
	int n, m, star, d;
	while (true) {
		std::cin >> n;
		
		if (n==0) break;
		
		std::cin >> m;
		std::cin >> star;
		std::cin >> d;
		
		std::string* bars = new std::string[d];
		for (int i=0; i<d; i++) std::cin >> bars[i];
		
		int* up_to_down = new int[d+2];
		int* down_to_up = new int[d+2];
		
		
		up_to_down[0] = m;
		for (int i=1; i<=d; i++) {
			bool left  = (up_to_down[i-1] >= 2   && bars[i-1][up_to_down[i-1]-2] == '1');
			bool right = (up_to_down[i-1] <= n-1 && bars[i-1][up_to_down[i-1]-1] == '1');
			if (left) up_to_down[i] = up_to_down[i-1] - 1;
			else if (right) up_to_down[i] = up_to_down[i-1] + 1;
			else up_to_down[i] = up_to_down[i-1];
		}
		up_to_down[d+1] = up_to_down[d];
		
		if (up_to_down[d+1] == star) { // can reach the star
			std::cout << 0 << std::endl;
		}
		else { // cannot reach the star
			down_to_up[d+1] = star;
			for (int i=d; i>=1; i--) {
				bool left  = (down_to_up[i+1] >= 2   && bars[i-1][down_to_up[i+1]-2] == '1');
				bool right = (down_to_up[i+1] <= n-1 && bars[i-1][down_to_up[i+1]-1] == '1');
				if (left) down_to_up[i] = down_to_up[i+1] - 1;
				else if (right) down_to_up[i] = down_to_up[i+1] + 1;
				else down_to_up[i] = down_to_up[i+1];
			}
			down_to_up[0] = down_to_up[1];
			
			bool reachable = false;
			for (int i=1; i<=d; i++) {
				if (up_to_down[i-1] == up_to_down[i] && down_to_up[i] == down_to_up[i+1]) {
					if (up_to_down[i] - down_to_up[i] == 1) {
						std::cout << i << " " << down_to_up[i] << std::endl;
						reachable = true;
						break;
					}
					else if (down_to_up[i] - up_to_down[i] == 1) {
						std::cout << i << " " << up_to_down[i] << std::endl;
						reachable = true;
						break;
					}
				}
			}
			if (!reachable) std::cout << 1 << std::endl;
		}
		
		//show(up_to_down, d);
		//show(down_to_up, d);
		
		delete[] bars;
		
		delete[] up_to_down;
		delete[] down_to_up;
	}
	return 0;
}
	


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

ll l, r;
const ll mod = 2019;

int main() {
    cin >> l >> r;
    ll mini = 1e18;
    for (int i = l; i <= min(r, l+mod); i++) {
        for (int j = i+1; j <= min(r,l+mod); j++) {
            mini = min(mini, ((i%mod)*(j%mod))%mod);
        }
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;
    cin>>n;
    ld n1=n;
    ld div=3*3*3;
    ld ans=n1/div*n1*n1;
    cout<<fixed<<setprecision(12)<<ans;

    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
N,K=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
a=a[:bisect_left(a,K)]
d=[False]*(K)
d[0]=True
curr_max=0
ans=len(a)
for i,a in reversed(list(enumerate(a))):
  if curr_max+a>=K:
    ans=i
  c=curr_max
  for j in range(curr_max+1)[::-1]:
    if j+a<K and d[j]:
      d[j+a]=True
      c=max(c,j+a)
  curr_max=c
print(ans)
  
        

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

int dp[3001][3001];
 
int main()
{
  string str1,str2;
  cin>>str1>>str2;
  int len1 = str1.length();
  int len2 = str2.length();
 
  for(int i = 0 ; i<=len1 ; i++)
  {
    for(int j = 0 ; j<=len2 ; j++)
    {
      dp[i][j] = 0;
    }
  }
 
  for(int i = 1 ; i<=len1 ; i++)
  {
    for(int j = 1 ; j<=len2 ; j++)
    {
      if(str1[i-1]==str2[j-1])
      {
        dp[i][j] = dp[i-1][j-1] + 1;
      }
      else
      {
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
 
    }
  }
 
 
  int len = dp[len1][len2];

  string out;

  int i = len1 , j = len2;
  while(len > 0)
  {
    if(str1[i-1] == str2[j-1])
    {
      out.push_back(str1[i-1]);
      i--;
      j--;
      len--;
    }
    else
    {
      if(dp[i-1][j] > dp[i][j-1])
      {
        i--;
      }
      else
      {
        j--;
      }
    }
  }

  reverse(out.begin(),out.end());

  cout<<out;
 
  return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int a,b,c;
  while(cin >> a>> b >> c,a+b+c) {
    int n;
    cin >> n;
    vector<vector<int> > vv;
    vector<int> ans(a+b+c, 2);
    REP(i,n) {
      vector<int> v(3);
      REP(k,3) {
        cin >>v[k];
        v[k]--;
      }
      bool f;
      cin >> f;
      if (f) {
        REP(k,3) ans[v[k]] = 1;
      } else {
        vv.push_back(v);
      }
    }
    bool update = 1;
    while(update) {
      update = 0;
      FOR(it,vv) {
        if (ans[(*it)[2]] == 2 && ans[(*it)[0]] == 1 && ans[(*it)[1]] == 1) {
          update = 1;
          ans[(*it)[2]] = 0;
        } else if (ans[(*it)[0]] == 2 && ans[(*it)[1]] == 1 && ans[(*it)[2]] == 1) {
          update = 1;
          ans[(*it)[0]] = 0;
        } else if (ans[(*it)[1]] == 2 && ans[(*it)[0]] == 1 && ans[(*it)[2]] == 1) {
          update = 1;
          ans[(*it)[1]] = 0;
        } 
      }
    }
    REP(i,a+b+c) {
      cout << ans[i] << endl;
    }
  }

}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#define INT long long int

using namespace std;
string s;

INT dp(int x, INT v, INT z)
{
    if( x == s.size() ) return z+v;
    return dp(x+1, v*10+(s[x]-'0'), z) + dp(x+1, (s[x]-'0'), z+v);
}

int main()
{
    cin>>s;
    cout<<dp(1, s[0]-'0', 0);
}


Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <algorithm>
#define ll long long
#define INF 100000000000000
using namespace std;

int main(){
  ll N, W;
  cin >> N >> W;
  ll v[100], w[100];
  for(ll i = 0; i < N; i++){
    cin >> v[i] >> w[i];
  }
  ll dp[N+1][W+1];
  for(ll i = 0; i < N + 1; i++){
    for(ll k = 0; k < W + 1; k++){
      dp[i][k] = 0;
    }
  }

  for(ll i = 1; i <= N; i++){
    for(ll k = 1; k <= W; k++){
      dp[i][k] = dp[i-1][k];
      if(k >= w[i-1]){
	dp[i][k] = max(dp[i][k], dp[i-1][k-w[i-1]] + v[i-1]);
      }
    }
  }
  cout << dp[N][W] << endl;
  

}

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

map<int, int> to[6];

bool check(string s) {
    int now = 0;
    
    for (int i=0; i<s.size(); i++) {
        if (to[now].find(s[i]-'0')==to[now].end()) {
            return false;
        }
        
        now = to[now][s[i]-'0'];
    }
    
    return now==5;
}

int main() {
    to[0][0] = 1;
    to[0][1] = 2;
    to[1][1] = 3;
    to[2][0] = 1;
    to[3][0] = 4;
    to[3][1] = 5;
    to[4][0] = 5;
    to[4][1] = 2;
    to[5][0] = 2;
    to[5][1] = 1;
    
    while (true) {
        string p; cin >> p;
        
        if (p=="#") {
            break;
        }
        
        if (check(p)) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}


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

#define watch(x) cout << (#x) << " = " << x << endl;
#define mkp make_pair
#define mkt make_tuple
#define pb push_back
#define ll long long
#define ld long double
#define x first
#define y second

using namespace std;

pair<ll, ll> memo[3010][3010];
int n, a[3010];

pair<ll, ll> dp(int i, int j){
	if(i + j == n) return mkp(0, 0);
	pair<ll, ll>& ret = memo[i][j];

	if(ret.x != -1) return ret;

	if((i + j) & 1){
		//X - Y minimised

		if(dp(i + 1, j).x - a[i] - dp(i + 1, j).y < dp(i, j + 1).x - a[n - 1 - j] - dp(i, j + 1).y){
			ret = mkp(dp(i + 1, j).x, dp(i + 1, j).y + a[i]);
		} else {
			ret = mkp(dp(i, j + 1).x, dp(i, j + 1).y + a[n - j - 1]);
		}
	} else {
		if(dp(i + 1, j).x + a[i] - dp(i + 1, j).y > dp(i, j + 1).x + a[n - 1 - j] - dp(i, j + 1).y){
			ret = mkp(dp(i + 1, j).x + a[i], dp(i + 1, j).y);
		} else {
			ret = mkp(dp(i, j + 1).x + a[n - j - 1], dp(i, j + 1).y);
		}
	}

	return ret;
}

int main(){
	scanf("%d", &n);

	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			memo[i][j] = mkp(-1, -1);
		}
	}

	pair<ll, ll> ans = dp(0, 0);

	printf("%lld\n", ans.x - ans.y);

	return 0;
}

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

using namespace std;

typedef long long ll;

const ll maxn = 3e5+10;
const ll ZERO = 0;
const ll SADAT = 7.84e-17;
const ll INF = 1e10;
const ll mod = 1e9+7;

#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);

int n;

int main(){
	cin >> n;
	ll ans = 0  ;
	ans = n*n*n;
	cout << ans;

	return(0);
}
//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, l is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int h, w, k; cin >> h >> w >> k;
    vector<vector<int>> grid(h, vector<int>(w));

    FOR(i, 0, h) {
        FOR(j, 0, w) {
            char c; cin >> c;
            grid[i][j] = c == '#' ? 1 : 0;
        }
    }

    int countpat = 0;
    for (int biti = 0; biti < (1 << h); ++biti) {
        for (int bitj = 0; bitj < (1 << w); ++bitj) {
            int count = 0;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if (!bitcheck(biti, i)
                    && !bitcheck(bitj, j)
                    && grid[i][j] == 1
                    ) {
                        ++count;
                    } 
                }
            }
            if (count == k) ++countpat;
        }
    }
    cout << countpat << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3672
#include<cstdio>
long long GET()
{
    long long x=0,f=1;
    char c;
    c=getchar();
    if (c==' ') return x*f;
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    return x*f;
}
int main()
{
	long long n,m;
	n=GET();
	m=GET();
	//scanf("%lld%lld",&n,&m);
	long long ans=m-n*2;
	if(ans<0)
	{
		printf("%lld\n",m>>1);
		return 0;
	} 
	printf("%lld\n",n+(ans>>2));
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=55555;

int prime[MAX+1];
bool isp[MAX+1];

int main(){
	//入力
	int N;
	cin >> N;
	
	int p = 0;
	//初期化
	for(int i=0;i<=55555;i++)isp[i]=true;
	isp[0]=isp[1]=false;
	//2以上で素数ならふるい落とす
	for(int i=2;i<=55555;i++){
		if(isp[i]){
			p++;
			prime[p]=i;
			for(int j=2*i;j<=55555;j+=i) isp[j]=false;
		}
	}
	int flag=0,k=1;
	while(flag<N){
		if(prime[k]%5==1){
			cout<<prime[k]<<" ";
			flag++;
			}
		k++;
	}
}

Measured memory_bytes: 384
def solve(n, h, v):
    v = sorted(v, key=lambda x: -x[1])
    opt_a = 0
    opt_b = 0
    opt_i = 0
    for i in range(n):
        a, b = v[i]
        if (opt_a < a) or ((opt_a == a) and (opt_b > b)):
            opt_i = i
            opt_a = a
            opt_b = b
    ans = 0
    for i in range(n):
        a, b = v[i]
        if (i != opt_i) and (opt_a < b):
            h -= b
            ans += 1
            if h <= 0:
                return ans
    if h - opt_b <= 0:
        return ans + 1
    else:
        m = (h - opt_b + opt_a - 1) / opt_a
        return ans + m + 1

n, h = map(int, raw_input().split())
v = [map(int, raw_input().split()) for i in range(n)]
print solve(n, h, v)

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

a = [int(input()) for _ in range(n)]
a.sort()

ans = 0

if n % 2 == 0:
    ans = sum(a[n//2+1:]) * 2 + a[n//2] - sum(a[:n//2-1]) * 2 - a[n//2-1]
else:
    ans1 = sum(a[n//2+1:]) * 2 - sum(a[:n//2+1]) - sum(a[:n//2-1])
    ans2 = sum(a[n//2:]) + sum(a[n//2+2:]) - sum(a[:n//2]) * 2
    ans = max(ans1, ans2)

print(ans)

Measured memory_bytes: 7504
#include <iostream>
using namespace std;
int main() {
    int n,k=2;
    cin>>n;
    int i,j,ar[n],dp[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
        if(i==0)
        {
            dp[i]=0;
            continue;
        }
        else
        {
            dp[i]=2e9;
        }
        for(j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(ar[i]-ar[i-j]));
            }
            else
            {
                break;
            }
        }
    }
    cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Set as S

main :: IO ()
main = do
    ss <- getLine
    let s = S.fromList ss
    let t = S.fromDistinctAscList ['a'..'z']
    case S.minView (S.difference t s) of
        Nothing      -> putStrLn "None"
        Just (c, _)  -> putStrLn [c]

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);



int main(void)
{
    IOS
    int n,m;
    cin >> n >> m;
    vector<int> v(m);
    for(auto i = 0; i < m; i++) cin >> v[i];

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

    vector<int> d(m-1);
    for(auto i = 0; i < m-1; i++) d[i] = v[i+1] - v[i];
    sort(d.begin(),d.end());
    if (m <= n) {
        cout << "0" << endl;
    } else {
        auto l = accumulate(d.begin(),d.end()-n+1,0LL);
        cout << l << endl;
    }

    
    return 0;
    }


Measured memory_bytes: 1024
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int ha, sa, hb, sb;
    cin >> ha >> sa >> hb >> sb;
    int i = 1;
    while(1){
        if(i & 1){
            hb -= sa;
        }else{
            ha -= sb;
        }
        i++;
        if(ha <= 0){
            cout << "No";
            return 0;
        }
        if(hb <= 0){
            cout << "Yes";
            return 0;
        }
    }
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);

  ll ans = 0;
  for(ll i=1; i<=N; ++i){
    ll N_tmp = N/i;
    ll tmp = ((N_tmp*(N_tmp+1))/2)*i;
    ans += tmp;
  }

  OUT(ans);


  return 0;
}


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


int main() {
    int n,k;
    cin >> n >> k;
    int arr[n];
    int a;
    for (int i = 0; i < n; i++){
        cin >> a;
        arr[i] = a;
    }
    int cost[n];
    for (int i = 0; i < n; i++) {
        cost[i] = 0;
    }
    vector<int> costs;
    int left;
    for(int i = 1; i < n; i++) {
        costs.clear();
        if ((i - k) < 0) {
            left = 0;
        }
        else {
            left = i - k;
        }
        for (int j = left; j < i; j++) {
            costs.push_back(cost[j]+abs(arr[i]-arr[j]));
        }
        cost[i] =*min_element(costs.begin(),costs.end());
    }
    cout << cost[n-1];
    return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define setbits(x) (__builtin_popcount(x))
int mod=1000000007;
int INF64=mod*mod+1;

void solve(){
	int n;
	cin>>n;

	int ans=1;

	for(int a=2;a<=n-1;a++){
		int i=a;
		int curr=1;
		for(int j=2;j*j<=i;j++){
			int x=0;
			while((i%j)==0){
				i/=j;
				x++;
			}
			curr*=(x+1);
		}
		if(i!=1)
			curr*=2;
		ans+=curr;
	}

	cout<<ans;
}

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

	int T;
	// cin>>T;
	T=1;
	for(int i=1;i<=T;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll l,r;
    cin >> l >> r;
    r = min(r, l+4038);
    int ans=2018;
    for(ll i=l; i<=r; i++){
        for(ll j= i+1; j<= r; j++){
            int x = i*j%2019;
            ans = min(ans,x);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=107;
const int M=100007;
const LL inf=1e16;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,cnt,a[N];
int bgn[N],nxt[M],to[M],E=1;
LL c[M],ans;
inline void ADD(int u,int v,LL w){nxt[++E]=bgn[u],bgn[u]=E,to[E]=v,c[E]=w;}
inline void add_edge(int u,int v,LL w){ADD(u,v,w),ADD(v,u,0);}
struct Netflow
{
	int cur[N],dis[N],S,T,n;
	inline void init(int s,int t,int cnt){S=s,T=t,n=cnt;}
	inline bool bfs()
	{
		memset(dis,0,n*sizeof(int));
		dis[S]=1;
		queue<int>q;
		q.push(S);
		while(!q.empty())
		{
			int u=q.front();q.pop();
			for(int v,i=bgn[u];i;i=nxt[i])
				if(c[i]&&!dis[v=to[i]])
					dis[v]=dis[u]+1,q.push(v);
		}
		return dis[T]!=0;
	}
	inline LL dfs(int u,LL flow)
	{
		if(u==T)return flow;
		LL ret=flow;
		for(int v,&i=cur[u];i;i=nxt[i])
			if(c[i]&&dis[v=to[i]]==dis[u]+1)
			{
				LL f=dfs(v,min(ret,c[i]));
				c[i]-=f,c[i^1]+=f,ret-=f;
				if(!ret)return flow;
			}
		return flow-ret;
	}
	inline LL Maxflow()
	{
		LL ans=0;
		while(bfs())
		{
			memcpy(cur,bgn,n*sizeof(int));
			ans+=dfs(S,inf);
			cerr<<ans<<endl;
		}
		return ans;
	}
}Dinic;
int main()
{
	int s,t;
	file();
	read(n);
	For(i,1,n)read(a[i]);
	cnt=n;s=++cnt;t=++cnt;
	Dinic.init(s,t,++cnt);
	For(i,1,n)
	{
		if(a[i]>0)add_edge(i,t,a[i]),ans+=a[i];
		else add_edge(s,i,-a[i]);
		For(j,1,n/i)add_edge(i,i*j,inf);
	}
	printf("%lld\n",ans-Dinic.Maxflow());
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>

using namespace std;

int main()
{
	int n, l, r, sum = 0, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d", &l, &r);
		sum += r - l + 1;
	}

	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	
	static final int[] dx = { -1, 0, 0, 1 };
	static final int[] dy = { 0, -1, 1, 0 };
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		
		char[][] block = new char[h][w];
		Point[] point = new Point[n + 1];
		
		for (int y = 0; y < h; y++) {
			String s = sc.next();
			for (int x = 0; x < w; x++) {
				char c = s.charAt(x);
				if (c == 'S') {
					point[0] = new Point(x, y);
				} else if ('1' <= c && c <= '9') {
					point[c - '0'] = new Point(x, y);
				}
				block[y][x] = c;
			}
		}
		
		sc.close();
		
		int total = 0;
		int[][] time = new int[h][w];
		Deque<Point> q = new ArrayDeque<>();
		
		for (int i = 0; i < n; i++) {
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					time[y][x] = 0;
				}
			}
			q.clear();
			q.offer(point[i]);
			while (!q.isEmpty()) {
				Point p = q.poll();
				if (p.equals(point[i + 1])) {
					total += time[p.y][p.x];
					break;
				}
				for (int j = 0; j < 4; j++) {
					int _x = p.x + dx[j];
					int _y = p.y + dy[j];
					if (((0 <= _y && _y < h) && (0 <= _x && _x < w)) && time[_y][_x] == 0 && block[_y][_x] != 'X') {
						time[_y][_x] = time[p.y][p.x] + 1;
						q.offer(new Point(_x, _y));
					}
				}
			}
		}
		
		System.out.println(total);
	}
	
	static class Point {
		int x, y;
		
		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
		
		boolean equals(Point p) {
			return (this.x == p.x && this.y == p.y);
		}
	}
}

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

int main() {

    string s;
    cin >> s;
    cout << s[0] << s.length() - 2 << s[s.length()-1] << endl;

    return 0;
}

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

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

  ll ans = 0;
  for (int c = 1; c <= n-1; c++) {
    ll score = 0;
    vector<bool> v(n,false);
    for (int x = 0;(x+1)*c < n-1;x++) {
      if(v[x*c]) break;
      score += a[x*c];
      v[x*c] = true;
      if(v[n-1-x*c]) break;
      score += a[n-1-x*c];
      v[n-1-x*c] = true;
      ans = max(ans,score);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4052
n = int(input())
s = input()
num = [0 for i in range(n)]
w = [0 for i in range(n)]
if s[0] == 'W':
    w[0] = 1
for i in range(1, n):
    if s[i] == 'W':
        w[i] = (w[i-1] + 1)
    else:
        w[i] = w[i-1]
e = [0 for i in range(n)]
if s[n-1] == 'E':
    e[n-1] = 1
for i in range(2, n+1):
    if s[n-i] == 'E':
        e[n-i] = (e[n-i+1] + 1)
    else:
        e[n-i] = e[n-i+1]
sol = [0 for i in range(n)]
sol[0] = e[0]
sol[n-1] = w[n-2]
for i in range(1, n-1):
    sol[i] = w[i-1] + e[i+1]
print(min(sol))


Measured memory_bytes: 32084
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<=N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


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

long long  weight[110];
long long value[110];

for(int i=0;i<N;i++){
    cin>>weight[i]>>value[i];
}

long long dp[110][100010];
//dp[i][k]:=重さkまででi番目までのitemを詰めた時の価値の最大値

for(int k=0;k<=W;k++)dp[0][k]=0;
//rep(i,N)dp[i][0]=0;
for(int i=0;i<N;i++){
    for(int k=0;k<=W;k++){
    if(weight[i]<=k){   
    dp[i+1][k]=max(dp[i][k],dp[i][k-weight[i]]+value[i]);
    }
    else {
        dp[i+1][k]=dp[i][k];}
    }
}
cout<<dp[N][W]<<endl;
 return 0;
}
/*
3 8
3 30
4 50
5 60

90

5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

5000000000

6 15
6 5
5 6
6 4
6 6
3 5
7 2

17

*/

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

const int MAXM = 3000000;
const int MAXN = 3000;

int n , m ;

bool cmp(int a,int b){
return a>b;
}
int a[ MAXN ];
int ans[MAXN*2][2];
int tot=0;

int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int MAXi=0;
    for (int i=1;i<=n;i++)
        if (abs( a[i] ) > abs( a[MAXi] ) )
            MAXi = i;
    if ( MAXi )
    for (int i=1;i<=n;i++)
        if ( i!=MAXi )
        {
            ++tot;
            ans[tot][0]=MAXi;
            ans[tot][1]=i;
        }
    if ( a[ MAXi ] < 0 )
        {
            for (int i=n;i>=2;i--)
            {
                ++tot;
                ans[tot][0]=i;
                ans[tot][1]=i-1;
            }
        }
    else
        if ( a[ MAXi ] > 0 )
            {
                for (int i=1;i<n;i++)
                {
                    ++tot;
                    ans[tot][0]=i;
                    ans[tot][1]=i+1;
                }
            }
    printf("%d\n",tot);
    for (int i=1;i<=tot;i++)
        printf("%d %d\n",ans[i][0],ans[i][1]);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 998244353;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
ll n, m, k;

int main(){
    cin>>n>>k;
    n=n%k;
    n=min(n,abs(n-k));
    cout<<n<<endl;
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=3030;
int n,m;
ll dp[N][N];
string s,t;

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>s>>t;
	n=s.size(),m=t.size();
	for(int i=0;i<=n;++i)
		for(int j=0;j<=m;++j){
			if(i<n&&j<m&&s[i]==t[j])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
			dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		}
//	for(int i=0;i<=n;++i,cout<<endl)
//		for(int j=0;j<=m;++j)
//			cout<<dp[i][j]<<" ";
	int i=n,j=m,cnt;
	string res;
	while(cnt=dp[i][j]){
		while(i&&dp[i-1][j]==cnt)--i;
		while(j&&dp[i][j-1]==cnt)--j;
		--i;--j;
		res.push_back(s[i]);
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
}


Measured memory_bytes: 74708