akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
ch=[0]*(n+1)
kai=[0]
for i in a:
  ch[i]+=1
for i in range(n):
  kai.append(kai[i]+i+1)
ans=0
for i in ch:
  if i==0:
    continue
  ans+=kai[i-1]
for i in a:
  print(ans-(kai[ch[i]]-kai[ch[i]-1])+1)

Measured memory_bytes: 32292
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl

int main(){
    int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
    ll ans=0;

    if(2*c<a+b){
        ll temp=min(x,y);
        ans+=2*c*temp;
        x-=temp;
        y-=temp;
    }

    if(2*c<a){
        ans+=2*c*x;
        y-=x;
        x=0;
    }
    if(2*c<b&&y>0){
        ans+=2*c*y;
        x-=y;
        y=0;
    }

    if(x>0){
        ans+=a*x;
    }

    if(y>0){
        ans+=b*y;
    }

    cout<<ans<<endl;
}

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

using namespace std ;

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

const int MAXN =  100010 ; 

int a[MAXN];  
int main() { 
	
		int n, k ; 
		scanf("%d%d", &n, &k) ; 
		int d = 0 ; 
		for (int i = 1; i <= n; i ++) scanf("%d", &a[i]) , d = gcd(a[i], d);
	    
		for (int i = 1; i <= n; i ++) { 
				if (a[i] >= k && (a[i] - k) % d == 0) {
						puts("POSSIBLE") ;
						return 0 ; 
				}
		}
		puts("IMPOSSIBLE") ; 
}	




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y)
{
	return y?gcd(y,x%y):x;
}
int n,fir,sec,cnt[1000001]; 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		cnt[a]++;
		sec=gcd(sec,a);
	}
	for(int i=2;i<=1000000;i++)
	{
		int sum=0;
		for(int l=i;l<=1000000;l+=i)
			sum+=cnt[l];
		if(sum>1)
		{
			fir=1;
			break;
		}
	}
	cout<<(fir?sec==1?"setwise coprime":"not coprime":"pairwise coprime");
	return 0;
}

Measured memory_bytes: 7624
#include<stdio.h>
#include <iostream>
#include <math.h>
#define sq(x) ((x) * (x))
using namespace std;

int main()
{ 
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  printf("%f\n",  sqrt( sq(x1 - x2) + sq(y1 - y2))); 
  
  return 0;   
}


Measured memory_bytes: 3208
#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 REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
const int DEBUG = 0;

std::vector<int> perm_inv(const std::vector<int> &p) {
  int len = p.size();
  std::vector<int> ans(len);
  for (int i = 0; i < len; ++i) {
    ans[p[i]] = i;
  }
  return ans;
}

const int N = 100010;
bool done[N];

bool match(int n, int m, const VI &target, const VI &op, int tol) {
  assert (0 <= tol && tol < m);
  assert (target.size() == m);
  VI inv_t = perm_inv(target);
  VI prog(m + 1);
  VI pass(m + 1);
  prog[0] = n;
  REP(i, 0, op.size()) {
    int idx = inv_t[op[i]];
    if (prog[idx] == 0 && !pass[idx]) {
      return false;
    }
    if (prog[idx] == 0) {
      continue;
    }
    prog[idx]--;
    prog[idx + 1]++;
    pass[idx] = 1;
  }
  if (DEBUG) {
    REP(i, 0, m + 1) {
      cout << "prog[" << i << "]=" << prog[i] << endl;
    }
  }
  REP(i, 0, tol) {
    if (prog[i] > 0) {
      return 0;
    }
  }
  return 1;
}

