akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> x, std::vector<long long> y)
{
    long double ans = 0;
    ll divdiv = 1;
    vector<ll> order(N);
    for (int i = 0; i < N; i++)
    {
        divdiv *= (i + 1);
        order[i] = i;
    }
    do
    {
        long double tmp = 0;
        for (int i = 0; i < N - 1; i++)
        {
            ll tmptmp = 0;
            tmptmp += pow((x[order[i + 1]] - x[order[i]]), 2);
            tmptmp += pow((y[order[i + 1]] - y[order[i]]), 2);
            tmp += sqrt(tmptmp);
        }
        ans += tmp;

    } while (next_permutation(order.begin(), order.end()));

    cout << fixed << setprecision(10) << ans / divdiv << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll P = 1e9+7;
const ll N = 1e6+7;

ll binexpo(ll a,ll b ,ll mod)
{
	if(b == 0) return 1;
	else if(b&1) return (((binexpo(a,(b-1)/2,mod)*binexpo(a,(b-1)/2,mod))%mod)*a)%mod;
	else return (binexpo(a,b/2,mod)*binexpo(a,b/2,mod))%mod;
}


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

	ll t=1;
	// cin>>t;

	while(t--){
		ll n;
		cin>>n;

		ll p1 = binexpo(10,n,P) , p2  = binexpo(8,n,P) , p3 = binexpo(9,n,P);
		p3 = ( p3*2 )% P;

		ll ans;
		ans = (p1 + p2) % P;
		ans = (ans - p3  + P) % P;

		cout<<ans<<"\n";

	}	

	return 0;
}	


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using LL = long long;
using namespace std;
const int mod = 1e9 + 7;
inline LL f(LL n) { return n * (n + 1) / 2; }
int main() {
	int n, k; cin >> n >> k;
	LL ans = 1;
	for (int i = k; i <= n; i++) 
		ans = (ans + f(n) - f(n - i) - f(i - 1) + 1) % mod;
	cout << ans;
}

Measured memory_bytes: 3624
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
        int n=sc.nextInt();
        int a=0;
        for (int i = 1; i <=n ; i++) {
			int r=i,e=0;
			while(r>0) {
				e++;
				r/=10;
			}
			if(e%2==1)a++;
		}
        
      
        out.println(a);
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21460
n=int(input())
a=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
for i in a:d[i]+=1
ans=0
for i in d:ans+=d[i]*(d[i]-1)//2
for i in a:
  x=d[i]*(d[i]-1)//2
  y=(d[i]-1)*(d[i]-2)//2
  print(ans-x+y)
  

Measured memory_bytes: 25644
#include <bits/stdc++.h>
#define LL long long
using namespace std;

vector<int> bit, val;
int cnt[30];

