akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;

int n, m, a;
int h, p, q;
int now_a;
pair<int, pair<int, int> > data[1000];

int main(){

	while (1)
	{
		//Input
		cin >> n >> m >> a;
		now_a = a;
		if (n+m+a==0) break;
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			data[i] = make_pair(-h, make_pair(p, q));
		}
		
		//sort
		sort(data, data + m);


		//
		for (int i = 0; i < m; i++) {
			if ((now_a == data[i].second.first) || (now_a == data[i].second.second))
				(now_a == data[i].second.first) ? now_a = data[i].second.second : now_a = data[i].second.first;
		}
		

		//Output
		cout << now_a << endl;
	}

	return 0;
}

Measured memory_bytes: 1176
__DEUBG__ = 0

import math
import sys

H, W = map(int, input().split())

board = [
  list(input())
  for _ in range(H)]

def calc(board, x, y):
    if board[x][y] == '#':
        for i,j in [
          (x, y-1),
          (x-1, y),
          (x+1, y),
          (x, y+1)
        ]:
            if 0 <= i <= H-1 and 0 <= j <= W-1:
                if board[i][j] == '#':
                    return
        print('No')
        exit()
    else:
        return

for i in range(H):
    for j in range(W):
        if __DEUBG__:
            print(i, j)
        calc(board, i, j)

print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long ;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

