akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int col = 3;

void max_self(LL &a, LL b) {
	a = max(a, b);
}

int main() {
	string s, t;
	cin>>s>>t;
	int n = s.size(), m =  t.size();
	int dp[n+1][m+1];
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=m; j++) {
			if(i==0 || j==0) {
				dp[i][j] = 0;
				continue;
			}
			if(s[i-1] == t[j-1]) {
				dp[i][j] = dp[i-1][j-1]+1;
			}
			else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	string lcs = "";
	int i = n, j = m;
	while(i > 0 && j> 0) {
		if(s[i-1] == t[j-1]) {
			lcs += s[i-1];
			i--;
			j--;
		}
		else {
			if(dp[i-1][j] > dp[i][j-1]) i--;
			else j--;
		}
	}
	reverse(lcs.begin(), lcs.end());
	cout<<lcs;
	
	return 0;
	
	
}

Measured memory_bytes: 38756
import re
S = input()
cand = [
    r'^k.*eyence$', r'^ke.*yence$', r'^key.*ence$', r'^keye.*nce$',
    r'^keyen.*ce$', r'^keyenc.*e$', r'^keyence.*$'
]
for r in cand:
    if re.match(r, S):
        print('YES')
        exit()
print('NO')


Measured memory_bytes: 3188
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12564
#include<stdio.h>
int main(){
    int a,b,c,i;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b && a>c){
        i=a;
        i=(i*10)+b+c;
    }else if(c>b && c>a){
        i=c;
        i=(i*10)+a+b;
    }else{
        i=b;
        i=(i*10)+a+c;
    }
    printf("%d",i);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 20010
