akhauriyash/Code-Regression huggingface dataset:
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
    let s : String = sc.read();
    let mut acc = 0;
    for i in s.chars() {
        if i == '1' { acc += 1 }
    }
    println!("{}", acc);
	
}



Measured memory_bytes: 4352
s=input()
n=len(s)
now=s[0]
next=s[1]
flag=False
for i in range(2,n):
    if now!=s[i]:
        flag=True
        break
    if i==n-1:
        break
    now=next
    next=s[i]
if flag==False:
    print("Second")
else:
    if s[0]==s[n-1]:
        ans=n-3
        if ans%2==0:
            print("Second")
        else:
            print("First")
    else:
        ans=n-2
        if ans%2==0:
            print("Second")
        else:
            print("First")


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

static const int MAX = 100007;
static const int INF = 1e9+7;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, m;
vi adj[MAX];
int shirube[MAX];

void dijkstra(){
	priority_queue<P, vector<P>, greater<P>> pq;
	int color[MAX];
	int d[MAX];
	rep(i,n){
		d[i] = INF;
		color[i] = WHITE;
		shirube[i] = -1;
	}

	d[0] = 0;
	pq.push(make_pair(0,0)); // (部屋0からの距離, 部屋番号)
	color[0] = GRAY;

	while(!pq.empty()){
		P f = pq.top(); pq.pop();
		int u = f.second;
		color[u] = BLACK;

		if(d[u] < f.first) continue;

		rep(j,adj[u].size()){
			int v = adj[u][j];
			// cout << v << "," << d[v] << endl;
			if(color[v] == BLACK){
				continue;
			}
			if(d[v] > d[u] + 1){
				d[v] = d[u] + 1;
				shirube[v] = u;
				pq.push(make_pair(d[v], v));
			color[v] = GRAY;
			}
			
		}
	}
}

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	cin >> n >> m;
	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--;b--;
		adj[a].eb(b);
		adj[b].eb(a);
	}

	dijkstra();

	FOR(i,1,n){
		if(shirube[i] == -1){
			cout << "No" << endl;
			return;
		}
	}

	cout << "Yes" << endl;
	FOR(i,1,n){
		cout << shirube[i] + 1 << endl;
	}
}

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

