akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>


using namespace std;
typedef long long ll;
//using ll=long long;
using vll=vector<ll>;


ll nCr(int n, int r)
{
	ll ret=1;

	if(r*2>n) r=n-r;

	for(int i=0;i<r;i++)
	{
		ret*=(n-i);
		ret/=(i+1);
	}
	return ret;
}


int main(void)
{
	int n, a, b;

	while(scanf("%d%d%d", &n, &a, &b)==3)
	{
		vll v(n);
		for(int i=0;i<n;i++) scanf("%lld", &v[i]);
		sort(v.begin(), v.end(), greater<ll>());

		if(v[0]!=v[a-1]) b=a;

		ll sum=0;
		for(int i=0;i<a;i++) sum+=v[i];

		int l, r;
		for(r=a-1;r<n;r++)
		{
			if(v[r]<v[a-1]) break;
		}
		for(l=a;l>0;l--)
		{
			if(v[l-1]>v[a-1]) break;
		}

		ll ans=0;
		for(int i=a-1;i<min(r,b);i++)
		{
			ans+=nCr(r-l, i-l+1);
		}

		printf("%.8f\n", (double)sum/a);
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 305
using namespace std;
int n, m, ans=1e9, mx, ms, a[N][N], v[N], c[N];
int main() {
	int i, j, k, t;
	scanf("%d%d", &n, &m);
	for(i=0; i<n; i++) for(j=0; j<m; j++) scanf("%d", &a[i][j]);
	for(k=0; k<m; k++) {
		for(j=1; j<=m; j++) c[j] = 0;
		for(i=mx=0; i<n; i++) for(j=0; j<m; j++) {
			t = a[i][j];
			if(!v[t]) {
				c[t]++;
				if(c[t] > mx) mx = c[t], ms = t;
				break;
			}
		}
		ans = min(ans, mx);
		v[ms] = 1;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 640
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    array = sc.intarr_ver(n)
    count = 0
    for i in array:
        count += natural_num(i)
    print(count)


def natural_num(n):
    for j in range(2, int(math.sqrt(n))+1):
        if n % j == 0:
            return 0
    return 1


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


main()



Measured memory_bytes: 6092
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
  ll N; cin >> N;
  ll cnt = 0, mar = 0;
  N--;
  while(N >= 0){
    cnt++;
    if(N < modpow(26, cnt , (ll)1e18)){
      mar = N;
      break;
    }
    else{
      N -= modpow(26 , cnt , (ll)1e18);
    }
  }
  // cout << cnt << " " << mar << endl;

  string s;
  ll now = cnt - 1;
  rep(i,cnt){
    ll loop = mar / modpow(26, now , (ll)1e18 );
    mar -= loop * modpow(26, now , (ll) 1e18);
    now--;
    s.pb('a' + loop);
  }
  cout << s << endl;
}


Measured memory_bytes: 3628
g,p,w,l=0,0,0,0
for s in input():
  if s=="g":
    if g>p:
      p+=1
      w+=1
    else:
      g+=1
  else:
    if g>p:
      p+=1
    else:
      g+=1
      l+=1

print(w-l)

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

int main() {
  int N,Q,i,c=0,l,r;
  string S;
  cin >> N >> Q >> S;
  set<int> AC;
  vector<int> cn(N);
  
  for(i=0; i<N-1; i++)
    if(S.at(i)=='A' && S.at(i+1)=='C')
      AC.insert(i);
    else if(S.at(i+1)!='A')
      i++;
  
  for(i=0; i<N-1; i++) {
    cn.at(i) = c;
    if(AC.count(i))
      c++;
  }
  cn.at(N-1) = c;
  
  for(i=0; i<Q; i++) {
    cin >> l >> r;
    if(l>0)
      cout << cn.at(r-1)-cn.at(l-1) << endl;
    else
      cout << cn.at(r-1) << endl;
  }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
 
using namespace std;
 
struct State{
  string s;
  int d;
};
 
int N,size[10];
string a[10],b[10],src,dst,str;
 
int solve(){
  queue<State> Q;
  Q.push((State){src,0});
  set<string> visited;
  visited.insert(src);
 
  while(!Q.empty()){
    State now = Q.front(); Q.pop();
    string s = now.s;
    if(s == dst) return now.d;
     
    for(int i = 0 ; i < N ; i++){
      string next;
      for(int j = 0 ; j < (int)s.size() ; j++){
        string sub = s.substr(j,size[i]);
        if(sub == a[i]){
          next += b[i];
          j += size[i]-1;
        }else{
          next += s[j];
        }
      }
      if(next.size() > dst.size()) continue;
      if(!visited.count(next)){
        visited.insert(next);
        Q.push((State){next,now.d+1});
      }
    }
  }
  return -1;
}
 
int main(){
  while(cin >> N, N){
    for(int i = 0 ; i < N ; i++){
      cin >> a[i] >> b[i];
      size[i] = a[i].size();
    }
    cin >> src >> dst;
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1452
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int n,x,ans = 0;
    cin >> n >> x;
    vector<int>v(n);
    ans = n;
    
    for(int i = 0;i < n;i++)
        cin >> v[i];
    
    sort(v.begin(),v.end(),greater<int>());

    x -= accumulate(v.begin(),v.end(),0);

    ans += x/(*min_element(v.begin(),v.end()));

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {

	int a,b,c;
	cin >> a >> b >>c;

	if (b < c) { swap(b, c); }
	if (a < b) { swap(a, b); }
	if (b < c) { swap(b, c); }

	int counter = 0;
	while (a - c > 1) {
		counter++;
			c += 2;
	}
	while (a - b > 1) {
		counter++;
			b += 2;
	}
	if (b < c) { swap(b, c); }
	if (a < b) { swap(a, b); }
	if (b < c) { swap(b, c); }

	if (a == b && b > c) { counter += 2; }
	if (a != b && b == c) { counter++; }

	cout << counter << endl;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(b<a){
    for (int i = 0; i < a; i++) {
    cout << b;
    }
    }
    else{
    for (int i = 0; i < b; i++) {
    cout << a;
    } 
    }
}

Measured memory_bytes: 3580
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count


from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    a=list(map(int,readline().split()))
    uf=UnionFind(n+1)
    for i in range(m):
        x,y=map(int,readline().split())
        uf.union(x,y)

    ans=0
    for i in range(n):
        if uf.are_same(a[i],i+1):
            ans+=1
    
    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 13876
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

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



    int N;
    double T, A;
    cin >> N ;
    cin >> T >> A;
    double H[N+1];
    for(int i=1; i<=N; i++) {
        cin >> H[i];
    }
    double minimum =  100000000.0;
    int num = 0;
    for(int i=1; i<=N; i++){
        if(minimum > abs(T - 0.006 * H[i] - A)){
            num = i;
            minimum = abs(T - 0.006 * H[i] - A);
        }
    }

    cout << num << '\n';
}


Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll a;
    cin >> a;
    cout << a+ a*a+ a*a*a << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	double n, t, a;
	cin >> n >> t >> a;

	vector<double> h(n);
	for (auto &v : h) {
		cin >> v;
	}

	vector<double> kions(n);
	for (int i = 0; i < n; i++) {
		kions[i] = t - h[i] * 0.006;
	}

	int ans = 0;
	double diff = 1e9;
	for (int i = 0; i < (int)n; i++) {
		double score = fabs(a - kions[i]);
		if (diff > score) {
			diff = score;
			ans = i;
		}
	}
	ans++;

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))

dp = []
for i in range(h):
    dp.append([0 for j in range(w)])

def need_or_not(a,b): # aからbに移るときに操作が必要なら1,必要ないなら0
    if a == "." and b == "#":
        return 1
    return 0

for i in range(h):
    for j in range(w):
        if i == 0:
            if j != 0:
                dp[i][j] = dp[i][j-1] + need_or_not(s[i][j-1], s[i][j])
            else:
                if s[0][0] == "#":
                    dp[0][0] = 1
        else:
            if j!= 0:
                dp[i][j] = min(dp[i-1][j] + need_or_not(s[i-1][j], s[i][j]), dp[i][j-1] + need_or_not(s[i][j-1], s[i][j]))
            else:
                dp[i][j] = dp[i-1][j] + need_or_not(s[i-1][j], s[i][j])

print(dp[h-1][w-1])


Measured memory_bytes: 44272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A =sc.next();
		String B =sc.next();
		String C =sc.next();
		System.out.print((char)(A.charAt(0)+'A'-'a'));
		System.out.print((char)(B.charAt(0)+'A'-'a'));
		System.out.print((char)(C.charAt(0)+'A'-'a'));
	}
}

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

int main(){
  int n;
  cin >> n;
  cout << n << ":";
  for(int i=2;i*i<=n;i++){
    while(n%i==0) {
      cout << " " << i;
      n/=i;
    }
  }
  if(n!=1)
    cout << " " << n;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

const int MAX_N = 100010; // 要素数の最大

int par[MAX_N]; // 親
int siz[MAX_N]; // 木のサイズ

// n要素で初期化
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        siz[i] = 1;
    }
}

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

