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


using namespace std;

int main()
{
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;

	for (int i = 0; i < ((tx - sx)); ++i) {
		cout << "R" ;
	}

	for (int i = 0; i < ((ty - sy)); ++i) {
		cout << "U";
	}

	for (int i = 0; i < ((tx - sx)); ++i) {
		cout << "L";
	}

	for (int i = 0; i < ((ty - sy)); ++i) {
		cout << "D";
	}

	cout << "D";
	for (int i = 0; i < ((tx - sx)+1); ++i) {
		cout << "R";
	}
	for (int i = 0; i < ((ty - sy)+1); ++i) {
		cout << "U";
	}
	cout << "L";
	cout << "U";
	for (int i = 0; i < ((tx - sx) + 1); ++i) {
		cout << "L";
	}
	for (int i = 0; i < ((ty - sy) + 1); ++i) {
		cout << "D";
	}
	cout << "R";
	return 0;
}


Measured memory_bytes: 256
A = int(input())
if A >=1800:
    print(1)
elif A >= 1600:
    print(2)
elif A >= 1400:
    print(3)
elif A >= 1200:
    print(4)
elif A >= 1000:
    print(5)
elif A >= 800:
    print(6)
elif A >= 600:
    print(7)
elif A >= 400:
    print(8)

Measured memory_bytes: 9120
x = input()

if x == 'SUN':
  print(7)
elif x == 'MON':
  print(6)
elif x == 'TUE':
  print(5)
elif x == 'WED':
  print(4)
elif x == 'THU':
  print(3)
elif x == 'FRI':
  print(2)
else:
  print(1)

Measured memory_bytes: 2940
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[M];
		int[] d = new int[M];
		for(int i = 0;i < N;i ++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int i = 0;i < M;i ++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		for(int i = 0;i < N;i ++) {
			int min = 0, minidx = 0, dist = 0;
			for(int k = 0;k < M;k ++) {
				dist = Math.abs(a[i] - c[k]) + Math.abs(b[i] - d[k]);
				if(min > dist || k == 0) {
					min = dist;
					minidx = k + 1;
				}
			}
			System.out.println(minidx);
		}
	}
}

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

#define ll long long
#define pb push_back

int ans[2003][2003];
deque < int > v;
int sti1, sti2, fii1, fii2;

main() {
    int n = 43 * 44 + 1;
    int k = 44;
    printf ("%d %d\n", n, k);
    int cnt = 2;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            if (j == 1) {
                ans[i][j] = 1;
            } else {
                ans[i][j] = cnt++;
            }
        }
    }
    int add = k - 1;
    sti1 = 2, fii1 = k;
    for (int i = 2; i <= k; i++) {
        for (int j = 2; j <= k; j++) {
            v.pb(ans[j][i]);
        }
    }
    for (int i = k + 1; i <= k + add; i++) {
        ans[i][1] = 2;
        for (int j = 2; j <= k; j++) {
            ans[i][j] = v.front();
            v.pop_front();
        }
    }
    sti1 = k + 1, fii1 = sti1 + add - 1;
    sti2 = sti1 + add, fii2 = sti2 + add - 1;
    cnt = 3;
    int xi = sti1;
    int res = 0;
    int cn = 0;
//    cout << sti1 << ' ' << fii1 << endl;
//    cout << sti2 << ' ' << fii2 << endl;
    for (int i = sti2; i <= n; i++) {
        ans[i][1] = cnt;
        res++;
        v.clear();
        int ri = sti1 + cn;
        int rj = 2;
        for (int j = 2; j <= k; j++) {
            v.pb(ans[ri][j]);
            ri++;
            if (ri > fii1) {
                ri = sti1;
            }
        }
        for (int j = 2; j <= k; j++) {
            ans[i][j] = v[j - 2];
        }
        cn++;
        if (res >= add) {
            sti1 = sti2;
            fii1 = fii2;
            sti2 = fii1 + 1;
            fii2 = sti2 + add - 1;
            res = 0;
            cnt++;
            cn = 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            printf ("%d ", ans[i][j]);
        }
        puts("");
    }
}


Measured memory_bytes: 14208
#include <iostream>

int main(){
 int A,B,C,D;
 std::cin>>A>>B>>C>>D;

 while(1){
  C-=B;
  if(C<=0){
    std::cout<<"Yes\n";
    return 0;
  }
  A-=D;
  if(A<=0){
   std::cout<<"No\n";
   return 0;
  }
 }

 return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    if (k == 1) cout << 0 << '\n';
    else if (n == k) cout << 0 << '\n';
    else cout << n - k << '\n';
    return 0;
}

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

