akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn comp(a: &[usize], b: &[usize]) -> Vec<usize> {
    let n = a.len();
    let mut ret = vec![0; n];
    for i in 0..n {
        ret[i] = b[a[i]];
    }
    ret
}

fn inv(a: &[usize]) -> Vec<usize> {
    let n = a.len();
    let mut ret = vec![0; n];
    for i in 0..n {
        ret[a[i]] = i;
    }
    ret
}

fn pow(a: &[usize], mut k: i64) -> Vec<usize> {
    let mut cur = a.to_vec();
    let mut sum: Vec<_> = (0..a.len()).collect();
    while k > 0 {
        if k % 2 == 1 {
            sum = comp(&sum, &cur);
        }
        cur = comp(&cur, &cur);
        k /= 2;
    }
    sum
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        k: i64,
        p: [usize1; n],
        q: [usize1; n],
    }
    let k = k - 1;
    let mut tbl = vec![p, q];
    for i in 2..6 {
        let tmp = comp(&inv(&tbl[i - 2]), &tbl[i - 1]);
        tbl.push(tmp);
    }
    let hop = pow(&comp(&tbl[0], &tbl[3]), k / 6);
    let ans = comp(&comp(&inv(&hop), &tbl[(k % 6) as usize]), &hop);
    for i in 0..n {
        puts!("{}{}", ans[i] + 1, if i == n - 1 { "\n" } else { " " });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String s = br.readLine();
		int[] count = new int[26];
		for(int i=0;i<s.length();i++)
			count[s.charAt(i)-97]++;
		for(int i=0;i<26;i++)
		{
			if(count[i]%2 == 1)
			{
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 32668
#include"bits/stdc++.h"

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

using namespace std;

int main(void) {
	int N; cin >> N;
	vector<int> L(N);
	int sum = 0;
	int longest = 0;
	rep(i, N) {
		cin >> L[i];
		sum += L[i];
		if (L[i] > L[longest])longest = i;
	}

	cout << (L[longest] < sum - L[longest] ? "Yes" : "No") << endl;

	return 0;
}

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

#define ll long long
#define endl '\n'
#define N 1e5+1;
#define INF 1e9

const ll MOD = 10e9+7;
ll max(ll a, ll b){return a > b ? a : b;}
ll min(ll a, ll b){return a < b ? a : b;}

vector<int> ans;
ll a[200001];
ll b[200001];
vector<int> sorted;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    int bb = max(a, b);
    int aa = min(a, b);
    if(bb>c&&aa<c) cout << "Yes" << endl;
    else cout << "No" << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR_IN(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)

int main(void){
    int N;
    string S;
    cin >> N >> S;
    ll ans = count(S.begin(),S.end(),'R') * count(S.begin(),S.end(),'G') * count(S.begin(),S.end(),'B');
    FOR_IN(i,1,N-2){
        FOR_IN(j,i,N-1){
            int k = 2*j -i;
            if(k <= j || k > N) continue;
            if(S[i-1] != S[j-1] && S[j-1] != S[k-1] && S[i-1] != S[k-1]) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
using System;

namespace abc153B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            long H = long.Parse(str[0]);
            long N = long.Parse(str[1]);
            long[] a = new long[N];
            str = Console.ReadLine().Split();
            for (long i = 0; i < N; i++)
            {
                a[i] = long.Parse(str[i]);
            }
            for(long i = 0;i < N;i++)
            {
                H = H - a[i];
            }
            if (H > 0)
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}


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

int N, M;
int A[100], B[100];
bool G[100][100];
bool visited[100];

void dfs(int v) {
   visited[v] = true;
   for (int v2 = 0; v2 < N; v2++) {
      if (visited[v2] == true) continue;
      if (G[v][v2] || G[v2][v]) dfs(v2);
   }
}

int main() {
   cin >> N >> M;
   for (int i = 0; i < M; i++) {
      cin >> A[i] >> B[i];
      A[i]--, B[i]--;
      G[A[i]][B[i]] = G[B[i]][A[i]] = true;
   }

   int ans = 0;
   for (int i = 0; i < M; i++) {
      G[A[i]][B[i]] = G[B[i]][A[i]] = false; // 辺を消す
      fill(visited, visited+N, false);
      dfs(0);
      if (count(visited, visited+N, true) < N) ans++;
      G[A[i]][B[i]] = G[B[i]][A[i]] = true; // 辺を戻す
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, M, L;
    cin >> N >> M >> L;
    vvi G(N, vi(N, INF));
    rep(i, 0, N) G[i][i] = 0;
    rep(i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        G[a][b] = G[b][a] = c;
    }
    vvi dist = G;
    rep(k, 0, N) rep(i, 0, N) rep(j, 0, N) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    
    vvi G2(N, vi(N, INF));
    rep(i, 0, N) G2[i][i] = 0;

    rep(i, 0, N) {
        rep(j, 0, N) {
            if (dist[i][j] <= L) {
                G2[i][j] = G2[j][i] = 1;
            }
        }
    }

    vvi dist2 = G2;
    rep(k, 0, N) rep(i, 0, N) rep(j, 0, N) chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);

    

    int Q;
    cin >> Q;
    while (Q--) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        int ans = dist2[s][t] - 1;
        if (ans > N) {
            cout << -1 << endl;
        } else {
            cout << ans << endl;
        }
    }
    
    return (0^_^0);
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, W;
    cin >> N >> W;
    vector <ll> weights(N+1), values(N+1);
    ll valsum=0;
    loop(i,1,N+1) cin >> weights[i] >> values[i];
    loop(i,1,N+1) valsum += values[i];
    vector <ll> dp(valsum+1, (ll)1e18);
    dp[0]=0;
    // dp[i] = minimum weight possible with items having total value exactly i
    for (int i=1; i<=N; ++i)
    {
        for (int j=valsum-values[i]; j>=0; --j)
        {
            dp[j+values[i]] = min(dp[j+values[i]], dp[j]+weights[i]);
            /* Why this should work?
             * dp[0]=0, dp[j]=1e18 for j!=0
             * When processing first item, min(dp[j+values[1]], dp[j]+weights[1])
             * returns dp[j]+weights[1] only for j=0. 
             * Continues for second iteration and so on.
            */
        }
    }
    ll ans=0;
    loop(i,1,valsum+1)
        if (dp[i] <= W) ans=i;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
d=sorted([[int(x) for x in input().split()] for y in range(m)], key=lambda x:x[1])

c,e=0,0
for i in range(m):
  if d[i][0]>e:
    e=d[i][1]-1
    c+=1

print(c)


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int b[n];
    int count=0;
    for(int i = 0; i < n; i++) {
        int idx=n-i;
        int j=idx-1;
        b[idx-1]=0;
        while(j<n){
            b[idx-1]+=b[j];
            j+=idx;
        }
        if(b[idx-1]%2!=a[idx-1]){
            b[idx-1]=1;
            count++;
        }
        else b[idx-1]=0;
    }
    cout << count << "\n";
    if(count!=0){
        for(int i = 0; i < n; i++) {
            if(b[i]==1)cout << i+1 << " ";
        }
        cout << "\n";
    }

    return 0;
}

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

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

    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s, ans = "Yes";
    cin >> s;
    forx(i, a - 1, c - 1) if (s[i] == '#' && s[i + 1] == '#') ans = "No";
    forx(i, b - 1, d - 1) if (s[i] == '#' && s[i + 1] == '#') ans = "No";
    if (s[a - 1] == '#' || s[b - 1] == '#' || s[c - 1] == '#' || s[d - 1] == '#')
        ans = "No";

    if (d < c && ans == "Yes")
    {
        ans = "No";
        forx(i, b - 2, d - 1)
        {
            if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.')
            {
                ans = "Yes";
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
typedef struct aaaaa{
  int x,y,t;
}Grid;
using namespace std;
ll memo[1000]={};
ll num;
ll rec(int de){
  if(de==0)return 1;
  if(memo[de]!=0)return memo[de];
  return (memo[de]=2*rec(de-1)+3);
}
ll pa[100]={};
ll n,x;

ll dfs(int de){
  //cout<<num/2<<endl;
  if(num<=0)return 0;
  if(num/2>=x){
    num/=2;
    num--;
    x--;
    return dfs(de-1);
  }else if(num/2+2<=x){
    num/=2;
    num--;
    x-=num+2;
    //  cout<<pa[de]<<endl;
    return dfs(de-1)+pa[de]+1;
  }else{
    //cout<<"!"<<endl;
    return pa[de]+1;
  }
}

int main(){
  cin>>n>>x;
  //memo[0]="P";
  num=rec(n);
  for(int i=1;i<=n;i++)
   (pa[i]=pa[i-1]*2+1);
  cout<<dfs(n)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define init(A,B) { int i; for(i=0; i<B; i++) A[i]=0; }

struct data{ int time; char type; int ID; };

int main(void){
	int N;
	
	while(scanf("%d\n",&N), N!=0){
		int i, j=0, k, t[4], max=0, presence[1000], time[1000]; struct data dat[N];
		init(presence,1000); init(time,1000);
		
		for(i=0; i<N; i++){
			scanf("%2d/%2d %2d:%2d %c %3d\n",&t[0],&t[1],&t[2],&t[3],&dat[i].type,&dat[i].ID);
			dat[i].time=t[3]+60*(t[2]+24*(t[1]+31*t[0]));
		}
		
		for(i=dat[0].time; i<=dat[N-1].time; i++){
			if(dat[j].time==i && j<N){
				while(dat[j].time==i){
					if(dat[j].type=='I') presence[dat[j].ID]=1;
					else presence[dat[j].ID]=0;
					j++;
				}
			}
			if(presence[0]==1) for(k=1; k<100; k++) time[k]+=presence[k];
		}
		
		for(i=1; i<100; i++) if(max<time[i]) max=time[i];
		
		printf("%d\n",max);
	}
}

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

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
import collections

n= int(input())
s=[]
for i in range(n):
    s.append(input().rstrip())

ss=collections.Counter(s)
print(len(ss))

Measured memory_bytes: 38900
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int N;
	String[] C,D;
	int minj;
	String key;
	int num1,num2;
	
	public void input(){
		N=sc.nextInt();
		C = new String[N];
		D = new String[N];
		for(int i=0; i<N; i++){
			C[i]=sc.next();
			D[i] = C[i];
		}
	}
	
	public void bubblesort(){
		for(int i=0; i<=N-1; i++){
			for(int j=N-1; j>=i+1; j--){
				num1 = Integer.parseInt( C[j].substring(1) );
				num2 = Integer.parseInt(C[j-1].substring(1));
				if(num1< num2){
					key = C[j];
					C[j] = C[j-1];
					C[j-1] = key;
				}
			}
		}
		output(C);
		System.out.println("Stable");
	}
	
	public void selectionsort(){
		for(int i=0; i<=N-1; i++){
			minj = i;
			for(int j=i; j<=N-1; j++){
				num1 = Integer.parseInt( D[j].substring(1) );
				num2 = Integer.parseInt(D[minj].substring(1));
				if(num1 < num2){
					minj = j;
				}
			}
			key = D[i];
			D[i] = D[minj];
			D[minj] = key;
		}
		output(D);
		stability();
	}
	
	public void stability() {
		int flag=0;
		for(int i=0; i<N; i++) {
			if(C[i].compareTo( D[i] ) != 0) flag++;
		}
		if(flag == 0) System.out.println("Stable");
		else System.out.println("Not stable");
	}
	
	public void output(String[] A){
		System.out.print(A[0]);
		for(int i=1; i<N; i++){
			System.out.print(" "+A[i]);
		}
		System.out.println();
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.input();
		obj.bubblesort();
		obj.selectionsort();
	}
}



Measured memory_bytes: 26572
class UnionFind:
    def __init__(self, n):
        self._tree = [i for i in range(n)]
        self._rank = [1] * n
    def root(self, a):
        if self._tree[a] == a:return a
        self._tree[a] = self.root(self._tree[a])
        return self._tree[a]
    def is_same_set(self, a, b):
        return self.root(a)==self.root(b)
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self._rank[ra] < self._rank[rb]:
            self._tree[ra] = rb
        else:
            self._tree[rb] = ra
            if self._rank[ra] == self._rank[rb]:
                self._rank[ra] += 1
I=lambda:map(int,input().split())
N,M=I()
edges=[list(I()) for _ in range(M)]
r=0
for i in range(M):
  uf=UnionFind(N)
  for j in range(M):
    if j!=i: uf.unite(edges[j][0]-1, edges[j][1]-1)
  s={uf.root(n) for n in range(N)}
  if len(s)>1:r+=1
print(r)

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

int main(){
    string a, b;
    cin >> a >> b;
    int anum = a.size(), bnum = b.size();
    string ans[] = {"GREATER", "LESS", "EQUAL"};
    if(anum>bnum) cout << ans[0]<<endl;
    else if(anum<bnum) cout << ans[1]<<endl;
    else{
        for(int i = 0; i < anum; i++)
        {
            if(a[i] > b[i]){
                cout << ans[0];
                return 0;
            }
            else if(a[i] < b[i]){
                cout << ans[1];
                return 0;
            }
        }
        cout << ans[2]<< endl;
        
    }
    return 0;
}

Measured memory_bytes: 256
/* 
 Author:N_o_o_B 
 Created:November 24 2019 17:33:41
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#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 ford(i,n)  for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    int n;
    cin >> n;
    string s;
    cin >> s;
    fori(i,sz(s)){
        int foo=s[i]-'A';
        foo = (foo+n)%26;
        s[i]='A'+foo; 
    }
    cout << s << endl;




    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
char S[4];
int main() {
	for (int i = 0; i < 4; i++) {
		std::cin >> S[i];
	}
	for (int i = 1; i < 3; i++) {
		if (S[i - 1] != S[i]) {
			break;
		}
		if (i == 2) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}for (int i = 2; i < 4; i++) {
		if (S[i - 1] != S[i]) {
			break;
		}
		if (i == 3) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}
	std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;


public  class Main{
     public static void main(String[] args) {
         InputStream inputStream = System.in;
         OutputStream outputStream = System.out;
         InputReader in = new InputReader(inputStream);
         PrintWriter out = new PrintWriter(outputStream);
         TaskA solver = new TaskA();
         solver.solve(1, in, out);
         out.close();

     }

     static class TaskA {
         public void solve(int testNumber, InputReader in, PrintWriter out)
         {
             String s= in.next();
             char c[] =s.toCharArray();
             if(s.length()==2)
                 System.out.println(s);
             else
                 reverseString(c,s.length());

         }
         static  void reverseString(char[] word,int len)
         {

             if(len==0)
                 return;
             System.out.print(word[len-1]);
             word[len-1]='\0';
             reverseString(word,len-1);
         }
     }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.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: 21460
#include<stdio.h>
#include<stdlib.h>

int main(){
  int set1[3000], set2[3000];
  int x,y;
  int i=0,j=0,k;
  while(1){
    scanf("%d%d",&x,&y);
    if(x==0&&y==0){
      break;
    }else{
      set1[i] = x; set2[i]=y;
      i++;
    }
  }
  for(j=0;j<i;j++){
    if(set1[j]<=set2[j]){
      printf("%d %d\n",set1[j],set2[j]);
    }else{
      printf("%d %d\n",set2[j],set1[j]);
    }
  }
  return 0;
}



Measured memory_bytes: 1968
#include <stdio.h>

int main() {
	double menseki, tyotenx, tyoteny;
	double w, h, x, y;

	scanf("%lf %lf %lf %lf", &w, &h, &x, &y);

	menseki = w * h / 2;
	tyotenx = w / 2;
	tyoteny = h / 2;

	printf("%lf %d\n", menseki, tyotenx == x && tyoteny == y ? 1 : 0);

	return 0;
}

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

using namespace std;
 
int main () {
	string a,b,c,ans;
	cin >> a >> b >> c;

	ans.push_back(a[0]);
	ans.push_back(b[0]);
	ans.push_back(c[0]);
	transform(ans.begin(), ans.end(), ans.begin(),::toupper);
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int a,p;
  cin >> a >> p;
  a*=3;
  cout << (a+p)/2 << endl;
  return 0;
}

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

int main(void){
  long N;
  char str[100];
  
  fgets(str,"str",stdin);
  N=atoi(str);
  
  if(N%2==0){
    printf("%d",N);
  }else{
    printf("%d",2*N);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>
#include <list>
#include <math.h>
#include <cmath>
typedef long long int ll;
const ll oo = 2e18;
const int md = 1e9+7;

using namespace std;
ll n;
int ans, l;

int main(void)
{
	scanf("%lld",&n);
	ll tmp = n;
	while(tmp)
	{
		l += tmp%10;
		tmp /= 10;
	}
	while(n)
	{
		if(n > 10)
			ans += 9;
		else
			ans += n-1;
		n /= 10;
	}
	printf("%d\n",max(ans,l));
	return 0;
}

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


int main(){
    int n;
    cin >>n;
    int a[n];
    rep(i,n) cin >>a[i];
    rep(i,n+1){
        if(i==0)i++;
        int v=a[i];
        int j=i-1;
        rep(k,n) {
            cout << a[k];
            if(k<n-1) cout << " ";
        }
        cout <<endl;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1] =v;
        
    }
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

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

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

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}

static void D_task()
{
	auto str = new char[100001];
	memset(str, 0, sizeof(char) * 100001);
	getstring(str);

	int len = strlen(str);
	auto box = new int[len];
	memset(box, 0, sizeof(box[0]) * len);

	int nowPos = 0;
	int changePos = 0;
	int rnum = 0;
	int lnum = 0;
	char bfr = 'R';
	while (nowPos < len) {

		if (str[nowPos] == 'R') {
			rnum++;
		}
		else {
			lnum++;
		}

		if ((str[nowPos] != bfr) || (nowPos == (len - 1))){
			if (bfr == 'R')  {
				changePos = nowPos;
			}
			
			if ((str[nowPos] == 'R') || (nowPos == (len - 1))) {
				if (str[nowPos] == 'R') rnum--;
				
				box[changePos - 1] = (rnum / 2) + (rnum % 2) + (lnum / 2);
				box[changePos] = (rnum / 2) + (lnum / 2) + (lnum % 2);

				lnum = 0;
				rnum = 1;
			}
		}
		bfr = str[nowPos];
		nowPos++;
	}

	for (int i = 0; i < len - 1; i++) {
		printf("%d ", box[i]);
	}
	printf("%d\n", box[len - 1]);
}



Measured memory_bytes: 896
#include <stdio.h>
#include <algorithm>
int n;
long long k, l, m, r, x;
long long a[200000];
long long f[200000];
int main() {
	scanf("%d%lld", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
	}
	for (int i = 0; i < n; i++) {
		scanf("%lld", f + i);
	}
	std::sort(a, a + n);
	std::sort(f, f + n);
	r = a[n - 1] * f[n - 1];
	l = -1;
	while (r - l - 1) {
		m = (l + r) / 2;
		x = 0;
		for (int i = 0; i < n; i++) {
			if (m < a[i] * f[n - 1 - i]) {
				x += a[i] - m / f[n - 1 - i];
			}
		}
		if (x > k)l = m;
		else r = m;
	}
	printf("%lld\n", r);
}

Measured memory_bytes: 4856
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using P = pair<int, int>;

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

    int cnt = 0;
    int ans = 0;
    rep(i,n){
        int x, y;
        cin >> x >> y;
        //cout << x << y << endl;
        if (x==y){
            cnt++;
        }
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << (ans >= 3? "Yes" : "No") << endl;
    return 0;
}




Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

#define EPS     1e-11
#define INF     0x7fffffff
#define LL_INF  0x7fffffffffffffff

typedef long long LL;
struct Point {
        int x, y;
};
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> grid(H, vector<int>(W));
    for (int y = 0; y < H; y++)
        for (int x = 0; x < W; x++)
            cin >> grid[y][x];

    vector<vector<int>> res;
    for (int y = 0; y < H; y++)
        for (int x = 0; x < W; x++) {
            if (grid[y][x] % 2 == 0)
                continue;
            bool flag = false;
            for (int i = 0; i < 4; i++) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (ny >= 0 && ny < H && nx >= 0 && nx < W && grid[ny][nx] % 2 != 0) {
                    grid[y][x]--;
                    grid[ny][nx]++;
                    res.push_back({y+1, x+1, ny+1, nx+1});
                    flag = true;
                    break;
                }
            }
            if (!flag) {
            for (int i = 0; i < 4; i++) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (ny >= 0 && ny < H && nx >= 0 && nx < W) {
                    grid[y][x]--;
                    grid[ny][nx]++;
                    res.push_back({y+1, x+1, ny+1, nx+1});
                    break;
                }
            }
            }
        }

    cout << res.size() << endl;
    for (int i = 0; i < res.size(); i++) {
        cout << res[i][0] << " " << res[i][1] << " " << res[i][2] << " " << res[i][3] << endl;
    }
    return 0;
}


Measured memory_bytes: 10032
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int N;
    cin>>N;
    vector<int> d;
    for(int i=0;i<N;i++){
        int temp;
        cin >> temp;
        d.push_back(temp);
    }
    sort(d.begin(), d.end());
    int ans;
    if(d.at(N/2-1)==d.at(N/2)){
        ans = 0;
    }else{
        ans = d.at(N/2)-d.at(N/2-1);
    }
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 892
a, b, c = map(int, input().split())

ans = 'NO'
if a < b and c%a == 0:
  ans = 'YES'
else:
  for i in range(1, 100000):
    if (b*i + c)%a == 0:
      ans = 'YES'
      break
  
print(ans)

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

int main()
{
	int n, k, q;
	cin >> n >> k >> q;
	
	int score[n];
	for (int i = 0; i < n; i++)
	{
		score[i] = k;
	}
	
	for (int i = 0; i < q; i++)
	{
		int v;
		cin >> v;
		score[v-1]++;
	}
	
	for (int i = 0; i < n; i++)
	{
		//cout << score[i] << " ";
		if (score[i]-q <= 0) cout << "No\n";
		else cout << "Yes\n";
	}
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<string>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){
        int N = 0;
        scanf("%d", &N);
        int l[N];
        for (int i = 0; i < N; i++) {
                        scanf("%d", &l[i]);
        }
        int tmp = -1;
        int sum = 0;
        for (int i = 0; i < N; i++) {
                        if (tmp < l[i]) tmp = l[i];sum += l[i];
        }
        printf("%d\n",sum - tmp / 2);
//      for (int i = 0; i < N; i++) {
//                      printf("%d\n",l[i]);
//      }
        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b>c+d) puts("Left");
	if(a+b==c+d) puts("Balanced");
	if(a+b<c+d) puts("Right");
	return 0; 
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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


const string YES = "YES";
const string NO = "NO";

void func(long long H, long long W, long long N, long long s_r, long long s_c, std::string S, std::string T){

    s_r--,s_c--;
    lli l = -1, r = W;
    for(lli i=N-1;i>=0;i--){
        LOG3(i,l,r);
        //青木君落とされたくいない
        if(T[i]=='R')l = max(l-1,-1LL);
        if(T[i]=='L')r = min(r+1,W);

        //高橋君落としたい
        if(S[i]=='R')r = max(r-1,-1LL);
        if(S[i]=='L')l = min(l+1,W);

        if(r<=l+1){
            cout<<NO<<endl;
            return;
        }
    }
    LOG2(l,r);
    if(s_c<=l || r<=s_c){
        cout<<NO<<endl;
        return;
    }

    l = -1, r = H;
    for(lli i=N-1;i>=0;i--){
            
        //青木君落とされたくいない
        if(T[i]=='D')l = max(l-1,-1LL);
        if(T[i]=='U')r = min(r+1,H);

        //高橋君落としたい
        if(S[i]=='D')r = max(r-1,-1LL);
        if(S[i]=='U')l = min(l+1,H);

        if(r<=l+1){
            cout<<NO<<endl;
            return;
        }
    }
    if(s_r<=l || r<=s_r){
        cout<<NO<<endl;
        return;
    }

    cout<<YES<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long N;
    scanf("%lld",&N);
    long long s_r;
    scanf("%lld",&s_r);
    long long s_c;
    scanf("%lld",&s_c);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    func(H, W, N, s_r, s_c, S, T);
    return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  char A,B;
  cin >> A >> B;

  if (A==B) {
    cout << "H" << endl;
  } else if (A!=B) {
    cout << "D" << endl;
  }
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <vector>
#include <bits/stdc++.h>
#include <math.h>
#include <stack>
#define pb push_back
// #define pop pop_back
#define ll long long int
#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#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, a, b) for (ll i = a; i >= b; i--)
#define I long_max
#define pii pair<int, int>
#define pll pair<long, long>
#define vpair vector<pair<int, int>>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fir first
#define sec second
#define d (int)1e9 + 7
#define INF (int)2e9 + 1
#define el "\n"
#define fs fastscan

#define vrep(vec) for (const auto &value : vec)
#define arep(arrat) for (const auto &value : array)
using namespace std;

bool sortinrev(const pair<int, int> &a,
               const pair<int, int> &b)
{
    return (a.first > b.first);
}
void swap(int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

//over

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

ll dfs(ll n, vector<vector<ll>> &adj, vector<ll> &dp)
{
    for (ll j = 0; j < adj[n].size(); j++)
    {
        if (dp[adj[n][j]] == -1)
        {
            if (dp[n] == -1)
            {
                dp[n] = 0;
            }
            dp[n] = max(dp[n], 1 + dfs(adj[n][j], adj, dp));
        }
        else
        {
            if (dp[n] == -1)
            {
                dp[n] = 0;
            }
            dp[n] = max(dp[n], 1 + dp[adj[n][j]]);
        }
    }
    if (dp[n] == -1)
    {
        return dp[n] = 0;
    }
    return dp[n];
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //use auto instead of data types
    {
        ll n, m;
        cin >> n >> m;
        vector<vector<ll>> adj(n + 1);
        rep(i, m)
        {
            int t1, t2;
            cin >> t1 >> t2;
            adj[t1].push_back(t2);
        }
        vector<ll> dp(n + 1, -1);
        rep2(i, 1, n)
        {
            if (dp[i] == -1)
                dfs(i, adj, dp);
        }
        cout << *max_element(dp.begin(), dp.end()) << el;
    }
    return 0;
}


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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cout<< setprecision(20)<< fixed;
  double a, b;
  ll n;
  cin>> a>> b>> n;
  ll ans = min(n, ll(b)-1);
  ans = floor(a*ans/b) - ll(a)*floor(double(ans)/b);
  cout<< ans<<el;
}




Measured memory_bytes: 3692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	static Main main = new Main();
	static HashMap<String, Item> itemTable = new HashMap<String, Item>();

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

		while (!(line = br.readLine()).equals("0")) {
			int m = 0, n = 0;
			String target;

			n = Integer.parseInt(line);
			for (int i = 0; i < n; i++) {
				Item item = getItemInstance(br.readLine());
				itemTable.put(item.name, item);
			}

			m = Integer.parseInt(br.readLine());
			for (int i = 0; i < m; i++) {
				setRecipe(br.readLine());
			}

			target = br.readLine();
			System.out.println(itemTable.get(target).getMinCost());
		}
	}

	class Item {
		String name;
		int price;
		int recipeCount = 0;
		ArrayList<Item> recipe;

		Item(String name, int price) {
			this.name = name;
			this.price = price;
		}

		int getMinCost() {
			int min = 0;
			if (recipeCount == 0) {
				min = price;
			} else {
				for (Item i : recipe) {
					if (i != null)
						min += i.getMinCost();
				}
			}
			return min < price ? min : price;
		}
	}

	static Item getItemInstance(String info) {
		int n = info.indexOf(' ');
		String name = info.substring(0, n);
		int price = Integer.parseInt(info.substring(n + 1));
		return main.new Item(name, price);
	}

	static void setRecipe(String info) {
		StringTokenizer st = new StringTokenizer(info);
		Item item = itemTable.get(st.nextToken());
		item.recipeCount = Integer.parseInt(st.nextToken());
		item.recipe = new ArrayList<Item>();
		while (st.hasMoreTokens()) {
			item.recipe.add(itemTable.get(st.nextToken()));
		}
	}
}

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

typedef long long int ll;

int main() {
    ll n, m, k; cin >> n >> m >> k;
    vector<ll> as(n, 0), bs(m, 0);
    vector<ll> suma(n, 0), sumb(m, 0);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
        if (i == 0){
            suma[i] = as[i];
        } else {
            suma[i] = suma[i - 1] + as[i];
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> bs[i];
        if (i == 0){
            sumb[i] = bs[i];
        } else {
            sumb[i] = sumb[i - 1] + bs[i];
        }
    }
    ll ans = 0;
    suma.insert(suma.begin(), 0);

    for (int i = 0; i < (int)suma.size(); i++) {
        ll diff = k - suma[i];
        if (diff < 0) {
            continue;
        }
        ll tmp = i;
        auto ub = upper_bound(sumb.begin(), sumb.end(), diff);
        ll num = ub - sumb.begin();
        tmp += num;
        ans = max(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10800
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    
    long long b = 0;
    for (auto x : S) {
        if (x == 'B') ++b;
    }
    long long ans = 0;
    long long cnt = 0;
    for (long long i = 0; i < (long long)S.size(); ++i) {
        if (S[i] == 'B') {
            ans += S.size() - (b - cnt) - i;
            ++cnt;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (i > 0 && A[A.size()-1] == x) continue;
    A.push_back(x);
  }
  
  int s = A.size();
  int F = 0;
  for (int i = 1; i < s-1; i++) {
    if (signbit(A[i-1]-A[i]) ^ signbit(A[i]-A[i+1])) {
      F += 1;
      i += 1;
    }
  }
  
  cout << F+1 << endl;
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;

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

        for(int j = 0; j < 5; j++) {
            tmp_sum += tmp_n % 10;
            tmp_n /= 10;
        }

        if(tmp_sum >= a && tmp_sum <= b) {            
            sum += i;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k;
	int a,b;
	cin >> k >> a >> b;
	int q=a/k;
	int r=b/k;
	if(r-q>=1){
		cout << "OK" << endl;
	}
	else if(a%k==0&&r-q==0){
		cout << "OK" << endl;
	}
	else{
		cout << "NG" << endl;
	}




}

Measured memory_bytes: 3640
import sys

def solve():
    n, list_of_xy = read()
    result = think(n, list_of_xy)
    write(result)


def read():
    n, m = read_int(2)
    list_of_xy = []
    for i in range(m):
        list_of_xy.append(read_int(2))
    return n, list_of_xy


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, list_of_xy):
    num_of_input_edges = [0 for _ in range(n + 1)]
    num_of_output_edges = [0 for _ in range(n + 1)]

    linked_list = generate_linked_list(list_of_xy)

    invalid_value = -1
    length_of_longest_path_start_from = [invalid_value for _ in range(n + 1)]

    for x, y in list_of_xy:
        num_of_input_edges[y] += 1
        num_of_output_edges[x] += 1

    for i in range(1, len(num_of_input_edges)):
        if num_of_output_edges[i] == 0:
            length_of_longest_path_start_from[i] = 0

    for i in range(1, len(num_of_input_edges)):
        if num_of_input_edges[i] == 0:
            update_logest_path_start_from(i, linked_list, length_of_longest_path_start_from, invalid_value)

    return max(length_of_longest_path_start_from)


def generate_linked_list(list_of_xy):
    linked_list = {}
    for x, y in list_of_xy:
        if x in linked_list:
            linked_list[x].append(y)
        else:
            linked_list[x] = [y]
    return linked_list


def update_logest_path_start_from(x, linked_list, length_of_longest_path_start_from, invalid_value):
    if length_of_longest_path_start_from[x] != invalid_value:
        return

    dest_from_x = linked_list.get(x, [])
    for y in dest_from_x:
        if length_of_longest_path_start_from[y] == invalid_value:
            update_logest_path_start_from(y, linked_list, length_of_longest_path_start_from, invalid_value)
            length_of_longest_path_start_from[x] = max(length_of_longest_path_start_from[x], length_of_longest_path_start_from[y] + 1)
        else:
            length_of_longest_path_start_from[x] = max(length_of_longest_path_start_from[x], length_of_longest_path_start_from[y] + 1)


def write(result):
    print(result)


if __name__ == '__main__':
    sys.setrecursionlimit(10 ** 5)
    solve()

Measured memory_bytes: 198488
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

const long long MOD = 1e9 + 7;
long long dp[100001][13] = {0};
long long M[100000];

int main() {
  M[0] = 1; 
  for(long long i = 0; i < 99999; i++) {
    M[i+1] = (M[i] * 10) % 13;
  }
  string S;
  cin >> S;
  if(S[S.size()-1] == '?') {
    for(long long i = 0; i < 10; i++) {
      dp[1][i] = 1;
    }
  } else {
    dp[1][S[S.size()-1] - '0'] = 1;
  }

  for(long long key = 1; key <= S.size()-1; key++) {
    long long i = (S.size() - key - 1);
    if(S[i] != '?') {
      long long temp = S[i] - '0';
      for(long long j = 0; j < 13; j++) {
        long long t = (temp * M[key] + j) % 13;
        dp[S.size()-i][t] += dp[S.size()-i-1][j];
        dp[S.size()-i][t] %= MOD;
      }
    } else {
      rep(k, 13) {
        rep(j, 10) {
          long long temp = j;
          long long t = (temp * M[key] + k) % 13;
          dp[S.size()-i][t] += dp[S.size()-i-1][k];
          dp[S.size()-i][t] %= MOD;
        }
      }
    }
  }

  cout << dp[S.size()][5] << endl;

  return 0;
}

Measured memory_bytes: 14676