// xとyの属する集合を併合
bool unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return false;

    if (siz[x] < siz[y])
        swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
}

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

// xが属する木の大きさを返す
ll size(int x)
{
    return siz[find(x)];
}

int main()
{
    int n, m;
    cin >> n >> m;
    init(n);
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        unite(a, b);
    }
    set<int> cnt;
    for (int i = 0; i < n; ++i)
    {
        cnt.insert(find(i));
    }
    cout << cnt.size() - 1 << endl;
    return 0;
}


Measured memory_bytes: 8260
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    if k == 1:
        return 0

    return n - k


print(main())



Measured memory_bytes: 5076
#include<stdio.h>

int koukan(double *p, double *q);
double A;

int main(void)
{
  double a[50], M=0;
  int n, i, j;

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

//配列を小さい順に並び変え。大きいほうから順に確定させていってる。
  for (i = 0; i < n-1; i++) {
    for (j = 0; j < n-1-i; j++) {
      if (a[j] > a[j+1]) {
        koukan(&a[j], &a[j+1]);
      }
    }
  }

  M = a[0];
  for (i = 0; i < n-1; i++) {
    M = (M + a[i+1])/2 ;
  }

  printf("%lf\n", M);

  return 0;
}

//a[j]とa[j+1]を交換
int koukan(double *p, double *q){
  A = *p;
  *p = *q;
  *q = A;
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
struct Point{
  ll x,y,z;
  Point(){};
  Point(ll x,ll y,ll z):x(x),y(y),z(z){}
  Point operator+(Point p){
    return Point(x+p.x,y+p.y,z+p.z);
  }
  Point operator-(Point p){
    return Point(x-p.x,y-p.y,z-p.z);
  }
};
ll dot(Point a,Point b){
  return (a.x*b.x+a.y*b.y+a.z*b.z);
}
struct ball{
  Point p;
  ll r;
  ull l;
};
typedef Point Vector;
ull check(ball ba,Point x,Point y){
  ull z=0;
  Vector v=y-x,c=ba.p-x;
  if(dot(v,c)<=0){
    if(dot(c,c)<=ba.r*ba.r) z=ba.l;
  }else{
    if(dot(v,c)>dot(v,v)){
      if(dot(ba.p-y,ba.p-y)<=ba.r*ba.r) z=ba.l;
    }else{
      if(dot(c,c)*dot(v,v)-(dot(v,c)*dot(v,c))<=ba.r*ba.r*dot(v,v))  z=ba.l;
    }
  }
  return z;
}
int main(){
  ll n,q;
  cin >> n >> q;
  ball bs[51];
  int i,j,k;
  
  ll x,y,z;
  for(i=0;i<n;i++){
    cin >>  x >>  y >>  z >> bs[i].r >> bs[i].l;
    bs[i].p=Point(x,y,z);
  }
  for(i=0;i<q;i++){
    Point p,b;
    cin >> x >> y >> z;
    p=Point(x,y,z);
    cin >> x >> y >> z;
    b=Point(x,y,z);
    ull o=0;
    for(j=0;j<n;j++){
      o+=check(bs[j],p,b);
    }
    cout << o << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>
#include<math.h>
#define ll long long
int main(){
  ll n, x[102], i, min = 10000000, p;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&x[i]);
  }
  for(p=1;p<=100;p++){
    ll sum = 0;
    for(i=0;i<n;i++){
      sum+=pow(x[i]-p,2);
    }
    min = min>sum?sum:min;
  }
  printf("%lld\n", min);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int n, A[50];
int solve(int i, int m){
if(m == 0) return 1;
if(i >= n) return 0;
int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
return res;
}
int main(){
int q, M, i;
scanf("%d", &n);
for(i = 0; i < n; i++) scanf("%d", &A[i]);
scanf("%d", &q);
for(i = 0; i < q; i++){
scanf("%d", &M);
if(solve(0, M)) printf("yes\n");
else printf("no\n");
}
return 0;
}


Measured memory_bytes: 2572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int T[2][1<<18];
const int ADD = 1<<17;

void update(int c, int x, int v) {
	x += ADD; T[c][x] = v; x >>= 1;
	while(x) {
		T[c][x] = min(T[c][x<<1], T[c][x<<1|1]);
		x >>= 1;
	}
}

int read(int c, int l, int r) {
	int res = 1e9;
	l += ADD, r += ADD;
	while(l <= r) {
		if(l & 1) res = min(res, T[c][l++]);
		if(!(r & 1)) res = min(res, T[c][r--]);
		l >>= 1, r >>= 1;
	}
	return res;
}

int n, A[200020];
int rev[200020];

int read_odd(int l, int r) {
	if(l % 2 == 0) ++l;
	if(r % 2 == 0) --r;
	return read(1, (l+1) / 2, (r+1) / 2);
}

int read_even(int l,int r) {
	if(l % 2) ++l;
	if(r % 2) --r;
	return read(0, (l+1) / 2, (r+1) / 2);
}

pii get(int l, int r) {
	if(l % 2 == 0) {
		int t = read_odd(l+1, r-1);
		int v = rev[t];
		int u = read_even(v+1, r-1);
		return pii(t, u);
	}
	else {
		int t = read_even(l+1, r-1);
		int v = rev[t];
		int u = read_odd(v+1, r-1);
		return pii(t, u);
	}
}

void solve(){
	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", A+i), rev[A[i]] = i;
	for(int i=1;i<=n;i++) update(i&1, (i+1)/2, A[i]);
	priority_queue <pair<pii, pii>, vector <pair<pii, pii> >, greater<pair<pii, pii> > > T;
	T.push(make_pair(get(0, n+1), pii(0, n+1)));
	rep(i, n/2) {
		auto X = T.top(); T.pop();
		pii a = X.Fi, b = X.Se;
		printf("%d %d ", a.Fi, a.Se);
		int c = rev[a.Fi], d = rev[a.Se];
		if(b.Fi + 1 < c) T.push(make_pair(get(b.Fi, c), pii(b.Fi, c)));
		if(c+1 < d) T.push(make_pair(get(c, d), pii(c, d)));
		if(d+1 < b.Se) T.push(make_pair(get(d, b.Se), pii(d, b.Se)));
	}
}

int main(){
	int T = 1; //scanf("%d", &T);
	while(T--) {
		solve();
	}
	
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    //vi c(n);
    int ta0,a0;
    ta0 = a/d;
    if(a%d){
        ta0++;
    }
    a0 = c/b;
    if(c%b){
        a0++;
    }
    //cout << ta0 << a0 << endl;
    if(ta0 < a0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    //cout << n << endl;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
h = [0] + list(map(int, input().split()))

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

for i in reversed(range(1, N - 1)):
    dp[i] = min(dp[i + 1] + abs(h[i + 1] - h[i]), \
                dp[i + 2] + abs(h[i + 2] - h[i]))
print(dp[1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
int n;
int a[200005];
main(){
	while(~getI(n)){
		F(i,0,n) getI(a[i]);
		int sum=a[0];
		F(i,1,n) sum^=a[i];
		F(i,0,n) printf("%lld ",a[i]^sum);
	}
}


Measured memory_bytes: 5368
from collections import deque

n, m = list(map(int, input().split(' ')))
graph = {}

for i in range(m):
    a, b = list(map(int, input().split(' ')))

    if not a in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)

    if not b in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)

ans = [-1 for i in range(n)]

que = deque()

for c in graph[1]:
    ans[c-1] = 1
    que.appendleft(c)

while len(que) != 0:
    target = que.pop()
    candidates = graph[target]

    for c in candidates:
        if c != 1 and ans[c - 1] == -1:
            ans[c - 1] = target
            que.appendleft(c)

ans = ans[1:]

if -1 in ans:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int a, b;
  cin >> a >> b;
  int cnt = 1;
  int ans = 0;
  while (cnt < b) {
    cnt += a - 1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n;
	string s;
	while (cin >> n, n) {
		vector<int> w(n);
		for (int i = 0; i < n; i++) {
			cin >> s;
			w[i] = s.size();
		}
		int res = -1;
		for (int i = 0; i < n; i++) {
			bool tmp[] = { false, false, false, false };
			int sum = 0;
			for (int j = i;j < n; j++) {
				sum += w[j];
				if (sum == 5) {
					tmp[0] = true;
				}
				if (sum == 12) {
					if (tmp[0]) {
						tmp[1] = true;
					}
					else {
						break;
					}
				}
				if (sum == 17) {
					if (tmp[1]) {
						tmp[2] = true;
					}
					else {
						break;
					}
				}
				if (sum == 24) {
					if (tmp[2]) {
						tmp[3] = true;
					}
					else {
						break;
					}
				}
				if (sum == 31) {
					if (tmp[3]) {
						res = i + 1;
						break;
					}
					else {
						break;
					}
				}
			}
			if (res != -1)
				break;
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;

const int MOD=1e9+7;

//const int MOD=998244353;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s1="ATCG",s2;
    
    cin>>s2;
    
    int ans=0;
    for(int i=0; i<s2.size(); i++){
        if(s1.find(s2[i])==-1) continue;
        int pos=i;
        while(pos<s2.size() && s1.find(s2[pos])!=-1){
            pos++;
        }
        ans=max(ans,pos-i);
    }
    cout<<ans;
    
}

Measured memory_bytes: 256
#B
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
cnt = 0

for i in range(N):
    cnt += B[A[i]-1]
    if i == 0:
        continue
    elif A[i] == A[i-1]+1:
        cnt += C[A[i]-2]
print(cnt)

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

int main() {
  int N;
  cin >> N;
  vector<int> delicious(N);
  for(int i=0; i<N ; i++){
    cin >> delicious.at(i);
  }
  int Sum_delicious = 0;
  for (int i=0; i<N-1; i++){
    for (int k=i+1; k<=N-1; k++){
      Sum_delicious += delicious.at(i) * delicious.at(k);
    }
  }
  cout << Sum_delicious << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    int i=0;
    int N,M;
    cin >> N >> M;
    int ans = 0;
    ans = (N * (N-1))/2;
    ans = ans + (M * (M-1))/2;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
typedef long long ll;
#define F(i,L,R) for (ll i = L; i < R; i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(x) scanf("%lld",&x)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,d, cnt = 0;
  cin>>n>>d;
  d = d*d;
  F(i,0,n){
  	ll x,y;
  	cin>>x>>y;
  	ll val = x*x+y*y;
  	if(val<=d) cnt++;
  }
	cout<<cnt;
  
  return 0;
}

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


int main(){
  ll N,C;
  cin >> N >> C;
  vector<vector<ll>> D(C,vector<ll>(C,0));
  vector<vector<ll>> c(N,vector<ll>(N));
  for(ll i=0;i<C;++i){
    for(ll j=0;j<C;++j){
      cin >> D[i][j];      
    }
  }
  for(ll i=0;i<N;++i){
    for(ll j=0;j<N;++j){
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  ll grid[3][C];
  for(ll i=0;i<3;++i){
    for(ll j=0;j<C;++j){
      grid[i][j]=0;
    }
  }
  //modごとの個数数える
  for(ll i=0;i<N;++i){
    for(ll j=0;j<N;++j){
      if((i+j+2)%3==0) grid[0][c[i][j]]++;
      else if((i+j+2)%3==1) grid[1][c[i][j]]++;
      else if((i+j+2)%3==2) grid[2][c[i][j]]++;
    }
  }
  //色塗り全通り mod0,1,2をi,j,k
  ll ans=1e9;
  ll tmp=0;
  for(ll i=0;i<C;++i){
    for(ll j=0;j<C;++j){
      for(ll k=0;k<C;++k){
        if(i==j || j==k || i==k) continue;
        tmp =0;
        //mod0
        for(ll t=0;t<C;++t){
          tmp += grid[0][t]*D[t][i];
        }
        //mod1
        for(ll t=0;t<C;++t){
          tmp += grid[1][t]*D[t][j];
        }
        //mod2
        for(ll t=0;t<C;++t){
          tmp += grid[2][t]*D[t][k];
        }
        ans = min(ans,tmp);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2176
H,W=map(int, input().split())
S=[input() for i in range(H)]
s=[[0]*W for h in range(H)]
b=0
for h in range(H):
    for w in range(W):
        if S[h][w]=='#':
            s[h][w]=-1
            b+=1
q=[]
i=1
q.append((0,0))
s[0][0]=1
while (H-1,W-1) not in q:
    q2=[]
    i+=1
    for h,w in q:
        if h>0 and s[h-1][w]==0:
            q2.append((h-1,w))
            s[h-1][w]=i
        if h<H-1 and s[h+1][w]==0:
            q2.append((h+1,w))
            s[h+1][w]=i
        if w>0 and s[h][w-1]==0:
            q2.append((h,w-1))
            s[h][w-1]=i
        if w<W-1 and s[h][w+1]==0:
            q2.append((h,w+1))
            s[h][w+1]=i
    q=q2
    if len(q)==0:
        break
if len(q)==0:
    print(-1)
else:
    print(H*W-i-b)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

double d(double a, double b){
    if(a > b){
        return a - b;
    } else {
        return b - a;
    }
}

int main(){
    int n, t;
    double a;
    cin >> n >> t >> a;
    int ans = 0;
    int h = 0;
    double diff = 100001;
    for(int i = 1; i <= n; i++){
        cin >> h;
        double tmp = t - h*0.006;
        double p = d(a, tmp);
        if(diff >= p){
            diff = p;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int N, M;
vector< int > g[100000];
bool used[100000];
deque< int > v, q;

void dfs(int idx)
{
  used[idx] = true;
  v.push_back(idx + 1);
  for(auto &to : g[idx]) {
    if(!used[to]) {
      dfs(to);
      break;
    }
  }
}

int main()
{
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  dfs(0);
  swap(v, q);
  dfs(0);
  reverse(begin(q), end(q));
  q.pop_back();

  cout << v.size() + q.size() << endl;

  for(auto &k : q) cout << k << " ";
  for(auto &k : v) cout << k << " ";
  cout << endl;

}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    int divBy4 = 0;
    int odd = 0;
    int even = 0;
    
    while (n--) {
        int x;
        cin >> x;
        
        if (x % 4 == 0) {
            divBy4++;
        } else if (x % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }
    
    if (divBy4 >= odd ||
        (divBy4 == odd - 1 && even == 0)) {
        cout << "Yes";        
    } else {
        cout << "No";
    }

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(a, n) sort(a, a+n)
#define VSORT(v) sort(v.begin(), v.end())

using namespace std;

int main()
{
    int n;

    cin >> n;

    int a[n];
    long sum[200000] = {0}, c[200000];
    long sumc = 0;

    REP(i, n) {
        cin >> a[i];
        sum[a[i]-1] += 1;
    }

    REP(i, 200000) {
        c[i] = long(sum[i] * (sum[i]-1) / 2);
        sumc += c[i];
    }

    long add , sub;

    REP(i, n) {
        add = long((sum[a[i]-1] - 1) * (sum[a[i]-1] - 2) / 2);
        sub = long(sum[a[i]-1] * (sum[a[i]-1] - 1) / 2);
        cout << long(sumc + add - sub) << endl;
    }

    return 0;
}

Measured memory_bytes: 4992
N = int(input())
a = list(map(int,input().split()))

data = [0]*(N+1)
for i in range(N): data[a[i]] += 1

all_c = 0
for i in range(1,N+1): all_c += data[i]*(data[i]-1)//2

for i in range(N):
    ans = all_c
    if data[a[i]] >= 2:
        ans -= data[a[i]]*(data[a[i]]-1)//2
        ans += (data[a[i]]-1)*(data[a[i]]-2)//2
    print(ans)

Measured memory_bytes: 26140
/*

    * * * *      *       *     * * *        * *      * * * *    * * * *
    *       *    *     *       *     *    *     *   *          *
    *       *    *   *         *     *   *       *  *          *
    * * * *      * *           * * *     *       *    * * *      * * *
    *      *     *   *         *     *   *       *          *          *
    *       *    *     *       *     *    *     *           *          *
    *        *   *       *     * * *        * *     * * * *    * * * *

*/

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               9000000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define ppb               pop_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vvl               vector<vl>
#define lb                lower_bound
#define ub                upper_bound
#define be()              begin()
#define en()              end()
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


void solve()
{
    string s;
    cin >> s;
    ll n = len(s);
    f(i, 0, n)
    if (s[i] == '?')
        s[i] = 'D';

    cout << s << endl;



}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  vector<int>B=A;
  sort(rng(B));
  map<int,int>m;
  for(int i=0;i<N;i++){
    m[B[i]]=i;
  }
  int ans=0;
  for(int i=0;i<N;i++){
    int d=abs(m[A[i]]-i);
    if(d%2)ans++;
  }
  cout<<ans/2<<endl;
  return 0;
}


Measured memory_bytes: 5760
A, B = map(int, input().split())
# ans = 0
# for i in range(40):
#     # 含まれる1の数を数える
#     tmp = (B-A) // 2**(i+1) * 2**i
#     p = A%(2**(i+1))
#     q = (B-A)%(2**(i+1))
#     # p から p+qの中で余りが2**i ~ 2**(i+1)-1になる個数を求める
#     tmp += max(min(p+q,2**(i+1)-1) - max(p,2**i)+1,0)
#     tmp += max(min(p+q,2**(i+1)-1 + 2**(i+1)) - max(p,2**i + 2**(i+1))+1,0)
#     ans += (tmp%2) * 2**i
# print(ans)

def f(N):
    if N % 2 == 1:
        return ((N+1)//2)%2
    else:
        return ((N//2)%2)^N

print(f(A-1)^f(B))

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100000000000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll N,K;
vector<ll> A;
bool dp[100010];


int main(){
   cin >> N >> K;
   rep(i,N){
       ll a;cin >> a;
       A.push_back(a);
   }
   sort(ALL(A));
   fill(dp,dp+100010,0);
   FOR(i,1,K+1){
       FOR(j,0,N){
           if(i - A[j] >= 0 && !dp[i-A[j]]){
               dp[i] = 1;
               break;
           }
       }
   }
   if(dp[K]){
       cout << "First" << endl;
   }else{
       cout << "Second" << endl;
   }
}



Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+111;
#define ll long long
int n, a[maxn], vis[maxn];
ll k;
vector<int> q;

int main(){
    scanf("%d %lld", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int u = 1;
    while (!vis[u]){
        vis[u] = 1;
        q.push_back(u);
        u = a[u];
    }
    int p = 0;
    for (;p<q.size(); p++) if (q[p]==u) break;
    if (k <= p){
        u = 1;
        while (k--) u = a[u];
        printf("%d\n", u);
    }
    else {
        int m = (k-p)%(q.size()-p);
        u = q[p];
        while (m--){
            u = a[u];
        }
        printf("%d\n", u);
    }
}



Measured memory_bytes: 5864
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

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

int main(){
  ll N, M;
  cin >> N >> M;
  ll X[100005];
  rep(i,M) cin >> X[i];
  
  sort(X, X+M);
  
  ll dif[100005];
  rep(i,M-1) dif[i] = X[i+1]-X[i];
  
  sort(dif, dif+M-1);

  ll ans = 0;
  
  if(N>=M) cout << 0 << endl;
  else{
    rep(i,M-N) ans += dif[i];
    cout << ans << endl;
  }

}

Measured memory_bytes: 1792
#include<stdio.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b

int main() {
	int n;
	while (S(d, n), n) {
		getchar();
		char s[200] = "",
			 t;
		S(s, s);
		int a[100], b[100],i;
		for (i = 0; i < n;fscanf(stdin, "%d%d", a + i, b + i),a[i]--, b[i]--,i++);
		for (i = n - 1; i>=0;i--) {
			int c = b[i] - a[i];
			s[a[i]] = ((s[a[i]] - 'a')+c)%26+'a';
			s[b[i]] = ((s[b[i]] - 'a')+c)%26+'a';
			t = s[a[i]], s[a[i]] = s[b[i]], s[b[i]] = t;
		}
		P(s, s);
	}
	return 0;
}

Measured memory_bytes: 608
// INCLUDE LIST
#include <cstdio>
#include <bitset>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
  string a[10];
  int n;
  int ret = 0;
  
  cin >> n;
  for (int i = 0; i < 3; i++) cin >> a[i];
  
  for (int i = 0; i < n; i++) {
    int alph[100];
    memset(alph, 0, sizeof alph);
    
    for (int j = 0; j < 3; j++) {
      alph[a[j][i] - 'a']++;
    }
    
    int maks = 0;
    for (int j = 'a'; j <= 'z'; j++) {
      maks = max(maks, alph[j - 'a']);
    }
    
    ret += 3 - maks;
  }
  
  cout << ret << endl;
  return 0;
}



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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 22;

int dp[maxn][1<<maxn];
const int mod = 1e9 + 7;

void add(int &a, int b){
	a += b;
	if(a > mod){a -= mod;}
}

int main(){
	int n,i,j;
	scanf("%d",&n);
	int a[maxn][maxn];
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<n;i++){
		dp[i][0] = 1;	
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(a[i][j] == 0){continue;}
			for(int k=0;k<(1<<n);k++){
				if(!(k & (1<<j))){
					add(dp[i+1][k | (1<<j)], dp[i][k]);
				}
			}
		}
	}

	printf("%d\n",dp[n][(1<<(n))-1]);
	return 0;
};

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

int main() {
    vector<int> a(3);
    
    cin >> a[0] >> a[1] >> a[2];
    
    sort(a.begin(), a.end());
    
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    
    return 0;
}


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

using namespace std;

int main(){
  int h,w;
  cin >> h >> w;
  char mat[h][w];
  int num[h][w];

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

  bool flag=true;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(mat[i][j]=='#'){
        if(mat[i+1][j]=='#' || mat[i][j+1]=='#' || mat[i-1][j]=='#' || mat[i][j-1]=='#'){
          flag=true&&flag;
        }else{
          flag=false&&flag;
        }
      }
    }
  }

  if(flag == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<algorithm>
#include<cstdio>
#define N 100005
using namespace std;
long long int a[30],b[30];
long long int x,y;
int la=0,lb=0;
int main(){
scanf("%lld%lld",&x,&y);
a[++la]=1;
b[++lb]=1;
for(long long int i=2;i*i<=x;i++){
if(x%i==0){a[++la]=i;}
while(x%i==0){x/=i;}
}
if(x>1)a[++la]=x;
for(long long int i=2;i*i<=y;i++){
if(y%i==0){b[++lb]=i;}
while(y%i==0){y/=i;}
}
if(y>1)b[++lb]=y;
int z=1;
int ans=0;
for(int i=1;i<=la;i++){
while(b[z]<a[i]&&z<lb)z++;
if(b[z]==a[i])ans++;
}
printf("%d",ans);

}

Measured memory_bytes: 1720
// Problem : C - Three Circuits
// Contest : AtCoder - AtCoder Grand Contest 032
// URL : https://atcoder.jp/contests/agc032/tasks/agc032_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <vector>
using namespace std;
vector<int> e[100005];
int p,q,vis[100005];
void dfs(int u)
{
 vis[u]=1;
 for(auto v:e[u])
  if(vis[v]==-1)
  {
   if(p)q=v;
   else p=v;
  }
  else if(!vis[v])dfs(v);
}
int main()
{
 ios::sync_with_stdio(false);
 int n,m;
 cin>>n>>m;
 for(int i=1;i<=m;i++)
 {
  int u,v;
  cin>>u>>v;
  e[u].push_back(v);
  e[v].push_back(u);
 }
 int maxd=0,cnt=0;
 for(int i=1;i<=n;i++)
 {
  int t=e[i].size();
  if(t%2)
  {
   cout<<"No"<<endl;
   return 0;
  }
  if(t>maxd)
   maxd=t,cnt=1;
  else if(t==maxd)cnt++;
 }
 if(maxd>=6)
  cout<<"Yes"<<endl;
 else if(maxd==4)
 {
  if(cnt>=3)
   cout<<"Yes"<<endl;
  else if(cnt==1)
   cout<<"No"<<endl;
  else
  {
   for(int i=1;i<=n;i++)
    if(e[i].size()==4)vis[i]=-1;
   for(int i=1;i<=n;i++)
    if(!vis[i])
    {
     p=q=0;
     dfs(i);
     if(p==q)
     {
      cout<<"Yes"<<endl;
      return 0;
     }
    }
   cout<<"No"<<endl;
  }
 }
 else cout<<"No"<<endl;
 return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO 1e18
#define EPS 1e-6
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=100005;

int main()
{
    IO;
    int n;
    cin >> n;
    int sum=0;
    int Max=0;
    while(n--){
        int x;
        cin >> x;
        sum+=x;
        Max=max(Max,x);
    }
    sum-=Max;
    if(Max<sum)puts("Yes");
    else puts("No");
    re 0;
}

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

int main(){
	double a, b, x;
	cin >> a >> b >> x;
	x /= a;
	double ab = a*b;
	double angle=0.0;
	double e;
	if(ab/2>=x){
		e=2*x/b;
		angle = atan(b/e) * 360 / 2/M_PI;
	}else{
		e=(ab-x)*2/a;
		angle = atan(e/a) * 360 / 2/M_PI;
	}
	printf("%.7lf", angle);

	return 0;
}

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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

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

    int n;cin>>n;
    tuple<int, int, int>hp[100005];
    for(int i = 0;i < n;i++){
        int a, b, c;cin>>a>>b>>c;
        hp[i] = mt(a, b, c);
    }

    int dp[100005][3] = {};
    dp[0][0] = get<0>(hp[0]);
    dp[0][1] = get<1>(hp[0]);
    dp[0][2] = get<2>(hp[0]);
    for(int i = 1;i < n;i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+get<0>(hp[i]);
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])+get<1>(hp[i]);
        dp[i][2] = max(dp[i-1][1], dp[i-1][0])+get<2>(hp[i]);
    }

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;

    return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n, m,ans=0;
	int f=0;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	for(int i=0;i<m;i++){
		a[i]=0,b[i]=0;
	}
	for(int i=0;i<m;i++){
		cin>>a.at(i);
		if(a.at(i)==0){
			f=1;
		}
	}
	sort(a.begin(),a.end());
	for(int i=0;i<a.size()-1;i++){
		if(abs(a.at(i+1)-a.at(i))>0 && a.at(i)!=0 ){
			if(f==0){
				b.at(i)=abs(a.at(i+1)-a.at(i));
			}
		}
			b.at(i)=abs(a.at(i+1)-a.at(i));
	}
	sort(b.begin(),b.end(),greater<int>());
	for(int i=n-1;i<b.size();i++){
		ans+=b.at(i);
	}
		cout<<ans<<endl;
}


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

#define MAXN (int)(2 * 1e5 + 1)
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if (0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int, int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

long double eps = 1e-6;

long double a, b;

bool compare(long double a, long double b) {
  if(b-a <= eps) return true;
  return false;
}

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

  cin >> a >> b;

  for(int i=1;i<=1e5;i++){
    int aa = i*0.08, bb = i*0.1;
    if(aa == a and bb == b) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 384