akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int p,q,d[80],n;

int main(){
	while(cin>>p>>q){
		map<int,int> r;
		map<int,int>::iterator ite;
		p%=q;
		r[p]=-1;
		int n=0,s,f=0;
		while(1){
			d[n]=p*10/q;
			if(!((p*10)%q)){f=1;break;}
			ite=r.find((p*10)%q);
			if(ite!=r.end()){s=r[(p*10)%q];break;}
			r[(p*10)%q]=n++;
			p=(p*10)%q;
		}
		if(f){
			for(int i=0;i<=n;i++)cout<<d[i];cout<<endl;
		}
		else {
			for(int i=0;i<=n;i++)cout<<d[i];cout<<endl;
			for(int i=0;i<=n;i++){
				if(i<=s)cout<<" ";
				else cout<<"^";
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for (int i = (j); i <= (k); i++)
#define FFOR(i, j, k) for (int i = (j); i < (k); i++)
#define DFOR(i, j, k) for (int i = (j); i >= (k); i--)
#define bug(x) cerr << #x << " = " << (x) << '\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s) >> (i)) & 1LL)
#define mask(i) ((1LL << (i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll = long long;
using ld = long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const ld pi = acos(0) * 2;
template <typename T>
inline void read(T &x)
{
    char c;
    bool nega = 0;
    while ((!isdigit(c = getchar())) && (c != '-'))
        ;
    if (c == '-')
    {
        nega = 1;
        c = getchar();
    }
    x = c - 48;
    while (isdigit(c = getchar()))
        x = x * 10 + c - 48;
    if (nega)
        x = -x;
}
template <typename T>
inline void writep(T x)
{
    if (x > 9)
        writep(x / 10);
    putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    writep(x);
}
template <typename T>
inline void writeln(T x)
{
    write(x);
    putchar('\n');
}
#define taskname "C"
int main()
{
#ifdef Gaurav
    if (fopen(taskname ".in", "r"))
        freopen(taskname ".in", "r", stdin);
#endif // Gaurav
    int a,p;
    read(a),read(p);
    a*=3;
    int total=a+p;
    writeln(total/2);

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import deque
N, M = map(int, input().split())
abn = [list(map(int, input().split())) for _ in range(M)]

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

ans = 0
bnum = -1
for a,b in abn:
    if bnum == -1:
        bnum = b - 1
        ans += 1
    elif a <= bnum < b:
        continue
    else:
        bnum = b - 1
        ans += 1

print(ans)

Measured memory_bytes: 29392
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int x;
	cin >> x;
	if (x < 1200) {
		cout << "ABC" << endl;
		return 0;
	}
	cout << "ARC" << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		
		for (int i=0; i<N; i++) {
			A[i] = sc.nextInt();
			H -= A[i];
			
			if (H <= 0) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 51036
s = input()
t = input()


def judge(s, t):
    s = sorted(s)
    t = sorted(t)[::-1]
    N = len(s)
    M = len(t)

    org_t = sorted(t)
    if s == org_t:
        return False

    if N < M and s[:N] == org_t[:N]:
        return True

    min_len = min(N, M)
    for a, b in zip(s[:min_len], t[:min_len]):
        if a == b:
            continue
        return a < b
    # M の方が小さくて途中まで同じだったら最終的にFalse
    return False


if judge(s, t):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.matches("^A[a-z]+C[a-z]+$")) {
			System.out.println("AC");
		} else {
			System.out.println("WA");
		}

	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define rs (x<<1|1)
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) (int((x).size()))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
const int maxn=2e3+5;
int n;
int a[maxn],vis[maxn],dep[maxn];
vector<int>e[maxn];
priority_queue<int>A;
int getgcd(int x,int y){
	return !x?y:getgcd(y%x,x);
}
void dfs(int x){
	rep2(i,0,SZ(e[x]))if(!dep[e[x][i]])dep[e[x][i]]=dep[x]+1,dfs(e[x][i]);
}
int main(){
	read(n);
	rep(i,1,n)read(a[i]);
	sort(a+1,a+n+1);
	rep(i,1,n)rep(j,i+1,n)if(getgcd(a[i],a[j])!=1)e[i].pb(j),e[j].pb(i);
	rep(i,1,n)if(!dep[i])dep[i]=1,dfs(i),A.push(i);
	rep(i,1,n){
		int x=A.top();A.pop();
		printf("%d ",a[x]);
		rep2(i,0,SZ(e[x]))if(dep[e[x][i]]==dep[x]+1)A.push(e[x][i]);
	}
	return 0;
}

Measured memory_bytes: 17664
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
    long long int a,b,c,d,n,m,array[100000+10],ans=0,sum1=0,sum2=0,sum3=0,sum=0,cnt=0,cnt1=0,cnt2=0,cnt3=0,flag,flag1,flag2;
    int i,j;
    string s[1000],p[1000];
    char ch;
    cin>>n>>m;
    for(i=0; i<n; i++)
    {
        s[i]=m+'0';
    }
    for(i=0; i<m; i++)
    {
        p[i]=n+'0';
    }
    if( lexicographical_compare(s, s+n, p, p+m))
    {
        flag=1;
    }
    else
    {
        flag=0;

    }
    if(flag==1)
    {
        for(i=0; i<n; i++)
            cout<<s[i];
    }
    else
    {
        for(i=0; i<m; i++)
            cout<<p[i];
    }


}



Measured memory_bytes: 256
/*	ex7-1
	toshiwaka	*/

typedef struct point{
    int x_elem;
    int y_elem;
}point;

#include <stdio.h>

int main(void) {
  //point:正方形の頂点
  //diff:2点間のx,y軸方向の距離
  point point[4], diff;

  //入力
  scanf("%d %d %d %d", &point[0].x_elem, &point[0].y_elem, &point[1].x_elem, &point[1].y_elem);

  //2点間のx,y軸方向の距離
  diff.x_elem = point[1].x_elem - point[0].x_elem;
  diff.y_elem = point[1].y_elem - point[0].y_elem;

  //残りの２点を算出
  point[2].x_elem = point[1].x_elem - diff.y_elem;
  point[2].y_elem = point[1].y_elem + diff.x_elem;
  point[3].x_elem = point[0].x_elem - diff.y_elem;
  point[3].y_elem = point[0].y_elem + diff.x_elem;

  //出力
  printf("%d %d %d %d\n", point[2].x_elem, point[2].y_elem, point[3].x_elem, point[3].y_elem);

  return 0;
}


Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Judge judge = new Judge();

            List<string> ans = new List<string>();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n;  i++)
            {
                List<int> length = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                int max = length.Max();
                length.Remove(max);

                ans.Add(judge.Calc(max, length));
            }

            foreach (string item in ans)
            {
                Console.WriteLine(item);
            }
        }
    }

    class Judge
    {
        internal string Calc(int max, List<int> length)
        {
            string ans;

            double leftside = Math.Pow(max, 2);
            double rightside = Math.Pow(length[0], 2) + Math.Pow(length[1], 2);

            if (leftside == rightside)
            {
                ans = "YES";
            }
            else
            {
                ans = "NO";
            }

            return ans;
        }
        
    }
}