Measured memory_bytes: 11608
#include <iostream>
#include <vector>
#include <list>
#include <unordered_set>
using namespace std;

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<int> a(M);
	for(int i = 0; i < M; ++i) {
		cin >> a[i];
	}
	vector<int> q(Q);
	for(int i = 0; i < Q; ++i) {
		cin >> q[i];
	}
	
	list<int> l;
	
	for(int i = 0; i < N; ++i) {
		l.push_back(i);
	}
	
	auto pos = l.begin();
	
	for(int i = 0; i < M; ++i) {
		if(a[i] % 2 == 0) {
			for(int j = 0; j < a[i]; ++j) {
				++pos;
				if(pos == l.end()) {
					pos = l.begin();
				}
			}
		} else {
			for(int j = 0; j < a[i]; ++j) {
				if(pos == l.begin()) {
					pos = l.end();
				}
				--pos;
			}
		}
		
		pos = l.erase(pos);
		if(pos == l.end()) {
			pos = l.begin();
		}
	}
	
	unordered_set<int> s;
	for(int x : l) {
		s.insert(x);
	}
	
	for(int i = 0; i < Q; ++i) {
		cout << s.count(q[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 8128
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, w, h;
	cin >> n >> w >> h;
	vi wifi_x1(n);
	vi wifi_x2(n);
	vi wifi_y1(n);
	vi wifi_y2(n);
	int idx_x1 = 0;
	int idx_x2 = 0;
	int idx_y1 = 0;
	int idx_y2 = 0;
	REP(i, n) {
		int x, y, koto;
		cin >> x >> y >> koto;
		wifi_x1[i] = max(0, x - koto);
		wifi_x2[i] = min(w, x + koto);
		wifi_y1[i] = max(0, y - koto);
		wifi_y2[i] = min(h, y + koto);
	}
	SORT(wifi_x1);
	SORT(wifi_x2);
	SORT(wifi_y1);
	SORT(wifi_y2);
	int cnt = 0;
	string clear = "No";
	REP(i, w) {
		while (idx_x1 < n&&wifi_x1[idx_x1] == i) {
			cnt++;
			idx_x1++;
		}
		while (idx_x2 < n&&wifi_x2[idx_x2] == i) {
			cnt--;
			idx_x2++;
		}
		if (cnt == 0) {
			goto res1;
		}
		
	}
	clear = "Yes";
	goto res2;
	res1:
	cnt = 0;
	REP(i, h) {
		while (idx_y1 < n&&wifi_y1[idx_y1] == i) {
			cnt++;
			idx_y1++;
		}
		while (idx_y2 < n&&wifi_y2[idx_y2] == i) {
			cnt--;
			idx_y2++;
		}
		if (cnt == 0) {
			goto res2;
		}
		
	}
	clear = "Yes";
res2:
	cout << clear << endl;
}

Measured memory_bytes: 4396
A,B,C=map(int,input().split())

if max(A,B,C)*3%2==(A+B+C)%2:
    print((3*max(A,B,C)-(A+B+C))//2)
else:
    print((3*(max(A,B,C)+1)-(A+B+C))//2)

Measured memory_bytes: 9048
#include <cstdio>
#include <map>

int main()
{
    int n, m;
    scanf("%d", &n);
    std::map<int, int> count;
    for (int i = 0, a; i < n; ++ i) {
        scanf("%d", &a);
        count[a] ++;
    }
    scanf("%d", &m);
    bool ok = true;
    for (int i = 0, b; i < m; ++ i) {
        scanf("%d", &b);
        count[b] --;
        ok &= count[b] >= 0;
    }
    puts(ok ? "YES" : "NO");
}

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(int64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

// 最小公倍数lcm=m*n/gcd
uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// nCm
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

signed main() {
  int64_t q, t, f;
  char c;
  string s = "";
  string head = "";
  string tail = "";
  cin >> s;
  cin >> q;

  bool isReversed = false;
  for(int64_t i=0; i< q; i++) {
    cin >> t;
    if(t==1){
      isReversed = !isReversed;
      continue;
    }
    cin >> f >> c;
    if ( (f==1 && !isReversed)
      || (f==2 && isReversed) ) {
      head += c;
    }
    else if( (f==2 && !isReversed)
          || (f==1 && isReversed) ){
      tail += c;
    }
  }
  if(isReversed){
    reverse(tail.begin(), tail.end());
    reverse(s.begin(), s.end());
    s = tail + s + head;
  }
  else {
    reverse(head.begin(), head.end());
    s = head + s + tail;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 1348
import std.stdio;
import std.conv;
import std.string;
import std.range;
import std.algorithm;

void main(){
    foreach(i; 0..readln().chomp().to!int()){
        auto input = readln().split();
        (input[0].decode() + input[1].decode()).encode().writeln();
    }
}

int decode(string input){
    int res;
    int qual = 1;
    foreach(c; input){
        switch(c){
            case 'm':
                res += qual * 1000;
                qual = 1;
                break;
            case 'c':
                res += qual * 100;
                qual = 1;
                break;
            case 'x':
                res += qual * 10;
                qual = 1;
                break;
            case 'i':
                res += qual;
                qual = 1;
                break;
            case '2': .. case '9':
                qual = c - '0';
            default:
        }
    }
    return res;
}

unittest{
    assert(decode("m2c4i") == 1204);
    assert(decode("5m2c3x4i") == 5234);
    assert(decode("5m2c3x") == 5230);
}

auto keta = ['m', 'c', 'x', 'i'];

string encode(int input){
    string res;
    foreach(i; 0..4){
        int qual = input / 10 ^^ (3 - i);
        input -= qual * 10 ^^ (3 - i);
        if(qual > 1){
            res ~= text(qual, keta[i]);
        }else if(qual == 1){
            res ~= keta[i];
        }
    }
    return res;
}

unittest{
    assert(encode(5234) == "5m2c3x4i");
    assert(encode(1204) == "m2c4i");
    assert(encode(5230) == "5m2c3x");
}

Measured memory_bytes: 1808
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
    int n,a[9]={111,222,333,444,555,666,777,888,999};
    cin>>n;
    for(int i=0;i<9;i++){
    	if(n<=a[i]) {
	cout<<a[i]<<endl;
	return 0;
	}
		
    }
    
    


    
    

   	

   return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=(1<<17)+10;
vector<int> bt[18];
void cons(int n,int a,int b,vector<int> &to)
{
	if(n==1)
	{
		to[0]=a;to[1]=b;
		return;
	}
	int pos=-1,aa,bb;
	for(int i=0;i<n;i++)
		if((a>>i&1)!=(b>>i&1))
		{
			pos=i;
			aa=(a>>(i+1)<<i)|(a%(1<<i));
			bb=(b>>(i+1)<<i)|(b%(1<<i));
			break;
		}
	int cc=(aa&1)?aa-1:aa+1;	
	vector<int> lft(1<<(n-1));
	vector<int> rht(1<<(n-1));
	cons(n-1,aa,cc,lft);
	cons(n-1,cc,bb,rht);
//	cout<<a<<" "<<b<<" "<<pos<<" "<<aa<<" "<<bb<<" "<<cc<<endl;
	for(int i=0;i<(1<<(n-1));i++)
	{
//		cout<<lft[i]<<" "<<(lft[i]%(1<<pos))<<" "<<((a>>pos&1)<<pos)<<" "<<((lft[i]/(1<<pos))<<(pos+1))<<endl;
		to[i]=(lft[i]%(1<<pos))|((a>>pos&1)<<pos)|((lft[i]/(1<<pos))<<(pos+1));
	}
//	system("pause");
	for(int i=0;i<(1<<(n-1));i++)
	{
//		cout<<rht[i]<<" "<<(rht[i]%(1<<pos))<<" "<<((b>>pos&1)<<pos)<<" "<<((rht[i]/(1<<pos))<<(pos+1))<<endl;
		to[i+(1<<(n-1))]=(rht[i]%(1<<pos))|((b>>pos&1)<<pos)|((rht[i]/(1<<pos))<<(pos+1));
	}
//	for(int i=0;i<(1<<n);i++)
//		cout<<to[i]<<" ";
//	cout<<endl;system("pause");
}
int main()
{
	int n,a,b;scanf("%d%d%d",&n,&a,&b);
	int ca=__builtin_popcount(a);
	int cb=__builtin_popcount(b);
	if(ca%2==cb%2){printf("NO\n");return 0;}
	printf("YES\n");
	vector<int> arr;
	arr.resize(1<<n);
	cons(n,a,b,arr);
	for(int i=0;i<arr.size();i++)
		printf("%d ",arr[i]);
	return 0;
}

Measured memory_bytes: 1852
N  = int(input())
h =  list(map(int , input().split(' ')))
#N = 6
#h = [30,10,60 , 10, 60,50]

dp =[-1]*(N)
dp[N-1] = 0
dp[N-2] = abs(h[N-2] - h[N-1])

m=N-3

while m>=0:
    diff = 0
    index  = 0
    diff = min(abs(h[m]-h[m+2]) + dp[m+2]  ,  abs(h[m]-h[m+1])+dp[m+1])
    dp[m] = diff 
    m -=1
print(dp[m+1])



Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define DBG(v) cerr << #v << " = " << (v) << endl;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	const int mod = (int)1e9 + 7;

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int &x : a)
		cin >> x;

	ll ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j)
			if (a[i] > a[j])
				(ans += k) %= mod;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			if (a[i] > a[j])
				(ans += k * (k - 1LL) / 2) %= mod;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
type dice = {one : int ; two : int ; three : int ; four : int ; five : int ; six : int };;
type dir = W | E | S | N | L | R ;;

let roll dice =
  let {one = a; two = b; three = c; four = d; five = e; six = f} = dice in
  function
    W -> {dice with one = c; three = f; six = d; four = a}
  | E -> {dice with one = d; four = f; six = c; three = a}
  | S -> {dice with one = e; two = a; six = b; five = f}
  | N -> {dice with one = b; two = f; six = e; five = a}
  | L -> {dice with two = c; three = e; five = d; four = b}
  | R -> {dice with two = d; four = e; five = c; three = b} ;;

let dir_list1 = [[];[W];[E];[S];[N];[W; W]];;
let dir_list2 = [[];[L];[R];[L;L]] ;;

let make_all_dices dice =
  let f d lst = List.fold_left (fun e dir -> roll e dir) d lst in
  let dice_list = List.map (f dice) dir_list1 in 
  List.map (fun x -> List.map (f x) dir_list2) dice_list |> List.concat ;;

let check_eq dice list =
  List.exists (fun x -> x = dice) list ;;

let () =
  let read () = Scanf.scanf "%d %d %d %d %d %d\n" (fun a b c d e f -> {one = a; two = b; three = c; four = d; five = e; six = f}) in
  let d1 = read () and d2 = read () in
  let all_dices = make_all_dices d2 in
  if check_eq d1 all_dices then print_endline "Yes" else print_endline "No" ;;



Measured memory_bytes: 2220
#include <iostream>
#include <string>

std::string s;

int main() {
    std::cin >> s;
    if ((s.at(2) == s.at(3)) and (s.at(4) == s.at(5))) {
        std::cout << "Yes";
    } else {
        std::cout << "No";
    }
}


Measured memory_bytes: 3636
#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(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(a + b, min(b + c, c + a)) << endl;
}



Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cassert>

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

using namespace std;

typedef pair<double,double> pdd;

const double EPS=1e-9;

int n,x[100],y[100];

struct Pos{
	double a,b;
	Pos(double A,double B):a(A),b(B){}
	bool operator<(const Pos &p)const{
		if(abs(a-p.a)>EPS) return a<p.a;
		if(abs(b-p.b)>EPS) return b<p.b;
		return false;
	}
};

vector<Pos> findNextPos(const Pos &p){
	vector<int> ca,cb;
	rep(i,n-1){
		if(x[i]-EPS<p.a && p.a<x[i+1]+EPS) ca.push_back(i);
		if(x[i]-EPS<p.b && p.b<x[i+1]+EPS) cb.push_back(i);
	}

// rep(i,ca.size()) printf("ca[%d] = %d\n",i,ca[i]);
// rep(i,cb.size()) printf("cb[%d] = %d\n",i,cb[i]);
	vector<Pos> res;
	rep(i,ca.size()) rep(j,cb.size()) {
		int i1=ca[i],i2=ca[i]+1,j1=cb[j],j2=cb[j]+1;
		double yy,x1,x2;

		if(y[i1]==y[i2] || y[j1]==y[j2]){
			if(y[i1]==y[i2]){
				res.push_back(Pos(x[i1],p.b));
				res.push_back(Pos(x[i2],p.b));
			}
			if(y[j1]==y[j2]){
				res.push_back(Pos(p.a,x[j1]));
				res.push_back(Pos(p.a,x[j2]));
			}
		}
		else{
			yy=min(max(y[i1],y[i2]),max(y[j1],y[j2]));
			x1=(double)(x[i2]-x[i1])/(y[i2]-y[i1])*(yy-y[i1])+x[i1];
			x2=(double)(x[j2]-x[j1])/(y[j2]-y[j1])*(yy-y[j1])+x[j1];
			res.push_back(Pos(x1,x2));

			yy=max(min(y[i1],y[i2]),min(y[j1],y[j2]));
			x1=(double)(x[i2]-x[i1])/(y[i2]-y[i1])*(yy-y[i1])+x[i1];
			x2=(double)(x[j2]-x[j1])/(y[j2]-y[j1])*(yy-y[j1])+x[j1];
			res.push_back(Pos(x1,x2));
		}
	}

	return res;
}

inline double height(double xx){
	rep(i,n-1) if(x[i]-EPS<xx && xx<x[i+1]+EPS) {
		return (double)(y[i+1]-y[i])/(x[i+1]-x[i])*(xx-x[i])+y[i];
	}
	assert(0);
}

inline double calcDistance(const Pos &p,const Pos &q){
	double hpa=height(p.a),hpb=height(p.b),
		   hqa=height(q.a),hqb=height(q.b);
	return sqrt((p.a-q.a)*(p.a-q.a)+(hpa-hqa)*(hpa-hqa))
		  +sqrt((p.b-q.b)*(p.b-q.b)+(hpb-hqb)*(hpb-hqb));
}

double solve(){
	map<Pos,double> d;
	d[Pos(0,x[n-1])]=0;

	priority_queue< pair<double,Pos> > pq;
	pq.push(make_pair(0,Pos(0,x[n-1])));
	while(!pq.empty()){
		double cost=-pq.top().first;
		Pos p=pq.top().second; pq.pop();

		if(d[p]+EPS<cost) continue;
// printf("now : %2.3f %2.3f\n",p.a,p.b);
		if(abs(p.a-p.b)<EPS) return cost;

		vector<Pos> next=findNextPos(p);
// rep(i,next.size()){
	// printf(" next[%d] = %2.3f %2.3f\n",i,next[i].a,next[i].b);
// }
		rep(i,next.size()){
			double cost2=calcDistance(p,next[i]);
// if(d.count(next[i])) printf("  %.3f < %.3f\n",cost+cost2,d[next[i]]);
// else printf(" nothing\n");
			if(d.count(next[i])==0 || cost+cost2+EPS<d[next[i]]){
// printf("  push %2.3f %2.3f\n",next[i].a,next[i].b);
				d[next[i]]=cost+cost2;
				pq.push(make_pair(-(cost+cost2),next[i]));
			}
		}
	}
	assert(0);
}

int main(){
	for(;scanf("%d",&n),n;){
		rep(i,n) scanf("%d%d",x+i,y+i);

		printf("%.15f\n",solve());
	}

	return 0;
}

Measured memory_bytes: 0
from collections import deque

def bfs(start):
    queue = deque([start])
    visited = []

    while queue:
        label = queue.pop()

        #if label not in visited:
        visited.append(label)

        for v in d[label]:
            if dist[v[0]] == float("inf"):
                dist[v[0]] = dist[label] + v[1]
                queue.appendleft(v[0])

    return

n = int(input())
d = [[] for _ in range(n)]
for _ in range(n - 1):
	a, b, c = map(int, input().split())
	d[a - 1].append([b - 1, c])
	d[b - 1].append([a - 1, c])

q, k = map(int, input().split())
dist = [float("inf") for _ in range(n)] # nは頂点数
dist[k - 1] = 0

bfs(k - 1)

for _ in range(q):
	x, y = map(int, input().split())
	print(dist[x - 1] + dist[y - 1])


Measured memory_bytes: 99616
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	string a;
	getline(cin, a);
	for (int i = 0; a[i] != '\0'; i++) {
		if (a[i] >= 'a'&&a[i] <= 'z') {
			a[i] += 'A' - 'a';
		}
		else if (a[i] >= 'A'&&a[i] <= 'Z') {
			a[i] -= 'A' - 'a';
		}
	}
	cout << a << endl;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (t <= a[i] * 4 * m) ans++;
  }
  if (m <= ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define INF 1e15
#define MOD 1000000007
int n;
int dp[111][4][4][4];
signed main() {
	cin >> n;
	dp[0][3][3][3] = 1;
	for (int i = 1; i <= n; i++) {//i個目まで見て
		rep(j, 4) {//3個前
			rep(k, 4) {//2個前
				rep(l, 4) {//1個前
					if (j == 0 && k == 2 && l == 1)continue;//AGC〇
					if (j == 2 && k == 0 && l == 1)continue;//GAC〇
					if (j == 0 && k == 1 && l == 2)continue;//ACG〇
					rep(m, 4) {//今見てるやつ
						if (k == 0 && l == 2 && m == 1)continue;//〇AGC
						if (k == 2 && l == 0 && m == 1)continue;//〇GAC
						if (k == 0 && l == 1 && m == 2)continue;//〇ACG
						if (j == 0 && k == 2 && m == 1)continue;//AG〇C
						if (j == 0 && l == 2 && m == 1)continue;//A〇GC
						dp[i][k][l][m] += dp[i - 1][j][k][l];
						dp[i][k][l][m] %= MOD;
					}
				}
			}
		}
	}
	int ans = 0;
	rep(i, 4) {
		rep(j, 4) {
			rep(k, 4) {
				if (i == 0 && j == 2 && k == 1)continue;
				if (i == 2 && j == 0 && k == 1)continue;
				if (i == 0 && j == 1 && k == 2)continue;
				ans += dp[n][i][j][k];
				ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>

using namespace std;

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



int main(){
    while(1){
    string ans="";
    map<char,char> x;
    int m,n;
    cin>>m;
        if(m==0)break;
    rep(i,m){
        char a,b;
        cin>>a>>b;
        x[a]=b;
    }
    cin>>n;
    rep(i,n){
        char tm;
        cin>>tm;
        if(x.count(tm)==0){
            ans+=tm;
        }
        else{
            ans+=x[tm];
        }
    }
    cout<<ans<<endl;
    
    }
    return 0;
    
}

Measured memory_bytes: 1340
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
boolean ans=false;
		int n = sc.nextInt();
		for(int i=1;i<=9;i++){
			for(int o=1;o<=9;o++){
				if(i*o==n){
ans=true;
break;
				}
			}
			if(ans){
				break;
			}
		}
if(ans){
	System.out.println("Yes");
}else{
	System.out.println("No");
}
	}
}

Measured memory_bytes: 23124
#include <stdio.h>

int main()
{
 int a[5],k;
 scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4]);

 for(int i=0;i<5;i++){
   if(a[i]==0){
     k=i+1;
   }
 }

 printf("%d",k);
  
  }
    
    
    
  
  
  


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

typedef vector<vector<pair<ll,int>>> wgraph;
typedef pair<ll,int> pli;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

vector<ll> inv,fact,invfact;
void mod_build(int n){  
  fact.resize(n+1); inv.resize(n+1); invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1; inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return fact[n]*invfact[n-k]%mod; } }
ll comb(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod; }}
ll modpow(ll n,ll k){
  k%=mod-1; if(k<0)k+=mod-1;
  ll ret=1; while(k){ if(k&1)ret=ret*n%mod; n=n*n%mod; k>>=1; }
  return ret;
}
ll modinv(ll a){ return modpow(a, mod-2); }

int main(){
  mod_build(mx);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  vector<mint> r(n+1,0);
  rep(i,n){
    r[i+1] = r[i]+inv[i+1];
  }

  mint ans=0;
  rep(i,n){
    mint p = r[i-0+1] + r[n-i] - r[1];
    ans += p*a[i];
  }
  ans *= fact[n];
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
    {
		Scanner sc = new Scanner(System.in);
      	int a = Integer.parseInt(sc.nextLine());
      	int result = 0;
      	for(int i = 0; i < a; i++)
        {
         	if(sc.nextInt() % 2 == 1 && i % 2 == 0)
            {
             	result++; 
            }
        }
      
      	System.out.println(result);
    }
}

Measured memory_bytes: 35872
#define _DEBUG
#include "bits/stdc++.h"
#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M;
	scan(N>>M);
	vll a(N),b(M);
	rep(i,N) scan(a[i]);
	rep(i,M) scan(b[i]);
	vll C=convolution<998244353>(a,b);
	for(const auto& c:C){
		printf("%lld ",c);
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 27224
s = input()
ls = list(s)
n = len(ls)

atcg = ["A","T","C","G"]
ans = [0]*n
if s[0] in atcg:
    ans[0] += 1
    
for i in range(1,n):
    if s[i] in atcg:
        ans[i] += ans[i-1] + 1
        
print(max(ans))

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
string s[9];
int indeces[9];
int ans;

void rec(int n){ // n テ」ツつ津ァツスツョテ」ツ??

  int nn = n-1;  // nn テ」ツ?セテ」ツ?ァテァツスツョテ」ツ?凝」ツつ古」ツ?ヲテ」ツ??」ツつ?
  if( n>0 && nn%3!=0 ){ // check left
    char a = s[indeces[nn-1]][1];
    char b = s[indeces[nn]][3];
    if(b<a) swap(a,b );
    switch(a){
    case 'R': if(b!='r') return; break;
    case 'G': if(b!='g') return; break;
    case 'B': if(b!='b') return; break;
    case 'W': if(b!='w') return; break;
    default: return; // テ、ツクツ。テヲツ鳴ケテ・ツーツ湘ヲツ鳴?・ツュツ?
    }
  }
  if( nn>=3 ){ // check up
    char a = s[indeces[nn-3]][2];
    char b = s[indeces[nn]][0];
    if(b<a) swap(a, b);
    switch(a){
    case 'R': if(b!='r') return; break;
    case 'G': if(b!='g') return; break;
    case 'B': if(b!='b') return; break;
    case 'W': if(b!='w') return; break;
    default: return; // テ、ツクツ。テヲツ鳴ケテ・ツーツ湘ヲツ鳴?・ツュツ?
    }
  }
  if( n == 9 ){
    ans++;    return;
  }

  for( int i=0;i<9;i++ ){
    bool flag = false;
    for( int j=0;j<n;j++ )
      if( indeces[j] == i ){ flag = true; break; }
    if( flag )
      continue;

    indeces[n] = i;
    for( int j=0;j<4;j++ ){
      string ss = s[i].substr(1) + s[i][0]; // totation
      s[i] = ss;
      rec( n+1 );
    }
  }
}

int main(){
  int n;
  cin >> n;
  while( n-- ){
    for( int i=0;i<9;i++ )
      cin >> s[i];
    ans=0;
    rec(0);
    cout << ans << endl;
  }

  return 0;
}

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

int main() {
  int N, A, B, sum = 0;
  cin >> N >> A >> B;

  for (int i = 1; i <= N; i++) {
    int c = i % 10 + i / 10 % 10 + i / 100 % 10 + i / 1000 % 10 + i / 10000;
    if (A <= c && c <= B) {
      sum += i;
    }
  }
  cout << sum << endl;
}

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

using namespace std;

int sim(const vector<int> &v, int start) {
    int l = start, r = start+1;
    while(true) {
        int pl = l, pr = r;
        int color = v[l];
        while(l >= 0 && v[l] == color) --l;
        while(r < v.size() && v[r] == color) ++r;
        if(pl-l + r-pr < 4) {
            l = pl;
            r = pr;
            break;
        }
    }
    return l+1 + v.size()-r;
}

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<int> v(N);
        for(int i = 0; i < N; ++i) {
            cin >> v[i];
        }
        int ans = N+100;
        for(int i = 0; i < N; ++i) {
            v[i] = 1+v[i]%3;
            ans = min(ans, sim(v, i));
            v[i] = 1+v[i]%3;
            ans = min(ans, sim(v, i));
            v[i] = 1+v[i]%3;
        }
        cout << ans << endl;
    }
    return 0;
}
    

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define fastio		ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define For(i,a,b)               for(int i=a;i<b;i++)
#define input(a,n)	For(i,0,n)cin>>a[i]
#define pb                          push_back
#define minimum(a)					*min_element(a.begin(), a.end())
#define maximum(a)					*max_element(a.begin(), a.end())
#define f 	first
#define s 	second
#define nl cout<<endl
#define print(a,n)	For(i,0,n){cout<<a[i]<<' ';}nl
#define pii pair<int,int>
using namespace std;
typedef long long ll;

int main()
{
	fastio;
	int n;
	cin>>n;
	int a[n],b[n];
	input(a,n);
	b[0]=0, b[1]=abs(a[0]-a[1]);
	For(i,2,n)
		b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
	cout<<b[n-1];
	return 0;
}

Measured memory_bytes: 1024
/* ex 9_2
   yumizmiz */

#include <stdio.h>
#include <stdlib.h>
//最大要素数
#define SIZE 100000
//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    //リストの先頭
    node *first = NULL;
    //キューブの配列,最大文字数10^5+1
    char cubes[SIZE+1], *ptr;
    ptr = cubes;
    scanf("%s",cubes);
    
    int pop_count = 0;
    while(*ptr){
        //空だったら無条件にpushする．または同じ色なら取り除かずpush
        if(first == NULL || first->elem == *ptr){
            push(&first,*ptr);
        }
        else{
            pop(&first);
            //取り除く数は2つ
            pop_count+=2;
        }
        ptr++;
    }
    printf("%d\n",pop_count);
    return 0;
}