int main(){
  
  ll n,ans=1;
  cin >> n;
  vector<ll>a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(),a.end());
  if(a[0]==0){
    bool judge=true;
    for(int i=1; i<n; i+=2){
      if(a[i]!=i+1 || a[i+1]!=i+1)judge=false;
    }
    if(judge){
      for(int i=1; i<=(n-1)/2; i++){
        ans*=2;
        ans%=1000000007;
      }
    }
    else ans = 0;
  }
  
  else{
    bool judge=true;
    for(int i=0; i<n; i+=2){
      if(a[i]!=i+1 || a[i+1]!=i+1)judge=false;
    }
    if(judge){
      for(int i=1; i<=n/2; i++){
        ans*=2;
        ans%=1000000007;
      }
    }
    else ans = 0;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b && b!=c && a!=c) || (b==c && a!=b && a!=c) || (a==c && b!=a && b!=c)) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;
 
int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
 
    vec a(Q);
    for(int i = 0; i < Q; i++){
        cin >> a[i];
        a[i]--;
    }
 
    vector<bool> used(M, false);
    vec que(M + 1, 0);
    vec next(M, -1);
    int prev = -1;
 
    que[M] = N - 1;
 
    for(int p = Q - 1; p >= 0; p--){
        if (que[a[p]] > 0){
            que[a[p]]--;
            if(next[a[p]] != -1){
                assert(0 <= next[a[p]] && next[a[p]] < M);
                que[next[a[p]]]++;
            }else{
                que[M]++;
            }
        }else{
            if(!used[a[p]]){
                used[a[p]] = true;
                if(prev >= 0) next[prev] = a[p];
                prev = a[p];
                que[a[p]] += que[M];
                que[M] = 0;
            }
        }
    }
 
    for(int i = 0; i < M; i++){
        if(!used[i]){
            used[i] = true;
            if(prev >= 0) next[prev] = i;
            prev = i;
            que[i] += que[M];
            que[M] = 0;
        }
        if(que[i] > 0){
            if(next[i] != -1){
                assert(0 <= next[i] && next[i] < M);
                que[next[i]] += que[i];
            }else{
                que[M] += que[i];
            }
        }
    }
 
    if(que[M] == N - 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main(){
   string s;
   cin >>s;
   int cnt = 0;
   for(int i=0;i<s.length()/2;i++){
      if(s[i] != s[s.length()-1-i]) cnt++;
   }
   cout << cnt << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define cn cout<<"\n"
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repr(i,a,b) for(int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>
#define flush fflush(stdout)

const int INF = 1e8;
const ll MOD = 1e9 + 7;

using namespace std;




int main(){
	_

	int n;
	cin>>n;
	vll v(n);
	int neg = 0;
	ll ans = 0;
	rep(i, 0, n){
		cin>>v[i];
		if(v[i] < 0) neg++;
		v[i] = abs(v[i]);
		ans += v[i];
	}

	sort(all(v));
	if(neg%2) ans -= 2*v[0];

	cout<<ans; cn;

	return 0;
}

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

int main() {
    string s;
    cin >> s;

    for (size_t i = 0; i < s.size(); i++)
    {
        char c = s[i];
        if (97 <= c && c <= 122) {
            cout << "x";
        } else {
            cout << c;
        }
    }
    cout << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define ll long long
int pos(int n)
{
    if(n<0)
        return 0;
    else
        return n;
}
using namespace std;
int main()
{
    int n,x=0,y=0,tx,ty,time=0,tptime=0,flag=0;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>tptime>>tx>>ty;
        time=tptime-time;
        int  sum=abs(x-tx)+abs(y-ty);
        if(sum>time||(time-sum)%2!=0)
            flag=1;
        time=tptime,x=tx,y=ty;
    }
    if(flag==1)
        cout<<"No";
    else
        cout<<"Yes";
}


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

using namespace std;

constexpr int N = 50;
constexpr int MAX = 100;

char aux[MAX + 2];
string str[N + 1];
int t[N + 1];

int main() {
	string x;
	int ans, n, i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++) {
		scanf(" %s %d", aux, t + i);
		str[i] = string(aux);
	}

	scanf(" %s", aux);
	x = string(aux);

	for (i = 1; i <= n; i++) {
		if (str[i] == x) {
			break;
		}
	}

	i++;
	ans = 0;

	for (; i <= n; i++) {
		ans += t[i];
	}

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

	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
c = [0] * 26
for _ in range(H):
	for i in input():
		c[ord(i) - ord('a')] += 1
a = 0
b = 0
for i in c:
	a += i % 4 // 2
	b += i % 2
if (H % 2) * (W % 2) < b:
	print("No")
elif (H % 2) * (W // 2) + (H // 2) * (W % 2) < a:
	print("No")
else:
	print("Yes")

Measured memory_bytes: 3064
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__);
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__);


#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){

    CIN(n,a);
    COUT(n*n-a);


   return 0;


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int mod = (int)1e9+7;

int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, l, q;
	cin >>n ;
	VI x(n);
	rep(i,n) cin >> x[i];
	cin >> l >>q;
	vector<VI> ds(n+2, VI(20,0));
	
	rep(i,n) ds[i][0] = upper_bound(all(x), x[i]+l) - x.begin() - 1;
	rep(i, 19) rep(j,n) ds[j][i+1] = ds[ds[j][i]][i];
	while(q--){
		int a,b;
		cin >>a  >>b;
		a--;b--;
		if(a>b) swap(a,b);
		int ans = 1;
		repr(i, 18, 0) if(ds[a][i] < b){
			ans += 1<<i; a = ds[a][i];
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 12928
#include<stdio.h>
int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	m=S/60;
	s=S%60;
	h=m/60;
	m=m%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 2728
s = int(input())
l = [s]
for i in range(1, 1000001):
    num_i = 1000001
    if l[i - 1] % 2 == 0:
        num_i = l[i - 1] / 2
    else:
        num_i = l[i - 1] * 3 + 1
    if num_i in l:
        print(i+1)
        break
    else:
        l.append(num_i)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>

using namespace std;

int gcd(int x, int y){
    int r;

    while(1){
        r = x % y;

        if(r == 0){
            break;
        }

        x = y;

        y = r;
    }

    return y;
}

int main(void)
{
    int N, A[100001], i, j, judge, ans;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];
    }

    sort(A+1, A+N+1);

    ans = gcd(A[1], A[2]);

    for(i=2; i<N; i++){
        ans = gcd(ans, A[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
def resolve():
    X, Y, Z, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    B = sorted(list(map(int, input().split())), reverse=True)
    C = sorted(list(map(int, input().split())), reverse=True)
    pushed = set("0-0-0")

    import heapq
    Q = [[-1*(A[0]+B[0]+C[0]), 0, 0, 0]]
    heapq.heapify(Q)
    for i in range(K):
        v, i, j, k = heapq.heappop(Q)
        print(-v)
        if "{}-{}-{}".format(i+1, j, k) not in pushed and i+1 < X:
            heapq.heappush(Q, [-1*(A[i+1]+B[j]+C[k]), i+1, j, k])
            pushed.add("{}-{}-{}".format(i+1, j, k))
        if "{}-{}-{}".format(i, j+1, k) not in pushed and j+1 < Y:
            heapq.heappush(Q, [-1*(A[i]+B[j+1]+C[k]), i, j+1, k])
            pushed.add("{}-{}-{}".format(i, j+1, k))
        if "{}-{}-{}".format(i, j, k+1) not in pushed and k+1 < Z:
            heapq.heappush(Q, [-1*(A[i]+B[j]+C[k+1]), i, j, k+1])
            pushed.add("{}-{}-{}".format(i, j, k+1))

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 58456
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

t = [a,b,c,d,e]
tt = [a%10, b%10, c%10, d%10, e%10]

min_i = 9
total = 0
for v in t:
  if v%10 < min_i and v%10 > 0:
    min_i = v%10
  if v%10 != 0:
    total += v + 10 - v%10
  else:
    total += v

if any(tt):
	print(total - 10 + min_i)
else:
  	print(total)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main () {
    long long int n, m;
    
    scanf("%lld%lld", &n, &m);
    
    if (n * 2 >= m) {
        printf("%lld", m / 2);
    }
    else {
        printf("%lld", (m + 2 * n) / 4);
    }
}

Measured memory_bytes: 128
I=->{gets.split.map &:to_i}
N,Q=I[]
A=[1,c=1,1,*[0]*(N-2),1]
Q.times{
	a,b=I[]
	A[a],A[b]=A[b],A[a]
c=c==a||c==b ?c=a+b-c :c
	A[c-1]=A[c+1]=1
}
p A.reduce(:+)-2

Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000005

ll r, g, b, n, ans, x, y;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> r >> g >> b >> n;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n; j++){
            x = i*r + j*g;
            y = n - x;
            if (y%b == 0 && y >= 0) ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc_155b
{
    class Program
    {
        static void Main(string[] args)
        {
            int kazu = int.Parse(Console.ReadLine());
            string[] number = Console.ReadLine().Split(' ');
            bool OK = true;

            for(int i = 0;i < number.Length && OK; i++)
            {
                OK = judge(number[i]);
            }

            if (OK)
            {
                Console.WriteLine("APPROVED");
            }
            else
            {
                Console.WriteLine("DENIED");
            }

            Console.Read();

        }
        static public bool judge(string number)
        {
            if (int.Parse(number) % 2 == 0 )
            {
                return int.Parse(number) % 3 == 0 || int.Parse(number) % 5 == 0 ? true : false;
            }
            else
            {
                return true;
            }
        }
    }
}


Measured memory_bytes: 11092
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int x, a;
    cin >> x >> a;
    if(x < a)
        cout << 0;
    else
        cout << 10;   
    return 0;
}

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


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

vector<int> to[100005];
int main(){
  int n, m;
  cin >> n >> m;

  rep(i,m){
    int a, b;
    cin >> a >> b;
    --a; --b;

    to[a].push_back(b);
    to[b].push_back(a);
  }
  queue<int> que;
  vector<int> dist(n,INF);//距離
  vector<int> pre(n,-1);//

  dist[0] = 0;
  que.push(0);

  while(!que.empty()){
    int v = que.front(); que.pop();
    for (int u : to[v]){
      if(dist[u] != INF)continue;
      dist[u] = dist[v] + 1;//上のノードまでの距離に＋1
      pre[u] = v;//直前のノードvを記憶
      que.push(u);
    }
  }
  cout << "Yes" << endl;

  rep(i,n){
    if(i == 0)continue;
    int ans = pre[i];
    ans ++;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 10728
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, l, m;
  string s, t;
  char u, p;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    cin >> t;
    l = s.size();
    m = t.size();
    for (int i = l-1; i >= 0; --i) {
      p = s[i];
      if (p == 'P') {
	for (int j = 0; j < m; ++j) {
	  if (t[j] == '0') t[j] = '9';
	  else if ('0' < t[j] && t[j] <= '9') {
	    t[j] = t[j] - 1;
	  }
	}
      } else if (p == 'M') {
	for (int j = 0; j < m; ++j) {
	  if (t[j] == '9') t[j] = '0';
	  else if ('0' <= t[j] && t[j] < '9') {
	    t[j] = t[j] + 1;
	  }
	}
      } else if (p == 'C') {
	u = t[0];
	for (int j = 0; j < m-1; ++j) t[j] = t[j+1];
	t[m-1] = u;
      } else if (p == 'A') {
	for (int j = 0; j < m/2; ++j) {
	  u = t[m-1-j];
	  t[m-1-j] = t[j];
	  t[j] = u;
	}
      } else if (p == 'E') {
	for (int j = 0; j < m/2; ++j) {
	  u = t[m/2+m%2+j];
	  t[m/2+m%2+j] = t[j];
	  t[j] = u;
	}
      } else if (p == 'J') {
	u = t[m-1];
	for (int j = m-1; j > 0; --j) t[j] = t[j-1];
	t[0] = u;
      }
      //      cout << p << " " << t << endl;
    }
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 3040
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;


int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;


    string str;
    cin >> str;
    int cnt, even, odd;
    cnt = even = odd = 0;
    vector<int> ans((int)str.size(), 0);
    for (int i = 0; i < (int)str.size(); ++i) {
        if (str[i] == 'R') {
            ++cnt;
            if (i & 1)
                ++odd;
            else
                ++even;
        }
        if (str[i] == 'L') {
            if (i & 1) {
                ans[i] += odd;
                ans[i - 1] += even;
            } else {
                ans[i] += even;
                ans[i - 1] += odd;
            }
            even = odd = 0;
        }
    }

    for (int i = (int)str.size() - 1; ~i; --i) {
        if (str[i] == 'L') {
            ++cnt;
            if (i & 1)
                ++odd;
            else
                ++even;
        }
        if (str[i] == 'R') {
            if (i & 1) {
                ans[i] += odd;
                ans[i + 1] += even;
            } else {
                ans[i] += even;
                ans[i + 1] += odd;
            }
            even = odd = 0;
        }
    }

    for (int x : ans)
        cout << x << ' ';
    cout << '\n';

    return 0;
}

Measured memory_bytes: 1104
S=input()
N=len(S)

def rule1():
  return S==S[::-1]

def rule2():
  s = S[:(N-1)//2]
  return s==s[::-1]

def rule3():
  s = S[(N+3)//2-1:]
  return s==s[::-1]  

print ('Yes' if rule1() and rule2() and rule3() else 'No')


Measured memory_bytes: 9048
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue<LL>
#define PQS priority_queue<LL, vector<LL>, greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

void ret(deque<char> a,ST s,deque<char> b){
  for(char i:a)cout<<i;
  cout<<s;
  for(char i:b)cout<<i;
  cout<<endl;
}

int main(){
  LL i,Q,f=0,q,F;
  char C;
  string S;
  deque<char> d,e;
  cin>>S>>Q;
  rep(i,Q){
    cin>>q;
    if(q==1)f=(f+1)%2;
    if(q==2){
      cin>>F>>C;
      if(F==1){
        if(f==0)d.PF(C);
        else e.PB(C);
      }else{
        if(f==0)e.PB(C);
        else d.PF(C);
      }
    }
  }
  if(f==0)ret(d,S,e);
  else{
    REV(d);REV(S);REV(e);
    ret(e,S,d);
  }
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int> 
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
void shikhar7s(int cas)
{
    int n,i,a=0,f,c;
    cin>>n;
    rep(i,1,2000005)
    {
        a=(a*10)%n;
        a=(a+7)%n;
        if(!a)
        {
            cout<<i;
            return;
        }
    }
    cout<<-1;
}
signed main()
{
    fast;
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	char c;
	cin>>a>>c>>b;
	if(c=='+') cout<<a+b<<endl;
	else if(c=='-') cout<<a-b<<endl;
	else if(c=='*') cout<<a*b<<endl;
	else if(c=='/'){cout<<a/b<<endl;
		
	} 
	
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        double w = sc.nextDouble(), h = sc.nextDouble(), x = sc.nextDouble(), y = sc.nextDouble();
        int ans = 0;

        if(w / 2 == x && h / 2 == y) ans = 1;

        pw.println(w*h/2 + " " + ans);
        pw.close();
    }
}

Measured memory_bytes: 22100
#include<cstdio>
#include<cstdlib>
#include<vector>
using namespace std;
const long long MAXN=100005;

vector<long long> adj[MAXN],s[MAXN];

long long flag[MAXN];
long long val[MAXN];
long long mn=1,mx=0x7FFFFFFFFFFFFFFFLL;

void dfs(long long u)
{
	for(long long i=0;i<(int)adj[u].size();i++)
	{
		long long v=adj[u][i];
		if(flag[v]==0)
		{
			flag[v]=(-flag[u]);
			val[v]=s[u][i]-val[u];
			if(flag[v]==1)
				mn=max(mn,-val[v]+1);
			else
				mx=min(mx,val[v]-1);
			if(mn>mx)
			{puts("0");exit(0);}
			dfs(v);
			continue;
		}
		if(flag[u]!=flag[v])
		{
			if(val[u]+val[v]!=s[u][i])
			{puts("0");exit(0);}
		}
		else
		{
			if((s[u][i]-val[u]-val[v])%2LL!=0)
			{puts("0");exit(0);}
			if((s[u][i]-val[u]-val[v])/2LL*flag[u]<=0)
			{puts("0");exit(0);}
			mn=max(mn,(s[u][i]-val[u]-val[v])/2LL*flag[u]);
			mx=min(mx,(s[u][i]-val[u]-val[v])/2LL*flag[u]);
		}
	}
}

int main()
{
	long long n,m;
	scanf("%lld%lld",&n,&m);
	for(long long i=1;i<=m;i++)
	{
		long long u,v,a;
		scanf("%lld%lld%lld",&u,&v,&a);
		adj[u].push_back(v);
		s[u].push_back(a);
		adj[v].push_back(u);
		s[v].push_back(a);
	}
	
	flag[1]=1;
	val[1]=0;
	dfs(1);
	
	printf("%lld\n",max(mx-mn+1,0LL));
	
	return 0;
}


Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define maxn 300020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

int n,a[maxn],sumw,sumb;

inline bool check(int mid){
	int mx = 0;
	rep(i,1,n){
		if ( i & 1 ){
			mx += a[i];
			if ( mx >= mid && i + 1 <= n ) mx = max(mx,a[i + 1]);
		}
		else mx -= a[i];
	}
	return mx >= mid;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]) , ((i & 1) ? sumb : sumw) += a[i];
	if ( !(n & 1) ){
		cout<<max(sumw,sumb)<<" "<<min(sumw,sumb)<<endl;
		return 0;
	}
	int l = 0 , r = inf , x = 0;
	while ( l <= r ){
		int mid = (l + r) >> 1;
		if ( check(mid) ) l = mid + 1 , x = mid;
		else r = mid - 1;
	}
	cout<<sumw + x<<" "<<sumb - x<<endl;
}



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

int main() {
    int N, K;
    cin >> N >> K;
    vector<long int> high(N);
    for (int i = 0; i < N; ++i) {
        cin >> high[i];
    }
    sort(high.begin(), high.end(), greater<>());
    auto answer = (long int) 1e18;
    for (int i = 0; i < N - K + 1; ++i) {
        answer = min(high[i] - high[i + K - 1], answer);
    }
    cout << answer << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  std::string s;
  cin >> n >> s;
  std::stack<char> stack;
  for (auto c : s) {
    if (c == '(') {
      stack.push(c);
    } else {
      if (!stack.empty() && stack.top() == '(') {
        stack.pop();
      } else {
        stack.push(c);
      }
    }
    // cerr << "\033[93m" << stack.size() << "\033[m" << endl;
  }
  while (!stack.empty()) {
    // cerr << "\033[93m" << s << "\033[m" << endl;
    if (stack.top() == '(') {
      s = s + ')';
    } else {
      s = '(' + s;
    }
    stack.pop();
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.1.6
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a.back()<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  Vi a(n), b(n);
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) cin >> b[i];
  sort(ALL(a));
  sort(ALL(b));
  
  map<int,int> kind;
  rep(i,0,n){
    kind[a[i]]++;
    kind[b[i]]--;
  }
  
  int ans = 1,now = 0;
  for (auto p : kind ) {
    auto v = p.second;
    if(now == 0) now += v;
    else if(now > 0 && v==1) now++;
    else if(now > 0 && v==-1) {
      ans = ans*now%MOD;
      now--;
    }
    else if(now < 0 && v==-1) now--;
    else if(now < 0 && v==1) {
      ans = ans*(-1)*now%MOD;
      now++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N;
    cin >> N;
    while(true){
        if(N > 1000){
            N-=1000;
        }else{
            fin(1000-N);
            break;
        }
    }
    return 0;
}

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

typedef long long int ll;

int main()
{
    string s;
    cin >> s;

    for(ll i = 0;i < 3;i++){
        if(s[i] == '7'){
            cout << "Yes";

            return 0;
        }
    }

    cout << "No";

    return 0;
}


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

int main(){
  int N,A[3];
  cin >> N >> A[0] >> A[1] >> A[2];
  int l[N];
  for(int i=0;i<N;i++) cin >> l[i];

  int ans=100000000;

  for(int i=0;i<(1 << 2*N);i++){
    vector<int> use[4];
    int t=i;
    for(int j=0;j<N;j++){
      use[t%4].push_back(l[j]);
      t=t/4;
    }

    int sum=0;
    for(int j=0;j<3;j++){
      if(use[j].size()==0){
        sum=100000000;
        break;
      }

      int mp=10*(use[j].size()-1);
      int sm=0;
      for(int k : use[j]) sm+=k;
      mp=mp+abs(A[j]-sm);
      sum+=mp;
    }

    ans=min(ans,sum);
  }

  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
# 最小二乗法とやってること同じなので平均で最小になると考えて
P1, P2 = sum(X) // N, -(-sum(X) // N)
ans1, ans2 = 0, 0
for x in X:
    ans1 += (x - P1)**2
    ans2 += (x - P2)**2
print(min(ans1, ans2))


Measured memory_bytes: 2940
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =10010;
int parent[MAX_N];
int rank[MAX_N];
int V;
void init(int V){
	for(int i = 0;i <V;i++){
		parent[i] = i;
		rank[i] = 0;
	}
}
int find(int x){
	if(parent[x]==x){
		return x;
	}else{
		return find(parent[x]);
	}
}

void unit(int x,int y){
	x = find(x);
	y = find(y);
	if(x==y)
		return;
	else{
		if(rank[x]>rank[y]){
			parent[y] = x;
		}else if(rank[x]<rank[y]){
			parent[x]= y;
		}else{
			parent[y] = x;
			rank[x]++;
		}
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}
int main(){
	int n,q;
	cin>>n>>q;
	V =n;
	init(V);
	rep(i,q){
		int com;
		int x,y;
		cin>>com>>x>>y;
		if(com==0){
			unit(x,y);
		}else{
			if(same(x,y)){
				cout <<1<<endl;
			}else{
				cout <<0<<endl;
			}
		}
	}
	return 0;
}

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

int dp[5010][5010] = {0};

int main()
{
    int n; cin >> n;
    string s; cin >> s;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (s[i-1] == s[j-1]) {
                dp[i][j] = min(dp[i-1][j-1] + 1, abs(i - j));
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 98048
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		int x = r.nextInt();
		int y = r.nextInt();
		if (x % y == 0)
			System.out.println(-1);
		else
			System.out.println(x);
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

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

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

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

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 22228
a = int(input())
i = 0
o = 0
p = 0
s = 0
l = 0
while i < a :
    b = input()
    if b == "AC" :
        o = o + 1
    if b == "WA" :
        p = p + 1
    if b == "TLE" :
        s = s + 1
    if b == "RE" :
        l = l + 1
    i = i + 1
print("AC" , "x" , o)
print("WA" , "x" , p)
print("TLE" , "x" , s)
print("RE" , "x" , l)

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

using ll = long long;

void solve(std::string S){
    if(S.back() == 's'){
        cout<<S + "es"<<endl;
    }else{
        cout<<S + "s"<<endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, t;
  x = A[r];
  i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

int main() {
  int q;

  cin >> n;

  for (int i = 0; i < n; i++) cin >> A[i];

  q = partition(0, n-1);

  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    if (i == q) cout << "[";
    cout << A[i];
    if (i == q) cout <<"]";
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 3468
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector <pair <long long, long long> > ba(n);
  for (int i = 0; i < n; i++) {
	  long long a, b;
	  cin >> a >> b;
	  ba[i] = make_pair(b, a);
	}
  long long t = 0;
  bool ans    = true;
  sort(ba.begin(), ba.end());
  for (int i = 0; i < n; i++) {
	  t += ba[i].second;
	  if (t > ba[i].first) {
		  ans = false;
		  break;
		}
	}
  if (ans) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}
  return 0;
}


Measured memory_bytes: 3328
#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;


template<typename T>
struct VoronoiMST{
  int n;
  using E = pair<int, T>;
  using TI = pair<T, int>;
  vector<vector<E> > G;
  VoronoiMST(vector<T> &x){
    n=x.size();
    G.assign(n<<1,vector<E>());
    for(int i=0;i<n;i++) G[i].emplace_back(n+i,x[i]);
  }
  void add_edge(int u,int v,T c){
    G[u+n].emplace_back(v+n,c);
    G[v+n].emplace_back(u+n,c);
  }
  vector<vector<E>> build(){
    priority_queue<TI, vector<TI>, greater<TI> > pq;
    const T INF = numeric_limits<T>::max();
    vector<T> dist(n<<1,INF);
    vector<int> from(n<<1,-1);
    for(int i=0;i<n;i++){
      dist[i]=0;from[i]=i;
      pq.emplace(dist[i],i);
    }
    while(!pq.empty()){
      T d;
      int v;
      tie(d,v)=pq.top();pq.pop();
      if(dist[v]<d) continue;
      for(E e:G[v]){
        int u=e.first;
        T c=e.second;
        if(dist[u]<=dist[v]+c) continue;
        dist[u]=dist[v]+c;
        from[u]=from[v];
        pq.emplace(dist[u],u);
      }
    }
    vector<vector<E> > H(n);
    for(int v=0;v<(n<<1);v++){
      for(E e:G[v]){
        int u=e.first;
        T c=e.second;
        if(from[v]==from[u]) continue;
        int x=from[v],y=from[u];
        T z=dist[v]+dist[u]+c;
        H[x].emplace_back(y,z);
        H[y].emplace_back(x,z);
      }
    }
    return H;
  }
};


template<typename T>
struct Kruskal{
  struct edge{
    int from,to;
    T cost;
    int used;
    edge(int from,int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };
 
  int n;
  vector<int> r,p;
  vector<edge> es;
 
  Kruskal(){}
  Kruskal(int n):n(n),r(n,1),p(n){
    iota(p.begin(),p.end(),0);
  }
 
  int find(int x){ return (x==p[x]?x:p[x]=find(p[x])); }
 
  bool same(int x,int y){ return find(x)==find(y); }
 
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
 
  void add_edge(int u,int v,T c){ es.emplace_back(u,v,c); }
 
  T build(){
    sort(es.begin(),es.end());
    T res=0;
    for(auto &e:es){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};
 

int main(){
  int n,d;
  cin >> n >> d;
  vector<ll> a(n);
  rep(i,n){ cin>>a[i]; }
  
  VoronoiMST<ll> vo(a);
  for(int i=1; i<n; i++){ vo.add_edge(i-1,i,d); }
  auto G = vo.build();
  
  Kruskal<ll> ks(n);
  for(int v=0; v<n; v++){
    for(auto e:G[v]){
      int u=e.F; ll c=e.S;
      if(v<u){ ks.add_edge(v,u,c); }
    }
  }
  ll ans=ks.build();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 69428
N = int(input())
S = input()
MOD = 10**9+7

lr = []
rc = 0
for i,c in enumerate(S):
    isr = (i%2) ^ int(c=='W')
    lr.append(isr)
    rc += isr

if rc != N:
    print(0)
    exit()

l = 0
ans = 1
for isr in lr:
    if isr:
        if l:
            ans *= l
            ans %= MOD
            l -= 1
        else:
            print(0)
            exit()
    else:
        l += 1

for n in range(1,N+1):
    ans *= n
    ans %= MOD
print(ans)

Measured memory_bytes: 5096
while gets
    s=$_.chomp
    arr=s.scan(/@../)
    str1=s.split(//)
    str2=[]
    (arr.size).times do |i|
        str2[i]=[]
        (arr[i][1].to_i).times do |j|
            str2[i][j]=arr[i][2]
        end
        str2[i]=str2[i].join
    end
    i=0
    j=0
    loop do
        break if(str1[i]==nil)
        if(str1[i]=='@')
            print str2[j]
            j+=1
            i+=3
        else
            print str1[i]
            i+=1
        end
    end
    puts
end

Measured memory_bytes: 6108
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
typedef long long ll;
using namespace std;

int main(){
	int N;
	cin>>N;
	int i=0;
	while(N>0){
		N-=i+1;
		i++;
	}
	p(i);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int M, N;
vector<string> vs(1000);
vector<string> JOI(2);
bool calc(int y, int x) {
  if(y < 0 || x < 0 || y + 1 >= M || x + 1 >= N) return false;
  return vs[y][x] == JOI[0][0] && vs[y][x+1] == JOI[0][1] && vs[y+1][x] == JOI[1][0] && vs[y+1][x+1] == JOI[1][1];
}
int change(int y, int x, char c, int cy, int cx) {
  if(y < 0 || x < 0 || y + 1 >= M || x + 1 >= N) return 0;
  int ret = 0;
  ret -= calc(y, x);
  char vsc = vs[cy][cx];
  vs[cy][cx] = c;
  ret += calc(y, x);
  vs[cy][cx] = vsc;
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> M >> N;
  FOR(i,0,M) cin >> vs[i];
  FOR(i,0,2) cin >> JOI[i];
  int p = 0;
  FOR(y,0,M) FOR(x,0,N) p += calc(y, x);

  int mx = 0;
  // ?´????->?´??????§????????? -1????´??????§?????????->?´???? +1????´??????§?????????->?´??????§????????? 0
  string str = "JOI";
  FOR(y,0,M) {
    FOR(x,0,N) {
      FOR(i,0,3) {
        int cnt = 0;
        int Y = y - 1, X = x - 1;
        cnt += change(Y, X, str[i], y, x);
        Y = y, X = x - 1;
        cnt += change(Y, X, str[i], y, x);
        Y = y - 1, X = x;
        cnt += change(Y, X, str[i], y, x);
        Y = y, X = x;
        cnt += change(Y, X, str[i], y, x);
        mx = max(mx, cnt);
      }
    }
  }
  cout << p + mx << endl;
  return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 
 
inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}
 
//約数列挙O(root n)
PLL div(ll n){
  for(ll i=sqrt(n); i>=1; --i){
    if(n%i == 0) return PLL(i,n/i);
  }
  return PLL(0,0);
}
 
 
int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll S;cin >> S;
  // S = x1y2 - x2y1;
  // S = E9y2 - x2;
  ll E9 = 1e9;
  ll x1=E9,y1=1;
  ll x2=E9-(S%E9),y2=(S/E9)+1;
  if(S!=1e18)cout << 0 SP 0 SP x1 SP y1 SP x2 SP y2 << endl;
  else cout << 0 SP 0 SP 0 SP 1e9 SP 1e9 SP 0 << endl;
  return 0;
}

Measured memory_bytes: 256