akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  long long K,ans=0;
  cin >> S >> K;
  int N = S.size();
  
  int l=1,r=1;
  for(int i=1;i<N;i++){
    if(S[i]==S[0]) l++;
    else break;
  }
  for(int i=N-2;i>=0;i--){
    if(S[i]==S[N-1]) r++;
    else break;
  }
  if(S[0]!=S[N-1]){
    l=0;
    r=0;
  }
  
  if(l==N){
    ans = (N*K) / 2;
    cout << ans << endl;
    return 0;
  }
  
  int count = 1;
  for(int i=l+1;i<N-r;i++){
    if(S[i]==S[i-1]) count++;
    else{
      ans += (count/2) * K;
      count = 1;
    }
  }
  ans += (count/2) * K;
  ans += l/2;
  ans += r/2;
  ans += ((l+r)/2) * (K-1);
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;


int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int>A(N+1, 1);
  for(int i=0;i<M;i++){
    int a;
    cin >> a;
    A[a]=0;
  }
  
  vector<long long int>p(N+1);
  p[0]=1;
  for(int now=0;now<N;now++){
    for(int next=now+1;next<=min(N,now+2);next++){
      if(A[next]){
        p[next]+=p[now];
		p[next]%=mod;
      }
    }
  }
   
  cout<<p[N]<<endl;

}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a, b;
  string s, z;
  cin >> s >> z;
  a = s.size();
  b = z.size();
  for(int i = 0; i < a; i++){
    if(s[i] != z[i]){
      cout << "No\n";
      break;
    }
    if(i == a - 1 && a == b - 1){
      cout << "Yes\n";
    }
  }
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	ll ans = 0;

	if (a <= k) {
		ans += a;
		k -= a;
	}
	else {
		ans += k;
		k -= a;
	}

	k -= b;

	if (k > 0) {
		if (c >= k) ans -= k;
		else ans -= c;
	}
		
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int a, b;
    char op;
    cin >> a >> op >> b;
    cout << (op == '+' ? a + b : a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FILLINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a, T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a, T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) { for(auto &e : t) fill_v(e, v); }
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const lint MOD = 1000000007;

void _main() {
    int N;
    cin >> N;
    N %= 10;
    if (N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
    else if (N == 3) cout << "bon" << endl;
    else cout << "hon" << endl;
}

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

Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<bitset>
using namespace std;
#define ll long long
#define re register
#define mp make_pair
typedef pair<int,int> pii;
inline int gi()
{
	int sum=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
ll n,x; 
int main()
{
	scanf("%lld%lld",&n,&x);int tmp=n;ll len=1,ans=0;
	while(tmp--)len=(len<<1)+3;
	while(x&&n>=0)
	{
		if(x>=(len+1)/2)ans+=1ll<<n,x-=(len+1)/2;
		else x--;
		len=(len-3)/2;n--;
	}
	printf("%lld\n",ans); 
	return 0;
}


Measured memory_bytes: 256
def f(num, base):
    ret = 1
    while num >= ret:
        ret *= base
    return ret // base


a = {int(input())}
cnt = 0
while all(a):
    a = {x - f(x, 6) for x in a} | {x - f(x, 9) for x in a}
    cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b; }

inline void solve(){

    vpi x;
    int n, a[200005],b[200005];
    cin >> n;
    FOR(i,n){
        cin >> a[i] >> b[i] ;
        x.bash(pii(b[i],a[i]));
    }
    sort(ALL(x));
    int sum = 0;
    bool is = true;
    FOR(i,n){
        sum += x[i].second;
        if(sum > x[i].first)
            is = false;
    }

    cout << (is?"Yes":"No") fin;
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 3568
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [usize; m]
    }
    let d = 1000000007;
    let a = vec![vec![2, 1, 1], vec![2, 1, 0], vec![1, 1, 1]];
    let b = vec![vec![1, 0, 0], vec![2, 1, 0], vec![1, 1, 1]];
    let mut mat = vec![vec![1, 0, 0], vec![0, 1, 0], vec![0, 0, 1]];
    let mut p = 0;
    for &x in &v {
        mat = matmul_m(&matpow_m(&a, x - p - 1, d), &mat, d);
        mat = matmul_m(&b, &mat, d);
        p = x;
    }
    mat = matmul_m(&matpow_m(&a, n - p - 1, d), &mat, d);
    println!("{}", (mat[0][0] + mat[1][0] + mat[2][0]) % d);
}