Measured memory_bytes: 4896
n=int(input());f,p=[],[];ans=""
for _ in range(n):f.append(list(map(int,input().split())))
for _ in range(n):p.append(list(map(int,input().split())))
for i in range(1,2**10):
  s=bin(i)[2:].zfill(10);a=0
  for j in range(n):
    m=0
    for h in range(10):
      if s[h]=="1":m+=f[j][h]
    a+=p[j][m]
  ans=(a if ans==""else max(ans,a))
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        int sumxor = array[0];
        for (int i = 1; i < n; i++) {
            sumxor ^= array[i];
        }
        for (int i = 0; i < n; i++) {
            System.out.print(sumxor^array[i]);
            if (i == n - 1) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
        }
        
    }
}


Measured memory_bytes: 61408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    ll mn = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a == mn + 1) {
            mn++;
            continue;
        }
        ans += (a - 1) / (mn + 1);
        if (mn == 0) {
            mn++;
        }
        debug(mn, ans);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int N;

int main(){
  cin >> N;
  map<char,int> m;
  m['f'] = 0;
  
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    
    if(tmp >= 1 && tmp < 400)m['g']++;
    else if(tmp >= 400 && tmp < 800)m['n']++;
    else if(tmp >= 800 && tmp < 1200)m['e']++;
    else if(tmp >= 1200 && tmp < 1600)m['a']++;
    else if(tmp >= 1600 && tmp < 2000)m['b']++;
    else if(tmp >= 2000 && tmp < 2400)m['y']++;
    else if(tmp >= 2400 && tmp < 2800)m['o']++;
    else if(tmp >= 2800 && tmp < 3200)m['r']++;
    else if(tmp >= 3200)m['f']++;
  }
  
  int fixed = 0;
  int free = 0;
  
  for(auto iter = m.begin(); iter != m.end(); iter++){   
    if(iter->first != 'f' && iter->second > 0) fixed++;
    else if(iter->first == 'f') free = iter->second;
  }
  int minc, maxc;
  minc = max(1,fixed);
  maxc = fixed + free;
  cout << minc << " " << maxc;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.readline


