akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        String c=in.next();
        int front=-1;
        int rear=-1;
        for(int i=0;i<n;i++)
        {
            if(c.charAt(i)=='W')
            {
                front=i;
                break;
            }
        }
        for(int i=n-1;i>=0;i--)
        {
            if(c.charAt(i)=='R')
            {
                rear=i;
                break;
            }
        }
        if(front==-1 || rear==-1)
            System.out.println(0);
        else
        {
            int w=0;
            int r=0;
            for(int i=front;i<=rear;i++)
            {
                if(c.charAt(i)=='W')
                    w++;
                else
                    r++;
            }
            int cnt=0;
            for(int i=front;i<front+r;i++)
            {
                if(c.charAt(i)=='W')
                    cnt++;
            }
            System.out.println(cnt);
        }
            
    }
}

Measured memory_bytes: 40908
#include <iostream>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=(a),i##Len_=(b);i<i##Len_;i++)
 


map<ll, ll> acnt;
int main()
{
	ll N;
	cin >> N;

	string res = "No";

	vector <ll> a(N,0);

	bool zeroari = false;
	bool allzero = true;
	REP(i,N)
	{
		cin >> a[i];
		acnt[a[i]]++;
		
		if(a[i] != 0)
		{
			allzero = false;
		}
		else
		{
			zeroari = true;
		}
	}

	if(allzero)
	{
		cout << "Yes" << endl;
		return 0;
	}


	//3で割り切れなければ満たせない
	if(N % 3 == 0)
	{
		ll Nb3 = N/3;

		if(zeroari)
		{
			//zero-> Nb3枚
			REP(i,N)
			{
				if(a[i] != 0)
				{
					ll x = a[i];
					if(acnt[x] == 2 * Nb3 && acnt[0] == Nb3)
					{
						res = "Yes";
					}
					break;
				}
			}
		}
		else
		{
			// x と y と x^y
			REP(i,N)
			{
				if(a[0] != a[i])
				{
					ll x = a[0];
					ll y = a[i];
					ll z = x^y;

					if(acnt[x] == Nb3 && acnt[y] == Nb3 && acnt[z] == Nb3)
					{
						res = "Yes";
					}
					break;
				}
			}
		}
	}
	cout << res << endl;

	return 0;

}

Measured memory_bytes: 5632
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=len(set(a))
b=dict(Counter(a).most_common())
d=list(b.values())
d.sort()
if c<=k:
    print(0)
else:
    tmp=c-k
    ans=0
    for i in range(tmp):
        ans+=d[i]
    print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> H;
  
  int result = 1;
  int h;
  cin >> h;
  H.push_back(h);
  for (int i = 1; i < N; i++) {
    cin >> h;
    int tmp = 1;
    for (int j = 0; j < H.size(); j++) {
      if (h < H[j]) tmp = 0;
    }
    result += tmp;
    H.push_back(h);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    unsigned long long N; cin >> N;

    unsigned long long ans = N*(N-1)/2;
    if (N == 1) {
        ans = 0;
    } else if (N == 2) {
        ans = 1;
    }

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

Measured memory_bytes: 256
n = int(input())
a = [list(input().split()) for i in range(n)]
result = 0
for i in range(n):
    b = a[i]
    if b[1] == "JPY":
        result += int(b[0])
    else:
        result += float(b[0]) * 380000.0
print(result)


Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Stellar Performance of the Debunkey Family (Prim)
 */
public class Main {

	static Main main = new Main();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0 0")) {

			int n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int m = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			Graph graph = main.new Graph(n);

			for (int i = 0; i < m; ++i) {
				graph.addEdge(br.readLine());
			}
			System.out.println(graph.prim());

		}

	}

	class Graph {

		final int INFINITY = Integer.MAX_VALUE;
		final int UNREACHABLE = -1;

		int length;
		int[][] adjacency;

		Graph(int n) {

			length = n;
			adjacency = new int[length][length];
			for (int i = 0; i < length; ++i) {
				for (int j = 0; j < length; ++j) {
					adjacency[i][j] = INFINITY;
				}
			}

		}

		void addEdge(String info) {

			StringTokenizer st = new StringTokenizer(info);
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());

			adjacency[a][b] = c;
			adjacency[b][a] = c;

		}

		int prim() {

			boolean[] checked = new boolean[length];
			int total, next;

			next = 0;
			total = 0;
			checked[next] = true;

			while (next != UNREACHABLE) {

				next = -1;
				int min = INFINITY;
				for (int i = 0; i < length; ++i) {
					if (checked[i]) {
						for (int j = 0; j < length; ++j) {
							if (!checked[j] && min > adjacency[i][j]) {
								min = adjacency[i][j];
								next = j;
							}
						}
					}
				}
				if (next != UNREACHABLE) {
					total += min;
					checked[next] = true;
				}
			}
			return total;
		}

	}

}

