akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<cstring>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<string>
#include<ctime>
//#include "optimization.h"
#include<bitset>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
typedef long long ll;
using namespace std;
const int N =  3e5 +100;
ll INF = (1LL << 62) - 1;
ll MOD = 1e9 + 7;
ll dp[1000][3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    ll ans = 0;
    dp[0][0] = 1;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++)
    {
        int k =  a[i] % 2;
        if(k == 0)
        {
            dp[i + 1][k + 1] = dp[i][k] + 3 * dp[i][k + 1];
            dp[i + 1][k] = 2 * dp[i][k];
        }
        else
        {
            dp[i + 1][k] = 2 * dp[i][k - 1] + 3 * dp[i][k];
            dp[i + 1][k - 1] = dp[i][k - 1];

        }
        ans = dp[n][1];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   int n;
   cin >> n;
   
   long long ans = 0;
   for(int i=1; i<=n; i++){
      if(i%3!=0 && i%5!=0){
         ans += i;
      }
   }
   
   cout << ans << endl;
   
   return 0;
}

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

int Socket(int A, int B){
    int num_socket=0;
    int socket=1;
    while(socket<B){
        socket += A-1;
        num_socket++;
    }
    return num_socket;
}

int main(){
    int A, B; cin >> A >> B;
    cout << Socket(A,B) << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC151C()
{
	int N, M;
	cin >> N >> M;
	vi A(N);
	vi B(N);
	int t = 0;
	for (int i = 0; i < M; ++i)
	{
		int p;
		string s;
		cin >> p >> s;
		--p;
		if (s == "WA")
		{
			if (A[p] >= 0)
			{
				++B[p];
			}

		}
		else
		{
			if(A[p] >= 0)
				++t;
			A[p] = -1;
		}
	}
	int wa = 0;
	for (int i = 0; i < N; ++i)
	{
		if (A[i] == -1)
			wa += B[i];
	}

	cout << t << ' ' << wa << endl;
}


int main()
{
	ABC151C();
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long w = sc.nextInt();
		long h = sc.nextInt();
		
		if(w%3==0 || h%3==0)
			System.out.println(0);
		else
			System.out.println(Math.min(solve(w, h), solve(h, w)));

	}
	static long solve(long w, long h){
		long min = Long.MAX_VALUE;
		for(int i=1;i<h;i++){
			long a = w*i;
			long b = 0, c = 0;
			if(w%2==0){
				b = w/2*(h-i);
				c = b;
				min = Math.min(min, Math.max(a, Math.max(b, c))-Math.min(a, Math.min(b, c)));
			}
			else if((h-i)%2==0){
				b = w*((h-i)/2);
				c = b;
				min = Math.min(min, Math.max(a, Math.max(b, c))-Math.min(a, Math.min(b, c)));
			}
			else{
				b = w*((h-i)/2);
				c = w*((h-i)/2+1);
				min = Math.min(min, Math.max(a, Math.max(b, c))-Math.min(a, Math.min(b, c)));
				
				b = w/2*(h-i);
				c = (w/2+1)*(h-i);
				min = Math.min(min, Math.max(a, Math.max(b, c))-Math.min(a, Math.min(b, c)));

			}
		}
		return min;
	}
}


Measured memory_bytes: 22100
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int func1(int a, int b){
    if (b == 0){
        return a;
    }
    return func1(b, a%b);
}

int main(){
    int n; cin >> n;
    int max = 0;
    vector<int> v(n);
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    for (int i = 0; i < n; i++){
		if (i==0){
          max = v[0];
        }
        max = func1(v[i], max);
    }
    cout << max << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int A, B, C;
	cin >> A >> B >> C;

	if ((max(max(A, B), C) * 3 - A - B - C) % 2 == 0) {
		cout << (max(max(A, B), C) * 3 - A - B - C) / 2;
	}
	else {
		cout << (max(max(A, B), C) * 3 - A - B - C + 3) / 2 ;
	}





}	


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