Measured memory_bytes: 16152
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005

int main()
{
    fio;
    int t,n,i;
    char c;
    cin >> c;
    if(c >= 'A' && c <= 'Z')
      cout << 'A';
    else
      cout << 'a';
}


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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// ***************************************

vector<set<int>> vec;
string S;

void query(int mode) {
	if (mode == 1) {
		int idx; char c;
		cin >> idx >> c;
		idx--;
		char c1 = S[idx];
		S[idx] = c;
		vec[c1 - 'a'].erase(idx);
		vec[c - 'a'].insert(idx);
	}
	else {
		int v1, v2;
		cin >> v1 >> v2;
		v1--;
		int ans = 0;
		REP(i, 26) {
			if (vec[i].empty()) continue;
			auto left = *vec[i].lower_bound(v1);
			auto right = *vec[i].lower_bound(v2);
			if (right - left <= 0) {
				continue;
			}
			ans++;
		}
		cout << ans << endl;
	}
	
}


int main()
{

	int N, Q;
	cin >> N >> S >> Q;
	
	vec.assign(26, set<int>({ 1<<30 }));
	REP(i, S.size()) {
		vec[S[i] - 'a'].insert(i);
	}


	int mode;
	REP(aaa, Q) {
		cin >> mode;
		query(mode);
	}
}

Measured memory_bytes: 24196
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define f first
#define sc second
using namespace std;
ll mod=1e9+7,i,j;
ll n,m,p[1000005];
vector<ll> nod[1000005];
vector<ll> poz;
vector<ll> val;
ll ans[1000005];
bool viz[1000005];
ll dfs(ll x){
    viz[x]=true;
    poz.pb(x);
    for(unsigned int i=0;i<nod[x].size();i++){
        ll vecin=nod[x][i];
        if(viz[vecin]==0) dfs(vecin);
    }

}
int main(){
    ll x,y,z;
    cin>>x>>y>>z;
    if((x+y+z)>=22) cout<<"bust";
    else cout<<"win";
    return 0;
}



Measured memory_bytes: 24832
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
    int x;cin>>x;
    cout<<(x^1)<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//**always check if you are not killing input in between
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//string2=string1.substr(pos,length);if len no specified then till end
//void fill (ForwardIterator first, ForwardIterator last, const T& val);
//The range filled is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.