Measured memory_bytes: 19564
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  string S;
  cin >> S;
  int S_length = 4;
  int cnt = 0;

  rep(i, S_length) {
    if(S[i] == '+') ++cnt;
    else --cnt;
  }

  cout << cnt << endl;

  return 0;
}


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

int main(){
int n;
cin >> n;
int m;
cin >> m;
int a[2*n];
int b[m];
int e[2*n];
int c;
int d;
c=0;
while(c<2*n){
a[c]=c;
c=c+1;}
c=0;
while(c<m){
cin >>b[c];
c=c+1;}
c=0;
while(c<m){
d=0;
if(b[c]==0){ while(d<2*n){if(d%2==0){e[d]=a[d/2];} else{e[d]=a[(d-1)/2+n];} d=d+1; } }

else{ while(d<2*n){ if(d<2*n-b[c]){e[d]=a[d+b[c]];} else{e[d]=a[d-2*n+b[c]];} d=d+1; } }

d=0;
while(d<2*n){
a[d]=e[d];
d=d+1;
}

c=c+1;
}

c=0;
while(c<2*n){
cout << a[c]+1<<endl;
c=c+1;
}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define SIZE 1001
int h,w,k,ans=0;
int s[100][100];

int wdfs(int i){
  //cout<<"wi"<<i<<endl;
  if(i==w){
    int count=0;
    REP(ii,h) REP(jj,w) if(s[ii][jj]==1) count++;
    if(count==k) ans++;
    /*REP(ii,h){
      REP(jj,w) cout<<s[ii][jj];
      cout<<endl;
    }*/
  }else{
    wdfs(i+1);
    int tt[100];
    REP(jj,h){
      tt[jj]=s[jj][i];
      s[jj][i]=2;
    }
    wdfs(i+1);
    REP(jj,h) s[jj][i]=tt[jj];
  }
  return 0;
}

int hdfs(int i){
  //cout<<"hi"<<i<<endl;
  if(i==h) wdfs(0);
  else{
    hdfs(i+1);
    int tt[100];
    REP(ii,w){
      tt[ii]=s[i][ii];
      s[i][ii]=2;
    }
    hdfs(i+1);
    REP(ii,w) s[i][ii]=tt[ii];
  }
  return 0;
} 

int main(){
  cin>>h>>w>>k;
  REP(i,h) REP(j,w){
    char tmp;cin>>tmp;
    if(tmp=='.') s[i][j]=0;
    else s[i][j]=1;
  }
    
  hdfs(0);
  cout<<ans;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#define D 1000000007
int main()
{
    long m,n,i;
    long long *x,*y;
    unsigned long long w=0,h=0;
    scanf("%ld %ld",&n,&m);
    x=(long long *)malloc(sizeof(x)*n);
    y=(long long *)malloc(sizeof(y)*m);
    for(i=0;i<n;i++){
        scanf("%lld",&x[i]);
        w+=i*x[i]-(n-i-1)*x[i];
    }
    w%=D;
    for(i=0;i<m;i++){
        scanf("%lld",&y[i]);
        h+=i*y[i]-(m-i-1)*y[i];
    }
    h%=D;
    printf("%lld\n",w*h%D);
    free(x);
    free(y);
    return 0;
}

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

int main(){
    int a[3],b,c,d;
    cin >> a[0] >> a[1] >> a[2];
    for(int i=0; i<3; i++){
        int v=a[i];
        int j = i-1;
        while(a[j]>v&&j>=0){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
    }
    for(int i=0; i<2; i++)cout << a[i] << " ";
    cout << a[2] << endl;
    return 0;
}


Measured memory_bytes: 3072
import java.math.BigDecimal
import java.util.*

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val d = sc.nextInt()

    val a: List<List<Int>> = (1..n).map {
        sc.asSequence().take(d).map(String::toInt).toList()
    }.toList()

    var r = 0;
    a.forEachIndexed { i, iL ->
        for (j in i + 1 until n) {
            val jL = a[j]
            val x: Int = (0 until d).map { iL[it] - jL[it] }.map { it * it }.sum()
            val y = Math.sqrt(x.toDouble())
            if (Math.floor(y) == y) r++
        }
    }

    println(r)
}


Measured memory_bytes: 33632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
#define int ll
signed main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n+1), b(m+1);
    a[0] = b[0] = 0;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= m; ++i) cin >> b[i];
    for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
    for (int i = 1; i <= m; ++i) b[i] += b[i - 1];
    int ai = 0, bi = 0, r=0;
    while (ai + 1 <= n && a[ai + 1] <= k) ++ai;
    for (int i = ai; i >= 0; --i) {
        while (bi + 1 <= m && b[bi + 1] + a[i] <= k) ++bi;
        r = max(r, i + bi);
    }
    cout << r;
}

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

