akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

long long sumBA=0,sumA=0,sumB=0,ans=0;
int n;
string s;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s[0]=='B'&&s.size()>1&&s[s.size()-1]=='A') sumBA++;
		else if(s[0]=='B'&&s[s.size()-1]!='A') sumB++;
		else if(s[s.size()-1]=='A'&&s[0]!='B') sumA++;
		for(int i=0;i<s.size()-1;i++){
			if(s[i]=='A'&&s[i+1]=='B') ans++;
		} 
	}
	if(sumBA==0){
		int mi=min(sumA,sumB);
		ans+=mi;
		cout<<ans;
		return 0;
	}
	ans+=sumBA-1;
	if(sumA){
		sumA--;
		ans++;
	}
	if(sumB){
		sumB--;
		ans++;
 	}
	int mi=min(sumA,sumB);
	ans+=mi;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {

	int a, b, c, d, e, f = 0;
	cin >> a >> b;
	if (b > 21) {
		for (int i = 20; i < b; i += 10) {
			for (int j = 2; j < 10 && i + j <= b; j++) {
				c = i + j;
				d = c / 10;
				e = c % 10;
				//cout << a << "," << d * e << "," << e << endl;
				if (a >= d * e) {
					f++;
				}
			}
		}
	}
	cout << f;
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define pow POW
vector<int> v[100005];
int dfs(int x,int f){
    int res=0;
    for(auto it:v[x]){
        if(it!=f){
            res=res^(dfs(it,x)+1);
        }
    }
    return res;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i= 1;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    if(dfs(1,0))printf("Alice\n");
    else printf("Bob\n");
}
/*
7 7
1 1 4 7
1 1 2 5
1 2 6 7
1 1 5 8
1 1 3 6
1 3 7 5
0 1 6 7
d-1 2-d 3-d=d
d-1 2-d 3-d 4-d
12 02 0 1
a1 a2 a3 a4
a1-a2-a3-a4
a1-a2-a3+a4
a1-a2+a3-a4
a1-a2+a3+a4
a1-a2-a3+a4
a1-a2+a3-a4
*/
//a+a+1=10a+1
//3a+2=10a+2

Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	while(cin >> n and n!=0)
	{
		bool l=false,r=false;
		bool bef=false;
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			string s;
			cin >> s;
			if(s=="lu")
				l=true;
			if(s=="ld")
				l=false;
			if(s=="ru")
				r=true;
			if(s=="rd")
				r=false;

			if(bef==true and l==false and r==false)
			{
				bef=false;
				cnt++;
			}
			else if(bef==false and r==true and l==true)
			{
				bef=true;
				cnt++;
			}
		}
		cout << cnt << endl;
	}




}



Measured memory_bytes: 3140
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var pq []int

func push(x int) {
	p := sort.Search(len(pq), func(i int) bool { return pq[i] <= x })
	if p == len(pq) {
		pq = append(pq, x)
		return
	}
	pq = append(pq[:p+1], pq[p:]...)
	pq[p] = x
}

func pop() int {
	if len(pq) == 0 {
		return 0
	}

	ans := pq[0]
	pq = pq[1:]
	return ans
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	ts := make(map[int][]int)
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		ts[a] = append(ts[a], b)
	}

	pq = make([]int, 0, n)
	ans := 0
	for i := 1; i <= m; i++ {
		if _, ok := ts[i]; ok {
			for _, v := range ts[i] {
				push(v)
			}
		}
		ans += pop()
	}
	fmt.Println(ans)
}


Measured memory_bytes: 11264
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
typedef std::vector<int> vin;
const int HASH = 131;
const int MAXS = 2e6+5;
const int MOD = 1e9+7;
const int NOPE = -1;
int F[MAXS]; // KMP failure function
vin G[MAXS]; // Matching T
char s[MAXS];
char t[MAXS];
int deg[MAXS]; // In-degree
int lvl[MAXS]; // Distance
int N, S, T;
vin pos;

void kmp() {
  int i = 0;
  int j = 0;
  while (i < N) {
    if (t[j] == s[i]) {
      if (j == T-1) {
//        return i-T+1;
        pos.push_back(i-T+1);
        j = F[j-1];
//        j = 0;
//        ++i;
      } else {
        ++i;
        ++j;
      }
    } else if (j > 0) {
      j = F[j-1];
    } else {
      ++i;
    }
  }
}

void pmt() {
  F[0] = 0;
  int i = 1;
  int j = 0;
  while (i < T) {
    if (t[i] == t[j]) {
      ++j;
      F[i] = j;
      ++i;
    } else if (j > 0) {
      j = F[j-1];
    } else {
      F[i] = 0;
      ++i;
    }
  }
}