def readln():
    return list(map(int, read().split()))


N, M = readln()
AB = [readln() for _ in range(M)]
A = [ab[0]-1 for ab in AB[::-1]]
B = [ab[1]-1 for ab in AB[::-1]]


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def concat(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True


ans = [N * (N - 1) // 2]
uni = UnionFind(N)
for a, b in zip(A, B):
    if uni.root(a) == uni.root(b):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uni.size(a) * uni.size(b))
        uni.concat(a, b)

for a in ans[-2::-1]:
    print(a)


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

typedef long long ll;
const int INF = 1000000000;
string s;
int n;
map<string, int> hm;

typedef string::const_iterator State;
class err{};
class Parsing
{
public:
  static inline ll solve(string s)
  {
    State begin = s.begin();
    return Molecule(begin);
  }

  static void consume(State& begin, char e)
  {
    if(*begin == e){
      begin++;
    }
    else{
      cerr << "Exp : " << e << ", but got : " << *begin << endl;
      cerr << "Rest : ";
      while(*begin){
        cerr << *begin++;
      }
      cerr << endl;
      throw err();
    }
  }

  static ll Molecule(State& begin)
  {
    ll sum = 0LL;
    while(true){
      ll ret = 0LL;
      ll num = 0LL;
      if(*begin >= 'A' && *begin <= 'Z'){
        ret = Atom(begin);
        if(ret < 0) return -INF;
        num = Number(begin);
      }
      else if(*begin == '('){
        begin++;
        //        consume(begin, '(');
        ret = Molecule(begin);
        begin++;
        num = Number(begin);
        if(ret < 0) return -INF;
        //        consume(begin, ')');
      }
      else{
        break;
      }
      sum += ret * num;
    }
    return sum;
  }

  static ll Number(State& begin)
  {
    ll num = 0LL;
    while(isdigit(*begin)){
      num *= 10;
      num += (*begin++) - '0';
    }
    if(num == 0LL) num = 1LL;
    return num;
  }

  static ll Atom(State& begin)
  {
    string s = "";
    s += *begin++;
    if(*begin >= 'a' && *begin <= 'z'){
      s += *begin++;
    }
    if(hm[s] == 0) return -INF;
    return hm[s];
  }
};

int main()
{
  while(cin >> s, s != "END_OF_FIRST_PART"){
    cin >> n;
    hm[s] = n;
  }

  while(cin >> s, s != "0"){
    ll res = Parsing::solve(s);
    if(res > 0) cout << res << endl;
    else cout << "UNKNOWN" << endl;
  }

  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

u64 H, W;
char **S;

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

    cin >> H >> W;
    S = new char*[H];
    rep (i, H)
    {
        S[i] = new char[W];
    }

    vector< vector<s64> > L(H, vector<s64>(W, 0));
    vector< vector<s64> > R(H, vector<s64>(W, 0));
    vector< vector<s64> > U(H, vector<s64>(W, 0));
    vector< vector<s64> > D(H, vector<s64>(W, 0));

    rep (i, H)
    {
        cin >> S[i];
    }

    // L, U
    rep (h, H)
    {
        rep (w, W)
        {
            if (S[h][w] == '#')
            {
                L[h][w] = 0;
                U[h][w] = 0;
            }
            else
            {
                L[h][w] = w > 0 ? L[h][w - 1] + 1 : 1;
                U[h][w] = h > 0 ? U[h - 1][w] + 1 : 1;
            }
        }
    }

    // R, D
    for (int h = H - 1; h >= 0; --h)
    {
        for (int w = W - 1; w >= 0; --w)
        {
            if (S[h][w] == '#')
            {
                R[h][w] = 0;
                D[h][w] = 0;
            }
            else
            {
                R[h][w] = w < W - 1 ? R[h][w + 1] + 1 : 1;
                D[h][w] = h < H - 1 ? D[h + 1][w] + 1 : 1;
            }
        }
    }

    s64 ans = 0;
    rep (h, H)
    {
        rep (w, W)
        {
            ans = MAX(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
        }
    }

    cout << ans << "\n";

    return 0;
}



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

int main() {
  int n;
  cin >> n;
  string ans = "Three";
  rep(i,n) {
    char s;
    cin >> s;
    if (s == 'Y') {
      ans = "Four";
      break;
    }
  }
  cout << ans << endl;
}

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


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

  int n;
  cin >> n;
  map<int,int> s;
  rep(i,n-1){
    int a;
    cin >> a;
    --a;
    s[a]++;
  }
  rep(i,n){
    cout << s[i] << endl;
  }

  return 0;
    

}


Measured memory_bytes: 13016
/*
 * 文字列 t について、t の長さが 2 以上であり、かつ t の中の文字のうち過半数が同じ文字であるとき、t をアンバランスであると呼ぶことにします。
 * 例えば、voodoo や melee はアンバランスであり、noon や a はアンバランスではありません。
 * 
 * 小文字のアルファベットからなる文字列 s が与えられます。s にアンバランスな (連続する) 部分文字列が存在するか判定してください。
 * 存在する場合は、s の中でそのような部分文字列が存在する位置を一つ示してください。
 */

import java.util.*;
	public class Main{
		public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            // 入力
            String s = sc.next();
            int n = String.valueOf(s).length();

            for(int i=0; i<n-2; i++){
            	if(s.substring(i, i+1).equals(s.substring(i+1,i+2))){
            		System.out.println((i+1) + " " + (i+2));
            		sc.close();
            		return;
            	}else if(s.substring(i, i+1).equals(s.substring(i+2,i+3))){
            		System.out.println((i+1) + " " + (i+3));
            		sc.close();
            		return;
            	}
            }
            if(s.substring(n-2, n-1).equals(s.substring(n-1,n))){
        		System.out.println((n-1) + " " + n);
        		sc.close();
        		return;
        	}
            
            // 出力
            System.out.println("-1 -1");

            sc.close();
        }
    }
	