int main() {
  
  int N,K;
  cin >> N >> K;
  
  
  int count=1;
  
  while(N>=K) {
   N/=K;
    count++;
  }
  
  cout << count << endl;
}
    
    
    

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

int main(){
  int n;
  cin >> n;
  double c[n-1], s[n-1], f[n-1], ans[n];
  for ( int i = 0; i < n-1; i++){
    cin >> c[i] >> s[i] >> f[i];
  }
  for ( int i = 0; i < n-1; i++){
    ans[i] = s[i]+c[i];
    for ( int j = i+1; j < n-1; j++){
      if ( ans[i] >= s[j]){
        ans[i] = s[j] + f[j] * ceil((ans[i] - s[j]) / f[j]) + c[j];
      } else {
        ans[i] = s[j] + c[j];
      }
    }
  }
  ans[n-1] = 0;

  for ( int i = 0; i < n; i++){
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  string t;
  cin >> t;
  int n = t.size();

  int sum = 0;
  rep(i,n) {
    if (t[i] == '?') t[i] = 'D';
  }
  cout << t << endl;
}


Measured memory_bytes: 3760
#include <bitset>
#include <iostream>

void getResult(const int n) {
  if (n == 0) {
    std::cout << 0 << std::endl;
    return;
  }
  const bool is_plus = (n >= 0);
  std::bitset<32> normal_bits(static_cast<unsigned long long>(std::abs(n)));
  std::bitset<34> minus_bits;
  if (is_plus) {
    for (int i = 0; i < 32; ++i) {
      if (normal_bits[i]) {
        if (i % 2 == 0) {
          if (minus_bits[i]) {
            minus_bits.reset(i);
            minus_bits.set(i + 1);
            minus_bits.set(i + 2);
          } else {
            minus_bits.set(i);
          }
        } else {
          if (!minus_bits[i] && !minus_bits[i + 1]) {
            minus_bits.set(i);
            minus_bits.set(i + 1);
          } else if (minus_bits[i] && minus_bits[i + 1]) {
            minus_bits.reset(i);
            minus_bits.set(i + 1);
          }
        }
      }
    }
  }
  else {
    for (int i = 0; i < 32; ++i) {
      if (normal_bits[i]) {
        if (i % 2 == 1) {
          if (minus_bits[i]) {
            minus_bits.reset(i);
            minus_bits.set(i + 1);
            minus_bits.set(i + 2);
          }
          else {
            minus_bits.set(i);
          }
        }
        else {
          if (!minus_bits[i] && !minus_bits[i + 1]) {
            minus_bits.set(i);
            minus_bits.set(i + 1);
          }
          else if (minus_bits[i] && minus_bits[i + 1]) {
            minus_bits.reset(i);
            minus_bits.set(i + 1);
          }
        }
      }
    }
  }
  bool shown = false;
  for (int i = 33; i >= 0; --i) {
    if (minus_bits[i]) {
      std::cout << 1;
      shown = true;
    }
    else if (shown) {
      std::cout << 0;
    }
  }
  std::cout << std::endl;
}

int main() {
  int n;
  std::cin >> n;
  getResult(n);
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(3e5 + 5)];

ll Bit[62], cnt0[62], cnt1[62];

int main(){
  Bit[0] = 1;
  for (int i = 1; i < 62; i++){
    Bit[i] = Bit[i-1] * 2;
    Bit[i] %= MOD;
  }

  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    scanf("%lld", A + i);

    ll num = A[i];
    for (int j = 0; j < 62; j++){
      if (num % 2 == 0) cnt0[j]++;
      else cnt1[j]++;
      num /= 2;
    }
  }

  ll ans = 0;
  for (int i = 0; i < 62; i++){
    ll now = cnt0[i] * cnt1[i] % MOD;
    ans += Bit[i] * now;
    ans %= MOD;
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 6096
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;
	n %= 1000;
	int ans  = (1000 - n) % 1000;
	cout << ans << "\n";
	return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);



int main(void)
{
    IOS
    string s;
    cin >> s;

    if (s.length() == 1) {
        cout << 0 << endl;
        return 0;
    }
    
    int l = s.length();
    int count = 0;
    for(auto i = 0; i < l-1; i++)
    {
        if (s[i] == s[i+1]) {
            if (s[i] == '0') s[i+1] = '1';
            if (s[i] == '1') s[i+1] = '0';
            count++;
        }
    }
    
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

const int MAX_N = 300000;
vector<int> prime;
void setPrime(int n) {
    vector<bool> alive(n, true);
    alive[0] = alive[1] = false;
    rep2(i, 2, n + 1) {
        if (alive[i]) {
            prime.emplace_back(i);
            for (int j = 2 * i; j <= n; j += i) {
                alive[j] = false;
            }
        }
    }
}

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

    setPrime(MAX_N);
    int n, p;
    while (cin >> n >> p, n != -1) {
        int s = upper_bound(all(prime), n) - prime.begin();
        vector<int> cand;
        rep(i, 100) {
            rep2(j, i, 100) {
                cand.emplace_back(prime[s + i] + prime[s + j]);
            }
        }
        sort(all(cand));
        cout << cand[p-1] << endl;
    }

}

Measured memory_bytes: 3244
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
int a[205];
/**********************************************/

int main(){
    cin >> n;
    REP(i, n){
        cin >> a[i];
    }
    int ans = 0;
    while(1){
        bool flag = false;
        REP(i, n){
            if(a[i] % 2 == 0) a[i] /= 2;
            else flag = true;;
        }
        if(flag) break;
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
using namespace std;
const int maxx = 100010;
const int INF = 1 << 30;

vector<int>G[maxx];
list<int>out;
bool flag[maxx];
int n;
int indeg[maxx];

void bfs(int s) {
	queue<int> q;
	q.push(s);

	while (!q.empty()) {
		int u = q.front(); q.pop();
		out.push_back(u);
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]--;
			if (indeg[v] == 0 && flag[v] == 0) {
				flag[v] = true;
				q.push(v);
			}
		}
	}
}

void tsort() {
	for (int i = 0; i < n; i++) {
		indeg[i] = 0;
		flag[i] = false;
	}

	for (int u = 0; u < n; u++) {
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]++;
		}
	}


	for (int u = 0; u < n; u++) {
		if (indeg[u] == 0 && flag[u] == 0)
			bfs(u);
	}

	for (list<int>::iterator it = out.begin(); it != out.end(); it++)
		printf("%d\n", *it);
}
int main()
{
	int s, t, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &s, &t);
		G[s].push_back(t);
	}

	tsort();
	return 0;
}

Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
int main( void ){
	int N; cin >> N;
	map<int, int> mp;
	rep(i,0,N){
		int input; cin >> input;
		mp[min(input/400, 3200/400)]++;
	}
	int ans = 0, up = 0;
	for(auto m:mp){
		if (m.first != 8)
			ans++;
		else{
			up = m.second;
			if (ans == 0){
				ans++;
				up--;
			}
		}
	}
	cout << ans << " " << ans+up << endl;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

int main() {
    string s;
    cin>>s;
    bool check[26]={false};
    int ans=10000;
    if(s.length()==1){
        cout<<0<<endl;
        return 0;
    }

    for(int i=1;i<s.length();i++){
        if(check[s[i]-'a']) continue;
        check[s[i]-'a']=true;
        bool complete=false;
        int times=-1;
        string t=s;
        char target=s[i];
        while(!complete){
            complete=true;
            for(int j=0;j<t.length()-1-times;j++){
                if(t[j]!=target) complete=false;
                if(t[j+1]==target) t[j]=target;
            }
            times++;
        }
        ans=min(ans,times);
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef struct edge{
    int to, cap, rev;
    edge(int t, int c, int r){
        to = t; cap = c; rev = r;
    }
}edge;

vector<edge> G[210];
bool used[210];

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

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

int max_flow(int s, int t){
    int flow = 0;
    while(true){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, 100000);
        if(f == 0) return flow;
        flow += f;
    }
}

int main(){
    int n; cin >> n;
    rep(i, n){
        add_edge(0, i+1, 1);
        add_edge(n+i+1, 2*n+1, 1);
    }
    int a[n], b[n], c[n], d[n];
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n) cin >> c[i] >> d[i];
    rep(i, n)rep(j, n)if(a[i] < c[j] && b[i] < d[j]) add_edge(i+1, n+j+1, 1);
    cout << max_flow(0, 2*n+1) << endl;
}

Measured memory_bytes: 384
N, K=map(int, input().split())
A=list(map(int, input().split()))
A=[-1]+A

machi=[-1]*(N+1)
counter=0
basyo=1
while counter<K:
  counter+=1
  basyo=A[basyo]
  if machi[basyo]==-1:
    machi[basyo]=counter
  else:
    tmp=counter-machi[basyo]
    counter+=((K-counter)//tmp)*tmp
    
print(basyo)

Measured memory_bytes: 32308
#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 x, n;
  cin >> x >> n;
  vector<int> v(102);
  rep(i, n){
    int p;
    cin >> p;
    v[p] = 1;
  }
  P ans(99999, -1);
  for(int i = 0; i <= 101; ++i){
    if(v[i] == 1) continue;
    int dif = abs(x-i);
    ans = min(ans, P(dif, i));
  }
  cout << ans.second << endl;
}


Measured memory_bytes: 3628
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int lli;

int main(){
    
    fastio
    lli x, y, z;
    cin >> x >> y >> z;
    lli s = x + y + z;
    puts(s >= 22?"bust" :"win");

    return 0;
}




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

long long dp[1004][1004];
const long long mod=1000000007;
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
      char tmp;cin>>tmp;
      if(tmp=='#')dp[i][j]=-1;
    }
  dp[1][1]=1;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
      if(dp[i][j]==-1||(i==1&&j==1))continue;
      dp[i][j]=(dp[i-1][j]==-1?0:dp[i-1][j])+(dp[i][j-1]==-1?0:dp[i][j-1]);
      dp[i][j]=dp[i][j]%mod;
    }
  cout<<dp[n][m]<<endl;
  return 0;
}