void kr() {
  int B = 1;
  int P = 0;
  for (int i = 0; i < T; ++i) {
    P = (1LL * HASH * P % MOD + t[i]) % MOD;
    B = 1LL * HASH * B % MOD;
  }
  int Q = 0;
  for (int i = 0; i < N; ++i) {
    Q = (1LL * HASH * Q % MOD + s[i]) % MOD;
    if (i >= T) {
      Q = (Q - 1LL * B * s[i-T] % MOD + MOD) % MOD;
    }
    if (P == Q) {
      pos.push_back(i-T+1);
    }
  }
}

void repeat() {
  // Concatenate S with itself
  N = S;
  int st = S + T;
  while (N < st) {
    for (int i = 0; i < S; ++i, ++N) {
      s[N] = s[i];
    }
    s[N] = '\0';
  }
}

int solve() {
  for (int u: pos) {
    int v = (u + T) % S;
    G[u].push_back(v);
    ++deg[v];
//    printf("%d -> %d\n", u, v);
  }
  std::queue<int> Q;
  for (int i = 0; i < N; ++i) {
    if (!deg[i]) {
      lvl[i] = 0;
      Q.push(i);
//      printf("%d: start\n", i);
    } else {
      lvl[i] = NOPE;
    }
  }
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (int nxt: G[cur]) {
      if (!--deg[nxt]) {
        lvl[nxt] = lvl[cur] + 1;
        Q.push(nxt);
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < N; ++i) {
    if (lvl[i] == NOPE) {
      return NOPE;
    }
    ret = std::max(lvl[i], ret);
  }
  return ret;
}

int main() {
  scanf(" %s%s", s, t);
  S = strlen(s);
  T = strlen(t);
  repeat();
//  pmt(); // Partial match table
//  kmp(); // Knuth-Morris-Pratt
  kr();
  printf("%d\n", solve());
  return 0;
}

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

int main(void){
    int a,b,c,d,e,k;
    cin >> a >> b>> c>> d>> e>> k;
    if (e - a > k)
        cout << ":(\n";
    else
        cout << "Yay!\n";


}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

#define N 105
ll n,k;
l_l a[N];
void load(){
    sort(a,a+n);
    reverse(a,a+n);
}

int main(){fastio
    cin>>n>>k;
    
    rep(i,0,n-1){
        cin>>a[i].fi;a[i].se=i+1;
    }
    vector<ll>ans;
    load();
    rep(i,0,n-1){
        ans.pb(a[i].se);
        a[i].fi--;
        if(a[i].fi<0){
            cout<<-1<<endl;return 0;
        }
    }
    ll skip=a[n-1].se;
    while(k--){
        ll nextskip;
        rep(i,0,n-1){
            if(a[i].se==skip)continue;
            ans.pb(a[i].se);
            a[i].fi--;
            if(a[i].fi<0){
                cout<<-1<<endl;return 0;
            }
            nextskip=a[i].se;
        }
        skip=nextskip;
        load();
    }
    cout<<ans.size()<<endl;
    for(auto x:ans)cout<<x<<" ";
    
    
    return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong();
        return getLcm(a,b);
    }
    long gcd(long a, long b){
        if(a<b){
            long c = a;
            a = b; b = c;
        }
        while(a%b!=0){
            long c = a%b;
            a = b; b = c;
        }
        return b;
    }
    long getLcm(long a, long b){
        return a/gcd(a,b)*b;
    }
}



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

int main() {
  int n; cin >>n;
  int a[212345];
  rep(i,n) cin >>a[i];
  int ans[512345];
  int left = 212345, right = left+1;
  rep(i,n){
    if(i%2==(n-1)%2) ans[left--]=a[i];
    else ans[right++]=a[i];
  }
  for(int i = left+1; i<right; i++){
    printf("%d ", ans[i]);
  }
  return 0;
}

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

int main() {
    int a;
    string s;

cin>>a>>s;

for(int i=0;i<s.size();i++){
    s[i]+=a;
    if(s[i]>'Z'){
        s[i]-=26;
    }
}
cout<<s;
}

Measured memory_bytes: 256
loop do
  n,x = gets.chomp.split.map(&:to_i)
  break if n == 0 && x == 0
  ans = 0
  (1..n).each do |a|
    (1..n).each do |b|
      c = x - a - b
      if [a,b,c].uniq.size == 3 && c > 0 && c <= n
        ans += 1
      end
    end
  end
  puts ans / 6
end



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

using namespace std;

#define MAX 55
int n, m, q;
vector<int> v[MAX];
int maxs = 0;

void calc(vector<int> &V)
{
    int nows = 0;
    for(int i=0; i<q; i++){
        int a = v[i][0], b = v[i][1], c = v[i][2], d = v[i][3];
        if(V[b]-V[a] == c) nows += d;
    }
    maxs = max(maxs, nows);
}