fn matmul_m(a: &Vec<Vec<usize>>, b: &Vec<Vec<usize>>, d: usize) -> Vec<Vec<usize>> {
    let mut ret = vec![vec![0; b[0].len()]; a.len()];
    for i in 0..a.len() {
        for k in 0..b.len() {
            for j in 0..b[0].len() {
                ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % d;
            }
        }
    }
    ret
}

fn matpow_m(a: &Vec<Vec<usize>>, mut p: usize, d: usize) -> Vec<Vec<usize>> {
    let mut ret = vec![vec![0; a[0].len()]; a.len()];
    for i in 0..a.len() {
        ret[i][i] = 1;
    }
    let mut r = a.clone();
    while p > 0 {
        if p & 1 == 1 {
            ret = matmul_m(&ret, &r, d);
            p ^= 1;
        } else {
            r = matmul_m(&r, &r, d);
            p >>= 1;
        }
    }
    ret
}


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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD 1000000007
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;
int k;

int dp[100005];
int heights[100005];


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

    cin >> n >> k;

    memset(dp, 0x3f, sizeof(dp));
    dp[0]=0;

    poiu(n) cin >> heights[i];

    for(int i=0; i<n; ++i) {
        for( int j=i+1; j<=i+k && j<n; j++) {
            min_self(dp[j], dp[i]+abs(heights[i]-heights[j]));
        }
    }

    cout << dp[n-1] << endl;
    return 0;

}



Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 100002
#define MOD 1000000007

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
char ch;
int n,c[N],x;
ll ans;

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

inline ll pow2(int t)
{
	ll rtn=1,w=2;
	while(t)
	{
		if(t&1)rtn=rtn*w%MOD;
		w=w*w%MOD;
		t>>=1;
	}
	return rtn;
}