int main(void){
  int n, m, q;
  cin >> n >> m >> q;
  VI a(q);
  REP(i, 0, q) {
    cin >> a[i];
    a[i]--;
  }
  reverse(a.begin(), a.end());
  vector<bool> used(m);
  int cur = 0;
  VI target(m);
  REP(i, 0, q) {
    if (used[a[i]]) {
      continue;
    }
    used[a[i]] = 1;
    target[cur] = a[i];
    cur++;
  }
  REP(i, 0, m) {
    if (!used[i]) {
      target[cur++] = i;
    }
  }
  assert (cur == m);
  int oldcur = m - 1;
  while (oldcur > 0) {
    if (target[oldcur - 1] < target[oldcur]) {
      oldcur--;
    } else {
      break;
    }
  }
  if (DEBUG) {
    cerr << "target:";
    REP(i, 0, m) {
      cerr << " " << target[i];
    }
    cerr << endl << "tol = " << oldcur << endl;
  }
  cout << (match(n, m, target, a, oldcur) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 2304
#include <iostream>

using namespace std;

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

    int h[n];

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

    int cnt = 1;

    for (int j = 1; j < n; j++) {    
        int flag = 0;
        for (int i = 0; i < j; i++) {
            if (h[j] < h[i]) {
                flag = 1;
                break;
            }
        }
        if (flag == 0)
            cnt = cnt + 1;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}

void solve() {
  // main coding
  ll n,w; cin>>n>>w;
  vector<ll> W(n+1),V(n+1);
  rep1(i,n+1) cin>>W[i]>>V[i];
  vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
  rep1(i,n+1) rep(c,w+1) {
    if(c-W[i]>=0) dp[i][c]=max(dp[i-1][c],dp[i-1][c-W[i]]+V[i]);
    else dp[i][c]=dp[i-1][c];
  }
  cout<<dp[n][w]<<endl;
}

int main() {
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;
int main(){ 
  int n;
  cin >> n;
  vector<P> a(n);
  rep(i,n) {
    int x, l;
    cin >> x >> l;
    a[i].first = x + l;
    a[i].second = x - l;
  }
  sort(a.begin(), a.end());
  int res = 0;
  int pl = -INF;
  for (int i = 0; i < n; i++) {
    if (a[i].second < pl) {
      res++;
      continue;
    }
    pl = a[i].first;
  }
  cout << n - res << endl;
  return 0;
} 

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        int H = sc.nextInt();
        int W = sc.nextInt();
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt();
        }

        System.out.println(solve(H, W, a));

        sc.close();
    }

    static String solve(int H, int W, int[] a) {
        int[][] colors = new int[H][W];
        int r = 0;
        int c = 0;
        int offsetC = 1;
        int index = 0;

        while (r != H) {
            colors[r][c] = index + 1;

            c += offsetC;
            if (c == -1 || c == W) {
                ++r;
                c -= offsetC;
                offsetC *= -1;
            }

            --a[index];
            if (a[index] == 0) {
                ++index;
            }
        }

        return Arrays.stream(colors)
                .map(row -> Arrays.stream(row).mapToObj(String::valueOf).collect(Collectors.joining(" ")))
                .collect(Collectors.joining("\n"));
    }
}

Measured memory_bytes: 33692
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
typedef long long ll;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    
    vector<int> cost(n,INT_MAX);
    cost[0] = 0;

    for(int i = 0; i < n; ++i){
       for(int j = 1; j <= k && i+j < n; ++j){
           cost[i+j] = min(cost[i+j],cost[i]+abs(h[i+j]-h[i]));
       }
    }

    cout << cost[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var (
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
)

func main() {
	defer writer.Flush()
	var S string
	fmt.Fscanf(reader, "%s\n", &S)
	ss := strings.Split(S, "")
	az := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	azMap := make(map[string]bool)
	for _, alfa := range az {
		azMap[alfa] = false
	}
	for _, s := range ss {
		azMap[s] = true
	}
	for _, alfa := range az {
		if !azMap[alfa] {
			fmt.Fprintf(writer, "%s\n", alfa)
			return
		}
	}
	fmt.Fprintf(writer, "%s\n", "None")
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long double pi=3.141592653589793;
int main(void){
  long double a,b;
  cin>>a>>b;
  long double h;
  long double m;
  cin>>h>>m;
  m+=h*60;
  pair<long double,long double> aa,bb;
  long double hdig=(30*m/60)*pi/180;
  long double mdig=(6*m*pi)/180;
  aa.first=sin(hdig)*a;
  aa.second=cos(hdig)*a;
  bb.first=sin(mdig)*b;
  bb.second=cos(mdig)*b;
  long double ans=sqrt((aa.first-bb.first)*(aa.first-bb.first)+(aa.second-bb.second)*(aa.second-bb.second));
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 4172
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        for (int i = 1; i < 50000; i++) {
            double x = i * 1.08;
            if (Math.floor(x) == n) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(":(");
    }
}


Measured memory_bytes: 79540
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll a[1003];
    ll s[2]{0};
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] > 0) s[i % 2] += a[i];
    }
    int j;
    if(s[0] > s[1]) j = 0;
    else j = 1;
    int l = n, r = -1;
    for(int i = 0; i < n; i++){
        if(i % 2 == j % 2 && a[i] > 0){
            l = min(l, i);
            r = max(r, i);
        }
    }
    if(l > r){
        int m = 0;
        for(int i = 1; i < n; i++){
            if(a[i] > a[m]) m = i;
        }
        cout << a[m] << endl;
        cout << n - 1 << endl;
        for(int i = n - 1; i > m; i--) cout << i + 1 << endl;
        for(int i = 0; i < m; i++) cout << 1 << endl;
        return 0;
    }
    cout << max(s[0], s[1]) << endl;
    cout << (r - l) / 2 + (n - 1) - r + l << endl;
    for(int i = n - 1; i > r; i--) cout << i + 1 << endl;
    int q = r;
    while(q != l){
        int p;
        for(p = q - 2; p >= 0; p -= 2){
            if(a[p] > 0) break;
        }
        for(int i = (q + p) / 2; i > p; i--) cout << i + 1 << endl;
        q = p;
    }
    for(int i = 0; i < l; i++) cout << 1 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    while b:
        a, b = b, a % b
    return a


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


