akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t,ans="";
    cin>>s;
    cin>>t;
    int dp[s.length()+1][t.length()+1];
    int i,j,len=0;
    for(i=0;i<=s.length();i++)
    {
        for(j=0;j<=t.length();j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;continue;
            }
            if(s[i-1]==t[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    i=s.length();j=t.length();
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans=s[i-1]+ans;
            i--;j--;continue;
        }
        if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,m,k,x,y,a[100001];
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
   cin>>n;
   if(n%1000==0)
   cout<<0<<endl;
   else
   cout<<(((n/1000)+1)*1000)-n<<endl;
   return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;


public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n;
		while((n = sc.nextInt()) != 0) {
			run(n);
		}
	}

	static void run(int n) {
		int A=0, B=0;
		for(int i=0; i<n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			if(a>b) A += a+b;
			else if(b>a) B += a+b;
			else {
				A += a;
				B += b;
			}
		}

		System.out.println(A + " " + B);
	}

}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

const int N = 1e5 + 5;

int h[N], dp[N];
int n;

int sol(int idx) {
    int & ret = dp[idx];

    if(ret != -1) return ret;

    if(idx == n - 1) return 0;

    ret = sol(idx + 1) + abs(h[idx] - h[idx + 1]);

    if(idx + 2 < n) ret = min(ret, sol(idx + 2) + abs(h[idx] - h[idx + 2]));

    return ret;
}

int main(){
    fIO

    cin >> n;

    h[n] = 1e9;

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

    memset(dp, -1, sizeof(dp));

    cout << sol(0);

}








Measured memory_bytes: 4224
<?php
fscanf(STDIN, "%d %d", $n, $max);
$x = $b[0] = 0;
for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%d %d", $w, $v);
	foreach ($b as $p => $q) {
		$w1 = $p + $w;
		$v1 = $q + $v;
		if ($w1 <= $max && (!isset($b[$w1]) || $b[$w1] < $v1)) {
			$b[$w1] = $v1;
			if ($x < $v1) $x = $v1;
		}
	}
}
echo $x;

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    int d[N];
    rep(i, N) { cin >> d[i]; }

    int sum = 0;
    rep(i, N) {
        for (int j = i + 1; j < N; ++j) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
/**
 *    AUTHOR:    __SIGSEGV__                  
 *   CREATED:   13.09.2020 20:52:35  
**/

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7;

long long expo(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long total = expo(10LL, n);
  long long ans = ((mod + total - 2 * expo(9LL, n) % mod) % mod + expo(8LL, n)) % mod;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int A,B,C;
    cin >> A >> B >> C;
    
    for(int i=0;i<=100;i++){
        if((B*i+C)%A==0){
            cout << "YES" << endl;
            return 0;
        }
    }
    
    cout << "NO" << endl;
    
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
nice_h_list = h_list[:]
ab_list = [list(map(int, input().split())) for _ in range(m)]

for a, b in ab_list:
    # 0始まりにする
    a -= 1
    b -= 1
    if h_list[a] == h_list[b]:
        nice_h_list[a] = nice_h_list[b] = 0
    elif h_list[a] < h_list[b]:
        nice_h_list[a] = 0
    else:
        nice_h_list[b] = 0

print(len([h for h in nice_h_list if h > 0]))

Measured memory_bytes: 32464
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int flg = 0;
    if(N == 1 && M == 0){
        System.out.println("0");
        flg = 1;
    }
    int[] n = new int[N];
    int[] flg2 = new int[N];
    for(int i = 0; i < M; i++){
      int s = sc.nextInt();
      int c = sc.nextInt();
      if(N == 1 && M == 1){
        System.out.println(c);
        flg = 1;
        break;
      } else if(s == 1 && c == 0){
        System.out.println("-1");
        flg = 1;
        break;
      } else if(n[s - 1] == 0 || n[s - 1] == c || flg2[s - 1] == 0){
        n[s - 1] = c;
        flg2[s - 1] = 1;
      } else {
        System.out.println("-1");
        flg = 1;
        break;
      }
    }
    if(N != 1 && n[0] == 0){
      n[0] = 1;
    }
    if(flg == 0){
      for(int i = 0; i < N; i++){
        System.out.print(n[i]);
      }
    }
  }
}


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