int main(void)
{
	read(n);
	rep(i,1,n)
	{
		read(x),c[x]++;
		if((n&1)&&(x&1))
		{
			printf("0");
			return 0;
		}
	}
	rep(i,1,n)if(c[i]!=0&&c[i]!=2){printf("0");return 0;}
	printf("%lld",pow2(n>>1));
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a;i>0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

double n;
ll a[100002];
ll increans[40];
ll p;

ll getres(ll now, ll from){
    ll ret = now;
    for(int i = from; i >= 0; i--)if(increans[i]>0)ret += increans[i];
    return ret;
}

int main() {
    ll k;
    cin >> n >> k;
    REP(i, n)cin >> a[i];
    while(true){
        if(k < pow(2, p))break;
        p++;
    }
    REP(i, 40) {
        ll cnt0 = 0;
        ll cnt1 = 0;
        REP(j, n){
            if(a[j] & 1L << i){cnt1++;}
            else{cnt0++;}
        }
        increans[i] = (cnt0 - cnt1) * pow(2, i);
    }
    jkl;
    ll tmp = 0;
    REP(i, n)tmp += a[i];
    ll ans = tmp;
    for(int i = 40; i >= 0; i--){
        if(k & 1L << i){
            ans = max(ans, getres(tmp, i-1));  //set the i-bit to 0 and rest is free.
            tmp += increans[i];              //set i-bit to 1.
        }
        ans = max(ans, tmp);
    }
    print(ans);
}

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

int main() {
  ll a[3];
  bool f=true;
  for(int i=0;i<3;i++){
    cin>>a[i];
    if(a[i]%2==0) f=false;;
  }
  sort(a,a+3);
  if(f) cout<<a[0]*a[1]<<endl;
  else cout<<"0"<<endl;
}


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

const int N_COLOR = 10000;

void find_max_vals(int vals[], int N,
    int *cnt, int *first_idx, int *max_val) {
  *max_val = -1;
  for (int i=0; i<N; i++) {
    if (vals[i] > *max_val) {
      *cnt = 1;
      *first_idx = i;
      *max_val = vals[i];
    } else if (vals[i] == *max_val) {
      *cnt += 1;
    }
  }
}

int get_second_max(int vals[], int N, int max_val) {
  int second_max_val = -1;
  for (int i=0; i<N; i++) {
    if (vals[i] > second_max_val && vals[i] < max_val) {
      second_max_val = vals[i];
    }
  }
  return second_max_val;
}

int main() {
  int N;
  std::cin >> N;
  int a[N];
  for (int i=0; i<N; i++) std::cin >> a[i];
  
  int scores[N_COLOR];
  for (int j=0; j<N_COLOR; j++) scores[j] = 0;
  
  int cnt, first_idx, max_val;
  for (int i=0; i<N; i++) {
    find_max_vals(scores, N, &cnt, &first_idx, &max_val);
    if (cnt > 1) {
      for (int j=0; j<N_COLOR; j++) scores[j] = max_val;
    } else {
      for (int j=0; j<N_COLOR; j++) {
        if (j == first_idx) {
          scores[j] = get_second_max(scores, N, max_val);
        } else {
          scores[j] = max_val;
        }
      }
    }
    
    int color_idx = a[i] - 1;
    scores[color_idx] += 1;
  }
  
  find_max_vals(scores, N, &cnt, &first_idx, &max_val);
  std::cout << N - max_val << std::endl;
  
  return 0;
}


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

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int n, l, a[N];
PII best = {-1, -1};

int main()
{
    init_ios();
    cin >> n >> l;
    for (int i = 1; i <= n; ++i)
    	cin >> a[i];
    for (int i = 1; i < n; ++i) {
    	if (a[i]+a[i+1] > best.ST)
    		best = {a[i]+a[i+1], i};
    }
    if (best.ST < l) {
    	cout<<"Impossible\n";
    	return 0;
    }
    cout<<"Possible\n";
    for (int i = 1; i < best.ND; ++i)
    	cout<<i<<"\n";
    for (int i = n-1; i > best.ND; --i)
    	cout<<i<<"\n";
    cout<<best.ND<<"\n";
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int gcd(int a,int b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int main(){
  int K; cin>>K;
  ll ans=0;
  for(int i=1; i<=K; i++){
    for(int j=1; j<=K; j++){
      int ggccdd=gcd(i, j);
      for(int k=1; k<=K; k++){
        ans+=gcd(ggccdd, k);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, m, c = na()
b = na()
a = nan(n)

ans = 0
for i in range(n):
    s = 0
    for j in range(m):
        s += a[i][j] * b[j]
    if s + c > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  ll X;
  cin>>X;
  cout<<X/500*1000+X%500/5*5<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
const int MAXN=1005;
 
int n,m,A,B;
char grid[MAXN][MAXN];

void debug()
{
	puts("---debug---");
	for(int i=1;i<=n;i++)
		puts(grid[i]+1);
	puts("---debug---");
}

int main()
{
	scanf("%d%d%d%d",&n,&m,&A,&B);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			grid[i][j]='.';
	if(n%2==1)
		for(int j=1;j<m&&A;j+=2)
			grid[n][j]='<',grid[n][j+1]='>',A--;
	if(m%2==1)
		for(int i=1;i<n&&B;i+=2)
			grid[i][m]='^',grid[i+1][m]='v',B--;
	if(n%2==1&&m%2==1&&A%2==1&&B%2==1)
	{
		grid[n][m-2]='<',grid[n][m-1]='>';
		grid[n-2][m-1]='<',grid[n-2][m]='>';
		grid[n-2][m-2]='^',grid[n-1][m-2]='v';
		grid[n-1][m]='^',grid[n][m]='v';
		A--,B--;
	}
	//debug();
	for(int i=1;i<=n&&A;i+=2)
		for(int j=1;j<=m&&A;j+=2)
		{
			if(grid[i][j]=='.'&&grid[i][j+1]=='.'&&A)
				grid[i][j]='<',grid[i][j+1]='>',A--;
			if(grid[i+1][j]=='.'&&grid[i+1][j+1]=='.'&&A)
				grid[i+1][j]='<',grid[i+1][j+1]='>',A--;
		}
	//debug();
	for(int i=1;i<=n&&B;i+=2)
		for(int j=1;j<=m&&B;j+=2)
		{
			if(grid[i][j]=='.'&&grid[i+1][j]=='.'&&B)
				grid[i][j]='^',grid[i+1][j]='v',B--;
			if(grid[i][j+1]=='.'&&grid[i+1][j+1]=='.'&&B)
				grid[i][j+1]='^',grid[i+1][j+1]='v',B--;
		}
	//debug();
	if(A||B)
		puts("NO");
	else
	{
		puts("YES");
		for(int i=1;i<=n;i++)
			puts(grid[i]+1);
	}
	return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
using namespace std;

const int SIEVE_SIZE = 1000000;

bool sieve[SIEVE_SIZE + 1];
int prime_count[SIEVE_SIZE + 1];

int main()
{
	int i,j,n,l,r;
	
	sieve[0] = sieve[1] = true;
	for (i = 2; i * i <= SIEVE_SIZE; i++){
		if (sieve[i]) continue;
	   	for (j = i*i; j <= SIEVE_SIZE; j += i){
	    	 sieve[j] = true;
	    }
	}
	
	while(scanf("%d", &n) != EOF){
		for(l = n-1; sieve[l] == true; l--);
		for(r = n+1; sieve[r] == true; r++);
		printf("%d %d\n", l, r);
	}
	
	
	return(0);
}

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

using namespace std;
typedef long long int lld;
#define INF 1000000000000000000
#define MOD 1000000007
double DP[301][301][301];
int n;
int arr[400];
double compute(int a,int b,int c){//cout<<a<<" "<<b<<" "<<c<<endl;
	if(a==-1 || b==-1 || c==-1)return 0;
	if(DP[a][b][c]!=-1)return DP[a][b][c];
	
	double A=(double)a/(a+b+c);
	double B=(double)b/(a+b+c);
	double C=(double)c/(a+b+c);
	double D=(double)n/(a+b+c);
	//cout<<D<<" "<<n<<" "<<(a+b+c)<<endl;
	DP[a][b][c]=compute(a-1,b,c)*A+compute(a+1,b-1,c)*B+compute(a,b+1,c-1)*C+D;
	return DP[a][b][c];
}
int main(){
	cin>>n;
	int cnt[3];
	for(int j=0;j<3;j++)cnt[j]=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		cnt[arr[i]-1]++;
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;k<=n;k++)DP[i][j][k]=-1;
		}
	}
	DP[0][0][0]=0;
	double ans=0;
	ans=compute(cnt[0],cnt[1],cnt[2]);
	cout<<setprecision(15)<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 213376
N = gets.to_i
a = gets.split(' ').map(&:to_i)
ss = [0]
sum = 0
N.times do |i|
	sum += a[i]
	ss[i + 1] = sum
end
cand = []
e = sum
2.upto(N - 2) do |j|
	c = ss[j]
	i = ss.bsearch_index{|n| n >= c / 2}
	i -= 1 if i == j
	i -= 1 if (c / 2 - ss[i - 1]).abs < (c / 2 - ss[i]).abs 
	b = ss[i]
	k = ss.bsearch_index{|n| n >= (c + e) / 2}
	k -= 1 if k == N
	k -= 1 if ((c + e) / 2 - ss[k - 1]).abs < ((c + e) / 2 - ss[k]).abs 
	d = ss[k]
	cand.push([b, c - b, d - c, e - d].max - [b, c - b, d - c, e - d].min)
end
puts cand.min

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


int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n){
        cin >> a.at(i);
        a.at(i)--;
    }
    rep(i, n){
        cin >> b.at(i);
    }
    rep(i, n-1){
        cin >> c.at(i);
    }
    int sum = 0;
    vector<int> vec_c;
    rep(i, n) sum += b.at(i);
    int x = a.at(0);
    for(int i = 1; i < n; i++){
        if(x == a.at(i)-1) vec_c.push_back(c.at(x));
        x = a.at(i);
    }
    int sum_c = 0;
    rep(i,vec_c.size()) sum_c += vec_c.at(i);
    cout << sum + sum_c << endl;

    return 0;
}


Measured memory_bytes: 3600
N=int(input())
*A,=map(int,input().split())
*B,=map(int,input().split())

ca=cb=0
for a,b in zip(A,B):
    ca+=max(0,(b-a)//2)
    cb+=max(0,a-b)

print('YNeos'[ca<cb::2])

Measured memory_bytes: 10448
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def add_mod(a,b): return (a+b) % MOD

N = iin()
h = iln()

dp = [10**10 for _ in range(N)]
dp[0] = 0

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

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

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  int n = s.size();
  rep(i, n) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3912
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  std::string s;
  int w = 0;
  std::cin >> s;
  for (std::size_t i = 0; i < s.length(); ++i) {
    if (i < (s.length() + 1) / 2) {
      w += (s[i] == 'p'? -1: 0);
    } else {
      w += (s[i] == 'g'? +1: 0);
    }
  }
  std::cout << w << std::endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, d;
	
	cin >> a >> b >> c >> d;
	
	if (a+b < c+d){
		cout << "Right" << "\n";
	}
	else if (a+b > c+d){
		cout << "Left" << "\n";
	}
	else {
		cout << "Balanced" << "\n";
	}
	
	return (0);
}

Measured memory_bytes: 256
n,x=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
count = 0
0.upto(n-2) do |i|
  diff = a[i] + a[i+1] - x
  if diff > 0
    if diff > a[i+1]
      a[i] -= diff - a[i+1]
      a[i+1] = 0
    else
      a[i+1] -= diff
    end
    count += diff
  end
end
puts count


Measured memory_bytes: 8580
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
char s[N];
int main(){
	scanf("%s",s);int l=strlen(s);
	if(s[l-1]=='s')s[l++]='e';
	s[l++]='s';
	puts(s);
	return 0;
} 

Measured memory_bytes: 3684
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
	double x1, x2, w, y1, y2, h, ans;
	cin >> x1 >> y1 >> x2 >> y2;
	w = x1 - x2;
	h = y1 - y2;
	ans = w*w + h*h;
	ans = sqrt(ans);
	printf("%.8f\n", ans);
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int zero = S.length(), one = S.length();
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '1') {
      one = min(one,max(i,(int)S.length()-i-1));
    }
    if (S[i] == '0') {
      zero = min(zero,max(i,(int)S.length()-i-1));
    }
  }
  cout << max(one,zero);
}

Measured memory_bytes: 3736
N = int(input())
A = list(map(int, input().split()))
B = 0
for i in range(N):
  if A[i]%6 == 0 or A[i]%10 == 0:
    continue
  elif A[i]%2 == 1:
    continue
  else:
    B = 1
print('APPROVED' if B==0 else 'DENIED')


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

N = int(input())
print("{}".format(str(N).count('2')))


Measured memory_bytes: 2940
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7


N,M = I()
links = [[] for _ in range(N)]
link = []
for i in range(M):
    a,b = I()
    links[a-1].append(b-1)
    links[b-1].append(a-1)
    link.append((a-1,b-1))
def dfs(n):
    if visited[n] == 1:
        return
    visited[n] = 1
    L = linky[n]
    for l in L:
        dfs(l)
ans = 0
for i in range(M):
    visited = [0]*N
    linky = deepcopy(links)
    a,b = link[i]
    linky[a].remove(b)
    linky[b].remove(a)
    dfs(0)
    if 0 in visited:
        ans += 1
print(ans)

Measured memory_bytes: 80152
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[fastout]
fn main() {
    input! {
        n:usize,
    }
    let mut v = vec![];
    for _ in 0..n {
        input! {
            a:usize,b:usize,
        }
        if a == b {
            v.push(true);
        } else {
            v.push(false);
        }
    }
    let mut ans = false;
    for i in 0..n - 2 {
        if v[i] && v[i + 1] && v[i + 2] {
            ans = true;
        }
    }
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2200
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
 
typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
 
#define ALL(a) (a).begin(),a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))


int main(){
  string a;
  cin >> a;
  int N = a.length();
  int b[N];
  REP(i,N)b[i]=0; 
  //jがi回後にいる場所
  int dp1[N];
  REP(j,N){
    if(a[j]=='R') dp1[j] = j+1;
    else dp1[j] = j-1;
  }
  int dp2[N],dp4[N],dp8[N],dp16[N],dp32[N],dp64[N],dp128[N],dp256[N],dp512[N];
  int dp1024[N],dp2048[N],dp4096[N],dp8192[N],dp16384[N],dp32768[N],dp65536[N],dp131072[N];
  REP(j,N) dp2[j] = dp1[dp1[j]];
  REP(j,N) dp4[j] = dp2[dp2[j]];
  REP(j,N) dp8[j] = dp4[dp4[j]];
  REP(j,N) dp16[j] = dp8[dp8[j]];
  REP(j,N) dp32[j] = dp16[dp16[j]];
  REP(j,N) dp64[j] = dp32[dp32[j]];
  REP(j,N) dp128[j] = dp64[dp64[j]];
  REP(j,N) dp256[j] = dp128[dp128[j]];
  REP(j,N) dp512[j] = dp256[dp256[j]];
  REP(j,N) dp1024[j] = dp512[dp512[j]];
  REP(j,N) dp2048[j] = dp1024[dp1024[j]];
  REP(j,N) dp4096[j] = dp2048[dp2048[j]];
  REP(j,N) dp8192[j] = dp4096[dp4096[j]];
  REP(j,N) dp16384[j] = dp8192[dp8192[j]];
  REP(j,N) dp32768[j] = dp16384[dp16384[j]];
  REP(j,N) dp65536[j] = dp32768[dp32768[j]];
  REP(j,N) dp131072[j] =dp65536[dp65536[j]];

  REP(i,N){
    int x = dp131072[i];
    b[x]++;
  }
  REP(i,N)cout << b[i] << " ";
  cout << endl;
}


Measured memory_bytes: 8064
// 2019/12/05 Tazoe

#include <iostream>
using namespace std;

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

	long long T;
	cin >> T;

	int Q;
	cin >> Q;

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

		int D;
		cin >> D;

		if(D==1){
			A[i] += T;
		}
		else{
			A[i] -= T;
		}
	}
	A[0] = A[1]-1;
	A[N+1] = A[N]+1;

	for(int i=1; i<=N-1; i++){
		if(A[i]<=A[i+1])
			continue;

		A[i] = A[i+1] = (A[i]+A[i+1])/2;

		int j = i;
		while(A[j-1]>A[j]){
			A[j-1] = A[j];
			j--;
		}

		j = i+1;
		while(A[j]>A[j+1]){
			A[j+1] = A[j];
			j++;
		}
	}
/*
	for(int i=1; i<=N; i++){
		cout << A[i] << endl;
	}
*/

	for(int i=0; i<Q; i++){
		int X;
		cin >> X;

		cout << A[X] << endl;
	}

	return 0;
}