//If wrong on pretest 2 means logically wrong
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct goods { ll w, v; };

int main() {
  ll N, W; cin >> N >> W;
  ll vm = N*1000;
  goods g[N]; rep(i,N) { ll w, v; cin >> w >> v; g[i] = {w,v}; }
  vector<vector<ll>> dp(N+1,vector<ll>(vm+1,LLINF)); dp[0][0] = 0;
  rep(i,N) rep(j,vm+1) {
    if (g[i].v>j) dp[i+1][j] = dp[i][j];
    else dp[i+1][j] = min(dp[i][j], dp[i][j-g[i].v]+g[i].w);
  }
  ll result = vm; while (dp[N][result]>W) result--;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 80256
import java.util.*;
import java.io.*;
import java.math.*;
 
 
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,-1,0,0};
    static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
 
    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 m=sc.nextInt();
        // char c[][] = new char[h][w];
        double s=0, base=(n-m)*100, b= 1<<m,d=(1-1/b),e=d;
        d = 1;
        for (int i=1; i<100000; i++ ) {
            s += (base+1900*i*m/b) * d;
            d*=e;
        }
       
        out.println((long)(s+0.5));
        out.flush();
    }
     
    static void db(Object... os){
     
        System.err.println(Arrays.deepToString(os));
     
    }
     
    static boolean validpos(int x,int y,int r, int c){
        
        return x<r && 0<=x && y<c && 0<=y;
        
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}
 
class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}
 
class P implements Comparable<P>{
    int x,y;
    P(int x, int y) {
        this.x=x;
        this.y=y;
    } 
      
    public int compareTo(P p){
        return -x + p.x;//des
    } 
}
 
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 long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

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

using namespace std;

const int N = 2e5 + 5;

ll l, r;
int len, S, T;
int ans[30][N], nxt[N];
char A[N];

ll cal(int a, ll now){
    if (now <= len) return ans[a][now];
    if (now <= 2 * len) return ans[a][len] + ans[a][now - len];
    ll f1 = ans[a][S], f2 = ans[a][len], lenf1 = S, lenf2 = len;
    while (now > lenf1 + lenf2) {
        ll tem = f2, lentem = lenf2;
        f2 += f1; lenf2 += lenf1;
        f1 = tem; lenf1 = lentem;
    }
    return f2 + cal(a, now - lenf2);
}

int main(){
    scanf("%s", A + 1);
    scanf("%lld%lld", &l, &r);
    len = strlen(A + 1) / 2;
    
    nxt[1] = 0;
    for (int i = 2; i <= len; i ++) {
        int j = nxt[i - 1];
        while(j != 0 && A[j + 1] != A[i]) j = nxt[j];

        if(A[j + 1] == A[i]) nxt[i] = j + 1; 
        else nxt[i] = 0;
    }
    T = nxt[len];
    S = len - T;
    
    for (int i = 1; i <= 26; i ++) {
        for (int j = 1; j <= len; j ++) {
            ans[i][j] = ans[i][j - 1];
            if ((int)A[j] - 96 == i) ans[i][j] ++;
        }
    }
    for (int i = 1; i <= 26; i ++)
        printf("%lld ", cal(i, r) - cal(i, l - 1));
    printf("\n");
    return 0;
}

Measured memory_bytes: 21632
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, k, a, b = 0, e;
	cin >> n >> k;
	for (int h = 1; h <= n; h++) {
		cin >> a;
	}
	n = n - k; b++;
	b += n / (k - 1);
	if (n % (k - 1) >= 1) {
		b++;
	}
	cout << b << endl;
	cin >> e;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;


