akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n;
	cin >> n;
	vector <int> a(n);
	vector <int> hash((int)1e6 + 1,0);
	for(int i = 0;i < n;++i){
		cin >> a[i]; 
		++hash[a[i]];
	}
	if(hash[1] == 1){
		cout << 1 << newl;
		return;
	}
	else if(hash[1] > 1){
		cout << 0 << newl;
		return;
	}
	sort(a.begin(),a.end());
	vector <bool> marked((int)1e6 + 1,0);
	for(int i = 0;i < n;++i){
		if(i > 0 and a[i] == a[i - 1]) continue;
		for(int j = 2;j * a[i] <= (int)1e6;++j) marked[j * a[i]] = 1;
	}
	int count = 0;
	for(int i = 0;i < n;++i){
		if(hash[a[i]] > 1) continue;
		++count;
		if(marked[a[i]]) --count;
	}
	cout << count << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 8168
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> stones(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> stones[i];
    }

    int ans = 0;
    for(int i = 0; i <= n; ++i)
    {
        for(int j = 0; j <= n - i; ++j)
        {
            if(i + j > k
            || i + j > n)
            {
                break;
            }
            vector<int> drop;
            int score = 0;
            for(int t = 0; t < i; ++t)
            {
                int num = stones[t];
                score += num;
                if(num < 0)
                {
                    drop.push_back(num);
                }
            }
            for(int t = n-1; t > n-1-j; --t)
            {
                int num = stones[t];
                score += num;
                if(num < 0)
                {
                    drop.push_back(num);
                }
            }
            sort(drop.begin(),drop.end());
            int count = min((int)drop.size(), k-i-j);
            for(int t = 0; t < count; ++t)
            {
                score -= drop[t];
            }
            ans = max(ans, score);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int W, H;
  while(cin>>W>>H && W){
    int N;
    cin>>N;
    int x1[1000], y1[1000], x2[1000], y2[1000];
    vector<int> ax, ay;
    REP(i, N) cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
    REP(i, N) ax.push_back(x1[i]);
    REP(i, N) ax.push_back(x2[i]);
    REP(i, N) ay.push_back(y1[i]);
    REP(i, N) ay.push_back(y2[i]);
    ax.push_back(0); ax.push_back(W);
    ay.push_back(0); ay.push_back(H);
    sort(ax.begin(), ax.end());
    sort(ay.begin(), ay.end());
    ax.erase(unique(ax.begin(), ax.end()), ax.end());
    ay.erase(unique(ay.begin(), ay.end()), ay.end());
    bool block[2002][2002] = {};
    REP(i, ay.size() - 1){
      REP(j, ax.size() - 1){
        int bx = ax[j], ex = ax[j + 1];
        int by = ay[i], ey = ay[i + 1];
        REP(k, N){
          if(x1[k] <= bx && ex <= x2[k] && y1[k] <= by && ey <= y2[k]){
            block[i][j] = true;
            break;
          }
        }
      }
    }
    bool used[2002][2002] = {};
    int ans = 0;
    REP(i, ay.size() - 1){
      REP(j, ax.size() - 1){
        if(!block[i][j] && !used[i][j]){
          ans++;
          queue<int> qx, qy;
          qx.push(j); qy.push(i);
          used[i][j] = true;
          while(!qx.empty()){
            int x = qx.front(), y = qy.front();
            qx.pop(); qy.pop();
            REP(r, 4){
              int nx = x + dx[r];
              int ny = y + dy[r];
              if(valid(nx, ny, ax.size() - 1, ay.size() - 1) && !block[ny][nx] && !used[ny][nx]){
                used[ny][nx] = true;
                qx.push(nx);
                qy.push(ny);
              }
            }
          }
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 9084
#include <stdio.h>

int max_index(int data[]){
	if (data[0] < data[1]){
		if (data[1] < data[2]){
			return 2;
		}else{
			return 1;
		}
	}else{
		if (data[0] < data[2]){
			return 2;
		}else{
			return 0;
		}
	}
}

int ind(int i){
	if (i < 0){
		return 2;
	}else if (i > 2){
		return 0;
	}else{
		return i;
	}
}

int main(){
	int data[3];
	scanf("%d%d%d", &data[0], &data[1], &data[2]);
	int i = max_index(data);
	if (data[ind(i)] == data[ind(i+1)] + data[ind(i-1)]){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (i == 0) {
				x = a;
			} else {
				x = gcd(x, a);
			}
			if (x == 1) {
				break;
			}
		}
		System.out.println(x);
	}
	
	static int gcd(int a, int b) {
		if (a % b == 0) {
			return b;
		} else {
			return gcd(b, a % b);
		}
	}
}


Measured memory_bytes: 50104
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define put puts("")
#define print(x) cout << x << endl
#define print2(x,y) cout << x << " " << y << endl
#define print3(x,y,z) cout << x << " " << y << " " << z << endl
int n,m;
int a,b,c;
int ans;
int d[10000],p[10000];
int dp[10000][10000];

int main(){
  cin >> n >> m;
  print((n-1)*(m-1));
  return 0;
}


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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        m: usize,
        es: [(usize1, usize1); m],
    }

    let mut lo = 0;
    let mut hi = n;

    for (l, r) in es {
        lo = max(lo, l);
        hi = min(hi, r + 1);
    }

    // dbg!((lo, hi));

    println!("{}", max(0, hi as i64 - lo as i64));
}


Measured memory_bytes: 6396
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    ll n;
    int i,j;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n,0);
    rep(i,n){
        cin>>a[i];
        b[a[i]-1]++;
    }
    ll ans=0;
    rep(i,n){
        ans+=b[i]*(b[i]-1)/2;
    }
    rep(i,n){
        cout<<ans-b[a[i]-1]+1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    char str[4]={0};
    scanf("%s", str);

    sort(str+0, str+3);
    if(strcmp(str,"abc")==0) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int h[N];
  for(int i=1;i<N+1;i++){
    cin>>h[i];
  }
  int ans=0;
  for(int i=1;i<N;i++){
    if(h[i]>h[i+1]){
      ans+=h[i]-h[i+1];
    }
  }
  ans+=h[N];
  cout<<ans<<endl;
}


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

int main(){
    char ch;
    int cnt[26]={};
    
    while(cin>>ch){
        ch=tolower(ch);
        if (isalpha(ch)){
            cnt[ch-'a']++;
            
        }
    }
    
    for(int i=0;i<26;i++){
        printf("%c : %d\n",i+'a',cnt[i]);
        
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0,m;
  cin >> n;
  vector<long long> v[n];
  for(int i=0;i<n;i++){
    cin >> m;
    for(int j=0;j<m;j++){
      long long a;
      cin >> a;
      v[i].push_back(a);
    }
  }
  priority_queue<long long> que;
  for(int i=n-1;i>=0;i--){
    for(int j=0;j<v[i].size();j++){
      que.push(v[i][j]);
    }
    ans+=que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19504
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        ab: [(u64, u64); n]
    }

    let mut fc = ab .iter()
        .map(|&(a, b)| (b, a))
        .collect::<Vec<_>>();
    fc.sort();
    let mut is_ok = true;
    let mut time = 0;
    for (f,cost) in fc {
        if time + cost <= f {
            time += cost;
        } else {
            is_ok = false;
            break;
        }
    }
    println!("{}", if is_ok {"Yes"} else {"No"});
}

Measured memory_bytes: 14588
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
flag=0
for i in range(N-M+1):
	for j in range(N-M+1):
		for k in range(M):
			if A[i+k][j:j+M]!=B[k]:
				break
		else:
			flag=1
print('Yes' if flag else 'No')


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

typedef long long ll;

int main(void){
    ll N;
    cin>>N;
    
    ll f=0,t=0;
    for(int i=0;i<N;i++){
        ll a;
        cin>>a;
        
        if(a%4==0){
            f++;
        }else if(a%2==0){
            t++;
        }
    }
    
    N-=f*2;
    if(t>1){
        N-=t;
    }else{
        N--;
    }
    
    if(N<=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static int n, m, x;
	public static int[] c;
	public static int[][] a;
	public static boolean[] b;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		x = sc.nextInt();
		c = new int[n];
		a = new int[n][m];
		for(int i = 0; i < n; i++){
			c[i] = sc.nextInt();
			for(int j = 0; j < m; j++){
				a[i][j] = sc.nextInt();
			}
		}
		b = new boolean[n];
		int min = search(0);
		if(min == Integer.MAX_VALUE){
			System.out.println(-1);
		} else {
			System.out.println(min);
		}
	}
	public static int search(int idx){
		if(idx == n){
			return calc();
		}
		int ret = Integer.MAX_VALUE;
		b[idx] = true;
		ret = Math.min(ret, search(idx+1));
		b[idx] = false;
		ret = Math.min(ret, search(idx+1));
		return ret;
	}
	public static int calc(){
		int ret = 0;
		int[] sum = new int[m];
		for(int i = 0; i < n; i++){
			if(!b[i])continue;
			ret += c[i];
			for(int j = 0; j < m; j++){
				sum[j] += a[i][j];
			}
		}
		for(int i = 0; i < m; i++){
			if(sum[i] < x)return Integer.MAX_VALUE;
		}
		return ret;
	}
}

Measured memory_bytes: 38428
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int key = sc.nextInt();
    int num = sc.nextInt();
    if(num > 0){
      int map[] = new int[102];
      for(int i = 0;i < 102;i++){
        map[i] = 0;
      }
      for(int i = 0;i < num;i++){
        int n = sc.nextInt();
        map[n] = n;
      }
      int plus = key;
      int minus = key;
      while(map[plus] != 0 && map[minus] != 0){
        plus++;
        minus--;
        if(map[plus] == 0 && map[minus] == 0){
            break;
        }
        else if(map[plus] == 0){
            minus--;
        }
        else if(map[minus] == 0){
            plus++;
        }
        
      }
      if(key - minus <= plus - key){
        System.out.println(minus);
      }
      else{
        System.out.println(plus);
      }
    }
    else{
      System.out.println(key);
    }
  }
}

Measured memory_bytes: 35400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,i;
	cin>>n;
	string s;
	map<string, ll> mp;
	ll mx = 0;
	for(i=0;i<n;i++)
	{
	    cin>>s;
	    mp[s]++;
	    mx = max(mx, mp[s]);
	}
	vector<string> ans;
	for(auto k:mp)
	{
	    if(k.second == mx) ans.pb(k.first);
	}
	sort(all(ans));
	for(auto s:ans) cout<<s<<"\n";
}

Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


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

  int a,b;
  vector<pair<int,int> > red;
  rep(i,n){
    cin >> a >> b;
    red.push_back(make_pair(a,b));
  }
  vector<pair<int,int> > blue;
  rep(i,n){
    cin >> a >> b;
    blue.push_back(make_pair(a,b));
  }
  sort(all(red));
  sort(all(blue));

  int ans = 0;
  int redIndex = 0, blueIndex = 0;
  vector<int> redY;
  while(blueIndex < n){
    if(redIndex < n && red[redIndex].first < blue[blueIndex].first){
      redY.push_back(red[redIndex].second);
      redIndex ++;
    }else{
      sort(all(redY),greater<int>());
      rep(i,redY.size()){
        if(redY[i] < blue[blueIndex].second){
          ans++;
          //cout << blue[blueIndex].first << ' ' << blue[blueIndex].second << ' ' << redY[i] << endl;
          redY[i] = 2000;
          break;

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


Measured memory_bytes: 256
s = list(input())

tmp = [0] * 10
num = 0
for i in range(len(s)):
    if s[i] == "0":
        tmp[num] = "0"
        num += 1
    elif s[i] == "1":
        tmp[num] = "1"
        num += 1
    else:
        num = max(0, num-1)

for i in range(num):
    print(tmp[i],end="")
print()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define INF 1e18

int H, W, K, src_h, src_w, dst_h, dst_w;

ll get_id(ll h, ll w, ll d) {
    return ((ll)h * W + w) * 4 + d;
}

int main() {
    cin >> H >> W >> K >> src_h >> src_w >> dst_h >> dst_w;
    src_h--; src_w--; dst_h--; dst_w--;
    ll cost[H][W][4];
    REP(i, H) {
        string s;
        cin >> s;
        REP(j, W) {
            ll c = s[j] == '.' ? INF : -1;
            REP(k, 4) cost[i][j][k] = c;
        }
    }

    priority_queue<pll, vector<pll>, greater<pll>> que;
    REP(i, 4) {
        cost[src_h][src_w][i] = 0;
        que.push({0, get_id(src_h, src_w, i)});
    }

    int dh[4] = {1, 0, -1, 0}, dw[4] = {0, 1, 0, -1};
    while (!que.empty()) {
        pll p = que.top(); que.pop();
        ll c = p.first, h = p.second / (4 * W), w = p.second / 4 % W, d = p.second % 4;
        if (c > cost[h][w][d]) continue;

        REP(i, 4) {
            if (i == d) continue;
            ll nc = (c + K - 1) / K * K;
            if (nc < cost[h][w][i]) {
                que.push({nc, get_id(h, w, i)});
                cost[h][w][i] = nc;
            }
        }

        ll nh = h + dh[d], nw = w + dw[d];
        if (0 <= nh && nh < H && 0 <= nw && nw < W) {
            if (c + 1 < cost[nh][nw][d]) {
                que.push({c + 1, get_id(nh, nw, d)});
                cost[nh][nw][d] = c + 1;
            }
        }
    }

    if (cost[dst_h][dst_w][0] == INF) {
        cout << -1 << endl;
    } else {
        ll c = INF;
        REP(i, 4) c = min(c, cost[dst_h][dst_w][i]);
        cout << (c + K - 1) / K << endl;
    }
    return 0;
}

Measured memory_bytes: 42820
import copy
N,M = map(int, input().split())
isFirst = True
like_list_all = []

for i in range(N):
    like_list = input().split()
    del like_list[0]
    if isFirst:
        like_list_all = copy.copy(like_list)
        isFirst = False
        continue
    like_list_all = list(set(like_list_all) & set(like_list))

print(len(like_list_all))

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

int main() {
  int n;
  cin >> n;
  int count;
  if(n == 100000) {
    count = 9 + 900 + 90000;
  } else if(n >= 10000) {
    count = 9 + 900 + (n - 9999);
  } else if(n >= 1000) {
    count = 9 + 900;
  } else if(n >= 100) {
    count = 9 + (n - 99);
  } else if(n >= 10) {
    count = 9;
  } else {
    count = n;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
sr = input()

a, b, c, d = int(sr[0]), int(sr[1]), int(sr[2]), int(sr[3])

def calc(one, two, three):
  if a + one*b + two*c + three*d == 7:
    return True
  else:
    return False
  
def change(num):
  if num == 1:
    return "+"
  else:
    return "-"
  
flag = False
for q in [1, -1]:
  for w in [1, -1]:
    for e in [1, -1]:
      if calc(q, w, e):
        r, t, y = change(q), change(w), change(e)
        print(str(a)+r+str(b)+t+str(c)+y+str(d)+"=7")
        flag = True
        break
    if flag:
      break
  if flag:
    break


Measured memory_bytes: 3064
sd = input()
t = input()
sf = ""
for i in sd:
  if i == "?":
    sf += "a"
  else:
    sf += i
S = []
for i in range(len(sd)-len(t)+1):
  b = True
  for j in range(len(t)):
    if sd[i+j] != t[j] and sd[i+j] != "?":
      b = False
  if b:
    s = sf[:i] + t + sf[i+len(t):]
    S.append(s)
if S == []:
  print("UNRESTORABLE")
else:
  print(sorted(S)[0])

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
long long int a,b,i,d,e,f;
long long int c=0;
  scanf("%lld %lld",&a,&b);
f=10*10*10*10*10*10*10*10*10+7;
for(i=b;i<a+2;++i)
  {d=(i-1)*i/2;
   e=i*(2*a+1-i)/2;
   c=c+e-d+1;
  }
printf("%lld",c%f);
return 0;
}

Measured memory_bytes: 1736
N,M = map(int,input().split())
H = list(map(int,input().split()))
H.insert(0,0)
S = set()

for m in range(M):
  A,B = map(int,input().split())
  if H[A]<=H[B]:
    S.add(A)
  if H[A]>=H[B]:
    S.add(B)

print(N-len(S))

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

string s;
int main(){
  cin>>s;
  int At=s.size();
  int Zt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      At=min(i,At);
    }
    if(s[i]=='Z'){
      Zt=i;
    }
  }

  cout<<Zt-At+1<<endl;


}


Measured memory_bytes: 640
def query(l,r,c)
  h = (l + r) / 2
  if c == K
    if (h - T).abs <= E then return 1.0
    else return 0.0
    end
  end
  return 0.0 if T - E > r  || l > T + E
  return 1.0 if T - E <= l && r <= T + E

  if h <= T
    return P * query(l, h, c + 1) + (1 - P) * query(h, r, c + 1)
  else
    return (1 - P) * query(l, h, c + 1) + P * query(h, r, c + 1)
  end
end

K,r,l = gets.split.map(&:to_i)
P,E,T = 3.times.map{ gets.to_f }
puts "%.15f" % query(r.to_f, l, 0)

Measured memory_bytes: 8756
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector<pair<int, int>> A;

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

    int N;
    cin >> N;
    A.resize(N, pair<int, int>(0, 0));
    int a;
    rep (i, N)
    {
        cin >> a;
        A[i] = pair<int, int>(a, i + 1);
    }

    auto cmp = [](pair<int, int>& x, pair<int, int>& y) { return x.first < y.first; };
    sort(A.begin(), A.end(), cmp);

    rep (i, N)
    {
        cout << A[i].second << " ";
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

const int INF = (int)1e9;
typedef pair<int, int> P;
struct Edge {
    int to, cost;
    Edge(int t, int c) : to(t), cost(c) { }
};

int dijkstra(const vector<vector<Edge> > &edges, const int from, const int to) {
    vector<int> dist(edges.size(), INF);
    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push(P(1, from));
    dist[from] = 1;
    while(!Q.empty()) {
        P p = Q.top(); Q.pop();
        int v = p.second;
        int d = p.first;
        if(v == to) break;
        if(d > dist[v]) continue;
        for(int i = 0; i < (int)edges[v].size(); i++) {
            Edge e = edges[v][i];
            int c = dist[v] + e.cost;
            if(dist[e.to] > c) {
                dist[e.to] = c;
                Q.push(P(c, e.to));
            }
        }
    }
    return dist[to];
}

int main() {
    int n; cin >> n;
    vector<vector<Edge> > edges(n + 1);
    for(int i = 0; i < n; i++) {
        int r, k; cin >> r >> k;
        for(int j = 0; j < k; j++) {
            int t; cin >> t;
            edges[r].push_back(Edge(t, 1));
        }
    }
    int p; cin >> p;
    for(int i = 0; i < p; i++) {
        int from, to, ttl;
        cin >> from >> to >> ttl;
        int d = dijkstra(edges, from, to);
        if(d > ttl) {
            cout << "NA" << endl;
        }
        else {
            cout << d << endl;
        }
    }
}

Measured memory_bytes: 1204
dict = {}

n = int(input())

for i in range(n):
	s = input()
	try:
		dict[s] += 1
	except:
		dict[s] = 1

m = int(input())

for i in range(m):
	s = input()
	try:
		dict[s] -= 1
	except:
		dict[s] = -1

ans = sorted(dict.items(), key=lambda x: -x[1])

if ans[0][1] < 0:
	print(0)
else:
	print(ans[0][1])

Measured memory_bytes: 38512
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans,j=0,m
for i in range(n+1):
  if a[i]>k:
    break
  while b[j]>k-a[i]:
    j-=1
  ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 134160
// --------------
// Tejas Pandey  |
// 28 - 03 - 20  |
// Atcoder BC 160|
// --------------

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

#define mod 998244353
#define vi vector<int>
typedef long long int ll;

int main (void)
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll x;
  cin >> x;
  ll ans = 0;
  ans += 1000*(x/500);
  x -= 500*(x/500);
  ans += 5*(x/5);
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll int64_t
#define pb push_back

using namespace std;

int main()
{
    int n;
    cin>>n;
    int t[n+1],x[n+1],y[n+1];
    t[0]=x[0]=y[0]=0;
    bool flag=true;
    for(int i=1;i<=n;i++){
        cin>>t[i]>>x[i]>>y[i];
        int time_remaining = (t[i] - t [i-1]) - (abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]));
        if(time_remaining < 0 || (time_remaining&1))
            flag=false;
    }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main() {
	char str[200 + 1] = "";

	while (1) {
		scanf("%s", str);
		if (strcmp(str, "-") == 0) { break; }

		int m = 0;
		int h = 0;
		scanf("%d", &m);

		char temp1[200 + 1] = "";
		char temp2[200 + 1] = "";
		for (int i = 0; i < m; i++) {
			scanf("%d", &h);
			strncpy(temp1, str, h);
			temp1[h] = '\0';

			strncpy(temp2, &str[h], strlen(str) - h);
			temp2[strlen(str) - h] = '\0';

			sprintf(str, "%s%s", temp2, temp1);
		}

		printf("%s\n", str);
	}

	return 0;
}

Measured memory_bytes: 1804
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int a[maxn],n;ll sum[maxn];
ll cal(int m){
	ll cnt = 0;
	for(int i=1;i<=n;i++){
		int k = lower_bound(a+1,a+1+n,m-a[i])-a;
//		cout<<i<<": "<<k<<endl; 
		cnt += n-k+1;
	}
//	cout<<"->"<<m<<" "<<cnt<<endl;
	return cnt;
}
int main()
{
	cin>>n;
	ll  m;cin>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int l = 0,r = 200001;
	while(l!=r){
		int mid = (l+r)>>1;
		if(cal(mid)>m)l = mid+1;
		else r = mid;
	}
//	cout<<"!!!!!!!!!!"<<l<<endl;
	ll ans = 0,cnt = 0;
	for(int i=n;i;i--)sum[i] = sum[i+1] + a[i];
	for(int i=1;i<=n;i++){
		int k = lower_bound(a+1,a+1+n,l-a[i])-a;
//		cout<<i<<": "<<k<<endl;
		ans += 1LL*(n-k+1)*a[i]+sum[k];
		cnt += n-k+1;
	}
	ans += 1LL*(m-cnt)*(l-1);
	cout << ans << endl;
	return 0;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
vector<ll> A;
string S;

signed main(){
    cin >> S;
    A.resize(26,0);
    for(int i=0;i<S.size();i++) {
        ll abc = S[i]-'a';
        A[abc]++;
    }
    for(int i=0;i<26;i++) {
        ans += A[i]*(S.size()-A[i]);
    }
    ans /= 2;
    cout << ans+1 << endl;
    return 0;
}

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

lli n;

int main(void){
	cin >> n;
	lli x = 0;
	vector<lli> a(n);
	rep(i, n) cin >> a[i];
	lli l = 0, r = n-1;
	while(l <= r){
		if(x <= 0){
			x += a[l];
			l++;
		}else{
			x -= a[r];
			r--;
		}
	}
	cout << abs(x) << endl;
	return 0;
}


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

int main() {
    long k, ans = 0;
    cin >> k;
    queue<long> que, tmp;
    rep(i, 9) {
        que.push(i + 1);
        tmp.push(i + 1);
    }
    while(que.size() <= k) {
        long temp = tmp.front();
        tmp.pop();
        if(temp % 10) {
            que.push(temp * 10 + temp % 10 - 1);
            tmp.push(temp * 10 + temp % 10 - 1);
        }
        que.push(temp * 10 + temp % 10);
        tmp.push(temp * 10 + temp % 10);
        if(temp % 10 - 9) {
            que.push(temp * 10 + temp % 10 + 1);
            tmp.push(temp * 10 + temp % 10 + 1);
        }
    }
    long cnt = 0;
    while(que.size()) {
        cnt++;
        if(cnt == k) {
            ans = que.front();
            break;
        }
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
int main(){
    uint N, M;cin>>N>>M;
    vector<int64> X(N),Y(N),Z(N);
    for(uint i=0;i<N;++i){cin>>X[i]>>Y[i]>>Z[i];}
    int64 m=0;
    vector<int64> v(N);
    for(uint i=0; i<8; ++i){
        int x=(i&0b001)?1:-1;
        int y=(i&0b010)?1:-1;
        int z=(i&0b100)?1:-1;
        for(uint i=0; i<N; ++i){v[i]=x*X[i]+y*Y[i]+z*Z[i];}
        sort(v.begin(),v.end(),greater<int64>());
        int64 s=accumulate(&v[0],&v[0]+M,0ll);
        m=max(m,s);
    }
    cout<<m<<endl;
    return 0;
}

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

int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  int C;
  int D;
  D = 0;
  for(int i = 0;i < A;i++){
    cin >> C;
    if(B <= C){
      D = D + 1;
    }
  }
  cout << D << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll deg[100];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

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

    F0R(i,M) {
        int u,v; cin >> u >> v;
        --u; --v;
        deg[u]++; deg[v]++;
    }

    F0R(i,N) {
        cout << deg[i] << "\n";
    }


}




Measured memory_bytes: 256
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

from math import atan2

pts = []
for x, y in xy:
    if x == 0 and y == 0:
        continue
    else:
        pts.append((atan2(y, x), x, y))

pts.sort()

cum_xy = [(0, 0)]
for a, x, y in pts:
    pv_x, pv_y = cum_xy[-1]
    cum_xy.append((pv_x + x, pv_y + y))

ans2 = 0

for i in range(len(cum_xy)):
    for j in range(i, len(cum_xy)):
        length = (cum_xy[j][0] - cum_xy[i][0]) ** 2 + (cum_xy[j][1] - cum_xy[i][1]) ** 2
        if length > ans2:
            ans2 = length

        length = (cum_xy[j][0] - cum_xy[i][0] - cum_xy[-1][0]) ** 2 + (
            cum_xy[j][1] - cum_xy[i][1] - cum_xy[-1][1]
        ) ** 2
        if length > ans2:
            ans2 = length

print(ans2 ** 0.5)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1000;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }

    sort(a,a+n,greater<int>());
    LL ans = 0;
    int n1 = n - 1;

    loop(i,0,n)
    {
        if(n1 == 0) break;
        ans += a[i]; --n1;
        if(i && n1) {ans += a[i]; --n1;}
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 4428
#include <iostream>
#include <algorithm>
using namespace std;
int C[26];

int main(){
    int N,K;
    cin>>N>>K;
    for(int i=0;i<N;i++){
        string P;
        cin>>P;
        C[P[0]-'A']++;
    }
    sort(C,C+26,greater<int>());
    int ans=0;
    while(true){
        int k=0;
        for(int i=0;i<26;i++){
            if(C[i]){
                k++;C[i]--;
            }
            if(k==K){
                ans++;
                break;
            }
        }
        sort(C,C+26,greater<int>());
        if(k!=K) break;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	vector<int>v; int n, p;
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> p; v.push_back(p); }
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> p; v.push_back(p); }
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++) {
		if (i + 1 < v.size() && v[i] == v[i + 1])i++;
		else cout << v[i] << endl;
	}
}


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
#define fastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define stk             stack<ll>
#define que             queue<ll>
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define rev             reverse
#define Y               "YES"
#define N               "NO"
#define br              "\n"
#define sp              " "
#define debug(x)        cout << #x << " : " << x << endl;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ll inf = 1e18;
const ll MAX = 2e5 + 1;


// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

inline ll add(ll a, ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a, ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a, ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x, ll n) {
	x = x % mod;
	if (!n) return 1;
	if (n & 1) return mul(x, pwr(mul(x, x), (n - 1) / 2));
	else return pwr(mul(x, x), n / 2);
}
// O(nlogn) for [1,n]
ll modinv(ll n) {
	return pwr(n, mod - 2);
}
// O(logn) for[1,n]
ll inv(ll i) {
	if (i == 1) return 1;
	return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;
}
// =============================

const int INF = 1e9 + 5;
vector<ll> w, profit;
int n, W;
ll dp[105][100005];
ll ans;
ll f(int W, int index)
{

	//cout << W << endl;
	if ((index == n + 1))
		return 0;

	if (dp[index][W] != -1)
		return dp[index][W];

	if ((W - w[index] ) >= 0)
		ans = max(profit[index] + f(W - w[index], index + 1), f(W, index + 1));
	else
		ans = f(W, index + 1);

	return dp[index][W] = ans;


}

void solve()
{


	cin >> n >> W;
	w.resize(n + 1); profit.resize(n + 1);
	for (int i = 1; i <= n; i++)
	{
		cin >> w[i] >> profit[i];
	}

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= W; j++)
			dp[i][j] = -1;
	}

	cout << f(W, 1);


}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	// cin >> t;
	// while (t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 82448
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int n,k,a[200010],nxt[200010];
map<int,int> prv;
int memo[200010];

int nxtpos(int pos){
	if(pos) pos = nxt[pos - 1] + 1;
	while(nxt[pos] > pos) pos = nxt[pos] + 1;
	return (pos + 1) % (n + 1);
}

signed main(){
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		nxt[i] = i;
	}
	nxt[n] = 0;
	for(int i = 0;i <= n;i++) memo[i] = -1;
	for(int i = 0;i < 2 * n;i++){
		if(prv.count(a[i % n])) nxt[prv[a[i % n]]] = i % n;
		prv[a[i % n]] = i % n;
	}
	int shuki = -1,pos = 0;
	for(int i = 0;i < k - 1;i++){
		if(i && !pos){
			shuki = i;
			break;
		}
		pos = nxtpos(pos);
	}
	if(shuki != -1){
		for(int i = 0;i < (k + shuki - 1) % shuki;i++){
			pos = nxtpos(pos);
		}
	}
	set<int> st;
	if(pos) st.insert(a[pos - 1]);
	vector<int> vec;
	if(pos) vec.pb(a[pos - 1]);
	for(int i = 0;i < n;i++){
		if(st.count(a[i])){
			st.erase(a[i]);
			while(vec.back() != a[i]){
				st.erase(vec.back());
				vec.pop_back();
			}
			vec.pop_back();
		}else {
			st.insert(a[i]);
			vec.pb(a[i]);
		}
	}
	for(int i = 0;i < vec.size();i++) cout << (i ? " " : "") << vec[i];
	cout << endl;
}