int dp[10001];
int N, M;
int digit[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main(){
    cin >> N >> M;
    vector<int> A(M);
    for(int i = 0; i < M; i++){
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());
    for(int i = 1; i <= 10000; i++){ // dp[10001]={0 -1 -1 -1 -1 ...}
        dp[i] = -1;
    }
    for(int i = 2; i <= 10000; i++){ // start with 2 because no digit can be form with 1 match stick
        for(int j = 0; j < M; j++){
            if(i - digit[A[j]] >= 0 && dp[i - digit[A[j]]] >= 0){
                dp[i] = max(dp[i], dp[i - digit[A[j]]] + 1);
            }
        }
    }

    int now = N;
    for(int i = dp[N]; i > 0; i--){
        for(vector<int>::iterator it = A.begin(); it != A.end(); it++){
            if(now >= digit[*it] && dp[now - digit[*it]] + 1 == dp[now]){
                cout << *it;
                now -= digit[*it];
                break;
            }
        }
    }

    cout <<endl;
//    cout << dp[N] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s,t;
    cin >> s >> t;
    if (s.size() != t.size()) {
        cout << "No" << endl;
        return;
    }
    int n = s.size();
    char c[26] = {};
    REP(i,0,n) {
        if (c[s[i]-'a'] < 'a') c[s[i]-'a'] = t[i];
        else if (c[s[i]-'a'] != t[i]) {
            cout << "No" << endl;
            return;
        }
    }
    REP(i,0,26) REP(j,0,26) {
        if (i == j) continue;
        if (c[i] < 'a') break;
        if (c[i] == c[j]) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    solve();
    
    return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, m; cin >> n >> m;
  vvc a(n, vc(n)), b(m, vc(m)); rep(i, n) rep(j, n) cin >> a[i][j]; rep(i, m) rep(j, m) cin >> b[i][j];
  for(ll i = 0;i <= n - m;i++)
  {
    for(ll j = 0;j <= n - m;j++)
    {
      ll flag = 0;
      for(ll k = 0;k < m;k++)
      {
        for(ll t = 0;t < m;t++)
        {
          if(a[i+k][j+t] == b[k][t]) flag++;
        }
      }
      if(flag == m * m)
      {
        fin("Yes") return;
      }
    }
  }
  fin("No")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

long long int BuyStock(long long int i, long long int arr[], long long int N)
{
    long long int j;
    for(j=i;j<N-1;j+=1)
    {
        if(arr[j]<arr[j+1])
        {
            return(j);
        }
    }
    return(N-1);
}

long long int SellStock(long long int i, long long int arr[], long long int N)
{
    long long int j;
    for(j=i;j<N-1;j+=1)
    {
        if(arr[j]>arr[j+1])
        {
            return(j);
        }
    }
    return(N-1);
}


int main()
{
    long long int N, i, arr[85], temp, buy, sell, stock=0, amount=1000;
    cin>>N;
    for(i=0;i<N;i+=1)
    {
        cin>>arr[i];
    }
    i = 0;
    while(i<N)
    {
        buy = BuyStock(i, arr, N);
        if(buy==N-1)
        {
            break;
        }
        sell = SellStock(buy+1, arr, N);
        stock = amount/arr[buy];
        amount = amount%arr[buy];
        amount = amount+stock*arr[sell];
        stock = 0;
        i = sell+1;
    }
    cout<<amount<<endl;
}

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

int num[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main() {
    int n, m; cin >> n >> m;
    map<int, int> u;
    for (int i = 0; i < m; i++) {
        int p; cin >> p;
        u[num[p]] = max(u[num[p]], p);
    }
    vector<int> c, d;
    for (auto it = u.begin(); it != u.end(); it++) {
        c.push_back(it->first);
        d.push_back(it->second);
    }
    sort(c.begin(), c.end());
    sort(d.rbegin(), d.rend());    
    int dp[10010];
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    for (int i = 0; i <= n; i++) {
        if (dp[i] == 0) continue;
        for (int j = 0; j < c.size(); j++) {
            if (i+c[j] > n) continue;
            dp[i+c[j]] = max(dp[i+c[j]], dp[i]+1);
        }
    }    
    deque<int> ans;
    int f = n;
    while (f > 0) {
        for (int i = 0; i < d.size(); i++) {
            if (dp[f-num[d[i]]] == dp[f] - 1) {
                ans.push_back(d[i]);
                f -= num[d[i]];
                break;
            }
        }
    }
    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <mutex>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <vector>
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define SQR(x) (x) * (x)
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);
int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = SQR(x);
    x %= MOD;
  }
  return ans;
};
int LIST[100000 + 10]{};
signed main() {
  int N, K;
  cin >> N >> K;
  for (int i = 100000; i >= 1; i--) {
    LIST[i] = bpm(K / i, N) * i;
    for (int j = 2; i * j <= K; j++) {
      LIST[i] -= LIST[i * j] / (i * j) * i;
    }
  }
  int ans = accumulate(ALL(LIST), 0LL) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 4620
s = input()
n = len(s)


def dfs(i, now):
    if i == n-1:
        return sum(list(map(int, now.split('+'))))
    return dfs(i + 1, now + s[i + 1]) + dfs(i + 1, now + '+' + s[i + 1])


print(dfs(0, s[0]))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> line;
vector<int> ans;
bool check(int place) {
	return line[place] == ans[place];
}
int main() {
	int time;
	cin >> time;
	line.resize(time);
	for (int i = 0; i < time; ++i) {
		cin >> line[i];
	}
	ans = line;
	sort(ans.begin(), ans.end());
	int oknum = 0;
	for (int i = 0, I = line.size(); i < I; ++i) {
		oknum += check(i) ? 0 : 1;
	}

	int Q;
	cin >> Q;
	if (oknum == 0) {
		cout << 0 << endl;
	}
	else {
		int res = -1;
		for (int i = 1; i <= Q; ++i) {
			int a, b;
			cin >> a >> b;
			--a;
			--b;
			oknum += check(a) ? 1 : 0;
			oknum += check(b) ? 1 : 0;
			swap(line[a], line[b]);
			oknum -= check(a) ? 1 : 0;
			oknum -= check(b) ? 1 : 0;
			if (oknum == 0) {
				res = i;
				break;
			}
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 5200
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////
int cnt[100010];
int main(){
    int n, q;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        sum += a[i];
        cnt[a[i]]++;
    }
    cin >> q;
    vector<long long> ans(q+1);
    ans[0] = sum;
    for (int i = 0;i < q;i++){
        int b,c;
        cin >> b >> c;
        sum += (c - b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 4712
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll H;
  cin>>H;
  ll ans = 0;
  ll two = 1;
  while(H>0) {
    H /= 2;
    ans += two;
    two *= 2;
  }
  cout<<ans<<endl;
}



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

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

    if(n == 0){
        cout << x << endl;
        return 0;
    }

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

    int flag_a;
    int flag_b;
    for(int i = 0; i < 101; i++){
        flag_a = 0;
        flag_b = 0;
        for(int j = 0; j < n; j++){
            if(p[j] == x - i && p[j] == x + i){
                flag_a = 1;
                flag_b = 1;
            }else if(p[j] == x - i){
                flag_a = 1;
            }else if(p[j] == x + i){
                flag_b = 1;
            }
        }
        if(flag_a == 0){
            cout << x - i << endl;
            break;
        }else if(flag_b == 0){
            cout << x + i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int gcd(int x, int y) {
    if (x < y) {
        return gcd(y, x);
    }

    if (y == 0) {
        return x;
    }

    return gcd(y, x % y);
}

int M, N;
int b[505], r[505];

int g[505][505];
char visited[505];
int matcha[505], matchb[505];

bool rec(int u) {
    if (u == -1) return true;
    for (int j = 0; j < N; ++j) {
        if (!visited[j] && g[u][j] == 1) {
            visited[j] = true;
            bool t = rec(matchb[j]);
            if (t) {
                matcha[u] = j;
                matchb[j] = u;
                return true;
            }
        }
    }
    return false;
}

bool solve() {
    cin >> M >> N;
    if (M == 0 && N == 0) {
        return false;
    }
    for (int j = 0; j < M; ++j) {
        cin >> b[j];
    }
    for (int j = 0; j < N; ++j) {
        cin >> r[j];
    }

    fill(matcha, matcha+M, -1);
    fill(matchb, matchb+N, -1);

    for (int j = 0; j < M; ++j) {
        for (int k = 0; k < N; ++k) {
            g[j][k] = gcd(b[j], r[k]) > 1 ? 1 : 0;
        }
    }

    for (int j = 0; j < M; ++j) {
        fill(visited, visited+N, 0);
        rec(j);
    }

    int ret = 0;
    for (int j = 0; j < M; ++j) {
        if (matcha[j] >= 0) {
            ++ret;
        }
    }

    cout << ret << endl;

    return true;
}

int main() {
    while(solve());
    return 0;
}

Measured memory_bytes: 4084
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int n;
  int ans=1000;
  n = str.length();
  for(int i=0; i<n-2; i++){
    int value = 0;
    value = (str[i]-'0')*100 + (str[i+1]-'0')*10 + (str[i+2]-'0');
    int dif = abs(value-753);
    ans = min(ans, dif);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
/**
 * Created by PhpStorm.
 * User: ramia
 * Date: 2016/09/24
 * Time: 21:00
 */
class STD {
	static function input(){
		$line = trim(fgets(STDIN));
		return $line;
	}

	static function output( $text ){
		echo $text."\n";
	}
}
list( $n , $a , $b ) = explode(' ' ,STD::input());
$s = STD::input();

$result_count = 0;

for( $i=0;$i<$n;$i++ ){
	$result = 'No';
	if( $s[$i] == 'a' ){
		if( 0 < $a + $b ){
			$result = 'Yes';

			if( $a>0 ){
				$a--;
			}else{
				$b--;
			}
		}
	}
	if( $s[$i] == 'b' ){
		if( 0 < $b ){
			$result = 'Yes';
			$b--;
		}
	}

	if( $result == 'Yes' ){
		$result_count++;
	}

	STD::output($result);
}




?>

Measured memory_bytes: 4240
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
#define INF 10000000000
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
const long long int max_v=100009;
const long long int max_e=max_v*2;
vector<int> par(max_v);/*親*/
vector<int> Rank(max_v);/*根の深さ*/
/*n要素で初期化*/
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        Rank[i]=0;
    }
}
/*木の根を求める*/
int find(int x){
    if(par[x]==x){/*親が自分自身＝根*/
        return x;
    }
    else{
        return par[x]=find(par[x]);/*一つ上の階層へ*/
    }
}
/*ｘとｙの集合を併合*/
void unite(int x,int y){
    x=find(x);
    y=find(y);
    /*根を求める*/
    if(x==y) return;/*同じ集合に属していたら終了*/
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
/*同じ集合に属するか調べる*/
bool same(int x,int y){
    return find(x)==find(y);
}
/*利用方法はparのそれぞれの要素に対応させる形で別の配列を用意し、そこに入力する。*/

//入力par,Rankの配列数にノードの最大数を入力(max_v)
//使用時、初期化を忘れずに！init
struct edge{
    int u,v,cost;
};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}
edge es[max_e];
int v,E=0;
int kluskal(){
    sort(es,es+E,comp);//costが小さい順にソート
    init(v);//ufの初期化
    int res=0;
    rep(i,E){
        edge e=es[i];
        if(!same(e.u,e.v)){//同じグループに属さない＝閉路にならない
            unite(e.u,e.v);
            res+=e.cost;
        }
    }
    return res;
}
int main(){
    int n;
    cin>>n;
    v=n;
    vector<pair<pii,int>> p(n);
    rep(i,n){
        cin>>p[i].first.first>>p[i].first.second;
        p[i].second=i;
    }
    sort(p.begin(),p.end());
    rep(i,n-1){
        es[E].u=p[i].second;
        es[E].v=p[i+1].second;
        es[E].cost=min(abs(p[i].first.first-p[i+1].first.first),abs(p[i].first.second-p[i+1].first.second));
        E++;
    }
    rep(i,n){
        swap(p[i].first.first,p[i].first.second);
    }
        sort(p.begin(),p.end());
    rep(i,n-1){
        es[E].u=p[i].second;
        es[E].v=p[i+1].second;
        es[E].cost=min(abs(p[i].first.first-p[i+1].first.first),abs(p[i].first.second-p[i+1].first.second));
        E++;
    }
    out(kluskal());
}

Measured memory_bytes: 4608
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

struct Mod {
	static ll BASE;
	ll value = 0;
	static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
	Mod(ll value)
	: value(residue(value)) {}
	Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
	void operator+=(const Mod& rhs) { *this = *this + rhs; }
	Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
	void operator-=(const Mod& rhs) { *this = *this - rhs; }
	Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
	void operator*=(const Mod& rhs) { *this = *this * rhs; }
};
ll Mod::BASE = 1000000007;

int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> Ais(N);
	rep(i,0,N) {
		cin >> Ais[i];
	}
	vector<ll> Bis(M);
	rep(i,0,M) {
		cin >> Bis[i];
	}
	sort(Ais.rbegin(), Ais.rend());
	rep(i,1,N) {
		if (Ais[i] == Ais[i-1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	sort(Bis.rbegin(), Bis.rend());
	rep(i,1,M) {
		if (Bis[i] == Bis[i-1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	Mod ans = 1;
	ll x = 0;
	ll y = 0;
	rrep(n, N*M+1, 1) {
//		cout << "n: " << n << endl;
		if (x < N && Ais[x] == n && y < M && Bis[y] == n) {
//			cout << "A" << endl;
			x++;
			y++;
		} else if (x < N && Ais[x] == n) {
//			cout << "B:" << y << endl;
			ans *= y;
			x++;
		} else if (y < M && Bis[y] == n) {
//			cout << "C:" << x << endl;
			ans *= x;
			y++;
		} else {
//			cout << "D:" << (x)*(y) - (N*M - n) << endl;
			ans *= x*y - (N*M - n);
		}
	}
	cout << ans.value << endl;
}


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

int main() {
	long long int a;
	long long int b;
	long long int x;
	while(cin>>a>>b>>x){
		long long int  y= a/x;
		long long int z=b/x;
		if(a%x==0){
			z++;
		}
		cout<<abs(y-z)<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 100005
#define M 1000000007
using namespace std;
long long dp[MAXN][13];
int main()
{
    string s;
    cin>>s;
    long long n=s.length();
    memset(dp,0,sizeof(dp));
    if(s[0]=='?')
        for(long long i=0;i<10;i++)
            dp[0][i]=1;
    else
        dp[0][s[0]-'0']=1;
    for(long long i=1;i<n;i++)
    {
        if(s[i]=='?')
        {
            for(long long k=0;k<10;k++)
            {
                for(long long j=0;j<13;j++)
                {
                    int mid=(j*10+k)%13;
                    dp[i][mid]=(dp[i-1][j]+dp[i][mid])%M;
                }
            }
        }
        else
        {
            for(long long j=0;j<13;j++)
            {
                int mid=(j*10+s[i]-'0')%13;
                dp[i][mid]=(dp[i-1][j]+dp[i][mid])%M;
            }
        }
    }
    cout<<dp[n-1][5];
    return 0;
}


Measured memory_bytes: 10624
from collections import deque

n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0] * (n-1)
# グラフの作成
g = [[] * n for _ in range(n)]
for i in range(n-1):
    g[i].append(i + 1)
    g[i + 1].append(i)
g[x].append(y)
g[y].append(x)


# 幅優先探索
def bfs(u):
    dist = [-1] * n
    dist[u] = 0
    que = deque([])
    que.append(u)
    while que:
        v = que.popleft()
        for nv in g[v]:
            if dist[nv] != -1:
                continue
            dist[nv] = dist[v] + 1
            que.append(nv)
    for i in dist:
        if i == 0:
            continue
        ans[i - 1] += 1
    return ans


# 頂点の探索
for i in range(n):
    bfs(i)
for i in ans:
    print(i // 2)


Measured memory_bytes: 4200
from collections import Counter
n = int(input())
a = [int(input()) for i in range(n)]

cnt = Counter(a)
maxs = sorted(list(set(a)))[::-1]
for ai in a:
  if ai == maxs[0]:
    if cnt[ai] > 1:
      print(ai)
    else:
      print(maxs[1])
  else:
    print(maxs[0])

Measured memory_bytes: 24172
#include <iostream>

using namespace std;

const int maxn = 2e5 + 9;
int n, q;
string s;
pair<char, char> query[maxn];

bool cmp1(int a, int b) {
    return a >= b;
}

bool cmp2(int a, int b) {
    return a > b;
}

int fall(int pos) {
    for (int i = 0; i < q; i++) {
        if (query[i].first == s[pos]) {
            pos += (query[i].second == 'L' ? -1 : 1);
        }
        if (pos < 0) {
            return 1;
        } else if (pos >= n) {
            return 3;
        }
    }
    return 2;
}

int bound(int x, bool (*cmp)(int a, int b)) {
    int start = 0, end = n - 1;
    while (end > start) {
        int mid = (start + end) / 2;
        if (cmp(fall(mid), x)) {
            end = mid;
        } else {
            start = mid + 1;
        }
    }
    return end;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < q; i++) {
        cin >> query[i].first >> query[i].second;
    }
//    for (int i = 0; i < n; i++) {
//        cout << fall(i) << '\n';
//    }
    int pos1 = bound(1, cmp2), pos2 = bound(3, cmp1);
//    cout << pos1 << ' ' << pos2 << '\n';
    int ans = 0;
    if (pos1 == n - 1) {
        cout << 0 << '\n';
        return 0;
    }
    if (fall(pos1 - 1) == 1) {
        ans += pos1;
    }
    if (fall(pos2) == 3) {
        ans += (n - pos2);
    }
    cout << n - ans << '\n';
    return 0;
}


Measured memory_bytes: 976
/*
TASK: AGC143 - C - Slimes
LANG: C++
NAME: picolylamine
*/
#define _CRT_SECURE_NO_WARNINGS
#define N_MAX 100010

#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int N;
	char S[N_MAX];
	scanf("%d%s", &N, S);

	int ret = 0;
	char last = '!';
	for (int i = 0; i < N; i++){
		if (S[i] != last){
			ret++;
			last = S[i];
		}
	}

	printf("%d", ret);

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>

/********
*	??§????????¨?°????????????\?????????
*********/

/*********??¢?????´?????????
*	(1)?????????????????????????????§??????????°??????????????????????
*	(2)?°?????????¨??§???????????\????????????
*	(3)??¢????????????????????\??????????????????????????????????????????????????????\n??§?????????
*********/

int main(void)
{
	char  ch;			//????????\???
	
	while(1){
		scanf("%c", &ch);
		if ( ch == '\n' ){
			printf("\n");
			break;
		}
		else if (islower(ch)){	//?°???????????????°???
			ch = toupper(ch);
		}
		else if(isupper(ch)){	//??§??????????????°???
			ch = tolower(ch);
		} else {
			//????????????
		}
		
		printf("%c", ch);
		
	}
	return 0;

}


/*
int islower(char ch){// ch ????°????????????? true ?????????}

int isupper(char ch){// ch ?????§???????????? true ?????????}

int tolower(char ch){// ch ????°????????????????}

int toupper(char ch){// ch ?????§???????????????}

*/

Measured memory_bytes: 940
// C - Low Elements
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = INF;
  string s, t;
  cin >> n;
  vlli d(n);
  rep(i, 0, n)
  {
    cin >> d[i];
    count = min(count, d[i]);
    if (d[i] > count)
    {
      ans++;
    }
  }
  ans = n - ans;
  cout << ans << endl;
}

Measured memory_bytes: 1792
num = int(input())
a = input().split(" ")

count = 0
ans = -1

while count == 0:
  ans = ans + 1
  for i in range(num):
    if int(a[i])%2 == 1:
      count = count + 1  
    a[i] = int(a[i])/2
  
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  int a,b,k;
  cin>>a>>b>>k;
  if(k>=a)
  {
    k-=a;
    a=0;
  }
  else
  {
    a-=k;
    k=0;
  }
  if(k>=b)
  {
    b=0;
  }
  else b-=k;
  cout<<a<<" "<<b<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


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

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	 cin>>a[i];
	for(int i=k;i<n;i++)
	 {
	 	if(a[i]>a[i-k])
	 	 cout<<"Yes"<<endl;
	 	else cout<<"No"<<endl; 
	 }
	return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
ll n;
vll a; 


ll under_nums(ll x){//xより小さい積の数
	ll cnt = 0;
	rep(i,n){//aiにおけるx未満になる組み合わせの数
//	cout << " -- i = " << i << " -- " << endl;
		ll l = -1;
		ll r = n;
		bool sei;
		if(a[i]>0) sei = true; else sei = false;
		while(l+1<r){
			ll mid = (l+r)/2;
			auto ok = [&]{
				if(a[i]*a[mid]<x) return sei;
				else return !sei;
			};
			if(ok()) l = mid; else r = mid;
//			cout << "l = " << l << "  : r = " << r << "  : sei = " << sei << endl;
		}
		if(sei) cnt += r;else cnt += n-r;
		if(r>i&&sei) cnt--;
		else if(l<i&&!sei) cnt--;
//		cout << "cnt = " << cnt << endl;
	}
	cnt /= 2;
	return cnt;
}

int main(void) {
	cin >> n;
	ll k; cin >> k;
	a = vll(n);
	rep(i,n) cin >> a[i];
	SORT(a);
	ll l = -LL_INF;
	ll r = LL_INF;
	while(l+1<r){
		ll mid = (l+r)/2;
		auto ok = [&]{
			if(under_nums(mid)<k) return true;
			else return false;
		};
		if(ok()) l = mid; else r = mid;
	}
	cout << l << endl;

}




Measured memory_bytes: 1920
main()
{float a;
  for(;~scanf("%f",&a);)
    puts(a<=48?"light fly":a<=51?"fly":a<=54?"bantam":a<=57?"feather":a<=60?"light":a<=64?"light welter":a<=69?"welter":a<=75?"light middle":a<=81?"middle":a<=91?"light heavy":"heavy");exit(0);
}

Measured memory_bytes: 0
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	int mx = a[0];
	int ans = 0;
	repn(i, 1, n){
		if(a[i] >= mx){
			ans++;
		}
		mx = max(a[i], mx);
	}
	cout << ans + 1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main()
{
  int N;
  int sum = 0;

  cin >> N;
  int tmp = N;
  while (tmp > 0)
  {
    sum += tmp % 10;
    tmp /= 10;
  }
  if (N % sum == 0)
  {
    puts("Yes");
  }
  else
  {
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> h(n),ans(n);
    for(int i=0;i<n+m-1;i++){
        int a,b;cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        h[b]++;
    }
    int r;
    for(int i=0;i<n;i++){
        if(!h[i]){
            r=i;
            break;
        }
    }
    queue<int> q;
    q.push(r);
    ans[r]=0;
    while(!q.empty()){
        int p=q.front();
        q.pop();
        for(int x:g[p]){
            h[x]--;
            if(!h[x]){
                ans[x]=p+1;
                q.push(x);
            }
        }
    }
    for(int x:ans){
        cout << x << endl;
    }
}

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

int main(){
  int n,m,a;
  set<int> s,t;
  cin >> n;
  while(n--){
    cin >> a;
    s.insert(a);
  }
  cin >> m;
  while(m--){
    cin >> a;
    t.insert(a);
  }
  vector<int> v;
  set_difference(s.begin(),s.end(),t.begin(),t.end(),back_inserter(v));
  r(i,v.size()){
    cout << v.at(i)<<endl;
  }
}


Measured memory_bytes: 22636
import Control.Monad
import Data.List
import Data.Char
import Debug.Trace

abc :: [Char]
abc = map chr $ map (+(ord 'a')) [0..25]

coprime :: Int->Bool
coprime alpha = ((alpha`mod`2)/=0) && ((alpha`mod`13)/=0) && ((alpha`mod`26)/=0)

oneToOne :: Int->Int->Bool
oneToOne alpha beta = 26==(length $ nub $ map (affine alpha beta) abc)

correctAffine :: Int->Int->Bool
correctAffine alpha beta = (coprime alpha) && (oneToOne alpha beta)

affine :: Int->Int->Char->Char
affine alpha beta c = chr $ (alpha*((ord c)-(ord 'a'))+beta)`mod`26 + (ord 'a')

affineR :: Int->Int->Char->Char
affineR alpha beta c = head $ filter (\x->(affine alpha beta x)==c) abc

affineWord :: Int->Int->String->String
affineWord alpha beta word = map (affine alpha beta) word

affineWordR :: Int->Int->String->String
affineWordR alpha beta word = map (affineR alpha beta) word

wordsToStr :: [String]->String
wordsToStr [] = []
wordsToStr (x:xs) = if null xs then x else x++" "++(wordsToStr xs)

solve' :: [String]->[(Int,Int)]->String
solve' lwords ((a,b):xs)
    | (correctAffine a b)&&
      ((elem this lwords)||(elem that lwords)) = wordsToStr $ map (affineWordR a b) lwords
    | otherwise                                = solve' lwords xs
        where this = affineWord a b "this"
              that = affineWord a b "that"

solve str = do
    let lwords = words str
    putStrLn (solve' lwords $ foldr (++) [] $ [[(a,x)|a<-[1..(x-1)]]++[(x,b)|b<-[1..(x-1)]]++[(x,x)]|x<-[1..]])

main = do
    n <- readLn :: IO Int
    ss <- replicateM n getLine
    mapM_ solve ss

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

vector<int> vi;

int main(){
   string str;
   cin>>str;
   int maxi=0;
   int temp=0;
   for(int i=0;i<=str.size();i++){
    if(str[i]=='R'){
        temp++;
        maxi=max(maxi,temp);
    }else{
    temp=0;
    }
   }
   printf("%d",maxi);
    return 0;
}




Measured memory_bytes: 3716
import numpy as np
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
tmp = []
for x in Xs:
  tmp.append(x)
  for n in range(N):
    if Xs[n] in tmp:
      l = np.linalg.norm(np.array(x) - np.array(Xs[n]))
      if l.is_integer() and l > 0:
        result.append(l)
print(int(len(result)))


Measured memory_bytes: 12504
#include<stdio.h>
#include<string.h>

int main(){

  int n,m,i,j,k;
  char before[100000]={'\0'};
  char after[100000]={'\0'};
  char str[100000]={'\0'};

  while(1){

    scanf(" %d",&n);

    if(n==0){
      break;
    }

    for(i=0;i<n;i++){
      scanf(" %c %c",&before[i],&after[i]);
    }

    scanf("%d",&m);

    for(j=0;j<m;j++){

      scanf(" %c",&str[j]);

      for(k=0;k<n;k++){
	if(str[j]==before[k]){
	  str[j]=after[k];
	  break;
	}
      }

    }

    for(i=0;i<m;i++){
      printf("%c",str[i]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 872
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;
ll modpow(ll a,ll n,ll mod){ // a^n の mod を計算
    ll res = 1;
    while(n>0){
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int ssk[10][200009];
signed main(){
    string s;
    cin>>s;
    ll sz = s.size();
    ll ans = 0;
    vector<int> sk(sz);
    vector<int> stp(sz);
    vector<int> sl(sz);
    vector<int> sr(sz);
    rep(i,sz){
        sk[i]=s[sz-1-i]-'0';
        if(i==0) stp[i]= 1;
        else{
            stp[i] = 10 * stp[i-1];
            stp[i] %= 2019;
        }
    }
    ll bx[2100];
    rep(i,2100) bx[i] = 0;
    bx[0]=1;
    rep(i,sz){
        if(i==0) sr[i] = sk[i];
        else{
            sr[i] = sr[i-1] + stp[i]*sk[i];
            sr[i] %= 2019;
        }
        bx[sr[i]]++;
        // cout<<sr[i]<<" "<<bx[sr[i]]<<endl;
    }
    rep(i,2020){
        ans += (bx[i])*(bx[i]-1)/2;
    }
    cout<<ans<<endl;
    // rep(i,sz) cout<<sk[i]<<endl;
}


Measured memory_bytes: 9916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  ll ans=0, cnt=1;
  rep(i, n) {
    if(i<n-1 && a[i]==a[i+1]) cnt++;
    else {ans += cnt&1; cnt=1;}
  }
  cout << ans << newl;
  return 0;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

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

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

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


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

    int n;
    cin >> n;

    s64 a;
    vs64 s(n + 1);
    map<s64, int> m;
    s[0] = 0;
    m[0] = 1;
    rep (i, n)
    {
        cin >> a;
        s[i + 1] = s[i] + a;
        ++m[s[i + 1]];
    }

    s64 ans = 0;
    rep (i, n)
    {
        --m[s[i]];
        ans += m[s[i]];
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 14336
#include <iostream>
using namespace std;
void print_array(int a[],int n){
    for(int i=0;i<n;i++){
        if(i != 0) cout<<' ';
        cout<<a[i];
    }
    cout<<'\n';
}

void insertion_sort(int a[],int n){
    for(int i=1;i<n;i++){
        int key=a[i];
        int j = i-1;
        while(j>=0 && a[j]>key){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=key;
        print_array(a,n);
    }
}

int main(){
    int A[100],N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    print_array(A,N);
    insertion_sort(A,N);
}


Measured memory_bytes: 3092
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt(),
		    k=in.nextInt();
		    
		double value[]=new double[n];
		
		for(int i=0; i<n; i++)
            value[i]=(in.nextInt()+1.0)/2.0;
            
        double sum=0.0, max;
        for(int i=0; i<k; i++)
            sum+=value[i];
            
        max=sum;
        
        for(int i=k; i<n; i++) {
            sum+=value[i];
            sum-=value[i-k];
            max=Math.max(max, sum);
        }
        
        System.out.println(max);
	}
}


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


int main() {
	int N;
	cin >> N;
	vector<string> str(N+1);
	vector<int> num(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> str.at(i);
	}
	sort(str.begin(), str.end()-1);
	int next = 0;
	for (int i = 0; i < N; i++) {
		num.at(i) = next;
		if (str.at(i) == str.at(i + 1)) { 
			next++; 
		}
		else {
			next = 0;
		}
	}
	int max_val = *max_element(num.begin(), num.end());
	for (int i = 0; i < N; i++) {

		if (num.at(i) == max_val)cout << str.at(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 10388
#include<iostream>
#include<algorithm>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int a;
    string s;

    cin >> a;
    cin >> s;
    if( a < 3200 ){
        s = "red";
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256