int main(){
   ll n;cin >>n;
   map<ll,int>p;
    for (ll i = 1; i*i <= n ; ++i) {
        if(i*i==n)p[i]++;
        else if(n%i==0){
            p[i]++;
            p[n/i]++;
        }
    }
    ll ans=0;
    for(auto u:p){
        ll k=(n-u.first)/u.first;
        if(k>0) {
            if (n % k == n / k)ans += k;
        }
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;


void solve() {

    int N;
    cin >> N;

    list<int> v;

    REP(_,N) {
        string cmd;
        int val;
        cin >> cmd;

        if (cmd == "insert") {
            cin >>  val;
            v.push_front(val);
            continue;
        }

        if (cmd == "delete") {
            cin >>  val;
            auto itr = find(ALL(v),val);
            if(itr != v.end()) v.erase(itr);
            continue;
        }

        if (cmd == "deleteFirst") {
            v.pop_front();
            continue;
        }

        if (cmd == "deleteLast") {
            v.pop_back();
            continue;
        }

    }


    for(auto itr = v.begin(); itr != v.end(); itr++) {
        if(itr != v.begin()) {
            cout << ' ';
        }
        cout << *itr;
    }

    cout << endl;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 34360
#include <bits/stdc++.h>
#define int long long
const int MOD = 998244353;
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 3005, maxa = 3005;

int n, s, a[maxn], ways, cnt[maxa] = {0};
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> s;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = maxa - 1; j > a[i]; j--)
        {
            cnt[j] += cnt[j - a[i]];
            cnt[j] %= MOD;
        }
        cnt[a[i]] += (i + 1);   // counted by i + 1 Ls
        cnt[a[i]] %= MOD;
        ans += cnt[s];    
        ans %= MOD;
    }
    cout << (ans + MOD) % MOD << "\n";
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c, x int
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)
	fmt.Scanf("%d", &c)
	fmt.Scanf("%d", &x)
	count := 0
	for i:=0; i<=a; i++{
	  for j:=0; j<=b; j++ {
		for k:=0; k<=c; k++ {
		  if 500*i + 100*j + 50*k == x{
			count++
		  }
		}
	  }
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
n,m,k=map(int,input().split())
num=n*m
MOD = 10**9+7

def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
f_mod=[1]*(num+1)
f_mod_inverse=[1]*(num+1)
for i in range(1,num+1):
  f_mod[i]=f_mod[i-1]*i%MOD
  f_mod_inverse[i]=f_mod_inverse[i-1]*inv_mod(i)%MOD
N=0;M=0
for i in range(1,n):
  N+=i*(n-i)
  N%=MOD
for i in range(1,m):
  M+=i*(m-i)
  M%=MOD
print((N*(m**2)%MOD+M*(n**2)%MOD)*comb_mod(n*m-2,k-2)%MOD)

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

long long n,q,l,r;
string s;
char t[1000000],d[1000000];

int main(){

	cin>>n>>q>>s;
	
	for(int i=0;i<q;i++){
	    cin>>t[i]>>d[i];
    }
    
    l=-1;
    r=n;
    
    for(int i=q-1;i>=0;i--){
        
        if(d[i]=='L'){
            if(l+1<n && s[l+1]==t[i])l++;
        }
        else{
            if(l>=0 && s[l]==t[i])l--;
        }
        
    }
    
    
    for(int i=q-1;i>=0;i--){
        
        if(d[i]=='R'){
            if(r-1>=0 && s[r-1]==t[i])r--;
        }
        else{
            if(l<n && s[r]==t[i])r++;
        }
        
    }
    
    
    cout<<max(r-l-1ll,0ll)<<"\n";

return 0;
}


Measured memory_bytes: 1028
#include <iostream>

#define Yes(condition) cout << (condition ? "Yes" : "No") << endl

using namespace std;

int main() {
    int a, b;
    string s;
    bool flag = true;
    cin >> a >> b >> s;
    for (int i = 0; flag && i < a; ++i) flag &= (s.at(i) >= '0' && s.at(i) <= '9');
    flag &= (s.at(a) == '-');
    for (int i = a + 1; flag && i < a + b + 1; ++i) flag &= (s.at(i) >= '0' && s.at(i) <= '9');
    Yes(flag);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#define MOD 1000000007
typedef long long ll;

using namespace std;

ll euc(ll a, ll b) {
    ll temp;
    
    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;
    
    if( a % b == 0 ) return b;
    return euc( b, a % b );
}

ll abc(ll a) {
    ll ret = 0;
    ll tmp = 2;
    while(a >= tmp * tmp) {
        if(a % tmp == 0) {
            ret++;
            while(a % tmp == 0) {
                a /= tmp;
            }
        }
        else {
            tmp++;
        }
    }
    
    if(a != 1) {
        ret++;
    }
    
    return ret;
}

int main() {
    ll a, b;
    cin >> a >> b;
    
    ll max = euc(a, b);
    
    cout << abc(max) + 1 << endl;

    return 0;
}



Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long dp[101][1000000] = {};
int main() {
	int n, k;
	cin >> n >> k;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	vector<pair<long long, long long>> first_one,second_one;
	first_one.push_back(make_pair(sqrt(n), sqrt(n)));
	second_one.push_back(make_pair(sqrt(n) + 1, n / (int)sqrt(n)));
	for (int i = sqrt(n)-1; i >= 1; --i) {
		int geko = n / i;
		first_one.push_back(make_pair(i, i));
		second_one.push_back(make_pair(second_one[second_one.size() - 1].second + 1, geko));
	}
	reverse(first_one.begin(), first_one.end());
	vector<long long>  mul;
	REP(i, first_one.size()) {
		mul.push_back(1);
	}
	REP(i, second_one.size()) {
		mul.push_back(second_one[i].second - second_one[i].first + 1);
	}
	for (int i = 0; i < mul.size(); ++i) {
		dp[0][i] = mul[i];
	}
	k--;
	REP(i, k) {
		long long total_sum = 0;
		for (int q = 0; q < mul.size(); ++q) {
			total_sum += dp[i][q];
			total_sum %= MAX_MOD;
		}
		for (int q = 0; q < mul.size(); ++q) {
			long long addition = mul[q] * total_sum;
			addition %= MAX_MOD;
			dp[i + 1][q] += addition;
			dp[i + 1][q] %= MAX_MOD;
			total_sum += (MAX_MOD - dp[i][mul.size() - q - 1]);
			total_sum %= MAX_MOD;
		}
	}
	long long ans = 0;
	REP(i, mul.size()) {
		ans += dp[k][i];
		ans %= MAX_MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256372
#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
//	freopen("SNOOKER.inp","r",stdin);
//	freopen("SNOOKER.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
/*----------------------------------------------------------------------
2
3 4
2 4 2
3 3
3 3 3
-----------------------------------------------------------------------*/
using ll =  long long;
#define endl "\n"
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define what_is(x)  cerr << #x << " is :" << (x) << endl
#define what_are(x,y) cerr << #x <<" is : " << (x) <<" ; " << #y <<" is: " <<y << endl
#define pii pair<int,int>
#define fs first
#define sc second
const int MOD =  1e9+7;
const int inf = INT_MAX;
const int MAX_N = 1e3 + 7;

int n,m;
int a[MAX_N][MAX_N], dp[MAX_N][MAX_N];
void solve()
{
	cin >> n >> m;
	char c;
	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= m; j ++)
		{
			cin >> c;
			a[i][j] = (c == '.' ? 1: 0);
		}
	}
	dp[1][1] =a[1][1] ;
	
	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= m; j ++)
		{
			if(a[i][j]) dp[i][j] = max(dp[i][j] , dp[i-1][j]+dp[i][j-1] ) % MOD;
		}
	}
	cout << dp[n][m];
	
}