Measured memory_bytes: 29680
N, = map(int, raw_input().split())
p = {}
for i in range(2, N+1):
  ii = i
  for j in range(2, i+1):
    while(ii%j==0):
      p[j] = p.get(j, 0)+1
      ii //= j
m = [3,5,15,25,75]
x = {}
for l in m:
  x[l-1] = 0
for k in p:
  for l in m:
    if p[k]>=l-1:
      x[l-1] += 1
r = 0
if x[4]>=2 and x[2]-2>=1:
  r += x[4]*(x[4]-1)*(x[2]-2)//2
if x[14]>=1 and x[4]-1>=1:
  r += x[14]*(x[4]-1)
if x[24]>=1 and x[2]-1>=1:
  r += x[24]*(x[2]-1)
if x[74]>=1:
  r += x[74]
print r

Measured memory_bytes: 2696
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if N * A <= B:
        print(N*A)
    else:
        print(B)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
abcd = input()
int_abcd = list(map(int, abcd))
for i in range(1 << 3):    
    op = ['-'] * 3 + ['=7']
    sum_abcd = int_abcd[0]
    for j in range(3):
        if (i >> j) & 1:
            op[2 - j] = '+'
        sum_abcd += (-1)**(((i >> j) & 1) + 1) * int_abcd[3 - j]
    if sum_abcd == 7:
        break