Measured memory_bytes: 3864
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

const int maxn = 2e5 + 50;
vector<int> adj[maxn];
bool used[maxn];
int val[maxn];

void dfs(int s, int curr_val){
	int now = val[s];
	val[s] += curr_val;
	used[s] = true;
	for(auto u:adj[s]){
		if(!used[u]){
			dfs(u, curr_val + now);
		}
	}
}

int main(){
	FIO
	
	int n, q;cin >> n >> q;
	forn(i, n - 1){
		int u, v;cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	while(q--){
		int p, x;cin >> p >> x;
		val[p] += x;
	}
	dfs(1, 0);
	for1(i, n)cout << val[i] << " ";
	return 0;
}


Measured memory_bytes: 20608
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int n,max_num = -1000001,min_num = 1000001,tmp;
	long long int sum = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		sum += tmp;
		max_num = max(max_num,tmp);
		min_num = min(min_num,tmp);
	}
	printf("%d %d %lld\n",min_num,max_num,sum);
}



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

int main(){
	vector<int>v;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
		int p;
        cin>>p;
        v.push_back(p);
    }
    int cnt=0;
    for(int i=2;i<v.size();i++){
    	vector<int>t;
        t.push_back(v[i-2]);
        t.push_back(v[i-1]);
        t.push_back(v[i]);
        sort(t.begin(),t.end());
        if(t[1]==v[i-1])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    char ch;
    while(1){
        scanf("%c",&ch);
        if(isupper(ch)!=0){
            ch=tolower(ch);
            printf("%c",ch);
        }else if(islower(ch)!=0){
            ch=toupper(ch);
            printf("%c",ch);
        }else{
            printf("%c",ch);
        }
        if(ch=='\n') break;
    }

    
    return 0;
}