Measured memory_bytes: 8192
N, x = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
for i, a in enumerate(A):
    x -= a
    if x == 0:
        print(i+1)
        exit()
    elif x < 0:
        print(i)
        exit()
    elif i == len(A) - 1:
        print(i)
        exit()




Measured memory_bytes: 3060
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	class E{

		int i;

		int j;

		char x;

		E(int i,int j,char x){

			this.i = i;

			this.j = j;

			this.x = x;

		}

	}



	LinkedList<E> list = new LinkedList<Main.E>();

	

	void label(char map[][],E e){

		label(map,e.i,e.j,e.x);

	}

	

	void label(char map[][],int i,int j,char x){

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

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

		for(int a = 0 ; a < 4;a++){

			int ni = i + dx[a];

			int nj = j + dy[a];

			if(map[ni][nj] == x){

				map[ni][nj] = '_';

				list.add(new E(ni,nj,x));

			}

		}

	}

	

	void run() {

		for (;;) {

			int h = sc.nextInt();

			int w = sc.nextInt();

			if ((h | w) == 0)

				break;

			char map[][] = new char[h + 2][w + 2];

			

			for(int i =1; i < h+1;i++){

				String buffer = "_"+sc.next()+"_";

				map[i] = buffer.toCharArray();

			}

			for(int i = 0; i < w+2;i++){

				map[0][i]='_';

				map[h+1][i] = '_';

			}

			int num = 0;

			for(int i = 1; i < h+1;i++){

				for(int j= 1; j < w+1;j++){

					if(map[i][j] != '_'){

						char x = map[i][j];

						map[i][j]='_';

						label(map,i,j,x);

						num++;

					}

					for(;!list.isEmpty();){

						label(map,list.poll());

					}

				}

			}

			System.out.println(num);

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

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

  in(int, d, n);
  int cnt = 0;
  for (int i = 1;; ++i) {
    int j = i;
    int cnt2 = 0;
    while (j % 100 == 0) {
      j /= 100;
      ++cnt2;
    }
    if (cnt2 == d) ++cnt;
    if (cnt == n) {
      out(i);
      return 0;
    }
  }
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
long long int S[200010];
long long int U[200010];




int main(void){
    // Your code here!
    long long int N,H,W,A,B,K,i,j,k,ans,count,cost,tmp,first,pos;
    
    
    string T;
    bool flag;
    count=0;
    ans=0;
    flag=false;
    cin >>N;
    
    
    
    
    


    
   
       if (N>=30){ 
            cout<< "Yes" <<endl;
       }
        else{
            cout<< "No" <<endl;
        }
    

    
    

    return 0;
    
}



Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String kuuhaku = sc.nextLine();
        
        
        Map<String, Integer> map = new HashMap<>();
        
        for(int i = 0; i < N; i++) {
            String a = sc.nextLine();
            if(map.containsKey(a)) {
                map.replace(a, map.get(a)+1);
            }else {
                map.put(a, 0);
            }
        }
        
        int max = 0;
        
        for(int c1 : map.values()) {
            if(max < c1) {
                max = c1;
            }    
        }
        
        List<String> ans = new ArrayList<>();
        
        for(String c1 : map.keySet()) {
            if(map.get(c1) == max) {
                ans.add(c1);
            } 
        }
        
        Collections.sort(ans);
        for(String s : ans) {
            System.out.println(s);
        }
    }
}