def make_mindiv_table(n):
    mindiv = [i for i in range(n + 1)]
    for i in range(2, int(n ** 0.5) + 1):
        if mindiv[i] != i:
            continue
        for j in range(2 * i, n + 1, i):
            mindiv[j] = min(mindiv[j], i)
    return mindiv


def get_prime_factors(num):
    res = []
    while mindiv[num] != 1:
        res.append(mindiv[num])
        num //= mindiv[num]
    return res


n = int(input())
a = list(map(int, input().split()))


mindiv = make_mindiv_table(10 ** 6)

set_primes = set()
flag = True
for val in a:
    set_ = set(get_prime_factors(val))
    for v in set_:
        if v in set_primes:
            flag = False
        set_primes.add(v)
    if not flag:
        break
else:
    print("pairwise coprime")
    exit()

gcd_ = multi_gcd(a)
if gcd_ == 1:
    print("setwise coprime")
    exit()

print("not coprime")

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

#ifdef LOCAL_BOOKNU
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// ........................macro.......................... //
#define FOR(i, f, n) for(int (i) = (f); (i) < (int)(n); ++(i))
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (int)(n); --(i))
#define pb push_back
#define emb emplace_back
#define fi first
#define se second
#define ENDL '\n'
#define sz(A) (int)(A).size()
#define ALL(A) A.begin(), A.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define next next9876
#define prev prev1234
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef long long i64;
typedef unsigned long long ui64;
// inline i64 GCD(i64 a, i64 b) { if(b == 0) return a; return GCD(b, a % b); }
inline int getidx(const vi& ar, int x) { return lower_bound(ALL(ar), x) - ar.begin(); } // 좌표 압축에 사용: 정렬된 ar에서 x의 idx를 찾음
inline i64 GCD(i64 a, i64 b) { i64 n; if(a < b) swap(a, b); while(b != 0) { n = a % b; a = b; b = n; } return a; }
inline i64 LCM(i64 a, i64 b) { if(a == 0 || b == 0) return GCD(a, b); return a / GCD(a, b) * b; }
inline i64 CEIL(i64 n, i64 d) { return n / d + (i64)(n % d != 0); } // 음수일 때 이상하게 작동할 수 있음.
inline i64 ROUND(i64 n, i64 d) { return n / d + (i64)((n % d) * 2 >= d); }
const i64 MOD = 1e9+7;
inline i64 POW(i64 a, i64 n) {
	assert(0 <= n);
	i64 ret;
	for(ret = 1; n; a = a*a%MOD, n /= 2) { if(n%2) ret = ret*a%MOD; }
	return ret;
}
template <class T> ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	int cnt = 0;
	for(auto vv : v) { os << vv; if(++cnt < v.size()) os << ","; }
	return os << "]";
}
template <class T> ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	int cnt = 0;
	for(auto vv : v) { os << vv; if(++cnt < v.size()) os << ","; }
	return os << "]";
}
template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> p) { return os << "(" << p.fi << "," << p.se << ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H, debug_out(T...); }
// ....................................................... //

const int MAXN = 1e5+10;
i64 n, ans, cnt[26];
string s;
void input() {
	cin >> n >> s;
}

int solve() {
	FOR(i, 0, n) {
		i64 cur = 1;
		FOR(j, 0, 26) {
			if(j == s[i]-'a') continue;
			cur *= (cnt[j]+1);
			cur %= MOD;
		}
		++cnt[s[i]-'a'];
		ans += cur;
		ans %= MOD;
	}
	cout << ans << ENDL;
	return 0;
}

// ................. main .................. //
void execute() {
	input(), solve();
}

int main(void) {
#ifdef LOCAL_BOOKNU
	freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	cin.tie(0), ios_base::sync_with_stdio(false);
	execute();
	return 0;
}
// ......................................... //

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int[] input = new int[2];
		for (int i = 0; i < 2; i++) {
			input[i] = sc.nextInt();
		}
		// 参加回数:N
		int n = input[0];
		// 表示レーティング:R
		int r = input[1];
		// 内部レーティング:output
		int output;
		
		// 参加回数が10回未満の場合
		if (n < 10) {
			output = r + 100 * (10 -n);
			
		// 参加回数が10回以上の場合
		} else {
			output = r;
		}
		
		System.out.println(output);

	}

}

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

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

	int n, l;
	cin >> n >> l;

	vector<string> arr(n);
	for (int i = 0; i < n; ++i) cin >> arr[i];

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

	for (string& u: arr) cout << u;
}

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

