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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    
    vector<vector<int>> accum(1<<20);
    int now = 0;
    vector<ll> zero(N+1, 0);
    for (int i = 0; i < N; i++) {
        now ^= A[i];
        accum[now].push_back(i+1);
        if (now == 0) zero[i+1]++;
    }
    
    for (int i = 0; i < N; i++) {
        zero[i+1] += zero[i];
    }
    
    ll mod = 1e9+7;
    
    if (now > 0) {
        int K = accum[now].size(); 
        vector<ll> dp0(K+1, 0), dp1(K+1, 0);
        dp0[0] = 1;
        
        for (int i = 1; i <= K; i++) {
            if (i == 1) {
                dp0[i] = 1;
                dp1[i] = 1;
            }
            else {
                ll n = zero[accum[now][i-1]] - zero[accum[now][i-2]];
                dp0[i] = (dp0[i-1] + n * dp1[i-1]) % mod;
                dp1[i] = (dp0[i-1] + (n+1) * dp1[i-1]) % mod;
            }
        }
        cout << dp0[K]%mod << endl;
    }
    else {
        ll ans = 1;
        for (int i = 0; i < (int)accum[0].size()-1; i++) {
            ans = ans * 2 % mod;
        }
        
        for (int i = 1; i < (1<<20); i++) {
            if (accum[i].empty()) continue;
            int K = accum[i].size(); 
            vector<ll> dp0(K+1, 0), dp1(K+1, 0);
            dp0[0] = 1;
        
            for (int j = 1; j <= K; j++) {
                if (j == 1) {
                    dp0[j] = 1;
                    dp1[j] = 1;
                }
                else {
                    ll n = zero[accum[i][j-1]] - zero[accum[i][j-2]];
                    dp0[j] = (dp0[j-1] + n * dp1[j-1]) % mod;
                    dp1[j] = (dp0[j-1] + (n+1) * dp1[j-1]) % mod;
                }
            }
            ans += dp1[K];
        }
        cout << ans%mod << endl;
    }
    
    return 0;
}

Measured memory_bytes: 40308
iptA=list(map(int,input().split()))
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
X.append(iptA[2])
Y.append(iptA[3])
     
xmax,ymin=max(X),min(Y)
if xmax>=ymin:
    print('War')
else:
    print('No War')

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

void shuffleCards( int* a, int n, int p, int c )
{
    int copy1[p], copy2[c];
    for( int i = 1; i < p; i++ )
        copy1[i] = a[n+1-i];

    for( int i = p; i < p + c; i++ )
        copy2[i-p] = a[n+1-i];

    for( int i = 1; i <= c; i++ )
        a[n+1-i] = copy2[i-1];

    for( int i = 1; i < p; i++ )
        a[n+1-c-i] = copy1[i];
    
}

int main()
{
    int n, r, a[51], p, c;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 1; i <= 50; i++ )
            a[i] = i;

        cin >> r;

        for( int i = 0; i < r; i++ )
        {
            cin >> p >> c;
            shuffleCards( a, n, p, c );
        }
        cout << a[n] << endl;
    }
    return 0;
}



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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(v) {for (auto x : v) cerr << x << ' '; cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int N = 10005;
int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[N], num[N];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m;
	scanf("%d%d", &n, &m);
	vi a(m);
	for (int i = 0; i < m; i++) scanf("%d", &a[i]);

	for (int i = 1; i <= n; i++) dp[i] = -1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			int k = cost[a[j]];
			if (k > i || dp[i-k] < 0) continue;
			int tmp = dp[i-k] + 1;
			if (dp[i] < tmp || (dp[i] == tmp && num[i] < a[j])) {
				dp[i] = tmp;
				num[i] = a[j];
			}
		}
	}

	vi ans;
	for (int i = n; i > 0; ) {
		assert(dp[i] > 0);
		ans.push_back(num[i]);
		i -= cost[num[i]];
		assert(i >= 0);
	}
	sort(all(ans), greater<int>());
	for (int x : ans) printf("%d", x);
	puts("");
}


Measured memory_bytes: 384
n=int(input())
t, a = map(int, input().split())
H = list(map(int, input().split()))

min_d = abs(a-(t-H[0]*0.006))
ans = 0
for i in range(n):
    d = abs(a-(t-H[i]*0.006))
    if(min_d > d):
        min_d = d
        ans   = i
print(ans+1)


Measured memory_bytes: 3060
uses math;
var n,x,y,i,j:longint;
    a,b,c:array[0..107] of longint;
	f:array[0..57,-10007..10007] of longint;
