akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
ll ksm (ll a , ll b)
{
    ll ans = 1 , base = a;
    while (b){
        if (b & 1) ans = ans * base % mod;
        b >>= 1;
        base = base * base % mod;
    }
    return ans;
}
ll n , k;
vector<ll> fact;
ll dp[50005];
ll getans (ll x){
    return ksm(k , (x - 1) / 2 + 1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> k;
    ll ans = 0;
    for (ll i = 1 ; i * i <= n ; i++){
        if (n % i == 0){
            fact.push_back(i);
            if (i != n / i)
                fact.push_back(n / i);
        }
    }
    sort(fact.begin() , fact.end());
    int m = fact.size();
    for (int i = 0 ; i < m ; i++) dp[i] = getans(fact[i]);
    for (int i = 0 ; i < m ; i++){
        // 容斥掉重复部分
        for (int j = 0 ; j < i ; j++)
            if (fact[i] % fact[j] == 0)
                dp[i] = (dp[i] - dp[j] + mod) % mod;
        if (fact[i] & 1) ans = (ans + dp[i] * fact[i]) % mod;
        else ans = (ans + dp[i] * (fact[i] / 2)) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;

  if(S==U){
    cout<<A-1<<endl;
   cout<<B<<endl;
  }
  if(T==U){
    cout<<A<<endl;
   cout<<B-1<<endl;
  }


 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define M 100000

int n,k;
int T[M];

int check(long p){
  int i,j=0,s;

    for(i=0;i<k;i++){
      s=0;
      while(s+T[j]<=p){
	s+=T[j];
	j++;
	if(j==n) return n;
      }
    }
    return j;
}

int kai(){
  long right=100000*10000;
  long left=0,man;
  int v;

  while(right-left>1){
    man=(right+left)/2;

    v=check(man);
    if(v>=n)right=man;
    else left=man;
  }

  return right;
}

int main(){
  int i;
  long a;
  
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++) scanf("%d",&T[i]);
  a=kai();
  printf("%d\n",a);

  return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >>N;
  if(N==100000){
    cout <<90909<<endl;
  }
  if(N<10){
    cout <<N<<endl;
  }
  else if(N<100){
    cout <<9<<endl;
  }
  else if(N<1000){
    cout <<N-90<<endl;
  }
  else if(N<10000){
    cout <<909<<endl;
  }  
  else if(N<100000){
    cout << N-9090 <<endl;
  }
}

Measured memory_bytes: 256
X = int(input())

if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
elif X <= 1999:
    print(1)

Measured memory_bytes: 9104
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;

void normalize(char* str)
{
	char res[] = "0m0c0x0i";
	char tmp = 1;
	for (int i = 0; str[i] != '\0'; i++)
	{
		if (isdigit(str[i]))
		{
			tmp = str[i];
		}
		else
		{
			if (tmp == 1)	tmp = '1';
			switch(str[i])
			{
			case 'm':
				res[0] = tmp;
				break;
			case 'c':
				res[2] = tmp;
				break;
			case 'x':
				res[4] = tmp;
				break;
			case 'i':
				res[6] = tmp;
				break;
			}
			tmp = 1;
		}
	}
	for (int i = 0; i < 8; i += 2)
	{
		res[i] -= '0';
	}
	memcpy(str, res, sizeof(char) * 9);
}

int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		char str1[16], str2[16];
		scanf("%s %s", str1, str2);
		normalize(str1);
		normalize(str2);
		char str[] = "0m0c0x0i";
		for (int j = 0; j < 8; j += 2)
		{
			str[j] = str1[j] + str2[j];
		}
		for (int j = 6; j >= 0; j -= 2)
		{
			if (j != 0)
				str[j-2] += str[j] / 10;
			str[j] = str[j] % 10;
			str[j] += '0';
		}
		for (int j = 0; j < 8; j++)
		{
			if (str[j] == '0') {j++;continue;}
			if (str[j] == '1') continue;
			putchar(str[j]);
		}
		putchar('\n');
	}
	
	return 0;
}

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

public class Main {

	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(System.out);
		out.println(6452);
		int A = 0, B = 1;
		sum(A, B, ONE);
		positive(ONE);