for num, pm in zip(abcd, op):
    print(num, pm, sep='', end='')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<string> v;
int d[410][410];
int main () {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        string S;
        cin >> S;
        v.push_back(S);
    }
    for (int i = 0; i < H*W; i++) {
        for (int j = 0; j < H*W; j++) {
            int ix = i % W, iy = i / W;
            int jx = j % W, jy = j / W;
            if (abs(ix-jx)+abs(iy-jy) == 1 && v[iy][ix] == '.' && v[jy][jx] == '.') {
                d[i][j] = d[j][i] = 1;
            }
            else if (i == j) {
                d[i][j] = d[j][i] = 0;
            }
            else {
                d[i][j] = d[j][i] = INT_MAX / 3;
            }
        }
    }
    for (int k = 0; k < H*W; k++) {
        for (int i = 0; i < H*W; i++) {
            for (int j = 0; j < H*W; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (v[i][j] == '.') {
                for (int ii = 0; ii < H; ii++) {
                    for (int jj = 0; jj < W; jj++) {
                        if (v[ii][jj] == '.') {
                            ans = max(ans, d[ii*W+jj][i*W+j]);
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;

const int INF = 1e9;
const int MAX_V = 1010;
struct edge{ int to,cap,rev;edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}};

vector<vector<edge> > G(MAX_V); //??°???????????£??\???????????¨???
bool used[MAX_V]; //DFS??§??¢???????????????????????????????????°

void add_edge(int from, int to, int cap){
		G[from].push_back(edge(to,cap,G[to].size()));
		G[to].push_back(edge(from,0,G[from].size() - 1));
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if( !used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -=d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		fill(used,used + MAX_V,false);
		int f = dfs(s,t,INF);
		if(f == 0)return flow;
		flow += f;
	}
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int v,e;
	cin >> v >> e;
	REP(i,e){
		int from,to,cap;
		cin >> from >> to >> cap;
		add_edge(from,to,cap);
	}
	cout << max_flow(0,v-1) << endl;
  return 0;
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L


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

int main(void) {
	long long N, ans = 0, tmp;
	bool isDivided = false;
   	map<long long, long long> mp;
   	map<long long, bool> check;

	cin >> N;

	vector<long long> A(N);


	for (long long i = 0; i < N; i++) {
   		cin >> tmp;
		A[i] = tmp;
        check[tmp]=false;
        mp[tmp]++;
	}

	sort(A.begin(), A.end());
    tmp=A[A.size()-1];

    for(long long i=0;i<A.size()-1;i++){
        for(long long j = A[i]*2;j<=tmp;j=j+A[i]){
            if(check.count(j) > 0){
                check[j]=true;
            }
        }
        if(mp[A[i]] >1){
            check[A[i]]=true;
        }
    }

    for(auto i : check){
        if(i.second == false){
            ans++;
        }
    }


	


	cout << ans << endl;


	return 0;
}



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

using namespace std;

typedef long long int LL;

int main() {
    LL n, m;
    cin >> n >> m;
    vector<vector<LL>> s(m);
    vector<LL> p(m);
    for (LL i = 0; i < m; ++i) {
        LL k;
        cin >> k;
        s[i].resize(k);
        for (LL j = 0; j < k; ++j) {
            cin >> s[i][j];
        }
    }
    for (LL i = 0; i < m; ++i) cin >> p[i];

    LL ans = 0;

    for (LL bit = 0; bit < (1 << n); ++bit) {
        bool flag = true;
        for (LL i = 0; i < m; ++i) {
            LL c = 0;
            for (LL j : s[i]) {
                if (bit & (1 << (j - 1))) ++c;
            }
            if (c % 2 != p[i]) flag = false;
        }
        if (flag) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int a,b,c,k;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        k = sc.nextInt();
        
        int sn = 0 ;
        
        if(a<=k){
            sn += a*1;
            k -= a;
        }
        else{
            sn += k;
            k -= k;
        }
        
        if(b<=k){
            sn += 0;
            k -= b;
        }
        else{
            k -= k;
        }
        
        if(c<=k){
            sn -= 1*c;
            k -= c;
        }
        else{
            sn -= k;
            k -= k;
        }
        
        System.out.println(sn);
        
    }
}



Measured memory_bytes: 35780