Measured memory_bytes: 2040
#include <stdio.h>
int N;

void Process(int A[ ], int n){
	int i;
	for(i=0;i<n-1;i++)
		printf("%d ",A[i]);
	/*while(n>1){
		printf("%da", *A++);
	n--;
}*/
	printf("%d\n",A[i]);
}

void InsertionSort(int A[ ], int n){
	int i,j,v;
	for(i=1;i<n;i++){
		v = A[i];
		for(j = i; j > 0 && A[j-1] > v; j--)
			A[j] = A[j-1];
		A[j] = v;
		Process(A, N);

	}
}



int main(void){
	int i;
	scanf("%d",&N);
	int A[100];
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);
	Process(A, N);
	InsertionSort(A, N);
	
	
	return 0;


}

Measured memory_bytes: 1768
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <stdio.h>

int main() {
	int N, Y;
	scanf("%d %d", &N, &Y);
	if (Y % 1000) {
		printf("-1 -1 -1");
		return 0;
	}
	int a = 0, b = 0, c = Y / 1000;
	int k = std::max(0, std::min((c - N) / 4, c / 5));
	c -= 5 * k;
	b += k;
	k = std::max(0, std::min(b + c - N, b / 2));
	b -= 2 * k;
	a += k;
	if (a + b + c != N) {
		printf("-1 -1 -1");
		return 0;
	}
	printf("%d %d %d", a, b, c);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		
		int x = scan.nextInt();
        int[] n = new int[x];
        
        for(int i=0; true; i++){
        	n[i] = scan.nextInt();
        	if(i == x-1) break;
        }
        for(int i=x-1; true; i--){
        	System.out.print(n[i]);
        	if(i == 0) break;
        	System.out.print(" ");
        }
    	System.out.println();
	}

}