		int fromA = 5;
		int fromB = SIZE + fromA;
		getBin(fromA, SIZE, A);
		getBin(fromB, SIZE, B);
		int fromRes = fromB + SIZE;
		int tmp = fromRes + 2 * SIZE;
		for (int i = 0; i < SIZE; i++) {
			for (int j = 0; j < SIZE; j++) {
				and(fromA + i, fromB + j, tmp);
				sum(fromRes + i + j, tmp, fromRes + i + j);
			}
		}
		for (int i = 0; i < 2 * SIZE - 1; i++) {
			makePot(fromRes + i, i);
			sum(fromRes + i, TARGET, TARGET);
		}

		out.flush();
	}

	static int SIZE = 30;
	static int ZERO = 3;
	static int ONE = 4;
	static int TARGET = 2;

	static void getBin(int from, int size, int val) {
		sum(from, ONE, from);
		for (int i = 1; i < size; i++) {
			sum(from + i - 1, from + i - 1, from + i);
		}
		for (int i = size - 1; i >= 0; i--) {
			compEquals(from + i, val, from + i);
			makePot(from + i, i);
			for (int j = 0; j < i; j++) {
				sum(from + i, from + j, from + j);
			}
		}
		for (int i = 0; i < size; i++) {
			positive(from + i);
		}
	}
	static void positive(int val) {
		cmp(ZERO, val, val);
	}

	static void compEquals(int i, int j, int to) {
		cmp(j, i, to);
		cmp(to, ONE, to);
	}

	static void makePot(int val, int exp) {
		for (int i = 0; i < exp; i++) {
			sum(val, val, val);
		}
	}

	static void and(int i, int j, int to) {
		sum(i, j, to);
		cmp(ONE, to, to);
	}

	static void sum(int i, int j, int to) {
		out.println("+ " + i + " " + j + " " + to);
	}
	
	static void cmp(int i, int j, int to) {
		out.println("< " + i + " " + j + " " + to);
	}

	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 38376
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int x = parseInt(sc.next());
		int[] m = new int[n];
		int sum = 0;
		int mn = x;
		for (i = 0; i < n; i++) {
			m[i] = parseInt(sc.next());
			sum += m[i]; 
			if(m[i] < mn)mn = m[i]; 
		}
		sc.close();
		out.println(n+(x-sum)/mn);
	}
}


Measured memory_bytes: 21712
N = int(input())
C = list(input())

ans = C.count("R")
ans = min(ans, N - ans)

from heapq import *

idxW = []
idxR = []
for i,c in enumerate(C):
    if c == "R":
        heappush(idxR, -i)
    else:
        heappush(idxW, i)

LEN = min(len(idxW), len(idxR))

cnt = 0
for i in range(LEN):
    iW = heappop(idxW)
    iR = heappop(idxR) * (-1)

    if iW < iR:
        cnt += 1

ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 18764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
ll n;
cin>>n;
vector<ll> r(n);
for(ll i=0;i<n;i++){
cin>>r[i];
}
ll ans=r[1]-r[0];
ll m=r[0];
if(n==2){
cout<<ans<<endl;
}
else{
for(ll i=2;i<n;i++){
m=min(m,r[i-1]);
ans=max(ans,r[i]-m);
}
cout<<ans<<endl;
}
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
int main(){
   string a,b;
   cin>>a>>b;
   if(a.size()>b.size()){
     cout<<"GREATER"<<endl;  
   }
   else if(a.size()<b.size()){
    cout<<"LESS"<<endl;   
   }
   else{
     for(int i=0;i<a.size();i++){
       if(a[i]>b[i]){
         cout<<"GREATER"<<endl;
         return 0;
       }
       else if(a[i]<b[i]){
           cout<<"LESS"<<endl;
         return 0;
       }
       if(i==a.size()-1&&a[i]==b[i]){
         cout<<"EQUAL"<<endl;
         return 0;
       }
     }
   }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7828
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
int N;
pi a[200000+9];
int main(){
    scanf("%d", &N);

    for(int i=0;i<N;i++){
        scanf("%d %d", &a[i].second, &a[i].first);
    }

    sort(a, a+N);

    for(int i=0;i<N;i++){
        if(i)a[i].second += a[i-1].second;
        if(a[i].second > a[i].first) return printf("No"), 0;
    }

    printf("Yes");

    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<cmath>

using namespace std;

int main(){

    int n,A[1000];

    while(1){
        cin >> n;

        if (n == 0){
            break;
        }

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

            cin >> A[i];
            
        }

        int sum = 0;

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

            sum += A[i];
            
        }

        double avg = 1.0 * sum / n;
        double a = 0.0;

        for (int i = 0; i < n; i++){
            a += (A[i] - avg)*(A[i] - avg);
        }  

        double r = sqrt(a / n);

        printf("%lf\n",r); 

    }

    return 0;

}


