akhauriyash/Code-Regression huggingface dataset:
BIGMOD = 10**9+7

def modPow(x,n):
    ans = 1
    while n >= 1:
        if bin( n & 1)==bin(1):
            ans = (ans*x) % BIGMOD
        x = x * x % BIGMOD
        n = n>>1
    return ans % BIGMOD

def modFact(N):
    fact = []
    fact.append(1) #0! = 1
    for i in range(1,N+1):
        a = fact[i-1]*i % BIGMOD
        fact.append(a)
    return fact

def modInvFact(fact):
    invFact = []
    for i in range(1,N+2):
        a = modPow(fact[i-1],BIGMOD-2)
        invFact.append(a)
    return invFact

def modPlus(a,b):
    return (a + b) % BIGMOD

def modMinus(a,b):
    if a-b >= 0:
        return (a - b) % BIGMOD
    else:
        return (a - b + BIGMOD)
    
def modMulti(a,b):
    return a * b % BIGMOD

# fact(n),invFact(r),invFact(n-r)
def nCr(fact,invFact,n,r):
    return (fact[n] * invFact[r] * invFact[n-r] ) %BIGMOD

N,M = map(int,input().split())
fact = modFact(max(N,M))
factN = fact[N]
factM = fact[M]
ans = 0
if abs(N-M) == 0:
    ans = modMulti(factN,factM)*2 % BIGMOD
elif abs(N-M) == 1:
    ans = modMulti(factN,factM)
else:
    ans = 0
    
print(ans)

Measured memory_bytes: 7088
#include <iostream>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