Measured memory_bytes: 26252
import java.util.Scanner;

public class Main {

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

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

#define int long long
#define MAX_N (200005)
#define INF (1LL<<60)
#define EPS (1e-7)
#define DEBUG(x) cerr << #x <<":"<< x << endl;
#define DEBUGVC(x) cerr << #x <<": "; for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define DEBUGVCP(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<", "<< p.second << endl;
#define DEBUG2(x, y) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y << endl;
#define DEBUG3(x, y, z) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y <<", "<< #z <<" : "<< z << endl;
const int MOD = (int)1e9+7;

int comb[3010][1510];

void calc_comb(int n, int k) {
	comb[0][0] = 0;
	comb[1][0] = comb[1][1] = 1;

	for (int i = 2; i < n; i++) {
		for (int j = 0; j < k; j++) {
			if(i<j) continue;
			if(j==0 || j==i) comb[i][j] = 1;
			else {
				if(comb[i-1][j]==-1 || comb[i-1][j-1]==-1) comb[i][j]=-1;
				else comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
			}
			// でかすぎたら-1にする
			if(comb[i][j] > (int)1e16) comb[i][j]=-1;
		}
	}
}


signed main() {
	// 前処理


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

    cout << n-k+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <unordered_map>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

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

signed main()
{
	int n;
	cin >> n;
    string ans;
    while (n > 0)
    {
        ans.push_back('a' + ((n - 1) % 26));
        n = (n - 1) / 26;
    }
    reverse(all(ans));
    cout << ans << '\n';
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 200000

// x^n in mod
ll modpow(ll x, ll n, ll mod){
  if(n==0) return 1;

  if(n%2==0){
    return modpow(x*x%mod, n/2, mod) % mod;
  }else{
    return x * modpow(x, (n-1), mod) % mod;
  }
}

int n;
vector<int> to[MAXN];

ll result=0;

int dfs(int v, int p=-1){
  int res=1;
  vector<int> ts;
  for(int u: to[v]){
    if(u==p)continue;
    int t = dfs(u, v);
    res += t;
    ts.push_back(t);
  }
  if(p!=-1)ts.push_back(n-res);

  ll now = modpow(2, n-1, MOD)-1;
  for(int t: ts){
    now -= modpow(2, t, MOD)-1;
    now += MOD;
    now %= MOD;
  }
  result += now;
  result%=MOD;

  return res;
}

int main(){
  cin>>n;
  rep(i, n-1){
    int a,b;cin>>a>>b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  dfs(0);
//cout<<result<<' '<<modpow(2, n, MOD)<<endl;
  ll all = modpow(2, n, MOD);
  result *= modpow(all, MOD-2, MOD);

  cout<<result%MOD<<endl;

  return 0;
}


Measured memory_bytes: 24832
//encoding:utf-8
//#include <iostream> //c++
//#include<stack> //スタックに関して　最新のデータから捨てる
//#include<queue> //キューに関して　最古のデータから捨てる
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort とかにいる
#include<bits/stdc++.h>//vector,algorithm,que
#include<time.h> //時間にかんして

#define ll long long
#define MOD 1000000007
#define INF (1<<29)
using namespace std;
int main(){
  int N,M,R;
  cin>>N>>M>>R;
  vector<int> r(R);

  for(int i=0;i<R;i++){
    cin>>r[i];
  }
  sort(r.begin(),r.end());
  int ways[M][3];
  for(int i=0;i<M;i++){
    cin>>ways[i][0]>>ways[i][1]>>ways[i][2];
  }
  // warshall_floyd
  int cost[N][N];
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cost[i][j]=INF;
    }
  }

  for(int i=0;i<M;i++){
    cost[ways[i][0]-1][ways[i][1]-1] = ways[i][2];
    cost[ways[i][1]-1][ways[i][0]-1] = ways[i][2];
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        cost[j][k] = min(cost[j][k],cost[j][i]+cost[i][k]);
      }
    }
  }