Measured memory_bytes: 3208
def divisionCnt(n):
    cnt = 0
    while n % 2 == 0:
        n = n / 2
        cnt += 1
    return cnt

N = int(input())
numbers = [int(i) for i in input().split() if int(i) % 2 == 0]

cnt = 0
for n in numbers:
    cnt += divisionCnt(n)

print(cnt)

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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
 
using namespace std;

int32_t main(){
    string s;
    cin >> s;

    stack<char> q;
    q.push(s[0]);
    int i=1;
    FOR(i, 1, s.length()){
        if(!q.empty() && s[i]=='T' && q.top()=='S'){
            q.pop();
        }
        else{
            q.push(s[i]);
        }
    }

    cout << q.size() << endl;
}

Measured memory_bytes: 644
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



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

void gcd(vector<vector<int>> &g, int k)
{
    int c;
    for (int i = 1; i <= k; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            c = j;
            while (i % c > 0 || j % c > 0) {c--;}
            g[i-1][j-1] = c; g[j-1][i-1] = c;
        }
    }
}

int main(void)
{
    int k; cin >> k;
    vector<vector<int>> g(k, vector<int>(k)); gcd(g, k);
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            for (int l = 0; l < k; l++) ans += g[i][g[j][l]-1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
inline bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> a = {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};
	int k;cin >> k;
	cout << a[k - 1] << endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 広い間隔を持ってa,bを作っておく（a[i]+b[i]=const.）
# 下からi番目に+iをしていく

N = I()
p = LI()

a = [(i+1)*3*10**4 for i in range(N)]
b = a[::-1]

for i,p0 in enumerate(p):
    a[p0-1] += i

print(*a)
print(*b)

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

long long a, b, c;

int main(){
    while(~scanf("%lld %lld %lld", &a, &b, &c)){
        if(a + b >= c - 1){
            printf("%lld\n", b + c);
        } else {
            printf("%lld\n", a + b + b + 1);
        }
    }
    return 0;
}


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

using namespace std;

void sol() {
    int x ;
    cin >> x;
    if (x == 1) cout << 0 << endl;
    else cout << 1 << endl;
}

int main () {
    //int T;
    //cin >> T;
    //while(T--){
        sol();
    //}
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int):
    L = [2, 1]
    for _ in range(1, N):
        L = [L[1], L[0]+L[1]]
    print(L[1])
    return


def main():

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


if __name__ == '__main__':
    main()


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int H,N;
    cin>>H >> N;
    int nums[N];
    for(int i=0;i<N;i++)
    {
        cin>>nums[i];
    }
    int k = 0;
    int count = 0;
    while(H>0 && k<N)
    {
        H -= nums[k];
        count++;
        k++;
    }
    
    if(H<=0)
    {
        cout<<"Yes"<<" ";
    }
    else
    {
        cout<<"No"<<" ";
    }
    return 0;
}

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

int dp[1<<15][15];
int path[15][15];

int main(){
	
	for(int i=0;i<(1<<15)*15;i++)dp[i/15][i%15]=114514;
	for(int i=0;i<15*15;i++)path[i/15][i%15]=114514;
	
	int v,e;
	cin>>v>>e;
	for(int i=0;i<e;i++){
		int s,t,d;
		cin>>s>>t>>d;
		path[s][t]=d;
	}
	
	//?????????
	dp[0][0]=0;
	
	for(int i=0;i<(1<<v);i++){
		for(int j=0;j<v;j++){
			if(dp[i][j]==114514)continue;
			
			for(int k=0;k<v;k++){
				if(i & (1<<k))continue;
				dp[i+(1<<k)][k]=min(dp[i+(1<<k)][k],dp[i][j]+path[j][k]);
			}
		}
	}
	cout<<(dp[(1<<v)-1][0]==114514?-1:dp[(1<<v)-1][0])<<endl;
	
	
	return 0;
}


Measured memory_bytes: 5004
x1, y1, x2, y2 = gets.split.map(&:to_i)

dx = (x2 - x1)
dy = (y2 - y1)

if dx < 0
  dx *= -1
end

if dy < 0
  dy *= -1
end

if x1 < x2 && y1 <= y2
  puts "#{x2-dy} #{y2+dx} #{x1-dy} #{y1+dx}"
elsif x1 >= x2 && y1 < y2
  puts "#{x2-dy} #{y2-dx} #{x1-dy} #{y1-dx}"
elsif x1 > x2 && y1 >= y2
  puts "#{x2+dy} #{y2-dx} #{x1+dy} #{y1-dx}"
else
  puts "#{x2+dy} #{y2+dx} #{x1+dy} #{y1+dx}"
end


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

using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;

int main() {
  string s; cin >> s;
  int n = s.size();
  vector<int> ans(n);
  rep(ri, 2) {
    int cnt = 0;
    rep(i, n) {
      if(s[i] == 'R') cnt++;
      else {
        ans[i] += cnt/2;
        ans[i-1] += (cnt+1)/2;
        cnt = 0;
      }
    }
    reverse(ans.begin(), ans.end());
    reverse(s.begin(), s.end());
    rep(i, n) {
      if(s[i] == 'L') s[i] = 'R';
      else s[i] = 'L';
    }
  }

  rep(i, n) {
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<String> ad = new ArrayDeque<String>();
        int n = ip(br.readLine());
        for (int i = 0; i < n; i++) {
            String[] lines = br.readLine().split(" ");
            switch (lines[0]) {
            case "insert":
                ad.push(lines[1]);
                break;
            case "delete":
                ad.remove(lines[1]);
                break;
            case "deleteFirst":
                ad.removeFirst();
                break;
            case "deleteLast":
                ad.removeLast();
                break;
            }
        }
        System.out.println(ad.parallelStream().collect(Collectors.joining(" ")));
    }
    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
}

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int dp[3001][3001];
int N;

int main(void) {
    cin>>N;
    vector<Int> A(N);
    
    for(int i = 0;i < N;i++) {
        cin>>A[i];
    }

    for(int len = 1;len <= N;len++) {
        for(int i = 0;i + len <= N;i++) {
            int j = i+len;
            
            if((N - len) % 2 == 0)
                dp[i][j] = max(dp[i+1][j]+A[i],dp[i][j-1]+A[j-1]);
            else
                dp[i][j] = min(dp[i+1][j]-A[i],dp[i][j-1]-A[j-1]);
        }
    }

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

    return 0;
}



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

public class Main {

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			char[][] board = new char[3][];

			// read
			for (int i = 0; i < 3; ++i) {
				board[i] = line.substring(i * 3, i * 3 + 3).toCharArray();
			}

			// judge
			char winner = 'd';

			for (int i = 0; i < 3; i++) {
				if (board[i][1] != 's' && board[i][0] == board[i][1]
						&& board[i][1] == board[i][2]) {
					winner = board[i][1];
				}
			}
			if (winner == 'o' || winner == 'x') {
				System.out.println(winner);
				continue;
			} else {
				winner = 'd';
			}

			for (int i = 0; i < 3; i++) {
				if (board[1][i] != 's' && board[0][i] == board[1][i]
						&& board[1][i] == board[2][i]) {
					winner = board[1][i];
				}
			}
			if (winner == 'o' || winner == 'x') {
				System.out.println(winner);
				continue;
			} else {
				winner = 'd';
			}

			//
			if (board[1][1] != 's' && board[0][0] == board[1][1]
					&& board[1][1] == board[2][2]) {
				winner = board[1][1];
			}
			if (winner == 'o' || winner == 'x') {
				System.out.println(winner);
				continue;
			} else {
				winner = 'd';
			}

			if (board[1][1] != 's' && board[2][0] == board[1][1]
					&& board[1][1] == board[0][2]) {
				winner = board[1][1];
			}
			if (winner == 'o' || winner == 'x') {
				System.out.println(winner);
				continue;
			} else {
				winner = 'd';
			}

			System.out.println(winner);

		}
	}
}