void gen(int len, int last, vector<int> &seq)
{
    if(len == n+1){
        calc(seq);
        return;
    }
    for(int i=last; i<=m; i++){
        seq.push_back(i);
        gen(len+1, i, seq);
        seq.pop_back();
    }
}

int main()
{
    //freopen("in.txt", "r", stdin);
    scanf("%d %d %d", &n, &m, &q);
    for(int i=0; i<q; i++){
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        a--, b--;
        v[i].push_back(a);
        v[i].push_back(b);
        v[i].push_back(c);
        v[i].push_back(d);
    }
    vector<int> temp;
    gen(1, 1, temp);
    cout << maxs << endl;
}



Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */

int main()
{
	int		n,m,c[21],i,j;
	int		dp[50001];
	scanf("%d %d", &n, &m);
	for(i=0; i<m; i++) {
		scanf("%d",&c[i]);
	}

	for(i=0;i<m;i++) {
		if (c[i]==1) {
			c[i] = c[0];
			c[0] = 1;
		}
	}
	dp[0] = 0;
	for(i=1;i<=n;i++) {
		dp[i] = 0x7fffffff;
	}
	for(i=0;i<m;i++) {
		for(j=0; j+c[i]<=n; j++) {
			dp[j+c[i]] = min( dp[j+c[i]] , dp[j]+1 );
			if (DEBUG) printf("%d %d dp[%d]:%d\n",i,j,j+c[i], dp[j+c[i]]);
		}
	}

	printf("%d\n",dp[n]);

	return 0;
}



Measured memory_bytes: 2108
#include <iostream>
using namespace std;
typedef double d;

bool is_inner(d a1,d a2,d b1,d b2,d c1,d c2) {
  if(((b1-a1)*(c2-b2)-(b2-a2)*(c1-b1)) >0) return true;
  return false;
}
int main() {
  d x1,y1,x2,y2,x3,y3,xp,yp;
  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    bool a,b,c;
    a = is_inner(x1,y1,x2,y2,xp,yp);
    b = is_inner(x2,y2,x3,y3,xp,yp);
    c = is_inner(x3,y3,x1,y1,xp,yp);
    if(a == b && b == c) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1216
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 998244353
N, A, B, K = lr()
answer = 0
# A * x + B * y = K
# nCx * nCy

def F(x, y):
    return comb[x] * comb[y]

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = N + 1 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
fact_N = fact[N]
comb = fact_N * fact_inv % MOD * fact_inv[::-1] % MOD

for x in range(N+1):
    temp = K-A*x
    q, r = divmod(temp, B)
    if r != 0:
        continue
    if q > N:
        continue
    if q < 0:
        break
    answer += F(x, q)
    answer %= MOD

print(answer % MOD)


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

int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

char d[128][128];
int h, w;

bool in(int y, int x){return 0 <= y && y <= h && 0 <=x && x <= w;};

void po(int y, int x, char c)
{
  if (!in(y, x)) return;
  if (d[y][x] != c) return;

  d[y][x] = '.';
  for (int i = 0; i < 4; i++){
    po(y + dy[i], x + dx[i], c);
  }
}

int main()
{
  while (cin >> h >> w, h){
    for (int i = 0; i < h; i++){
      for (int j = 0; j < w; j++){
        cin >> d[i][j];
      }
    }

    char s[3] = {'@', '#', '*'};
    int cnt = 0;
    for (int i = 0; i < 3; i++){
      for (int j = 0; j < h; j++){
        for (int k = 0; k < w; k++){
          if (d[j][k] == s[i]) {
            po(j, k, s[i]);
            cnt++;
          }
        }
      }
    }

    cout << cnt << endl;
  }
}

Measured memory_bytes: 3544
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

 struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ
    vector<int>sz;//要素数

    UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);sz.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
            sz[i]=1;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
            sz[y]+=sz[x];
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
            sz[x]+=sz[y];
		}
		return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}

    int size(int k){//要素数を求める
        return sz[find(k)];
    }
};


void solve(){
  int n,k,l;
  cin>>n>>k>>l;
  UF road(n),train(n);
  rep(i,k){
    int p,q;
    cin>>p>>q;
    p--;q--;
    road.unite(p,q);
  }
  rep(i,l){
    int r,s;
    cin>>r>>s;
    r--;s--;
    train.unite(r,s);
  }
  map<pair<int,int>,int>mp;
  rep(i,n)mp[make_pair(road.find(i),train.find(i))]++;
  vector<int>cnt(n);
  rep(i,n)cnt[i]=mp[make_pair(road.find(i),train.find(i))];
  rep(i,n){
    if(i)cout<<" ";
    cout<<cnt[i];
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 17408
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

typedef struct node{
  struct node *right, *left, *parent;
  int key
  ;} * Node;

Node root;

Node treeSearch(Node u, int t){
  if(u == NIL || t == u ->key) return u;
  if(t < u->key) return treeSearch(u->left,t);
  else return treeSearch(u->right,t);

  while(u != NIL && t != u->key){
    if(t < u->key) u = u->left;
    else if(t > u->key) u = u->right;
  }
  return u;
}


void insert(int t){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = t;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)  x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL)   root = z;
  else if(z->key < y->key) y->left = z;
  else y ->right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}

