akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

int main(void){
  string S_;   cin >> S_;
  int i, j;
  deque<string> S(S_.size());
  for(i=0; i<S_.size(); i++){
    string tmp = {S_[i]};
    S.push_back(tmp);
  }
    
  int Q;   cin >> Q;
  char query[Q][3];
  for(i=0; i<Q; i++){
    cin >> query[i][0];
    if(query[i][0] == '2')
      cin >> query[i][1] >> query[i][2];
  }

  //1なら先頭から，0なら末尾から見ていく
  int top = 1;
  //各クエリの処理
  for(i=0; i<Q; i++){
    //反転させるとき
    if(query[i][0] == '1'){
      //cout << "反転" << endl;
      top = !top;
    }
    //追加するとき
    else{
      char fob = query[i][1]; //front or back
      string push = {query[i][2]};
      //cout << "挿入 : ";
      if(top == 1){
	if(fob == '1')
	  S.push_front(push);
	else
	  S.push_back(push);
      }
      else{
	if(fob == '1')
	  S.push_back(push);
	else
	  S.push_front(push);
      }
    }
    /*for(j=0; j<S.size(); j++)
      cout << S[j];
      cout << endl;*/
  }
  
  //top=0なら，末尾が先頭になるようにswapしていく
  if(top == 0){
    for(i=0; i<S.size()/2; i++)
      swap(S[i], S[S.size()-1-i] );
  }

  //cout << "answer : ";
  //出力
  for(auto str=S.begin(); str<S.end(); str++)
    cout << *str;
  cout << endl;
  
  
  return 0;
}


Measured memory_bytes: 18560
#include <iostream>
#include <string>
using namespace std;
int main(){
	string S, T;
	cin >> S >> T;
	int same = 0;
	int max=0;
	for (int i = 0;i <(int)S.length()-(int)T.length()+1 ;i++) {
		for (int k = 0;k < (int)T.length();k++) {
			if (T[k] == S[i + k]) same++;
		}
		if (max < same) max = same;
		same = 0;

	}
	cout << (int)T.length()-max;

}

Measured memory_bytes: 3628
import java.math.BigInteger;
import java.util.Scanner;

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

        BigInteger A = new BigInteger(sc.next());
        BigInteger B = new BigInteger(sc.next());

        if (A.compareTo(B) == 1) System.out.println("GREATER");
        if (A.compareTo(B) == -1) System.out.println("LESS");
        if (A.compareTo(B) == 0) System.out.println("EQUAL");
    }
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		
		System.out.println(x - (a + ((x-a)/b) * b));
	}

}