int main(){
    int K, S;
    cin >> K >> S;
    int c = 0;
    for (int i=0; i<= K; i++){
        for (int j=0; j<=K; j++){
            if ((S - i - j <= K) && (0 <= S - i - j)) c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
n = int(input())
t = []
sum = 0
p = []
x = []

line = input().split(" ")
for i in range(n):
    t.append(int(line[i]))
    sum += int(line[i])

m = int(input())
for i in range(m):
    line = input().split(" ")
    p.append(int(line[0]) - 1)
    x.append(int(line[1]))

for i in range(m):
    for j in range(len(t)):
        if j == p[i]:
            comp = sum - t[j] + x[i]
    print(comp)

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<cctype>
using namespace std;
int main()
{
  map<char,int> m;
  m['m']=1000;
  m['c']=100;
  m['x']=10;
  m['i']=1;
  int n,a,b,i;
  string s,t;
  cin>>n;
  while(cin>>s){
    a=0;
    for(i=0;i<s.size();i++){
      if(isalpha(s[i])){
	if(i-1>=0){
	  if(isdigit(s[i-1]))a+=(s[i-1]-'0')*m[s[i]];
	  else a+=m[s[i]];
	}else{
	  a+=m[s[i]];
	}
      }
    }
    cin>>s;
    for(i=0;i<s.size();i++){
      if(isalpha(s[i])){
	if(i-1>=0){
	  if(isdigit(s[i-1]))a+=(s[i-1]-'0')*m[s[i]];
	  else a+=m[s[i]];
	}else{
	  a+=m[s[i]];
	}
      }
    }
    b=0;
    while(a>=1000){b++;a-=1000;}
    if(b){
      if(b>1)cout<<b;
      cout<<"m";
    }
    b=0;
    while(a>=100){b++;a-=100;}
    if(b){
      if(b>1)cout<<b;
      cout<<"c";
    }
    b=0;
    while(a>=10){b++;a-=10;}
    if(b){
      if(b>1)cout<<b;
      cout<<"x";
    }
    b=0;
    while(a>=1){b++;a-=1;}
    if(b){
      if(b>1)cout<<b;
      cout<<"i";
    }
    cout<<endl;
  }
}

Measured memory_bytes: 0
import sys
n,k = map(int,input().split())
if k == 1:
    print(1)
    sys.exit()
a = n
n0 = n
i = 0
sum = 0
power_list = [0] * 24
if n > k:
    power_list[0] = n - k + 1
    n = k - 1
    a = k 
i = 1
a = k
while a != 1:
    if a % 2 == 0 and a//2 > n:
        a = a//2
        k = a
        i += 1
    elif a % 2 == 0 and a//2 <= n:
        power_list[i] = n - a//2 + 1
        n = a//2 - 1
        a = a//2
        i += 1
    else:
        a += 1
for i in range(24):
    sum += (1/2)**i * power_list[i] / n0
#print(power_list)
print(sum)
    


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

int main(){
  char s[1010], t[1010];
  scanf("%s %s", s, t);
  int i, j, count = 0, high = 0;

  for(j = 0; j <= (strlen(s) - strlen(t)); j++){
    for(i = j; i < (strlen(t) + j); i++){
      if(s[i] == t[i - j]){
        count++;
      }
    }
    if(count >= high){
      high = count;
    }
    count = 0;
  }

  printf("%d\n", strlen(t) - high);
  return 0;
}


Measured memory_bytes: 1736
import numpy as np


def main():
    city_count, express_count, query_count = map(int, input().split())

    city_list = np.zeros((city_count + 1, city_count + 1), np.int_)

    for _ in range(express_count):
        l, r = map(int, input().split())
        city_list[l, r] += 1

    city_list.cumsum(1, out=city_list)
    city_list.cumsum(0, out=city_list)

    for _ in range(query_count):
        p, q = map(int, input().split())
        print(city_list[q, q] - city_list[p - 1, q])


if __name__ == '__main__':
    main()


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

int main(){
    int layers;
    cin >> layers;
    vector<int> array;
    for(int i = 0; i < layers; i++){
        int c;
        cin >> c;
        array.push_back(c);
    }
    sort(array.begin() , array.end());
    int sum = 1;
    for(int i = layers -2; i >= 0; i--){
        //cout << "location: " << array[i] << endl;
        //if(array[i] == array[i+1]) continue;
        if(array[i] < array[i+1]) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  int64_t x;
  cin>>x;
  vector<int64_t>A(N+1);
  A.at(0)=0;
  for(int i=1;i<=N;i++)
    cin>>A.at(i);
  int64_t ans=0;
  for(int i=0;i<N;i++){
  if(x<A.at(i)+A.at(i+1)){
  int64_t y=A.at(i)+A.at(i+1)-x;
    A.at(i+1)-=y;
    ans+=y;
  
  }
   
  
  }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1024
import * as readline from 'readline';
const rl = readline.createInterface(process.stdin, process.stdout);

let line = 0;
let n: number;
let a: number[] = [];
let b: number[];

rl.on("line", input => {
  line++;
  if (line === 1) {
    n = parseInt(input);
    a.length = n;
    for (let i = 0; i < n-1; i++) a[i] = 0;
  } else {
    b = input.split(/\s+/).map(val=>parseInt(val));
    a[0] = b[0];
    for (let i = 0; i < n-1; i++) {
      a[i+1] = b[i];
      if (a[i] > b[i]) a[i] = b[i];
    }
    let x = 0;
    for (let i = 0; i < n; i++) {
      x += a[i];
    }
    console.log(x);
  }
});

Measured memory_bytes: 7628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
typedef pair<int, int> P;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int n; string a, b, c; cin >> n >> a >> b >> c;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == b[i] && b[i] != c[i]){
            cnt++;
        } else if(a[i] != b[i] && b[i] == c[i]){
            cnt++;
        } else if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]){
            cnt += 2;
        } else if(a[i] == c[i] && a[i] != b[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    ll n,m;
    cin >> n >> m;
    map<ll,ll> d;

    rep(i,0,n){
	ll a;
	cin >> a;
	d[-a]++;
    }
    rep(i,0,m){
	ll b,c;
	cin >> b >> c;
	d[-c] += b;
    }
    ll ans = 0;
    for(auto i:d){
	ans += -i.ft * min(n,i.sd);
	n -= min(n,i.sd);
	if(n <= 0)break;
    }
    P(ans);
    return  0;
}


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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
    }
    println!("{}",
        if a <= c && c <= b { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
# 一番小さい値と大きい値を比べるその値と一致していたら、他の数値で試す
def getLCM(num1,num2):
    base1 = num1
    base2 = num2
    while 1:
        if num1 < num2:
            num1 =  num1 + base1
        elif num1 > num2:
            num2 =  num2 + base2
        elif num1 == num2:
            return num1

def getNextLCM(base1,base2,lcm):
    num1 = lcm + base1
    num2 = lcm
    while 1:
        if num1 < num2:
            num1 =  num1 + base1
        elif num1 > num2:
            num2 =  num2 + base2
        elif num1 == num2:
            return num1
while 1:
    try:
        n = int(input())
        numbers = list(int(x) for x in input().split())
    except:break
    
    # 1があったら消す
    if 1 in numbers:
        numbers.remove(1)
    numbers = sorted(numbers)
    reduceIndex = []
    size = len(numbers) - 1
    
    # for i in numbers:
    #     print(str(i) + " ",end="")
    # print()
    
    # 割れたらその数を消す
    while(size > 1):
        isReduce = False
        
        for i in range(size - 1,-1,-1) :
            if numbers[size] % numbers[i] == 0:
                reduceIndex.append(numbers[i])
                isReduce = True
        for i in reduceIndex:
            numbers.remove(i)
        if isReduce:
            size = len(numbers) - 1
            reduceIndex.clear()
        else:
            size = size - 1
            
    # for i in numbers:
    #     print(str(i) + " ",end="")
    # print()
    
    size = len(numbers)
    if size == 1:
        print(numbers[size - 1])
        break
    
    lcm = getLCM(numbers[size - 1],numbers[size - 2])
    
    while(1):
        isFind = True
        for i in range(size - 2,-1,-1):
            # print(i)
            # print(lcm % numbers[i])
            if lcm % numbers[i] != 0:
                i = -1
                isFind = False
 
        if isFind:
            break
        else:
            lcm = getNextLCM(numbers[size - 2],numbers[size - 1],lcm)
    print(lcm)


Measured memory_bytes: 5608
import java.io.*;

class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
                int x = 0;
                int[] b = new int[100000];
                int a = 1;

                while(a != 0){
                    String line = reader.readLine();
                    a = Integer.parseInt(line);
                    b[x] = a;
                    x += 1;
                }

                for(int i = 0; i < (x - 1); i++){
                    System.out.println("Case " + (i+1) + ": " + b[i]);
                }
                
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 32160
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	string s;
	cin >> s;
	int n = s.size();
	set<char> st;
	string ans = "yes";
	rep(i, n) {
		if (st.count(s[i])) {
			ans = "no";
			break;
		}
		else {
			st.insert(s[i]);
		}
	}
	cout << ans << endl;
		return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N, M;
    std::cin >> N >> M;

    if (N == 1 && M == 1)
    {
        std::cout << 1 << std::endl;
        return;
    }
    if (N == 1)
    {
        std::cout << M - 2 << std::endl;
        return;
    }
    if (M == 1)
    {
        std::cout << N - 2 << std::endl;
        return;
    }
    std::cout << (M - 2) * (N - 2) << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int x[110000];
    int sa[110000];
    int min = 0;

    for (int i = 0; i < m; i++)
    {
        cin >> x[i];
    }
    if (n >= m)
        cout << 0 << endl;
    else
    {
        sort(x, x + m);
        for (int i = 1; i < m; i++)
        {
            sa[i - 1] = x[i] - x[i - 1];
        }
        sort(sa, sa + m - 1);
        for (int i = 0; i < m - n; i++)
        {
            min += sa[i];
        }
        cout << min << endl;
    }
    return 0;
}

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

#define INF 1e9

int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }

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

    vector<vector<int> > dp(n, vector<int>(n + 1, 0));
    for(int k = 2; k <= n; k++){
      for(int i = 0; i < n; i++){
        if(i + k <= n){
          for(int j = 1; j < k; j++)
            dp[i][i + k] = max(dp[i][i + k], dp[i][i + j] + dp[i + j][i + k]);
          if(dp[i + 1][i + k - 1] == k - 2 && abs(w[i] - w[i + k - 1]) <= 1)
            dp[i][i + k] = dp[i + 1][i + k - 1] + 2;
        }
      }
    }

    cout << dp[0][n] << endl;
  }

  return 0;
}

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