begin
  readln(n,x,y);
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  fillchar(c,sizeof(c),0);
  for i:=1 to n do
  begin
    readln(a[i],b[i],c[i]);
    a[i]:=a[i]*y;
    b[i]:=b[i]*x;
  end;
  for i:=0 to n do
	for j:=-10000 to 10000 do
	  f[i,j]:=maxlongint div 2;
  for i:=1 to n do
    f[i,a[i]-b[i]]:=c[i];
  for i:=2 to n do
	for j:=-10000 to 10000 do
	  f[i,j]:=min(f[i,j],min(f[i-1,j],f[i-1,j-a[i]+b[i]]+c[i]));
  if (f[n,0]<maxlongint div 2) then writeln(f[n,0]) else writeln(-1);
end.
	

Measured memory_bytes: 3968
#define _CRT_SECURE_NO_WARNINGS 1

#include <set>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int a[maxn];
int n,k;

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

int main() {
	sd(n), sd(k);
	rep(i,1,n) sd(a[i]);
	int l = 1, r = INF;
	int ans = 0;
	while(l <= r) {
		int mid = (l + r + 1) >> 1;
		// cout << "mid = " << mid << endl;
		if(check(mid)) {
			ans = mid;
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	pd(ans);
	return 0;
}

Measured memory_bytes: 4504
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

int64_t Func(int64_t b, int64_t n) {
  if (b > n) return n;
 
  return Func(b, n / b) + (n % b);
}

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

    if(n == s){
        cout << n + 1 << endl;
        return 0;
    }
    for(int64_t i = 2; i * i <= n; ++i){
        if(Func(i, n) == s){
            cout << i << endl;
            return 0;
        }
    }
    for(int64_t p = sqrt(n); p >= 1; --p){
        int64_t b = (n - s) / p + 1;
        if(b >= 2 && Func(b, n) == s){
            cout << b << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

using namespace std;
using L64 = int64_t;

/* {x,y}という表現で格納される[x^y] */
vector<pair<L64, int>> prime_factorize(L64 N) {
  vector<pair<L64, int>> res;
  for (int a = 2; a * a <= N; ++a) {
    if (N % a != 0) {
      continue;
    }
    int ex = 0;
    while (N % a == 0) {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

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

  L64 x = 0;
  for (int a = 1; a <= N; a++) {
    for (int n = a; n <= N; n += a) {
      x += n;
    }
  }
  cout << x;

  return 0;
}

#if 0
  vector<int> num(N + 1, 0);

  for (int i = 2; i <= N; i++) {
    vector<pair<L64, int>> res = prime_factorize(i);
    for (auto p : res) {
      num[p.first] += p.second;
    }
  }
  L64 result = 1;
  for (int i = 2; i <= N; i++) {
    result += i * num[i];
  }
  cout << result;
#endif

Measured memory_bytes: 3588
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        mut t: Chars
    }

    let mut pred = 'D';
    for c in 0..t.len() {
        if t[c] == 'P' {
            print!("P");
            pred = 'P'
        }
        if t[c] == 'D' {
            print!("D");
            pred = 'D'
        }
        if t[c] == '?' {
            if pred == 'P' {
                print!("D");
                pred = 'D';
            } else {
                if c < t.len() - 1 {
                    if t[c + 1] == 'D' || t[c + 1] == '?' {
                        print!("P");
                        pred = 'P';
                    } else {
                        print!("D");
                        pred = 'D';
                    }
                } else {
                    print!("D");
                    pred = 'D';
                }
            }
        }
    }
    print!("\n");
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

ll dp[101010];

int main() {
    int n,k;
    cin>>n>>k;
    ll sum=0;
    for(int i=k;i>=1;i--){
        dp[i]=modpow(k/i,n,MOD);
        for(int j=i*2;j<=k;j+=i) dp[i]-=dp[j];
        dp[i]=(dp[i]%MOD+MOD)%MOD;
        sum+=i*dp[i]%MOD; 
    }
    cout<<sum%MOD<<endl;
}



Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
int main()
{
    string a, b;
    cin >> a >> b;
    
    ll res = 1e12;
    for (int i = 0; i < a.length() - b.length() + 1; i++) {
        ll tmp = 0;
        for (int j = 0; j < b.length(); j++) {
            if (a[j + i] != b[j]) {
                tmp++;
            }
        }
        res = min(res, tmp);
    }
    cout << res;

    return 0;
}


Measured memory_bytes: 3640
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> a(n), s(n + 1); rep(i, n)cin >> a[i];
	sort(all(a));
	rep(i, n)s[i + 1] = s[i] + a[i];
	int res = 1;
	rrep(i, n)
	{
		if (s[i] * 2 >= a[i])++res;
		else break;
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef deque<int> di;
typedef pair<int,int> pi;
#define pb push_back
#define mp make_pair
#define mh make_heap
#define pf push_front
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define FOR(i,a,b) for(ll i=a;i<b;i++)
int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    ll sum=0;
    string s;
    cin>>s;
    FOR(i,0,s.length())
    {
        sum+=s[i]-'0';
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



    return 0;
}


Measured memory_bytes: 3708
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;
string s , t ;
int main ( ){
cin >> s  >> t ;
n = s.length() ;int  m = t.length() ;
if ( m > n ){
    puts("UNRESTORABLE");
    return 0;
}
string tmp = "", ANS = "" ;
for ( int i = 0 ;  i+m-1 < n ; i++ ){
 string tmp2 = tmp ;
 int j = 0 ;
 if ( s[i] == '?' || s[i] == t[j] ){
    bool sol = 1 ;
    int st = i+1 ;
    j++;
    while ( j < m  ){
        if ( !(s[st] == t[j] || s[st] == '?' ) ) { sol = 0 ; break; }
       st++; j++;
    }
    if ( sol ){
        tmp2 += t ;
        for ( int w = st ; w < n ; w++  ) tmp2.push_back( s[w] == '?' ? 'a' :s[w]);
        if ( ANS.size() == 0 ) ANS = tmp2 ;
        else ANS = min ( ANS , tmp2 );
    }
 }
 tmp.push_back(s[i] == '?' ? 'a' : s[i]);
}
if ( ANS.size() == 0 ) puts("UNRESTORABLE");
else cout <<  ANS ;
return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const ll mod = 1e9 + 7;

int m;
string K;
int n;

ll d[10005][105];

inline void add(ll &x, ll y){
    x = (x + y) % mod;
}

void build(){
    for(int j = 0; j < 10; j++) (++d[0][j%m]) %= mod;
    for(int i = 1; i < n; i++){
        for(int j = 0; j < m; j++){
            for(int k = 0; k < 10; k++){
                add(d[i][(j + k) % m], d[i-1][j]);
            }
        }
    }
}

ll dp(int i, int v){
    if(!i){
        ll c = 0;
        for(int j = 0; j <= K[i]; j++) if(j % m == v) ++c;
        return c;
    }
    ll ans = 0;
    for(int j = 0; j < K[i]; j++){
        add(ans, d[i-1][(v + m - (j%m)) % m]);
    }
    return (ans + dp(i-1, (v+m-(K[i]%m)) % m)) % mod;
}

int main(){
    fio;
    cin >> K >> m;
    n = K.size();
    for(int i = 0; i < n; i++) K[i] -= '0';
    build();
    reverse(K.begin(),K.end());
    cout << (dp(n-1,0) + mod - 1) % mod << '\n';
/*
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cout << d[i][j] << ' ';
        cout << '\n';
    }
*/
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

int main(){ 
   string s;
   cin>>s;
   ll y=0;
   ll n=stoll(s);
   rep(i,s.size()){
      y+=int(s[i]-'0');
   }
   
   n%y==0? cout<<"Yes":cout<<"No";
   

   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,N,a[2001000];
bool check_big(int x,int k){
	return (a[x+1]>k)&(a[x]>k);
}
bool check_small(int x,int k){
	return (a[x+1]<=k)&(a[x]<=k);
}
bool check(int k){
	for(int i=0;i<N-1;i++){
		if(check_big(N-i-1,k)||check_big(N+i,k)){
			return 0;
		}
		if(check_small(N-i-1,k)||check_small(N+i,k)){
			return 1;
		}
	}
	return (a[1]<=k);
}
int main(){
//	freopen("pyramid.in","r",stdin);
//	freopen("pyramid.out","w",stdout);
	cin>>N;
	n=N*2-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int l=1,r=n;
	while(l+1<r){
		int m=(l+r)/2;
		if(check(m)){
			r=m;
		}
		else{
			l=m;
		}
	}
	cout<<r;
	return 0;
}

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

int main() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    ll A[5000], B[5000], C[5000];
    ll E[10000000], D[10000000];

    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];
    int idx = 0;
    for (int i=0; i < X; i++) {
        for (int j=0; j < Y; j++) {
            E[idx++] = A[i] + B[j];
        }
    }
    sort(E, E + idx, greater<ll>());
    //for (int i = 0; i < K; i++) cout << E[i] <<"\n";
    idx = 0;
    for (int i = 0; i < K; i++) {
        for (int j=0; j < Z; j++) {
            D[idx++] = E[i] + C[j];
        }
    }

    sort(D, D + idx, greater<ll>());

    for (int i = 0; i < K; i++) cout << D[i] <<"\n";
}

Measured memory_bytes: 36224
package main

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

type intStack struct {
	stack []int
	idx   int
}

func (s *intStack) push(i int) {
	s.stack[s.idx] = i
	s.idx++
}

func (s *intStack) pop() (int, bool) {
	if s.idx == 0 {
		return 0, false
	}
	val := s.stack[s.idx-1]
	s.idx--
	return val, true
}

func initStack() *intStack {
	s := make([]int, 20000)
	return &intStack{
		stack: s,
		idx:   0,
	}
}

type intStack2 struct {
	stack [][2]int
	idx   int
}

func (s *intStack2) push(i, v int) {
	s.stack[s.idx][0] = i
	s.stack[s.idx][1] = v
	s.idx++
}

func (s *intStack2) pop() (int, int, bool) {
	if s.idx == 0 {
		return 0, 0, false
	}
	val1 := s.stack[s.idx-1][0]
	val2 := s.stack[s.idx-1][1]
	s.idx--
	return val1, val2, true
}

func initStack2() *intStack2 {
	s := make([][2]int, 10000)
	return &intStack2{
		stack: s,
		idx:   0,
	}
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()

	slant := initStack()
	pools := initStack2()
	sum := 0

	t := stdin.Text()
	for i, c := range t {
		switch c {
		case rune('\\'):
			slant.push(i)
		case rune('/'):
			s, ok := slant.pop()
			if ok {
				pools.push(s, i-s)
				sum = sum + i - s
			}
		}

	}

	fmt.Println(sum)

	s := 1000000
	pool := 0
	ps := []int{}
	for {
		v1, v2, ok := pools.pop()
		if !ok {
			break
		}
		if s > v1 {
			if pool != 0 {
				ps = append(ps, pool)
				pool = 0
			}
			s = v1
		}
		pool = pool + v2
	}
	if pool != 0 {
		ps = append(ps, pool)
		pool = 0
	}
	fmt.Print(len(ps))
	for i := len(ps) - 1; i >= 0; i-- {
		fmt.Print(" ", ps[i])
	}
	fmt.Println()

}



Measured memory_bytes: 1424
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!{
        x: i64
    }
    for a in 0..1000i64 {
        let n = a.pow(5u32) - x;
        let mut l: i64 = -1000;
        let mut r: i64 = 1000;
        while l + 1 < r {
            let m = (l + r) / 2;
            if m.pow(5u32) > n {
                r = m;
            } else {
                l = m;
            }
        }
        if l.pow(5u32) == n {
            println!("{} {}", a, l);
            return;
        }
    }
}


Measured memory_bytes: 2168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int a,b,max;
    while(~scanf("%d%d",&a,&b))
    {
        if(a+b>a-b)
            max=a+b;
        else
            max=a-b;
        if(max<a*b)
            max=a*b;
        printf("%d\n",max);
    }
        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
ll gcd(ll a, ll b){
  if(a<b){
    swap(a,b);
  }
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,x;
  cin>>n>>x;
  vint a(n);
  int ans;
  rep(i,n){
    cin>>a[i];
    if(i==0){
      ans=abs(x-a[i]);
    }
    else{
      ans=gcd(ans,abs(x-a[i]));
    }
  }
  cout<<ans<<'\n';
  return(0);
}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

int main()
{
  IOS;
  int n, m;
  cin >> n >> m;
  cout << n*(n-1)/2+m*(m-1)/2 << endl;
  return 0;
}


Measured memory_bytes: 3584
import fractions


def main() -> None:
    N = int(input())
    A = [int(x) for x in input().split()]

    left = [0] * (N + 1)
    right = [0] * (N + 1)
    for i in range(N):
        left[i + 1] = (fractions.gcd(left[i], A[i]))
        right[N - i - 1] = (fractions.gcd(right[N - i], A[N - 1 - i]))

    ans = 0
    for i in range(N):
        ans = max(ans, fractions.gcd(left[i], right[i + 1]))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16112
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

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

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double ans = 0;
	cin >> N;
	rep(i, N){
		double n;
		string S;
		cin >> n >> S;
		ans += (S[0] == 'J' ? n : n * 38e4);
	}
	printf("%lf\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    map<ll,ll, greater<ll>>mp;
    for(ll i=0; i<n; i++ )
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    ll c=0;
    ll ar=1;
    ll f=0;
    for(auto it=mp.begin(); it!=mp.end(); ++it)
    {
        ll s=it->second;
        if(c==0)
        {
            if(s>=4)
            {
                cout<<it->first*it->first<<endl;
                f=1;
                break;
            }
        }
        if(s>=2)
        {
            ar=ar*it->first;
            c++;
            if(c==2)
            {
                break;
            }
        }
    }
    if(c!=2&&f==0)
    {
        cout<<0<<endl;
    }
    else if(c==2&&f==0)
    {
        cout<<ar<<endl;
    }

}


Measured memory_bytes: 10460
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == 'B'){
                if(sb.length() != 0){
                    sb.deleteCharAt(sb.length() - 1);
                }
            }
            else{
                sb.append(s.charAt(i));
            }
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 27024
s = str(input())

ans = "Yes"
for i in range(len(s)):
    if (i+1) %2 == 1:
        if s[i]=="L":
            ans = "No"
    if (i+1) %2 == 0:
        if s[i]=="R":
            ans = "No"         
print(ans)

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int n;
int main()
{
	cin >> n;
	int i, a[1000], b[1000], c[1000], x[1000], y[1000], z[1000], res[1000];
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		x[i] = a[i];
		if (x[i] < b[i]) {
			y[i] = x[i];
			x[i] = b[i];
		}
		else {
			y[i] = b[i];
		}
		if (x[i] < c[i]) {
			z[i] = y[i];
			y[i] = x[i];
			x[i] = c[i];
		}
		else if (y[i] < c[i]) {
			z[i] = y[i];
			y[i] = c[i];
		}
		else {
			z[i] = c[i];
		}
	}
	for (i = 0; i < n; i++) {
		res[i] = x[i] * x[i] - z[i] * z[i] - y[i] * y[i];
		if (res[i] == 0) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1172
fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: i64 = s.next().unwrap().parse().unwrap();
	let m: i32 = s.next().unwrap().parse().unwrap();
	let d: i64 = s.next().unwrap().parse().unwrap();
	let p = if d == 0 { n } else { 2 * (n - d) };
	println!("{}", p as f64 * (m - 1) as f64 / (n * n) as f64);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (510)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,m,a[N][N]; LL f[N][N],suf[N][N],sum[N][N],ans;
int main(){
	read(n);
	for(int i=1;i<=n;i++)
	for(int j=1;j<n;j++)read(a[i][j+(j>=i)]);
	for(int i=1;i<=n;i++)
	for(int j=n;j>i;j--){
		suf[i][j]=suf[i][j+1];
		for(int k=1;k<=i;k++)suf[i][j]+=a[j][k];
	}
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n+1;j++){
		sum[i][j]=sum[i][j-1];
		for(int k=i;k<j;k++)sum[i][j]+=a[k][j];
	}
	memset(f,inf,sizeof(f)),ans=1e18,f[0][0]=0;
	for(int i=0;i<=n;i++)
	for(int j=i;j<=n;j++)
	for(int k=j+1;k<=n+1;k++)
	f[j][k]=min(f[j][k],f[i][j]+sum[j+1][k]+suf[j][k+1]-suf[i][k+1]);
	for(int i=0;i<=n;i++)ans=min(ans,f[i][n+1]);
	cout<<ans;
}

Measured memory_bytes: 9344
import scala.io.StdIn

object Main extends App {
  val N  = StdIn.readLine().split(" ").map(_.toInt).head
  val a  = StdIn.readLine().split(" ").map(_.toInt)

  def solve(a: Array[Int], N: Int): Int = {
    var max = a.head
    var cnt = 1
    a.tail.foreach {x =>

      if (x >= max) {
        cnt = cnt + 1
        max = x
      }
    }
    cnt
  }

  println(solve(a, N))
}
  



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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

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

int f(int a, int b) {
	int ret = 0;
	while (a) {
		a /= 10;
		++ret;
	}
	int cur = 0;
	while (b) {
		b /= 10;
		++cur;
	}
	return max(ret, cur);
}

void solve() {
	long long n; scanf("%lld", &n);
	vector<long long> v;
	for (long long i = 1; i*i <= n; ++i) {
		if (n%i == 0) v.push_back(i);
	}
	int ans = 2e9;
	for (long long x: v) {
		ans = min(ans, f(x, n/x));
	}
	printf("%d", ans);
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define FL 100005

int main(void){
  int i,time[FL+1],cpu=0,n,q,head=0,tail,ent[FL+1],j,count;
  char ko[FL+1][15],en[FL+1][15];

  scanf("%d %d",&n,&q);

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

  tail=i;

  j=0;
  i=0;
  count=0;
  while(1){

    if(time[i]<q){
      cpu+=time[i];
    }
    else if(time[i]>=q){
      cpu+=q;
    }

    time[i]=time[i]-q;

    if(time[i]<=0){
      ent[j]=cpu;
      strcpy(en[j],ko[i]);
      j++;
      count++;
    }

    else if(time[i]>0){
      if(tail<FL){
      strcpy(ko[tail],ko[i]);
      time[tail]=time[i];
      tail++;
      }
      else{
	tail=head;
	strcpy(ko[tail],ko[i]);
	time[tail]=time[i];
	tail++;
      }
    }

    i++;
    if(i>=FL){
      i=head;
    }

    if(count==n) break;
  }
      
  for(i=0;i<n;i++){
    printf("%s ",en[i]);
    printf("%d\n",ent[i]);
  }

  return 0;
  
}

Measured memory_bytes: 3504
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
ll max(ll a,ll b){
	if(a>b) return a;
	else return b;
}
ll min(ll a,ll b){
	if(a<=b) return a;
	else return b;
}
int n,a,b,c,d;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,n;
  	cin>>a>>b>>c>>n;
  	if(n<=a) cout<<n<<endl;
  	else if(n<=a+b) cout<<a<<endl;
  	else cout<<a-(n-(a+b));
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int w,s;
		w = sc.nextInt() - 1;
		s = sc.nextInt() - 1;
		System.out.println(w*s);
	}
}

Measured memory_bytes: 21972
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] b = new int[n - 1];
    for(int i = 0; i < n - 1; i++) {
      b[i] = sc.nextInt();
    }
    int ans = b[0] + b[n - 2];
    for(int i = 0; i < n - 2; i++) {
      ans += Math.min(b[i], b[i + 1]);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

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

    int X, Y, Z, N;
    cin >> X >> Y >> Z;
    N = X + Y + Z;
    
    vi A(N), B(N), C(N);
    using T = tuple<int, int, int, int>;
    vector<T> U(N);
    rep(i, N) {
        cin >> A[i] >> B[i] >> C[i];
        U[i] = T(B[i] - A[i], A[i], B[i], C[i]);
    }
    sort(all(U));
    rep(i, N) {
        int x;
        tie(x, A[i], B[i], C[i]) = U[i];
        // cout << A[i] << ' ' << B[i] << ' ' << C[i] << endl;
    }

    vll L(N+1), R(N+1);


    {
        priority_queue<int> Q; // c-a, c-b
        ll S = 0;
        rep(i, X - 1)S += A[i], Q.push(C[i] - A[i]);
        for (int i = X - 1; i <= N - Y; ++i) {
            S += A[i];
            Q.push(C[i] - A[i]);
            while (sz(Q) > X)S += Q.top(), Q.pop();
            L[i] = S;
        }
    }
    {
        priority_queue<int> Q; // c-a, c-b
        ll S = 0;
        for (int i = N - 1; i > N - Y; --i)S += B[i], Q.push(C[i] - B[i]);
        for (int i = N - Y; i >= X; --i) {
            S += B[i];
            Q.push(C[i] - B[i]);
            while (sz(Q) > Y)S += Q.top(), Q.pop();
            R[i] = S;
        }
    }

    ll ans = -1;
    for (int i = X - 1; i <= N - Y - 1; ++i) {
        smax(ans, L[i] + R[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5244
import java.util.*;
public class Main{
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	int M = sc.nextInt();
        long L = sc.nextLong();
        long[][] E = new long[N+1][N+1];
        for(int i=0;i<=N;i++){
          for(int j=i;j<=N;j++){
            E[i][j]=Long.MAX_VALUE/2 -1;
          }
        }
        for(int i=0;i<M;i++){
          int A = sc.nextInt();
          int B = sc.nextInt();
          E[Math.min(A,B)][Math.max(A,B)] = sc.nextLong();
        }
        long[][] Ed = E.clone();
        for(int k=0;k<=N;k++){
          for(int i=0;i<N;i++){
            for(int j=i+1;j<=N;j++){
              long compare = (k<j)?(k<i)?Ed[k][i]+Ed[k][j]:Ed[i][k]+Ed[k][j]:Ed[i][k]+Ed[j][k];
        	  Ed[i][j]=Math.min(Ed[i][j],compare);
            }
          }
        }
        for(int i=0;i<=N;i++){
          for(int j=i;j<=N;j++){
            Ed[i][j] = (Ed[i][j]>L)?1000000000:1;
          }
        }
        for(int k=0;k<=N;k++){
          for(int i=0;i<N;i++){
            for(int j=i+1;j<=N;j++){
              long compare = (k<j)?(k<i)?Ed[k][i]+Ed[k][j]:Ed[i][k]+Ed[k][j]:Ed[i][k]+Ed[j][k];
        	  Ed[i][j]=Math.min(Ed[i][j],compare);
            }
          }
        }
        int Q = sc.nextInt();
        for(int i=0;i<Q;i++){
          int s = sc.nextInt();
          int t = sc.nextInt();
          System.out.println((E[Math.min(s,t)][Math.max(s,t)]==1000000000)?-1:E[Math.min(s,t)][Math.max(s,t)]-1);
        }
    }
}
        

Measured memory_bytes: 93088
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int dp[1<<17];
int g[20][20];
int pre[1<<17][17];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int nega=0;
	if(a<0)nega=-a;
	if(b<0)nega-=1-b;
	
	if((long long)a*b<=0){
		printf("Zero\n");return 0;
	}else if(nega%2){
		printf("Negative\n");return 0;
	}printf("Positive\n");
}

Measured memory_bytes: 128
import java.util.*; 
import java.io.*;

public class Main {
	static int dp[] = new int[500001]; 
	static int n = 0; 
	static int a[]; 
	public static int func(int ind) {
		if(ind == n - 1) return 0; 
		if(ind >= n) return Integer.MAX_VALUE; 
		if(dp[ind] != -1) return dp[ind]; 
		
		int left = Math.abs(a[ind] - a[ind + 1]) + func(ind+1); 
		int right = Integer.MAX_VALUE; 
		if(2 + ind < n) 
			 right = Math.abs(a[ind] - a[ind + 2]) + func( ind + 2); 
		return dp[ind] = Math.min(right, left); 
	}
	public static void solve(InputReader in) {
		n = in.readInt(); 
		a = new int[n]; 
		Arrays.fill(dp, -1);
		for(int i = 0; i<n; i++) {
			a[i] = in.readInt(); 
		}
		System.out.println(func(0)); 
	}
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in); 
		int t = 1; 
		while(t-- > 0) {
			solve(in); 
		}
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
     
     public String next() {
		return readString();
	}
    
     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

int main(){
  int M, D;
  fastScan(M);
  fastScan(D);
  int ans = 0;
  for(int i = 0; i <= M; i++){
    for(int j = 0; j <= D; j++){
      int d1 = j % 10;
      int d2 = j / 10;
      if(d1 >= 2 && d2 >= 2){
        if(d1 * d2 == i){
          ans++;
        }
      }
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
main=interact $ f
f y
 | 'A' /= head x ="WA"
 | 'C' == last x ="WA"
 | 'C' == x !! 1 ="WA"
 | "AC" == filter (`elem` ['A'..'Z']) x ="AC"
 | otherwise = "WA"
 where x = init y

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  int N;
  string S;
  cin>>S;
  N=S.size();

  rep(i,N){
    if(S[i]=='?'){
      S[i]='D';
    }
  }
  cout<<S<<endl;

  return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll>a(n),b, c;
    rep(i, 0, n)cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    rep(i, 0, n/2)b.push_back(a[i]);
    rep(i, n/2, n)c.push_back(a[i]);
    ll ans=0,sumb=0,sumc=0;
    rep(i, 0, b.size())sumb += b[i];
    rep(i, 0, c.size())sumc += c[i];
    ans = (sumb-sumc)*2;
    ll ans2 = ((sumb+c[0])-(sumc-c[0]))*2;
    //cout << sumb << sumc << endl;
    if(n%2==0){
        cout << ans-b[b.size()-1]+c[0] << endl;
        return 0;
    }else{
        ll ansa = ans + c[0] + c[1];
        ll ansb = ans2 - c[0] - b[b.size()-1]; 
        //cout << ansa << " " << ansb << endl;
        cout << max(ansa, ansb) << endl;
        return 0;
    }
}

Measured memory_bytes: 5112
#include <iostream>
#include <cstdlib>
using namespace std;
int N;
int solve(int N){
	int i,j;
	int num=0;
	int cnt;
	for (i = 3; i <= N; i+=2) {
		cnt = 0;

		for (j = 3; j < i/2; j+=2) {
			if(i % j == 0){

                cnt++;
            }
		}


		if(cnt+2 == 8) num++;
	}
	return num;
}
int main()
{
	cin >> N;
	cout << solve(N) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int main()
{
  char s[51], t[51];
  scanf("%s %s", s, t);
  int slen = strlen(s);
  int tlen = strlen(t);
  
  for (int i = slen - tlen; i >= 0; --i)
  {
    bool re = true;
    for (int j = 0; j < tlen; ++j)
    {
      if (s[i + j] != t[j] && s[i + j] != '?')
      {
        re = false;
        break;
      }
    }
    if (re == false) continue;
    memcpy(s + i, t, tlen);
    for (int j = 0; j < slen; ++j)
    {
      if (s[j] == '?') s[j] = 'a';
    }
    puts(s);
    return 0;
  }
  puts("UNRESTORABLE");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define mx 10000005
#define ll long long
vector<int>prime(10000000);
bool vis[10000005];
int a[10000005],store[10000005],cn;
void sieve()
{
    vis[0]=vis[1] = true;
    for(int i=2;i*i<mx;i++)
    {
        if(!vis[i])
        {
            prime[cn++]=i;
            for(int j=i*2;j<mx;j+=i)
                vis[j]=true;
        }

    }
}

int main()
{
    sieve();
    ll n;
    cin >> n;
    ll ans=1;
    for(ll i=2;i<=n;i++)
    {
        ll p = i;
        ll tmp=1;
        for(ll j=0;prime[j]*prime[j]*prime[j]<=p;j++)
        {
            ll cnt=0;
            if(p%prime[j]==0)
            {
                while(p%prime[j]==0)
                {
                    cnt++;
                    p/=prime[j];
                }
                tmp*=(cnt+1);
            }
        }
        if(p>1)
        {
            ll sq = sqrt(p);
            if(vis[p]==0)
                tmp*=2;
            else if(sq*sq==p)
                tmp*=3;
            else
                tmp*=4;
        }
        ans+=(tmp*i);
    }

    printf("%lld\n",ans);
}


Measured memory_bytes: 51852
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18


const ll MAX_A = 2e3;
string A;
ll dp[MAX_A+1][MAX_A+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
ll comb(ll n, ll r){ // nCr
	ll ans = 1;
	REP(i,r) ans *= n - i;
	REP(i,r) ans /= r - i;
	return ans;
}
 
int main() {
	// 入力
	cin >> A;
	
	// 解法
	ll ans = comb(A.size(),2) + 1;
	string abc = "abcdefghijklmnopqrstuvwxyz";
	REP(i,26){
		ll count = 0;
		REP(j,A.size()){
			if (A[j]==abc[i]) count++;
		}
		ans -= comb(count, 2);
	}
	
	//出力
	cout << ans << endl;
}


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

int main() {
  int N, A;   //Nは払う金額　Aは一円玉の枚数
  cin >> N >> A;
  
  if( A >= N - (N/500)*500 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

typedef long long ll;

bool is_all(vector<bool> &b) {
	for(auto x: b) {
		if(x == false) return false;
	}
	return true;
}

int calc(vector<pair<int, int>> &p, pair<int, int> &c) {

	vector<bool> s(p.size(), false);

	int res = 1;
	s[0] = true;
	int bef = 0;
	while(is_all(s) == false) {
		for(int i = 0; i < p.size(); i++) {
			if(bef == i) continue;
			if(p[i].first - p[bef].first == c.first && p[i].second - p[bef].second == c.second) {
			s[i] = true;
			bef = i;
			goto next_calc;
			}
		}
		for(int i = 0; i < p.size(); i++) {
			if(s[i] == false) {
				res++;
				s[i] = true;
				bef = i;
				break;
			}
		}
		next_calc:
		;
	}
	return res;
}

int main() {
	int N;
	cin >> N;
	vector<pair<int, int> > p(N);
	for(auto &x: p) cin >> x.first >> x.second;

	sort(p.begin(), p.end());


	int out = N;
	for(int i = 0; i < N - 1; i++) {
		for(int j = i + 1; j < N; j++) {
			pair<int, int> c = make_pair(p[j].first - p[i].first, p[j].second - p[i].second);
			out = min(out, calc(p, c));
		}
	}

	cout << out << endl;
}


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

int main() {
    ios::sync_with_stdio(false);
    
    vector<int> arr(5);
    for (auto &el: arr) cin >> el;

    int res = 999999;
    do {    

        int t = 0, i = 0;
        while( i < 5 ) {
            while( t % 10 != 0 ) t++;
            t += arr[i++];
        }

        res = min(res, t);

    } while( next_permutation(begin(arr), end(arr)) );

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	string S;
	cin >> S;
	string ans = "No";
	if ((int)(S[0] - 'a' + 1)*(int)(S[1] - 'a' + 1)*(int)(S[2] - 'a' + 1) == 6)
	{
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

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

//---- Print Test Cases
int main(){
    int x = 1, i = 1;
    while(true){
        scanf("%d", &x);
        if(x == 0) break;
        printf("Case %d: %d\n", i, x);
        i++;
    }
    return 0;
}

Measured memory_bytes: 3092