int main()
{
    int n;
    scanf("%d", &n);
    val.push_back(0);

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

        if(x < 12)
            cnt[x] ++;
        else
            cnt[24 - x] ++;

    }

    for(int i = 0; i < 12; i++) {
        if(cnt[i] > 2)
            return !printf("0");
        else if(cnt[i] == 2)
            val.push_back(i), val.push_back(24 - i);
        else if (cnt[i] == 1)
            bit.push_back(i);
    }

    if(cnt[12] > 1)
        return !printf("0");
    else if (cnt[12] == 1)
        bit.push_back(12);

    int ans = -1;

    for(int i = 0; i < 1 << bit.size(); i++) {
        int cur = 100;
        for(int j = 0; j < bit.size(); j++) {
            if(i & (1 << j))
                val.push_back(bit[j]);
            else
                val.push_back(24 - bit[j]);
        }
        for(int j = 0; j < val.size(); j++) {
            for(int k = j + 1; k < val.size(); k++) {
                int t = val[j], tt = val[k];
                if(t > tt)
                    swap(t, tt);
                tt -= t;
                cur = min(cur, min(tt, 24 - tt));
            }
        }
        for(int j = 0; j < bit.size(); j++)
            val.pop_back();
        ans = max(ans, cur);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  int l_x = 0, l_y = 0, l_t = 0;
  for(int i=0; i<N; ++i){
   int t, x, y; cin >> t >> x >> y;
   int k = (abs(l_x-x)+abs(l_y-y));
   int p = k%2;
   if(abs(t-l_t)%2 != p ||  k > abs(t-l_t)){
     cout << "No\n"; 
     return 0;
   }
   l_x = x, l_y = y, l_t = t;
  }
  cout << "Yes\n";
  return 0; 
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int n,pos;
vector<int>pre,in,post;
void rec(int l,int r){
	if(l>=r)
		return ;
	//将树一分为二的节点 
	int root = pre[pos++];
	//寻找root在中序中的位置 
	int m = distance(in.begin(),find(in.begin(),in.end(),root));
	rec(l,m);
	rec(m+1,r);
	//每一个子树的根节点最后输出 
	post.push_back(root); 
}
void solve(){
	pos=0;
	rec(0,pre.size());
	for(int i=0;i<n;i++){
		if(i)
			cout<<" ";
		cout<<post[i];
	}
	cout<<endl;
}
int main(){
	cin>>n;
	int k;
	for(int i=0;i<n;i++){
		cin>>k;
		pre.push_back(k);
	}
	for(int i=0;i<n;i++){
		cin>>k;
		in.push_back(k);
	} 
	solve();
	return 0;
} 


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

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

    int sum = 0;

    for (int i = a; i <= b; i++) {
        string str = to_string(i);
        string rev;
        reverse_copy(str.begin(), str.end(), back_inserter(rev));
        sum += str == rev;
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<char, int> P;
const int mod = 1000000007;
const int INF = 1e18;

vector<pair<char, int> > run_length_factorization(string s){
    vector<pair<char, int> > res;
    s += '$';
    char c = s[0];
    int now = 1;
    for(int i = 1; i < s.size(); i++){
        if(s[i] != c){
            res.push_back(pair<char, int>(c, now));
            c = s[i]; now = 1;
        }else now++;
    }
    return res;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<P> rle = run_length_factorization(s);
    int ans = 0;
    for(auto i : rle){
        ans += i.second * (i.second + 1) / 2;
    }
    for(int i = 0; i < rle.size() - 1; i++){
        if(rle[i].first == '<'){
            ans -= min(rle[i].second, rle[i + 1].second);
        }
    }
    cout << ans << endl;
}

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



int main()
{
    int n;
    cin>>n;
    
    int a[n];
    long int dp[n];
    
    for(int i=0;i<n;i++)cin>>a[i];
    
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    
    for(int i=2;i<n;i++)
    {
        dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
    }
    
    cout<<dp[n-1];
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 15;
int n, a[N], x[N][N], y[N][N];
bool check(int b){
  FOR(i, 0, n)if((b>>i)&1)FOR(j, 0, a[i])if(((b>>x[i][j])&1)!=y[i][j]) return false;
  return true;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> a[i];
    FOR(j, 0, a[i]) cin >> x[i][j] >> y[i][j], x[i][j]--;
  }
  int ans = 0;
  FOR(i, 0, 1<<n) if(check(i)) maxs(ans, pcnt(i));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <unistd.h>
#include <cstdio>
#include <x86intrin.h>

typedef long long ll;
int mat[3000][3000]; 
ll dp0[3000] __attribute((aligned(32)));

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx512vl"))), apply_to=function)
int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    __m256i mask0 = _mm256_set_epi64x(0, 0, 0, -1); 
    __m256i mask1 = _mm256_set_epi64x(-1, -1, -1, 0); 
    for (int y = 0; y < rr; y++) {
        __m256i work = _mm256_setzero_si256();
        //ymm[0] = ymm[1] = ymm[2] = ymm[3] = 0;
        for (int x = 0; x < cc; x++) {
            __m256i tmp = _mm256_maskload_epi64(&dp0[x], mask0);
            work = _mm256_max_epi64(work, tmp);
            //ymm[0] = std::max(ymm[0], dp0[x]);
            //int v = mat[y][x];
            __m256i v = _mm256_set1_epi64x(mat[y][x]);
            v = _mm256_andnot_si256(mask0, v);
            __m256i s = _mm256_permutex_epi64(work, (2 << 6) + (1 << 4));
            s = _mm256_add_epi64(s, v);
            work  = _mm256_max_epi64(work, s);
            __m256i s2 = _mm256_permutex_epi64(work, (1 << 6) + (0 << 4) + (3 << 2) + (2 << 0));
            __m256i s3 = _mm256_max_epi64(work, s2);
            __m256i s4 = _mm256_permutex_epi64(s3, 5);
            __m256i s5 = _mm256_max_epi64(s3, s4);

//            for (int c = 3; c > 0; c--) {
//                ymm[c] = std::max(ymm[c], ymm[c - 1] + v);
//            }
//            dp0[x] = std::max(std::max(ymm[0], ymm[1]), std::max(ymm[2], ymm[3]));
            _mm256_maskstore_epi64(&dp0[x], mask0, s5);
        }
    }
    std::printf("%lld\n", dp0[cc - 1]);
    return 0;
}
#pragma clang attribute pop

Measured memory_bytes: 39272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    int N;
    cin >> N;
    cout << (N-1)/2 << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
  string str;
  cin >> str;
  int result = 0;
  for (int i = 0; i < 4; i++) {
    if (str[i] == '+') {
      result++;
    }else{
      result--;
    }
  }
  cout << result << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int[] ll = new int[n];
        int min = Integer.MAX_VALUE;
        int tmp = 0;
        for (int i = 0; i < n; i++) {
            ll[i] = l + i - 1 + 1;
            int lll = Math.abs(ll[i]);
            if(min > lll) {
                min = lll;
                tmp = i;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if(!(i == tmp)) {
                ans += ll[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35836
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, A, B, C, D;
  cin >> n >> A >> B >> C >> D;
  A--;
  B--;
  C--;
  D--;
  bool posible = true;
  string s;
  cin >> s;
  for (int i = A; i < C; ++i) {
    if (s[i] == '#' && s[i+1] == '#')
      posible = false;
  }
  for (int j = B; j < D; ++j) {
    if (s[j] == '#' && s[j+1] == '#')
      posible = false;
  }
  if (D < C) {
    // Tendré que saltar a B en algún punto
    // entre B-1 y D
    bool puedoSaltar = false;
    for (int j = B-1; j < D; ++j) {
      if (j < A) continue;
      if (j+2 >= n) continue;
      if (s[j] == '.' && s[j+1] == '.' && s[j+2] == '.') {
        puedoSaltar = true;
      }
    }
    posible &= puedoSaltar;
  }
  cout << (posible ? "Yes" : "No") << "\n";
  return 0;
}

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

#define MOD 1000000007
int arrayMax(vector<int> p,int idx){
  int max_Val = p.at(0);
  rep(i,idx){
    max_Val = max(max_Val,p.at(i)); 
  }
  
  return max_Val;
}

int main() {
  int N;
  cin >> N;
  
  vector<int> Hi;
  rep(i,N){
    int tmpHi;
    cin >> tmpHi;
    Hi.push_back(tmpHi);
  }

  int ans = 1;
  rep(i,N){
    if(i == 0) continue;
    int Himax = arrayMax(Hi,i);
    if(Hi.at(i) >= Himax) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n;
int res,id;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d%lld",&a,&b,&c,&d,&n);
	res=a*8;
	id=8;
	if(b*4<res)res=b*4,id=4;
	if(c*2<res)res=c*2,id=2;
	int tres=res;
	if(d<res)res=d,id=1;
	if(id>1)printf("%lld",(long long)n*res/2LL);
	else
	{
		if(n&1LL)printf("%lld",(long long)n/2LL*d+(long long)tres/2LL);else printf("%lld",(long long)n/2LL*d);
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<ll>vec(3 * N);
	rep(i, 0, 3 * N)cin >> vec[i];
	sort(all(vec), greater<ll>());
	ll sum1 = 0, sum2 = 0;
	rep(i, 0, N) {
		sum1 += vec[N + i];
	}
	rep(i, 0, 2 * N) {
		++i;
		sum2 += vec[i];
	}
	cout << max(sum1, sum2) << "\n";

	return 0;
}


Measured memory_bytes: 5556
L, R = map(int, input().split())
diff = R - L
D = 0
if diff >= 2018:
  print(0)
  D = 1
else:    
  ans = [(i * j)%2019 for i in range(L, R+1) for j in range(i+1, R+1)]
if  D == 0:
  print(min(ans))

Measured memory_bytes: 75408
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

S = stdin.readline().rstrip()
SS = []
for x in S:
    SS.append(x)

flg = False

for i in range(len(SS)-1):
    if SS[i] == S[i+1]:
        flg = True

if flg:
    print("Bad")
else:
    print("Good")

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n;
	cin >> n;
	map<int, int>mp;
	vector<int>vec;
	bool zero = true;
	rep(i, n) {
		int a;
		cin >> a;
		if (a != 0) zero = false;
		mp[a]++;
		vec.push_back(a);
	}
	if (zero) {
		cout << "Yes" << endl;
	}
	else if (n % 3 == 0) {
		if (mp.size() > 3) {
			cout << "No" << endl;
			return 0;
		}
		sort(vec.begin(), vec.end());
		vector<int>v;
		v.push_back(vec[0]);
		for (int i = 1; i < vec.size(); i++) {
			if (vec[i] != vec[i - 1]) {
				v.push_back(vec[i]);
			}
		}
		if (mp.size() == 3) {
			if ((mp[v[0]] == mp[v[1]] && mp[v[1]] == mp[v[2]]) &&( v[0] ^ v[1]) == v[2]) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (mp.size() == 2) {
			if (((mp[v[0]] * 2 == mp[v[1]]) && (v[1] ^ v[1]) == v[0]) || (mp[v[1]] * 2 == mp[v[0]] && (v[0] ^ v[0]) == v[1])) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

int main()
{ 
  int n, a, b, c, d ;
  cin >> n >> a >> b ;
  c = min(a, b) ;

  if(n >= a + b)
  {
    d = 0 ;
  }
  else
  {
    d = a + b - n ;
  }
  
  cout << c << " " << d << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
struct edge
{
    long long from, to, cost;
};
vector<long long> dijkstra(long long s, vector<edge> G[], long long V)
{
    vector<long long> d(V + 1);
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> que;
    for (long long i = 0; i < V; i++)
    {
        d[i] = 1e18;
    }
    d[s] = 0;
    que.push(pair<long long, long long>(0, s));
    while (!que.empty())
    {
        pair<long long, long long> p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first)
            continue;
        for (long long i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(pair<long long, long long>(d[e.to], e.to));
            }
        }
    }
    return d;
}
ll dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
ll h, w;
string s[55];
ll vis[55][55];
vector<edge> G[5555];
void dfs(ll i, ll j)
{
    // cout << i << " " << j << endl;
    edge eee;
    eee.cost = 1;
    rp(k, 0, 4)
    {
        if (i + dx[k] >= 0 && i + dx[k] < h && j + dy[k] >= 0 && j + dy[k] < w && s[i + dx[k]][j + dy[k]] == '.')
        {
            eee.to = (i + dx[k]) * w + j + dy[k];
            G[i * w + j].push_back(eee);
            if (vis[i + dx[k]][j + dy[k]] == 0)
            {
                vis[i + dx[k]][j + dy[k]] = 1;
                dfs(i + dx[k], j + dy[k]);
            }
        }
    }
}
int main()
{
    cin >> h >> w;
    rp(i, 0, h) cin >> s[i];
    dfs(0, 0);
    ll ww = 0;

    rp(i, 0, h) rp(j, 0, w) if (s[i][j] == '.') ww++;
    vl d = dijkstra(0, G, h * w);
    if (d[h * w - 1] < inf)
        ce(ww - d[h * w - 1] - 1);
    else
        ce(-1);
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

set<int> sep_digit(int x) {
    set<int> st;
    while (x) {
        st.insert(x%10);
        x/=10;
    }
    return st;
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> unlike(k);
    int tmp;
    for (auto& x:unlike) {
        cin >> x;
    }
    set<int> st;
    int answer = -1;
    for (int i = n;answer == -1; ++i) {
        answer = i;
        st = sep_digit(i);
        for (auto x:unlike) {
            if (st.count(x) != 0) {
                answer = -1;
                break;
            }
        }
    }
    cout << answer;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<string>s(5);
    rep(i,n){
      string a,b,c,d,e;
      cin>>a>>b>>c>>d>>e;
      s[0]=a+s[0];
      s[1]=b+s[1];
      s[2]=c+s[2];
      s[3]=d+s[3];
      s[4]=e+s[4];
    }
    rep(i,5)while(s[i].size()<11)s[i].push_back('%');
    //
    int ans=0;
    while(1){
      bool han=true;
      rep(i,11){
	int j;
	for(j=1;j<4;j++){
	  if(s[j-1][i]==s[j][i]&&s[j][i]==s[j+1][i]&&s[j][i]!='%')break;
	}
	if(j!=4){
	  han=false;
	  char tmp=s[2][i];
	  rep(j,5){
	    if(tmp==s[j][i]){
	      ans+=s[j][i]-'0';s[j][i]='!';
	    }
	  }
	  if(s[0][i]==s[2][i]&&s[0][i]!=s[1][i]){ans-=tmp-'0';s[0][i]=tmp;}
	  else if(s[2][i]==s[4][i]&&s[3][i]!=s[4][i]){ans-=tmp-'0';s[4][i]=tmp;}
	}
      }
      rep(i,5){
	for(int j=10;j>=0;j--){
	  if(s[i][j]=='!'){s[i].erase(s[i].begin()+j);s[i].push_back('%');}
	}
      }
      if(han)break;
      //rep(i,5)cout<<s[i]<<endl;
    }
    cout<<ans<<endl;
  }
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<int> vec1(N+1), vec2(N);
  rep(i, N){
    if (S.at(i) == 'R') vec1[i] = 1;
    else if (S.at(i) == 'L') vec1[i] = -1;
  }
  vec1[N] = 1;
  
  int rn = 0;
  int ln = 0;
  int turn = 0; 
  
  rep(i, N+1){
    if (ln == 0 && vec1[i] == 1 ){
      rn++;
    }
    else if (ln == 0 && vec1[i] == -1){
      ln++;
      turn = i;
    }
    else if (ln > 0 && vec1[i] == -1){
      ln++;
    }
    else if (ln > 0 && vec1[i] == 1) {
      int mean_rl = (rn + ln) / 2;
      if ( (rn -ln) % 2 == 0 ){
        vec2[turn-1] = mean_rl;
        vec2[turn] = mean_rl;
      }
      else if (rn % 2 == 0 ){
        vec2[turn-1] = mean_rl;
        vec2[turn] = mean_rl + 1;
      }
      else if (rn % 2 == 1 ){
        vec2[turn-1] = mean_rl + 1;
        vec2[turn] = mean_rl;
      }
      rn = 1;
      ln = 0;
    }

  }
  
  rep(i, N) cout << vec2[i] << ' ';  
  
}

Measured memory_bytes: 1408
import numpy as np
N,M = map(int,input().split())
LR_mat = np.zeros((M,2))
for i in range(M):
  LR_mat[i,:]=list(map(int,input().split()))

a = np.max(LR_mat[:,0],axis=0)
b = np.min(LR_mat[:,1],axis=0)
num_ID = int(b-a+1)
if num_ID >= 0:
  print(num_ID)
else:
  print(0)  

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

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
    ll A,B; cin >> A >> B;
    auto pa = prime_factor(A), pb = prime_factor(B);
    set<ll> st;
    for(auto p : pa){
        st.insert(p.first);
    }
    for(auto s : st){
        if(pb[s]==0) st.erase(s);
    }
    st.insert(1);
    cout << st.size() << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int len = S.length();
    long sum = 0;
    for(int i = len - 1; i >= 0; i--) {
      String s = String.valueOf(S.charAt(i));
      long digit = Long.parseLong(s);
      for(int k = 0; k < len - i; k++) {
        if(k < len - i - 1) {
          sum += digit * (long)Math.pow(10, k) * (long)Math.pow(2, len - 2 - k);
        } else {
          sum += digit * (long)Math.pow(10, k) * (long)Math.pow(2, i);
        }
      }
    }
    System.out.println(sum);
  }
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int A, B;
    cin >> A >> B;

    int cur = 1;
    for(int ans = 0; ans < 100; ++ans) {
        if(cur >= B) {
            printf("%lld\n", ans);
            break;
        }
        cur--;
        cur += A;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pr pair<int, int>
#define v1d vector<int>
#define mp make_pair
#define pb push_back
#define v1p vector<pr>
#define vb vector<bool>
#define v2d vector<vector<int>>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define eb emplace_back
#define endl "\n"
#define MOD 1000000007
#define pqx priority_queue <int>
#define pqn priority_queue <int, v1d, greater<int> >
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int INF = 1e18;

int32_t main() {
    fio
    int a; cin >> a;
  	long double b; cin >> b;
  	a *= b;
  	cout << a; 
}

Measured memory_bytes: 3752
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,l,m,n,p,s=1000,a[105];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(;i++<n;)cin>>a[i];
	for(i=0;++i<n;)
	{
		if(a[i]<a[i+1])s+=s/a[i]*(a[i+1]-a[i]);
	}
	cout<<s;
}

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

    int n;  
    int x[10],y[10];

    double dist(int i,int j){
        double dx=x[i]-x[j];
        double dy=y[i]-y[j];
        return pow(dx*dx+dy*dy,0.5);
    }

    void solve(){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
        double sum=0.0;
        vector<int> v(n);
        rep(i,n) v[i]=i+1;
        do{
            for(int i=0;i<n-1;i++) sum+=dist(v[i],v[i+1]);
        }while(next_permutation(v.begin(),v.end()));
        int ave=1;
        for(int i=2;i<=n;i++) ave*=i;
        cout<<fixed<<setprecision(8)<<sum/ave<<endl;
        return;
    }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define MX LLONG_MAX
#define MN LLONG_MIN

const int N=1e5+5;
const ll mod=1e9+7;
 
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
void EE(ll a,ll b,ll &co1,ll &co2)
{
    if(a%b==0)
    {
        co1=0;
        co2=1;
        return;
    }
    EE(b,a%b,co1,co2);
    ll temp=co1;
    co1=co2;
    co2=temp-co2*(a/b);
}
ll modinv(ll a,ll m)
{
    ll x,y;
    EE(a,m,x,y);
    if(x<0) x+=m;
    return x;
}

int32_t main()                  
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<min(min(a+b,a+c),b+c);
    return 0;
}  

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
void func(int,int,int);
int su[15],w,kan[15],f;
using namespace std;
int main(void)
{
	int i,flg;
	for(i=0;i<15;i++)	kan[i]=0;
	f=0;
	scanf("%d",&w);
	func(0,0,1);
	flg=0;
	for(i=14;i>=0;i--)	{
		if(kan[i]==-1)	{
			printf("-");
			flg=1;
		}
		else if(kan[i]==1)	{
			printf("+");
			flg=1;
		}
		else {
			if(flg==1)	{
				printf("0");
			}
		}
	}
	printf("\n");
	return 0;
}
void func(int nn,int sum,int suu)
{
//	printf("nn=%d sum=%d f=%d\n",nn,sum,f);
	int i;
	if(nn<15)	{
		if(sum==w)	{
			for(i=0;i<nn;i++)	kan[i]=su[i];
			f=1;
		}
			if(f==0)	{
				for(i=-1;i<=1;i++)	{
					su[nn]=i;
					func(nn+1,sum+i*suu,suu*3);
				}
			}
	}
}


Measured memory_bytes: 996
#include<iostream>
#include<algorithm>
using namespace std;
const int N=110;
char s[N],t[N];
int main(){
    int n;
    cin>>n;
    cin>>s;
    cin>>t;
    
    for(int i=0;i<n;i++){
        cout<<s[i]<<t[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll INF=1e9+7;

int main(){
    //vector<char> s(3);
    set<char> s;
    rep(i,3){
        char c;
        cin >> c;
        s.insert(c);
    }
    if(s.size()==3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

Measured memory_bytes: 256
import sys
def 解():
    iH,iW,iN = [int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    iMax = (iH - 2) * (iW -2)
    #print (iMax)

    dC={}
    for i in range(10):
        dC[i]=0

    #愚直 無理 つらい
    #for i in range(1,iH -1):
    #   for j in range(1,iW-1):
    #       tmp = 0
    #       for a in aD:
    #           if j<= a[1] <=j+2 and i<= a[0] <= i+2:
    #               tmp +=1
    #       dC[tmp] +=1

    #なんというか、面倒くさくなって解法みても
    #面倒くさがらずやれとしか書いてなくてつらい
    dM = {}
    for a in aD:
        y=a[0]
        x=a[1]
        for aP in [(y-2,x-2),(y-2,x-1),(y-2,x),(y-1,x-2),(y-1,x-1),(y-1,x),(y,x-2),(y,x-1),(y,x)]:
            if 0< aP[0]<iH-1 and 0 < aP[1] < iW-1:
                iP = aP[0]*iW + aP[1]
                if iP in dM: #もう最初から足したったらええんや
                    dM[iP] += 1
                else:
                    dM[iP] = 1
    for i in dM:
        dC[dM[i]]+=1

    iAllBM=0
    for i in range(1,10):
        iAllBM+=dC[i]
    dC[0] = iMax -iAllBM #点のないマス0は引き算で出せる

    for i in range(10):
        print(dC[i])
解()


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

int main() {
  int r;
  cin >> r;
  
  cout << fixed << setprecision(10) << 3.141592 * r * 2 << endl;
}

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

int main() {
  
  int K, S;
  cin >> K >> S;
  
  int count = 0;
  for(int i = 0; i <= K; i++) {
    for(int j = 0; j <= K; j++) {
        if(0 <= (S - i -j) && (S - i -j) <= K) {
          ++count;
        }
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
from numpy import *
import itertools

A = [ list(map(int,input().split(" "))) for i in range(3)]
N=int(input())

b=[]
for i in range(N):
  b.append(int(input())) 
C=zeros((3,3))
for i in range(0,3):
  for j in range(0,3): 
    for k in range(0,N):
      if A[i][j]==b[k]:
        C[i][j]=1     
if C[0][0]==1 and C[1][1]==1 and C[2][2]==1:
  print("Yes") 
elif C[0][2]==1 and C[1][1]==1 and C[2][0]==1:  
   print("Yes") 
elif C[0][0]==1 and C[1][0]==1 and C[2][0]==1:
  print("Yes")    
elif C[0][1]==1 and C[1][1]==1 and C[2][1]==1:
  print("Yes")  
elif C[0][2]==1 and C[1][2]==1 and C[2][2]==1:
  print("Yes") 
elif C[0][0]==1 and C[0][1]==1 and C[0][2]==1:
  print("Yes")   
elif C[1][0]==1 and C[1][1]==1 and C[1][2]==1:
  print("Yes")   
elif C[2][0]==1 and C[2][1]==1 and C[2][2]==1:
  print("Yes") 
else:
  print("No") 

Measured memory_bytes: 21304
#include<stdio.h>
int main(){
    int N,i;
    double A[1000],total=0;
    
    
    scanf("%d",&N);
    for(i = 0 ; i < N ; i++){
        scanf("%lf",&A[i]);
    }
    
    for(i = 0 ; i < N ; i++){
        total += 1/A[i];
    }
    printf("%f\n",1/total);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e3 + 5;
const int MOD = 1e9 + 7;

int n, m;
int a[N], b[N];
int cache[N][N];

int dp(int i, int j)
{
	if(i > n)
		return 0;
	if(j > m)
		return 0;
	int &ans = cache[i][j];
	if(ans != -1)
		return ans;
	if(a[i] == b[j])
		ans = 1 + dp(i + 1, j) + dp(i, j + 1);
	else
		ans = dp(i + 1, j) + dp(i, j + 1) - dp(i + 1, j + 1);
	ans += MOD;
	ans %= MOD;
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= m; i++)
		cin >> b[i];
	int ans = dp(1, 1);
	ans++;
	ans %= MOD;
	cout << ans;
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int cyadder(char& c,int add,int cyc,char start){
	int carry=add/cyc;
	add%=cyc;
	while(add--){
		c++;
		if(c>start+cyc-1){
			c=start;
			carry++;
		}
	}
	return carry;
}

int fulladder(char* s,int add,int cyc,char start,int n){
	int r=add;
	for(int i=n-1;i>=0;i--){
		r=cyadder(s[i],r,cyc,start);
		if(r==0)break;
	}
	return r;
}

char s[111111];
int k;

int main(){
	cin.sync_with_stdio(false);
	cin>>s>>k;
	int n=strlen(s);
	rep(i,n){
		if(i==n-1){
			if(k>0)cyadder(s[i],k,26,'a');
		}else{
			if(s[i]!='a'&&k+s[i]>'z'){
				k-=('z'-s[i]+1);
				s[i]='a';
				//dbg(k);
			}
		}
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 512
def gcd(a,b):
	if a > b:
		n,m = a,b
	else:
		n,m = b,a
	while m > 0:
		t = n % m
		n = m
		m = t
	return n

def gcd_3(a,b,c):
	return gcd(gcd(a,b),c)

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N,A,B,K = map(int,input().split())
g = gcd_3(A,B,K)
A = A // g
B = B // g
K = K // g
mod = 998244353 #出力の制限
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
n0,m0=-1,-1
for i in range(K//A + 1):
	if (K - A*i) % B == 0:
		n0,m0 = i, (K - A*i)//B
		break
k = 0
while k*B + n0 <= N and m0 - k*A >= 0:
	n,m = k*B + n0, m0 - k*A
	if m <= N:
		ans = (ans + cmb(N,n,mod) * cmb(N,m,mod)) % mod
	k += 1
print(ans)

Measured memory_bytes: 38884
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    int f=0,n=s.length();
    for(int i=0;i<n;i+=2){
        if(s[i]=='L')
            f=1;
    }
    for(int i=1;i<n;i+=2){
        if(s[i]=='R')
            f=1;
    }
    if(f)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 3644
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    N, M, Q = read_values()
    S = [[0 for _ in range(N + 1)] for __ in range(N + 1)]
    
    for _ in range(M):
        l, r = read_values()
        S[l][r] += 1

    for l in range(N):
        for r in range(N):
            S[l + 1][r + 1] += S[l + 1][r] + S[l][r + 1] - S[l][r] 

    res = [0] * Q
    for i in range(Q):
        p, q = read_values()
        res[i] = str(S[q][q] - S[p - 1][q] - S[q][p - 1] + S[p - 1][p - 1])
    print("\n".join(res))


if __name__ == "__main__":
    main()

Measured memory_bytes: 66268
n, m = map(int, input().split())
ab = []
for _ in range(m):
    ab.append(list(map(int, input().split())))

ab.sort(key=lambda x: x[1])

c = -float("inf")
ans = 0
for i in range(m):
    if c <= ab[i][0]:
        c = ab[i][1]
        ans += 1

print(ans)


Measured memory_bytes: 29072
def g;gets.split.map &:to_i;end
while(m,n=g)[0]>0
a=(1..g[0]).map{|i|g<<i}
p (1..g[0]).map{d=a+[c=g<<11]
s=0
(1..n).map{|j|(1..m).map{|i|d.min_by{|x,y,t|z=(y-j).abs
[z+[(x-i).abs-(z+(i<x ?1-j%2:j%2))/2,0].max,t]}==c&&s+=1}}
s}.max
end

Measured memory_bytes: 6108
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)







int main(){
    int m, n;
    cin >> m >> n;
    while(n || m){
        vector<bool> used(7368792);
        int k = m;
        for(int cnt = 0; cnt < n;){
            if(!used[k]){
                used[k] = true;
                for(int j = k * 2; j <= 7368791; j += k){
                    used[j] = true;
                }
                cnt++;
            }
            k++;
        }
        while(used[k]) k++;
        
        cout << k << endl;
        
        cin >> m >> n;
    }
}


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

int N;
vector< pair<int, int> > ab;
vector<int> exist(N, false);

void solve(){
  vector<int> g(N), h(N);
  for(int i = 0; i < N; i++){
    int v = ab[i].first;
    g[v] = v;
    h[v] = v;

    if(exist[v] == false){
      h[v] = (v+1)%N;
    }
  }
  for(int i = 0; i < N; i++){
    int v = ab[i].first;
    if(i != 0) cout << " ";
    cout << g[v]+1;
  }
  cout << endl;
  for(int i = 0; i < N; i++){
    int v = ab[i].first;
    if(i != 0) cout << " ";
    cout << h[v]+1;
  }
  cout << endl;
}

int main(void){
  cin >> N;
  ab = vector< pair<int, int> >(N);
  for(int i = 0; i < N; i++){
    cin >> ab[i].first;
    ab[i].first--;
  }
  for(int i = 0; i < N; i++){
    cin >> ab[i].second;
    ab[i].second--;
  }

  exist = vector<int>(N, false);

  bool flg = false;
  for(int i = 0; i < N; i++){
    int b = ab[i].second;
    if(exist[b] == true){
      flg = true;
    }else{
      exist[b] = true;
    }
  }
  if(flg == false){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
    solve();
  }
  return 0;
}



Measured memory_bytes: 4852
n=int(input())
a=list(map(int,input().split()))
arr=[0]*(n+1)
for i in range(1,n+1):
  arr[i]=arr[i-1]+a[i-1]
ans=10**18
for i in range(1,n):
  ans=min(ans,abs(arr[n]-2*arr[i]))
print(ans)

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int n,x;
	cin >> n >> x;
	int c=0;
	rep(i,1,n)
	{
		int f;
		cin >> f;
		if(f>=x)
		{
			c++;
		}
		}	
		cout << c << endl;
}



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

int n, tim;
struct Node {
    char s[10];
    int v;
};
queue<Node> Q;

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d %d", &n, &tim);
    for (int i = 0; i < n; i++) {
        Node node;
        scanf("%s %d", node.s, &node.v);
        Q.push(node);
    }
    int tmp = 0;
    while (!Q.empty()) {
        Node node = Q.front();
        Q.pop();
        if (node.v <= tim) {
            tmp += node.v;
            printf("%s %d\n", node.s, tmp);
        } else {
            tmp += tim;
            node.v -= tim;
            Q.push(node);
        }
    }
    return 0;
}

Measured memory_bytes: 3664