int n,p[N],a[N],b[N];
int main() {
	int x;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&x),p[x]=i;
	for(int i=1;i<=n;++i) printf("%d ",20000*(i-1)+p[i]);
	puts("");
	for(int i=1;i<=n;++i) printf("%d ",20000*(n-i)+p[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

//ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

bool fac(int a)
{
	FOR(i, 2, sqrt(a) + 1)
	{
		if (a%i == 0) {
			return  false;
		}
	}
	return true;
}

int main()
{
	int a;
	for (;;) {
		cin >> a;
		if (a == 0) {
			break;
		}
		int ans = 0;
		FOR(i, a + 1, 2 * a + 1)
		{
			if (fac(i)) {
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
#define p(l) (ll)pow(2, l + 1) - 1

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

ll ans(int l, ll x) {
	if (l == 0)return 1;
	if (x == 1)return 0;
	if (x < (ll)pow(2, l + 1) - 1)return ans(l - 1, x - 1);
	if (x == (ll)pow(2, l + 1) - 1)return p(l - 1) + 1;
	if (x < (ll)pow(2, l + 2) - 3)return p(l - 1) + 1 + ans(l - 1, x - (ll)pow(2, l + 1) + 1);
	if (x == (ll)pow(2, l + 2) - 3)return p(l);
	throw "error";
}

int main() {
	makei(n);
	makel(x);
	say(ans(n, x));
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint ans;

signed main(){
  string s; cin >> s;
  lint K; cin >> K;
  lint counter = 0;
  lint start = 0;
  for(lint start = 0; start < s.size(); start++){
    if(s[start] == 'a') continue;
    lint need = 'z' - s[start] + 1;
    if(K - counter >= need){
      s[start] = 'a';
      counter += need;
    }
  }
  s[s.size() - 1] += (K - counter) % 26;
  cout << s << endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
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; }
const long long INF = 1LL<<60;

int N;
long long W, weight[110], value[110]; 
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout << dp[N][W] << endl;
}

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

int n, lc = 0, rc = 0;
string s;

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

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == ')') {
			if (lc == 0) {
				rc++;
			}
			else {
				lc--;
			}
		}

		if (s[i] == '(') {
			lc++;
		}
	}

	for (int i = 0; i < rc; i++) {
		s = '(' + s;
	}
	for (int i = 0; i < lc; i++) {
		s = s + ')';
	}

	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ct[105];
int main(){
	int x,n;
	scanf("%d%d",&x,&n);
	for (int i =0,X; i < n; i++){
		scanf("%d",&X);
		ct[X]  =1;
	}
	int ans = 0;
	for (int i = 0; i <= 101; i++){
		if (ct[i] == 0){
			if (abs(ans-x) > abs(i-x)) ans = i;
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 3816
from math import gcd

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    all = 0
    for a in A:
        all = gcd(all, a)
    if all != 1:
        return "not coprime"

    M = 10 ** 6
    B = dict()
    for a in A:
        if a in B:
            B[a] += 1
        else:
            B[a] = 1

    for i in range(2, M + 1):
        cnt = 0
        for j in range(i, M, i):
            if j in B:
                cnt += B[j]
        if cnt > 1:
            return "setwise coprime"

    return "pairwise coprime"

print(solve())


Measured memory_bytes: 241324
fn main() {
    let (n,k) = read_pair();
    let neighbors = {
        let mut neighbors = vec![Vec::new(); n];
        for _ in 0..n-1 {
            let (a,b): (usize,usize) = read_pair();
            neighbors[a-1].push(b-1);
            neighbors[b-1].push(a-1);
        }
        neighbors
    };

    let fact = {
        let mut fact = vec![F(1); k+1];
        for i in 1..k+1 { fact[i] = fact[i-1] * F(i as u64); }
        fact
    };
    let perm = |n: usize, r: usize|{
        if n<r {F(0)} else {fact[n] / fact[n-r]}
    };

    let mut case_num = perm(k, neighbors[0].len()+1);
    let mut visited = vec![false; n]; visited[0] = true;
    let mut stack = neighbors[0].clone();
    while let Some(v) = stack.pop() {
        visited[v] = true;
        case_num *= if k<2 { F(0)} else {
            perm(k-2, neighbors[v].len()-1)
        };
        for &w in &neighbors[v] {
            if !visited[w] { stack.push(w); }
        }
    }

    println!("{}", case_num);
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_pair<T: std::str::FromStr + Copy>() -> (T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1])
}

const MOD: u64 = 1_000_000_007;

#[derive(Copy, Clone, PartialEq, Eq)]
struct F(u64);

impl F {
    pub fn new(n: i32) -> Self { F((MOD as i32 + n)as u64%MOD) }
    pub fn pow(self, mut exp: u32) -> Self {
        let mut base = self.0;
        let mut acc = 1;
        while exp > 1 {
            if (exp & 1) == 1 { acc *= base; acc %= MOD; }
            exp /= 2; base *= base; base %= MOD;
        }
        if exp == 1 { acc *= base;acc %= MOD; }
        F(acc)
    }
}
impl std::fmt::Display for F {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
use std::ops::*;
impl Mul for F {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {F((self.0 * rhs.0)%MOD)}
}
impl MulAssign for F {
    fn mul_assign(&mut self, rhs: Self) {*self = F((self.0 * rhs.0)%MOD)}
}
impl Div for F {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {F(self.0 * rhs.pow(MOD as u32-2).0 %MOD)}
}

Measured memory_bytes: 14588
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

ll solve() {
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    V<ll> A(n);
    for(ll &e : A) cin >> e;
    sort(ALLR(A));
    ll ret = p;
    ll sum = A[p - 1];
    for(ll i = p; i < n; i++) {
        if(A[i] + m < A[p - 1]) break;
        ll val = A[i] + m;
        ll rest = m * v - m * p;
        DEBUG(make_tuple(i, rest));
        if(rest <= 0) {
            ret++;
            continue;
        }
        ll cnt = i - p + 1;
        ll ok = (A[i] + m) * cnt - sum;
        ok += m * (n - 1 - i);
        DEBUG(make_tuple(rest, ok));
        if(rest <= ok) ret++;
        else break;
        sum += A[i];
    }

    return ret;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define re register
int x[100100],y[100100],d[100100],c[100100],v[100100],q[100100];
std::bitset<50010>bc[50010];
int main()
{
	re int n,m,t;
	scanf("%d%d%d",&n,&m,&t);
	if(t==1)
	{
		for(re int i=1;i<=n;i++)bc[i].set(i);
		for(re int i=1;i<=m;i++)
			scanf("%d%d",&x[i],&y[i]),bc[x[i]]=bc[y[i]]=bc[x[i]]|bc[y[i]];
		for(re int i=1;i<=n;i++)
		if(bc[i].count()==n){
			c[i]=1;
			for(re int j=m;j;j--)
			{
				if(c[x[j]])c[y[j]]=1,v[j]=1;
				else c[x[j]]|=c[y[j]];
			}
			for(re int j=1;j<=m;j++)putchar(v[j]?'^':'v');
			exit(0);
		}
		puts("-1");
	}else
	{
		if(n==2)puts("-1"),exit(0);
		for(re int i=1;i<=m;i++)
			scanf("%d%d",&x[i],&y[i]);
		re int ta=0;
		for(re int i=1;i<=m;i++)if(y[i]>3)v[i]=1;
		else q[++ta]=i;
		for(re int i=1;i<=ta;i++)
		{
			v[q[i]]=(x[q[i]]!=x[q[i+1]]&&x[q[i]]!=y[q[i+1]]);
		}
		for(re int j=1;j<=m;j++)putchar(v[j]?'^':'v');
	}
}

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

using namespace std;

int solve(vector<int>& arr) {
	int n = arr.size();
  	if(n<2) return 0;
  	vector<int> dp(n);
	dp[0] = 0;
  	dp[1] = abs(arr[0]-arr[1]);
  	for(int i=2;i<n;i++) {
    	dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    }
  	return dp[n-1];
}


int main() {
	int n;
  	cin>>n;
  	vector<int> arr(n);
  	for(int i=0;i<n;i++) {
    	cin>>arr[i];
    }
  	cout<<solve(arr);
	return 0;
}





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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
    // A[0]は1で固定して増加させず使わないのでn+1になるまで
    if(A.size() == n+1){
        int now = 0;
        rep(i,q){
            if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        if(ans < now) ans = now;
        return;
    }
    // A.back()はAの最後尾の数値
    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}


int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q); // 
    rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define nmax 100005
#define lld long long
#define mod 1000000007LL
using namespace std;

lld a[nmax];

lld expLog(lld a, lld n){
    if (!n){
        return 1LL;
    }
    if (n & 1){
        return (a * expLog((a*a)%mod, n>>1))%mod;
    }
    return expLog((a*a)%mod, n>>1);
}

int main()
{
    int n, k;
    cin>>n>>k;
    lld ans = 0;
    for (int i=k;i>=1;--i){
        a[i] = expLog(k/i,n);
        lld sub = 0;
        for (int j=i+i;j<=k;j+=i){
            sub = (sub + a[j]) % mod;
        }
        a[i] -= sub;
        a[i] %= mod;
        if (a[i] < mod){
            a[i] = a[i] + mod;
        }
        ans = (ans + 1LL * i * a[i]) % mod;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 4340
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
             total = 500*i + 100*j + 50*k
             if total == x:
                 count+=1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,l,r,ans;
int main(void)
{
	scanf("%lld",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld%lld",&l,&r);
		ans+=r-l+1;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    read(a);
    read(b);
    if(a%b==0){
        cout<<a/b<<endl;
    }
    else{
        cout<<(a/b)+1<<endl;
    }
    
    


   

}

Measured memory_bytes: 256
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae += tmp[2]
    elif tmp[1] == '2' and not inv:
        usiro += tmp[2]
    elif tmp[1] == '1' and inv:
        usiro += tmp[2]
    elif tmp[1] == '2' and inv:
        mae += tmp[2]

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Measured memory_bytes: 4320
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; } 
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } 

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())

string s;

void init() {
}

void input() {
	cin >> s;
}

void solve() {
	int res = (SZ(s) & 1) ^ (s[0]==s[SZ(s)-1]);
	if(res) cout << "First" << endl;
	else cout << "Second" << endl;
}

int main() {
	init();
    input();
    solve();
	return 0;
}








Measured memory_bytes: 512
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b
for i in range(n - 2):
    interval = 1
    while i + 2 * interval < n:
        if s[i] != s[i + interval] and s[i] != s[i + 2 * interval] and s[i + interval] != s[i + 2 * interval]:
            ans -= 1
        interval += 1

print(ans)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int M;
LL K;
LL D[114514];
LL X[114514];

vector<int> Compose(vector<int> as, vector<int> bs) {
  vector<int> cs(N);
  rep(i, N) {
    cs[i] = bs[as[i]];
  }
  return cs;
}

int main() {
  scanf("%d", &N);

  vector<int> ps, es;
  rep(i, N) {
    scanf("%lld", &X[i]);
    D[i] = X[i];
    if (i > 0) D[i] -= X[i-1];
    ps.eb(i);
    es.eb(i);
  }

  scanf("%d%lld", &M, &K);
  rep(i, M) {
    int a;
    scanf("%d", &a);
    --a;
    swap(es[a], es[a+1]);
  }

  rrep(i, 60) {
    ps = Compose(ps, ps);
    if (K >> i & 1) {
      ps = Compose(ps, es);
    }
  }

  LL s = 0;
  rep(i, N) {
    s += D[ps[i]];
    printf("%lld\n", s);
  }
}


Measured memory_bytes: 4820
N, X, M = map(int, input().split())
if X == 0:
    print(0)
    exit()
tx = X % M
tl = []
ts = set()
ttl = []
for i in range(N):
    tl.append(tx)
    ts.add(tx)
    tx = pow(tx, 2, M)
    if tx in ts:
        ttl = tl[tl.index(tx):]
        break
ans = sum(tl)
if len(ttl)>0:
    d, m = divmod(N-len(tl), len(ttl))
    ans += sum(ttl)*d+sum(ttl[:m])
print(ans)


Measured memory_bytes: 13244
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;

std::vector<int> C[20], D[20];// D[i][j]: 種類iでj個選ぶときの最大価格
int G[20];

int main(){
    int N, K;
    std::cin >> N >> K;

    std::fill(G, G+20, 0);

    REP(i, N){
        int c, g;
        std::cin >> c >> g;

        C[g].push_back(c);
        G[g]++;
    }

    FOR(i, 1, 11){
        std::sort(C[i].begin(), C[i].end(), std::greater<int>());

        D[i].push_back(0);

        int sum = 0;

        //printf("%d: ", i);

        REP(j, G[i]){
            int t = j + 1;
            sum += C[i][j];

            D[i].push_back(sum + t * (t-1));
            //printf("%d, ", sum + t * (t-1));
            //std::cout << i << "," << sum << std::endl;
        }
        //puts("");
    }

    int dp[20][2010];
    REP(i, 20){
        REP(j, 2010){
            dp[i][j] = -INF;
        }
    }

    FOR(i, 1, 11){
        dp[i][0] = 0;
    }

    FOR(i, 1, std::min(G[1], K)+1){
        dp[1][i] = D[1][i];
    }

    FOR(i, 2, 11){
        REP(j, K+1){
            dp[i][j] = dp[i-1][j];

            FOR(k, 1, std::min(G[i], K)+1){
                if(j - k >= 0){
                    dp[i][j] = std::max(dp[i][j], dp[i-1][j-k] + D[i][k]);
                }
            }
        }
    }

    // FOR(i, 1, 4){
    //     REP(j, K+1){
    //         printf("%d, ", dp[i][j]);
    //     }
    //     puts("");
    // }

    std::cout << dp[10][K] << std::endl;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define FOR(i,a,b) for(LL i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const LL INF=1LL<<60;
const LL MAX=1e10;
const int BITSIZE=1<<17;
const LL p=7+1e9;
const int SIZE=2*1e5;
LL DP[51][2601][51];
int main(){
	int N,M,A,x;
	string s;
	cin >> N >> A;
	DP[0][0][0]=1;
	REP(i,N){
		cin >> x;
		REP(k,N*50+1){
			REP(j,N){
				DP[i+1][k+x][j+1]+=DP[i][k][j];
				DP[i+1][k][j]+=DP[i][k][j];
			}			
		}
	}
	LL ans=0;
	FOR(i,1,N+1){
		ans+=DP[N][A*i][i];
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 51200
#include <stdio.h>

int main(void)
{
  int i, p_min = 2000, j_min = 2000, price;

  for(i = 0; i < 3; i++){
    scanf("%d", &price);
    if(p_min > price)
      p_min = price;
  }

  price = 0;
  for(i = 0; i < 2; i++){
    scanf("%d", &price);
    if(j_min > price)
      j_min = price;
  }

  printf("%d\n", p_min + j_min - 50);

  return 0;
}

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

int main() {
	int h, w; cin >> h >> w;
	vector<string> s;
	string temp = "";
	for (int i = 0; i < w + 2; i++) {
		temp += "#";
	}
	s.push_back(temp);
	for (int i = 0; i < h; i++) {
		string z; cin >> z;
		s.push_back("#" + z + "#");
	}
	for (int i = 0; i < w + 2; i++) {
		temp += "#";
	}
	s.push_back(temp);
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			cout << s[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

namespace AOJALDS14A
{
    class Program
    {
        static void Main(string[] args)
        {
            var Snum = int.Parse(Console.ReadLine());
            var S = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            var Tnum = int.Parse(Console.ReadLine());
            var T = Console.ReadLine().Split(' ').Select(a => int.Parse(a));
            var C = 0;

            foreach (var Ti in T)
            {
                if (Search(S,Ti))
                {
                    ++C;
                }

            }

            Console.WriteLine(C);
            Console.ReadLine();
        }

        private static bool Search(int[] n, int key)
        {
            var left = 0;
            var right = n.Length;
            while (left < right)
            {
                var mid = (left + right) / 2;
                if (n[mid] == key)
                {
                    return true;
                }
                else if (key < n[mid])
                {
                    right = mid;
                }
                else
                    left = mid + 1;
            }

            return false;
        }
    }
}



Measured memory_bytes: 28548
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll INF=1e18;

int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            ans+=i;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3636
-- 全ての受け取った値を全てconcat, sort, groupByして，大きさがNのリスト要素を返す

import Control.Applicative
import Control.Monad as M
import Data.List

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  likes <- M.replicateM n (map read .words <$> getLine)
  putStrLn $ show (solve n (map (\(x:xs) -> xs) likes))

solve :: Int -> [[Int]] -> Int
solve n = sum . map (\xs -> if length xs == n then 1 else 0) . group . sort . concat


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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int mod=1000000007;
template<class T,class U>
void add(T& a,U b){
	a=((ll)a+b)%mod;
}

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

template<class T,class U>
void sub(T& a,U b){
	a=((ll)a-b%mod+mod)%mod;
}

template<>
void sub(int& a,int b){
	a-=b;
	if(a<0)a+=mod;
}

template<class T,class U>
void mult(T& a,U b){
	a=((ll)a*b)%mod;
}

ll modPow(ll a,ll p){
	ll s=1;
	REP(i,30){
		if((p>>i)&1)
			mult(s,a);
		mult(a,a);
	}
	return s;
}

ll modInv(ll a){
	return modPow(a,mod-2);
}

int main(){
	vector<ll> pow2({1});
	REP(i,114514)
		pow2.PB(pow2.back()*2%mod);
	int n=read();
	vector<vi> c(n);
	REP(i,n)REP(j,n)
		c[i].PB(read());
	int cr=0;
	REP(i,n){
		int p=-1;
		REP(j,n)if(c[i][j])
			p=j;
		if(p!=-1){
			cr++;
			FOR(k,i+1,n)if(c[k][p])REP(j,n)
				c[k][j]^=c[i][j];
		}
	}
	vector<vector<ll>> cur(n+1,vector<ll>(cr+1,0)),nx(n+1,vector<ll>(cr+1,0));
	cur[0][cr]=1;
	REP(_,n){
		REP(i,n+1)
			fill(ALL(nx[i]),0);
		REP(i,n+1)
			REP(j,cr+1)if(i+j<=n){
				add(nx[i][j],cur[i][j]*pow2[i]);
				if(i<n&&0<j)
					add(nx[i+1][j-1],cur[i][j]*(pow2[j]-1+mod)%mod*pow2[i]);
				if(i<n)
					add(nx[i+1][j],cur[i][j]*(pow2[n-i-j]-1+mod)%mod*pow2[i+j]);
			}
		swap(cur,nx);
	}
	ll ans=0;
	REP(i,n+1)
		add(ans,cur[i][0]*pow2[n*(n-i)]);
	cout<<ans<<endl;
}


Measured memory_bytes: 3188
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    B=sorted(A, reverse=True)
    for i, a in enumerate(A):
        if a == B[0]:
            print(B[1])
        else:
            print(B[0])


# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc134","c",main)

Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> > 
#define vpll vector<pair<lli,lli> > 
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> >
#define maxn 1005
#define mod 1000000007
#define inf 10000000000000000

int gp=0;
vector < pair<int,int> > gc[1000005]; 
int gr[maxn][maxn];
bool vis[maxn][maxn];
string s[maxn];
int n,m;

void dfs(int x,int y)
{
    vis[x][y]=1;
    gr[x][y]=gp;
    gc[gp].pb({x,y});
    int dx[]={1,-1,0,0};
    int dy[]={0,0,-1,1};
    for(int i=0;i<4;i++)
    {
        int nx=x+dx[i],ny=y+dy[i];
        if(nx<0 or nx>=n or ny<0 or ny>=m or s[nx][ny]=='#' or vis[nx][ny]) continue;
        dfs(nx,ny);
    }
}

int main()
{
    fastio;
    cin>>n>>m;
    int sx,sy,ex,ey;
    cin>>sx>>sy>>ex>>ey;
    sx--,sy--,ex--,ey--;
    for(int i=0;i<n;i++)
    cin>>s[i];
    memset(gr,0,sizeof(gr));
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {
        if(!vis[i][j] and s[i][j]=='.') 
        {
            dfs(i,j),gp++;
        }
    }
    int dx[]={2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2,2,2,1,-1,-1,1};
    int dy[]={-2,-2,-2,-2,-2,-1,0,1,2,2,2,2,2,1,0,-1,-1,-1,1,1};
    
    int st=gr[sx][sy];
    queue<int> qu;
    qu.push(st);
    int dis[gp];
    memset(dis,-1,sizeof(dis));
    int vs[gp]={0};
    dis[st]=0;
    vs[st]=1;
    while(!qu.empty())
    {
        int cr=qu.front();
        for(pair<int,int> pr : gc[cr])
        {
            int i=pr.f,j=pr.s;
            for(int k=0;k<20;k++)
                {
                    int nx=i+dx[k],ny=j+dy[k];
                    if(nx<0 or nx>=n or ny<0 or ny>=m or s[nx][ny]=='#') continue;
                    int dd=gr[nx][ny];
                    if(!vs[dd]){vs[dd]=1,dis[dd]=dis[cr]+1,qu.push(dd);}
                }
        }
        qu.pop();
    }
    cout<<dis[gr[ex][ey]]<<"\n";
    return 0;
}







Measured memory_bytes: 40156
def main():
    n,m=map(int,input().split())
    x = n*m
    if n == 1 and m == 1:
        x = 1
    elif n < 2 or m < 2: # 4隅
        x -= 2
    else:
        x -= (2*m + 2*n)-4
    print(max(0, x))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9060
#include<bits/stdc++.h>
#define MAX_N 200005
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(V) (V).begin(),(V).end()
#define reset(V) (V).clear();(V).resize(0);
#define sq(x) ((x)*(x))
#define abs(x) ((x)>0?(x):(-(x)))
#define fi first
#define se second
#define inf 0x3fffffff
#define full_inf 0x7fffffff
#define half_inf 0x3fffffff
//#define inf 0x3fffffff
#define MOD 1000000007LL
#define cpx_mod(x) (((LD)(((LL)x.real())%MOD)),((LD)(((LL)x.imag())%MOD)))
#define prev(x) (((x)+n-1)%n)
#define next(x) (((x)+1)%n)
#define mod(x) (((x)%h + h)%h)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pil;
typedef pair<LL,string> pls;
typedef complex<LD> Complex;
int n;
int lst[35] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	scanf("%d",&n);
	printf("%d\n",lst[n - 1]);
	return 0;
}

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

using namespace std;

template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')
fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;}
template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}

typedef long long LL;
typedef pair<int, int> pii;
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)

LL n, k;

int main(){
	read(n, k);
	if(n > k)	n = n - n / k * k;
	while(1){
		if(n <= abs(n - k)){
			printf("%lld\n", n);
			return 0;
		}
		n = abs(n - k);
	}
}

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

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

int main() {

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

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

	return 0;
}

Measured memory_bytes: 256
def modinv(a,m):
    b, u, v = m, 1, 0
    while b:
        t = a//b
        a -= t*b
        a,b = b,a
        u -= t * v
        u,v = v,u
    u %= m
    return u

n,a,b = map(int, input().split())
MOD = 10**9+7
ncnt = pow(2,n,MOD)-1
acnt = 1
for i in range(a):
    acnt *= (n-i)
    acnt *= modinv(i+1,MOD)
    acnt %= MOD

bcnt = 1
for i in range(b):
    bcnt *= (n-i)
    bcnt *= modinv(i+1,MOD)
    bcnt %= MOD

ans = ncnt - acnt - bcnt
print(ans%MOD)

Measured memory_bytes: 73620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int N,M;
  cin >> N >> M;
  vector<long long> a[3];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      long long num; cin >> num;
      a[j].pb(num);
    }
  }

  long long res = 0;
  // ビット全探索
  for (int bit = 0; bit < (1 << 3); ++bit) {
    vector<long long> b;
    for (int i = 0; i < N; ++i) {
      long long tmp = 0;
      for (int j = 0; j < 3; ++j) {
        // 絶対値をとるという操作は, 「そのまま」と「-1倍したもの」の大きい方を選ぶ操作
        if (bit & (1 << j)) tmp += a[j][i];
        else tmp -= a[j][i];
      }
      b.pb(tmp);
    }
    sort(b.begin(), b.end(), greater<long long>());
    long long sum = 0;
    for (int i = 0; i < M; ++i) {
      sum += b[i];
    }

    res = max(res, sum);
  }
  cout << res << endl;
}


Measured memory_bytes: 256
use std::collections::HashMap;
macro_rules! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }

fn solve(s: &String, t: &String) -> bool {
    let mut diff: HashMap<char, char> = HashMap::new();
    s.chars().zip(t.chars()).all(|(c1, c2)| {
        let c3 = diff.entry(c1).or_insert(c2);
        c2 == *c3
    })
}

fn main() {
    input! {
        s: String,
        t: String,
    }

    if solve(&s, &t) && solve(&t, &s) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <cstdio>
char s[11], r[11];
int idx = -1;
int main()
{
  scanf("%s", s);
  for (int i = 0; s[i]; ++i) {
    switch (s[i]) {
    case '0':
      r[++idx] = '0';
      break;
    case '1':
      r[++idx] = '1';
      break;
    case 'B':
      idx = idx - 1 >= -1 ? idx - 1 : -1;
      break;
    }

  }
  r[idx + 1] = NULL;
  puts(r);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector< string > s(n);
    vector< int > p(n);
    vector< int > num(n);
    for(int i = 0 ; i < n ; i++){
      cin >> s[i] >> p[i];
      num[i] = i+1;
    }
    string st;
    for(int i = 0; i < n ; i++){
      int t = 0;
      int m = 101;
      st = s[0];
      m = p[0];
      for(int j = 0; j < s.size() ; j++){
        if(st > s[j]){
          t = j;
          m = p[j];
          st = s[j];
        }
        else if(st == s[j]){
          if(m <= p[j]){
            m = p[j];
            t = j;
          }
        }
      }
      cout << num[t] << endl;
      s.erase(s.begin()+t);
      p.erase(p.begin()+t);
      num.erase(num.begin()+t);
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;

    int max_cnt = -1, ans;
    for (int i = 1; i <= N; i++) {
        int cnt = 0, tmp = i;
        while ((tmp&1) == 0) {
            cnt++;
	    tmp >>= 1;
        }
        if (cnt > max_cnt) {
            max_cnt = cnt;
            ans = i;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstring>
 
using namespace std;
 
#define MAX 10000
#define INF 1e9
typedef pair<int,int> P;
int ans, N;
vector<P> vec[MAX];
int dp[100][100]; 

int dist(int x1, int y1, int x2, int y2){
  return abs(x1-x2) + abs(y1-y2);
}

int getNum(string &s){
  stringstream ss(s);
  int res;
  ss >> res;
  return res;
}
 
int main(){
  int W, H;
 
  while(cin >> W >> H, (W | H)){
    string in;
    int gx, gy, max = 0;
    for(int i = 0 ; i < MAX ; i++){
      vec[i].clear();
    }
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> in;
        if(in == ".") continue;
        if(in == "S"){
          vec[0].push_back(P(i,j));
        }else if(in == "G"){
          gx = i, gy = j;
        }else{
          int num = getNum(in);
          max = std::max(max, num);
          vec[num].push_back(P(i,j));
        }
      }
    }
    vec[max+1].push_back(P(gx,gy));
    ans = INF; N = max+2;
    fill(dp[0],dp[H],INF);
    for(int i = 0 ; i < N-1 ; i++){
      for(int j = 0 ; j < vec[i+1].size() ; j++){
        for(int k = 0 ; k < vec[i].size() ; k++){
          int bx = vec[i][k].first;
          int by = vec[i][k].second;
          int nx = vec[i+1][j].first;
          int ny = vec[i+1][j].second;
          if(dp[bx][by] == INF) dp[bx][by] = 0;
          dp[nx][ny] = min(dp[nx][ny],dp[bx][by] + dist(bx,by,nx,ny));;
        }
      }
    }
    cout << dp[gx][gy] << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1636
n, *R = map(int, open(0).read().split())
A = [int(-1e9) for _ in range(n)]
B = [int(1e9) for _ in range(n)]
A[n-1] = max(A[n-1], R[n-1])
B[0] = min(B[0], R[0])
for i in range(n-1, 0, -1):
    A[i-1] = max(R[i-1], A[i])
for i in range(n-1):
    B[i+1] = min(B[i], R[i+1])

ans = int(-3e9)
for i in range(n-1):
    ans = max(ans, A[i+1] - B[i])
print(ans)


Measured memory_bytes: 29400
require 'prime'

def _divisors(primes, k)
  Enumerator.new do |y|
    if primes.size == k
      y << 1
    else
      p, e = primes[k]
      _divisors(primes, k + 1).each {|d|
        (e + 1).times {|e1|
          y << p ** e1 * d
        }
      }
    end
  end
end

def divisors(n)
  _divisors(Prime.prime_division(n), 0).to_a.sort
end

N=gets.to_i
ds = divisors(N)
puts ds[ds.length/2].to_s.length


Measured memory_bytes: 14332
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int m;
    if (a <= b) {
        if (b <= c)m = c;
        else
        {
            m = b;
        }
    }
    if (b <= a) {
        if (a <= c)m = c;
        else
        {
            m = a;
        }
    }
    cout << a + b + c - m;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int x = scanner.nextInt();
      int y = scanner.nextInt();
      if (x == 0 && y == 0) {
        break;
      }
      if (x < y) {
        x = x + y;
        y = x - y;
        x = x - y;
      }
      for (int s = 0; ;s++) {
        if (y == 0) {
          System.out.printf("%d %d\n", x, s);
          break;
        }
        x = x % y;
        x = x + y;
        y = x - y;
        x = x - y;
      }
    }
  }
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool ans = true;
    map<string, bool> done;
    done[s] = 1;
    
    REP(i, n-1) {
        string t;
        cin >> t;
        if (ans) ans = t[0] == s[s.length() - 1] && !done[t];
        s = t;
        done[s] = 1;
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    
    return 0;
}


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

int best[310][310][310];

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.size();
    for(int i = n-1; i >= 0; i--){
        for(int a = 0; a <= k; a++){
            if(i > 0) best[i][i-1][a] = 0;
        }
    }
    for(int i = n-1; i >= 0; i--){
        for(int j = i; j < n; j++){
            for(int a = 0; a <= k; a++){
                best[i][j][a] = 1;
                if(i == j) continue;
                best[i][j][a] = max(best[i][j][a], best[i+1][j][a]);
                best[i][j][a] = max(best[i][j][a], best[i][j-1][a]);
                if(s[i] == s[j]){
                    best[i][j][a] = max(best[i][j][a], 2 + best[i+1][j-1][a]);
                } else {
                    if(a > 0){
                        best[i][j][a] = max(best[i][j][a], best[i+1][j-1][a-1] + 2);
                    }
                }
            }
        }
    }
    
    
    cout << best[0][n-1][k] << endl;
}


Measured memory_bytes: 112896
n=int(input())
S=input()
l=[]
for i in range(10**3):
    num=str(i).zfill(3)
    s=S
    if s.find(num[0])==-1: continue
    s=s[s.index(num[0])+1:]
    if s.find(num[1])==-1: continue
    s=s[s.index(num[1])+1:]
    if s.find(num[2])==-1: continue
    l.append(num)
print(len(set(l)))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 




////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,a[110000];
signed main(){
  cin>>n;int mx = -1, mm = INF;
  rep(i,n){
    cin>>a[i];
    chmax(mx, a[i]);chmin(mm, a[i]);
  }
  if(mx - mm >= 2){
    cout << "No" << endl;
  }else if(mx == mm){
    if(mx == n-1 || n >= 2*mx)cout << "Yes" << endl;
    else cout << "No" << endl;
  }else{
    int cntx = 0, cntm = 0;
    rep(i,n)(a[i] == mx ? cntx : cntm)++;
    if(cntx >= 2 && cntx >= 2*(mx-cntm) && mx-cntm > 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}

inline long long read() {
 long long x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
long long a[100005];
int n;
int m;
long long k;
int c[100005];
long long  ans[100005];
int vis[100005],st[100005];
int main () {
#ifndef ONLINE_JUDGE
//file("agc006c");
#endif
    int n=read();
	int sum=0;
	F(i,1,n){
	    a[i]=read();
		a[i]-=sum;
		sum+=a[i];
		c[i]=i;
	}
	m=read();k=read();
	F(i,1,m){
	   int x=read();
	   swap(c[x],c[x+1]);
	}
    F(i,1,n){
	   if(!vis[i]){
		  int cnt=0;
		  int j;
		  for(j=i;!vis[j];j=c[j]){
		     vis[j]=1;
			 st[++cnt]=j;
		  }
		  F(j,1,cnt)ans[st[j]]=a[st[(j+k-1)%cnt+1]];
	   }
	}
    F(i,1,n){
	   ans[i]=ans[i]+ans[i-1];
	   printf("%.10lf\n",(double)ans[i]);
	}
    return 0;
}

Measured memory_bytes: 5120
n = int(input())
H = list(map(int, input().split()))
T = [0 for _ in range(n)]
c = 0
while True:
  f = False
  S = {0:1}
  for j in range(n):
    if H[j] > 0:
      S[1] = 1
      H[j] -= 1
      f = True
    elif len(S) > 1 and H[j] == 0:
      break
  if f: c += 1
  if H == T: break
print(c)


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

long long solve(int n, int *a, int sgn) {
    long long ans = 0;
    long long sum = a[0];
    if(sgn > 0 && sum <= 0) {
        ans += abs(sum) + 1;
        sum = 1;
    } else if(sgn < 0 && sum >= 0) {
        ans += abs(sum) + 1;
        sum = -1;
    }
    for(int i=1; i<n; ++i) {
        if((sum > 0 && sum + a[i] >= 0) || (sum < 0 && sum + a[i] <= 0)) {
            ans += abs(sum + a[i]) + 1;
            if(sum > 0) sum = -1;
            else sum = 1;
        } else {
            sum += a[i];
        }
    }
    return ans;
}

int main() {
    int n;
    int a[100000];
    cin >> n;
    for(int i=0; i<n; ++i) cin >> a[i];

    cout << min(solve(n,a,1), solve(n,a,-1)) << endl;
}

Measured memory_bytes: 640