Measured memory_bytes: 20820
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
int aa[213][213], ans[213][213];
signed main() {
    int n, a, b, c = 0, d = 0, e = 0; 
    for (int h = 0; h < 3; h++) {
        for (int i = 0; i < 3; i++) {
            cin >> a; aa[h][i] = a;
        }
    }
    cin >> n;
    for (int h = 0; h < n; h++) {
        cin >> b;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (aa[i][j] == b) {
                    ans[i][j] = 1;
                }
            }
        }
    }
    for (int h = 0; h < 3; h++) { if (ans[0][h] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } c = 0;
    for (int h = 0; h < 3; h++) { if (ans[1][h] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } c = 0;
    for (int h = 0; h < 3; h++) { if (ans[2][h] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } c = 0;
    for (int h = 0; h < 3; h++) { if (ans[h][0] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } c = 0;
    for (int h = 0; h < 3; h++) { if (ans[h][1] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } c = 0;
    for (int h = 0; h < 3; h++) { if (ans[h][2] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } c = 0;
    for (int h = 0; h < 3; h++) { if (ans[h][h] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } c = 0;
    for (int h = 0; h < 3; h++) { if (ans[h][2 - h] == 1) { c++; } }
    if (c == 3) { cout << "Yes" << endl; return 0; } 
    cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Monad
v=(map p) (replicateM 10 "0357")
u=[x|x<-v,not(elem '0' x),elem '3' x,elem '5' x,elem '7' x]
p ('0':s) = p s
p [] = "0"
p s = s
main=readLn>>=print.(\n->(sum[1|x<-[x|x<-u,(read x)<=(n::Int)]]))

Measured memory_bytes: 45180
console.log((args=>{
  let [N,...a] = args.trim().split`\n`.map(v=>v-1);
  let c = a[0];
  for ( let i = 1; i <= N; i++ ) {
    if ( c === 1 ) return i;
    c = a[c];
  }
  return '-1';
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 43532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
const int mod=998244353;
const int INF=0x3f3f3f3f;
ll quick(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1)
			ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
ll inv(ll a){return quick(a,mod-2);}
const int maxn=55;
ll dp[maxn][maxn][maxn*maxn];
int x[maxn];
int main()
{
	int n,a;
	cin>>n>>a;
	for(int i=1;i<=n;i++) cin>>x[i];
	ll ans=0;
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			for(int s=0;s<=j*50;s++)
			{
				if(s>=x[i]&&j>=1)
					dp[i][j][s]=dp[i-1][j][s]+dp[i-1][j-1][s-x[i]];
				else dp[i][j][s]=dp[i-1][j][s];
				if(j&&i==n&&s%j==0&&s/j==a) ans+=dp[i][j][s];
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 65792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(Math.max(a*c, Math.max(a*d, Math.max(b*c, b*d))));
	}
}


Measured memory_bytes: 27060
#include <iostream>
#include <math.h>
using namespace std;

int main(void){
    double v;
    double h;
    double N;
    while(cin>>v){
        h=v*v/(2*9.8);
        N=h/5+1;
        cout<<ceil(N)<<endl;
    }
    return 0;
}



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

const ll MOD = 1e9+7;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  int cnt = 0;
  int ans = 0;
  rep(i, s.size()) {
    if(s[i] == 'R') {
      ++cnt;
      ans = max(ans, cnt);
    }
    if(s[i] == 'S') {
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  if((b / k) * k >= a) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3596
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define pf psuh_front
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 2 * 1e5 + 7;
const ld pi = 3.14159265359;
const int INF = 1e9 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

ll n, arr[N];

bool f = 0;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> n;

  f = 1;

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

    int x;
    cin >> x;

    if(n % 2 == x){
      f = 0;
    }
    if(++arr[x] > 2){
      f = 0;
    }
  }

  if(n % 2 == 1 && arr[0] > 1){
    f = 0;
  }

  if(f){
    ll ans = 1;

    for(int i = 1; i <= n / 2; i++){
      ans = ans * 2 % INF;
    }

    cout << ans;
  }
  else{
    cout << 0;
  }
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int[] x = new int[4];
    int[] y = new int[5];
    int c = 0;
    for(int i=0; i<5; i++){
      int a = sc.nextInt();
      if(a!=0){
        x[c] = a;
        c++;
      }
      y[i] = i+1;
    }
    Arrays.sort(x);
    for(int i=0; i<5; i++){
      if(i<4 && x[i]!=y[i]){
        System.out.println(y[i]);
        break;
      }
      else if(i==4){
        System.out.println(5);
      }
    }
  }
}

Measured memory_bytes: 35916
#include<bits/stdc++.h>
using namespace std;
int a[55];
int main(){
    int n,ans=1;
    cin>>n;
    string s;
    cin>>s;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

typedef long long int ll;

int main () {
    int n, k; cin >> n >> k;
    vector<int> ps(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> ps[i];
    }
    sort(ps.begin(), ps.end());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += ps[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3196
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll a, b, c; cin >> a >> b >> c;
  cout << a * b / 2 << endl;
}


Measured memory_bytes: 256
import Text.Printf
main :: IO()
main = do
  [n, k] <- map read . words <$> getLine
  printf "%s" $ unlines $ map show $ slv n k [1..k] []
 
slv :: Integer -> Integer -> [Integer] -> [Integer] -> [Integer]
slv n k (m:ms) ret = slv n k ms (val:ret)
  where val = ((comb (n - k + 1) m) * (comb (k - 1) (m - 1))) `mod` (10^9 + 7)
slv _ _ [] ret = reverse ret

comb :: Integer -> Integer -> Integer
comb n k = (product [(n - k + 1)..n]) `div` (product [1..k]) 

Measured memory_bytes: 3452
n, m = map(int, input().split())
city = []

for i in range(m):
    a = list(map(int, input().split()))+[i]
    city.append(a)
city.sort(key=lambda x: x[1])

count = [1 for _ in range(n)]
for k in range(m):
    city[k].append(count[city[k][0]-1])
    count[city[k][0]-1] += 1
city.sort(key=lambda x: x[2])

for i in city:
    print(str(i[0]).zfill(6)+str(i[-1]).zfill(6))


Measured memory_bytes: 37384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using ll = long long;
using P = pair<int, int>;


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

    int m_min;
    int m_max;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (n % 2 == 0) {
        m_min = a[n/2 - 1] + a[n/2];
        m_max = b[n/2 - 1] + b[n/2];
        cout << m_max - m_min + 1 << endl;
    } else {
        m_min = a[(n + 1) / 2 - 1];
        m_max = b[(n + 1) / 2 - 1];
        cout << m_max - m_min + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

int n;
LL ai[55];

LL chk(LL x){
	LL sum = 0;
	REP(i, 1, n){
		LL t = (ai[i] + x - (n - 1));
		if (t < 0) continue;
		if (t % (n + 1)) t = t / (n + 1) * (n + 1) + (n + 1);
		t /= (n + 1);
		sum += t;
	}
	// cerr << x << ' ' << sum << endl;
	return abs(sum - x);
	// sum <= x;
}

int main(){
	cin >> n;
	REP(i, 1, n) cin >> ai[i];
	LL l = 0, r = 500000000000000000;
	while (l + 10000 <= r){
		LL lmid = l + (r - l) / 3, rmid = r - (r - l) / 3;
		if (chk(lmid) <= chk(rmid)) r = rmid;
		else l = lmid;
	}
	// debug("l = %lld, r = %lld\n", l, r);
	for (LL i = l; i <= r; ++i)
		if (chk(i) == 0){
			cout << i << endl;
			return 0;
		}
	assert(0);
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int res = a * 100 + b * 10 + c;
    cout << (res % 4 == 0 ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        String s = sc.next();
        String p = sc.next();

        s += s.substring(0, p.length());

        System.out.println((s.contains(p))? "Yes" : "No");
    }
}

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

int main(){
  long k, a, b, n = 1;
  cin >> k >> a >> b;
  while(k > 0){
    if(n >= a && k > 1 && b - a > 2){
      k -= 2;
      n += (b - a);
    }
    else {
      k--;
      n++;
    }
  }
  cout << n;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] a = new long[n][2];
        Arrays.stream(a)
              .forEachOrdered(ai -> {
                  ai[0] = sc.nextLong();
                  ai[1] = sc.nextLong();
              });
        long ans = 0L;
        for (int i = n-1; i >= 0; i--) {
            if((a[i][0] + ans)% a[i][1] != 0)
            ans += a[i][1] - ((a[i][0] + ans)% a[i][1]);
        }
        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 95208
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        p: [usize;n],
    }

    let mut ans = 0;
    let mut current_min = n;
    for i in p {
        if i <= current_min {
            ans += 1;
            current_min = i;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
 int main() {
   long long N;
   cin >>N;
   vector <long long> vec(N);
    for(long long i=0; i<N; i++) {
      cin >>vec.at(i);
    }
    sort(vec.begin(), vec.end());
   int count=0;
   
   for(int i=0;i<N-1;i++) {
     if (vec.at(i) !=vec.at(i+1)) {
       count++;
     }
   }
   if (count == N-1) {
     cout << "YES" << endl;
   }
   else {
     cout << "NO" << endl;
   }
     
       
   
   
   
 }

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  
  int k,n,x,y;
  scanf("%d",&k);
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&x,&y);
    x=min(x,k-x+1);
    y=min(y,k-y+1);
    if(x<y) printf("%d\n",(x+2)%3+1);
    else printf("%d\n",(y+2)%3+1);
  }
  return 0;
}

Measured memory_bytes: 1188
S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(S[K-1])

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

ll n;
ll k;
bool ok;

int main(){
    cin>>n;
    vector<vector<ll>> s(n,vector<ll>());
    rep(i,n){
        string str;
        cin>>str;
        rep(j,n){
            if(str[j]=='1'){
                s[i].push_back(j);
            }
        }
    }
    ll ans=-1;
    rep(i,n){
        vector<ll> v(n,-1);
        k=1;
        ok=true;
        queue<pair<ll,ll>> que;
        que.push(make_pair(i,1));
        v[i]=1;
        while(que.size()){
            pair<ll,ll> p=que.front();
            que.pop();
            ll vertex=p.first;
            ll vn=p.second;
            for(ll next:s[vertex]){
                if(v[next]==-1){
                    que.push(make_pair(next,vn+1));
                    v[next]=vn+1;
                    if(k<vn+1)k=vn+1;
                }else{
                    if(v[next]!=vn+1 && v[next]!=vn-1){
                        ok=false;
                        break;
                    }
                }
            }
            if(!ok)break;
        }
        if(ok)ans=max(ans,k);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
def C(m):
    return m[1:]+m[:1]

def J(m):
    return m[-1:]+m[:-1]

def E(m):
    lenm=len(m)
    h=lenm/2
    if h*2==lenm or h==0:
        temp=m[-h:]+m[:h]
    else:
        temp=m[-h:]+m[h]+m[:h]
    return temp

def A(m):
    return m[::-1]

def M(m):
    m=list(m)
    for i in range(len(m)):
        if m[i].isdigit():
            if m[i]=="9":
                m[i]="0"
            else:
                m[i]=str(int(m[i])+1)
    return "".join(m)

def P(m):
    m=list(m)
    for i in range(len(m)):
        if m[i].isdigit():
            if m[i]=="0":
                m[i]="9"
            else:
                m[i]=str(int(m[i])-1)
    return "".join(m)

for i in range(input()):
    messenger=raw_input()
    message=raw_input()
    for m in messenger[::-1]:
        if m=="J":
            message=J(message)
        elif m=="C":
            message=C(message)
        elif m=="E":
            message=E(message)
        elif m=="A":
            message=A(message)
        elif m=="P":
            message=P(message)
        elif m=="M":
            message=M(message)
    print message

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

int graph[60][60] = {};
int memo[60] = {};
int n, m;

void dfs(int i){
  if(memo[i] != 0) return;
  memo[i] = 1;
  for(int j = 0;j < n;j++){
    if(graph[i][j] == 1){
      dfs(j);
    }
  }
  return;
}

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

  int a,b;
  for(int i = 0;i < m;i++){
    cin >> a >> b;
    a--; b--;
    graph[a][b] = 1;
    graph[b][a] = 1;
  }

  int ans = 0;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(graph[i][j] == 1){
        graph[i][j] = 0;
        graph[j][i] = 0;
        for(int x = 0;x < n;x++) memo[x] = 0;
        dfs(0);
        for(int x = 0;x < n;x++){
          if(memo[x] == 0){
            ans++;
            break;
          }
        }
        graph[i][j] = 1;
        graph[j][i] = 1;
      }
    }
  }

  if(ans != 0){
    cout << ans/2 << endl;
  }else{
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var numbers = Console.ReadLine()
                .Split()
                .Select((elem, index) => new { Number = index + 1, Count = int.Parse(elem) })
                .OrderBy(elem => elem.Count)
                .Select(elem => elem.Number);
            Console.WriteLine(string.Join(" ", numbers));
        }
    }
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int p = 0;
  for(int i = 1; i < n; i++){
    if(s.at(i) == 'E') p++;
  }
  int out = p;
  for(int i = 0; i < n - 1; i++){
    if(s.at(i) == 'W') p++;
    if(s.at(i + 1) == 'E') p--;
    if(out > p) out = p;
  }
  cout << out;
}

Measured memory_bytes: 900
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

typedef pair<double, ll> pdlg;

struct edge {
    int to;
    double cost;
};

int V;
vector<edge> G[1000000];
double d[1000000];

void addedge(int st, int ed, double co) {
    edge e;
    e.to = ed;
    e.cost = co;
    G[st].push_back(e);
}

void dijkstra(int s) {
    priority_queue<pdlg, vector<pdlg>, greater<pdlg> > que;
    fill(d, d + V + 10, llmax);
    d[s] = 0;
    que.push(pdlg(0, s));

    while (!que.empty()) {
        pdlg p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) {
            continue;
        }
        int len = G[v].size();
        for (int i = 0; i < len; i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pdlg(d[e.to], e.to));
            }
        }
    }
}

int main() {
    while (1) {
        int n, m, p, a, b;
        cin >> n >> m >> p >> a >> b;
        if (n == 0) {
            break;
        }
        V = (1 << n) * m + 1;
        int t[n];
        for (int i = 0; i < n; i++) {
            cin >> t[i];
        }
        for (int i = 0; i < V; i++) {
            G[i].clear();
        }
        for (int i = 0; i < p; i++) {
            int x, y, z;
            cin >> x >> y >> z;
            for (int j = 0; j < (1 << n); j++) {
                for (int k = 0; k < n; k++) {
                    if ((j & (1 << k)) == 0) {
                        addedge((x - 1) * (1 << n) + j, (y - 1) * (1 << n) + (j + (1 << k)), z / (t[k] * 1.0));
                        addedge((y - 1) * (1 << n) + j, (x - 1) * (1 << n) + (j + (1 << k)), z / (t[k] * 1.0));
                    }
                }
            }
        }
        for (int i = 0; i < (1 << n); i++) {
            addedge((b - 1) * (1 << n) + i, V - 1, 0);
        }
        dijkstra((a - 1) * (1 << n));
        double ans = d[V - 1];
        cout << fixed;
        cout << setprecision(5);
        if (ans != llmax) {
            cout << ans << endl;
        } else {
            cout << "Impossible" << endl;
        }
    }
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL ans = 0;

	LL N, K; cin >> N >> K;
	vector<PLL>a;
	FOR(i, 0, N) {
		LL x, y; cin >> x >> y;
		a.push_back(PLL(x, y));
	}
	SORT(a);
	for (auto it : a) {
		if (it.second >= K) {
			cout << it.first << endl; return 0;
		}
		else {
			K -= it.second;
		}
	}

	return 0;
}


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

using ll = long long int;
using P = pair<ll, ll>;
using P3 = pair<int, P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};


int main() {
    int x, ans = 0;
    cin >> x;
    if(x == 1){
        cout << 1 << endl;
    }else{
        for(int i=2;i*i<=x;i++){
            int b = i;
            while(b <= x){
                ans = max(ans, b);
                b *= i;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

weight = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)
dp[0] = 0
for i in range(n+1):
    for a in A:
        if i+weight[a] < n+1:
            dp[i+weight[a]] = max(dp[i+weight[a]], dp[i]*10+a)
print(dp[n])


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

#define all(A) (A).begin(), (A).end()
#define sz(A) int((A).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  ll a;
  cin >> a;
  cout << a * a * a << '\n';
  return (0);
}

Measured memory_bytes: 256
import sys
from numpy import*
from scipy.sparse import*
def main():
  f=csgraph.floyd_warshall
  n,m,l,*t=map(int,sys.stdin.buffer.read().split())
  t=int32(t)
  d=f(f(csr_matrix((t[2:m*3:3],(t[:m*3:3],t[1:m*3:3])),(n+1,n+1)),0)<=l)-1
  d[d==inf]=-1
  print('\n'.join(map(str,map(int,d[t[m*3+1::2],t[m*3+2::2]]))))
main()

Measured memory_bytes: 36216
#include<stdio.h>

void trace(int A[],int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0) printf(" ");//??¨?????????????´???´?????\??????
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionSort(int A[],int N){
    int i,j,v;
    for(i=1;i<N;i++){
        v=A[i];
        j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(){
    int N,i,j;
    int A[100];

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    trace(A,N);
    insertionSort(A,N);
    return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
int main(void)
{
	int t; cin >> t;
	t = pow(t, 3);
	cout << t << endl;

	return 0;
}

Measured memory_bytes: 256
//---------- begin union_find ----------
#[allow(dead_code)]
mod union_find {
    pub struct UF {
        p: Vec<i32>,
        stack: Vec<usize>
    }
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {
                p: vec![-1; n],
                stack: vec![],
            }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&mut self, mut x: usize) -> usize {
            let stack = &mut self.stack;
            while self.p[x] >= 0 {
                stack.push(x);
                x = self.p[x] as usize;
            }
            while let Some(v) = stack.pop() {
                self.p[v] = x as i32;
            }
            x
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, mut x: usize, mut y: usize) -> Option<(usize, usize)> {
            x = self.root(x);
            y = self.root(y);
            if x == y {
                return None;
            }
            if self.p[x] > self.p[y] {
                let s = x;
                x = y;
                y = s;
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
            Some((x, y))
        }
        pub fn get_size(&mut self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let d: u64 = it.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let mut e = vec![];
    let mut stack = vec![(0, n)];
    while let Some((l, r)) = stack.pop() {
        if l + 1 == r {
            continue;
        }
        let m = (l + r) / 2;
        stack.push((l, m));
        stack.push((m, r));
        let mut local = (a[l], l);
        for i in (l + 1)..m {
            local.0 += d;
            if local.0 > a[i] {
                local = (a[i], i);
            }
        }
        for i in m..r {
            local.0 += d;
            e.push((local.1, i, local.0 + a[i]));
        }
        let mut local = (a[r - 1], r - 1);
        for i in (m..(r - 1)).rev() {
            local.0 += d;
            if local.0 > a[i] {
                local = (a[i], i);
            }
        }
        for i in (l..m).rev() {
            local.0 += d;
            e.push((i, local.1, local.0 + a[i]));
        }
    }
    e.sort_by_key(|e| e.2);
    let mut u = union_find::UF::new(n);
    let mut ans = 0;
    for (a, b, c) in e {
        if u.unite(a, b).is_some() {
            ans += c;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 134512
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;
#define ll long long

int main() {
	int N; cin >> N;
	vector<ll> v(N);
	for(int i=0; i<N; ++i) cin >> v[i];
	sort(v.begin(), v.end());
	ll ans=0;
	int p=N/2;
	if(N%2==0){
	    for(int i=0; i<N; ++i){
	        if(i==p || i+1==p) ans += abs(v[i]-v[p]);
	        else ans += abs(v[i]-v[p])*2;
	    }
	}
	else{
	    for(int i=0; i<N; ++i){
	        if(abs(i-p)>1) ans += abs(v[i]-v[p])*2;
	        else ans += abs(v[i]-v[p]);
	    }
	    ans += max(v[p+1]-v[p], v[p]-v[p-1]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 1005;
const int MMAX = 2005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << "(DUMP) " << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> pl;
typedef pair<ll, ll> pll;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A[MMAX],B[MMAX],C[MMAX],D,E;
ll d[NMAX] = {};

string S;
vec v;

ll ans = 0;

void solve(){
  // main algorithm
  Fill(d,INFLL);
  d[1] = 0;
  for (int i = 0; ; ++i)
  {
    bool update = false;
    for (int j = 0; j < M; ++j)
    {
      if (d[A[j]] != INFLL && d[B[j]] > d[A[j]] + C[j])
      {
        update = true;
        d[B[j]] = d[A[j]] + C[j];
        if (i >= N-1 && B[j] == N)
        {
          cout << "inf\n";
          return;
        }else if(i >= 2 * N){
          update = false;
          break;
        }
      }
    }
    if (!update)
    {
      cout << -d[N] << endl;
      return;
    }
  }
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  // printf("%lld\n", ans);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  scanf("%lld%lld", &N,&M);
  for (int i = 0; i < M; ++i)
  {
    scanf("%lld%lld%lld", &A[i],&B[i],&C[i]);
    C[i] *= -1;
  }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	ll x,y,w;
}b[4000010];
ll n,m,u,tot,val[500010],e[500010],hd[500010],nt[500010],sz[500010],
v[500010],rt,mx,mn,zo,ans,a[500010],pa[500010];
void build(ll x,ll y,ll w){
	tot++;
	e[tot]=y;val[tot]=w;
	nt[tot]=hd[x];hd[x]=tot;
}
void get(ll x,ll fa){
	ll i,now=0;
	sz[x]=1;
	for(i=hd[x];i;i=nt[i]){
		if(e[i]==fa||v[e[i]])continue;
		get(e[i],x);sz[x]+=sz[e[i]];
		now=max(now,sz[e[i]]);
	}
	now=max(now,zo-sz[x]);
	if(now<mx)mx=now,rt=x;
}
void dfs(ll x,ll fa,ll dep){
	ll i;
	if(a[x]+dep<mn)mn=a[x]+dep,u=x;
	for(i=hd[x];i;i=nt[i]){
		if(e[i]==fa||v[e[i]])continue;
		dfs(e[i],x,dep+val[i]);
	}
}
void link(ll x,ll fa,ll dep){
	ll i;
	b[++m].x=x;b[m].y=u;b[m].w=dep+a[x]+mn;
	for(i=hd[x];i;i=nt[i]){
		if(e[i]==fa||v[e[i]])continue;
		link(e[i],x,dep+val[i]);
	}
}
void divide(ll x){
	ll i;
	v[x]=1;
	mn=1e18;
	dfs(x,0,0);link(x,0,0);
	for(i=hd[x];i;i=nt[i]){
		if(v[e[i]])continue;
		zo=mx=sz[e[i]];get(e[i],x);
		divide(rt);
	}
}
bool cmp(aaa a,aaa b){
	return a.w<b.w;
}
ll find(ll x){
	if(x==pa[x])return x;
	return pa[x]=find(pa[x]);
}
int main(){
	ll i,x,y,w;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(i=1;i<n;i++){
		scanf("%lld%lld%lld",&x,&y,&w);
		build(x,y,w);build(y,x,w);
	}
	zo=mx=n;
	get(1,0);
	divide(rt);
	for(i=1;i<=n;i++)pa[i]=i;
	sort(b+1,b+m+1,cmp);
	for(i=1;i<=m;i++){
		x=find(b[i].x);y=find(b[i].y);
		if(x!=y){
			pa[x]=y;ans+=b[i].w;
		}
	}
	printf("%lld",ans);
}
/*
确实不会... 
*/

Measured memory_bytes: 119680
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
   int n,k;
    cin>>n>>k;
    int c=0;
    int f=1;
  int a[n];
    for(int i=0;i<n;i++)
    {
       cin>>a[i];
    }
    sort(a, a+n);
 int arr[n];
    int curr=a[0];
    int i,j;
    int pos=0;
        for( i=0;i<n;i=j)
    {c=0;
     curr=a[i];
       for(j=i;j<n;j++)
       {
           if(a[j]==a[i])
               c++;
           else
               break;
       }
     arr[pos]=c;
     pos++;
    }
 
    sort(arr, arr+pos, greater<int>());
 int s=0;
    for(i=k;i<pos;i++)
        s+=arr[i];
    cout<<s;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int a[10005],b[505];
int main()
{
	int n,m,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	cin>>m;
	for(int i=1;i<=m;i++) cin>>b[i];
	for(int i=1;i<=m;i++){
	for(int j=1;j<=n;j++){
		if(b[i]==a[j]){
			ans++;
			break;
		}
	} 
}
cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3140
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    T = input()
    ans = False
    for i in range(len(S)):
        if T == S[i:] + S[:i]:
            ans = True
            break
    print('Yes' if ans else 'No')
if __name__ == '__main__':
    main()



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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 211111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;


int main() {
  ll n, t,prev_input = 0, input, diff = 0 , sum = 0 ; 

  scanf("%lld %lld",&n, &t) ;
  for(int i = 1 ;i<=n ;i++){
    scanf("%lld", &input) ;
    diff = input - prev_input ;
    sum+=min(diff, t) ;
    prev_input = input ;
  }
  sum+=t ;

  cout << sum << endl ;


	
  return 0 ;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    j = 0
    if i < k:
        while i*(2**j) < k:
            j +=1
        ans += (1/n) *1/(2**j)
    else:
        ans += (1/n)
print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/*Coding Space*/
unordered_map<ll,char> ans;
int main(){
  int n,m; cin >> n >> m;
  string s,t; cin >> s >> t;
  ll g = lcm(n,m);
  
  rep(i,n){
    int index = g*i/n;
    //cerr << index <<" " <<  s[i]<<endl;
    ans[index] = s[i];
  }
  rep(i,m){
    int index = g*i/m;
    //cerr << index <<" " <<  t[i]<<endl;
    if(ans[index] != 0 && ans[index] != t[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << g << endl;
}


Measured memory_bytes: 7624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>

using namespace std;
using ll=long long;
map<ll, ll> m;
ll N;

int main()
{
    cin >> N;
    ll NN = N;
    for(ll i = 2;i <= 1000000;i++)
    {
        while(NN % i == 0)
        {
            NN /= i;
            m[i]++;
        }
    }
    ll sum = NN == 1 ? 0 : 1;
    for(auto ite = m.begin(); ite != m.end(); ite++)
    {
        ll dec = 1;
        //cout << ite->first << ':' << ite->second << endl;
        while(ite->second - dec >= 0)
        {
            ite->second -= dec;
            dec++;
            sum++;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3196
s = gets.chomp.chars
t = gets.chomp.chars

if s == t
  puts 'No'
  exit 0
end

sorted_s = s.sort
sorted_t = t.sort.reverse
is_ok = [sorted_s, sorted_t].sort[0] == sorted_s
puts(is_ok ? 'Yes' : 'No')

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    List<Integer> list1 = new ArrayList<>();
    List<Integer> list2 = new ArrayList<>();
    int count = 0;

    int a = sc.nextInt();
    String s = sc.next();

    if(a < 3200){
        System.out.println("red");
    }else{
        System.out.println(s);
    }
    
    
    







}
}

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

int main(){
  int n,a[210],cnt=0;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<1000000000;i++){
    for(int k=0;k<n;k++){
      if(a[k]%2!=0){ cout<<cnt; return 0;}
      a[k]/=2;
    }
    cnt++;
  }

}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, K, = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()

if max(L) < K:
    print("IMPOSSIBLE")
    exit()

def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    return gcd(b, a % b)

p = L[0]
for v in L:
    p = gcd(p, v)

if K % p == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14628
R = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')
K = int(input())
print(R[K-1])

Measured memory_bytes: 2940
-- heap
local Heap = {}
function Heap.new(upper_func)
    local self = setmetatable({}, {__index = Heap})
    self.a = {}
    self.upper_func = upper_func
    self.upper = function(k1, k2)
        assert(k1 < k2)
        if k1 == 0 then
            return false
        else
            return upper_func(self.a[k1], self.a[k2])
        end
    end
    self.lower = function(k1, k2)
        return not self.upper(k1, k2)
    end
    return self
end

function Heap:count()
    return #self.a
end

function Heap:_swap(k1, k2)
    local old_k1 = self.a[k1]
    self.a[k1] = self.a[k2]
    self.a[k2] = old_k1
end

function Heap:upheap(newk)
    local ku = math.floor(newk / 2)
    local k = newk
    while ku > 0 and self.lower(ku, k) do
        self:_swap(ku, k)
        k = math.floor(k/2)
        ku = math.floor(ku/2)
    end
end

function Heap:insertq(e)
    table.insert(self.a, e)
    self:upheap(#self.a)
end

function Heap:downheap(newk)
    local k = newk
    while k <= math.floor(#self.a/2) do
        local kdl = k*2
        local kdr = kdl + 1
        local kd
        if kdr <= #self.a and self.lower(kdl, kdr) then
            kd = kdr
        else
            kd = kdl
        end
        if self.upper(k, kd) then
            break
        end
        self:_swap(k, kd)
        k = kd
    end
end

function Heap:top()
    assert(#self.a >= 1)
    return self.a[1]
end

function Heap:remove_top()
    assert(#self.a >= 1)
    local v = self.a[1]
    self:_swap(1, #self.a)
    table.remove(self.a)
    self:downheap(1)
    return v
end

----
local N, M = io.read("*n", "*n")
local jobs_of_a = {}
for i=1, 100000 do
    jobs_of_a[i] = {}
end
for i=1, N do
    local a, b = io.read("*n", "*n")
    table.insert(jobs_of_a[a], b)
end
local q = Heap.new(function (v1, v2)
    return v1 > v2
end)
local ans = 0
for a=1,M do
    local day = M + 1 - a
    assert(day >= 1)
    for k,v in ipairs(jobs_of_a[a]) do
        q:insertq(v)
    end
    if q:count() > 0 then
        local job = q:remove_top()
        ans = ans + job
    end
end
print(ans)

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int time = 0;
	time = min(b,d) - max(a,c);
	if(time < 0) time = 0;
	cout << time << endl;
}

Measured memory_bytes: 3604