akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

class Main {
    int N;
    void input() { cin >> N; }
    void output() {
        mint res = mint(10).pow(N);
        res -= mint(9).pow(N) * 2;
        res += mint(8).pow(N);
        cout << res << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 3648
let get_int () = Scanf.scanf "%d " (fun v -> v)
let get_3_ints () = Scanf.scanf "%d %d %d " (fun u v w -> u,v,w)

let () =
  let n = get_int ()
  in let ar =
    Array.map 
    (fun _ -> get_3_ints ())
    (Array.make n (-1,-1,-1))
  in 
  let (t,_,_) = Array.fold_left (fun (t,x,y) (u,p,q) -> 
    let dist = abs (p-x) + abs (q-y)
    in let span = u-t
    in if t>=0 && dist <= span && span mod 2 = dist mod 2 then (u,p,q)
    else (-1,0,0)
  ) (0,0,0) ar
  in
  print_endline @@ if t>=0 then "Yes" else "No"

Measured memory_bytes: 7680
#pragma comment(linker, "/STACK:640000000")
#include <bits/stdc++.h>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);

int n, m;

string s[12];
bool used[12];
int o[12];
ll a[12], b[12];

bool check() {
	//for (int i = 0; i < m; i++) cout << o[i] << " ";
	//cout << endl; 
	map< pair<ll, ll>, int> d;
	for (int i = 0; i < n; i++) {
		a[i] = 0;
		for (int j = 0; j < m; j++) {
			a[i] = a[i] * 26 + s[i][o[j]];
		}
		b[i] = 0;
		for (int j = m - 1; j >= 0; j--) {
			b[i] = b[i] * 26 + s[i][o[j]];
		}
		if (a[i] <= b[i]) {
			d[mp(a[i], b[i])]++;
		} else {
			d[mp(b[i], a[i])]--;
		}
	}
	int odd = 0;
	for (auto &it : d) {
		if (it.first.first != it.first.second) {
			if (it.second != 0) return false;
		} else {
			if (it.second % 2 == 1) odd++;
		}
	}
	if (odd > 1) return false;
	if ((odd != 0) != (n % 2 != 0)) return false;
	return true;
}

bool dfs(int x, int p) {
	if (x == m) {
		if (check()) return true;
		return false;
	}
	if (used[x]) return dfs(x + 1, p);
	for (int i = x + 1; i < m; i++) if (!used[i]) {
		used[x] = true;
		used[i] = true;
		o[p] = x;
		o[m - 1 - p] = i;
		if (dfs(x + 1, p + 1)) return true;
		used[x] = false;
		used[i] = false;
	}
	return false;
}

int main() {
	#ifdef LOCAL
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	cin >> n >> m;

	for (int i = 0; i < n; i++) cin >> s[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			s[i][j] -= 'a';
		}
	}

	if (m % 2 == 0) {
		if (dfs(0, 0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	} else {
		for (int i = 0; i < m; i++) {
			used[i] = true;
			o[m / 2] = i;
			if (dfs(0, 0)) {
				cout << "YES" << endl;
				return 0;
			}
			used[i] = false;
		}
		cout << "NO" << endl;
	}

	return 0;
}

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

int main() {
  int N,res;
  cin >> N;
  for(int a=0; a < 30; ++a) {
    for(int b=0; b < 30; ++b) {
      int total = 4 * a + 7 * b;
      if(total == N) ++res;
    }
  }
  if (res>0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

ll gcd(ll a, ll b){
	if(b>a) swap(a,b);
	ll t = a%b;
	while(b!=0){
		t = a%b;
		a = b;
		b = t;
	}
	return a;
}

int main(){
	int N;
	ll A[100000];
	cin >> N;
	for(int i=0;i<N;i++) cin >> A[i];

	ll ans = A[0];
	for(int i=0;i<N;i++) ans = gcd(ans,A[i]);
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc079_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N = 4;
  vector<int> c(N, 0);
  string S;
  cin >> S;
  rep(i, N) { c[i] = S[i] - '0'; }

  rep(i, pow(3, 2)) {
    int ans = c[0];
    rep(j, 3) {
      if (i & 1 << j) {
        ans += c[j + 1];
      } else {
        ans -= c[j + 1];
      }
    }
    if (ans == 7) {
      cout << c[0];
      rep(j, 3) { cout << ((i & 1 << j) ? "+" : "-") << c[j + 1]; }
      cout << "=7";
      return 0;
    }
  }
}

Measured memory_bytes: 3660
kn = gets.chomp.split
k = kn[0].to_i
n = kn[1].to_i

a = gets.chomp.split
a[0] = a[0].to_i
distances = []
distance_sum = 0
(n-1).times do |i|
    a[i+1] = a[i+1].to_i
    distance = a[i+1] - a[i]
    distance_sum += distance
    distances << distance
end
distances << (k - a.last + a[0]).abs
distance_sum += (k - a.last + a[0]).abs

puts distance_sum - distances.max

Measured memory_bytes: 16836
import java.util.Arrays;

//intのオーバーフローに気をつけろ,AGCはだいたいlongにしておけ
//毎回余りを求めることでオーバーフローしなくなる
//nextLineよりnextだ
//charは''で囲うんだぞ
//読み込みは先に全部やっておけ
//for文を回す回数に気をつけろ
	//for文は10^3の三重はTLE,10^5の二重はTLE,10^9のforはTLE
//貪欲は使えるか？？試した？？

import java.util.Scanner;
public class Main {
	public static void main(String args[]) throws InterruptedException {
		    Scanner sc = new Scanner(System.in);
		   
		    
		    // 2数が同じときのみ2を足すのが丸そう
		    int[] a = new int[3];
		    a[0] = Integer.parseInt(sc.next());
		    a[1] = Integer.parseInt(sc.next());
		    a[2] = Integer.parseInt(sc.next());
		    int count = 0;
		    
		    Arrays.sort(a);
		    
		    while(a[1] != a[2]) {
		    	a[0]++;
		    	a[1]++;
		    	count++;
		    }
		    if((a[2]-a[0]) % 2 ==0) {
		    	count += (a[2]-a[0])/2;
		    }else {
		    	count += (a[2]+1-a[0])/2+1;
		    }
		    System.out.println(count);
		    
		    sc.close(); }
	
	public static String caesar(String a, int k) {
		//シーザー暗号
		String t = ""; 
		for(int i = 0; i < a.length(); i++) {
			if(a.charAt(i) < 'a') {
				t = t + String.valueOf((char)(a.charAt(i)) );
			}else if(a.charAt(i) + k <= 'z') {
				t = t + String.valueOf((char)(a.charAt(i) + k));
			}else {
				t = t + String.valueOf((char)(a.charAt(i) + k - 26));
			}
		}
		return t;
	}
	public static String raseac(String a, int k) {
		//シーザー暗号の復号
		String t = ""; 
		for(int i = 0; i < a.length(); i++) {
			if(a.charAt(i) < 'a') {
				t = t + String.valueOf((char)(a.charAt(i)) );
			}else if(a.charAt(i) - k >= 'a') {
				t = t + String.valueOf((char)(a.charAt(i) - k));
			}else {
				t = t + String.valueOf((char)(a.charAt(i) - k + 26));
			}
		}
		return t;
	}


	public static void saiki(int a, String b) {
		//再帰コーディングのお手本

		if(a == 0) {
			System.out.println(b);
		}else {
			for(char ch = 'a'; ch <= 'c'; ch++) {
				saiki(a-1,b + ch);
			}
		}
	}

	public static  int gcd(int a, int b) {
	    if (a < b) {
	        int tmp = a;
	        a = b;
	        b = tmp;
	    }

	    int r = -1;
	    while (r != 0) {
	        r = a % b;
	        a = b;
	        b = r;
	    }

	    return a;
	}
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    string t;
    for(i = 0;i < s.size();++i){
        if(s.at(i) != 'x') t.push_back(s.at(i));
    }
    for(i = 0;i < t.size();++i){
        if(t.at(i) != t.at(t.size()-i-1)){
            cout << -1 << endl;
            return 0;
        }
    }
    ll n = t.size();
    vector<ll> ind(n);
    ll now = 0;
    for(i = 0;i < s.size();++i){
        if(s.at(i) != 'x'){
            ind.at(now) = i;
            ++now;
        }
    }
    ll ans = 0;
    if(n%2){
        for(i = 0;i <= (n-1)/2;++i){
            if(i == 0){
                ll tmp1 = ind.at(i) - 0;
                ll tmp2 = s.size() - 1 - ind.at(n-1-i);
                ans += abs(tmp1 - tmp2);
            }else{
                ll tmp1 = ind.at(i) - ind.at(i-1);
                ll tmp2 = ind.at(n-i) - ind.at(n-1-i);
                ans += abs(tmp1 - tmp2);
            }
        }
    }else{
        for(i = 0;i < n/2;++i){
            if(i == 0){
                ll tmp1 = ind.at(i) - 0;
                ll tmp2 = s.size() - 1 - ind.at(n-1-i);
                ans += abs(tmp1 - tmp2);
            }else{
                ll tmp1 = ind.at(i) - ind.at(i-1);
                ll tmp2 = ind.at(n-i) - ind.at(n-1-i);
                ans += abs(tmp1 - tmp2);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += p[i];
  }
  cout << sum;
}

Measured memory_bytes: 3628
WHITE = '.'
BLACK = '#'

A, B = list(map(int, input().split()))

remain_white = A-1
remain_black = B-1

print("100 100")
for i in range(25):
    print(BLACK*100)
    if remain_white >= 50:
        print((WHITE+BLACK)*50)
        remain_white -= 50
    else:
        print((WHITE+BLACK)*remain_white + BLACK*(100-remain_white*2))
        remain_white = 0

for i in range(25):
    print(WHITE*100)
    if remain_black >= 50:
        print((WHITE+BLACK)*50)
        remain_black -= 50
    else:
        print((WHITE+BLACK)*remain_black + WHITE*(100-remain_black*2))
        remain_black = 0

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h,n;
  cin>>w>>h>>n;
  int xl=0,xg=w,yl=0,yg=h;
  for(int i=0;i<n;i++){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1)
      xl=max(xl,x);
    if(a==2)
      xg=min(xg,x);
    if(a==3)
      yl=max(yl,y);
    if(a==4)
      yg=min(yg,y);
  }
  cout<<max(xg-xl,0)*max(yg-yl,0)<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    ArrayList<Integer> H = new ArrayList<>();
    ArrayList<Integer> W = new ArrayList<>();
    while (true) {
    	int h = sc.nextInt(); int w = sc.nextInt();
    	if (h == 0 && w == 0) { break; }
    	H.add(h); W.add(w);
    }
    for (int k = 0; k < H.size(); k++) {
	  	for (int i = 0; i < H.get(k); i++) {
	  		for (int j = 0; j < W.get(k); j++) {
				System.out.print("#");
			}
			System.out.print("\n");
	  	}
	  	System.out.print("\n");
    }
  }
}


Measured memory_bytes: 37408
from collections import defaultdict
import heapq

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

col_cnt = [0] * W
row_cnt = [0] * H
col_max = 0
row_max = 0

w2h = defaultdict(list)
h2w = defaultdict(list)
bombs = set()

for _ in range(M):
    h, w = map(lambda x:int(x)-1, input().split())
    row_cnt[h] += 1
    col_cnt[w] += 1
    row_max = max(row_max, row_cnt[h])
    col_max = max(col_max, col_cnt[w])
    bombs.add((h, w))

max_rows = set()
max_cols = set()

for h in range(H):
    if row_cnt[h] == row_max:
        max_rows.add(h)
for w in range(W):
    if col_cnt[w] == col_max:
        max_cols.add(w)

cnt = 0
for h, w in bombs:
    if h in max_rows and w in max_cols:
        cnt += 1

if cnt == len(max_rows) * len(max_cols):
    print(row_max + col_max-1)
else:
    print(row_max + col_max)



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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

struct UnionFind {
  vint par ;  //iの親
  vint rank ; //木の深さ
  
  //n要素の初期化
  void init(int n){
    REP(i,n){
      par.PB(i) ;
      rank.PB(0) ;
    }
  }
  
  //木の根を求める
  //根が一緒なら同じ集合と判断するため
  int find(int x){
    if(par[x]==x){
      return x ;
    }
    else{
      return par[x] = find(par[x]) ;
    }
  }
  
  //木の併合
  //記録してあるrankをもとに併合
  void unite(int x,int y){
    x = find(x) ;
    y = find(y) ;
    if(x==y){
      return ;
    }
    
    if(rank[x] < rank[y]){
      par[x] = y ;
    }
    else{
      par[y] = x ;
      if(rank[x]==rank[y]){
        rank[x]++ ;
      }
    }
  }
  
  //xとyが同じ集合に属するか
  bool same(int x,int y){
    return find(x) == find(y) ;
  }
  
};


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m ;
  cin >> n >> m ;
  vll ans(m,0) ;
  
  UnionFind tree ;
  tree.init(n) ;
  
  vll you(n,1) ;
  //iの属する集合の要素数
  
  UnionFind memo ;
  memo.init(n) ;
  
  vpii pai(m) ;
  
  REP(i,m){
    int a, b ;
    cin >> a >> b ;
    pai[i] = MP(a-1,b-1) ;
    memo.unite(a-1,b-1) ;
  }
  
  reverse(ALL(pai)) ;
  
  
  vll num2(n,0) ;
  
  REP(i,n){
    num2[memo.find(i)]++ ;
  }
  
  
  ans[0] = 0 ;
  
  REP(i,n){
    ans[0] += num2[i]*(num2[i]-1)/2 ;
  }
  
  REP(i,m-1){
    int A, B ;
    A = pai[i].FI ;
    B = pai[i].SE ;
    if(!tree.same(A,B)){
      ans[i+1] = ans[i] - (you[tree.find(A)]*you[tree.find(B)]) ;
      you[tree.find(A)] += you[tree.find(B)] ;
      you[tree.find(B)] = you[tree.find(A)] ;
    }
    else{
      ans[i+1] = ans[i] ;
    }
    tree.unite(A,B) ;
  }
  
  reverse(ALL(ans)) ;
  
  REP(i,m){
    cout << ans[i] <<endl ;
  }

  return 0 ;
}

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

int main(){
    int N, X, cnt = 1;
    cin >> N >> X;
    vector<int> L(N), D(N+1);
    for(int i=0; i<N; i++){
        cin >> L.at(i);
    }

    D.at(1)=0;
    for(int i=1; i<N+1; i++){
        D.at(i) = D.at(i-1) + L.at(i-1);
        if(D.at(i)<=X){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc065/tasks/arc076_b?fbclid=IwAR0STem5aakN0X9ogLTeeUqSxyYJ0_NVqqNFUqdgG6pbO2akcR7sJ3SojkY
*/
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define ROF(i,a,b) for(int i = a; i >= b; --i)
#define fast_read ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define maxN 2000005
using namespace std;
struct oo {
    int id;
    ll x , y;
}   Point[maxN];
struct edge {
    int u , v;
    ll w;
} e[maxN];
int n,p[maxN],h[maxN];
int res = 0;
ll s = 0 ;
int cnt = 0 ;
bool cmp( edge a , edge b) {
    return a.w <b.w;
}
bool ok1(oo a, oo b) {
    return a.x < b.x ;
}
bool ok(oo a, oo b) {
    return a.y < b.y ;
}
void make_set(int u) {
    p[u] = u;
    h[u] = 0 ;
}
int Find(int u) {
    while(u != p[u]) u = p[u] ;
    return u ;
}
bool Union(int u,int v) {
    int x = Find(u);
    int y = Find(v);
    if(x == y) return false;
    if(h[x] < h[y]) p[x] = y;
    else {
        p[y] = x;
        if(h[x] == h[y]) h[x] ++;
    }
    return true ;
}
int main () {
    fast_read
    cin>>n;
    FOR(i,1,n) {
        Point[i].id = i;
        cin>>Point[i].x>>Point[i].y;
    }
    sort(Point + 1, Point + 1 + n,ok1) ;
    FOR(i,1,n - 1)  {
        ll w = Point[i+1].x - Point[i].x;
        int u = Point[i].id, v = Point[i + 1].id;
        e[++cnt] = {u,v,w};
    }
    sort(Point + 1, Point + 1 + n,ok) ;
    FOR(i,1,n - 1)  {
        ll w = Point[i+1].y - Point[i].y;
        int u = Point[i].id, v = Point[i + 1].id;
        e[++cnt] = {u,v,w};
    }
    sort(e + 1, e+ 1 +cnt,cmp);
//    FOR(i,1,cnt)
//        cout<<e[i].u<<' '<<e[i].v<<' '<<e[i].w<<endl;
    FOR(i,1,n)
        make_set(i);
    FOR(i,1,cnt) {
        if(Union(e[i].u,e[i].v)) {
            s += e[i].w;
            res++;
            if(res == n - 1) {
                cout<<s;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main(){
    string s,t;
    int n;
    cin>>n>>s>>t;
    for(int i=0;i<n;i++){
        int f=1;
        for(int j=0;j<n-i;j++){
            if(s[i+j]!=t[j]) f=0;
        }
        if(f){
            cout<<i+n<<endl;
            break;
        }
        if(i==n-1) cout<<n*2<<endl;
    }
    return 0;
}

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

int N;

signed main() {
	deque<int> b;
	cin >> N;
	rep(i,N) {
		int a;
		cin >> a;
		if(i%2) {
			b.push_front(a);
		}else {
			b.push_back(a);
		}
	}
	if(N%2) {
		RREP(i,N) {
			cout << b[i] << (i ? " " : "");
		}
	}else {
		rep(i,N) {
			cout << (i ? " " : "") << b[i];
		}
	}
	cout << endl;
	return 0;
}

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

int n, k;
int a[200200];

bool check(int now){
	if(now == 0) return 0;
	int cnt = 0;
	rep(i, n){
		cnt += ((a[i] - 1) / now);
	}
	return cnt <= k;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	int lb = 0, ub = 1000000000;
	while(lb <= ub){
		int mid = (lb + ub) >> 1;
		if(check(mid)) ub = mid - 1;
		else lb = mid + 1;
	}
	cout << lb << endl;
	return 0;
}

Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector <int> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    vector <int> dp(n,INT_MAX);
    dp[0]=0;
    if(n==1)
    {
        cout<<v[0];
        return 0;
    }
    for(int i=1;i<n;i++)
    {
        int j=1;
        while(i-j>=0 && j<=k)
        {
            dp[i]=min(dp[i],abs(v[i]-v[i-j])+dp[i-j] );
            j++;
        }
    }
    //for(int i=0;i<n;i++)
      //  cout<<dp[i]<<" ";
    //cout<<endl;
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
A.append(0)
A.insert(0,0)
usualsum=0
for i in range(N+1):
    usualsum+=abs(A[i+1]-A[i])
#print(usualsum)

for i in range(1,N+1):
    print(usualsum+abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]))



Measured memory_bytes: 13920
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	int sum = 0;
	int right = 0;
	ll ans = 0;
	for(int left = 0; left < n; left++){
		while(right < n && ((sum + v[right]) == (sum ^ v[right])) ){
			//cout << sum + v[right] << " " << (sum ^ v[right]) << endl;
			sum += v[right];
			right ++ ;
		}
		//cout << left+1 << " " << right+1 << endl;
 		ans += right - left;
		sum -= v[left];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	
	int k,s,z;
	int ans;
	cin>>k>>s;
	for(int x=0;x<=k;x++)
	{
		for(int y=0;y<=k;y++)
		{
			z=s-(x+y);
			if(z>=0 && z<=k && x+y+z==s){
			
		
		ans++;
	    	
		}
	}
}
	 cout<<ans;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  map<ll, ll> mp;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    mp[a] += b;
  }

  ll ans, cnt = 0;
  for (auto x : mp) {
    cnt += x.second;
    if (k <= cnt) {
      ans = x.first;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7568
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b/a, c) << endl;
}



Measured memory_bytes: 256
N, M = list(map(int, input().split()))
li = [list(map(int, input().split()))[1:] for i in range(N)]

Ms = list(range(1, M+1))
ans = list(range(1, M+1))

for i in li:
    ans = list(set(ans) - (set(Ms) - set(i)))

print(len(ans))



Measured memory_bytes: 38384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;

int main(void){
    int N;

    cin >> N;
    FOR(i, 1, 10){
        FOR(j, 1, 10) {
            if(N == i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		double r = Double.parseDouble(br.readLine());

		DecimalFormat dmfmt = new DecimalFormat("0.000000");

		System.out.println(dmfmt.format(r * r * Math.PI) + " " + dmfmt.format(r * 2 * Math.PI));
	}

}

Measured memory_bytes: 17108
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    character(200000):: a
    integer(int64):: i,l,ia,ans
    integer(int64):: cnt(ichar("a"):ichar("z"))
    
    read*, a
    cnt(:) = 0
    l = len_trim(a)
    do i=1,l
        ia = ichar(a(i:i))
        cnt(ia) = cnt(ia) + 1
    end do

    ans = (l*(l-1))/2
    do i=ichar("a"),ichar("z")
        ans=ans-(cnt(i)*(cnt(i)-1))/2
    end do
    print'(i0)', ans+1
end program main

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

using namespace std;

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

  int sz, size = s.size();
  for (int i = 2; i <= size; i += 2) {
    s = s.substr(0, s.size() - 2);
    sz = s.size() / 2;
    if (s.substr(0, sz) == s.substr(sz, sz)) {
      cout << size - i << endl;
      return 0;
    }
  }

  return 0;
}

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

#ifdef LOCAL
  #include <contest/local.hpp>
#else
  #define LOG(...) do {} while (false)
#endif

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  string s;
  cin >> s;

  constexpr auto n = 13u;
  constexpr auto mod = static_cast <int64_t> (1e9 + 7);
  vector <int64_t> dp (n, 0);
  dp [0] = 1;

  int64_t mul = 1;
  for (auto ite = s.rbegin (); ite != s.rend (); ++ ite)
  {
    auto && elem = * ite;
    vector <int64_t> next_dp (n, 0);
    if (elem == '?')
    {
      for (auto k = 0u; k < 10; ++ k)
      {
        for (auto i = 0u; i < n; ++ i)
        {
          next_dp [(k * mul + i) % n] += dp [i];
          next_dp [(k * mul + i) % n] %= mod;
        }
      }
    }
    else
    {
      auto k = elem - '0';
      for (auto i = 0u; i < n; ++ i)
      {
        next_dp [(k * mul + i) % n] += dp [i];
        next_dp [(k * mul + i) % n] %= mod;
      }
    }
    mul *= 10;
    mul %= n;
    dp = move (next_dp);
    LOG (dp);
  }

  cout << dp [5] << endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

typedef long long ll;

int main(){
  ll N, W;
  std::cin >> N >> W;
  std::vector<ll> w(N);
  std::vector<ll> v(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> w[i] >> v[i];
  }
  
  std::vector<std::vector<ll> > dp(N + 1, std::vector<ll>(W + 1, 0) );
  
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j <= W ; j++){
      if(j >= w[i]) dp[i+1][j] = std::max(dp[i+1][j],dp[i][j-w[i]] + v[i]);
      dp[i+1][j] = std::max(dp[i+1][j], dp[i][j]);
    }
  }
  std::cout << dp[N][W] << std::endl;
  return 0;
}


Measured memory_bytes: 83152
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    char buf = 0;
    for (int i=0; i<n; i++) {
        cin >> buf;
        if (buf == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int sum = a + b;
  int ans  = min(k, a);
  k -= (a + b);
  if (k > 0) {
    ans -= k;
  }
  cout << ans << "\n";
  return 0;
}

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


int main()
{
	long long n;
	//vector<long long> a;
	cin >> n;
	//a.resize(n);
	long long max1 = 0;
	long long max2 = 0;
	long long temp;
	long long index;
	for (long long i = 0; i < n; ++i) {
		cin >> temp;
		if (max1 < temp) {
			index = i;
			max2 = max1;
			max1 = temp;
		}
		else if (max2 < temp) {
			max2 = temp;
		}
	}

	for (long long i = 0; i < n; ++i) {
		if (index == i) {
			cout << max2 << endl;
		}
		else {
			cout << max1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1664
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

access = []
for i in 1..N do
  access[i-1] = []
end
for j in 1..M do
  access[lines[j][0]-1].push(lines[j][1])
  access[lines[j][1]-1].push(lines[j][0])
end

label = []
finished = []

for i in 1..N do
  label[i-1] = "none"
  finished[i-1] = false
end

next_target = [1]
while next_target.length != 0 do
  last_target = next_target
  next_target = []
  last_target.each do |go_to|
    access[go_to-1].each do |go_from|
      if finished[go_from-1] == false then
        label[go_from-1] = go_to
        next_target.push(go_from)
        finished[go_from-1] = true
      end
    end
  end
end

puts "Yes"
for i in 2..N do
  puts label[i-1]
end

Measured memory_bytes: 54268
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

const int maxn = 100005;

struct Edge {
    int v, x;
} E[maxn*2];

int l[maxn], e, n, m;
typedef long long ll;

void init() {
    memset(l, -1, sizeof(l)); e = 0;
}

inline void insert(int u, int v) {
    E[e].v = v, E[e].x = l[u], l[u] = e++;
    E[e].v = u, E[e].x = l[v], l[v] = e++;
}

int cr[maxn][2];
int vis[maxn];

int cnt[2];

void cal(int u) {
    queue<pair<int, int> > q;
    cnt[0] = cnt[1] = 0;
    memset(cr, 0, sizeof(cr));
    cr[u][0] = 1;
    q.push(make_pair(u, 0));
    while (!q.empty()) {
        pair<int, int> f = q.front(); q.pop();
        for (int p = l[f.first]; p >= 0; p = E[p].x) {
            if (!cr[E[p].v][!f.second]) {
                cr[E[p].v][!f.second] = 1;
                q.push(make_pair(E[p].v, !f.second));
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (cr[i][0]) cnt[0]++;
        if (cr[i][1]) cnt[1]++;
    }
}

ll ans = 0;

int tmp = 0;

void dfs(int u) {
    vis[u] = 1;
    ans += cnt[tmp^1];
    if (cr[u][tmp^1]) ans--;
    for (int p = l[u]; p >= 0; p = E[p].x) {
        if (!vis[E[p].v]) {
            vis[E[p].v] = 1;
            tmp = tmp^1;
            dfs(E[p].v);
            tmp = tmp^1;
        }
    }
}

int main() {
    init();
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        insert(a, b);
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            tmp = 0;
            cal(i);
            dfs(i);
        }
    }
    cout << ans/2-m << endl;
    return 0;
}

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

int main(){

  double a,b;
  double h,m;
  cin >> a >> b >> h >> m;

  long double Apoint,Bpoint;
  long double height,distance;
  long double adeg,bdeg;
  static const long double pi = 3.141592653589793;

  adeg=(h*60+m)*0.5;
  bdeg=m*6;
  double tpi=180;

  double aX,aY,bX,bY;

  aY=a*sin(adeg*pi/tpi);
  aX=a*cos(adeg*pi/tpi);
  bY=b*sin(bdeg*pi/tpi);
  bX=b*cos(bdeg*pi/tpi);

  double xdist,ydist;

  xdist=pow(aX-bX,2);
  ydist=pow(aY-bY,2);

  distance=pow(xdist+ydist,0.5);

  cout << setprecision(20) << distance << endl;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
typedef long long ll;
typedef long double ld;
using namespace std;

const int N = 18;
int n, M;

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

  cin >> n;
  M = 1 << n;

  multiset<int> all;

  for (int i = 0; i < M; i++) {
    int s; cin >> s;
    all.insert(s);
  }

  multiset<int> unused = all;
  multiset<int> cur = {*unused.rbegin()};

  unused.erase(unused.find(*unused.rbegin()));

  for (int i = 0; i < n; i++) {
    multiset<int> ncur = cur;

    for (int x : cur) {
      auto it = unused.lower_bound(x);
      if (it != unused.begin()) {
        it--;
        ncur.insert(*it);
        unused.erase(it);
      }
    }

    cur = ncur;
  }

  cout << (all == cur ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 37248
results = []

while True:
    N = int(input())
    if N == 0:
        break
       
    A = [list(map(int, input().split())) for _ in range(N)]
    K = list(map(int, input().split()))
    
    count = 0
    for i in range(N):
        tmp = 0
        A[i][0] = -1
        for j in range(K[0]):
            if K[j+1] in A[i]:
                tmp += 1
                
        if tmp == K[0]:
            count += 1
            res = i + 1
    
    if count == 1:
        results.append(res)
    else:
        results.append(-1)
        
for result in results:
    print(result)


Measured memory_bytes: 5756
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	for {
		h := nextInt()
		w := nextInt()
		if h == 0 {
			break
		}
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				fmt.Printf("#")
			}
			fmt.Println()
		}
		fmt.Println()
	}

}



Measured memory_bytes: 1076
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if((a+b)%2 !=0)cout <<"IMPOSSIBLE";
    else cout << (a+b)/2;
    return 0;
}

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

int main() {
	
	string s, t;
	cin >> s >> t;
	string ans = "UNRESTORABLE";
	int ns = s.size(), nt = t.size(); 
	for(int i = ns - nt; i >= 0; i--){
		string tmp = s.substr(i, nt);
		bool all_ok = true;
		rep(j, nt){
			if(tmp[j] != t[j] && tmp[j] != '?') all_ok = false;
		}
		if(all_ok){
			rep(j, nt){
				s[i + j] = t[j];
			}
			rep(j, ns){
				if(s[j] == '?') s[j] = 'a';
			}
			ans = s;
			
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
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;
}

Measured memory_bytes: 1216
N = int(input())
h_list = list(map(int,input().split()))
h_list.reverse()
def func():
    for i in range(N-1):
        if h_list[i+1] <= h_list[i]:
            pass
        elif h_list[i+1] == h_list[i]+1:
            h_list[i+1] -= 1
        elif h_list[i+1] >= h_list[i]+2:
            return False
    return True

if func():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63984
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace AGC34
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(i => int.Parse(i) - 1).ToArray();
            var S = Console.ReadLine();
            if (input[3] < input[4])
                Console.WriteLine(Regex.IsMatch(S.Substring(input[1], input[4] - input[1] + 1), @"##") ? "No" : "Yes");
            else
            {
                if (Regex.IsMatch(S.Substring(input[1], input[3] - input[1] + 1), @"##"))
                {
                    Console.WriteLine("No");
                    return;
                }
                Console.WriteLine(Regex.IsMatch(S.Substring(input[2] - 1, input[4] - input[2] + 3), Regex.Escape("...")) ? "Yes" : "No");
            }
        }
    }
}


Measured memory_bytes: 15320
#include <iostream>
using namespace std;
int main()
{
	string s;
	cin >> s;
	char c=s[s.size()/2];
	for (int k=1;k<=s.size();k++)
	{
		if (k-1>=s.size()-k)
		{
			if (s[k-1]!=c || s[s.size()-k]!=c)
			{
				printf("%d",k-1);
				return 0;
			}
		}
	}
	printf("%d",s.size());
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll k,ans=0,num=7;
    cin >> k;
    vector<ll> a;
    ll index = 1;
    bool flag = true;
    if(num%k == 0){
        cout << 1 << endl;
        return 0;
    }
    rep(i,k){
        if(num == 0){
            flag = false;
            break;
        }
        a.pb(num);
        num = (num*10+7)%k;
        index++;
    }
    if(flag){
        cout << -1 << endl;
    }else{
        cout << index << endl;
    }
    return 0;

}


Measured memory_bytes: 11544
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll n;
    cin >> n;
    vector<char> colors(n,0);
    string co;
    cin >> co;

    for(ll i = 0;i < n;++i){
        colors[i] = co[i];
    }

    ll posl = 0;
    ll posr = n - 1;

    ll c = 0;
    while (true){
        while(colors[posl] == 'R')++posl;
        while(colors[posr] == 'W')--posr;
      //  cout << posl << ":" << posr << endl;

        if(posl - 1 == posr){
            cout << c << endl;
            return 0;
        }

        colors[posl] = 'R';
        colors[posr] = 'W';
        ++c;
    }



}




Measured memory_bytes: 3620
package main

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

func main() {
	io := newIo()
	n := io.nextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = io.nextInt()
	}

	ans := math.MaxInt64
	for j := 0; j <= 1; j++ {
		miniAns := 0
		now := 0
		for i, v := range a {
			k := pow(-1, (i+j)%2)
			now += v
			if sign(now) != k {
				miniAns += abs(k - now)
				now = k
			}
		}
		ans = min(ans, miniAns)
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func sign(a int) int {
	if a != 0 {
		return a / abs(a)
	}
	return 0
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func pow(a, b int) int {
	res := 1
	for range make([]struct{}, b) {
		res *= a
	}
	return res
}

type io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}


Measured memory_bytes: 6912
use std::collections;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! print_vec {
    ($vec:expr) => {
        for (i, &v) in $vec.iter().enumerate() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", v);
        }
        println!();
    };
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(i64;;);
    let mut dq = collections::VecDeque::new();
    for (i, v) in vs.iter().enumerate() {
        if n % 2 == 1 {
            if i % 2 == 0 {
                dq.push_front(v);
            } else {
                dq.push_back(v);
            }
        } else {
            if i % 2 == 0 {
                dq.push_back(v);
            } else {
                dq.push_front(v);
            }
        }
    }
    print_vec!(dq);
}


Measured memory_bytes: 10988
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int N ;
    cin >> N;
    vector<int>P(N);
    rep(i, 0, N) {
        cin >> P[i];
    }
    int ans = 1;
    int minP = P[0];
    rep(i, 1, P.size()){
        if(minP > P[i]){
            minP = P[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 100001;
const int maxk = 17;
struct info{
	int v, c, w;
};
struct query{
	int id, c, w, y;
};
int n, sz[maxn], g[maxn], top[maxn], up[maxn], depth[maxn], m;
long long ans[maxn];
vector < info > edge[maxn];
vector < query > ask[maxn];
inline int get_lca(int a, int b){
	while(g[a] != g[b])
		if(depth[top[g[a]]] < depth[top[g[b]]])b = up[top[g[b]]];
		else a = up[top[g[a]]];
	return depth[a] < depth[b] ? a : b;
}
void dfs1(int now, int last = 1){
	static int now_d = 0;
	up[now] = last;
	depth[now] = now_d++;
	sz[now] = 1;
	if(last != now){
		for(int i = 0;i < edge[now].size();++i)
			if(edge[now][i].v == last){
				edge[now].erase(edge[now].begin() + i);
				break;
			}
	}
	for(int i = 0;i < edge[now].size();++i){
		dfs1(edge[now][i].v, now), sz[now] += sz[edge[now][i].v];
		if(sz[edge[now][i].v] > sz[edge[now][0].v])swap(edge[now][i], edge[now][0]);
	}
	--now_d;
}
void dfs3(int now){
	static int now_g = 0;
	g[now] = now_g;
	if(!top[now_g])top[now_g] = now;
	if(!edge[now].empty()){
		dfs3(edge[now][0].v);
		for(int i = 1;i < edge[now].size();++i)
			++now_g, dfs3(edge[now][i].v);
	}
}
void dfs2(int now, int last = 1){
	static int total_w = 0;
	static int q_of[maxn] = {};
	static int w_of[maxn] = {};
	for(auto &i : ask[now]){
		ans[i.id] += (total_w - w_of[i.c] + q_of[i.c] * i.y) * i.w;
	}
	for(auto &i : edge[now]){
		if(i.v != last){
			++q_of[i.c];
			w_of[i.c] += i.w;
			total_w += i.w;
			dfs2(i.v, now);
			--q_of[i.c];
			w_of[i.c] -= i.w;
			total_w -= i.w;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for(int a, b, c, d, i = 1;i < n;++i){
		cin >> a >> b >> c >> d;
		edge[a].push_back({b, c, d});
		edge[b].push_back({a, c, d});
	}
	dfs1(1);
	dfs3(1);
	for(int i = 0, x, y, u, v;i < m;++i){
        cin >> x >> y >> u >> v;
		ask[u].push_back({i, x, 1, y});
		ask[v].push_back({i, x, 1, y});
		ask[get_lca(u, v)].push_back({i, x, -2, y});
	}
	dfs2(1);
	for(int i = 0;i < m;++i)cout << ans[i] << '\n';
}


Measured memory_bytes: 23924
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("out.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
//struct compare
//{
//  bool operator()(const int& l, const int& r)
//  {
//      return l>r;
//  }
//};

bool cmp(int a, int b)
{
    return a<b;
}
int on(int mask,int st)
{
    return mask|(1<<st);
}
int off(int mask,int st)
{
    return mask&(~(1<<st));
}
bool check(int mask,int st)
{
    return mask&(1<<st);
}
ll inf=1e18;
ll mod=1e9+7;
ll vis[30];
int main()
{
//    READ;
    for(int i=0;i<26;i++)
        vis[i]=1;
    int n;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        vis[s[i]-'a']++;
    }
    ll ans=1;
    for(int i=0;i<26;i++)
    {
        ans*=vis[i];
        ans%=mod;
    }
    cout<<ans-1<<endl;

}


Measured memory_bytes: 512