akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE ScopedTypeVariables #-}
--n -bit flags in 0~
number_of_n_bit::Int->Int->Int
number_of_n_bit n a = let (d,m) = divMod (a+1) (2^n) in
                      ((2^(n-1)) * d) + (max 0 ( m - (2^(n-1))))

--40bit is enough to this

bin_to_int::[Bool]->Integer
bin_to_int = sum . (map (\(i,_)->(2^i))) . (filter snd) . (zip [(0::Int)..])

solver::Int->Int->Integer
solver a b = bin_to_int  [mod ((number_of_n_bit n b)-(number_of_n_bit n (a-1))) 2 == 1 |n<-[1..40]]

main::IO()
main=do
  a:b:[]<-return.map read.words=<<getLine
  print (solver a b)

Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  int n, a;
  int result = 0;
  cin >> n;
  REP(i,n) {
    cin >> a;
    result += (a - 1);
  }

  cout << result << endl;
  return 0;
}


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

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int y, m, d; scanf("%d/%d/%d", &y, &m, &d);
    if (y < 2019) {
        printf("Heisei\n");
        return 0;
    } else {
        if (m < 4) {
            printf("Heisei\n");
            return 0;
        } else if (m == 4) {
            if (d <= 30) {
                printf("Heisei\n");
                return 0;
            } else {
                printf("TBD\n");
                return 0;
            }
        } else {
            printf("TBD\n");
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int N;
  int ans = 0;
  cin >> N;
  vector<int> odd;
  for(int i = 1; i <= N; i+= 2){
    odd.push_back(i);
  }
  for(int i = 1; i <= N; i+= 2 ){
    int x = 0;
    for(int j = 0; j < odd.size(); j++){
      if(i%odd[j] == 0) x++;
    }
    if(x == 8) ans ++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    string s;
    cin >> s;
    int n = s.size();
    long dp[n+5][3];
    if(s[0] == 'A'){
        dp[0][0] = 1;
        dp[0][1] = 0;
        dp[0][2] = 0;
    }
    else{
        dp[0][0] = dp[0][1] = dp[0][2] = 0;
    }
    for(int i = 1;i<n;i++){
        if(s[i] == 'A'){
            dp[i][0] = dp[i-1][0] + 1;
            dp[i][1] = 0;
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'B'){
            dp[i][1] = dp[i-1][0];
            dp[i][0] = 0;
            dp[i][2] = dp[i-1][2];
        }
        else if(s[i] == 'C'){
            if(dp[i-1][1] == 0){
                dp[i][0] = 0;
                dp[i][1] = 0;
                dp[i][2] = dp[i-1][2];
            }
            else{
                dp[i][0] = dp[i-1][1];
                dp[i][1] = 0;
                dp[i][2] = dp[i-1][2] + dp[i-1][1];
            }
        }
    }
    cout << dp[n-1][2] << endl;
}

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

struct prog{
  int month, day, h, m;
  bool in;
};

int calc(prog state, prog tmp){
  int res = (tmp.h*60 + tmp.m) - (state.h*60 + state.m);
  return res >= 0 ? res : 0;
}
  
int main(){
  int n;
  while(cin >> n, n){
    vector<prog> state(n);
    for(int i = 0; i < n; i++){
      state[i].in = false;
    }
    prog tmp;
    int  id;
    vector<int> sum(n, 0);
    for(int i = 0; i < n; i++){
      char in;
      scanf("%d/%d %d:%d %c %d\n", &tmp.month, &tmp.day, &tmp.h, &tmp.m, &in, &id);
      if(in == 'I')tmp.in = true;
      else tmp.in = false;
      if(state[id].in == true && tmp.in == false){
	if(id == 0){
	  for(int i = 1; i < n; i++){
	    if(state[i].in)sum[i] += min(calc(state[0], tmp), calc(state[i], tmp));
	  }
	}else if(state[0].in){
	  sum[id] += min(calc(state[0], tmp), calc(state[id], tmp));
	}
      }
      state[id] = tmp;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
      ans = max(ans, sum[i]);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1268
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();
        int l = s.length();
        int ans = 0;
        if (l == 0) {
            System.out.println(ans);
            return;
        }
        for (int i = 0; i< l; i++) {
            if (s.charAt(i) != t.charAt(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


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

int main(){
    int N; cin >> N;
    vector<pair <int , int> > v;
    for(int i = 1; i <= N; i++){
        int a;
        cin >> a;
        v.push_back(make_pair(a, i));
    }
    sort(v.begin(), v.end(), 
    [](pair<int, int> &a, pair<int , int> &b){
        return a.first > b.first;
    });    

    for(int i = 1; i <= N; i++){
        for(auto vec:v){
            if(vec.second != i){
                cout << vec.first << endl;
                break; 
            }
        }
    }
}

Measured memory_bytes: 3312
from collections import*
n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C)
if l==3:
  x=0
  for c in C:x^=c[0]
  f=(len(set(c[1]for c in C))>1)+n%3+x>0
elif l==2:f=(abs(sum(c[1]*(-1)**i for i,c in enumerate(C)))!=n//3)+n%3>0
else:f=(l!=1)+A[0]>0
print('YNeos'[f::2])

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  else return gcd(b, a % b);
  // return (b == 0) ? a : gcd(b, a % b);
}

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

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  ll x = lcm(c, d);
  ll tmp1 = (b / x) - (a / x);
  ll tmp2 = (b / c) - (a / c);
  ll tmp3 = (b / d) - (a / d);
  cout << (b-a) - (tmp2+tmp3-tmp1) << endl;
}


Measured memory_bytes: 256
h,w,k = map(int,input().split())
if w == 1:
  print(1)
  exit()
a = [0]*(w+2)
a[1] = 1
f = [0]*(w-1)
p = 0
q = 1
for i in range(w-1):
  f[i] = p+q
  q = p + q
  p = q - p  
f.append(1)
b = []
mod = 10**9+7
for i in range(w):
  if i == 0:
    b.append([0,f[w-2],f[w-3]])
  elif i == w-1:
    b.append([f[w-3],f[w-2],0])
  else:
    b.append([f[i-2]*f[w-i-2],f[i-1]*f[w-i-2],f[i-1]*f[w-i-3]])
for _ in range(h):
  newa = [0]*(w+2)
  for i in range(1,w+1):
    newa[i] = (a[i-1]*b[i-1][0]+a[i]*b[i-1][1]+a[i+1]*b[i-1][2])%mod
  a = newa
print(a[k])

Measured memory_bytes: 38256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ky112233
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGoToSchool solver = new CGoToSchool();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGoToSchool {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = in.nextInt();
            int[] ans = new int[n];
            for (int i = 0; i < n; i++) {
                ans[a[i] - 1] = i + 1;
            }
            for (int num : ans) {
                out.print(num + " ");
            }
        }

    }
}



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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template<class T,T op(T,T)> class segtree{
public:
    int n,size_;
    vector<T> dat;
    T id_;
    segtree()=default;
    segtree(int size,T id,T initial_value){ init(size,id,initial_value); }
    void init(int size,T id,T initial_value){
        size_=size;
        id_=id;
        n=1;
        while(n<size) n*=2;
        dat.assign(2*n-1,id);
        for(int i=0; i<size; ++i) update(i,initial_value);
    }
    int size()const{ return size_; }
    void update(int k, T a) {
        k+=n-1; // leaf
        dat[k]=a;
        while(k>0) {
            k=(k-1)/2;
            dat[k]=op(dat[k*2+1],dat[k*2+2]);
        }
    }
    T at(int index){ return dat[index+n-1]; }
    void add(int k,T a){ update(k,at(k)+a); }
    T query(int a,int b) { return query(a,b,0,0,n); }
    T query(int a,int b,int k,int l,int r) {
        if(r<=a or b<=l) return id_;
        if(a<=l and r<=b) return dat[k];
        int m=(l+r)/2;
        return op(query(a,b,k*2+1,l,m),query(a,b,k*2+2,m,r));
    }
};

i64 add(i64 a,i64 b){
    return a+b;
}

void solve(){
    string S;
    cin >> S;

    vector<int> count(26);
    vector<vector<int>> index(26);
    rep(i,0,S.size()){
        ++count[S[i]-'a'];
        count[S[i]-'a']%=2;
        index[S[i]-'a'].emplace_back(i);
    }

    if(accumulate(begin(count),end(count),0)>1){
        cout << -1 << endl;
        return;
    }

    vector<tuple<i64,int,int>> vt;
    rep(i,0,26){
        rep(j,0,index[i].size()/2){
            vt.emplace_back(make_tuple(index[i][j]-index[i][index[i].size()-1-j],index[i][j],index[i][index[i].size()-1-j]));
        }
    }

    sort(begin(vt),end(vt));
    
    i64 ans=0;
    segtree<i64,add> seg(S.size(),0,1);
    rep(i,0,vt.size()){
        auto tup=vt[i];
        int l=get<1>(tup),r=get<2>(tup);
        ans+=seg.query(0,l)+seg.query(r+1,S.size());
        seg.update(l,0);
        seg.update(r,0);
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 7944
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
string table[]={"dream","dreamer","erase","eraser"};
string s;
bool f[100100];
int main(void){
    cin>>s;
    f[0]=1;
    rep(i,s.size()){
        if(f[i]){
            rep(j,4){
                bool F=1;
                rep(k,table[j].size()){
                    if(table[j][k]!=s[i+k]) F=0;
                }
                if(F) f[i+table[j].size()]=1;
            }
        }
    }
    if(f[s.size()]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3812
/******************************************
* AUTHOR : DHRUV GUPTA *
* NICK : COSMOGOD *
* INSTITUTION : LNMIIT *
******************************************/

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 100000000000007
ll dp[1000][1000];
ll a[1000];

ll sum(ll s, ll e) {
	ll ans = 0;
	for (ll i = s; i <= e; i++) {
		ans += a[i];
	}
	return ans;
}

ll solve(ll i, ll j) {
	if (i >= j) {
		return 0;
	}

	if (dp[i][j] != -1)
		return dp[i][j];

	dp[i][j] = inf;
	for (ll k = i; k <= j; k++) {
		dp[i][j] = min(dp[i][j], solve(i, k) + solve(k + 1, j) + sum(i, k) + sum(k + 1, j));
	}

	return dp[i][j];
}

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

	ll n;
	cin >> n;
	for (ll i = 0; i < n; i++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << solve(0, n - 1);

	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
//#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back

string s;
void solve()
{
    cin>>s;
    if(s.find("RRR") != string::npos)
    {
        cout << 3 << '\n';
    }
    else if (s.find("RR")!= string::npos)
    {
        cout << 2 << '\n';
    }
    else if (s.find("R")!= string::npos)
    {
        cout << 1 << "\n";
    }
    else cout << 0 << '\n';
}

signed main(void)
{
    int T = 1;
    cout << fixed;
    cout.precision(3);
    ios_base::sync_with_stdio(0); cin.tie(0);

    //cin>>T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <utility>
#include <algorithm>
#include <fstream>
using namespace std;

namespace Namespace_Random_Generator {
	class Random_Generator {
	public:
		inline unsigned int get_random_value() const {
			return (((rand()) & 65535UL) << 16UL) + ((rand()) & 65535UL);
		}
	};
};
using namespace Namespace_Random_Generator;
Random_Generator QQ;

int const MAX_N = 512 * 1024;
double const EPS = 1e-8;
double const PI = 3.1415926535897932384626433832795;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	double angle;
	cin >> angle;
	angle = angle / 180.0 * PI;
	double x = 0, y = 0, vx = 0, vy = 1;
	int k = 0;
	while (1) {
		x += vx;
		y += vy;
		k++;
		if (fabs(x) <= EPS && fabs(y) <= EPS)
		{
			printf("%d", k);
			break;
		}
		double new_vx = vx * cos(angle) - vy * sin(angle);
		double new_vy = vx * sin(angle) + vy * cos(angle);
		vx = new_vx;
		vy = new_vy;
	}
	return 0;
}


Measured memory_bytes: 3936
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int won = 0;
	std::string str;
	std::cin >> str;
	for(auto c : str) if(c == 'o') won++;
	if(won + 15 - (int) str.size() >= 8) {
		std::cout << "YES\n";
	} else {
		std::cout << "NO\n";
	}
}

Measured memory_bytes: 256
#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() {
  ll n, t, pt = 0, nt, ans = 0;
  cin >> n >> t;
  rep(i, n) {
    cin >> nt;
    if (nt < pt) ans -= pt - nt;
    ans += t;
    pt = nt + t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int b = 1;
    if (n % 2 == 0) {
        for (int i = 0; i < n / 2; i++) {
            if (s[i] != s[i + n / 2]) b = 0;
        }
    } else {
        b = 0;
    }

    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

ll f (ll a, ll b, ll x, ll y)
{
    ll res;
    if (x>y) 
        res = a*abs(x-y);
    else
        res = b*abs(x-y);
    return res;
}

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

    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll eq1 = a*x + b*y;
    ll eq2 = 2*c*min(x,y) + f(a,b,x,y);
    ll eq3 = 2*c*max(x,y);

    vector<ll> ans({eq1, eq2, eq3});
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
const int MX=200000;
int N, M, k, x;
int arr[MX];
int main()
{
   /// for(int i=0;i<20;i++) cout<<i%4<<" ";
    ll n, k, an=0;
    cin>>n>>k;
    for(ll b=k+1;b<=n;b++)
    {
        ll d=n/b;
        an+=d*max(0LL, b-k);
        d=n%b;
        an+=max(0LL, d-k+1);
    }
    if(!k) an=n*n;
    cout<<an<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
	long long a,b;
}NODE,*PNODE;
NODE tmp[100001];
bool mycmp(const NODE & x,const NODE & y)
{
	return x.a<y.a;
}
int main()
{
	long long n,m,i,count1=0,value=0;
	scanf("%lld %lld",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%lld %lld",&tmp[i].a,&tmp[i].b);
	}
	i=1;
	sort(tmp+1,tmp+n+1,mycmp);
	while(count1<m)
	{
		if(count1+tmp[i].b>m)
		{
			value+=(m-count1)*tmp[i].a;
			break;
		}
		else
		{
			value+=tmp[i].a*tmp[i].b;
			count1+=tmp[i].b;
			i++;
		}
	}
	printf("%lld",value);
	return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

int main(){
	while(true){
		int hand[5], res[3];
		bool latte[3] = {};
		for(int i = 0; i < 5; i++){
			cin >> hand[i];
			if(hand[i] == 0) return 0;
			hand[i]--;
			latte[hand[i]] = true;
		}
		for(int i = 0; i < 3; i++){
			if( latte[ (i+1)%3 ] && !latte[ (i+2)%3 ] ) res[i] = 1;
			else if( latte[ (i+2)%3 ] && !latte[ (i+1)%3 ] ) res[i] = 2;
			else res[i] = 3;
		}
		for(int i = 0; i < 5; i++){
			printf("%d\n", res[ hand[i] ] );
		}
	}
	return 0;
}

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

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(b<=a&&k>0)
    {
        b*=2;
        k--;
    }
    while(c<=b&&k>0)
    {
        c*=2;
        k--;
    }
    if(a<b&&b<c)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int maxn=2000100;
int dist[maxn];
vector<pair<int,int> >g[maxn];
vector<int>newg[maxn];
vector<int>all[maxn];
int was[maxn],x[maxn],ptr[maxn];
int main()
{     int n,m,i,j,k;
      scanf("%d%d",&n,&m);
      for(i=0;i<m;i++){
      	int p,q,c;
      	scanf("%d%d%d",&p,&q,&c);
      	p--;
      	q--;
      	g[p].push_back(make_pair(c,q));
      	g[q].push_back(make_pair(c,p));
      	all[c].push_back(p);
      	all[c].push_back(q);
      }
      for(i=0;i<n;i++){
      	sort(g[i].begin(),g[i].end());
      	ptr[i]=0;
      }
      for(i=0;i<n;i++){
      	was[i]=-1;
      }
      int newn=n;
      for(i=0;i<maxn;i++){
      	newg[i].clear();
      }
      for(int color=0;color<maxn;color++){
      	if(all[color].empty())
      	  continue;
      	for(int it=0;it<all[color].size();it++){
      		int v=all[color][it];
      		if(was[v]==color)
      		  continue;
      	    int b=0,e=1;
      	    x[0]=v;
      	    was[v]=color;
      	    while(b<e){
      		    while(ptr[x[b]]<g[x[b]].size()){
      			    int c=g[x[b]][ptr[x[b]]].first;
      			    if(c!=color)
      			      break;
      		        int u=g[x[b]][ptr[x[b]]].second;
      		        if(was[u]!=color){
      			      was[u]=color;
      		          x[e]=u;
      			      e++;
      		        }
      		        ptr[x[b]]++;
      	        }
      	        b++;
      	     }
             for(i=0;i<e;i++){
      	     newg[x[i]].push_back(newn);
      	     newg[newn].push_back(x[i]);
      	     }
      	     newn++;
      	}
      }
      for(i=0;i<newn;i++){
      	dist[i]=-2;
      }
      int b=0,e=1;
      x[0]=0;
      dist[0]=0;
      while(b<e){
      	for(j=0;j<newg[x[b]].size();j++){
      		int u=newg[x[b]][j];
      		if(dist[u]==-2){
      			dist[u]=dist[x[b]]+1;
      			x[e]=u;
      			e++;
      		}
      	}
      	b++;
      }
      cout<<dist[n-1]/2<<endl;
	  return 0;
}


Measured memory_bytes: 171392
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;} return res; } 
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
// Constants //
 
 
/*** Template Ends ***/
ll cache[105][100005];
ll w[105],v[105];
ll calculate(ll n,ll W)
{
    if(n<1 || W==0)
      return 0;
    if(cache[n][W]!=-1)
      return cache[n][W];
    if(w[n]<=W)
      cache[n][W]=v[n]+calculate(n-1,W-w[n]);
    cache[n][W] = max(cache[n][W],calculate(n-1,W));
    return cache[n][W];
}
void solve()
{
  ll n,wei,i,j;
  cin>>n>>wei;
  for(i=1;i<=n;i++)
    cin>>w[i]>>v[i];
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=wei;j++)
      cache[i][j]=-1;
  }
  cout<<calculate(n,wei);
}
 
int main(){ 
  ios;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
 
  return 0;
}

Measured memory_bytes: 79360
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
#define Max (int)105
#define MAX2 (int)1e5+5
#define MOD ((int)1e9+7)
using namespace std;



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

	for(i=0;i<n;i++){
		a[i] = a[i]-b[i];
	}

	sort(a,a+n);

	int diff = 0;
	for(i=n-1;i>=0;i--){
		if(a[i] <= 0)
			break;
		diff += a[i];
	}

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


}










/*
Atcoder Dp G-Longest Path iterative solution

vector<int>vec[Max];
queue<int>q;

int dp[Max];
int vis[Max];

void init(){
	int i;
	for(i=0;i<Max;i++){
		dp[i] = 0;
		vis[i] = 0;
	}
}

int getMax(int a,int b){
	return (a<b)?b:a;
}

void solve(int x){
	int i,u;
	q.push(x);

	while(!q.empty()){
		u = q.front();
		q.pop();

		if(vis[u])
			continue;
		vis[u] = 1;
		
		for(i=0;i<vec[u].size();i++){
			dp[vec[u][i]] = getMax(dp[vec[u][i]],dp[u]+1);
			q.push(vec[u][i]);
		}
	}

}

int main(){
	int n,m,incoming[Max],x,y,i;
	for(i=0;i<Max;i++)
		incoming[i] = 0;
	
	init();

	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		vec[y].push_back(x);
		incoming[x]++;
	}
	
	for(i=1;i<=n;i++)
		solve(i);
	
	int max = 0;
	for(i=0;i<Max;i++)
		max = getMax(max,dp[i]);
	
	printf("%d\n",max);
	return 0;
}
*/

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main()
{
    
    //入力
    int N;
    cin >> N;
    string S[N];
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    
    int M;
    cin >> M;
    string T[M];
    for (int i = 0; i < M; i++) {
        cin >> T[i];
    }
    
    //出力
    int result = 0;
    for (int i = 0; i < N; i++) {
        int sum = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] == S[i]) {
                sum++;
            }
        }
        for (int j = 0; j < M; j++){
            if (T[j] == S[i]) {
                sum--;
            }
        }
        result = max(result, sum);
    }
    cout << result << endl;
    
    return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  ll X, Y;
  cin >> X >> Y;
  cout << (abs(X - Y) <= 1 ? "Brown" : "Alice") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,x[100005],s,a,b;
int main(void){
    scanf("%d%d",&n,&m);
    while(m--){
		scanf("%d%d",&a,&b);
		x[a]++,x[b]++;
	}
    for(int i=1;i<=n;i++)s+=x[i]%2;
    if(s)printf("NO\n");
    else printf("YES\n");
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int MOD = 1e9 + 7;

int main() {
  int mi[200001];
  memset(mi, 0, sizeof(mi));
  int N;
  cin >> N;
  int tmp;
  rep(i, N-1) {
    cin >> tmp;
    ++mi[tmp];
  }

  rep(i, N) {
    cout << mi[i+1] << "\n";
  }
  return 0;
}


Measured memory_bytes: 4424
q,h,s,d=[int(i) for i in input().split()]
n=int(input())

qr,hr,sr,dr=q*4,h*2,s,d/2
a=[[qr,q,0.25],[hr,h,0.5],[sr,s,1],[dr,d,2]]

a.sort()
k=0
if a[0][2]<2:
  k = n * a[0][0]
else:
  k=  (n//2) * a[0][1] + (n%2) *a[1][0]
  
print(round(k))

Measured memory_bytes: 3064
s,t = gets.chomp.split(" ").map{|e|e.to_s}
a,b = gets.chomp.split(" ").map{|e|e.to_i}
u = gets.chomp.to_s

if u==s then 
	a-=1
else
	b-=1
end

print(a.to_s + " " + b.to_s)

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

int main(){
  int n;
  cin >>n;
  int64_t ans=9223372036854775807;
  vector<int>x(n);
  for(int i=0;i<n;i++){
    cin >>x.at(i);
  }
  for(int i=1;i<=100;i++){
    int64_t tmp=0;
    for(int j=0;j<n;j++){
      tmp+=(i-x.at(j))*(i-x.at(j));
    }
    if(tmp<ans)
      ans=tmp;
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 3624
from math import gcd

N = int(input())
AB = [map(int, input().split()) for _ in range(N)]

m = 1000000007

t = []
d = {}
d[0] = {}
d[0][0] = 0
for a, b in AB:
    i = gcd(a, b)
    if i != 0:
        a //= i
        b //= i
    t.append((a, b))
    d.setdefault(a, {})
    d[a].setdefault(b, 0)
    d[a][b] += 1

used = set()
result = 1
for a, b in t:
    if (a, b) in used:
        continue
    used.add((a, b))
    if a == 0 and b == 0:
        continue
    i = d[a][b]
    j, k, l = 0, 0, 0
    if -a in d and -b in d[-a]:
        j = d[-a][-b]
        used.add((-a, -b))
    if -b in d and a in d[-b]:
        k = d[-b][a]
        used.add((-b, a))
    if b in d and -a in d[b]:
        l = d[b][-a]
        used.add((b, -a))
    result *= pow(2, i + j, m) + pow(2, k + l, m) - 1
    result %= m
result += d[0][0] - 1
result %= m
print(result)


Measured memory_bytes: 151468
#include <bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
int main() {
    int n,k;
    scanf("%d",&n);
    vector<int>h(n);
    for(int& x : h)
    {
        scanf("%d",&x);
    }
    vector<int> dp(n,INF);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+2;++j)
        {
            if(j<n)
            {
              //  cout<<j<<" ** ";
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
      //  cout<<endl;
    }
    printf("%d",dp[n-1]);
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_INPUT_SIZE  1024
#define INPUT_FROM_FILE

int* createArray(int size, char* input);
void insertionSort(int size, int *array);

int
main(int argc, char* argv[])
{
    char input[MAX_INPUT_SIZE];

    int size = atoi(fgets(input, sizeof(input), stdin));
    //printf("array size : %d\n", size);

    while ((fgets(input, sizeof(input), stdin)) != NULL) {
        int* array = createArray(size, input);
        insertionSort(size, array);

        if (array != NULL) {
            delete [] array;
        }
    }

    return 0;
}


int*
createArray(int size, char* input)
{
    int* array = new int[size];

    if (array != NULL) {
        for (int i = 0; i < size; i++) {
            array[i] = i == 0 ?
                atoi(strtok(input, " ")) : atoi(strtok(NULL," "));
        }
    }

    return array;
}

void
insertionSort(int size, int *array)
{
    for (int i = 0; i < size; i++) {
        int curNum = array[i];
        for (int j = i-1; j >= 0; j--) {
            if (curNum > array[j]) {
                array[j+1] = curNum;
                break;
            } else {
                array[j+1] = array[j];
                array[j] = curNum;
            }
        }
        for (int i = 0; i < size; i++) {
            if (i != 0) printf(" ");
            printf("%d", array[i]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 1000
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt(0);
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
  }
  for(int i = 0;i<n-1;i++){
    for(int j = i+1;j<n;j++){
      cnt += a.at(i)*a.at(j);
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
int dp[100050];

int main(){
    ll N,K;
    cin >> N >> K;
    if (K % 2 != 0) {
        ll ans = N / K;
        cout << ans * ans * ans << endl;
    }
    else {
        ll hoge = N / K;
        K /= 2;
        ll ans = 0;
        for (int i = 1; i <= N; i += 2) {
            if (K * i <= N) ans++;
        }
        cout << hoge * hoge * hoge + ans * ans * ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC096D();

#if 1
int main()
{
	ABC096D();
	fflush(stdout);
	return 0;
}
#endif

template <class _T> void tp_getPrimes(_T targ, std::map<_T, _T>& primes)
{
	_T target = targ;
	_T i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;
			primes[i]++;
		}
		else {
			i++;
		}
	}
	if (target > 1) {
		primes[target]++;
	}
}

static void ABC096D()
{
	int N;
	getint(N);
	
	std::vector<int> primeNumbers;

	for (int i = 2; i <= 55555; i++) {
		std::map<int, int> primes;
		tp_getPrimes<int>(i, primes);
		if ((primes.size() == 1) && (primes.begin()->second == 1)){
			primeNumbers.push_back(primes.begin()->first);
		}
	}

	int count = 0;
	std::vector<int> ans(N);
	auto it = primeNumbers.begin();
	while ((it != primeNumbers.end()) && (count < N)) {
		if ((*it % 5) == 1) {
			ans[count] = *it;
			count++;
		}
		it++;
	}
	std::string str;
	for (int i = 0; i < N; i++) {
		char tmp[16] = { 0 };
		sprintf(tmp, "%d", ans[i]);

		if (i) {
			str += ' ';
		}
		str += tmp;
	}
	printf("%s\n", str.c_str());
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    CIN(N);
    map<int,int> mp;
    int ans=0;
    rep(i,N){
        int a;
        cin>>a;
        if(mp[a]==0) mp[a]++;
        else mp[a]--;
    }
    RepA(mp) ans+=item.second;
    printf("%d\n",ans);   

    return 0;
}

Measured memory_bytes: 4992
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll M =1e9+7;
const int N = 1e5+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

// vector<int> adj[N];
// bool vis[N]={0};

// void dfs(int x)
// {
//     vis[x]=1;
        
//     for(auto it:adj[x])   
//     if(!vis[it])
//     dfs(it);
        
// }

ll me(ll x,ll n)
{
    ll res=1;

    while(n)
    {
        if(n&1)
        res*=x;

        x=x*x;

        n/=2;
    }

    return res;


}




int main()
{

    string s;
    cin>>s;

    int k; scf(k);

    int n=s.size();

    set<string>top;  // k sized set

    rep(i,0,n)
    {

        int m=min(5,n-i);

        rep(j,1,m+1)
        {
            string x=s.substr(i,j);

            int sz=top.size();

            if(sz<k)
            top.insert(x);

            else
            {
                for(auto it:top)
            { 
                if(x<it)
                top.insert(x);

                if(top.size()>k)
                top.erase(*(top.rbegin()));// last element erased i.e k th
            }

            }


        }
    }

    auto it=(--top.end());

    

    cout<< *it;
    


    
}

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

int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int alice=0;
    int bob=0;
    for(int i=0;i<N;i+=2){
        alice+=a.at(i);
    }
    for(int i=1;i<N;i+=2){
        bob+=a.at(i);
    }
    cout<<alice-bob<<endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * Lesson9B １つのアルファベットが描かれた n 枚のカードの山をシャッフルします。 1回のシャッフルでは、下から h 枚のカードをまとめて取り出し、
 * それを残ったカードの山の上に積み上げます。 カードの山は以下のように１つの文字列で与えられます。 abcdeefab
 * 最初の文字が一番下にあるカード、最後の文字が一番上にあるカードを示しています。 例えば、これを h が 4 でシャッフルすると、最初の4文字 abcd
 * が、 残りの文字 eefab の末尾へ連結されるので以下のようになります： eefababcd このシャッフルを何回か繰り返します。
 * カードの山の最初の並び（文字列）と h の列をを読み込み、最後の並び（文字列）を出力するプログラム
 *
 * @author Internship
 *
 */
public class Main{

	/**
	 * プログラムのエントリポイント
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		// 答えの格納場所
		ArrayList<String> StringAry = new ArrayList<String>();

		// charを繋げてStrinにする
		String StrFromChar = "";

		try {
			BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));

			while (true) {

				// 1行目読み込む
				String strLine = insBR.readLine();

				if (strLine.equals("-")) {
					break;
				}

				// char型に分解
				char[] chaAryLine1 = strLine.toCharArray();

				// 入れ替え後の配列
				char[] charAfter = new char[chaAryLine1.length];

				// 2行目の読み込み
				strLine = insBR.readLine();

				// 2つ目の引数を取得
				int intNum2 = Integer.parseInt(strLine);

				// 3行目以降を読み込む
				for (int i = 0; i < intNum2; i++) {
					strLine = insBR.readLine();

					// シャフルの切れ目を取得
					int intShuffle = Integer.parseInt(strLine);

					// 入れ替え
					System.arraycopy(chaAryLine1, 0, charAfter,
							chaAryLine1.length - intShuffle, intShuffle);

					System.arraycopy(chaAryLine1, intShuffle, charAfter, 0,
							chaAryLine1.length - intShuffle);

					// 入れ替え後のcharAfterの値をchaAryLine1へコピー
					System.arraycopy(charAfter, 0, chaAryLine1, 0,
							charAfter.length);
				}

				StrFromChar = String.valueOf(charAfter);

				StringAry.add(StrFromChar);

			}

			int intSize = StringAry.size();

			// 出力
			for (int i = 0; i < intSize; i++) {
				System.out.println(StringAry.get(i));
			}

		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("数字で入力して下さい");
		}
	}
}

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

using namespace std;

bool binary_search(vector<int> &v, int t){
    bool res = false;
    int le = -1, ri = v.size(), mid = 0;
    while(le < ri){
        mid = (le + ri) / 2;
        if(v[mid] == t){
            res = true;
            return res;
        } 
        if(v[mid] > t){
            ri = mid;
        }
        if(v[mid] < t){
            le = mid + 1;
        }
    }

    if(v[mid] == t) res = true;

    return res;
}

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

    cin >> q;
    int ans = 0;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;

        if(binary_search(s, t)){
            ans ++;
        }
    }

    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 3132
from math import factorial
n,m=map(int,input().split())
p=10**9+7
if abs(n-m)>1:
  print(0)
else:
  if n==m:
    print((factorial(n)**2*2)%p)
  else:
    print((factorial(min(n,m))**2*max(n,m))%p)

Measured memory_bytes: 4732
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

int main() {
    ll N;
    cin >> N;
    vector<map<char,ll>> letter(N);
    map<char,ll> ans;
    string s;
    rep(i,N){
        cin >> s;
        ll size = s.size();
        rep(j,size){
            letter[i][s[j]]++;
        }
    }
    ans = letter[0];
    rep(i,N){
        for(auto x : ans){
            ans[x.first] = min(x.second,letter[i][x.first]);
        }
    }
    for(auto x : ans){
        rep(i,x.second){
            cout << x.first;
        }
    }
    cout << endl;
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int a, p;
  cin >> a >> p;
  cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static long MOD = 109+7;

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

        int n = sc.nextInt();

        Map<Long, Integer> map = new HashMap<>();

        for (int i = 0; i < n; i++) {
            long d = sc.nextLong();
            map.put(d, map.getOrDefault(d, 0) + 1);
        }
        TreeSet<Long> nums = new TreeSet<>(map.keySet());

        long a = -1;
        long b = -1;

        Stack<Long> stack = new Stack<>();
        for (long num: nums) {
            if(map.get(num) >= 4) {
                stack.push(num);
                stack.push(num);
            } else if(map.get(num) >= 2) {
                stack.push(num);
            }
        }

        if(stack.size() >= 2) {
            System.out.println(stack.pop() * stack.pop());
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 72896
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int N, M;
int d[1005], c[1005];
int dp[1005][1005];

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> c[i];
	}

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			dp[i][j] = 999999999;
		}
	}

	dp[0][0] = 0;

	for (int i = 1; i <= M; i++) {
		for (int j = 0; j <= N; j++) {
			if (j == 0) dp[i][j] = dp[i - 1][j];
			 else dp[i][j] = min(dp[i-1][j], dp[i-1][j-1] + c[i-1] * d[j-1]);
		}
	}

	cout << dp[M][N] << endl;


	return 0;
}



Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0);
	//freopen("in.txt", "r", stdin);
	string s;
	cin >> s;
	if(s[0] == s.back()) {
		if(s.size()%2) {
			cout << "Second" << '\n';
		} else {
			cout << "First" << '\n';
		}
	} else {
		if(s.size()%2) {
			cout << "First" << '\n';
		} else {
			cout << "Second" << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int n,m,i,j,t,r=0,b[30]={0};
  int q[30],c[30]={0};
  int d[30][30]={0};
  scanf("%d %d",&n,&m);
  while(m--){
    scanf("%d %d",&i,&j);
    d[i][j]=1;
    b[i]=1;
    c[j]++;
  }
  for(i=1;i<=n;i++){
    if(c[i]==0)q[r++]=i;
  }
  for(t=0;r-t;t++){//printf("%d\n",q[t]);
    for(i=1;i<=n;i++){
      c[i]-=d[q[t]][i];
      if(c[i]==0&&d[q[t]][i])q[r++]=i;
    }
  }
  for(t=1;b[t];t++);
  for(i=0;i<n;i++){
    if(q[i]-t)printf("%d\n",q[i]);
  }
  printf("%d\n",t);
  return 0;
}

Measured memory_bytes: 600
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] num = line.split(" ");
        int n = Integer.parseInt(num[0]);
        int l = Integer.parseInt(num[1]);
        List<String> str = new ArrayList<String>();
        for(int i = 0; i < n; i++){
            str.add(br.readLine());
        }
        Collections.sort(str);
        for(int i=0; i<n;i++){
            System.out.print(str.get(i));   
        }
    }    
}


Measured memory_bytes: 21204