Measured memory_bytes: 16884
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1
{
    class ITP1_2_B
    {
        static void Main(string[] args)
        {
            int a = 0, b = 0, c = 0;

            List<int> numberList = Console.ReadLine().Split().Select(int.Parse).ToList<int>();

            a = numberList[0];
            b = numberList[1];
            c = numberList[2];

            if ((a < b) && (b < c))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}



Measured memory_bytes: 18368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  if(S == "Sunny") cout << "Cloudy" << endl;
  else if(S == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
from collections import deque


def main():
    n = int(input())
    deq = deque()
    for i in range(n):
        query = input()
        if (query[0] == '0'):
            vals = query.split(" ")
            d = int(vals[1])
            elem = int(vals[2])
            if d == 0:
                deq.appendleft(elem)
            else:
                deq.append(elem)
        elif (query[0] == '1'):
            vals = query.split(" ")
            idx = int(vals[1])
            print(deq[idx])
        elif (query[0] == '2'):
            vals = query.split(" ")
            d = int(vals[1])
            if d == 0:
                deq.popleft()
            else:
                deq.pop()


if __name__ == '__main__':
    main()



Measured memory_bytes: 21820
/*  
   |\_/|
   |* *|
   \_+_/
          */
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int used[10];
int cnt=0;

vector<int>node[10];
  
int N,M;

int ans=0;

int dfs(int i){

  if(cnt==N-1){
    ans++;
  }
  
  used[i]=1;
  
  for(int j=0;j<node[i].size();j++){

    if(used[node[i][j]]==0){
      cnt++;
      dfs(node[i][j]);
      used[node[i][j]]=0;
      cnt--;
    }

  }

  return 0;
}

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  cin>>N>>M;

  int a,b;  
  
  for(int i=0;i<M;i++){
    cin>>a>>b;

    node[a].push_back(b);
    node[b].push_back(a);

  }

  dfs(1);

  cout<<ans<<endl;
  
  return 0;

}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll a; cin>>a;
  ll ans=a+a*a+a*a*a;
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstring>

using namespace std;

int g[5][5];
bool vis[5][5];

int main(){
	int a,n;
for(a=0;a<3;a++)cin>>g[a][0]>>g[a][1]>>g[a][2];
    cin>>n;
for(a=0;a<n;a++){int b;cin>>b; for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(g[i][j]==b)vis[i][j]=1;
}
bool flag=0;
if(vis[0][0]&&vis[0][1]&&vis[0][2])flag=1;
else if(vis[0][0]&&vis[1][1]&&vis[2][2])flag=1;
else if(vis[0][0]&&vis[1][0]&&vis[2][0])flag=1;
else if(vis[0][1]&&vis[1][1]&&vis[2][1])flag=1;
else if(vis[0][2]&&vis[1][2]&&vis[2][2])flag=1;
else if(vis[1][0]&&vis[1][1]&&vis[1][2])flag=1;
else if(vis[2][0]&&vis[2][1]&&vis[2][2])flag=1;
else if(vis[0][2]&&vis[1][1]&&vis[2][0])flag=1;
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define N 200000
 
int main(){
  int n, i, j, maxv = 0, minv = 0;
  int a[N];
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
 
  minv = a[0];
  maxv = a[1] - a[0];
  for(j = 1; j < n; j++){
    if(maxv < (a[j] - minv)) maxv = a[j] - minv;
    if(minv > a[j]) minv = a[j];
  }
 
  printf("%d\n", maxv);
 
  return 0;
}

Measured memory_bytes: 1376
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for j in range(m)]
[print(*x) for x in [[sum(j*k for j, k in zip(x, y)) for y in zip(*b)] for x in a]]


Measured memory_bytes: 7008
fn solve() {
    let stdin = std::io::stdin();
    let mut scn = Scanner { stdin: stdin.lock() };
    let k: i64 = scn.read();
    let n: usize = scn.read();
    let a: Vec<i64> = scn.vec(n);
    let mut costs = vec![];
    for x in a.windows(2) {
        costs.push((x[0] - x[1]).abs());
    }
    costs.push((k- a[n - 1] + a[0]).abs());
    costs.sort();
    let mut result = 0;
    for x in costs.iter().take(n-1) {
        result += *x;
    }
    println!("{}", result);

}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    string s;
    cin >> s;
    int N = s.size();
    int count = 0;
    int start[N];
    rep(i, N-2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            start[count] = i;
            count++;
        }
    }
    ll L[count], R[count];
    rep(i, count){
        L[i] = 1;
        int posL = start[i];
        while(posL-1 >= 0){
            if(s[posL-1] == 'A'){
                L[i]++;
                posL--;
            }
            else break;
        }
        R[i] = 1;
        int posR = start[i]+2;
        while(posR+2 < N){
            if(s[posR+1] == 'B' && s[posR+2] == 'C'){
                R[i]++;
                posR += 2;
            }
            else break;
        }
    }
    ll ans = 0;
    rep(i, count) ans += L[i]*R[i];
    int i = 0;
    while(i < count-1){
        int j = 1;
        while(start[i+j-1]+2*R[i+j-1]+L[i+j] == start[i+j]) j++;
        rep2(k, i, i+j-1){
            rep2(l, k+1, i+j) ans += L[k]*R[l];
        }
        i += j;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1284
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

template <typename T, class F = std::function<T(const T&, const T&)>>
class SegmentTree {
public:
  SegmentTree(size_t n, T i, F f) : identity(i), operation(f) {
    for (size = 1; size < n; size <<= 1) {}
    data.assign(size * 2, identity);
  }

  void update(size_t i, T value) {
    for (data[i += size] = value; i > 1; i >>= 1)
      data[i >> 1] = operation(data[i >> 1 << 1], data[i >> 1 << 1 | 1]);
  }
  // [a,b)
  T query(size_t l, size_t r) {
    T res = identity;
    for (l += size, r += size; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res = operation(res, data[l++]);
      if (r & 1) res = operation(data[--r], res);
    }
    return res;
  }

private:
  size_t size;    // num of leaves
  vector<T> data; // root index is 1
  T identity;
  F operation;
};

int main() {
  int n;
  string s;
  int q;
  cin >> n >> s >> q;
  SegmentTree<int> st(n, 0, [](int a, int b) { return a | b; });

  rep(i, 0, n) {
    int c = s[i] - 'a';
    st.update(i, 1 << c);
  }

  int t;
  while (q--) {
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      st.update(i - 1, 1 << (c - 'a'));
    } else {
      int l, r;
      cin >> l >> r;
      int bit = st.query(l - 1, r);
      cout << __builtin_popcount(bit) << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 7956
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    map<char,int>mp;
    rep(i,n) {
        string s;
        cin >> s;
        mp[s[0]]++;
    }
    vector<int>p = {0,0,0,0,0,0,1,1,1,2};
    vector<int>q = {1,1,1,2,2,3,2,2,3,3};
    vector<int>r = {2,3,4,3,4,4,3,4,4,4};
    vector<ll>D(5);
    D[0] = mp['M'];D[1] = mp['A'];D[2] = mp['R'];D[3] = mp['C'];D[4] = mp['H'];
    ll ans = 0;
    rep(i,10) {
        ans += D[p[i]]*D[q[i]]*D[r[i]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
N, M = map(int, input().split())
A = list(map(int, input().split()))

B = A[:M]
sumA = sum(A)
check = 4*M
checkA=0
A = sorted(A ,reverse=True)

i = 0
while i<len(B):
    if A[i]>= (sumA/check):
        checkA+=0
    else:
        checkA+=1
    
    i+=1

if checkA==0:
    print("Yes")
else:
    print("No")

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

#define ll long long
#define pii pair<int,int>
#define two(x) (x<<1)
#define towd(x) (x>>1)
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define x first
#define y second
#define re return

int main(){
	ll n,p;
	cin>>n>>p;
	ll res=1;
	if (n==1){
		cout<<p;re 0;
	}
	if (n>=40){
		cout<<1;re 0;
	}
	for (ll i=2; i*i<=p; i++){
		if (p%i==0){
			ll cnt=0;
			while (p%i==0){
				cnt++;
				p/=i;
			}
			ll t=cnt/n;
			while (t--) res*=i;
		}
	}
	cout<<res;
	re 0;
}

Measured memory_bytes: 256
class DisjointSet:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.siz = [1]*n

    def root(self,x):
        if x != self.parent[x]: 
            self.parent[x] = self.root(self.parent[x])
        return self.parent[x]

    def same(self,x,y): 
        return self.root(x) == self.root(y)

    def unite(self,x,y): 
        x = self.root(x)
        y = self.root(y)
        if x == y: 
            return
        if self.siz[x] < self.siz[y]: 
            x,y = y,x
        self.parent[y] = x
        self.siz[x] += self.siz[y]

    def size(self,x):
        return self.siz[self.root(x)]

n,m,k = map(int,input().split())
cnt = [0]*n
ds = DisjointSet(n)
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    cnt[a] += 1
    cnt[b] += 1
    ds.unite(a,b)
for _ in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    if ds.same(c,d):
        cnt[c] += 1
        cnt[d] += 1
ans = [ds.size(i) - cnt[i] - 1 for i in range(n)]
print(*ans)

Measured memory_bytes: 11832
{-# LANGUAGE Strict #-}
import qualified Data.Array.Unboxed    as A
import qualified Data.ByteString.Char8 as B
import           Data.List             (unfoldr)


main :: IO ()
main = do
  n <- readLn
  as <- readIntsLn
  putStr . unlines . map show $ solve n as

solve :: Int -> [Int] -> [Int]
solve n as = A.elems xs
  where xs = A.accumArray (+) 0 (1, n) [(a, 1) | a <- as]:: A.UArray Int Int

readIntsLn :: IO [Int]
readIntsLn = unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine


Measured memory_bytes: 9648
import sys
input = sys.stdin.readline

n = int(input())

X = [list(map(int,input().split())) for i in range(n)]

ans = 0
for i in range(n):
    for j in range(n):
        ans += ((X[i][0]-X[j][0]) ** 2 + (X[i][1]-X[j][1]) ** 2) ** 0.5

print(ans /n)

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

int gcd(int p,int q){
    if(p%q == 0){
        return q;
    }
        return gcd(q,p%q);
}

int main(){
    int64_t N; cin >> N;
    int64_t cnt = 0;
    map<string,int> S;

    rep(i,N){
        string s; cin >> s;
        if(S.count(s)){

        }else{
            S[s] = 1;
            cnt++;
        }
    }

    cout << cnt << endl;
}



Measured memory_bytes: 19228
import itertools

N = int(input())
P = [int(a) for a in input().split()]
Q = [int(a) for a in input().split()]


listN=list(itertools.permutations(range(1,N+1)))
countP = 0
for i in range(0,len(listN)):
    if list(listN[i])==P:
        break
    else:
        countP+=1



countQ = 0
for j in range(0,len(listN)):
    if list(listN[j])==Q:
        break

    else:
        countQ+=1

print(abs(countP-countQ))


Measured memory_bytes: 8180
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int ll;

int main(){
	ll L, R;
	cin >> L >> R;
	if(R - L + 1 >= 2019){
		cout << 0 << endl;
	}else{
		ll ret = 1LL << 60;
		for(ll i = L; i <= R; i++){
			for(ll j = i + 1; j <= R; j++){
				ret = min(ret, (i % 2019) * (j % 2019) % 2019);
			}
		}
		cout << ret << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

#define reps(i,f,n) for(ll i=f; i<ll(n); ++i)
#define rep(i,n) reps(i,0,n)

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;

bool f()
{
    int h, w;
    cin >> h >> w;
    
    int hist[26] = {};
    
    rep(i, h){
        string s;
        cin >> s;
        rep(j, w){
            hist[s[j]-'a']++;
        }
    }
    
    int x[4] = {};
    rep(i, 26){
        x[hist[i] % 4]++;
    }
    
    if(h%2 == 0 && w%2 == 0){
        return x[0] == 26;
    }
    
    if(h%2 == 0 && w%2 != 0){
        return x[1] == 0 && x[3] == 0 && x[2] <= h/2;
    }
    
    if(h%2 != 0 && w%2 == 0){
        return x[1] == 0 && x[3] == 0 && x[2] <= w/2;
    }
    
    if(h%2 != 0 && w%2 != 0){
        return x[1] + x[3] <= 1 && x[2] + x[3] <= (h+w)/2;
    }
}

signed main()
{
    cout << (f() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 100000007
typedef pair<short,short> P;
int main(void){
	int n,m;
	cin>>n>>m;
	P a[n],b[m];
	short x,y;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		a[i]=P(x,y);
	}
	for(int i=0;i<m;i++){
		cin>>x>>y;
		b[i]=P(x,y);
	}
	vector<P> cost[n+1];
	vector<short> rin[n+1];
	for(int i=0;i<m;i++){
		P p=b[i];
		rin[p.first].push_back(p.second);
		rin[p.second].push_back(p.first);
	}
	for(int i=0;i<n;i++){
		int lim=a[i].second;
		int flg[n+1]; fill(flg,flg+n+1,0);
		queue<P> q;
		q.push(P(i+1,0));
		while(!q.empty()){
			P p=q.front(); q.pop();
			for(int j=0;j<rin[p.first].size();j++){
				if(rin[p.first][j]!=i+1){
					cost[i+1].push_back(P(rin[p.first][j],a[i].first));
					if(p.second<lim-1&&flg[rin[p.first][j]]!=1){
						flg[rin[p.first][j]]=1;
						q.push(P(rin[p.first][j],p.second+1));
					}
				}
			}
		}
	}
/*	for(int i=1;i<=n;i++){
		for(int j=0;j<cost[i].size();j++){
			cout<<cost[i][j].first<<':'<<cost[i][j].second<<' ';
		}
		cout<<endl;
	}*/
	int leng[n+1]; fill(leng,leng+n+1,M);
	priority_queue<P,vector<P>,greater<P> > que;
	leng[1]=0; que.push(P(0,1));
	while(!que.empty()){
		P p=que.top(); que.pop();
		int v=p.second;
		if(leng[v]<p.first) continue;
		for(int i=0;i<cost[v].size();i++){
			P u=cost[v][i];
			int t=leng[v]+u.second;
			if(leng[u.first]>t){
				leng[u.first]=t;
				que.push(P(t,u.first));
			}
		}
	}
	cout<<leng[n]<<endl;
	return 0;
}


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

int N;
double x[8], y[8];

double dist(int i, int j){
    return sqrt( (x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]) );
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++)
        cin >> x[i] >> y[i];

    vector<int> v(N);
    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定

    double sum = 0;
    do{
        // print(v);
        for(int i=1;i<N;i++){
            sum += dist(v[i-1] - 1, v[i] - 1);
        }
    }while( next_permutation(v.begin(), v.end()) );

    double f = 1;
    for(double i=N;i>=1;i--)
        f = f*i;

    printf("%.10lf\n", sum/f);

}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
const int N=100000+10;
int a[N],n;
bool vis[N];

int main(){
	scanf("%d",&n);a[0]=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		if(i-1&&a[i-1]>a[i]){
			if(!vis[i-1]){
				a[i-1]--;vis[i-1]=1;
				if(a[i-1]>a[i]){
					printf("No");
					return 0;
				} else {
					int k=i-2;
					if(k) while(k&&a[k]>a[k+1]){
						if(vis[k]){
							printf("No");
							return 0;
						} else {
							a[k]--;
							vis[k]=1;
							if(a[k]>a[k+1]){
								printf("No");
								return 0;
							}
						}
						k--;
					}
				}
			} else {
				printf("No");
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 768
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    x = int(input())
    kyu = 8
    for i in range(400, 1801, 200):
        if i <= x <= i+199:
            print(kyu)
        kyu -= 1
    return 0

if __name__ == "__main__":
    solve()

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);


    for(int i=0;i<n;i++){
        cin >>v[i];
    }
    sort(v.begin(), v.end());

    bool ok = 1;
    for(int i=1;i<n;i++){
        if(v[i]==v[i-1]){
            ok = 0;
            break;
        }
    }
    cout<<(ok? "YES":"NO")<<endl;
}


Measured memory_bytes: 1024
def main():
    k, s = map(int, input().split())

    res = 0

    for x in range(k+1):
        for y in range(k+1):
            z = s - (x + y)
            if z <= k and z >= 0:
                res += 1
        
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,ans[60]={};
    cin>>k;
    cout<<50<<endl;
    rep(i,50){
        ans[i]+=(49-i+k/50);
    }
    rep(i,k%50){
        ans[i]++;
    }
    rep(i,50){
        if(i!=49) cout<<ans[i]<<" ";
        else cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
// :)
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <vector>

typedef long long ll;

using namespace std;

std::random_device rd_device;
std::mt19937 rng(rd_device());

int main() {
    ios::sync_with_stdio(false);
    cin.exceptions(ios_base::failbit);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(10);
    cout<<fixed;
    
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i=0;i<n;i++) {
        cin>>v[i];
    }

    map<int, int> cnt0, cnt1;
    for(int i=0;i<n;i++) {
        if (i % 2) cnt1[v[i]]++;
        else cnt0[v[i]]++;
    }    
    priority_queue<pair<int, int>> c0, c1;
    for (auto &p : cnt0) {
        c0.push(make_pair(p.second, p.first));
    }
    for (auto &p : cnt1) {
        c1.push(make_pair(p.second, p.first));
    }
    pair<int, int> r0 = c0.top();
    c0.pop();
    pair<int, int> r1 = c1.top();
    c1.pop();
    
    if (r0.second != r1.second) {
        cout<<n - r0.first - r1.first<<endl;
    } else {
        if (c0.size() != 0 && c1.size() != 0) {
            pair<int, int> r01 = c0.top();
            c0.pop();
            pair<int, int> r11 = c1.top();
            c1.pop();
            if (r01.first + r1.first > r11.first + r0.first) {
                cout<<n - r01.first - r1.first<<endl;
            } else {
                cout<<n - r11.first - r0.first<<endl;
            }
        } else if (c0.size() != 0) {
            pair<int, int> r01 = c0.top();
            c0.pop();
            cout<<n - r01.first - r1.first<<endl;
        } else if (c1.size() != 0) {
            pair<int, int> r11 = c1.top();
            c1.pop();
            cout<<n - r11.first - r0.first<<endl;
        } else {
            cout<<n/2<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 6524