int main(){
	
	int n,m;
	cin>>n>>m;
	
	int arr[m];
	int sum=0;
	for(int i = 0 ; i < m ; i++){
		
		cin>>arr[i];
		sum += arr[i];
	}
		
		if(sum > n){
			cout<<"-1"<<endl;
			
		}else{
			cout<<(n-sum)<<endl;
		}
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

const int max_n = 100005;

int par[max_n];
int rnk[max_n];

void init(int n){
	rep(i,n){
		par[i] = i;
		rnk[i] = 0;
	}
}

// find root of tree with x
int find(int x){
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rnk[x] < rnk[y]) par[x] = y;
	else{
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

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

	int N, M;
	cin >> N >> M;

	init(N);

	rep(i, M){
		int X, Y, Z;
		cin >> X >> Y >> Z;
		X--;
		Y--;

		unite(X, Y);
	}

	set<int> st;
	for(int i = 0; i < N; i++){
		st.insert(find(i));
	}

	cout << st.size() << endl;
}


Measured memory_bytes: 5760
require 'set'; require 'prime'; require 'pp'
require 'bigdecimal'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a, b = n.times.map{gets.split.map(&:to_i)}.transpose
a.sort!
b.sort!
if n.odd?
  # p [a[n/2], b[n/2]]
  puts b[n/2] - a[n/2] + 1
else

  amid = a[n/2-1] + a[n/2]
  bmid = b[n/2-1] + b[n/2]
  # p [amid, bmid]
  ret = bmid - amid + 1
  puts ret.to_i
end


Measured memory_bytes: 33448
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef vector<int> V;
typedef vector<V> VV;

int n,m,PRE[11111],X[1111];
string s;

VV init(){
    VV v(n,V(n));
    r(i,n)r(j,n)v[i][j]=i*n+j+1;
    return v;
}
inline void MUL(VV &a,VV &b){r(i,n)r(j,n)a[i][j]=b[PRE[a[i][j]]/n][PRE[a[i][j]]%n];}
inline void U(VV &a,int x){r(i,n-1)swap(a[i][x-1],a[i+1][x-1]);}
inline void D(VV &a,int x){r(i,n-1)swap(a[n-i-1][x-1],a[n-i-2][x-1]);}
inline void R(VV &a,int x){r(i,n-1)swap(a[x-1][n-i-1],a[x-1][n-i-2]);}
inline void L(VV &a,int x){r(i,n-1)swap(a[x-1][i],a[x-1][i+1]);}

inline void POW(VV &a,int x){ x--;
    VV v[30];
    v[0]=a;
    r(i,29){
        v[i+1]=v[i];
        MUL(v[i+1],v[i]);
    }
    r(i,30)if((1<<i)&x)MUL(a,v[i]);
}

inline VV dfs(int l,int r){
    VV res=init();
    for(int i=l;i<=r;i++){
        VV ret=init();
        if(s[i]=='('){
            int t=i,cc=1;
            i=X[i];
            ret=dfs(t+1,i-1);
            int p=0; i++;
            while(isdigit(s[i]))p=p*10+(s[i]-'0'),i++;
            POW(ret,p);
        }
        else if(isalpha(s[i])){
            int t=i,p=0; i++;
            while(isdigit(s[i]))p=p*10+(s[i]-'0'),i++;
            if(s[t]=='U')U(ret,p);
            if(s[t]=='D')D(ret,p);
            if(s[t]=='R')R(ret,p);
            if(s[t]=='L')L(ret,p);
        }
        MUL(ret,res);
        res=ret;
        i--;
    }
    return res;
}


int main(){
    r(i,11111)PRE[i]=i-1;
    cin>>n>>m>>s;s+='@';
    stack<int>st;
    r(i,m){
        if(s[i]=='(')st.push(i);
        if(s[i]==')')X[st.top()]=i,st.pop();
    }
    VV ans=dfs(0,m-1);
    r(i,n){
        r(j,n){
            if(j)cout<<' ';
            cout<<ans[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 32772
#include<bits/stdc++.h>
#define maxn 300005
using namespace std;

int n,A,B;

int main()
{
    while(~scanf("%d%d%d",&n,&A,&B))
    {
        if((long long)A*B<n||A+B>n+1) printf("-1\n");
        else
        {
            cout<<n-A+1;
            for(int i=n-A+2;i<=n;i++) cout<<" "<<i;
            if(B!=1)
            {
                int t=(n-A)/(B-1);
                int r=(n-A)%(B-1);
                int cur=n-A;
                for(int i=1;i<B;i++)
                {
                    if(r)
                    {
                        for(int i=t;i>=0;i--) cout<<" "<<cur-i;
                        cur-=t+1;
                        r--;
                    }
                    else
                    {
                        for(int i=t-1;i>=0;i--) cout<<" "<<cur-i;
                        cur-=t;
                    }
                }
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 2176
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if not(i == 0 or s[i-1][j] == '#') and not(j == 0 or s[i][j-1] == '#') and not(i == h-1 or s[i+1][j] == '#') and not(j == w-1 or s[i][j+1] == '#'):
                flag = False
print('Yes' if flag else 'No')


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

typedef long long ll;

int main() {        
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = (int)s.size();
	set<string> p;
	for (int i = 0; i  < n; ++i) {
		string o = "";
		for (int j = i; j < min(n, i + 5); ++j) {
			o += s[j];
			p.insert(o);
		}
	}
	auto it = p.begin();
	for (int i = 0; i < k - 1; ++i) {
		++it;
	}
	cout << *it;
}








Measured memory_bytes: 4744
N = int(input())
S = list(str(input()))
countlist=[]
for i in range(0,N):
    s1 = set(S[:i])
    s2 = set(S[i:])

    matched_list=list(s1 & s2)
    countlist.append(len(matched_list))

ans = max(countlist)
print(ans)

Measured memory_bytes: 3060
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created on 2017/10/20 7:35.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            int[] x = new int[N];
            int[] y = new int[N];

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

            int[] listX = Arrays.copyOf(x, N);
            int[] listY = Arrays.copyOf(y, N);
            Arrays.sort(listX);
            Arrays.sort(listY);

            long ans = Long.MAX_VALUE;

            for (int yi = 0; yi < N; yi++) {
                int yFrom = listY[yi];
                for (int yj = yi; yj < N; yj++) {
                    int yTo = listY[yj];
                    int xi = 0;
                    int xj = 0;

                    while (xj < N) {
                        int xFrom = listX[xi];
                        int xTo = listX[xj];
                        int cnt = 0;
                        for (int i = 0; i < N; i++) {
                            if (xFrom <= x[i] && x[i] <= xTo && yFrom <= y[i] && y[i] <= yTo) {
                                cnt++;
                            }
                        }
                        if (cnt >= K) {
                            ans = Math.min(ans, (long) (xTo - xFrom) * (yTo - yFrom));
                            xi++;
                            xj = Math.max(xj, xi);
                        } else {
                            xj++;
                        }
                    }
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 24276
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define SORT(v) sort((v).begin(),(v).end())
//#define scanf scanf_s

int main()
{
	int a, b, c, n, x;
	while (cin >> n >> a >> b >> c >> x, n)
	{
		int y[105];
		int ran[10005];
		REP(i, n) cin >> y[i];
		int frame = 0;
		int i = 0;
		for (frame = 0; frame <= 10000; frame++)
		{
			if (y[i] == x)
			{
				i++;
			}
			if (i >= n)
			{
				cout << frame << endl;
				goto end;
			}
			x = (a*x + b) % c;
		}
		cout << -1 << endl;
	end:;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        String strTmp;
        List<Integer> ignoreRow = new ArrayList<Integer>();
        List<Integer> ignoreCol = new ArrayList<Integer>();

        String[][] input = new String[a][b];
        for (int i=0;i<a;i++) {
        	strTmp = scanner.next();
        	input[i] = strTmp.split("");
        	if(!strTmp.contains("#")) {
        		ignoreRow.add(i);
        	}
        }
        for (int j=0;j<b;j++) {
        	strTmp = "";
        	for (int k=0;k<a;k++){
        		strTmp += input[k][j].toString();
        	}
        	if(!strTmp.contains("#")) {
        		ignoreCol.add(j);
        	}
        }
        for (int l=0;l<a;l++) {
        	strTmp = "";
        	if (ignoreRow.contains(l)) {
        		continue;
        	}
        	for (int m=0;m<b;m++) {
        		if(!ignoreCol.contains(m)) {
        			strTmp += input[l][m].toString();
        		}
        	}
        	System.out.println(strTmp);
        }

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 32724
use v5.18;
use warnings;

chomp(my $stay_day = <>);
chomp(my $switch_day = <>);
chomp(my $x = <>);
chomp(my $y = <>);

if ($switch_day > $stay_day) {
  say $stay_day * $x;
} else {
  say $switch_day * $x + ($stay_day - $switch_day) * $y;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int n, m;
    int a[128][128] = {0}, b[128] = {0};
    int i, j;

    scanf("%d %d", &n, &m);
    for (i = 0; i < n; i++){
        for (j = 0; j < m; j++){
            scanf("%d", a[i] + j);
        }
    }
    for (i = 0; i < m; i++){
        scanf("%d", b + i);
    }
    for (i = 0; i < n; i++){
        int c = 0;
        for (j = 0; j < m; j++){
            c += a[i][j] * b[j];
        }
        printf("%d\n", c);
    }

    return 0;
}

Measured memory_bytes: 672
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V == W:
    sec = T + 1
else:
    sec = abs(A - B) / (V - W)

if W >= V:
    print("NO")
else:
    if sec <= T:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9180
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
  
public class Main
{ 
    //By shwetank_verma
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static int mod=1000000007;
    static boolean primes[]=new boolean[1000007];
    
    static boolean seive(int n){
        Arrays.fill(primes,true);
        primes[0]=primes[1]=false;
        for(int i=2;i*i<=n;i++){
            if(primes[i]==true){
                for(int p=i*i;p<=n;p+=i){
                    primes[p]=false;
                }
            }
        }
        if(n<1000007){
            return primes[n];
        }
        return false;
        
    }
    static int gcd(int a,int b){
        if(b==0)
        return a;
        return gcd(b,a%b);
    }
    static long GCD(long a,long b){
        if(b==0)
        return a;
        return GCD(b,a%b);
    }
    
  
    public static void main(String[] args) 
    { 
        FastReader sc=new FastReader(); 
        try{
           
                String s=sc.next();
                char ch=s.charAt(0);
                if(ch>=65&&ch<=90)
                	System.out.println('A');
                else if(ch>=97&&ch<=122)
                	System.out.println('a');
                	
           
            
        }catch(Exception e){
            return;
        }
    } 
}


Measured memory_bytes: 33836
#include<cstdio>
#include<iostream>
int a[5];
int swa;
int change(int n){
    swa=a[n],a[n]=a[n-1],a[n-1]=swa;
}
int main(){
    for(int i=0;i<5;i++)
        scanf("%d",&a[i]);
    for(int i=4;i>=0;i--){
        for(int j=4;j>0;j--){
            if(a[j-1]<a[j])
                change(j);
        }
    }
    for(int i=0;i<4;i++)
        printf("%d ",a[i]);
        printf("%d\n",a[4]);
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#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 sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  string S;
  cin >> S;
  rep(i, sz(S)){
    cout << 'x';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n <= k) {
        cout << x*n;
    }
    else {
        cout << x*k + y*(n-k);
    }
    
    cout << endl;
    return 0;
}

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

int main(){
	int A, B;
	cin >> A >> B;

	if(A==B) cout << (A + B) << endl;
	else if(A>B) cout << 2 * A - 1 << endl;
	else cout << 2 * B - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    input()
    array = (int(x) for x in input().split())
    mod = 10 ** 9 + 7
    ans = 0
    multiplier = 0
    for x in array:
        ans = (ans + x * multiplier) % mod
        multiplier = (multiplier + x) % mod
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 25032
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ara[100009];
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;i++)cin>>ara[i];
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        if(i%2==0)sum+=ara[i];
        else sum-=ara[i];
    }
    ll a=sum/2;
    cout<<sum;
    ll prev=a;
    for(int i=0;i<n-1;i++)
    {
        ll val=(ara[i]-prev)*2;
        prev=val/2;
        cout<<" "<<val;
    }
    cout<<endl;
}


Measured memory_bytes: 1664
// 2008ツ姪債擬ツ地ツ凝ヲツ予ツ選 B : Headstrong Student

#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int x, y;
	static int pos[1000000];
	while(cin >> x >> y, x){
		memset(pos, -1, sizeof(pos));
		pos[x] = 0;
		x *= 10;
		for(int i=1; ;i++){
			x %= y;
			if(x==0){
				cout << i << " " << 0 << endl;
				break;
			}
			if(pos[x]!=-1){
				cout << pos[x] << " " << i-pos[x] << endl;
				break;
			}
			pos[x] = i;
			x *= 10;
		}
	}
}

Measured memory_bytes: 4772
#include<iostream>
using namespace std;
int main(){
  char s[110];
  cin>>s;
  int k;
  cin>>k;
  for(int i=0;i<k;i++){
    if(s[i]!='1'){
      cout<<s[i]<<endl;
      return 0;
    }
  }
  cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dl = long double;
int main()
{
    dl n;
    cin>>n;
    vector<dl>x(n),y(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    dl z=1;
    dl p=n-2;

    while(p>0){
        z*=p;
        p--;
    }
    dl space = n-2+1;

    //cout<<z<<endl;

    dl ans=0;
    for(int i=0;i<n;i++){
            dl sum=0;
        for(int j=i+1;j<n;j++){
            if(i!=j){
              sum=sqrt(((x[i]-x[j])*(x[i]-x[j]))+((y[i]-y[j])*(y[i]-y[j])))  ;
                sum*=z;
                sum*=space*2;
                ans+=sum;
                //cout<<ans<<endl;
            }
        }
    }



   dl m = z*(n-1)*n;
  // cout<<m<<endl;
   cout<<fixed <<setprecision(10)<<(ans/m)<<endl;



    return 0;
}


Measured memory_bytes: 3844
#include<cstdio>
#include<algorithm>

using namespace std;

#define FOR(i, a, b) for(int i = a; i <= b; i++)

const int MAX = 1e2 + 10;
int s[MAX];

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		FOR(i, 0, n - 1)
			scanf("%d", &s[i]);
		int cnt = 0;
		FOR(i, 0, n - 1)
		{
			int minj = i;
			for(int j = i + 1; j < n; j++)
			{
				if(s[j] < s[minj])
					minj = j;
			}
			if(minj != i)
			{
				swap(s[minj], s[i]);
				cnt++;
			}
		}
		FOR(i, 0, n - 1)
		{
			printf("%d", s[i]);
			if(i != n - 1)
				printf(" ");
			else
				printf("\n");
		}
		printf("%d\n", cnt);
	}
	return 0;
}



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

using namespace std;

int main(){

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

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

    int m = max(a,b);
    m = max(m,c);
    int s = a + b + c -m;

    cout << s + (m << k) << endl;

    return 0;

}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc137/tasks/abc137_b

#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stderr, stdin, BufRead, Write};

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[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) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn main() {
    let (k,x) = read!(i64, i64);

    let mut range = x-k+1..x+k; 

    if x - k < -100000 {
        range = x..x+k;
    }
    if x + k > 100000{
        range = x-k+1..x+1;    
    }

    let slots : Vec<String> = range.map(|x| x.to_string()).collect();

    println!("{}", slots.join(" "));
}


Measured memory_bytes: 4352
import bisect
n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a=L[i]
        b=L[j]
        k = bisect.bisect_left(L,a+b)
        ans += k-1-j
print(ans)

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

int main(){
    int s=0, t=0;
    int n=4;
    while(n--){ int a; cin>>a; s+=a; };
    n=4;
    while(n--){ int a; cin>>a; t+=a; };
    cout<<(s>t ? s : t)<<endl;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void){
	int n, x = 1, y, i;

	scanf("%d", &n);

	for(i = 0;i < 64;i++){
		x *= 2;
		if(x > n) break;
		y = x;
	}

	printf("%d\n", y);
	return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextInt()
	s := nextLine()
	if n >= 3200 {
		fmt.Println(s)
		return
	}
	fmt.Println("red")
}


Measured memory_bytes: 640
N = int(input())
S = [list(map(lambda x: ord(x) - ord("a") + 1, list(input()))) for _ in range(N)]
#print("S:", S)

yoko, tate = [], []
for i in range(N):
  tmp = 0
  for j in range(N):
    tmp += S[i][j] * 2 ** ((N - j - 1) * 5)
  yoko.append(tmp)
for j in range(N):
  tmp = 0
  for i in range(N):
    tmp += S[i][j] * 2 ** ((N - i - 1) * 5)
  tate.append(tmp)
#print("yoko:", yoko)
#print("tate:", tate)

answer = 0
yi, ti = 0, 0
for t in range(N):
  flag = 0
  for i in range(N):
    if yoko[(i + yi) % N] != tate[(i + ti) % N]:
      flag = 1
      break
  if flag == 0:
    answer += N
    
  # 左にずらす
  for i in range(N):
    tate[i] = (tate[i] << 5 | tate[i] >> (N - 1) * 5) & (2 ** (5 * N) - 1)
  yi += 1
  #print("tate:", tate)

print(answer)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define ll long long
#define a109 10000007
#define pb push_back
using namespace std;

string s1,s2;
pair<char,pair<int,int> > dp[5000][5000];
int dpl[5000][5000];
char c;
void yaz(int i,int j){
	if( i>=s1.size() || j>=s2.size() ){
		return ;
	}
	if(dp[i][j].first!='0')
		printf("%c",dp[i][j].first );
	yaz(dp[i][j].second.first,dp[i][j].second.second);
}
int main(){

	// freopen("a.gir","r",stdin);
 //    freopen("a.cik","w",stdout);
	cin>>s1>>s2;

  	for(int i=s1.size()-1;i>=0;i--){
  		for(int j=s2.size()-1;j>=0;j--){
  			if(  s1[i] == s2[j]  ){
				dp[i][j].first=s1[i];
				dp[i][j].second.first=i+1;
				dp[i][j].second.second=j+1;
				dpl[i][j]=1+dpl[i + 1][ j + 1 ];
			}
			else{
				if(dpl[ i + 1 ][ j ]>dpl[ i ][ j + 1 ]){
					dp[i][j].first='0';
					dp[i][j].second.first=i+1;
					dp[i][j].second.second=j;
					dpl[i][j]=dpl[ i + 1 ][ j ];
				}
				else{
					dp[i][j].first='0';
					dp[i][j].second.first=i;
					dp[i][j].second.second=j+1;
					dpl[i][j]=dpl[ i ][ j + 1 ];
				}
			}
  		}
  	}
  	yaz(0,0);
  //	printf("%s\n",(dp[ 0 ][ 0 ].c_str()) );
}


Measured memory_bytes: 237440
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,D,X;
  cin>>N>>D>>X;
 
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<N;i++){
    int Y=1;

    while(Y<=D){
      X+=1;
      Y+=A.at(i);
    }
  }
  cout<<X;
}
      

  


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N;
  scanf("%d", &N);
   float A[N];
	float B[N];
  float ans = 0;

 
  float sum = 0;
  int i= 0;
  for(i=0;i<N;i++){
    scanf("%f", &A[i]);
    //printf("A:%f\n",A[i]);
    B[i] = 1/A[i];
    //printf("B:%f\n",B[i]);
    sum = sum + B[i];
    //printf("sum:%f",sum);
  }
  
  ans = 1 / sum;

  printf("%f",ans);
    return 0;
}


Measured memory_bytes: 128
#include<vector>
#include<iostream>
#include<limits>
#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> ar;
    int max=0 , min = 9999999;
    for(int i =0; i< n; i ++)
    {
        int temp;
        cin>>temp;
        // if( temp > max ){

        //     max = temp;
        //     continue;
        // }
        // if ( temp < min ){

        //     min = temp;
        //     continue;
        // }
        ar.push_back(temp);

    }
    cout<<*max_element(ar.begin(), ar.end()) - *min_element( ar.begin() , ar.end() ) ;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,a,b;
	int ans1,ans2;

	scanf("%d%d%d",&n,&a,&b);

	ans1 = a*n;
	ans2 = b;
	if(ans1<ans2){
		printf("%d",ans1);
	}else{
		printf("%d",ans2);
	}
}

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

int main() {
  long long n;
  cin >> n;
  vector<long long> h(n), lower(1, 0);
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    cin >> h.at(i);
    if (i > 0) {
      if (h.at(i) <= h.at(i - 1)) cnt++;
      else {
        lower.push_back(cnt);
        cnt = 0;
      }
    }
    if (i == n - 1) lower.push_back(cnt);
  }
  long long cmax = 0;
  for (long long i = 0; i < lower.size(); i++)
    cmax = max(cmax, lower.at(i));
  cout << cmax << endl;
}

Measured memory_bytes: 2168
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#include <functional>

#define SIZE 300005
#define INF 1000000000
#define FD(d) fixed << setprecision(d)
#define MOD 1000000007
#define ll long long

using namespace std;

typedef pair<ll, ll> P;

int main()
{
	int n, l;
	

	cin >> n >> l;
	vector<string> s(n);

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

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

	for (int i = 0; i < n; i++) {
		cout << s[i];
	}
	cout << endl;
	
	return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
    return a>b;
}
int a[100010];
int main()
{
    register int n;
    cin>>n;
    for(register int i=1;i<=n;++i)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1,cmp);
    for(register int i=1;i<=n;++i)
        if(i+1>a[i+1])
        {
            register int ans=0;
            for(register int j=i+1;a[j]==i;++j)
                ans^=1;
            ans|=(a[i]-i)&1;
            if(ans)
                puts("First");
            else 
                puts("Second");
            return 0;
        }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    
    cin >> a >> b >> c >> d;
    
    if(abs(a - c) <= d){
        cout << "Yes" << endl;
    }else if(abs(a - b) <= d && abs(b - c) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin), idx##_sz = (int)(end); idx < idx##_sz; ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007, INF = 1111111111;
const double EPS = 1e-9;

char solve(string A, string B, string C, char turn) {

	switch (turn) {
	case('a'):
		if (A == "") return 'A';
		return solve(A.substr(1), B, C, A[0]);
		break;
	case('b'):
		if (B == "") return 'B';
		return solve(A, B.substr(1), C, B[0]);
		break;
	case('c'):
		if (C == "") return 'C';
		return solve(A, B, C.substr(1), C[0]);
		break;
	}
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string A, B, C;
	cin >> A >> B >> C;

	cout << solve(A, B, C, A[0]);
	return 0;
}

Measured memory_bytes: 384