akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}

int calc(int N)
{
   rep(k, 2, 1000) {
      if (k*(k-1)/2 == N) {
         return k;
      }
   }
   return -1;
}

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

   int K = calc(N);
   if (K == -1) {
      printf("No\n");
      return 0;
   }

   vec< vec<int> > G(K, vec<int>());
   int n = 1;
   rep(i, 0, K-1) {
      rep(j, i+1, K) {
         G[i].PB(n);
         G[j].PB(n);
         n++;
      }
   }

   printf("Yes\n");
   printf("%lld\n", K);
   rep(i, 0, K) {
      printf("%lld ", K-1);
      rep(j, 0, K-1) {
         printf("%lld ", G[i][j]);
      }
      printf("\n");
   }

   return 0;
}


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

int main() {
	int n,k;
	string s;
	cin >> n >> k;
	cin >> s;

	s[k - 1] = s[k - 1] - ('A' - 'a');
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;
    char s[600][600];

    rep (i, n)
    {
        rep (j, n)
        {
            cin >> s[i][j];
            s[i + n][j] = s[i][j];
            s[i][j + n] = s[i][j];
            s[i + n][j + n] = s[i][j];
        }
    }

    int ans = 0;

    for (int b = 0; b < n; ++b)
    {
        bool flag = true;
        for (int i = 0; i < n && flag; ++i)
        {
            for (int j = i + 1; j < n && flag; ++j)
            {
                if (i == j) continue;
                if (s[i][j + b] != s[j][i + b])
                {
                    flag = false;
                }
            }
        }
        if (flag)
        {
            ans += n - b;
        }
    }

    for (int a = 1; a < n; ++a)
    {
        bool flag = true;
        for (int i = 0; i < n && flag; ++i)
        {
            for (int j = i + 1; j < n && flag; ++j)
            {
                if (i == j) continue;
                if (s[i + a][j] != s[j + a][i])
                {
                    flag = false;
                }
            }
        }
        if (flag)
        {
            ans += n - a;
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 640
import sys
import bisect
input = sys.stdin.readline
 
def main():
    s = list(map(int,input().split()))
    s.sort()
    
    ans=1
    if(s[0]!=s[1]):
        ans+=1
    if(s[1]!=s[2]):
        ans+=1
    
    print(ans)
    
main()

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int h,w,a,b; cin>>h>>w>>a>>b;
    rep(i, h) rep(j, w){
        if(i<b&&j<a || i>=b&&j>=a) cout<<1;
        else cout<<0;
        if(j==w-1) out("");
    }
}

Measured memory_bytes: 1280
/*

import "core"
import "procon"

fn main() {
  n := read_int()
  power := int(1)
  for i in range(1, n) {
    power = (power * i) % (1000000000 + 7)
  }
  println(power)
}

main()

*/

#include "stdbool.h"
#include "stdint.h"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "inttypes.h"


struct core_string_String {
char* p;
int64_t len;
};
struct Array1024_core_prelude_Char { char data[1024]; };



bool core_prelude_true;
bool core_prelude_false;
bool core_definitions_is_windows;
bool core_definitions_is_compiletime;
bool core_definitions_is_runtime;
bool core_definitions_is_jscodegen;
float core_math_M_PI;
void* core_pointer_nullGG_() {
void* core_pointer_tmpid27 = ((void*)(0));
return core_pointer_tmpid27;
}
void* core_pointer_null;
char* core_pointer_plusexclGcore_prelude_CharG_core_pointer_Ptr_core_prelude_Char_core_prelude_Int(char* core_pointer_p, int64_t core_pointer_i) {
return ((char*)((((int64_t)(core_pointer_p)) + core_pointer_i)));
}
char core_string_getGG_core_prelude_CString_core_prelude_Int(char* core_string_cs, int64_t core_string_i) {
char core_string_tmpid28 = (*(core_pointer_plusexclGcore_prelude_CharG_core_pointer_Ptr_core_prelude_Char_core_prelude_Int(((char*)(core_string_cs)), core_string_i)));
return core_string_tmpid28;
}
char core_string_charGG_core_prelude_Int(int64_t core_string_c) {
char core_string_tmpid30 = ((char)(core_string_c));
return core_string_tmpid30;
}
char core_string_cr;
char core_string_lf;
int64_t procon_read_intGG_() {
int64_t procon_ret;
scanf("%" PRId64, &procon_ret);
int64_t procon_tmpid46 = procon_ret;
return procon_tmpid46;
}
bool procon_is_debug;
void b_mainGG_() {
int64_t b_n = procon_read_intGG_();
int64_t b_power = 1;
{
int64_t b_i = 1;
while ((b_i <= b_n)) {
b_power = (((b_power * b_i)) % ((1000000000 + 7)));
;
(b_i += 1);
};

}
;
;
;
printf("%lld", b_power);
;
;
printf("%s", "\n");
;
;
;
}

void flori_main() {
core_prelude_true = 1;
core_prelude_false = 0;
core_definitions_is_windows = 
#ifdef _WIN32
#define is_windows true
#elif _WIN64
#define is_windows true
#else
#define is_windows false
#endif
  is_windows;
core_definitions_is_compiletime = 
#ifdef FLORI_COMPILETIME
#define is_compiletime true
#else
#define is_compiletime false
#endif
  is_compiletime;
core_definitions_is_runtime = !(core_definitions_is_compiletime);
core_definitions_is_jscodegen = 
#ifdef FLORI_JSCODEGEN
#define is_jscodegen true
#else
#define is_jscodegen false
#endif
  is_jscodegen;
core_math_M_PI = M_PI;
core_pointer_null = core_pointer_nullGG_();
core_string_cr = core_string_charGG_core_prelude_Int(13);
core_string_lf = core_string_charGG_core_prelude_Int(10);
procon_is_debug = core_prelude_true;
b_mainGG_();
}
int main(int argc, char** argv) { flori_main(); }


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    rep(i,n){
        set<char> st1,st2;
        rep(j,n){
            if(j<i)st1.insert(s[j]);
            else st2.insert(s[j]);
        }
        set<char> ret;
        set_intersection(st1.begin(),st1.end(),st2.begin(),st2.end(), inserter(ret, ret.end()));
        ans=max(ans,(int)ret.size());
    }
    cout<<ans<<endl;
    return 0;
}

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

ll a,b,c,d,n,m,k;

string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll x,y;
  cin>>x>>y;

  for(int i=0;i<=x; i++){
    for(int j=0; j<=x-i; j++){
      if(i*2+j*4==y && i+j==x){
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";

  return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, P[1010], X[1010];
vi C[1010];
bool flag = true;

pi dfs(int idx) {
    int First = 0;
    itn Second = 0;
    itn SUM = 0;
    bitset<5555> BIT(1);
    for (auto& nxt : C[idx]) {
        auto tmp = dfs(nxt);
        int a = tmp.first;  /*  //部分木の重い色の和*/
        int b = tmp.second; /*  //部分木の軽い色の和*/
        //ナップサック？

        BIT <<= b;
        BIT |= (BIT << (a - b));

        // BIT = (BIT << a) | (BIT << b);

        SUM += a + b;
        Second += b;
        First += a;
    }

    if (First <= X[idx]) {
        return {X[idx], Second};
    }

    for (int i = X[idx]; i >= 0; i--) {
        if (BIT[i]) {
            //大小を保証
            if (SUM - i >= X[idx])
                return {SUM - i, X[idx]};
            else
                return {X[idx], SUM - i};
        }
    }
    //Impossible
    flag = false;
    return {0, 0};
}

void solve() {
    dfs(0);
    if (flag)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
}

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

    cin >> N;
    FOR(N - 1) {
        cin >> P[i];
        P[i]--;
        C[P[i]].eb(i + 1);
    }
    FOR(N) {
        cin >> X[i];
    }

    solve();
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    string s; cin >> s;
    int n = s.size();
    int ans = INF;
    rep(i,n-1){
        if(s[i] != s[i+1]){
            ans = min(ans,max(i+1,n-i-1));
        }
    }
    if(ans == INF) cout << n << endl;
    else cout << ans << endl;
}

    



Measured memory_bytes: 512
use input::Input;

fn main() {
    let mut input = Input::default();

    let d = input.parse::<usize>();
    let _c = (0..26).map(|_| input.parse()).collect::<Vec<i64>>();
    let _s = (0..d)
        .map(|_| (0..26).map(|_| input.parse()).collect())
        .collect::<Vec<Vec<i64>>>();

    let mut x = 1;
    for _ in 0..d {
        println!("{}", x);
        x = (x % 26) + 1;
    }
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2276
#include<stdio.h>
#include<math.h>

int main(void){
	int i;
	int n;
	int flag1, flag2;
	double x1, y1, x2, y2, x3, y3;
	double mx1,my1,mx2,my2;
	double a1,a2;
	double px,py;
	double r;

	scanf("%d", &n);

	for(i = 0; i < n; i++){
		scanf("%lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3);
		flag1 = flag2 = 0;

		mx1 = (x1+x2)/2;
		my1 = (y1+y2)/2;

		mx2 = (x1+x3)/2;
		my2 = (y1+y3)/2;

		if((y2-y1) == 0){
			px = mx1;
			a1 = 0;
			flag1 = 2;
		}else if((x1-x2) == 0){
			py = my1;
			a1 = 0;
			flag1 = 3;
		}else{
			a1 = (x1-x2)/(y2-y1);
			flag1 = 1;
		}

		if((y3-y1) == 0){
			px = mx2;
			a2 = 0;
			flag2 = 2;
		}else if((x1-x3) == 0){
			py = my2;
			a2 = 0;
			flag2 = 3;
		}else{
			a2 = (x1-x3)/(y3-y1);
			flag2 = 1;
		}


		if(flag1==1 && flag2==1){
			px = ((my2-my1)+(a1*mx1-a2*mx2))/(a1-a2);
			py = a1*px + (my1-a1*mx1);
		}else if(flag1 == 2 || flag2 == 2){
			if(flag1 == 2){
				py = a2*px+(my2 - a2*mx2);
			}else if(flag2 == 2){
				py = a1*px+(my1 - a1*mx1);
			}
		}else if(flag1 == 3 || flag2 == 3){
			if(flag1 == 3){
				px = (py+(a2*mx2-my2))/a2;
			}else if(flag2 == 3){
				px = (py+(a1*mx1-my1))/a1;
			}
		}

		r = sqrt((px-x1)*(px-x1)+(py-y1)*(py-y1));

		printf("%.3lf %.3lf %.3lf\n", px,py,r);
	}

	return 0;
}

Measured memory_bytes: 664
N, M = map(int, input().split())
K = []

for _ in range(M):
    a, _ = map(int, input().split())
    k = 0
    for i in map(lambda a: int(a) - 1, input().split()):
        k |= (1 << i)
    K.append((a, k))

dp = [10**18] * (1 << N)
dp[0] = 0
for state in range(1 << N):
    for a, k in K:
        if dp[state | k] > dp[state] + a:
            dp[state | k] = dp[state] + a
ans = dp[(1 << N) - 1]
print(ans if ans < 10**18 else -1)


Measured memory_bytes: 3276
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
const ll N = 200005;
ll a[N],h[N],bit[N],n;
void update(ll x,ll val){
    for(; x <= n ; x += (x&(-x))){
        bit[x] = max(bit[x],val);
    }
}
ll query(ll x){
    ll mx = 0;
    for(; x > 0 ; x -= (x&(-x))){
        mx = max(bit[x],mx);
    }
    return mx;
}


int32_t main(){
    IOS;
    ll i,j,k,m,p,q;
    cin >> n;
    fori2(n) cin >> h[i];
    fori2(n) cin >> a[i];
    fori2(n){
        k = query(h[i]-1);
        update(h[i],k + a[i]);
    }
    ll ans = 0;
    // fori2(n) {
    //     cout << query(i) <<" ";
    //     ans = max(ans,query(i));
    // }
    // cout <<"\n";
    cout << query(n) << "\n";
} 

Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int n;
	cin >> n;
	
	while(n--)
	{
		string snk;
		cin >> snk;
		
		if(snk.size() < 6 || snk.size() % 2 != 0 || (snk.substr(0, 2) != ">'" && snk.substr(0, 2) != ">^"))
		{
			cout << "NA" << endl;
		}
		else if(snk.substr(0, 2) == ">^")
		{
			if(snk.substr(2, 2) == "Q=" && snk.substr(snk.size() - 2, 2) == "~~")
			{
				for(int i = 4; i < snk.size() - 2; i += 2)
				{
					if(snk.substr(i, 2) != "Q=")
					{
						goto ng;
					}
				}
				
				cout << "B" << endl;
			}
			else
			{
			ng:;
				cout << "NA" << endl;
			}				
		}
		else
		{
			if(snk[(snk.size() - 3) / 2 + 2] == '#' && snk[snk.size() - 1] == '~')
			{
				rep(i, (snk.size() - 3) / 2)
				{
					if(snk[i + 2] != '=' || snk[i + 3 + (snk.size() - 3) / 2] != '=')
					{
						goto ng;
					}
				}
				
				cout << "A" << endl;
			}
			else
			{
				cout << "NA" << endl;
			}
		}
	}
}

Measured memory_bytes: 0
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(n - 1):
        if A[j] <= x:
            i += 1
            tmp = A[i]; A[i] = A[j]; A[j] = tmp
    tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp
    return i + 1

def print_list(A, r):
    for i, e in enumerate(A):
        if i == n - 1:
            print(e)
        elif i == r:
            print([e], end=' ')
        else:
            print(e, end=" ")

n = int(input())
A = [int(e) for e in input().split()]
r = partition(A, 0, -1)
print_list(A, r)



Measured memory_bytes: 16368
#include<bits/stdc++.h>
using namespace std;
long long f(long long n)
{
    if(n==1)
    return 1;
    return 2*f(n/2)+1;
}
int main()
{
  //int t;cin>>t;while(t--){
   long long h;cin>>h;
   cout<<f(h);
  //cout<<"  ";}
}

Measured memory_bytes: 256
/*input
60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)xize()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
bool on[3][3];
int arr[3][3];
int main(){
    int n;
    REP(i,3) REP(j,3) cin>>arr[i][j];
    cin>>n;
    REP(z,n){
        int x;
        cin>>x;
        REP(i,3) REP(j,3){
            if(arr[i][j]==x){
                on[i][j]=1;
            }
        }
    }
    REP(i,3) if(on[i][0] and on[i][1] and on[i][2]){
        cout<<"Yes";
        return 0;
    }
    REP(i,3) if(on[0][i] and on[1][i] and on[2][i]){
        cout<<"Yes";
        return 0;
    }
    if(on[0][0] and on[1][1] and on[2][2]){
                cout<<"Yes";
        return 0;
    }
    if(on[0][2] and on[1][1] and on[2][0]){
                cout<<"Yes";
        return 0;
    }
    cout<<"No";
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<String> list = new ArrayList<String>();
        list.add("a");
        String[] tStrings = new String[] {"a", "b","c","d","e","f","g","h","i","j"};
        for (int i = 2 ; i <= n ; i++) {
            List<String> list2 = new ArrayList<String>();
            for (int j = 0 ; j < list.size() ; j++) {
                for (int k = 0 ; k <= countS(list.get(j)) ; k++ ) {
                    list2.add(list.get(j) + tStrings[k]);
                }
            }
            list = list2;
        }

        for (String s : list) {
            System.out.println(s);
        }

    }

    static int countS(String s) {
        Set<String> t = new HashSet<>();
        for (int i = 0 ; i < s.length() ; i++) {
            t.add(s.substring(i, i+1));
        }
        return t.size();
    }

}

Measured memory_bytes: 85036
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
string s;
int main( ){
	int x,y,z,k;
	cin>>s;
	if(s=="Sunny")printf("Cloudy\n");
	else if(s=="Cloudy")printf("Rainy\n");
	else if(s=="Rainy")printf("Sunny\n");
	return 0;
}

Measured memory_bytes: 256
a, b= list(map(int, input().split()))
#a,b= list(input().split())

if a==1 or b==1:
    if a==b:
        print('Draw')
    elif b==1:
        print('Bob')
    else:
        print('Alice')
else:
    if a < b:
        print('Bob')
    elif a > b:
        print('Alice')
    else:
        print('Draw')

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	int n,x;
	cin >> n >> x;

    int sz=2*n-1;
	if(x==1 || x == sz){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
        REP(i,sz){
            cout << 1+(n+x+i-1)%sz <<endl;;
        }
	}

	return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
	int n=4;
	char a[4];
	for(int i=0;i<n;i++)
	{
		scanf("%c",&a[i]);
	}
	if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3])
	{
		printf("Bad");
	}
	else
	{
		printf("Good");
	}
}

Measured memory_bytes: 3196
k,n = map(int,input().split())
a = [int(x) for x in input().split()]
if a[0] == 0:
    a.append(k)
else:
    a.append(k + a[0])

dis = 0
d_li = []
for i in range(1,len(a)):
    tmp = abs(a[i] - a[i-1])
    dis += tmp
    d_li.append(tmp)
    
print(dis - max(d_li))


Measured memory_bytes: 25452
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[3];
		int total = 0;
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.nextInt();
			total += arr[i];
		}
		int k = sc.nextInt();
		Arrays.sort(arr);
		int max = arr[2];
		long dob = arr[2];
		for (int i = 0; i < k; i++) {
			dob *= 2;
		}
		System.out.println(total - max + dob);
	}
}


Measured memory_bytes: 22732
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        
        Scanner sn = new Scanner(System.in);
        int A = sn.nextInt();
        int B = sn.nextInt();
        int C = sn.nextInt();

        int sum = A + B + C;
        if(sum == 17){
            System.out.print("YES");
        } else {
            System.out.print("NO");
        }
    }
}

Measured memory_bytes: 21204
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc103_a.cpp
 * time   : Thu Apr 30 21:43:50 2020
 * quest  : A - Task Scheduling Problem
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(a, max(b, c)) - min(a, min(b, c)) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    cout << (S[2] == S[3] && S[4] == S[5] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	Int sum = 0;
	Int minB = 1e18;
	for (int i = 0; i < N; ++i) {
		Int a, b;
		cin >> a >> b;
		sum += a;
		if (a > b) { minB = min(minB, b); }
	}
	cout << max((Int)0, sum - minB) << endl;

	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] H = new int[N];
		boolean[] h = new boolean[N];
		int[] A = new int[M];
		int[] B = new int[M];
		for(int i=0; i<N; i++) {
			h[i] = true;
			H[i] = sc.nextInt();
		}
		for(int j=0; j<M; j++) {
			A[j] = sc.nextInt();
			B[j] = sc.nextInt();
			if(H[A[j]-1]<=H[B[j]-1]) {
				h[A[j]-1] = false;
			}
			if(H[A[j]-1]>=H[B[j]-1]) {
				h[B[j]-1] = false;
			}
		}
		sc.close();
		int s=0;
		for(int i=0; i<N; i++) {
			if(h[i])
				s++;
		}
		System.out.println(s);
	}

}


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

int main() {
	ll N, x;
	cin >> N >> x;

	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	int res = 0;
	for (int i = 0; i < N; i++) {
		if (i == N - 1) {
			if (x == a[i]) res++;
		} else if (x >= a[i]) {
			res++;
			x -= a[i];
		} else if (x < a[i]) {
			break;
		}
	}

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


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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	int n, a = 0, b = 10000;
	cin >> n;
	while (cin >> n) {
		a = max(a, n);
		b = min(b, n);
	}
	cout << a-b;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(a);
        int ai = a[n-1];
        int aj = a[0];
        for(int i = 0; i < n; i++){
            if(a[i] <= ai/2){
                aj = Math.max(aj, a[i]);
            } else {
                if(ai - a[i] > aj)
                    aj = a[i];
            }
        }

        System.out.println(ai + " " + aj);
    }
}

Measured memory_bytes: 50420
n,k=map(int,input().split())
a=list(map(int,input().split()))
t=[0 for i in range(n+1)]
town=1
for i in range(n+1):
    t[town]+=1
    if t[town]==2:
        break
    town=a[town-1]
r=0
sy=0
town=1
while t[town]!=2:
    r+=1
    town=a[town-1]
for i in range(n):
    sy+=1
    town=a[town-1]
    if t[town]==2:
        break
town=1
if r>=k:
    for i in range(k):
        town=a[town-1]
    print(town)
else:
    for i in range(r):
        town=a[town-1]
    k=k-r
    m=k//sy
    k=k-m*sy
    for k in range(k):
        town=a[town-1]
    print(town)
        
    



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

int main() {
	string n;
	cin >> n;
	string ans = "";
	for (int i = 0; i < 3; i++) {
		if (n.at(i) == '9')
			ans += "1";
		else if (n.at(i) == '1')
			ans += "9";
		else
			ans += n.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest029-A
#  https://agc029.contest.atcoder.jp/tasks/agc029_a

def  irr_operation(givenString):

	allLength = len(givenString)
	allRange = range(0,allLength)
	bCounter =0
	bPosition = []
	for i in allRange:
		if givenString[i] == 'B':
			bPosition.append(i)
			bCounter=bCounter+1

	collectPosition =[]
	bLength = len(bPosition)
	bRange = range(allLength-bLength,allLength)
	for i in bRange:
		collectPosition.append(i)

	bLengthRange = range(0,bLength)
	diffPosition = 0
	for i in bLengthRange:
		diffPosition = diffPosition+(collectPosition[i]-bPosition[i])

	answer = diffPosition
	return answer


if __name__ == '__main__':
	bwstring = input()
	solution=irr_operation(bwstring)
	print(solution)

Measured memory_bytes: 19304
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<int, ll> mp;
  vector<int> a(n);
  rep(i, n){
    int in;
    cin >> in;
    a.at(i) = in;
    mp[(i+1)+in]++;
  }
  ll ans = 0;
  rep(i, n){
    int l = (i+1) - a.at(i);
    ans += mp[l];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 26760
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# def sub(kouho, target):
#     l = len(kouho)
#     best = None
#     for b in range(1<<l):
#         v = 0
#         for i in range(l.bit_length()):
#             if b>>i&1:
#                 v += 1<<i
#         if 
                

n = int(input())
a = list(map(int, input().split()))

val = 0
for num in a[2:]:
    val ^= num
k = a[0] + a[1]
if (k-val)%2!=0 or k<val:
    ans = -1
else:
    tmp = (k-val)//2
    if tmp<0 or 2*tmp>k:
        ans = -1
    else:
        v1 = tmp
        v2 = tmp
        kouho = []
        ans = None
#         if tmp>a[0]:
#             ans = -1
        diff = k - 2*tmp
        for i in range(diff.bit_length()):
            if (diff&1<<i) & tmp:
                ans = -1
                break
            elif diff&1<<i:
                kouho.append(1<<i)
        s = sum(kouho)
        if ans is None:
            for num in kouho[::-1]:
                s -= num
                if v2+s<a[1]:
                    v2 += num
                elif v1+num<=a[0]:
                    v1 += num
                else:
                    v2 += num
            if v1==0 or v1>a[0]:
                ans = -1
            else:
                ans = a[0]-v1
        else:
            ans = -1
        
print(ans)

Measured memory_bytes: 9292
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>
#define rep(i,n) for((i)=0;(i)<(n);i++)

using namespace std;

int v[3],now;
string s;

int fomula(){
  now++;
  if(s[now-1]=='('){
    int res=fomula();
    now++;
    if(s[now-1]=='+')res=max(res,fomula());
    if(s[now-1]=='*')res=min(res,fomula());
    now++;
    return res;
  }
  if(isdigit(s[now-1]))return s[now-1]-'0';
  if(isupper(s[now-1]))return v[s[now-1]-'P'];
  if(s[now-1]=='-')return 2-fomula();
}

int main(void){

  while(cin >> s,s!="."){
    int cnt=0;
    rep(v[0],3)rep(v[1],3)rep(v[2],3){
      now=0;
      cnt+=2==fomula();
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxM = 31;
const int maxV = 90010;

 
const int maxN = 1e6+8;
const ll INF = 1000000000000000010LL;
const int MOD = 1e9+7;
ll p[maxN];
ll h[maxN];
int n,m;
int T;
char s[maxN];
char t[maxN];
int u[maxN];


int main() {


	scanf("%d",&n);
	int ans = n*n*n;
	cout<<ans<<endl; 
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    string s;
    cin >> s;
    int n = s.length();
    for(int i = 0; i < n; ++i){
        if(s[i] == '7'){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

ll arr[100000];
ll tree[100000],n;

void update(ll idx,ll val,ll n)
{
    while(idx<=n){
        tree[idx]+=val;
        idx+=(idx & -idx);
    }
}

int read(ll idx)
{
    ll sum=0;
    while(idx>0){
        sum+=tree[idx];
        idx-=(idx & -idx);
    }
    return sum;
}

int main()
{
    ll n,m,x=1;
    cin>>n>>m;
    if(abs(n-m)>=2)cout<<0;
    else{
        for(int i=n;i>=1;i--){
            x*=i;
            x%=(1000000007);
        }
        for(int i=m;i>=1;i--){
            x*=i;
            x%=(1000000007);
        }
        if(n!=m)cout<<x;
        else {
            x*=2;
            x%=(1000000007);
            cout<<x;
        }
    }

    return 0;
}


Measured memory_bytes: 256
from itertools import combinations

N, M = map(int, input().split())
nlist = [] 
mlist = []

for i in range(N):
  nlist.append(i)
  
for j in range(M):
  mlist.append(j)

if N == 1 and M == 1:
  print(0)
  exit()
  
if N == 1:
  print(len(list(combinations(mlist,2))))
  exit()
  
if M == 1:
  print(len(list(combinations(nlist,2))))
  exit()
  
print(len(list(combinations(nlist,2))) + len(list(combinations(mlist,2))))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pii;
///-------------------------

/// problem's variable---------------



///--------------------------

int main()
{
    Phuong_;
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    ll s=0;
    for(int i=0; i<n; ++i)
    {
        cin >> a[i];
        s+=a[i];
    }
    sort(a.begin(), a.end(), greater<ll>());
    for(int i=0; i<min(k,n); ++i) s-=a[i];
    cout << s;
    return 0;
}



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

int main(){
  int h, w;
  while(cin>>h>>w, h){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)) cout<<"#";
	else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
const int N=110;
const int MOD=1e9+7;
int n,dp[N][5][5][5];

int main()
{
	//1->A  2->C  3->G  4->T
	for (int i=1;i<=4;i++)
		for (int j=1;j<=4;j++)
			for (int k=1;k<=4;k++)
				dp[3][i][j][k]=1;
	dp[3][1][3][2]=0;
	dp[3][3][1][2]=0;
	dp[3][1][2][3]=0;
	
	cin>>n;
	//用刷表法更自然,用(i-2,i-1,i)推导出(i-1,i,i+1) 
	for (int i=3;i<n;i++)
		for (int j=1;j<=4;j++)	//i-2
			for (int k=1;k<=4;k++)	//i-1
				for (int l=1;l<=4;l++) {	//i
					
					if (dp[i][j][k][l]==0) continue;
					
					for (int m=1;m<=4;m++) {	//i+1
						if (k==1 && l==3 && m==2) continue;	//*AGC
						if (k==3 && l==1 && m==2) continue;	//*GAC
						if (k==1 && l==2 && m==3) continue; //*ACG
						if (j==1 && l==3 && m==2) continue; //A*GC
						if (j==1 && k==3 && m==2) continue; //AG*C
						
						dp[i+1][k][l][m]=(dp[i+1][k][l][m]+dp[i][j][k][l])%MOD;
					}
				}
	
	int ans=0;
	for (int i=1;i<=4;i++)
		for (int j=1;j<=4;j++)
			for (int k=1;k<=4;k++)
				ans=(ans+dp[n][i][j][k])%MOD;
	cout<<ans<<endl;						
	return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(raw_input())
    S = raw_input() # str
    count = 0
    for i in range(1, N): # count for leader is the 1st person case
        if S[i] == 'E':
            count += 1
    min_need_change = count
    for i in range(1,N): # count for leader is the 2nd, ... (N + 1)th person cases
        if S[i] == 'E':
            count -= 1
        if S[i - 1] == 'W':
            count += 1
        if count < min_need_change:
            min_need_change = count
    print str(min_need_change)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 12480
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    vl base_a(n);
    rep(i, n) {
        cin >> base_a[i];
    }

    if(k == 1) {
        out(0);
        re0;
    }
    
    ll ans = INF;
    rep(b, 1<<n) {
        if(b & 1) {
            continue;
        }
        vl a(n);
        rep(i, n) {
            a[i] = base_a[i];
        }
        ll now = 0;
        ll u = a[0] + 1;  // これまでの最高の高さ + 1
        rep(i, n) {
            if(b & 1<<i) {
                if(u > a[i]) {
                    now += u - a[i];
                    a[i] = u;
                    u++;
                }
                else {
                    u = a[i] + 1;
                }
            }
        }
        ll cnt = 1;
        ll t = a[0];  // これまでの最高の高さ
        exrep(i, 1, n-1) {
            if(t < a[i]) {
                cnt++;
                t = a[i];
            }
        }
        if(cnt >= k) {
            chmin(ans, now);
        }
    }

    out(ans);
    re0;
}

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

using namespace std;

int main()
{
       
       
          unsigned long long int n,sum=0;
          cin>>n;
          sum+=(n/500)*1000;
          
          
          n=n-(n/500)*500;
          sum+=(n/5)*5;
          cout<<sum<<endl;
           

    
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N);
    for (int i=0; i<N; ++i) {
        cin >> p[i];
        p[i] = (1.0+p[i])/2.0;
    }

    double sum = 0;
    for (int i=0; i<K; ++i) {
        sum += p[i];
    }
    double res = sum;
    for (int i=K; i<N; ++i) {
        sum += p[i];
        sum -= p[i-K];
        res = max(res, sum);
    }
    printf("%.10f\n", res);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;
typedef complex<double> C;
#define EPS (1e-8)
double cross(C a, C b) {
  return a.real() * b.imag() - a.imag() * b.real();
}
const string mes[2] = {"YES", "NO"};
double xa, ya, xb, yb, xc, yc, xd, yd;

void solve() {
  C a(xa, ya), b(xb, yb), c(xc, yc), d(xd, yd);
  // ABC
  // BCD
  // CDA
  // DAB
  double scross = 
    cross(a-b,b-c) * cross(b-c,c-d) * cross(c-d,d-a) * cross(d-a,a-b);
  int res = (scross > EPS) ? 0 : 1 ;
  cout<<mes[res]<<endl;
}

int main (int argc, char const* argv[]) {
  char c;
  while (cin>>xa>>c>>ya>>c>>xb>>c>>yb>>c>>xc>>c>>yc>>c>>xd>>c>>yd) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007
#define MAXN 300002
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
ll arr[300002],dp[MAXN];
int main() {
       ios::sync_with_stdio(false);
       cin.tie(0);
       cout.tie(0);
        ll n;string s;
        cin>>n;
        ll i;
        ll sum=1;

        for(i=1;i<=n;i++)
          {
            ll x;
            cin>>x;
            arr[i]=x;
            if(i!=1 and arr[i]==arr[i-1])
              continue;
            ll ans=(sum+dp[x])%mod;
            dp[x]=ans;
            sum=ans;
          }
          cout<<sum;
       return 0;
     
}

Measured memory_bytes: 3840