bool sorty(P l, P r){
    return l.second>=r.second;
}
int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vector<P> red,blue;
    ll x,y;
    rep(i,n){
        cin >> x >> y;
        red.push_back(make_pair(x,y));
    }
    rep(i,n){
        cin >> x >> y;
        blue.push_back(make_pair(x,y));
    }
    sort(red.begin(), red.end(), sorty);
    sort(blue.begin(), blue.end());
    ll res = 0;
    rep(i,n){
        ll bluey = blue.at(i).second;
        ll bluex = blue.at(i).first;
        rep(j,red.size()){
            ll redy = red.at(j).second;
            ll redx = red.at(j).first;
            if(redy<bluey && redx<bluex){
                res++;
                red.erase(red.begin()+j);
                break;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
mini=100000000
ans=0
for i in range(n):
    if abs(t-h[i]*0.006-a)<mini:
        mini=abs(t-h[i]*0.006-a)
        ans=i
print(ans+1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
typedef std::vector<pl> vpl;
const long double EPS = 1e-9;

#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c) 
#define rsort(a,n) sort(a,a+n,greater<>())
#define Forchar(c,a,z) for(char (c) = (a); (c) <= (z); (c)++) 
#define cntchar(s,c) count(all((s)), c)

const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100000;

int main(void){
    ll a, b,c,d;
    str s,t;

    in4(a,b,c,d);
    
    if (b<=c || d<=a) prl(0);
    else prl(min(b,d)-max(a,c));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int turn = 0;
    while(A > 0 && C > 0){
        if(turn % 2 == 0){
            C -= B;
        }
        else A -= D;
        turn = 1 - turn;
    }
    if(A <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 3652
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		int H = Integer.valueOf(s.next());
		int W = Integer.valueOf(s.next());
		int[] start = new int[4]; //y, x, 歩数, ワープ
		int[] goal = new int[2];
		start[0] = Integer.valueOf(s.next()) - 1;
		start[1] = Integer.valueOf(s.next()) - 1;
		goal[0] = Integer.valueOf(s.next()) - 1;
		goal[1] = Integer.valueOf(s.next()) - 1;

		int[][] maze = new int[H][W];
		char[] cur;
		for(int i = 0; i < H; i++) {
			cur = s.next().toCharArray();
			for(int j = 0; j < W; j++) {
				maze[i][j] = cur[j] == '.' ? -1 : -2;
			}
		}

		int[] vx = {1, 0, -1, 0};
		int[] vy = {0, -1, 0, 1};
		int[][] vxw = new int[4][5];
		int[][] vyw = new int[4][5];

		vxw[0] = new int[]{2, 2, 2, 2, 2}; //20個
		vyw[0] = new int[]{2, 1, 0, -1, -2}; //20個
		vxw[1] = new int[]{1, 1, 0, -1, -1}; //20個
		vyw[1] = new int[]{-1, -2, -2, -2, -1}; //20個
		vxw[2] = new int[]{-2, -2, -2, -2, -2}; //20個
		vyw[2] = new int[]{-2, -1, 0, 1, 2}; //20個
		vxw[3] = new int[]{-1, -1, 0, 1, 1}; //20個
		vyw[3] = new int[]{1, 2, 2, 2, 1}; //20個

		PriorityQueue<int[]> Q = new PriorityQueue<>((a, b) -> Integer.compare(a[3], b[3]));
		Q.add(start);

		int[] now;
		int[] tmp = new int[4];
		int ret = -1;
		while(!Q.isEmpty()) {
			now = Q.poll();

			for(int i = 0; i < 4; i++) {
				tmp[0] = now[0] + vy[i];
				tmp[1] = now[1] + vx[i];

				// 範囲内チェック
				if(-1 < tmp[0] && tmp[0] < H && -1 < tmp[1] && tmp[1] < W) {

					// 一回も行ってない
					if(maze[tmp[0]][tmp[1]] > now[3] || maze[tmp[0]][tmp[1]] < 0) {

						// 迷路が壁以外
						if(maze[tmp[0]][tmp[1]] != -2) {

							// ゴール
							if(tmp[0] == goal[0] && tmp[1] == goal[1]) {
								System.out.println(now[3]);
								return;
							}

							maze[tmp[0]][tmp[1]] = now[3]; // 迷路の値を更新
							Q.add(new int[] {tmp[0], tmp[1], 0, now[3]});

						// 迷路が壁
						}else {

							for(int j = 0; j < 5; j++) {
								tmp[0] = now[0] + vyw[i][j];
								tmp[1] = now[1] + vxw[i][j];

								// 範囲内チェック
								if(-1 < tmp[0] && tmp[0] < H && -1 < tmp[1] && tmp[1] < W) {

									// 一回も行ってない
									if(maze[tmp[0]][tmp[1]] > now[3] || maze[tmp[0]][tmp[1]] < 0) {
										// 迷路が壁以外
										if(maze[tmp[0]][tmp[1]] != -2) {

											// ゴール
											if(tmp[0] == goal[0] && tmp[1] == goal[1]) {
												System.out.println(now[3] + 1);
												return;
											}
											maze[tmp[0]][tmp[1]] = now[3] + 1; // 迷路の値を更新
											Q.add(new int[] {tmp[0], tmp[1], 0, now[3] + 1});
											j++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		System.out.println(ret);
	}
}

Measured memory_bytes: 65056
from collections import deque

def main():
    N, *AB = map(int, open(0).read().split())

    E = [[] for _ in range(N + 1)]
    I = []
    for a, b in zip(*[iter(AB)] * 2):
        E[a].append(b)
        I.append(b)

    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q.append(u)

    print(max(C))
    for i in I:
        print(C[i])

main()

Measured memory_bytes: 25900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1000000007;
int arr[22][22],n;
ll dp[1<<21];
ll solve(ll bit)
{
    int ones=__builtin_popcount(bit);
    if(ones==n)
        {return 1;}
    if(dp[bit]!=-1)
        return dp[bit];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        if(arr[ones][i] && ((bit&(1<<i))==0))
        {
            ans+=(solve(bit|(1<<i)))%mod;
            ans%=mod;
        }

    }
    return dp[bit]=ans%mod;

}
int main()
{

    ll i,j,k,l,m,a,b,c,d,cnt=0;
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>arr[i][j];
    cout<<solve(0);



}


Measured memory_bytes: 16640
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 23764
s = gets.chomp
@ans = 0
def dfs(s,sum,count)
  if s.size == count 
    sum += s.to_i
    @ans += sum 
  else
    dfs(s,sum,count+1)
    dfs(s[count..-1],sum + s[0..count-1].to_i,1)
  end
end 

puts dfs(s,0,1)

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

int main(){
  int n,a;
  cin>>n>>a;
  if(a>=500){
    cout<<"Yes"<<endl;
  }else{
    if(n%500<=a){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 200000;
int N, K, L;

static const int MAX_UF = MAX_N;

template <class T> class UnionFind {
private:
  T par[MAX_UF];
  T rank[MAX_UF];
  
public:
  T find(T x);
  void init(T n);
  void unite(T x, T y);
  bool same (T x, T y);
};

template <class T> void UnionFind<T>::init(T n) {
  for (T i = 0; i < n; ++i) {
    par[i] = i;
    rank[i] = 0;
  }
}

template <class T> T UnionFind<T>::find(T x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

template <class T> void UnionFind<T>::unite(T x, T y) {
  x = find(x); y = find(y);
  if (x == y) {
    return;
  } else {
    if (rank[x] > rank[y]) {
      par[y] = x;
    } else {
      par[x] = y;
      if (rank[x] == rank[y]) ++rank[y];
    }
  }
}

template <class T> bool UnionFind<T>::same(T x, T y) {
  return find(x) == find(y);
}

int main() {
  cin >> N >> K >> L;

  UnionFind<int> road_uinion;
  UnionFind<int> rail_uinion;
  road_uinion.init(N);
  rail_uinion.init(N);
  for (int i = 0; i < K; ++i) {
    int p, q;
    cin >> p >> q;
    road_uinion.unite(--p, --q);
  }
  for (int i = 0; i < L; ++i) {
    int r, s;
    cin >> r >> s;
    rail_uinion.unite(--r,--s);
  }

  map<pii, int> group;
  for (int i = 0; i < N; ++i) {
    ++group[pii(road_uinion.find(i), rail_uinion.find(i))];
  }


  for (int i = 0; i < N; ++i) {
    cout << group[pii(road_uinion.find(i), rail_uinion.find(i))] << endl;
  }

}


Measured memory_bytes: 15104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, M, L, R, Lmax = 0, Rmin = 100000;

	cin >> N >> M;
	rep(i, M) {
		cin >> L >> R;
		Lmax = max(Lmax, L);
		Rmin = min(Rmin, R);
	}

	cout << (Lmax <= Rmin ? Rmin - Lmax + 1 : 0) << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {

	var N,K,Q int
	fmt.Scan(&N,&K,&Q)
	winner := make([]int, Q)
	score := make ([]int, N)
	maps := map[int]int{}
	for i, _ := range winner {
		fmt.Scan(&winner[i])
		maps[winner[i]]++
	}
	for i,  _:= range score{

		score[i] += K - Q + maps[i+1]

		if score[i] <= 0 {
			fmt.Println("No")
		}else {
			fmt.Println("Yes")
		}
	}
}


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

int main()
{
    int n;
    cin >> n;
    vector<string> a(n);

    rep(i, n)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()),a.end());
    //rep(i,n)
    //cout << a[i] << endl;
    cout << a.size() << endl;

}

Measured memory_bytes: 9488
H, W = map(int,input().split())

S = []
for i in range(H):
    S.append(input())

ans = [[" " for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"

        else:
            a = 0
            if i > 0:
                if S[i-1][j] == "#":
                    a += 1
                    
                if j > 0:
                    if S[i-1][j-1] == "#":
                        a += 1

                if j < W-1:
                    if S[i-1][j+1] == "#":
                        a += 1

            if j > 0:
                if S[i][j-1] == "#":
                    a += 1

            if j < W-1:
                if S[i][j+1] == "#":
                    a += 1

            if i < H-1:
                if S[i+1][j] == "#":
                    a += 1
                    
                if j > 0:
                    if S[i+1][j-1] == "#":
                        a += 1

                if j < W-1:
                    if S[i+1][j+1] == "#":
                        a += 1

            ans[i][j] = str(a)

for i in range(H):
  print("".join(ans[i]))

Measured memory_bytes: 9288
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeSet;
fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
    }
    let mut set = BTreeSet::new();
    set.insert(a);
    set.insert(b);
    set.insert(c);
    println!("{}", set.len());
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m;
inline ll rd(){
    ll x=0;char c=getchar();bool f=0;
    while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return f?-x:x;
}
inline void MOD(ll &x){x=x>=mod?x-mod:x;}
struct matrix{
    ll a[3][3];
    matrix(){memset(a,0,sizeof(a));}
    inline matrix operator *(const matrix &b)const{
        matrix c;
        for(int i=0;i<3;++i)
            for(int j=0;j<3;++j){
                c.a[i][j]=0;
                for(int k=0;k<3;++k)
                    MOD(c.a[i][j]+=a[i][k]*b.a[k][j]%mod);
            }
        return c;
    }
    inline void print(){
        for(int i=0;i<3;++i){
            for(int j=0;j<3;++j)cout<<a[i][j]<<" ";puts("");
        }
        puts("");
    }
}a1,a2,ans;
inline matrix solve(matrix a,matrix b,int c){
    while(c){
        if(c&1)a=a*b;
        b=b*b;
        c>>=1;
    }
    return a;
}
int main(){
    n=rd();m=rd();
    a1.a[0][0]=1;a1.a[1][0]=1;a1.a[1][1]=1;a1.a[2][0]=1;a1.a[2][1]=2;a1.a[2][2]=1;
    a2=a1;a2.a[0][2]++;a2.a[1][2]++;a2.a[2][2]++;
    ans.a[0][2]=1;
    int x=0,pre=1;
    for(int i=1;i<=m;++i){
        x=rd();
        ans=solve(ans,a2,x-pre);
        ans=ans*a1;
        pre=x+1;
    }
    ans=solve(ans,a2,n-pre);
    cout<<(ans.a[0][0]+ans.a[0][1]+ans.a[0][2])%mod;
    return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<ulong, int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var n = int.Parse(line[2]);
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]) - 1;
            var b = int.Parse(line[1]) - 1;
            putDict(d, h, w, a, b);
        }
        var ret = new long[10];
        var rsum = 0;
        foreach (var x in d)
        {
            ret[x.Value]++;
            rsum++;
        }
        ret[0] = (long)(w - 2) * (h - 2) - rsum;
        foreach (var x in ret) Console.WriteLine(x);
    }
    public static void putDict(Dictionary<ulong, int> d, int h, int w, int a, int b)
    {
        if (a - 2 >= 0)
        {
            if (b - 2 >= 0) putDict2(d, a - 2, b - 2);
            if (b - 1 >= 0 && b + 1 < w) putDict2(d, a - 2, b - 1);
            if (b + 2 < w) putDict2(d, a - 2, b);
        }
        if (a - 1 >= 0 && a + 1 < h)
        {
            if (b - 2 >= 0) putDict2(d, a - 1, b - 2);
            if (b - 1 >= 0 && b + 1 < w) putDict2(d, a - 1, b - 1);
            if (b + 2 < w) putDict2(d, a - 1, b);
        }
        if (a + 2 < h)
        {
            if (b - 2 >= 0) putDict2(d, a, b - 2);
            if (b - 1 >= 0 && b + 1 < w) putDict2(d, a, b - 1);
            if (b + 2 < w) putDict2(d, a, b);
        }
    }
    public static void putDict2(Dictionary<ulong, int> d, int a, int b)
    {
        var nk = (ulong)a * 100000000000 + (ulong)b;
        if (d.ContainsKey(nk)) d[nk]++;
        else d[nk] = 1;
    }
}



Measured memory_bytes: 57404
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
    cout << head;
    print0(tail...);
}

int main() {
    ll R, C, K;
    cin >> R >> C >> K;

    vector<vector<ll>> itemtbl(R, vector<ll>(C));
    for (ll r = 0; r < R; r++) {
        for (ll c = 0; c < C; c++) {
            itemtbl[r][c] = 0;
        }
    }

    for (ll i = 0; i < K; i++) {
        ll r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        itemtbl[r][c] = v;
    }

    vector<vector<vector<ll>>> dp(R, vector<vector<ll>>(C, vector<ll>(4)));
    for (ll r = 0; r < R; r++) {
        for (ll c = 0; c < C; c++) {
            if (r == 0) {
                if (c == 0) {
                    dp[r][c][0] = itemtbl[r][c];
                    dp[r][c][1] = itemtbl[r][c];
                    dp[r][c][2] = itemtbl[r][c];
                    dp[r][c][3] = 0;
                } else {
                    dp[r][c][0] = max(dp[r][c - 1][1] + itemtbl[r][c], dp[r][c - 1][0]);
                    dp[r][c][1] = max(dp[r][c - 1][2] + itemtbl[r][c], dp[r][c - 1][1]);
                    dp[r][c][2] = max(dp[r][c - 1][3] + itemtbl[r][c], dp[r][c - 1][2]);
                    dp[r][c][3] = dp[r][c - 1][3];
                }
            } else {
                if (c == 0) {
                    dp[r][c][0] = itemtbl[r][c] + dp[r - 1][c][0];
                    dp[r][c][1] = itemtbl[r][c] + dp[r - 1][c][0];
                    dp[r][c][2] = itemtbl[r][c] + dp[r - 1][c][0];
                    dp[r][c][3] = dp[r - 1][c][0];
                } else {
                    dp[r][c][0] = max(
                        max(dp[r][c - 1][1] + itemtbl[r][c], dp[r][c - 1][0]),
                        dp[r - 1][c][0] + itemtbl[r][c]);
                    dp[r][c][1] = max(
                        max(dp[r][c - 1][2] + itemtbl[r][c], dp[r][c - 1][1]),
                        dp[r - 1][c][0] + itemtbl[r][c]);
                    dp[r][c][2] = max(
                        max(dp[r][c - 1][3] + itemtbl[r][c], dp[r][c - 1][2]),
                        dp[r - 1][c][0] + itemtbl[r][c]);
                    dp[r][c][3] = max(dp[r][c - 1][3], dp[r - 1][c][0]);
                }
            }
        }
    }
    print(dp[R - 1][C - 1][0]);
}


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

int N;
map<char, long long> S;
vector<char> H = {'M', 'A', 'R', 'C', 'H'};
vector<string> H_COMB = {"MAR", "MAC", "MAH", "MRC", "MRH", "MCH", "ARC", "ARH", "ACH", "RCH"};
long long ans;

void solve() {
  if (S.size() < 3) ans = 0;
  else {
    for (string h : H_COMB) {
      ans += S[h[0]] * S[h[1]] * S[h[2]];
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string str;
    cin >> str;
    for (char h : H) {
      if (h == str[0]) {
        ++S[h];
        break;
      }
    }
  }
  solve();
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,K=get_i
A=get_i
kind={}
A.each do|a|
    kind[a]=0 if kind[a].nil?
    kind[a]+=1
end
kind=kind.sort{|x,y| x[1]<=>y[1]}
kinds=kind.size
if K>=kinds
    puts 0
else
    puts kind[0..kinds-K-1].inject(0){|res,x| res+=x[1]}
end

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

int main() {
	long long int a,b,c,sum;
  	cin>>a>>b>>c;
  sum=0;
  
  sum += b/c +1;
  
  if(a-1==-1){
  	
  }
  else sum-= (a-1)/c+1;
  
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	R, C, K := scanInt(), scanInt(), scanInt()
	g := make([][]int, R+10)
	for i := 0; i < R+10; i++ {
		g[i] = make([]int, C+10)
	}
	for i := 0; i < K; i++ {
		r, c, v := scanInt(), scanInt(), scanInt()
		g[r][c] = v
	}

	dp := make([][][4]int, R+10)
	for i := 0; i < R+10; i++ {
		dp[i] = make([][4]int, C+10)
	}

	for i := 0; i <= R; i++ {
		for j := 0; j <= C; j++ {
			for k := 0; k < 4; k++ {
				dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k])
			}
			for k := 0; k < 4; k++ {
				dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][k]+g[i+1][j])
			}

			for k := 0; k < 4; k++ {
				dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])
			}
			for k := 0; k < 3; k++ {
				dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k]+g[i][j+1])
			}
		}
		// debug(dp[i][:C+1])
		// debug(g[i])
	}

	ans := 0
	for k := 0; k < 4; k++ {
		ans = max(ans, dp[R][C][k])
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 375116
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

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

using namespace std;
int mod = 1000000007;

int a, b, c;
int main() {
  cin >> a >> b >> c;
  if (a+b==c || a+c==b || b+c == a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second

inline int in(){int x, y; y = scanf("%d", &x); return x; }

const int N = 200002, E = 200002;

vector <int> g[N];
vector <pair<int, int>> ces;
int up[N], h[N], from[E], to[E];
bool mark[N], iscv[N];

int cecvme(int v, int pare = -1) // With multiple edge
{
	up[v] = h[v];
	mark[v] = true;
	int children = 0;
	for(int e : g[v])
		if(e != pare)
		{
			int u = to[e] ^ from[e] ^ v;
			if(mark[u])
				up[v] = min(up[v], h[u]);
			else
			{
				h[u] = h[v] + 1;
				up[v] = min(up[v], cecvme(u, e));
				if(up[u] >= h[v] && pare != -1)
					iscv[v] = true;
				children++;
			}
		}
	if(pare != -1 && up[v] == h[v])
		ces.push_back({from[pare] ^ to[pare] ^ v, v}); // pare
	if(pare == -1 && children > 1)
		iscv[v] = true;
	return up[v];
}
 
int cecv(int v, int par) // Without multiple edge
{
	up[v] = h[v];
	mark[v] = true;
	int children = 0;
	for(int u : g[v])
	{
		if(mark[u] && u != par)
			up[v] = min(up[v], h[u]);
		if(!mark[u])
		{
			h[u] = h[v] + 1;
			up[v] = min(up[v], cecv(u, v));
			if(up[u] >= h[v] && h[v] > 0)
				iscv[v] = true;
			children++;
		}
	}
	if(h[v] > 0 && up[v] == h[v])
		ces.push_back({par, v});
	if(h[v] == 0 && children > 1)
		iscv[v] = true;
	return up[v];
}

int main()
{
	int n = in(), m = in();
	for(int i = 0; i < m; i++)
	{
		int u = in(), v = in();
		g[u].push_back(v);
		g[v].push_back(u);
//		g[u].push_back(i);
//		g[v].push_back(i);
//		from[i] = u;
//		to[i] = v;
	}
	h[0] = 0;
	cecv(0, -1);
	for(int i = 0; i < n; i++)
		if(iscv[i])
			cout << i << endl;
}



Measured memory_bytes: 9500
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String input = reader.readLine();
        int x = Integer.parseInt(input);
        if(x==7||x==5||x==3){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 20692
N = int(input())

min_val = 1000000000
for i in range(1, int(N / 2)+1):
    A = i
    B = N - i
    val = sum(map(int, str(A))) + sum(map(int, str(B)))
    if val < min_val:
        min_val = val
print(min_val)

Measured memory_bytes: 3060
import sys
def amida(A,x):
  for e in A:
    if e[x]:x+=1
    elif e[x-1]:x-=1
  return x
def f():
  for i in D:
    for j in range(1,n):
      if A[i][j-1:j+2]==[0,0,0]:
        B=[e[:] for e in A]
        B[i][j]=1
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

while 1:
  n=input()
  if n==0:break
  m=input()
  p=input()
  D=range(input())
  A=[[0]+map(int,list(raw_input()))+[0] for i in D]
  if amida(A,m)==p:print 0
  else:f()

Measured memory_bytes: 4256
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

// 插入此處
const int MAXN = 1e5 + 2;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<int> p(MAXN), q(MAXN), r(MAXN);
    vector<tuple<int, int, int>> res;
    for (int i = 0; i < A; ++i) {
        int tmp; cin >> tmp;
        res.push_back(make_tuple(-tmp, 0, i));
    }
    for (int i = 0; i < B; ++i) {
        int tmp; cin >> tmp;
        res.push_back(make_tuple(-tmp, 1, i));
    }
    for (int i = 0; i < C; ++i) {
        int tmp; cin >> tmp;
        res.push_back(make_tuple(-tmp, 2, i));
    }
    sort(res.begin(), res.end());
    LL ans = 0, Z = 0;
    for (auto x : res) {
        int val = get<0>(x), type = get<1>(x), idx = get<2>(x);
        if (type == 0) {
            if (X > 0) {
                ans += -val;
                --X;
            }
        } else if (type == 1) {
            if (Y > 0) {
                ans += -val;
                --Y;
            }
        } else {
            ans += -val;
            ++Z;
        }
        if (X + Y == Z)  break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9328
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		while (m-- > 0) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			int ans = Math.min(w, Math.min(n + 1 - w, Math.min(h, n + 1 - h)));
			ans %= 3;
			System.out.println(ans == 0 ? 3 : ans);
		}
	}
}

Measured memory_bytes: 25176
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    IFOR(i, a, b){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    

    return 0;
}

Measured memory_bytes: 3116
def main():
    m, k = map(int, input().split())
    maximum = 2 ** m - 1

    if k==0:
        print(" ".join(map(str, range(0, maximum+1))), end=" ")
        print(" ".join(map(str, range(maximum, -1, -1))))
        return

    if m==1:
        print(-1)
        return

    if maximum < k:
        print(-1)
        return

    others = [i for i in range(1, maximum+1) if i!=k]
    print(0, k, 0, end=" ")
    print(" ".join(map(str, others)), k, " ".join(map(str, reversed(others))))


main()



Measured memory_bytes: 17968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll n;
    string s;
    cin>>n;
    cin>>s;
    ll count_R=0;
    ll count_G=0;
    ll count_B=0;
    for (ll i=0;i<n;i++){
    if(s[i]=='R'){
      count_R++;
    }
    else if(s[i]=='G'){
      count_G++;
    }
    else{
      count_B++;
    }
  }
  ll sum=count_R*count_G *count_B;
  for (ll i=0;i<n-2;i++){
    for (ll j=1;i+2*j<n;j++){
      if(s[i]!=s[i+j]&&s[i]!=s[i+2*j]&&s[i+j]!=s[i+2*j]){
        sum--;
      }
    }
  }
  cout<<sum;
return 0;
}


Measured memory_bytes: 3604
def gcd(a,b):
    c=0
    while b:(a,b),c=(b,a%b),c+1
    print(a,c)
 
while 1:
    n,m=map(int,input().split())
    if n==0:break
    gcd(n,m) if n>m else gcd(m,n)

Measured memory_bytes: 7676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=505;

int a[N],b[N];
ll l[N],r[N];
int n,k;
ll sum=0;
int judge(int x)
{
    for(int i=1;i<=n;i++)
        b[i]=a[i]%x;
    sort(b+1,b+1+n);
    for(int i=1;i<=n;i++)
        l[i]=l[i-1]+b[i];

    for(int i=n;i>=1;i--)
        r[i]=r[i+1]+(x-b[i]);
    for(int i=1;i<n;i++)
    {
        if(l[i]==r[i+1] && l[i]<=k)
            return x;
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int ans=1;
    for(int i=1;i*i<=sum;i++)
    {
        if(sum%i)continue;
        ans=max(ans,judge(i));
        ans=max(ans,judge(sum/i));
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};

int h,k,w,x,y,u,v;
vector<string> mat;
vector<vector<int>> vis;

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

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

void bfs() {
    queue<pair<int,int>> q;
    vis[x][y] = 1;
    q.push({x,y});

    while(q.size()) {
        auto cur = q.front();
        q.pop();
        for(int d = 0; d < 4; d++) {
            for(int i = 1; i<=k; i++) {
                int nx = cur.F + dx[d] * i;
                int ny = cur.S + dy[d] * i;
                if(!valid(nx, ny) || mat[nx][ny] == '@') break;
                if(vis[nx][ny] && vis[nx][ny] < 1 + vis[cur.F][cur.S]) break;
                if(vis[nx][ny]) continue;
                vis[nx][ny] = vis[cur.F][cur.S] + 1;
                q.push({nx,ny});
            }
        }
    }
}

int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        cin>>h>>w>>k>>x>>y>>u>>v;
        x--,y--,u--,v--;
        vis.resize(h);
        fori(i,h) vis[i].resize(w);
        fori(i,h)
            fori(j,w) vis[i][j] = 0;
        string s;
        fori(i,h) cin>>s,mat.pb(s);
        bfs();
        if(!vis[u][v]) cout<<"-1";
        else cout<<vis[u][v]-1;
    }
    
    return 0;
}

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

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	for(int i=0;i<=n;i++){
		int c=0;
		int t=i;
		for(int j=0;j<5;j++)c+=t%10,t/=10;
		if(a<=c&&c<=b)ans+=i;
	}
	cout<<ans<<endl;
}

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

int main() {
  int r;
  cin >> r;
  cout << 3*r*r;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define loop(i,x,y) for(ll i=x;i<y;i++)
#define pb push_back
#define S second
#define F first

int fun(ll b){

	int x = 0;

	while(b!=0){
		b /= 10;
		x++; 
	}

	return x;
}	


void solve(){
	
	ll n;
	cin >> n;

	ll a = sqrt(n);

	while(n%a != 0 )
		a--;

	ll b = n/a;

	cout << fun(b) << endl;

}
	
 
 
int main(){
	    
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	solve();
	 
	return 0;
 
}




Measured memory_bytes: 256
#include <stdio.h>
#define MAX 500000
#define SENTINEL 10000000000

void Merge(int[],int,int,int);
void MergeSort(int[],int,int);

int S[MAX],ct = 0;
int main(void){

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

  MergeSort(S,0,n);

  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i<n-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",ct);

  return 0;
}
void Merge(int S[],int left,int mid,int right){
   
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  int l[n1+1];
  int r[n2+1];
   
  for(i=0;i<n1;i++){
    l[i] = S[left+i];
  }
   
  for(i=0;i<n2;i++){
    r[i] = S[mid+i];
  }
  l[n1] = SENTINEL + 1;
  r[n2] = SENTINEL + 1;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(l[i]<=r[j]){
      S[k] = l[i];
      i += 1;
      ct++;
    } else{
      S[k] = r[j];
      j += 1;
      ct++;
    }
  } 
   
}
 
void MergeSort(int S[],int left,int right){
   
  int mid=0;
  if(left+1 < right){    
    mid=(left+right)/2;
    MergeSort(S,left,mid);
    MergeSort(S,mid,right);
    Merge(S,left,mid,right);  
  }
 
   
}

Measured memory_bytes: 4508
N, K = [int(s) for s in input().split()]
letters = list(input())

if letters[K-1] == 'A':
  letters[K-1] = 'a'
elif letters[K-1] == 'B':
  letters[K-1] = 'b'
elif letters[K-1] == 'C':
  letters[K-1] = 'c'

print(''.join(letters))


Measured memory_bytes: 38384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

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

int main(){
    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    sort(a.begin(), a.end());
    if ( (a[0]&1) == (a[1]&1) && (a[0]&1) == (a[2]&1) ) {
        cout << ( a[1] - a[0] ) / 2 + ( a[2] - a[1] ) << endl;
        return 0;
    }
    if ( (a[0]&1) != (a[1]&1) && (a[1]&1) == (a[2]&1) ) {
        cout << ( a[2] - a[1] ) / 2 + ( a[2] - a[0] + 1 ) / 2 + 1 << endl;  
        return 0;
    }
    if ( (a[0]&1) == (a[1]&1) && (a[0]&1) != (a[2]&1) ) {
        cout << ( a[1] - a[0] ) / 2 + ( a[2] - a[1] ) << endl; 
        return 0;
    }
    if ( (a[0]&1) == (a[2]&1) && (a[0]&1) != (a[1]&1) ) {
        cout << ( a[2] - a[0] ) / 2 + ( a[2] - a[1] + 1 ) / 2 + 1 << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
var visited = mutableListOf<Boolean>()
var pathList = Array(100) {arrayOfNulls<Boolean>(100)}
var n = 0
var m = 0

fun main(args: Array<String>) {

    val total = readLine()?.split(" ").orEmpty()
    n = total[0].toInt()
    m = total[1].toInt()

   var k = 0
   while(k < 100){
       var l = 0
       while(l < 100){
            pathList[k][l] = false
            l++
        }
       k++
    }

    var i = 0
    while(i < m){
        var path = readLine()?.split(" ").orEmpty()
            pathList[path[0].toInt() - 1][path[1].toInt() - 1] = true
            pathList[path[1].toInt() - 1][path[0].toInt() - 1] = true
        i++
    }


    for(j in 1 .. n){
        visited.add(false)
    }
    //----------------------------------------------------------

    println(dfs(0,0))

    //----------------------------------------------------------


}

fun dfs( now: Int, depth: Int): Int {
    if (visited[now]) {
        return 0
    }
    if (depth == n - 1) {
        return 1
    }
    visited[now] = true
    var totalPaths = 0

    for (h in 0 until n) {
        if (pathList[now][h]!!) {
            totalPaths += dfs(h, depth + 1)
        }
    }
    visited[now] = false
    return totalPaths
}




Measured memory_bytes: 37940
#include<iostream>
#include <bits/stdc++.h>
#define MAX 10000005
#define ll long  long
#define upperlimit 1000100
#define INF 1e18
#define inf 1e8
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>

#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mod 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a)printf("check%d\n",a)
#define ios ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
int a[200005],b[200005];
int main()
{
ios;
    int n;
    cin>>n;
    int o=0,ev=0;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        o+=a[i]%2;
        ev+=(1-a[i]%2);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
        if(b[i]%2==0)ans+=o%2;
        else ans+=ev%2;
        ans=ans%2;
    }

    int p2=1;

    for(int j=1;j<=28;j++)
    {
        p2=p2*2;
        int t=0;
        vector<pii>v1,v2;
        for(int i=1;i<=n;i++)
        {
            int w=1,num=0,no=a[i];
            for(int k=1;k<=j;k++)
            {
                num=num+(no%2)*w;
                no=no/2;
                w=w*2;
            }
            if(no%2==0)v1.pb(mp(num,0));
            else v1.pb(mp(num,1));
        }
        for(int i=1;i<=n;i++)
        {
            int w=1,num=0,no=b[i];
            for(int k=1;k<=j;k++)
            {
                num=num+(no%2)*w;
                no=no/2;
                w=w*2;
            }
            if(no%2==0)v2.pb(mp(num,0));
            else v2.pb(mp(num,1));
            t+=no%2;
        }
        sort(v1.begin(),v1.end());
        sort(v2.begin(),v2.end());
        int k=0,cnt=0,total=0;
        for(int i=n-1;i>=0;i--)
        {
            int ans1=0;
            while(k<n&&v2[k].FF<(p2-v1[i].FF))
            {
                cnt+=v2[k].SS;
               // cout<<v2[k].FF<<" "<<v1[i].FF<<" "<<i<<" "<<j<<" "<<k<<endl;
                k++;
            }
            //cout<<v1[i].FF<<" "<<cnt<<" "<<total<<" "<<k<<endl;
            if(v1[i].SS==0)
            {
                ans1+=cnt+(n-k-(t-cnt));
            }
            else ans1+=(k-cnt)+(t-cnt);

            total+=ans1%2;
        }
        if(total%2==1)ans+=p2;
    }
    cout<<ans<<endl;
        


}





 

Measured memory_bytes: 8072
#include <iostream>

using namespace std;

int main()
{
int A, B;
cin >> A >> B ;
if(A == B == 1){
    cout << "Draw" << endl;
}
else if (A == 1){
    cout << "Alice" << endl;
}
else if ( B== 1){
    cout << "Bob" << endl;
}
else if (A > B){
    cout << "Alice" << endl;
}
else if (A < B){
    cout << "Bob" << endl;
}
else if ( A == B){
    cout << "Draw" << endl;
}

    return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define size_of(a) (int)(a).size()

typedef long long lint;
typedef pair< lint, lint > pii;

template< typename DATA >
class SegmentTree {
private:
	int size__;
	vector< DATA > data;
	
	inline int left_t(int k) { return 2 * k + 1; }
	inline int right_t(int k) { return 2 * k + 2; }
	
public:
	SegmentTree(int n, DATA ini) {
		for (size__ = 1; size__ < n; size__ *= 2);
		data.assign(2 * size__ - 1, ini);
	}
	
	inline DATA calc(DATA d1, DATA d2) { return max(d1, d2); }
	
	void update(int k, DATA a) {
		k += size__ - 1;
		data[k] = a;
		
		while (k > 0) {
			k = (k - 1) / 2;
			data[k] = calc(data[left_t(k)], data[right_t(k)]);
		}
	}
	
	DATA query(int a, int b) {
		return query(a, b, 0, 0, size__);
	}
	
	DATA query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return -(1LL << 60);
		if (a <= l && r <= b) return data[k];
		return calc(query(a, b, left_t(k), l, (l + r) / 2),
					query(a, b, right_t(k), (l + r) / 2, r));
	}
};

int N;
lint D, X[33], Y[33];

void rec(int i, int end, lint subX, lint subY, vector< pii >& vec) {
	if (i == end) {
		vec.push_back(pii(subX, subY));
		return;
	}
	
	rec(i + 1, end, subX, subY, vec);
	rec(i + 1, end, subX + X[i], subY - Y[i], vec);
	rec(i + 1, end, subX - X[i], subY + Y[i], vec);
}

int main() {
	cin >> N >> D;
	for_(i,0,N) cin >> X[i] >> Y[i];
	
	vector< pii > vf, vs;
	
	rec(0, N / 2, 0, 0, vf);
	rec(N / 2, N, 0, 0, vs);
	
	sort(vs.begin(), vs.end());
	
	SegmentTree< lint > segtree(size_of(vs), -(1LL << 60));
		
	for_(i,0,size_of(vs)) segtree.update(i, vs[i].second);
	
	vs.push_back(pii(1LL << 60, 0));	
	sort(vf.begin(), vf.end(), greater< pii >());
	
	int indexL = 0, indexU = 0;
	lint ans = 0;
	
	for_(i,0,size_of(vf)) {
		lint subX = vf[i].first;
		lint upper = D - subX, lower = -(D + subX);
		
		while (vs[indexL].first < lower) ++indexL;
		while (vs[indexU].first <= upper) ++indexU;
		
		ans = max(ans, vf[i].second + segtree.query(indexL, indexU));
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 713652
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll a,b,c,d;

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

Measured memory_bytes: 3580
import heapq
N,M=map(int,input().split())
A=list(map(lambda x:int(x)*(-1),input().split()))

heapq.heapify(A)

def func():
   n=-heapq.heappop(A)
   n//=2
   heapq.heappush(A,-n)

for i in range(M):
   func()

print(-sum(A))

Measured memory_bytes: 14180