  ll ans = INF;
  int cnt = 0;
  do{
    ll tmp = 0;
    cnt += 1;
    for(int i=0;i<R-1;i++){
      tmp += cost[r[i]-1][r[i+1]-1];
    }
    ans = min(ans,tmp);
  }
  while( next_permutation(r.begin(),r.end()) );

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


Measured memory_bytes: 1148
import copy
import math
import time
 
# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():
 
    idx += 1
'''
 
def main():
    start = time.time()
 
    n = get_int()
    s_list = get_string_char_list()
    s_list = [int(x) for x in s_list]
 
    #n = 30000
    #s_list = [1] * 30000
 
    #ans_set = set([])
 
    #for i in range(0,n):
    #    for ii in range(i+1, n):
    #        for iii in range(ii+1, n):
    #            ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)
 
    #print(len(ans_set))
 
    ans = 0
 
    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
 
        find_a = False
        find_b = False
        for ii in s_list:
 
            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):
 
                ans += 1
                break
    print(ans)
 
    #print(time.time() - start)
 
if __name__ == '__main__':
    main()
 

Measured memory_bytes: 9916
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 62;
constexpr double eps = (1e-9);

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

  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  reverse(ALL(s));
  vector<int> ns(n+1, 0);   // 自分とその手前で，直近の安全なマス
  int tmp = 0;
  rep(i, n+1) {
    if (s[i] == '0') {
      ns[i] = i;
      tmp = i;
    } else {
      ns[i] = tmp;
    }
  }

  int cur = 0;
  vector<int> ans;
  while (true) {
    int next = cur + m;
    if (next >= n) {
      ans.push_back(n-cur);
      break;
    }
    if (s[next] == '0') {
      ans.push_back(next - cur);
      cur = next;
    } else {
      next = ns[next];
      if (cur == next) {
        cout << -1 << endl;
        return 0;
      } else {
        ans.push_back(next - cur);
        cur = next;
      }
    }
  }

  reverse(ALL(ans));

  for (auto& x : ans) cout << x << " "; cout << endl;

  return 0;
}


Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int a, p; cin >> a >> p;
  cout << (3 * a + p) / 2 << endl;
}


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


int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, A, B;
	cin >> N >> A >> B;
	if (N * A < B)
		cout << N * A << "\n";
	else
		cout << B << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    int c = 1e5;
    vvi G(c*2);
    rep(i,n) {
        int x,y;
        cin >> x >> y;
        x--; y--;
        G[x].pb(y+c);
        G[y+c].pb(x);
    }
    ll ans = 0;
    vi seen(2*c,0);
    auto bfs = [&](int s) {
        queue<int> q;
        q.push(s);
        seen[s] = 1;
        int cntx = 0,cnty = 0;
        while(q.size()) {
            int now = q.front();
            q.pop();
            if(now < c) cntx++;
            else cnty++;
            for(int i : G[now]) {
                if(seen[i]) continue;
                seen[i] = 1;
                q.push(i);
            }
        }
        ans += (ll)cntx*cnty;
    };
    rep(i,2*c) {
        if(seen[i]) continue;
        bfs(i);
    }
    cout << ans-n << endl;
}


Measured memory_bytes: 8960