int main(){
  int n, i, x;
  char com[10];
  Node t;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      t = treeSearch(root,x);
      if( t != NIL) printf("yes\n");
      else printf("no\n");
    }
    if( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

  }

  return 0;
}



Measured memory_bytes: 20448
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
vector<ll> a;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    a.resize(N);
    rep(i,0,N) cin>>a[i];
    sor(a);
    if(N==2){
        cout <<a[1]-a[0]<<"\n";
        cout <<a[1]<<" "<<a[0]<<"\n";
    }
    else if(a[0]>=0){
        ll sum=0;
        rep(i,1,N) sum+=a[i];
        sum-=a[0];
        cout <<sum<<"\n";
        cout <<a[0]<<" "<<a[1]<<"\n";
        ll res=a[0]-a[1];
        rep(i,2,N-1){
            cout <<res<<" "<<a[i]<<"\n";
            res-=a[i];
        }
        cout <<a[N-1]<<" "<<res<<"\n";
    }
    else if(a[N-1]<=0){
        ll sum=0;
        rep(i,0,N-1) sum+=-a[i];
        sum+=a[N-1];
        cout <<sum<<"\n";
        cout <<a[N-1]<<" "<<a[N-2]<<"\n";
        ll res=a[N-1]-a[N-2];
        rer(i,N-2,1){
            cout <<res<<" "<<a[i]<<"\n";
            res-=a[i];
        }
        cout <<res<<" "<<a[0]<<"\n";
    }
    else{
        vector<ll> neg, pos;
        ll sum=0;
        rep(i,0,N){
            if(a[i]<=0) neg.pb(a[i]);
            else pos.pb(a[i]);
            sum+=abs(a[i]);
        }
        ll k=sz(neg), l=sz(pos);
        ll res=pos[0];
        cout <<sum<<"\n";
        rep(i,1,k){
            cout <<res<<" "<<neg[i]<<"\n";
            res-=neg[i];
        }
        pos[0]=res;
        rep(i,1,l){
            cout <<neg[0]<<" "<<pos[i]<<"\n";
            neg[0]-=pos[i];
        }
        cout <<pos[0]<<" "<<neg[0]<<"\n";
        
    }
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

    	Scanner sc=new Scanner(System.in);

    	String order=sc.next();
    	
    	
    	int result=700;
    	for(String str:order.split("")) {
    		
    		if(str.equals("o")) {
    			result+=100;
    		}
    	}
    	
    	System.out.println(result);
    }


}







Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
string a;
int n,f=0;
int main()
{
    cin>>a;
    n=a.length();
    for(int i=0;i<n;i++)
    {
        if(a[i]=='9')
        {
            f=1;
            cout<<"Yes"<<endl;
            break;
        }
    }
    if(f==0)
    cout<<"No"<<endl;
    return 0;
}

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

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

    string s;
    int k;
    cin >> k;
    cin >> s;
    if(s.length()<=k)
        cout << s << endl;
    else
        cout << s.substr(0,k) << "..." << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    vector<ll> v(3);
    rep(i,3) cin>>v[i];
    sort(all(v));
    cout<<v[2]-v[0]<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace ConsoleAppAtCoderABC172
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var dc = new int[n + 1];
            var sum = 0L;

            for (int i = 1; i <= n; i++)
            {
                for (int j = i; j <= n; j += i)
                {
                    dc[j] ++;
                }

                sum += (long)i * dc[i];
            }

            WriteLine(sum);
        }
    }
}


Measured memory_bytes: 66516
class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if x > y:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)][::-1]