Measured memory_bytes: 183032
using System;
using System.Collections.Generic;
using System.Linq;



class Program
{
 
    public static void Main( )
    {
        var input = Console.ReadLine( ).Split( ).Select( int.Parse ).ToArray( );
        var values = Console.ReadLine( ).Split( ).Select( int.Parse ).ToList( );

        var selected = values.OrderBy( x => x ).Take( input[ 1 ] ).ToList( );
        Console.WriteLine(selected.Sum());
       
        
    }

}




Measured memory_bytes: 28748
from math import gcd

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

def LI():
    return list(map(int, input().split()))

N, X = MI()
x = LI()
D = abs(X - x[0])

for i in range(1, N):
    D = gcd(D, abs(X - x[i]))
    
print(D)

Measured memory_bytes: 84952
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    unsigned long long count = 0;
    cin >> n;
    for(int i = (n - 1); i > 0; i--)
    {
        for(int j = 1; j < n; j++)
        {
            if((i * j) < n)
                count++;
            else
                break;
                
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long
#define yes return cout<<"Yes",0
#define no return cout<<"No",0
signed main(){
  int a,b;
  string s;
  cin>>a>>b>>s;
  for(int i=0;i<s.size();++i){
    if(a){
      if(s[i]=='-')no;
      --a;
      if(!a){
        if(s[i+1]=='-')++i;
        else no;
      }
    }
    else if(b){
      if(s[i]=='-')no;
      --b;
    }
  }
  yes;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int A[200000],n;

int binary_searcher(int key)
{
    int mid;
    int left=0;
    int right=n-1;
    while(left<right)
    {
        mid=(left+right)/2;
        if(A[mid]==key || A[left] == key || A[right]==key) return 1;
        else if(key<=A[mid]) right=mid;
        else left=mid+1;
    }
    return 0;
}

int main()
{
    int i,q,sum=0;
    int key;
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i];
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>key;
        if(binary_searcher(key))
	  	sum++;
    }
    cout<<sum<<endl;
    return 0;

}



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

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

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

	int sum = 0, pos = 0;
	for(int i = 0; i < n; i++){
		sum += abs(a[i]-pos);
		pos = a[i];
	}
	sum += abs(a[n-1]);

	for(int i = 0; i < n; i++){
		if(i == 0){
			int k = sum;
			k -= abs(a[i])+abs(a[i+1]-a[i]);
			k += abs(a[i+1]);
			cout << k << endl;
		} else if(i == n-1){
			int k = sum;
			k -= abs(a[i]-a[i-1])+abs(a[i]);
			k += abs(a[i-1]);
			cout << k << endl;
		} else {
			int k = sum;
			k -= abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
			k += abs(a[i+1]-a[i-1]);
			cout << k << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2172
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;

const int MAXN = 1e5+10;

bool prime[MAXN];
int cnt[MAXN];

int q;
int l[MAXN], r[MAXN];

void init() {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i=2;i<=sqrt(MAXN);i++) {
    if (prime[i]) {
      for (int j=i*2;j<=MAXN;j+=i) {
        prime[j] = false;
      }
    }
  }
}

void solve() {
  init();
  for (int i=1;i<MAXN;i++) {
    if (prime[i] && prime[(i+1) / 2]) {
      cnt[i] = cnt[i-1] + 1;
    } else {
      cnt[i] = cnt[i-1];
    }
  }

  for (int i=0;i<q;i++) {
    cout << (cnt[r[i]] - cnt[l[i] - 1]) << endl;
  }
}

int main() {
  cin >> q;
  for (int i=0;i<q;i++) {
    cin >> l[i] >> r[i];
  }
  solve();
}


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

int main() {
    string s, cmd, p;
    int n, a, b;

    cin >> s >> n;
    for (int i=0; i<n; i++) {
        cin >> cmd >> a >> b;
        if (cmd == "print") {
            cout << s.substr(a, b-a+1) << endl;
        }
        else if (cmd == "reverse") {
            for (int j=a; j<=(a+b)/2; j++) {
                char tmp = s[j];
                s[j] = s[a+b-j];
                s[a+b-j] = tmp;
            }
        }
        else {
            cin >> p;
            for (int j=a; j<=b; j++) {
                s[j] = p[j-a];
            }
        }
    }
}


Measured memory_bytes: 3168
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_c

# input
s = input()
# output
s0 = s[0::2]
s1 = s[1::2]
cost1 = s0.count('0') + s1.count('1')
cost2 = s0.count('1') + s1.count('0')
ans = min(cost1, cost2)
print(ans)



Measured memory_bytes: 3188
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var S = ReadLine().ToCharArray();
            var K = Sarray()[0];
            var rem = K;
            for (var i = 0; i < S.Length; ++i)
            {
                var dirA = ('z' - S[i] + 1) % 26;
                if (dirA <= rem)
                {
                    rem -= dirA;
                    S[i] = 'a';
                }
            }
            if (0 != rem)
                S[S.Length - 1] = (char)((S[S.Length - 1] - 'a' + rem) % 26 + 'a');
            WriteLine(S);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13792
// Library
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

// MACRO

#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
#define ABS(X) (((X) > 0)? (X) : -(X))
#define YN(X) ((X)? "YES" : "NO")
#define SWAP(T, X, Y) {T t; t = X; X = Y; Y = t;}

// Global Tables

// Functions

void TC(int t)
{
    int R;
    cin >> R;
    float C = 2*M_PI*R;
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(6);
    cout << C << endl;
}

// Main

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int T, t;
    T = 1;
    for(t = 1; t <= T; t++)
    {
        TC(t);
    }
    return 0;
}


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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int cards[1000];
  for (int i = 0; i < n; ++i) {
    cin >> cards[i];
  }
  int a = 0;
  int b = 0;
  sort(cards, cards+n);

  for (int i = 0; i < n; i+= 2) {
    a += cards[i];
    b += cards[i+1];
  }
  std::cout << abs( a-b ) << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N;
     cin >> N;
     vector<int> H(N);
     for(int i=0;i < N;i++){
          cin >> H[i];
     }

     int ans = 0;
     int x = 0;
     for(int i=0;i < N;i++){
          if(x <= H[i]) ans++;
          x = max(x,H[i]);
     }

     cout << ans << endl;
}

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