int main() {

        int n;
        cin >> n;
        int last, res = 1;
        int dir = 0;
        cin >> last;
        for(int i = 1; i < n; ++i) {
                int curr;
                cin >> curr;
                if(curr == last) continue;
                int ndir = curr > last ? 1 : -1;
                if(dir * ndir < 0) {
                        ++res;
                        ndir = 0;
                }
                dir = ndir;
                last = curr;
        }

        cout << res << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;

void solve(){
  int n, m; cin >> n >> m;
  vector<vector<int> > v(n + 1);
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  queue<int> q;
  q.push(1);
  vector<bool> visited(n + 1, false);
  vector<int> ans(n + 1);
  visited[1] = true;
  while(q.size() > 0){
    int c = q.front();
    q.pop();
    for(int i = 0; i < v[c].size(); i++){
      int nx = v[c][i];
      if(visited[nx] == true) continue;
      visited[nx] = true;
      ans[nx] = c;
      q.push(nx);
    }
  }
  cout << "Yes" << endl;
  for(int i = 2; i <= n; i++){
    cout << ans[i] << endl;
  }
  return;
}

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


Measured memory_bytes: 10152
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int n; cin >> n;
  V x(n);
  rep(i, n) {
    int p; cin >> p;
    p--;
    x[p] = i+1;
  }

  V a = x;
  V b = x;
  rep(i, n-1) a[i+1] += a[i];
  rep(i, n-1) b[n-i-2] += b[n-i-1];
  
  rep(i, n) cout << a[i] << " ";
  cout << endl;
  rep(i, n) cout << b[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#define MAX 2000000

int n,A[MAX+1];

int main() {
  int i;

  scanf("%d",&n);
  for(i = 1 ; i <= n ; i++) {
    scanf("%d",&A[i]);
  }
  for(i = n / 2 ; i >= 1 ; i--) {
    maxHeapify(i);
  }
  
  for(i = 1 ; i <= n ; i++) {
    printf(" %d", A[i]);
  }
  printf("\n");
  return 0;
}

int maxHeapify(int i) {
  int l,r,largest,tmp;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= n && A[l] > A[i])
    largest = l;
  else largest = i;
  if(r <= n && A[r] > A[largest])
    largest = r;
  if (largest != i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}



Measured memory_bytes: 3692
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int x;
    scanf("%d",&x);
    int sz[x];
    int i;
    for(i=0;i<x;i++)
    {
        scanf("%d",&sz[i]);
    }
    sort(sz,sz+x);
    printf("%d",sz[x-1]-sz[0]);
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    if(n%2){
        cout << "No" << endl;
        return 0;
    }
    bool y = true;
    for(int i = 0; i < n; i+=2){
        y &= s.substr(i,2)=="hi";
    }
    cout << (y ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
from typing import Callable, TypeVar, List

T = TypeVar('T')


class SegTree:
    def __init__(self, v: List[T], op: Callable[[T, T], T], e: Callable[[], T]) -> None:
        self._n = len(v)
        self.log = (self._n - 1).bit_length()
        self.size = 1 << self.log
        self.d = [e() for _ in range(2 * self.size)]
        self.op = op
        self.e = e
        for i in range(self._n):
            self.d[self.size + i] = v[i]
        for i in reversed(range(1, self.size)):
            self.__update__(i)

    @classmethod
    def init_e(cls, n: int, op: Callable[[T, T], T], e: Callable[[], T]) -> 'SegTree':
        return cls([e() for _ in range(n)], op, e)

    def set(self, p: int, x: T) -> None:
        p += self.size
        self.d[p] = x
        for i in range(1, self.log + 1):
            self.__update__(p >> i)

    def get(self, p: int) -> T:
        return self.d[p + self.size]

    def prod(self, l: int, r: int) -> T:
        sml = self.e()
        smr = self.e()
        l += self.size
        r += self.size

        while l < r:
            if l & 1:
                sml = self.op(sml, self.d[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.d[r], smr)
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self) -> T:
        return self.d[1]

    def max_right(self, l: int, f: Callable[[T], bool]):
        if l == self._n:
            return self._n
        l += self.size
        sm = self.e()
        while True:
            while l % 2 == 0:
                l >>= 1
            if not f(self.op(sm, self.d[l])):
                while l < self.size:
                    l *= 2
                    if f(self.op(sm, self.d[l])):
                        sm = self.op(sm, self.d[l])
                        l += 1
                return l - self.size
            sm = self.op(sm, self.d[l])
            l += 1
            if (l & -l) == l:
                return self._n

    def min_left(self, r: int, f: Callable[[T], bool]):
        assert 0 <= r <= self._n
        assert f(self.e())
        if r == 0:
            return 0
        r += self.size
        sm = self.e()
        while True:
            r -= 1
            while r > 1 and r % 2:
                r >>= 1
            if not f(self.op(self.d[r], sm)):
                while r < self.size:
                    r = 2 * r + 1
                    if f(self.op(self.d[r], sm)):
                        sm = self.op(self.d[r], sm)
                        r -= 1
                return r + 1 - self.size
            sm = self.op(self.d[r], sm)
            if (r & -r) == r:
                return 0

    def __update__(self, k: int) -> None:
        self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1])


n, k = map(int, input().split())
seg = SegTree([0]*400000, max, lambda: 0)
for _ in range(n):
    a = int(input())
    ma = seg.prod(max(0, a-k), min(400000, a+k+1))
    seg.set(a, ma+1)
print(seg.all_prod())


Measured memory_bytes: 148592
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
 
P project(P a,P b,P c){
  b-=a,c-=a;
  return a+b*real(c/b);
}
 
int main(){
  int n;
  double ax,ay,bx,by,cx,cy;
  cin>>ax>>ay>>bx>>by>>n;
  while(n--){
    cin>>cx>>cy;
    P p=project(P(ax,ay),P(bx,by),P(cx,cy));
    printf("%.8f %.8f\n",p.real(),p.imag());
  }
  return 0;
}

Measured memory_bytes: 3284
#include<bits/stdc++.h>
#define maxn 200005
#define ll long long
#define mod 1000000007
using namespace std;
ll a[maxn],n,k,fhw,l,r,ans=1;
bool cmp(ll x,ll y){return x>y;}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;++i) 
		scanf("%lld",&a[i]);
	sort(a,a+n);
	l=0;r=n-1;
	if(k&1) k--,ans*=a[r--];
	if(ans<0) fhw=-1;else fhw=1;
	while(k){
		if(a[l]*a[l+1]*fhw<a[r]*a[r-1]*fhw) (ans*=a[r]*a[r-1]%mod)%=mod,r-=2;
		else (ans*=a[l]*a[l+1]%mod)%=mod,l+=2;
		k-=2;
	}
	cout<<(ans%mod+mod)%mod;
	
	return 0;
}