u = UnionFind(n)
ans = [n*(n-1)//2]
for a, b in ab:
    a, b = a-1, b-1
    ra, rb = u.root(a), u.root(b)
    p = u.parents[ra] * u.parents[rb] if ra != rb else 0
    ans.append(ans[-1] - p)
    u.unite(a, b)
ans.pop()
for i in ans[::-1]:
    print(i)

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

 int main() {
   int N;
   cin >> N;
   vector<char> A(N);
   for(int i = 0;i < N; i++){
     cin >> A.at(i);
   }
   
   int p = 0;
   int w = 0;
   int g = 0;
   int y = 0;
   for(int i = 0;i < N; i++){
    if(A.at(i) == 'P'){
      p++;
    }else if(A.at(i) == 'W'){
      w++;
    }else if(A.at(i) == 'G'){
      g++;
    }else if(A.at(i) == 'Y'){
      y++;
    }
   }
   if(p > 0 && w > 0 && g > 0 && y > 0){
     cout << "Four" << endl;
   }else{
     cout << "Three" << endl;
   }
 }

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

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> vec(N + 1);
    vec[0] = 0;
    rep(i,N){
        cin >> vec[i + 1];
    }
    rep(i,N){
        vec[i + 1] += vec[i];
    }
    rep(i,N + 1){
        vec[i] %= M;
    }
    sort(all(vec));
    ll ans = 0;
    ll count = 1;
    vec.push_back(-1);
    rep(i,N + 1){
        if (vec[i + 1] == vec[i]) count++;
        else{
            ans += (count - 1) * count / 2;
            count = 1;
        }
    }
    cout << ans << endl;
}

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

int gcd(int p, int q) {
    if (p % q == 0) return q;
    return gcd(q, p % q);
}
//さっきのツイートの関数で関数gcdを定義


int main() {
    int k, sum = 0;//整数変数kとsumを定義
    cin >> k;//入力をkとして受け取る

    for (int i = 1; i < k + 1; i++) {
        for (int j = 1; j < k + 1; j++) {
            for (int l = 1; l < k + 1; l++) {
                sum += gcd(i, gcd(j,l));//(i,j,l)の最大公約数をsumに加えていくループ
            }
        }
    }

    cout << sum << endl;//最大公約数の和を出力
}

Measured memory_bytes: 3196
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 30;
const int maxn=2e5+5;

int n,ques;
int a[maxn],tim[maxn];
int vis[maxn];

int main(){
	scanf("%d%d",&n,&ques);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),++tim[a[i]];
	for(int i=1;i<=n;i++)
		for(int j=max(i-tim[i],0);j<i;j++)++vis[j];
	int ans=0;
	for(int i=0;i<n;i++)if(!vis[i])++ans;
	while(ques--){
		int x,to;scanf("%d%d",&x,&to);
		int tmp=a[x];
		if(tmp-tim[tmp]>=0&&vis[tmp-tim[tmp]]==1)++ans;
		if(tmp-tim[tmp]>=0)--vis[tmp-tim[tmp]];
//		printf("----%d %d %d\n",ans,tmp,tim[tmp]);
		--tim[tmp];
		
		int tt=to;a[x]=tt;
		if(tt-tim[tt]>=1&&!vis[tt-tim[tt]-1])--ans;
		++tim[tt];
		if(tt-tim[tt]>=0)++vis[tt-tim[tt]];
		printf("%d\n",ans);
	}

	return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 998244353LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

lint dp[3030][3030][3];
int a[3030];

int main() {
  
  int n, k; cin >> n >> k;
  vector<lint> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      (dp[i + 1][j][0] += dp[i][j][0]) %= MOD;
      (dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1]) %= MOD;
      (dp[i + 1][j][2] += dp[i][j][2] + dp[i][j][1] + dp[i][j][0]) %= MOD;

      if (j + a[i] <= k) {
        (dp[i + 1][j + a[i]][1] += dp[i][j][0] + dp[i][j][1]) %= MOD;
        (dp[i + 1][j + a[i]][2] += dp[i][j][0] + dp[i][j][1]) %= MOD;
      }
    }
  }

  cout << dp[n][k][2] << endl;
  
  return 0;
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);


template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N; cin >> N;
	V<int> a(N),b;
	REP(i,N) cin >> a[i];
	for(int i = 0; i < N; ++i){
		int cnt = 0;
		int j;
		for(j = i+1; j < N; ++j){
			if(a[j-1]==a[j]) break;
		}
		b.push_back(j-i);
		i = j-1;
	}
	corner(b.size()<=3,accumulate(ALL(b),0));
	int ans = 0;
	for(int i = 1; i + 1 < b.size(); ++i) chmax(ans,b[i-1]+b[i]+b[i+1]);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3584
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		int ans = 0;
		int sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = m+i;
			sum += a[i];
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == 0) {
				ans = sum;
				break;
			}
		}
		if(a[0] > 0) {
			ans = sum-a[0];
		}else if(a[n-1] < 0) {
			ans = sum - a[n-1];
		}
		System.out.println(ans);
		sc.close();
	}


}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  string S;
  cin >> S;
  int ans = 0;
  int len = (int)(S.length());
  for(int i = 0; i < len/2; i++){
    if(S[i] != S[len-1-i]) ans++;
  }
  cout << ans << endl;
}

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

int main(){
    int D;
    scanf("%d\n", &D);
    if(D == 22){
        printf("Christmas Eve Eve Eve\n");
    } else if(D == 23){
        printf("Christmas Eve Eve\n");
    } else if(D == 24){
        printf("Christmas Eve\n");
    } else {
        printf("Christmas\n");
    }
    return 0;
}

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