typedef long long i64;
const int inf = (int)1.05e9;

/* Dinic Algorithm for Maximum Flow */
/* generic case: O( E V^2 ) */
/* network with unit capacities: O( min{E V^(2/3), E^(3/2)} ) */
/* network with each vertex (except for s, t)
    having a single (entering or outgoing) edge of capacity 1: O( E sqrt(V) ) */

struct edge { int to, cap, rev; };
typedef vector<edge> vertex;
typedef vector<vertex> graph;

void add_edge(int from, int to, int cap, graph& g)
{
	int fwd = g[from].size();
	int rev = g[to].size();
	g[from].push_back({to, cap, rev});
	g[to].push_back({from, 0, fwd});
}

void compute_level(int s, vector<int>& level, graph& g)
{
	level.resize(g.size());
	fill(level.begin(), level.end(), -1);

	queue<int> q;
	level[s] = 0;
	q.push(s);

	while(!q.empty()) {

		const int v = q.front();
		q.pop();

		for(const auto& e : g[v]) {

			const int w = e.to;
			const int c = e.cap;

			if(c <= 0 || level[w] != -1)
				continue;
			level[w] = level[v] + 1;
			q.push(w);
		}
	}
}

int compute_flow_path(int v, int t, int f, vector<int>& iter, vector<int>& level, graph& g)
{
	if(v == t)
		return f;

	for(int& i = iter[v]; i < (int)g[v].size(); ++i) {

		auto& e = g[v][i];
		const int c = e.cap;
		const int w = e.to;

		if(c <= 0 || level[v] >= level[w])
			continue;

		const int d = compute_flow_path(w, t, min(f, c), iter, level, g);
		if(d <= 0)
			continue;
		e.cap -= d;
		g[w][e.rev].cap += d;
		return d;
	}

	return 0;
}

int max_flow(int s, int t, graph& g)
{
	int flow = 0;
	vector<int> level(g.size());
	vector<int> iter(g.size());

	while(true) {

		compute_level(s, level, g);
		if(level[t] == -1)
			break;
		fill(iter.begin(), iter.end(), 0);
		while(true) {
			const int f = compute_flow_path(s, t, inf, iter, level, g);
			flow += f;
			if(f <= 0)
				break;
		}
	}

	return flow;
}