Measured memory_bytes: 5332
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int inf = 1001001001;
int main(){
  int N,M,S,T,i,u,v;scanf("%d%d",&N,&M);
  vector<int> G[N];
  for(i=0;i<M;i++){
    scanf("%d%d",&u,&v);u--;v--;
    G[u].push_back(v);
  }
  scanf("%d%d",&S,&T);S--;T--;
  int D[N][3];
  for(i=0;i<N;i++) fill(D[i],D[i]+3,inf);
  D[S][0] = 0;
  queue<pair<int,int>> q;q.push(make_pair(S,0));
  int fn,fd;
  while(!q.empty()){
    fn = q.front().first;fd = q.front().second;q.pop();
    for(i=0;i<G[fn].size();i++){
      if(D[G[fn][i]][(fd+1)%3] == inf){
        D[G[fn][i]][(fd+1)%3] = D[fn][fd]+1;
        q.push(make_pair(G[fn][i],(fd+1)%3));
      }
    }
  }
  if(D[T][0] == inf) printf("-1\n");
  else printf("%d\n",D[T][0]/3);
}


Measured memory_bytes: 10412
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    unordered_map<int, ll> mp;
    rep(i, n) mp[a[i]]++;
    ll ans = 0;
    for (auto kv : mp) {
        ans += kv.second * (kv.second-1) / 2;
    }
    rep(i, n) cout << ans - mp[a[i]] + 1 << endl;
    return 0;
}