template<typename T> constexpr function<T(T, T)> ex_assign(T initE) {
  return [&initE](const T& x, const T& y) -> const T { return (y == initE) ? x : y; };
}
template<typename T> constexpr function<T(T, int)> ex_multiplies(T initE) {
  return [&initE](const T& x, int y) -> const T { return (x == initE) ? x : x * y; };
}
template<typename T, typename E> struct LazySegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  using P = function<E(E, int)>;

  int n;
  T initT;
  E initE;
  F f;
  G g;
  H h;
  P p;
  vector<T> data;
  vector<E> lazy;

  LazySegmentTree() {}
  LazySegmentTree(int n_, F f, G g, H h, T initT = INT_MAX, E initE = INT_MAX,
      vector<T> v = vector<T>(), P p = [](E a, size_t b) { ++b; return a; })
      : f(f), g(g), h(h), initT(initT), initE(initE), p(p) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(n * 2 - 1, initT);
    lazy.assign(n * 2 - 1, initE);
    if (n_ == v.size()) build(v);
  }
  void build(vector<T> v) {
    for (int i = 0; i < v.size(); ++i) data[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  inline void eval(int len, int k) {
    if (lazy[k] == initE) return;
    if (k * 2 + 1 < n * 2 - 1) {
      lazy[k * 2 + 1] = h(lazy[k * 2 + 1], lazy[k]);
      lazy[k * 2 + 2] = h(lazy[k * 2 + 2], lazy[k]);
    }
    data[k] = g(data[k], p(lazy[k], len));
    lazy[k] = initE;
  }
  T update(int a, int b, E x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return data[k];
    if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      eval(r - l, k);
      return data[k];
    }
    T vl = update(a, b, x, k * 2 + 1, l, (l + r) / 2);
    T vr = update(a, b, x, k * 2 + 2, (l + r) / 2, r);
    return data[k] = f(vl, vr);
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return initT;
    if (a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};

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

  const ll initT = 0;
  const ll initE = 1e9;
  const LazySegmentTree<ll, ll>::F f = plus<ll>();
  const LazySegmentTree<ll, ll>::G g = ex_assign<ll>(initE);
  const LazySegmentTree<ll, ll>::H h = ex_assign<ll>(initE);
  const LazySegmentTree<ll, ll>::P p = ex_multiplies<ll>(initE);

  int n, q; cin >> n >> q;
  LazySegmentTree<ll, ll> seg(n, f, g, h, initT, initE, vector<ll>(), p);

  while (q--) {
    int com; cin >> com;
    if (com) {
      int s, t; cin >> s >> t;
      cout << seg.query(s, t + 1) << endl;
    } else {
      int s, t, x; cin >> s >> t >> x;
      seg.update(s, t + 1, x);
    }
  }
  return 0;
}



Measured memory_bytes: 7052
#include<iostream>
#include<vector>

using namespace std;

vector<long long> w, v;
vector<vector<long long>> dp;

int main(void) {
	int N;
	long long W,sumV = 0;
	cin >> N >> W;

	w = v = vector<long long>(N);

	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
		sumV += v[i];
	}
	dp = vector<vector<long long>>(N+1, vector<long long>(sumV + 1,1000000010));
	dp[0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (long long j = 0; j <= sumV;j++) {
			if (j - v[i] >= 0) {
				dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
			}
			else {
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	long long ans;
	for (long long i = 0; i <= sumV; i++) {
		if (dp[N][i] <= W) ans = i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
int a, b, c, n;
int main() {
	scanf("%d", &n);
	a = n % 10;
	n /= 10;
	b = n % 10;
	c = n / 10;
	if (a == 7 || b == 7 || c == 7)printf("Yes\n");
	else printf("No\n");
}

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

int digsum(int num){
    int sum=0;
    for(;num>0;num/=10){
        sum += num%10;
    }
    return sum;
}

int main(){
    int n;
    cin >> n;
    int _min=10000;

    for(int i=1; i<n; i++){
        int j = n - i;
        _min = min(_min, digsum(i)+digsum(j));
    }

    cout << _min << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<ll> v;

int main(void){
	int n,i;
	ll a,b,ans=0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a >> b;
		v.push_back(a+b);
		ans += a;
	}
	sort(v.begin(),v.end(),greater<ll>());
	for(i=1; i<n; i+=2){
		ans -= v[i];
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, M, p;
    cin >> N >> M >> p;
    vector<vector<P>> graph(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back({b, -c + p});
    }

    vector<ll> cost(N, INF);
    vector<bool> negative(N, false);
    cost[0] = 0;
    rep(i, N) {
        rep(j, N) {
            for (P &v: graph[j]) {
                if (cost[j] != INF && cost[v.first] > cost[j] + v.second) {
                    cost[v.first] = cost[j] + v.second;
                }
            }
        }
    }
    rep(i, N) {
        rep(j, N) {
            for (P &v: graph[j]) {
                if (cost[j] != INF && cost[v.first] > cost[j] + v.second) {
                    cost[v.first] = -INF;
                    negative[v.first] = true;
                }
            }
        }
    }
    if (negative[N - 1]) {
        cout << "-1" << '\n';
    } else {
        cout << max(0ll, -cost[N - 1]) << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, c=0;
  cin >> n;
  vecll a(n);
  forll(i, 0, n)
	cin >> a[i];
  forll(i, 0, n){
	if(a[a[i]-1] == i+1)
	  c++;
  }
  cout << c/2 << endl;
}

Measured memory_bytes: 1024
<?php

$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$k = (int)$input[1];

$v_list = [];
$h_list = [];
for ($i=1; $i <=$n ; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$v_list[] = [
		'x'=>(int)$input[0],
		'y'=>(int)$input[1],
	];
	$h_list[] = [
		'x'=>(int)$input[0],
		'y'=>(int)$input[1],
	];
}

usort($h_list, function($a,$b){
	if ($a['x']>$b['x']) {
		return 1;
	}
	return -1;
});
usort($v_list, function($a,$b){
	if ($a['y']>$b['y']) {
		return 1;
	}
	return -1;
});

$min = null;
for ($i=0; $i < $n-1; $i++) { 
	$bottom = $v_list[$i]['y'];
	for ($j=$i+1; $j < $n ; $j++) { 
		$top = $v_list[$j]['y'];
		for ($p=0; $p < $n-1; $p++) {
			$left = $h_list[$p]['x'];
			for ($l=$p+1; $l < $n; $l++) { 
				$right = $h_list[$l]['x'];
				$ten=0;
				for ($m=$p; $m <= $l; $m++) { 
					$cur_y = $h_list[$m]['y'];
					if ($cur_y<=$top && $cur_y>=$bottom) {
						++$ten;
					}
				}
				if ($ten >= $k) {
					$tate = $top-$bottom;
					$yoko = $right - $left;
					if ($min === null) {
						$min = $tate*$yoko;
					}else{
						$min = min($min,  $tate*$yoko);
					}
				}
			}
		}

	}
}
echo $min;

Measured memory_bytes: 4604
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

const int64_t dxs[] = {-1, 1, 0, 0};
const int64_t dys[] = {0, 0, -1, 1};

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

  int64_t sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  // 1********
  for (int64_t i = 0; i < (tx - sx); ++i) {
    cout << "R";
  }
  for (int64_t i = 0; i < ty - sy; ++i) {
    cout << "U";
  }
  // 2********
  for (int64_t i = 0; i < (tx - sx); ++i) {
    cout << "L";
  }
  for (int64_t i = 0; i < ty - sy; ++i) {
    cout << "D";
  }
  // 3********
  cout << "D";
  for (int64_t i = 0; i < (tx - sx) + 1; ++i) {
    cout << "R";
  }
  for (int64_t i = 0; i < ty - sy + 1; ++i) {
    cout << "U";
  }
  cout << "L";
  // 4********
  cout << "U";
  for (int64_t i = 0; i < (tx - sx) + 1; ++i) {
    cout << "L";
  }
  for (int64_t i = 0; i < ty - sy + 1; ++i) {
    cout << "D";
  }
  cout << "R";
  cout << endl;

  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double lb;
const ll MOD=1;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
void IOS(){	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return ;}

ll n,v[105],w[105],dp[105][1000000],k;

ll f(int wh,int l){
	if(wh==n)return 0;
	if(dp[wh][l]!=-1)return dp[wh][l];
	if(l-w[wh]>=0){
		return dp[wh][l]=max(v[wh]+f(wh+1,l-w[wh]),f(wh+1,l));
	}
	return dp[wh][l]=f(wh+1,l);
}

int main(){
	IOS();
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	REP(i,n){
		cin>>w[i]>>v[i];
	}
	cout<<f(0,k);
	return 0;
}

Measured memory_bytes: 820608
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    if (N == 1){
        cout << 1.0 << endl;
        return 0;
    }else if(N % 2 == 0){
        cout << 0.5 << endl;
        return 0;
    }else{
        double ans = 0.0;
        double evens = (N - 1) /2;
        double odds = evens + 1;
        
        ans = odds / N;
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt();
    if(a==b)
        cout<<"Draw\n";
    else if(a==1)
        cout<<"Alice\n";
    else if(b==1)
        cout<<"Bob\n";
    else
    {
        if(a>b)
            cout<<"Alice\n";
        else
            cout<<"Bob\n";
    }
    
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

#define N 500000

int tree[N + 2] = { 0, };

void add(int idx, int val)
{
	for (; idx <= N; idx += (idx&-idx))
	{
		tree[idx] += val;
	}
}

int get(int idx)
{
	int rvalue = 0;

	for (; idx; idx -= (idx&-idx))
	{
		rvalue += tree[idx];
	}

	return rvalue;
}

int psum(int l, int r)
{
	return get(r) - get(l);
}

bool func(const pair<pair<int, int>, int> &a, const pair<pair<int, int>, int> &b)
{
	return a.first.second < b.first.second;
}

int main()
{
	//freopen("input.txt", "r", stdin);

	int n, q;
	int arr[500001];

	scanf("%d %d", &n, &q);

	vector<pair<pair<int, int>, int>> query;

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &arr[i]);
	}

	for (int i = 0; i < q; i++)
	{
		int l, r;

		scanf("%d %d", &l, &r);

		query.push_back({ {l,r},i });
	}

	sort(query.begin(), query.end(), func);

	int ptr = 0;
	int sol[500001];
	int loc[500001];

	memset(loc, -1, sizeof(loc));

	for (int i = 0; i < q; i++)
	{
		const int l = query[i].first.first;
		const int r = query[i].first.second;
		const int idx = query[i].second;

		while (ptr < r)
		{
			ptr++;

			if (loc[arr[ptr]] != -1)
			{
				add(loc[arr[ptr]], -1);
			}

			add(ptr, 1);
			loc[arr[ptr]] = ptr;
		}

		sol[idx] = get(r) - get(l - 1);
	}

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

	return 0;
}

Measured memory_bytes: 17528
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>

using namespace std;
const int maxn=1e5+5;
int o[maxn],l[maxn],r[maxn];
long long w[maxn],s[maxn];

int sfind(int f)
{
    return f==o[f]?f:o[f]=sfind(o[f]);
}

long long sunion(int l,int r)
{
    int x,y;
    long long ans=0;
    x=sfind(l);
    y=sfind(r);
    if(x!=y)
    {
        o[x]=y;
        ans=w[x]*w[y];
        //cout<<x<<' '<<y<<'*'<<ans<<endl;
        w[y]+=w[x];
    }
    return ans;
}

int main()
{
    long long n,m,ans;
    while(cin>>n>>m)
    {
        ans=n*(n-1)/2;
        for(int i=1;i<=n;i++)
            o[i]=i,w[i]=1;
        for(int i=0;i<m;i++)
            cin>>l[i]>>r[i];
        for(int i=m-1;i>=0;i--)
        {
            s[i]=ans;
            ans-=sunion(l[i],r[i]);
        }
        for(int i=0;i<m;i++)
            cout<<s[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    int n, x;
    cin >> n >> x;
    cout << n * n - x << endl;
    return 0;
}

Measured memory_bytes: 256
import queue

o = input()
e = input()

odd = list(o)
even = list(e)

answer = []

o_q = queue.Queue()
e_q = queue.Queue()

for i in range(len(odd)):
    o_q.put(odd[i])

for i in range(len(even)):
    e_q.put(even[i])

while not o_q.empty():
    answer.append(o_q.get())
    if e_q.empty():
        continue
    answer.append(e_q.get())

for i in range(len(answer)):
    print(answer[i],end='')

    

Measured memory_bytes: 9628
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(input())
  S = input()
  A = ['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']
  B = A[N:] + A[:N]
  D = {}
  for a, b in zip(A,B):
    D[a] = b
  ans = ''
  for i in range(len(S)):
    ans += D[S[i]]
  print(ans)
  
  
if __name__ == '__main__':
  main()

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long INTEGER;
typedef double FLOAT;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int main()
{
entry:;

  int n; cin >> n;

  if (!n) return 0;

  int A = 0;
  int B = 0;
  rep (i, n) {
    int a, b; cin >> a >> b;
    if (a > b) {
      A += a + b;
    } else if (a == b) {
      A += a;
      B += b;
    } else {
      B += a + b;
    }
  }
  cout << A << ' ' << B << endl;

  goto entry;

  return 0;
}

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

using namespace std;

int main()
{
        string s;
        cin>>s;
        int i,f[1000]={0},k=0;
        for(i=0;i<4;i++)
        {
                f[s[i]]++;
        }
        for(i=0;i<4;i++)
        {
               if(f[s[i]]!=0)
               {
                       if(f[s[i]]==2)
                       k++;
                       f[s[i]]=0;
               }
        }
        if(k==2)
        cout<<"Yes"<<endl;
        else
                cout<<"No"<<endl;
        return 0;
}


Measured memory_bytes: 256
def patty(n,x):
  if n == 0:
    if x <= 0:
      return 0
    else: 
      return 1
  elif x <= 1 + a[n-1]:
    return patty(n-1, x-1)
  else:
    return p[n-1] + 1 + patty(n-1, x-2-a[n-1])

n,x = map(int, input().split())
a = [1]
p = [1]
for i in range(n):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)
ans = patty(n,x)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
	
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		auto s = 1ULL;
		for (auto i = 0; i < 63; ++i, s <<= 1)
		{
			if (p & s)
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
}

template<class T>void println(T const& v)
{
	std::cout << v << std::endl;
}

void Main()
{
	std::string str;
	std::cin >> str;
	if (str == "RRR")
	{
		println(3);
	}
	else if (str == "SSS")
	{
		println(0);
	}
	else if (str == "SRR" || str == "RRS")
	{
		println(2);
	}
	else
	{
		println(1);
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M,S,T;
vector<int>G[1<<17];
bool two[2][1<<17];
int vis[2][1<<17];
bool isp(int t)
{
	for(int i=3;i*i<=t;i+=2)if(t%i==0)return false;
	return true;
}
main()
{
	cin>>N>>M>>S>>T;
	S--,T--;
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int v:G[S])two[0][v]=true;
	for(int i=0;i<N;i++)
	{
		if(!two[0][i])continue;
		for(int v:G[i])two[1][v]=true;
	}
	if(two[1][T])
	{
		cout<<2<<endl;
		return 0;
	}
	for(int i=0;i<N;i++)vis[0][i]=vis[1][i]=1e9;
	vis[0][S]=0;
	queue<pair<int,int> >P;
	P.push(make_pair(0,S));
	while(!P.empty())
	{
		int t=P.front().first,u=P.front().second;
		P.pop();
		for(int v:G[u])
		{
			if(vis[(t+1)%2][v]>t+1)
			{
				vis[(t+1)%2][v]=t+1;
				P.push(make_pair(t+1,v));
			}
		}
	}
	int t=vis[1][T];
	if(t==1)t+=2;
	if(t%2==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	while(!isp(t))t+=2;
	cout<<t<<endl;
}



Measured memory_bytes: 10192
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,s;cin>>N;
    int ss=0; int tt=0; int ans=10000000;
    vector<int> w;
    for(int i=0; i<N;i++){
      cin>>s; w.push_back(s);
    }
    for(int t=0; t<N;t++){
      for(int i=0; i<N;i++){
        if(i<=t){
          ss+=w[i];
        }else{
          tt+=w[i];
        }
      }
      ans = min(ans, abs(tt-ss));
      ss=0; tt=0;
    }

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


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

int n;
int a[100000], b[100000];
long long int ans;

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

	for(int i=n-1; i>=0; i--){
		int t = (a[i] + ans) % b[i];
		if(t != 0) ans += b[i] - t;
	}

	printf("%lld\n", ans);
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
int n, k, a[100010],dp[100010];
int main(){
	scanf("%d%d",&n,&k);
	memset(dp,63,sizeof(dp));
	for(int i=1 ; i<=n ; i++){
		scanf("%d",a+i);
	}
	dp[1] = 0;
	for(int i=2 ; i<=n ; i++){
		for(int j=max(1,i-k) ; j<i ; j++)
		dp[i] = min(dp[i] , dp[j] + abs(a[i]-a[j]));
	}
	printf("%d\n", dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const ll inf=(1e14);
ll solve(){
    int h,m,w;
    cin>>h>>w>>m;
    set<vector<int>> tgt;
    vector<int> r(h+1),c(w+1);
    while(m--){
        int u,v;
        cin>>u>>v;
        tgt.insert({u,v});
        r[u]++;c[v]++;
    }
    vector<pair<int,int> > rr,cc;
    int rmx=*max_element(r.begin(), r.end()),cmx=*max_element(c.begin(), c.end());
    for(int i=1;i<=h;i++) if(r[i]==rmx) rr.push_back({r[i],i});
    for(int i=1;i<=w;i++) if(c[i]==cmx) cc.push_back({c[i],i});
    for(auto x:rr){
        for(auto y:cc){
            if(!tgt.count({x.second,y.second})){
                return rmx+cmx;
            }
        }
    }
    return rmx+cmx-1;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 42084
N = int(input())
S = input()

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

list_S = list(S)
for i in range(len(list_S)):
    alpha_before = alphabet.index(list_S[i])
    alpha_after = (alpha_before + N) % 26
    list_S[i] = alphabet[alpha_after]

print(''.join(list_S))


Measured memory_bytes: 3060
h, w = map(int, input().split())
S = []
for _ in range(h):
    s = str(input())
    S.append(s)

DP = [[0 for _ in range(w)] for _ in range(h)]

if S[0][0] == '.':
    DP[0][0] = 0
else:
    DP[0][0] = 1

ren = False
if DP[0][0] == 1:
    ren = True

for i in range(1,h):
    if S[i][0] == '.':
        DP[i][0] = DP[i-1][0]
        ren = False
    elif ren == False and S[i][0] == '#':
        DP[i][0] = DP[i-1][0] + 1
        ren = True
    elif ren == True and S[i][0] == '#':
        DP[i][0] = DP[i-1][0]
        ren = True

ren = False
if DP[0][0] == 1:
    ren = True
for j in range(1,w):
    if S[0][j] == '.':
        DP[0][j] = DP[0][j-1]
        ren = False
    elif ren == False and S[0][j] == '#':
        DP[0][j] = DP[0][j-1] + 1
        ren = True
    elif ren == True and S[0][j] == '#':
        DP[0][j] = DP[0][j-1]
        ren = True

for i in range(1,h):
    for j in range(1,w):
        if S[i][j] == '.':
            DP[i][j] = min(DP[i-1][j], DP[i][j-1])
        elif S[i][j] == '#':
            res_i = 0
            res_j = 0
            if S[i-1][j] == '.':
                res_i = 1
            if S[i][j-1] == '.':
                res_j = 1
            DP[i][j] = min(DP[i-1][j] + res_i, DP[i][j-1] + res_j)

print(DP[h-1][w-1])

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

int main() {
	list<int> lst; int tn, fn, en; cin >> tn; auto itr1 = lst.begin();
	for (int i = 0; i < tn; i++) {
		cin >> fn;
		switch (fn) {
		case 0: cin >> en; itr1 = lst.insert(itr1, en); break;
		case 1: cin >> en;
			if (en >= 0) for (int i = 0; i < en; i++) ++itr1;
			else for (int i = 0; i < abs(en); i++) --itr1;
			break;
		case 2: itr1 = lst.erase(itr1); break;
		}
	}
	for (auto itr2 : lst) cout << itr2 << endl;
	return 0;
}


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

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

int w, h;

void crawler(int y, int x) {
	field[y][x] = 0;
	for (int i = 0; i < 8; i++) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (nx < 0 || ny < 0 || w <= nx || h <= ny)continue;
		if (field[ny][nx] == 1)crawler(ny, nx);
	}
}

int main() {
	while (cin >> w >> h, w | h) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> field[i][j];
			}
		}
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (field[i][j] == 1) {
					crawler(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1240
#include<iostream>
#define maxn 10000010
using namespace std;
int ss[maxn];
int x;
int main(){
	cin >> x;
    ss[1] = 1;
    for(int i = 2; i*i <= 100000; ++i){
        if(!ss[i])
            for(int j = 2*i; j <= 1000000; j += i)
                ss[j] = 1;
    }
    for(int i = x; i <= 1000000; ++i){
    	if(!ss[i]){cout << i << endl;return 0;}
	}
    return 0;
}

Measured memory_bytes: 4352
#include<iostream>

using namespace std;

#define NMAX 200

int main(){

	int n;
	int hand[NMAX][3]={0};
	int sco[NMAX][3][101]={0};
	int sum;

	cin>>n;

	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>hand[i][j];
			for(int k=0;k<n;k++){
				if(k!=i) sco[k][j][hand[i][j]]++;
			}
		}
	}

	for(int i=0;i<n;i++){
		sum=0;
		for(int j=0;j<3;j++){
			if(sco[i][j][hand[i][j]]==0) sum+=hand[i][j];
		}
		cout<<sum<<endl;
	}

	return 0;
}

Measured memory_bytes: 1404
use std::io;

fn abc(a:i32, b:i32) -> i32 {
    let dif = b - a;
    let height;
    if b % 2 == 0 {
        height = (1 + dif) * dif / 2;
    }
    else {
        height = (2 + dif) * (dif / 2) + 1; 
    };
    let result = height - b;

    return result;
}

fn abc_(a:i32, b:i32) -> i32 {
    let result = (b - a) * (b - a + 1) / 2 - b;
    return result;
}

fn main() {
    /*test
    assert_eq!(abc(8, 13), 2);
    assert_eq!(abc(54, 65), 1);
    assert_eq!(abc(1, 4), 2);
    assert_eq!(abc(2, 5), 1);
    assert_eq!(abc(498500, 499499), 1);
    assert_eq!(abc(1, 1000), 498500);
    assert_eq!(abc_(8, 13), 2);
    assert_eq!(abc_(54, 65), 1);
    assert_eq!(abc_(1, 4), 2);
    assert_eq!(abc_(2, 5), 1);
    assert_eq!(abc_(498500, 499499), 1);
    assert_eq!(abc_(1, 1000), 498500);
    */


    let stdin = io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).ok();
    let txt:Vec<_> = line.trim().split(' ').collect();
    let a:i32 = txt[0].parse().unwrap();
    let b:i32 = txt[1].parse().unwrap();

    let result = abc_(a, b);
    println!("{}", result);
}



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

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

  long long quotient = N / (A + B);
  long long remain = N % (A + B);

  if (remain >= A){
    cout << quotient * A + A << endl;
  }
  else
  {
    cout << quotient * A + remain << endl;
  }
  
}

Measured memory_bytes: 3672
#include <stdio.h>

int main() {
    long long int X, K, D, Y;

    scanf("%lld %lld %lld", &X, &K, &D);

    if(X < 0) X = -X;
    if(D < 0) D = -D;

    Y = X / D;

    if(Y > K) X -= D * K;
    else X -= Y * D;

    K = K - Y;
    if(K % 2 != 0 && K > 0) X-= D;

    if(X < 0) X = -X;
    printf("%lld\n", X);
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	int max, min;
	int arr;
	cin >> arr;
	min = max = arr;
	for(int i = 1; i < n; i++){
		cin >> arr;
		if(arr > max)
			max = arr;
		if(arr < min)
			min = arr;
	}
	cout << max - min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	string S;
	ll K;
	cin >> S >> K;
	
	int idx = -1;
	for(int i=0;i<S.length();i++){
		if(S[i] != '1'){
			idx = i;
			break;
		}
	}
	if(idx == -1 || (ll)(idx) > K - 1){
		cout << 1 << endl;
	} else {
		cout << S[idx] << endl;
	}
	
	
	
    return 0;
}

Measured memory_bytes: 256
bool = true

n = gets.to_i
num = gets.split.map(&:to_i)
num.each{|num|
  if num % 2 == 0
    unless num % 3 == 0 || num % 5 == 0
      bool = false
    end
  end
}

if bool
  puts "APPROVED"
else
  puts "DENIED"
end

Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;

int main(){
  ll l,r;cin>>l>>r;
  ll d;cin>>d;
  int ans=0;
  for(int i=l;i<=r;i++){
    if(i%d==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int x,a,b; cin>>x>>a>>b;
  string ans = "";
  if (b <= a) {
    ans = "delicious";
  } else if(b - a < x + 1) {
    ans = "safe";
  } else {
    ans = "dangerous";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
class B{
    public:
        void solve(int n,int m){
            char a[n][n];
            char b[m][m];
            for(int i=0;i<n;i++)scanf("%s",a[i]);
            for(int i=0;i<m;i++)scanf("%s",b[i]);
            int match=0;
            for(int k=0;k<n;k++){
                for(int l=0;l<n;l++){
                    bool flag=true;
                    if(k+m-1>=n||l+m-1>=n)continue;
                    for(int i=0;i<m;i++){
                        for(int j=0;j<m;j++){
                            if(a[i+k][j+l]!=b[i][j])flag=false;
                        }
                    }
                    if(flag)match++;
                }
            }
            if(match!=0)cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
};
int main(){
    B inst;
    int n,m;
    cin>>n>>m;
    inst.solve(n,m);
    return 0;
}

Measured memory_bytes: 256
a, b, k = map(int, input().split())
if a + 2 * k > 1 + b:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(a, a + k):
        print(i)
    for i in range(b - k + 1, b + 1):
        print(i)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {
	vector<int> inp(3,0);
	for (int i = 0; i < 3; i++) {
		cin >> inp[i];
	}
	sort(inp.begin(),inp.end());
	cout << inp[0] + inp[1] + inp[2] * 10 << endl;

	return 0;
}


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

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

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

const long long mod=1e9+7;

int main(){
  int n,m;	cin >> n >> m;
  vector<bool>	a(n+1,true);
  rep(i,m){
    int x;	cin >> x;
    a[x]=false;
  }
  
  vector<long long>	dp(n+1);
  dp[0]=1;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=min(n,i+2);j++){
      if(a[j]){
        dp[j]+=dp[i];
        dp[j]%=mod;
      }
    }
  }
  cout << dp[n];
}

Measured memory_bytes: 3928
N,M,C=map(int,input().split()) 
B=list(map(int,input().split()))
A =[list(map(int,input().split()))for i in range(N)]
ans=0
for i in range(N):
    X=0
    for j in range(M):
        X+=(A[i][j]*B[j])
    X=X+C
    if  0 < X:
        ans = ans+1
print(ans)
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	int N,K,cnt=0,l;
	cin >> N >> K;
	string s;
	cin >> s;
	l = s.size();
	s = 'R' + s + 'L';
	FOR(i,1,l+1){
		if(s[i]=='R'&&s[i+1]=='L')cnt++;
		if(s[i]=='L'&&s[i-1]=='R')cnt++;
	}
	cnt -= 2*K;
	cnt = max(cnt,1);
	cout << N-cnt << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) (v).begin(), (v).end()

int main(){
  int N,K;cin>>N>>K;
  vector<int> D(N);
  for(int i=0; i<N; i++)cin>>D[i];
  int A,B,R=min(N,K);
  vector<int> GET;
  ll MAX = 0;
  for(A=0; A<=R; A++){
    for(B=0; A+B<=R; B++){
      ll sum = 0;
      GET.clear();
      int i=0;
      for(auto itr=D.begin(); i<A; i++,itr++){
        GET.push_back(*itr);
        sum += *itr;
      }
      int j=0;
      for(auto itr=D.end()-1; j<B; j++,itr--){
        sum += *itr;
        GET.push_back(*itr);
      }
      
      sort(all(GET),greater<int>());
      //DEBUG(GET);

      for(int i=0; i<K-A-B; i++){
        if(GET.empty())break;
        int x = GET.back();
        if(x>0)break;
        GET.pop_back();
        sum -= x;
      }
      //DEBUG(A,B,sum);
      MAX = max(MAX, sum);
    }
  }
  cout<<MAX<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long y = 1;
        for(long x =n; 0<x; x--)
           y =y*x;
        System.out.println(y);
        
    }
}



Measured memory_bytes: 26144
#include <iostream>
#include <cstdlib>

using namespace std;

int N, K;

void solve()
{
	long res = 1;
	while (N) {
		if (res < K) res *= 2;
		else {
			res += N * K;
			break;
		}
		N--;
	}
	cout << res << endl;
}


int main()
{
	cin >> N;
	cin >> K;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  string a,b;
  cin >> a >> b;
  a = a + b;
  ll c = 1;
  ll d = stoi(a);
  while(1){
    if(c*c==d){
      pri("Yes");
      return 0;
    }
    if(c*c>d)break;
    c++;
  }
  pri("No");
  return 0;
}


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

int main() {
  int N,G=0,W=0,Y=0,P=0;
  cin>>N;

  for(int i=0;i<N;i++){
    string op;
    cin>>op;
    if(op=="Y" && Y==0){
      Y=1;
    }
  }
  if(Y==0){
    cout << "Three" << endl;
  }else{
    cout<<"Four"<<endl;
  }
}

Measured memory_bytes: 256
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n = input_n
a = input_a

sum = 0
high = 0
n.times do |i|
  if i == 0
    high = a[i]
    next
  end
  if a[i] < high
    sum += high - a[i]
  else
    high = a[i]
  end
end
puts sum


Measured memory_bytes: 28112
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = dict()
    for a in map(int, input().split()):
        A[a] = A.get(a,0) + 1
    if N % 3:
        if 0 in A and A[0] == N:
            return 'Yes'
        else:
            return 'No'
    else:
        if 0 in A and A[0] == N:
            return 'Yes'
        elif 0 in A and A[0] == N//3:
            if len(A) == 2:
                return 'Yes'
            else:
                return 'No'
        elif len(A) == 3:
            if len(set(A.values())) == 1:
                a,b,c = A.keys()
                if c == a^b:
                    return 'Yes'
                else:
                    return 'No'
            else:
                return 'No'
        else:
            return 'No'

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

Measured memory_bytes: 15272
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

int main(void)
{
	double a, b, c, d, e, f, x, y;
	double b2, c2, e2, f2;

	while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){

		b2 = b * d;
		c2 = c * d;
		e2 = e * a;
		f2 = f * a;

		y = ((c2 - f2) / (b2 - e2));
		x = (c - b * y) / a;

		printf("%.3lf %.3lf\n", x, y);
	}

	return 0;
}

Measured memory_bytes: 652