Measured memory_bytes: 40036
#include <bits/stdc++.h>
#define long long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

const int N= 510;
int m,n;
char a[N][N];
void input()
{
    cin>>m>>n;
    up(i,1,m)
     up(j,1,n)
      cin>>a[i][j];
}

void solve()
{
    up(i,1,m)
    {
    	up(j,1,n)
    	 if (a[i][j]=='#') cout<<'#';
    	 else if (j==1 or (i%2==1 and j!= n) ) cout<<'#';
    	 else cout<<'.';
    	cout<<endl;
    }
    cout<<endl;

    up(i,1,m)
    {
    	up(j,1,n)
    	 if (a[i][j]=='#') cout<<'#';
    	 else if ( j==n or (i%2==0 and j!= 1) ) cout<<'#';
    	 else cout<<'.';
    	cout<<endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
	#endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;

int ans(int n) {
	int x = to_string(n).size();
	int m = pow(10, x - 1);
	if (x == 1)return n;
	else if (x % 2) {
		return n - m + 1 + ans(m - 1);
	}
	else return ans(m - 1);
}

signed main() {
	int n;
	cin >> n;
	cout << ans(n) << endl;
}

Measured memory_bytes: 256
n=int(input())
vlis=sorted(list(map(int,input().split())))
while len(vlis)>=2:
	a,b=vlis[0],vlis[1]
	vlis.pop(0)
	vlis.pop(0)
	vlis.insert(0,(a+b)/2)
print(vlis[0])
	

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

const int kMaxN = 1001;
const int kD[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int n, m, x, y, dx, dy, t = 1, h = 1;
int s[kMaxN][kMaxN];

struct Queue {
  int x, y;
} q[kMaxN * kMaxN];

void Check(int nx, int ny, int v) {
  if (nx < 1 || nx > n || ny < 1 || ny > m || s[nx][ny] != -1) {
    return ;
  }
  s[nx][ny] = v;
  q[t++] = {nx, ny};
}

int main() {
  cin >> n >> m >> x >> y >> dx >> dy;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      s[i][j] = c == '#' ? -2 : -1;
    }
  }
  Check(x, y, 0);
  for (int t_; h < t; ) {
    for (int i = h; i < t; i++) {
      for (int d = 0; d < 4; d++) {
        Check(q[i].x + kD[d][0], q[i].y + kD[d][1], s[q[h].x][q[h].y]);
      }
    }
    for (t_ = t; h < t_; h++) {
      for (int d1 = -2; d1 <= 2; d1++) {
        for (int d2 = -2; d2 <= 2; d2++) {
          Check(q[h].x + d1, q[h].y + d2, s[q[h].x][q[h].y] + 1);
        }
      }
    }
  }
  cout << s[dx][dy];
  return 0;
}

Measured memory_bytes: 11384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String o = in.string();
            String e = in.string();
            for (int i = 0; i < o.length(); i++) {
                out.print(o.charAt(i));
                if (i < e.length()) {
                    out.print(e.charAt(i));
                }
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 22996