int main(){
  int N;
  cin >>N;
  vector<vector<double>>dp(N+1,vector<double>(N+1));	
  vector<double>p(N+1);
 
  for(int i=1;i<=N;i++){
   cin >>p[i];
  }
  
  dp[0][0]=1;
  for(int i=1;i<=N;i++){
  	for(int j=0;j<=i;j++){
    	dp[i][j]+= dp[i-1][j]*(1-p[i]);
      	if(j!=0)dp[i][j]+= dp[i-1][j-1]*p[i];    	
    }
  }
  double ans=0; int x=(N/2)+1;
  for(int i=x;i<=N;i++){
  ans+=dp[N][i];
  }
  cout<< setprecision(12) <<ans<<endl;
  
}

Measured memory_bytes: 70656
#include <stdio.h>
#include <stdint.h>

int main(void) {
  int64_t N;
  scanf("%ld", &N);

  // N = q*r + m (m == q)
  // N = q(r + 1)
  int64_t sum = 0;
  for(int64_t i = 1; i*i <= N; i++) {
    if((N % i) == 0) {
      int64_t f = (N / i) - 1;
      if(f > i)
	sum += f;
    }
  }
  printf("%ld\n", sum);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<map>
#define LEN 100
#define BASE 25

using namespace std;

int maps[LEN][LEN];
int off[LEN][LEN];

int checker[4];
int ncheck[4];

map<int, int> points[LEN];

class State {
public:
	char where;
	int enemy;
	int budget;
	int check[4];
	State() {check[0]=0;check[1]=0;check[2]=0;check[3]=0;}
	State(char w, int e, int b ) {
		where = w;
		enemy = e;
		budget = b; 
		check[0] = ncheck[0];
		check[1] = ncheck[1];
		check[2] = ncheck[2];
		check[3] = ncheck[3];
	}
};

bool operator< ( const State& a, const State& b) {
	if( a.enemy == b.enemy )
		return a.budget < b.budget;
	return a.enemy < b.enemy;
}

bool operator> ( const State& a, const State& b) {
	if ( a.enemy == b.enemy )
		return a.budget > b.budget;
	
	return a.enemy > b.enemy;
}

priority_queue<State, vector<State>, greater<State> > status;

inline void copy ( State now ) {
	checker[0] = now.check[0];
	checker[1] = now.check[1];
	checker[2] = now.check[2];
	checker[3] = now.check[3];
}

inline void ncopy ( ) {
	ncheck[0] = checker[0];
	ncheck[1] = checker[1];
	ncheck[2] = checker[2];
	ncheck[3] = checker[3];
}

bool check ( int i ) {
	return 0 == ((1<<(i%25)) & checker[i/BASE]);
}

void add ( int i ) {
	ncheck[i/BASE] = ((1<<(i%25)) | checker[i/BASE]);
}

int main () {


	while ( true ) {
		int n,m,l;
		cin >> n >> m >> l;

		if ( n == 0 )
			break;

		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<n; j++ ) {
				maps[i][j] = -1;
				off[i][j] = 0;
			}
			points[i].clear();
		}

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

			maps[a-1][b-1] = maps[b-1][a-1] = d;
			off[a-1][b-1] = off[b-1][a-1] = e;
		}

		for ( int i=0; i<4; i++ ) {
			ncheck[i] = 0;
			checker[i] = 0;
		}

		while( !status.empty() ) {
			status.pop() ;
		}	

		ncheck[0] = 1;
		status.push(State(0,0,l));
		int count = 0;
		while(!status.empty()) {
			State now = status.top();
			status.pop();
			if ( now.where == n-1 ) {
				cout << now.enemy << endl;
				break;
			}

			copy(now);

			for ( int i=0; i<n; i++ ) {
				if ( maps[now.where][i] > 0 ) {
					if ( check( i ) ) {
						ncopy();
						add(i);
						int e, b;
						if ( off[now.where][i] == 0 ) {
							e = now.enemy;
							b = now.budget;
							if ( points[i].find(e) == points[i].end() ) {
								points[i][e] = b;
								status.push(State(i,e,b));
							} else if ( points[i][e] < b ) {
								points[i][e] = b;
								status.push(State(i,e,b));
							}
						} else {
							if ( now.budget - maps[now.where][i] >= 0 ) {
								e = now.enemy;
								b = now.budget - maps[now.where][i];
								if ( points[i].find(e) == points[i].end() ) {
									points[i][e] = b;
									status.push(State(i,e, b));
								} else if ( points[i][e] < b ) {
									points[i][e] = b;
									status.push(State(i,e,b));
								}
							}
							e = now.enemy + off[now.where][i];
							b = now.budget;
							if ( points[i].find(e) == points[i].end() ) {
								points[i][e] = b;
								status.push(State(i,e,b));
							} else if ( points[i][e] < b ) {
								points[i][e] = b;
								status.push(State(i,e,b));
							}
						}
					}
				}
			}
		}
	}
}

		

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