Measured memory_bytes: 8392
# -*- coding: utf-8 -*-
import math

N,M = list(map(int,input().split()))
ret = 0
base = 10**9+7
if abs(N-M) > 1:
    pass
elif abs(N-M) == 1:
    ret = math.factorial(N) * math.factorial(M)%base
else:
    ret = math.factorial(N) ** 2 * 2 % base

print(ret)


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

constexpr int kMod = 1'000'000'000 + 7;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  std::cin >> n;
  std::vector<int> a(n), s(n + 1);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
    s[i + 1] = s[i] ^ a[i];
  }
  if (s[n] != 0) {
    std::vector<int> dp(n + 1);
    std::vector<int> sum(1 << 20);
    sum[0] = 1;
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
      dp[i] = sum[s[i] ^ s[n]];
      (sum[s[i]] += dp[i]) %= kMod;
    }
    std::cout << dp[n] << "\n";
    return 0;
  }
  std::vector<std::vector<int>> pos(1 << 20);
  for (int i = 1; i <= n; ++i) pos[s[i]].push_back(i);
  std::vector<int> zeros(n + 1);
  zeros[0] = 1;
  for (int i = 1; i <= n; ++i) {
    zeros[i] = zeros[i - 1];
    if (s[i] == 0) zeros[i]++;
  }
  int cut = 0;
  for (int i = 0, v = 0; i < n; ++i) {
    v ^= a[i];
    if (v == 0) cut++;
  }
  int ans = 1;
  for (int i = 0; i < cut - 1; ++i) ans = (ans + ans) % kMod;
  for (int v = 1; v < (1 << 20); ++v) {
    if (pos[v].empty()) continue;
    std::vector<int> dp(pos[v].size());
    int sum = 0, prod = 0;
    for (int i = 0; i < pos[v].size(); ++i) {
      dp[i] = (1 + 1LL * zeros[pos[v][i]] * sum % kMod + prod) % kMod;
      sum = (sum + dp[i]) % kMod;
      prod = (prod + 1LL * (kMod - dp[i]) * zeros[pos[v][i]]) % kMod;
    }
    ans = (ans + sum) % kMod;
  }
  std::cout << ans << "\n";
  return 0;
}


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

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

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

  string s;
  cin >> s;

  int ans = 700;
  rep(i, 3) {
    if (s.at(i) == 'o') {
      ans += 100;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets().split().map(&:to_i)[0]

c = 0

m = (n ** (1.0 / 2)).ceil
for i in 1..([m, n-1].min)
    if (n - i) % i == 0
      r = (n - i) / i
      if r <= i
        break
      end
      c += r
    end
end

puts c


Measured memory_bytes: 1788
fun main(args: Array<String>) {
    val (n, a, b, c) = readLine()!!.split(" ").map(String::toLong)
    val l = (1..n).map { readLine()!!.toLong() }
    var use = mutableListOf<MutableList<USE>>()
    
    // useにそれぞれの竹の利用方法の全パターンを網羅   
    val USES = USE.values()
    USES.forEach { use.add(mutableListOf(it)) }
    for (i in 1 until n) {
        val temp = mutableListOf<MutableList<USE>>()
        use.forEach { oit -> USES.forEach { temp.add((oit + it).toMutableList()) } }
        use = temp
    }

    // 全てのパターンにおいてコストを計算して最小値を得る
    var minCost = Long.MAX_VALUE
    for (u in use) {
        if (!(u.contains(USE.A) && u.contains(USE.B) && u.contains(USE.C))) continue
        var tempA = 0L
        var tempB = 0L
        var tempC = 0L
        var cost = 0L
        u.forEachIndexed { index, tu ->
            if (tu == USE.A) {
                if (tempA != 0L) cost += 10;tempA += l[index]
            }
            if (tu == USE.B) {
                if (tempB != 0L) cost += 10;tempB += l[index]
            }
            if (tu == USE.C) {
                if (tempC != 0L) cost += 10;tempC += l[index]
            }
        }
        cost += Math.abs(a - tempA)
        cost += Math.abs(b - tempB)
        cost += Math.abs(c - tempC)
        minCost = Math.min(minCost, cost)
    }
    println(minCost)

}

enum class USE { A, B, C, N }


Measured memory_bytes: 48368
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   string s;
   cin >> s;
   map<char, int> log;
   for (int i = 0; i < (int)s.size(); i++) {
      log[s[i]]++;
   }
   int cnt = 0;
   for (auto it = log.begin(); it != log.end(); it++) {
      cnt++;
      if (it->second != 2) {
         cout << "No" << endl;
         return 0;
      }
   }
   if (cnt != 2) cout << "No" << endl;
   else cout << "Yes" << endl;
   return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def check(N, A):
    if N == 1:
        return A
    A.sort()

    C = Counter(A)
    c0 = C.get(0, 0)
    if c0 == N:
        return A
    c1 = C.get(1, 0)
    rest = A[c0+c1:]
    back = []
    if c0 > 0:
        if c0 % 2 == 0:
            back = [0]*c0 + [1]*c1
        else:
            if c1 > 0:
                x = 1
                c1 -= 1
            else:
                x, *rest = rest
            back = [0]*(c0 ^ 1) + [x] + [0] + [1]*c1
    else:
        back = [1]*c1
    if len(rest) >= 2 and rest[-1] == 3 and rest[-2] == 2:
        rest[-1], rest[-2] = rest[-2], rest[-1]
    return rest + back
def solve():
    N, *A = map(int, open(0).read().split())
    ans = check(N, A)
    write("\n".join(map(str, ans)))
    write("\n")
solve()




Measured memory_bytes: 6016
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)
#define rep(i,n) for(Int (i)=0;(i)<(n);(i)++)
Int dp[20][54000];
Int table[54000];

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

	Int A,B,C,X;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> X;
	int res =0;
	rep(i,A+1)rep(j,B+1)rep(k,C+1)if(i*500+100*j+k*50 == X) res++;

cout << res <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
unordered_map<int, vector<int>> mp;
int memo[100000+10];
int vis[100000+10];
int dp(int s){
	if(vis[s]==1)
		return memo[s];
	vis[s] =1;
	for(int i:mp[s]){
		memo[s]=max(memo[s],dp(i)+1);
	}
	return memo[s];
}
void solve(){
	int n, m; cin>>n>>m;
	for (int i = 0; i < m; ++i)
	{
		int x, y; cin>>x>>y;
		mp[x].push_back(y);
	}
	for(int i=1;i<=n;i++){
		memo[i] = max(memo[i], dp(i));
	}
	int ans = INT_MIN;
	for (int i = 1; i <=n; ++i)
	{
		ans= max(ans, memo[i]);
	}
	cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // ll t; cin>>t;
    // while(t--)
        solve();
    return 0;
}



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

int panjang, panjangout;
string input, output;

int main (){
	cin>>input;
	panjang=input.length();					//biar ga loop ampe mati
	for (int i=0; i<panjang; i++){			
		panjangout=output.length();			//dptin kalo mau delete
		if (input [i]=='B'){
			if (panjangout==0){
				//jgn ngapa2in
			}else{
				output.erase(panjangout-1, 1);				//apus paling belakang
			}
		}else{
			output+=input[i];					//yey ditambah
		}
	}
	cout<<output<<endl;							//bismillah bener
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)

ll gcd(ll a, ll b)
{
	if (a < b)
		swap(a, b);
	return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

ll g( ll a, ll div0, ll div1 )
{
	return ( a / div0 ) + ( a /div1 )-(a/lcm(div0,div1));
}

int main()
{
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll bb = g(b,c,d);
	ll aa = g(a-1,c,d);
	ll divable = bb - aa;

	cout << b - a + 1 - divable << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double deg(double d){
    return M_PI * d /180;
}
double nijou(double f){
    return f * f;
}
int main(){
   int a,b,h,m;
   cin >> a >> b >> h >> m;
   printf("%.21f\n",sqrt(nijou(a*cos(deg(30.0 * h + m/2.0))-b*cos(deg(6 * m))) 
   + nijou(a*sin(deg(30.0 * h + m/2.0))-b*sin(deg(6 * m)))));
 
}

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

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

    int ans = 0;
    
    for(int i = 0; i < q; i++){
        int left = 0;
        int right = n;
        do
        {
            int center = (left + right) / 2;
            if(T[i] < S[center]){
                right = center;
            }
            else{
                left = center;
            }
        } while (left + 1 < right);  
        if(S[left] != T[i]) continue;
        ans++;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3284
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int D, N;
    cin >> D >> N;
    if (N == 100) {
        N = 101;
    }
    cout << int(N * pow(100, D)) << endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List

main :: IO()
main = do
  s <- getLine
  k <- getLine
  printf "%s" $ slv s (read k :: Int)

slv :: String -> Int -> String
slv s k = subStrs !! (k - 1)
  where subStrs = map head $ group $ sort $ concat [subStrings y (length s - (y - 1)) s [] | y <- [1..k]]

subStrings :: Int -> Int -> String -> [String] -> [String]
subStrings k cnt str ret | cnt <= 0 = ret
                         | otherwise = subStrings k (cnt-1) (tail str) (take k str:ret)

Measured memory_bytes: 6396
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;
	S[3] = '8';
	cout << S << endl;
	return 0;
}


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

void solve(){
    int n; string s;
    cin >> n >> s;
    int k = n/2;

    string ret = "No";
    if(n%2==0 && s.substr(0,k)==s.substr(k,n)){
        ret = "Yes";
    }

    cout << ret << "\n";

}

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

    solve();

    return 0;
}

Measured memory_bytes: 3628
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

string s;
int n;

int main(){
    R(n, s);
    for(char &c: s)
        c = 'A' + (c - 'A' + n) % 26;
    W(s);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def prime(min=1, max=float('inf')):
    primes = [2]
    if min <= 2 < max:
        yield 2

    def odd(min=1, max=float('inf')):
        counter = min + (min % 2 == 0)
        while counter < max:
            yield counter
            counter += 2

    if max != float('inf'):
        numbers = list(odd(3, max))
        for i in range(len(numbers)):
            if numbers[i] != 0:
                if min <= numbers[i]:
                    yield numbers[i]

                o = odd(3)
                while True:
                    index = numbers[i] * next(o) // 2 - 1
                    if index >= len(numbers):
                        break
                    numbers[index] = 0

    else:
        for o in odd(3, max):
            for p in primes:
                if o % p == 0:
                    break
            else:
                primes.append(o)
                if min <= o:
                    yield o
                if max < o:
                    break


def solve(X: int):
    return next(prime(X, int(1e5) + 5))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    print(f'{solve(X)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 78976
#include <bits/stdc++.h>
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;
typedef unsigned long long ULong;

Long _lcm(Long x, Long y) {
  return x * y / __gcd(x, y);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, m;

  cin >> n >> m;

  string s, t;
  cin >> s >> t;

  Long l = _lcm(n, m);
  Long step = _lcm(l / n, l / m);

  for (int i = 0; i < l / step; ++i) {
    if (s[i * step / (l / n)] != t[i * step / (l / m)]) {
      cout << -1;
      return 0;
    }
  }

  cout << l;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
	using namespace std;
	#define pb push_back
	#define M 1000000007
	#define INF 100000005
	const int N = 1e5 + 5;
	#define maax(a,b,c) max((int)a,max((int)b,(int)c))
	#define mp make_pair
	#define in long long
	#define all(a) a.begin(),a.end()
	#define gcd(a,b) __gcd(a,b)
	#define lcm(a,b) (a*b)/gcd(a,b)
	#define inf (long long) 1e18
	#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
	#define fre(i,m, n) for (int i = (int)(n); i <= (int)(m); i--)
	typedef long long LL;
	typedef pair<int, int> PII;
	in y=1;
	int fact(int n)
	{
		if(n==1) 
		{int h=y;y=1;
		return h;}
		y*=n;fact(n-1);
	}
	bool is_prime(int n)
	{
		int k=(n/2)+1,m=0;//cout<<k<<" ";
		fr(i,2,k)
		{
			if(n%i==0) m=1,i=k;//cout<<n<<" "<<i<<" ";//return false;
		}
		if(m==0) return true;
		else return false;
		//return true;
	}
	int sollve()
	{
	    int n;cin>>n;string s;cin>>s;
	    fr(i,0,s.size())
	    {
	    	int p=0;
	    	fr(j,0,s.size()-1)
	    	{
	    		
	    		if(s[j]=='(' && s[j+1]==')')
	    		{
	    			//cout<<s[j]<<" "<<s[j+1]<<"\n";
	    			p=1;s.erase(j,2);
				}
			}
			(p==1)?i--:i=s.size();
			//cout<<s.size()<<" "<<s<<"\n";
		}
		//cout<<s<<" ";
		cout<<s.size()/2<<"\n";
	    return 0;
	}
	int solve()
	{
		in a,b,c;
		cin>>a>>b>>c;
		
	}
	int main()
	{
		ios::sync_with_stdio(0); cin.tie(0);
		int t=0;
		string a,b;
		cin>>a>>b;
		fr(i,0,a.size())
		{
		 (a[i]!=b[i])?t++:t+=0;	
		}
		cout<<t;
		return 0;
	}		
//set-> all elements are unique and sorted *_*

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

int ans[100001];

int main()
{
    string s;
    cin >> s;
    int n = s.size();
   
    for(int l=0, r=0; l<n; l=r){
        while(r<n && s[r]=='R') r++;
        int a=r-1,b=r;
        while(r<n && s[r]=='L') r++;

        for(int i=l; i<r; i++){
            if((a-i)%2) ans[b]++;
            else        ans[a]++;
        }
    }
    for(int i=0; i<n; i++){
        cout << ans[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int k, n, s, t, i = 0, j, maxV = INT_MIN, A[30] = {};
	while (cin >> k) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0;
	bool isP = false;
	for (k = 2; k < s; ++k){
		if (vP[k] == 0){
			vP[k] = ++c;
			t = (s - 1) / k;
			for (j = 2; j <= t; ++j)
				vP[j * k] = -1;
		}
		else if (vP[k] == -1)
			vP[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << vP[A[j]] << "\n";
	return 0;
}

Measured memory_bytes: 8984