int main()
{
	int n;
	vector<pair<int,int>> reds, blues;

	scanf("%d", &n);
	reds.resize(n);
	blues.resize(n);
	for(int i = 0; i < n; ++i)
		scanf("%d%d", &reds[i].first, &reds[i].second);
	for(int i = 0; i < n; ++i)
		scanf("%d%d", &blues[i].first, &blues[i].second);

	graph g;
	const int s = 2 * n + 0;
	const int t = 2 * n + 1;

	g.resize(2 * n + 2);

	for(int i = 0; i < n; ++i)
		add_edge(s, i, 1, g);
	for(int i = 0; i < n; ++i)
		add_edge(n + i, t, 1, g);

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(reds[i].first < blues[j].first && reds[i].second < blues[j].second)
				add_edge(i, n + j, 1, g);
		}
	}

	int ans = max_flow(s, t, g);

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

	return 0;
}

/* waffle */


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int L = sc.nextInt();
		Node[] nodes = new Node[N + 2];
		for (int i = 0; i < N; ++i) {
			nodes[i + 1] = new Node(L - sc.nextInt());
			nodes[i + 1].ord = i + 1;
		}
		nodes[0] = nodes[N + 1] = new Node(0);
		Node root = new Node(0);
		root.ord = -1;
		for (int i = 1; i <= N; ++i) {
			boolean left = nodes[i - 1].v > nodes[i].v;
			if (left) {
				nodes[i - 1].child.add(nodes[i]);
			}
			boolean right = nodes[i + 1].v > nodes[i].v;
			if (right) {
				nodes[i + 1].child.add(nodes[i]);
			}
			if (!left && !right) {
				root.child.add(nodes[i]);
			}
		}
		Stack<Frame> stack = new Stack<Frame>();
		stack.push(new Frame(root, 0, 0));
		long ret = 0;
		while (!stack.isEmpty()) {
			Frame f = stack.pop();
			if (f.i != 0) {
				f.t = Math.max(f.t, ret);
			}
//			System.out.println(f.n.ord + " " + f.i + " " + f.t);
			if (f.i == f.n.child.size()) {
				ret = f.t + f.n.v;
				continue;
			}
			stack.add(new Frame(f.n, f.i + 1, f.t));
			stack.add(new Frame(f.n.child.get(f.i), 0, 0));
		}
		System.out.println(ret);
	}

	static class Frame {
		Node n;
		int i;
		long t = 0;

		Frame(Node n, int i, long t) {
			this.n = n;
			this.i = i;
			this.t = t;
		}
	}

	static class Node {
		int ord;
		long v;
		ArrayList<Node> child = new ArrayList<Node>();

		Node(int v) {
			this.v = v;
		}

	}

}

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

int count_mines(vector<vector<char>> pixels, int pi, int pj, int  h, int w){
    int n_mines = 0;
    for(int i=pi-1; i<=pi+1; i++){
        for(int j=pj-1; j<=pj+1; j++){
            if(i<0 || j<0 || i==h || j==w) continue;
            if(pixels.at(i).at(j) == '#') n_mines++;
        }
    }

    return n_mines;
}

int main(){
    char buf[51];
    
    int h;
    cin >> h;

    int w;
    cin >> w;

    vector<vector<char>> pixels(h, vector<char>(w));
    
    for(int i=0; i<h; i++){
        cin >> buf;
        for(int j=0; j<w; j++){
            pixels.at(i).at(j) = buf[j];
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(pixels.at(i).at(j) == '.'){
                cout << count_mines(pixels, i, j, h, w);
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

def a(i):
    if 0 <= i < N:
        return A[i]
    else:
        return 0

base = 0
for i in range(N + 1):
    base += abs(a(i) - a(i - 1))

for i in range(N):
    print(base - abs(a(i) - a(i - 1)) - abs(a(i + 1) - a(i)) + abs(a(i + 1) - a(i - 1)))

Measured memory_bytes: 14048
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  string s;
  int cnt=0;
  cin>>s;
  rep(i,1,s.size()){
    if(s[i-1]!=s[i])cnt++;
  }
  cout<<cnt<<endl;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        int a, b;
        a = x[i] * 2;
        b = (k - x[i]) * 2;
        ans += min(a, b);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3512
# SPDX-License-Identifier: X11
# 2020-09-23
# : (Colon) (300pt)

lawofcosines(a, b, θ) = sqrt(a * a + b * b - 2a * b * cos(θ))
angleofhour(h,m) = π * (60h + m) / (6 * 60)
angleofminute(m) = 2π * m / 60

A, B, H, M = parse.(Int, split(readline()))

theta = abs(angleofminute(M) - angleofhour(H,M))
println(lawofcosines(A, B, theta))


Measured memory_bytes: 212360
def divs(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n,p = map(int, input().split())
if n>100:
  print(1)
  exit()

ans=1
for d in divs(p):
  if pow(d,n)>p:
    break
  if p % pow(d,n)==0:
    ans=d
print(ans)

Measured memory_bytes: 38640