using namespace std;

const int N = 5009;

int n, k, a[N]; 
int dp1[N][N], dp2[N][N]; 

void readInput() {

    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &a[i]);
    }
}

void preProcess() {

    dp1[0][0] = 1;
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j <= k; j ++) {
            if(dp1[i][j]) {
                dp1[i + 1][min(k, j + a[i + 1])] = 1;
                dp1[i + 1][j] = 1;
            }
        }
    } 

    dp2[n + 1][0] = 1;
    for(int i = n + 1; i > 1; i --) {
        for(int j = 0; j <= k; j ++) {
            if(dp2[i][j]) {
                dp2[i - 1][min(k, j + a[i - 1])] = 1;
                dp2[i - 1][j] = 1;
            }
        }
    }

    for(int i = 0; i <= n + 1; i ++) {
        for(int j = 1; j <= k; j ++) {
            dp2[i][j] += dp2[i][j - 1];
        }
    }
}

int main(int argc, char const *argv[]) {

    readInput();
    preProcess();

    int ans = 0;

    for(int i = 1; i <= n; i ++) {
        bool found = false;
        for(int leftSum = 0; leftSum < k; leftSum ++) {
            if(dp1[i - 1][leftSum]) {
                int rightSumLow = max(0, k - a[i] - leftSum);
                int rightSumHigh = k - 1 - leftSum;
                if(rightSumHigh < rightSumLow) {
                    continue;
                }
                if(dp2[i + 1][rightSumHigh] - (rightSumLow ? dp2[i + 1][rightSumLow - 1] : 0) > 0) {
                    found = true;
                    break;
                }
            }
        }
        if(!found) {
            ans ++;
        }
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 196096
import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())

a = list(map(int, input().split()))

check = [False for _ in range(n + 1)]
route = [1]
check[1] = True
now = a[0]
cnt = 1
while (1):
    # roup += 1
    # route.append(now)
    if cnt == k:
        print(now)
        exit()

    if check[now]:
        break
    else:
        check[now] = True
        route.append(now)
        cnt += 1
        now = a[now - 1]

indexnow = route.index(now)
roop_length = len(route) - indexnow
new_route = route[indexnow:]
# print(indexnow)
# print(new_route)
# print(roop_length)
# print(route)

print(new_route[(k - indexnow) % roop_length])


Measured memory_bytes: 32376
from collections import Counter
n, m = [int(item) for item in input().split()]
cnt = Counter()
for i in range(m):
  a, b = [int(item) for item in input().split()]
  cnt[a] += 1
  cnt[b] += 1
  
for key in cnt.keys():
  if cnt[key] % 2 != 0:
    print("NO")
    exit()
print("YES")

Measured memory_bytes: 9448
N = int(input())
a = list(map(int, input().split()))
for i in range(1, N):
    a[i] += a[i - 1]
mini = 10000000000
for i in range(N - 1):
    if abs(a[-1] - a[i] * 2) < mini:
        mini = abs(a[-1] - a[i] * 2)
print(mini)


Measured memory_bytes: 24824
N, K = map(int, input().split())
S = input()

if S[K-1] == 'A':
	newS = S[:K-1]+'a'+S[K:]
elif  S[K-1] == 'B':
	newS = S[:K-1]+'b'+S[K:]
else:
	newS = S[:K-1]+'c'+S[K:]
	
print(newS)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main(void){
    string a, b, c;
    cin >> a >> b >> c;
    string ans = "";
    ans += a[0] - 32;
    ans += b[0] - 32;
    ans += c[0] - 32;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// copied
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
typedef long long ll;
ll ans,a[60];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    ll* p;
    while(*(p=max_element(a+1,a+n+1)) >= (ll)n){
        for(int i=1;i<=n;++i){
            if(a+i!=p){
                a[i]+=(*p)/(ll)n;
            }
        }
        ans+=(*p)/(ll)n;
        (*p)%=(ll)n;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3708
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll K;
    cin >> K;

    if (K % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    ll now = 7;
    rep(i, 1000000) {
        ll tmp = (now + K) % K;

        if (tmp == 0) {
            cout << i + 1 << endl;
            return 0;
        }

        now = tmp * 10 + 7;
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;int sum=0;
    vector<int> vec(n);
  
for (int i = 0; i < n; i++) {
        cin>> vec.at(i);
      sum+=vec[i];
    }
  int m;
  cin >>m;
  vector<int> memo(2);
  int i=0;
while(i<m){
cin >> memo[0] >>memo[1];
int k= vec[memo[0]-1]-memo[1];
  cout << sum - k <<endl;
i++;
  
}
   
  
}

Measured memory_bytes: 3540
#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 repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string S;
int main(){
    cin >> S;
    int sum = 0;
    rep(i,S.size()){
        if(S[i] == '+') sum++;
        else sum--;
    }
    cout << sum << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)
 
struct Problem {
 
	void Solve() {
		UL P; cin >> P;
		vector<UL> A(P); rep(i, P) cin >> A[i];
		if (P == 2) { cout << A[0] << " " << (A[0] ^ A[1]) << endl; return; }
		UL R;
		for (UL r = 2; r < P; r++) {
			UL tmp = 1;
			rep(i, P - 1) {
				tmp *= r; tmp %= P;
				if (tmp == 1) { tmp = i + 1; break; }
			}
			if (tmp == P - 1) { R = r; break; }
		}
		vector<UL> Q(P); Q[0] = 1;
		rep(i, P - 1) Q[i + 1] = Q[i] * R % P;
		vector<UL> F(P);
		rep(i, P - 1) F[Q[i]] = i;
		reverse(Q.begin(), Q.end());
 
		vector<UL> B(P); B[0] = A[0];
		for (UL i = 1; i < P; i++) A[i] = (A[i] + P - A[0]) % P;
 
		for (UL i = 1; i < P; i++) {
			for (UL j = 1; j < P; j++) {
				B[i] += A[j] * Q[F[j] * i % (P - 1)];
				B[i] %= P;
			}
			B[i] = B[i] * (P - 1) % P;
		}
		rep(i, P) { if (i) cout << " "; cout << B[i]; }
		cout << endl;
 
		/*
		rep(i, P) {
			vector<UL> X(P); X[0] = 1;
			rep(j, P - 1) X[j + 1] = X[j] * i % P;
			UL ans = 0;
			rep(j, P) ans += B[j] * X[j] % P;
			ans %= P;
			cout << ans << " ";
		} cout << endl;
		*/
	}
 
	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

const ll MAX = 2e5 + 1;
ll MOD = 1e9 + 7;
ll INV[MAX] = {}, FACTORIAL[MAX] = {}, FACTORIAL_INV[MAX] = {};

void calc_init() {
  INV[1] = 1;
  FACTORIAL[0] = FACTORIAL[1] = 1;
  FACTORIAL_INV[0] = FACTORIAL_INV[1] = 1;

  for (int i = 2; i <= MAX; i++) {
    ll q = MOD / i, r = MOD % i;
    INV[i] = (-INV[r] * q) % MOD;
    INV[i] = (INV[i] + MOD) % MOD;
    FACTORIAL[i] = (i * FACTORIAL[i - 1]) % MOD;
    FACTORIAL_INV[i] = (INV[i] * FACTORIAL_INV[i - 1]) % MOD;
  }
}

ll nCk(ll n, ll k) {
  ll ans = FACTORIAL[n];
  ans = (ans * FACTORIAL_INV[k]) % MOD;
  ans = (ans * FACTORIAL_INV[n - k]) % MOD;
  return ans;
}


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

  ll N; cin >> N;
  ll K; cin >> K;
  calc_init();

  ll ans = 0;
  for (ll i = 0; i <= min(K, N - 1); i++) {
    ans = (ans + nCk(N, i) * nCk(N - 1, i)) % MOD;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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 GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int n, m, q;
	cin >> n >> m >> q;

	vvi sum(n + 1, vi(n + 1));
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		//a--, b--;

		sum[a][b]++;
	}

	rep(i, n) {
		rep(j, n) {
			sum[i + 1][j + 1] += sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
		}
	}

	rep(i, q) {
		int l, r;
		cin >> l >> r;
		//l--, r--;

		cout << sum[r][r] - sum[l - 1][r] - sum[r][l - 1] + sum[l - 1][l - 1] << endl;
	}
}

Measured memory_bytes: 1920
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int a[n];
    long long int sum = 0;
    long long int odd_sum = 0;
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        sum += a[i];
        if(i % 2 == 1)
        {
            odd_sum += a[i];
        }
    }
    long long int x = sum - 2 * odd_sum;
    cout << x << " ";
    for(int i = 1;i < n;i++)
    {
        x = 2 * a[i - 1] - x;
        cout << x << " ";
    }
    cout << "\n";
    
    return 0;
}

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

int main()
{
    int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int dp[n]={0};
    if(n<3)
    {
        if(n==1) {
        	cout<<0;
          	return 0;
        }
        if(n==2) {
           cout<<abs(arr[0]-arr[1]);
           return 0;        
        }
    }
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    cout<<dp[n-1];
}

Measured memory_bytes: 1024