Measured memory_bytes: 8064
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  int n;
  cin >> n;
  vector<int> a(n);
  bool thereis1 = false;
  rep(i,n) {
    cin >> a[i];
    if(a[i] == 1) thereis1 = true;
  }

  if(!thereis1) { cout << -1 << endl; return 0; }

  int res = 0, idx = 1;
  rep(i,n) {
    if(a[i] == idx) idx++;
    else res++;
  }
  cout << res << endl;
  return 0;
}

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

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

    vector<int> A(N);
    vector<int> B(N);
    string ans = "No";

    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i) >> B.at(i);
    }

    for (int i = 0; i < N - 2; i++)
    {
        if (A.at(i) == B.at(i) && A.at(i + 1) == B.at(i + 1) && A.at(i + 2) == B.at(i + 2))
        {
            ans = "Yes";
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <ios>
#include <iostream>

//going only up, can we reach the goal exactly?

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    int n;
    long long int a, a2, b, c, d;
    std::cin >> n >> a >> b >> c >> d;
    //can we do a -> b going only up?
    if (a+(n-1)*c <= b && b <= a+(n-1)*d)
        std::cout << "YES\n";
    else if (a+(n-1)*d < b)
        std::cout << "NO\n";
    else
    {
        n--;
        a2 = a;
        bool ok = false;
        while (n-1 >= 0)
        {
            a -= d;
            a2 -= c;
            if (a+(n-1)*c <= b && b <= a2+(n-1)*d)
                ok = true;
            n--;
        }
        std::cout << (ok ? "YES" : "NO") << '\n';
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

int main(void){
  string s, t;
  cin >> s >> t;

  int n = s.size();
  int m = t.size();
  vector<vector<int>> is(26);
  REP(i, n) is[s[i] - 'a'].emplace_back(i);
  REP(i, n) is[s[i] - 'a'].emplace_back(i+n);

  ll ans = 0;
  int p = 0;
  REP(i, m){
    int c = t[i] - 'a';
    if(is[c].empty()){
      cout << -1 << endl;
      return 0;
    }
    p = *lower_bound(ALL(is[c]), p)+ 1;
    if(p >= n){
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}

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

int main() {
	int N, R;
	cin >> N >> R;
	if (N >= 10) {
	    cout << R << endl;
	}
	else {
	    cout << (R + ((10 - N) * 100)) << endl;
	}
	return 0;
}


/*
mod = 1e9+7
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    N, R = [int(x) for x in raw_input().split()]
    
    if N >= 10:
      print(R)
    else:
      print(R + ((10 - N) * 100))
    
    

main()
*/

Measured memory_bytes: 3560
import java.util.Scanner;

public class Main {

	public static long CONST = (long) Math.pow(10, 9) + 7L;

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int S = scan.nextInt();
		int W = scan.nextInt();

		//WK変数

		//演算

		//結果出力
		System.out.println(S > W ? "safe" : "unsafe");
	}
}

Measured memory_bytes: 35836
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(b%a == 0){
			System.out.print(a+b);
		}else{
			System.out.print(b-a);
		}
	}
}


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

typedef long long ll;
const ll mod = 1e9+7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int n;
    cin >> n;
    
    ll inv[n+1];
    for(int i = 1; i <= n; i++) inv[i] = modpow(i, mod-2, mod);

    // frac[i] := \sum_i=1^n{1/i}
    ll frac[n+1];
    frac[0] = 0;
    for(int i = 1; i <= n; i++){
        frac[i] = (frac[i-1] + inv[i])%mod;
    }

    // fact := n!
    ll fact = 1;
    for(int i = 2; i <= n; i++) fact = (fact*i)%mod;
    
    ll ans = 0;
    ll a;

    for(int i = 0; i < n; i++){
        cin >> a;
        ans += (a * (frac[i+1]+frac[n-i]-1))%mod;
        ans %= mod;
    }

    cout << (ans*fact)%mod << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
int r,d,x; cin>>r>>d>>x;
  rep(i,10) {
    cout<<r*x-d<<endl;
    x=r*x-d;
  }
}


Measured memory_bytes: 256
N=int(input())
mod=10**9+7
X=[-1]*N
for i,a in enumerate(map(int,input().split())):
    if i==0:
        X[0]=a
    else:
        X[i]=X[i-1]^a
if X[-1]>0:
    x=X[-1]
    dp0=1
    dp1=0
    zero=0
    for i in range(N):
        if X[i]==x:
            dp0=(dp0+dp1*zero)%mod
            zero=0
            dp1=(dp1+dp0)%mod
        elif X[i]==0:
            zero+=1
        
    print(dp0)
    exit()
from collections import defaultdict
dp0=defaultdict(lambda :1)
dp1=defaultdict(int)
zero=defaultdict(int)
zeronow=0
for i in range(N-1):
    x=X[i]
    if x>0:
        dp0[x]=(dp0[x]+dp1[x]*(zeronow-zero[x]))%mod
        zero[x]=zeronow
        dp1[x]=(dp1[x]+dp0[x])%mod
    elif x==0:
        zeronow+=1

print((sum(dp1.values())+pow(2,zeronow,mod))%mod)

Measured memory_bytes: 73480
#include <iostream>
using namespace std;
int main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    if (A + B < C + D) printf("%s\n", "Right");
    else if (A + B == C + D) printf("%s\n", "Balanced");
    else printf("%s\n", "Left");
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  vector<string> grid(8);
  REP(i,8)cin>>grid[i];
  cout<<90<<endl;
  REP(y,8){
    REP(x,8){
      cout<<grid[7-x][y];
    }
    cout<<endl;
  }
  cout<<180<<endl;
  REP(y,8){
    REP(x,8){
      cout<<grid[7-y][7-x];
    }
    cout<<endl;
  }
  cout<<270<<endl;
  REP(y,8){
    REP(x,8){
      cout<<grid[x][7-y];
    }
    cout<<endl;
  } 
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static int n, k;
	static int[] array;

	public static boolean canLoad(int p) {//仮にpを最大値に設定して運べるかどうか
		int packages = 0, truck = 0, weightSum;
		while (packages < n && truck < k) {//n個の荷物をk個のトラックで運ぶ
			weightSum = 0; //新しいトラックになるので荷物の合計を０に
			while(packages < n && weightSum + array[packages] <= p) {//packages番目の荷物を載せられるか
				weightSum += array[packages];
				packages++;
			}
			truck++;//今のトラックがいっぱいになったので次のトラックへ
		}
		if(packages == n) {//n個の荷物がトラックに載っていたら
			return true;
		} else {
			return false;
		}
	}

	public static void main(String[] args) {
		BufferedReader br =
			new BufferedReader(new InputStreamReader(System.in));
		try {
			String[] strings = br.readLine().split(" ");
			n = Integer.parseInt(strings[0]);
			k = Integer.parseInt(strings[1]);
			array = new int[n];
			for(int i = 0; i < n; i++) {
				array[i] = Integer.parseInt(br.readLine());
			}
			int left = 0;
			int right = 100000 * 10000;//nの最大値100000 * wの最大値10000 がpがとりうる最大値
			int mid = (left + right) / 2;
			int p = 100000 * 10000; //とりあえず最大値にしておく
			while(left <= right) {//2分探索
				if(canLoad(mid)) {
					p = mid; //運べたのでpを更新
					right = mid - 1;//運べたのでもっと小さいpでいけるかもしれない
					mid = (left + right) / 2;
				} else {
					left = mid + 1;//運べなかったのでもっと大きいpが必要
					mid = (left + right) / 2;
				}
			}
			System.out.println(p);
		} catch(NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 35460
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n, m, x;
	lli cheep = INF;
	cin >> n >> m >> x;
	vector<lli> c(n);
	lli a[n][m];

	rep(i,n){
		cin >> c[i];
		rep(j,m) cin >> a[i][j];
	}
	rep(bit, 1<<n){
		vector<lli> ans(m);
		lli cost = 0;
		rep(i,n){
			if(bit&(1<<i)){
				cost += c[i];
				rep(j,m) ans[j] += a[i][j];
			}
		}
		if(*min_element(all(ans)) >= x){
			cheep = Min(cheep, cost);
		}
	}
	if(cheep == INF) cout << "-1" << endl;
	else cout << cheep << endl;
	return 0;
}

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

using namespace std;

using int64 = long long;

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

  int k, x;
  cin >> k >> x;

  for (int i= -1000000; i <= 1000000; i++) {
    if (abs(i - x) <= k - 1) {
      cout << i << " ";
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;
long long int Z = 0;
long long int Y = 0;

int positive(int X) {

	if (X <= 0) {
		 while(X<=0) {
			Z++;
			X++;
		}
	}
	return X;
}

int negative(int X) {

	if (X >= 0) {
		while (X>=0){
			Z++;
			X--;
		}
	}
	return X;
}

int main() {
	long long int U;
	int N;
	cin >> N;
	long long int A[100008];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	
	
		for (int i = 0; i < N ; i++) {
			Y += A[i];
			if(i%2==0)Y=positive(Y);
			else Y=negative(Y);
			
		}
	
		U = Z;
		 Y = 0;

		 Z = 0;
		for (int i = 0; i < N; i++) {
			Y += A[i];
			if (i % 2 != 0)Y = positive(Y);
			else Y = negative(Y);
			
		}

		if (Z < U) {
			cout << Z<< endl;
		}
		else {
			cout << U << endl;
		}

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    sort(S.begin(), S.end());
    if(S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
k = int(input())

nums = [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]

print(nums[k-1])



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI 2*acos(0.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define rt return true
#define rf return false
///................function.....................///
#define siz(s) (int)(s.size())
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define dbg(a) cout << #a << " = " << a << " ";
///...........knight moves.....................///
///int dx[] = {+1,+1,-1,-1,+2,+2,-2,-2};
///int dy[] = {+2,-2,+2,-2,+1,-1,+1,-1};

int main()
{
    FIO;
    ll n,m,w;
    cin>>n>>m>>w;
    vll row(n+1),col(m+1);
    ll a,b;
    map<pii,bool>point;
    for(ll i=0; i<w; i++)
    {
        cin>>a>>b;
        point[{a,b}]=true;
        row[a]++;
        col[b]++;
    }
    ll mxr1=0,mxrow1=0,i,j;
    ll tmp=0;
    for(i=1; i<=n; i++)
    {
        if(mxrow1<row[i])
        {
            mxrow1=row[i];
            mxr1=i;
        }
    }
    ll mxc1=0,mxcol1=0;
    for(i=1; i<=m; i++)
    {
        (point[{mxr1,i}])?tmp=1:tmp=0;
        if((col[i]-tmp)>mxcol1)
        {
            mxcol1=col[i]-tmp;
            mxc1=i;
        }
    }
    (point[{mxr1,mxc1}])?tmp=1:tmp=0;
    ll mxnow=mxrow1+mxcol1-tmp;
    ll r1=mxr1,c1=mxc1;
    mxr1=mxrow1=mxc1=mxcol1=0;
    for(i=1; i<=m; i++)
    {
        if(mxcol1<col[i])
        {
            mxcol1=col[i];
            mxc1=i;
        }
    }
    for(i=1; i<=n; i++)
    {
        (point[{i,mxc1}])?tmp=1:tmp=0;
        if((row[i]-tmp)>mxrow1)
        {
            mxrow1=row[i]-tmp;
            mxr1=i;
        }
    }
    (point[{mxr1,mxc1}])?tmp=1:tmp=0;
    cout<<max(mxnow,row[mxr1]+col[mxc1]-tmp)<<endl;

}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


void Dijkstra(int s, const vector<vector<P>> &g, vi &dis) {
  priority_queue<P, vector<P>, greater<P>> que; // pair = (cost, v);
  dis[s] = 0;
  que.emplace(0,s);
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int now = p.second;
    if(dis[now] < p.first) continue;
    for(P np : g[now]) {
      int next = np.second;
      if(dis[next] > dis[now] + np.first) {
        dis[next] = dis[now] + np.first;
        que.emplace(dis[next], next);
      }
    }
  }
}


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

  int n, m, r;
  cin >> n >> m >> r;
  vi city(r);
  rep(i,r) {
    cin >> city[i];
    city[i]--;
  }
  vector<vector<P>> g(n); // pair = (cost, to);
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    g[a].emplace_back(c,b);
    g[b].emplace_back(c,a);
  }

  vii dist(n, vi(n,inf));
  rep(i,r) {
    int s = city[i];
    dist[s][s] = 0;
    Dijkstra(s, g, dist[s]);
  }

  sort(all(city));
  
  int ans = inf;
  do {
    int tmp = 0;
    REP(i,r) {
      tmp += dist[city[i]][city[i-1]];
    } 
    ans = min(ans, tmp);
  } while(next_permutation(all(city)));

  cout << ans << endl;
}


Measured memory_bytes: 896
N, M = map(int,input().split())
X = list(map(int,input().split()))
D = [ [] for _ in range(M+1) ]
for x in X:
  D[ x % M ].append(x)
ans = 0

import collections
def count_pair(A):
  res = 0
  c = collections.Counter(A)
  for k, v in c.items():
    res += v // 2
  return res

ans += len(D[0]) // 2
for x in range(1, M):
  y = M - x
  if x < y:
    D[x].sort()
    D[y].sort()
    g = min(len(D[x]), len(D[y]))
    ans += g
    if len(D[x]) > len(D[y]):
      ans += min((len(D[x]) - g) // 2, count_pair(D[x]))
    else:
      ans += min((len(D[y]) - g) // 2, count_pair(D[y]))
  if x == y:
    ans += len(D[x]) // 2
print(ans)

Measured memory_bytes: 19072
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
i = -2
for a in A:
    ans += B[a-1]
    if a == i + 1:
        ans += C[i-1]
    i = a
print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
int main(){
	int N;
	cin>>N;
	string S;
	cin>>S;
	if(N%2){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<N/2;i++){
		if(S[i]!=S[i+N/2]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    ll vi; 
    map<ll, ll> V1, V2;
    for(int i=0;i<N;i++){
        cin >> vi;
        if(i%2==0){
            if(V1.count(vi)==0) V1[vi] = 0;
            V1[vi]++;
        }else{
            if(V2.count(vi)==0) V2[vi] = 0;
            V2[vi]++;
        }   
    }   
    array<ll, 2> v1_max1 = {-1, 0};
    array<ll, 2> v1_max2 = {-1, 0};
    array<ll, 2> v2_max1 = {-1, 0};
    array<ll, 2> v2_max2 = {-1, 0};
    for(auto m : V1){
        if(v1_max1[1] < m.second){
            v1_max2 = v1_max1;
            v1_max1 = {m.first, m.second};
        }else if(v1_max2[1] < m.second){
            v1_max2 = {m.first, m.second};
        }   
    }   
    for(auto m : V2){
        if(v2_max1[1] < m.second){
            v2_max2 = v2_max1;
            v2_max1 = {m.first, m.second};
        }else if(v2_max2[1] < m.second){
            v2_max2 = {m.first, m.second};
        }   
    }   
    if(v1_max1[0] != v2_max1[0]){
        cout<<(N-v1_max1[1]-v2_max1[1])<<endl;
    }else{
        auto n1 = N - v1_max1[1] - v2_max2[1];
        auto n2 = N - v1_max2[1] - v2_max1[1];
        cout<<min(n1, n2)<<endl; 
    }   

    return 0;
}   

Measured memory_bytes: 6528
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	e = [Int[] for i in 1:n]
	for i in 1:m
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
	end
	f = 0
	for i in e[1]
		for j in e[i]
			if j==n
				f = 1
				break
			end
		end
	end
	println(f==1?"POSSIBLE":"IMPOSSIBLE")
end

main()

Measured memory_bytes: 159956