akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
struct node
{
    char s[15];
    int p;
    int t;
} a[105],tmp;
int main()
{
    int n,i,j;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%s%d",a[i].s,&a[i].p);
        a[i].t=i;
    }
    for(i=1; i<=n; i++)
    {
        for(j=i+1; j<=n; j++)
        {
            if(strcmp(a[i].s,a[j].s)>0)
            {
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
            else if(strcmp(a[i].s,a[j].s)==0)
            {
                if(a[i].p<a[j].p)
                {
                    tmp=a[i];
                    a[i]=a[j];
                    a[j]=tmp;
                }
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        printf("%d\n",a[i].t);
    }
}


Measured memory_bytes: 128
def calc(S,T):
    ans = 0
    for i in range(N):
        count = 0
        for j in range(i,N):
            flag = False
            for k in range(M):
                if S[j] == T[k]:
                    flag = True
            if flag:
                count = count + 1
                ans = max(count,ans)
            else:
                break
    print(ans)

if __name__ == "__main__":
    S = input()
    N = len(S)
    Target = "ATGC"
    M = len(Target)
    calc(S,Target)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    string S, T;
    cin >> S >> T;

    reverse(all(T));
    char l = T[0];
    S.push_back(l);
    reverse(all(T));
    if(S == T) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

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

        for (int i = 0; i < count; i++) {
            numArr[i] = sc.nextInt();
        }

        Map<Integer, Integer> candidate = new HashMap<>();// 取りうる値と個数のMap
        for (int i = 0; i < count; i++) {
            int tmpKey = numArr[i];
            if (candidate.containsKey(tmpKey)) {
                candidate.put(tmpKey, candidate.get(tmpKey) + 1);
            } else {
                candidate.put(tmpKey, 1);
            }

            // +1
            int tmpKeyPlus1 = tmpKey + 1;
            if (candidate.containsKey(tmpKeyPlus1)) {
                candidate.put(tmpKeyPlus1, candidate.get(tmpKeyPlus1) + 1);
            } else {
                candidate.put(tmpKeyPlus1, 1);
            }

            // -1
            int tmpKeyMinus1 = tmpKey - 1;
            if (candidate.containsKey(tmpKeyMinus1)) {
                candidate.put(tmpKeyMinus1, candidate.get(tmpKeyMinus1) + 1);
            } else {
                candidate.put(tmpKeyMinus1, 1);
            }
        }

        // 最大化する値を探索
        int max = 0;
        int key = 0;
        for (Map.Entry<Integer, Integer> entry: candidate.entrySet()) {
            if (entry.getValue() > max) {
                key = entry.getKey();
                max = entry.getValue();
            }
        }

        int res = 0; // 操作後をした後のkeyのカウント
        for (int i = 0; i < numArr.length; i++) {
            if (numArr[i] == key) {
                res++;
            } else if (numArr[i] == key - 1 || numArr[i] == key + 1) {
                res++;
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 59736
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<sstream>
using namespace std;
long long int a[100000000],b[100000000];
int main(void){

    int m=0;
    int d=0;
    bool flg=0;
    string str="";
    while(getline(cin,str)){
        stringstream ss(str);
        ss>>m;
        d=max(m,d);
        ss.ignore();
        if(str=="")flg=1;
        else if(!flg){
            a[m]++;
        }
        else if(flg)b[m]++;
    }
    for(int i=0;i<=d;i++){
        if(a[i]!=0&&b[i]!=0)cout<<i<<" "<<a[i]+b[i]<<endl;
    }
    return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    cout << (N-1)*(M-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

int N, a;
  cin >> N;
int d[100] = {};
int cnt = 0;  
  
  for(int i = 0;i < N;i++){
  cin >> a;
    d[a - 1]++;
  }
  
  for(int i = 0;i < 100;i++){
  if(d[i] > 0) cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  vector<tuple<string,int,int>>t(N);
  for(int i=0;i<N;i++){
    string s;
    int p;
    cin>>s>>p;
    p=100-p;
    t.at(i)=make_tuple(s,p,i);
  }
  sort(t.begin(),t.end());
  for(int i=0;i<N;i++){
    string s;
    int p,n;
    tie(s,p,n)=t.at(i);
    cout<<n+1<<endl;
  }
}

Measured memory_bytes: 256
a, op, b = input().split()
a = int(a)
b = int(b)
L = []
while op != "?":
 L.append([a, b, op])
 a, op, b = input().split()
 a = int(a)
 b = int(b)

for (a, b, op) in L:
 if op == "+":
  print(str(a + b))
 elif op == "-":
  print(str(a - b))
 elif op == "*":
  print(str(a * b))
 else:
  print(str(a // b))

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

int main() {

    char s[27];
    scanf("%s", s);
    int arr[26];

    for (int j = 0; j < 26; j++) {
        arr[j] = 0;
    }

    for (int i = 0; i < strlen(s); i++) {
        int num = s[i] - 'a';

        if (arr[num] == 0) {
            arr[num] += 1;
        } else {
            printf("no");
            return 0;
        }

    }
    printf("yes");





    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int n;
P t[50];
int id[50];

int a[50];
int b[50];
int c[50];
int ans[50];

void solve(){
  
  priority_queue< P , vector< P > , greater< P > > Q;
  for(int i=0;i<n;i++){
    Q.push(P(0,i));
  }

  while(!Q.empty()){
    P p=Q.top();Q.pop();
    int x=p.first,y=p.second;
    //   cout<<x<<' '<<y<<' '<<a[y]<<' '<<b[y]<<' '<<c[y]<<endl;

    if(c[y]==t[y].second){
      c[y]++;
      continue;
    }
    
    int next=x+t[y].first;
    for(int i=0;i<n;i++){
      if(c[i]>t[i].second)continue;
      if(i==y)continue;
      if(b[i]!=b[y]){
        next=max(next,a[i]);
      }
    }
    a[y]=next;
    b[y]=1-b[y];
    if(b[y]==0)c[y]++;
    
    Q.push(P(a[y],y));
  }
  
  for(int i=0;i<n;i++){
    ans[id[i]]=a[i];
  }
}

void init(){
  for(int i=0;i<50;i++){
    a[i]=0;
    b[i]=0;
    c[i]=0;
  }
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      cin>>t[i].first>>t[i].second;
      id[i]=i;
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
        if(t[j]>t[j+1]){
          swap(t[j],t[j+1]);
          swap(id[j],id[j+1]);
        }
      }
    }
    solve();
    int ANS=0;
    for(int i=0;i<n;i++)
      ANS=max(ANS,ans[i]);
    cout<<ANS<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;


#define rep(a,n) for(int a = 0;a < n;a++)

template<typename T> class SegmentTree {
private:
	typedef function<T(T, T)> F;
	int n;
	T d0;
	vector<T> vertex;
	F f;
public:
	SegmentTree(int _n, F f, T d) :d0(d), f(f) {
		init(_n);
	}
	void init(int _n) {
		n = 1;
		while (n < _n) n *= 2;
		vertex.resize(2 * n - 1, d0);
	}
	void update(int i, T x) {
		int k = i + n - 1;
		vertex[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			vertex[k] = f(vertex[2 * k + 1], vertex[2 * k + 2]);
		}
		return;
	}
	T query(int l, int r) {
		T vl = d0, vr = d0;
		l += n - 1;
		r += n - 1;
		for (; l <= r; l /= 2, r = r / 2 - 1) {
			if (l % 2 == 0) vl = f(vl, vertex[l]);
			if (r & 1) vr = f(vr, vertex[r]);
		}
		return f(vl, vr);
	}
};

int main(void)
{
	ll n, m;
	cin >> n >> m;

	SegmentTree<ll> t(n+1, [&](ll a, ll b) {return min(a, b); }, (ll)1e15);
	t.update(1, 0);
	vector<tuple<ll, ll, ll>> vs;
	rep(i, m) {
		ll l, r, c;
		cin >> l >> r >> c;
		vs.emplace_back(l, r, c);
	}
	sort(vs.begin(), vs.end());
	rep(i, m) {
		ll l, r, c;
		tie(l, r, c) = vs[i];
		auto prev = t.query(l, n + 1);
		auto next = t.query(r, n + 1);
		t.update(r, min(prev + c, next));
	}
	auto dist = t.query(n, n + 1);
	if (dist >= (ll)1e15) {
		cout << -1 << endl;
	}
	else {
		cout << dist << endl;
	}
	return 0;
}	

Measured memory_bytes: 6644
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

int main(void) {
	long long N, K;
	cin >> N >> K;
	long long ans = 0;
	long long n = N / K;
	ans += n * n * n;
	if (K % 2 == 0) {
		n = (N + K / 2) / K;
		ans += n * n * n;
	}
	cout << ans << endl;
	system("pause");
	return 0;
}


Measured memory_bytes: 504
import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int S, W;
        S = Integer.parseInt (arr[0]);
        W = Integer.parseInt (arr[1]);
        System.out.println (S <= W ? "unsafe" : "safe");
        return;
    }
}

Measured memory_bytes: 32556
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

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

	vector<ll> D(N);
	rep(i, N) cin >> D[i];

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

	cout << D[N/2] - D[N/2 - 1] << endl;
}


Measured memory_bytes: 4064
//2020-04-11 23:20:32
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n,k;cin>>n>>k;
    ll a[n];
    rep(i,0,n){
        cin>>a[i];
        if(i!=0)
            a[i]+=a[i-1];
    }

    rep(i,0,n)a[i]-=((i+1)*k);
    set<pair<ll,ll>> ss;
    rep(i,0,n)ss.insert(mp(a[i],i));
    ss.insert(mp(-1,INF));
    map<pair<ll,ll>,int> m;
    int cnt=0;
    for(auto x: ss)m[x]=cnt++;
    rep(i,0,n)a[i]=m[mp(a[i],i)];
    ll ans=0;
    indexed_set s;s.insert(m[mp(-1,INF)]);
    rep(i,0,n){
        s.insert(a[i]);
        ll rank=s.order_of_key(a[i]);
        ans+=rank;
    }
    cout<<ans;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int i = 0;
	while(true) {
		ll tmp = x * pow(2, i);
		if(tmp > y) {
			cout << i << endl;
			return 0;
		}
		i++;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll mod = 998244353;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

void solve(long long N, long long S, std::vector<long long> A){
  vector<modint> dp(S+1);
  modint ans;
  rep(i,N){
    dp[0]+=1;
    for(ll j=S;j>=0;j--){
      if(j+A[i]<=S)dp[j+A[i]]+=dp[j];
    }
    ans+=dp[S];
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long S;
    scanf("%lld",&S);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, S, std::move(A));
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    s = S()
    t = S()
    sl = len(s)
    tl = len(t)
    c = 0
    sa = []
    for i in range(sl):
        c += 1 if s[i] == 'A' else 2
        sa.append(c)
    c = 0
    ta = []
    for i in range(tl):
        c += 1 if t[i] == 'A' else 2
        ta.append(c)

    r = []
    q = I()
    for _ in range(q):
        a,b,c,d = LI()
        st = sa[b-1]
        if a > 1:
            st -= sa[a-2]
        tt = ta[d-1]
        if c > 1:
            tt -= ta[c-2]
        if st % 3 == tt % 3:
            r.append('YES')
        else:
            r.append('NO')


    return '\n'.join(r)



print(main())


Measured memory_bytes: 14660
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

int main(){
  ll N,A,B; cin>>N>>A>>B;
  if(abs(A-B)%2) cout<<"Borys"<<endl;
  else cout<<"Alice"<<endl;
}

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

char ch[2001020];
int Ans;

int main()
{
	scanf ("%s", ch);
	int L = strlen(ch);
	for(int i = 0; i < L; i++) {
		Ans += ch[i] - '0';
		Ans %= 9;
	}
	if(Ans) puts("No");
	else puts("Yes");
	return 0;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    string s,t;
    cin >> s >> t;

    vector<vector<tuple<i64,i64,i64>>> memo(s.size()+1,vector<tuple<i64,i64,i64>>(vector<tuple<i64,i64,i64>>(t.size()+1,make_tuple(0,-1,-1))));
    vector<vector<bool>> done(s.size()+1,vector<bool>(t.size()+1));
    function<tuple<i64,i64,i64>(i64,i64)> rec=[&](i64 i,i64 j){
        if(done[i][j]) return memo[i][j];
        done[i][j]=true;
        if(i==s.size() or j==t.size()){
            return memo[i][j]=make_tuple<i64,i64,i64>(0,-1,-1);
        }
        i64 l=0;
        if(s[i]==t[j]){
            memo[i][j]=make_tuple(1,-1,-1);
            i64 nl,ni,nj;
            tie(nl,ni,nj)=rec(i+1,j+1);
            if(chmax(get<0>(memo[i][j]),nl+1)){
                get<1>(memo[i][j])=i+1;
                get<2>(memo[i][j])=j+1;
            }
        }else{
            if(chmax(get<0>(memo[i][j]),get<0>(rec(i+1,j)))){
                get<1>(memo[i][j])=i+1;
                get<2>(memo[i][j])=j;
            }
            if(chmax(get<0>(memo[i][j]),get<0>(rec(i,j+1)))){
                get<1>(memo[i][j])=i;
                get<2>(memo[i][j])=j+1;
            }
        }
        return memo[i][j];
    };

    string ans;
    if(s[0]==t[0]) ans+=s[0];
    i64 l,i,j;
    tie(l,i,j)=rec(0,0);
    while(i>=0 and j>=0){
        if(s[i]==t[j]) ans+=s[i];
        tie(l,i,j)=rec(i,j);
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 213632
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a,b,k;
	cin >> a >> b >> k;
	for(int i = 0;i < k;i++){
		if(i % 2){
			a += b / 2;
			b /= 2;
		}else{
			b += a / 2;
			a /= 2;
		}
	}
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
a, b, c, d = [int(i) for i in input()]
ops = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]

for op in ops:
    s = a
    for i, n in enumerate([b, c, d]):
        op = list(op)
        if op[i] == "+":
            s += n
        else:
            s -= n
    if s == 7:
        print(str(a) + op[0] + str(b) + op[1] + str(c) + op[2] + str(d) + "=7")
        break

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

using namespace std;

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int lx = 0, rx = w;
    int dy = 0, uy = h;
    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            lx = max(lx, x);
        } else if (a == 2) {
            rx = min(rx, x);
        } else if (a == 3) {
            dy = max(dy, y);
        } else {
            uy = min(uy, y);
        }
    }
    if (lx >= rx || dy >= uy) {
        cout << 0;
    } else {
        cout << (rx - lx) * (uy - dy);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int n, val[maxn];
bool used[maxn];
long long ans;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 0;i < n;++i)cin >> val[i];
	--n;
	for(int c = 1;c < n;++c){
		long long sum = 0;
		for(int k = 1;(k + 1) * c < n and !used[c * k] and !used[n - c * k] and (((c * k) << 1) != n);++k){
			ans = max(sum += val[c * k] + val[n - c * k], ans);
			used[c * k] = used[n - c * k] = true;
		}
		for(int k = 1;k * c < n and (used[c * k] || used[n - c * k]);++k){
			used[c * k] = used[n - c * k] = false;
		}
		memset(used, 0, sizeof(used));
	}
	cout << ans << '\n';
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long min = Long.MAX_VALUE;
		long N = sc.nextLong();
		for (int i = 0; i < 5; i++) {
			long tmp = sc.nextLong();
			if (tmp < min) {
				min = tmp;
			}
		}
		if (N % min == 0) {
			System.out.print(N / min + 4);
		} else {
			System.out.print(N / min + 5);
		}
	}
}

Measured memory_bytes: 21844
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print(A[K - 1])

Measured memory_bytes: 3060
import java.io.*;
public class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
}

Measured memory_bytes: 22048
n = gets.to_i
h = gets.split.map(&:to_i)
if n == 1
  puts "Yes"
  exit
end
(1..n-1).each do |i|
  if h[i-1]-1 > h[i]
    puts "No"
    exit
  elsif  h[i-1]-1 == h[i]
    h[i] += 1
  end
end
puts "Yes"

Measured memory_bytes: 8580
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n=s.length();
    s+="ZZZZ";
    ll num=0;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(s[i]=='A'){
            num++;
        }else if(s[i]=='B'){
            if(s[i+1]=='C'){
                ans+=num;
                i++;
            }else{
                num=0;
            }
        }else{
            num=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
#include<string>
using namespace std;
#define ll long long
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(void){
    ll a,b,c,d;
    cin >>a>>b>>c>>d;
    ll sum = b-a+1;
    ll e = c*d/euclidean_gcd(c,d);
    sum -= (b/c-(a-1)/c);
    sum -= (b/d-(a-1)/d);
    sum += (b/(e)-(a-1)/(e));
    cout << sum << endl;
}

Measured memory_bytes: 256
# C - 4-adjacent
n = int(input())
count2 = count4 = 0
for a in [int(x)%4 for x in input().split()]:
    if a==0: count4 += 1
    elif a==2: count2 += 1
print("Yes" if n//2 <= count4 + count2//2 else "No")

Measured memory_bytes: 11100
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
          ll n,i,j,k,c=0;
          string s;
          cin>>s;
          for(i=0;i<s.size();i++)
          {
                    c+=s[i]-48;
          }
          //cout<<c;
          if(c%9==0)
          cout<<"Yes";
          else cout<<"No";

}


Measured memory_bytes: 3720
#include <stdio.h>

int main(void)
{
    long long m,n,x=1,y=1,z=1,w;
    long long i;
    w=1000000007;
    
    scanf("%lld %lld",&m,&n);
    
    
    if(((m-n)==1||(n-m)==1)||m==n)
    {
        if(m==n)
        {
            for(i=0;i<m;i++)
            {
                x=(x*(m-i))%w;
            }
            z=(2*x*x)%w;
        }
        else
        {
            for(i=0;i<m;i++)
            {
                x=(x*(m-i)%w);
            }
            for(i=0;i<n;i++)
            {
                y=(y*(n-i)%w);
            }
            z=(x*y)%w;
        }
        
        
        printf("%lld\n",z);
    }
    else
    {
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 128
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

////////////////いろいろあるよ//////////////////////////////////
int main(){
	ll N,D;
 	cin >> N >> D;
  	ll count = 0;
  	ll DD = D * D;
  	REP(i,N){
      	ll x,y;
    	cin >> x >> y;
      	
      	if(x * x + y * y <= DD)count++;
      
    }
  
  	cout << count << endl;
  
  	
}


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

int main(void){
    vector<int> A[1010];
    int n, q;
    cin >> n >> q;
    for(int i=0; i<q; i++){
        int num;
        cin >> num;
        if(num==0){
            int t, x;
            cin >> t >> x;
            A[t].push_back(x);
        }
        else if(num==1){
            int t;
            cin >> t;
            for(int i=0; i<A[t].size(); i++){
                if(i!=0) cout << " " ;
                cout << A[t].at(i);
            }
            cout << "\n";
        }
        else {
            int t;
            cin >> t;
            A[t].clear();
        }
    }
    
    return 0;
}



Measured memory_bytes: 5892
N = int(input())
S = list(input())

ans = []
if len(set(S)) == 1:
    ans.append(1)
elif len(set(S)) == len(S):
    ans.append(0)
else:
    pass
    
for i in range(N):
    if i == 0:
        pass
    elif S[i] == S[i-1]:
        pass
    else:
        S_f = S[:i+1]
        S_b = S[i+1:]
        F = set(S_b)
        B = set(S_f)
        ans.append(len(F&B))
        
print(max(ans))



Measured memory_bytes: 3064
import java.util.Scanner

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val a = Array<Int>(n, { 0 })
    val b = Array<Int>(n, { 0 })
    val c = Array<Int>(n, { 0 })
    for (i in (0..(n - 1))) {
        a[i] = scanner.nextInt()
    }
    var s = 0L
    var t = 0L
    for (i in (0..(n - 1))) {
        b[i] = scanner.nextInt()
        c[i] = b[i] - a[i]
        s += c[i]
        if (c[i] > 0) {
            t += (c[i] + 1) / 2
        }
    }

    if (s < t) {
        println("No")
    } else {
        println("Yes")
    }
}

Measured memory_bytes: 43048
a=int(input())
if a%7==1:
    print("fri")
if a%7==2:
    print("sat")
if a%7==3:
    print("sun")
if a%7==4:
    print("mon")
if a%7==5:
    print("tue")
if a%7==6:
    print("wed")
if a%7==0:
    print("thu")


Measured memory_bytes: 5592
#include <stdio.h>
int main(void){
  int n;
  scanf("%d", &n);
  switch(n){
  case 22:
    printf("Christmas Eve Eve Eve\n");
    break;
  case 23:
    printf("Christmas Eve Eve\n");
    break;
  case 24:
    printf("Christmas Eve\n");
    break;
  case 25:
    printf("Christmas\n");
    break;
  default:
    break;
  }
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; string S; cin >> N >> S;
	int cur = 0;
	int mi = 0;
	for (char c : S) {
		if (c == '(') {
			cur ++;
		} else {
			cur --;
		}
		mi = min(mi, cur);
	}
	string ans = string(-mi, '(') + S + string(cur-mi, ')');
	cout << ans << '\n';

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a[N], t = 0;
  for (int i=0; i<N; i++) {
    cin >> a[i];
    t = t^a[i];
  }
  for (int i=0; i<N; i++) {
    cout << (t^(a[i])) << " ";
  }
  cout << endl;
  return 0;
}

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

using namespace std;

#define INF 210000000

static long long gcd(long long a, long long b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

static long long lcm(long long a, long long b) { return a * b / gcd(a, b); }

int main() {
  int n;
  cin >> n;
  vector<int> a;
  vector<int> b;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    b.push_back(tmp);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (b[i] == a[n - 1]) {
      cout << a[n - 2] << endl;
    } else {
      cout << a[n - 1] << endl;
    }
  }
}


Measured memory_bytes: 3436
def main():
    n, k = map(int, input().split())
    a = [int(i) - 1 for i in input().split()]
    ans = solve(n, k, a)
    print(ans)


def solve(n, k, a):
    #print(f'{n = } {k = }')
    #print(f'{a = }')
    mk = 60
    dp = [[i for i in a] for _ in range(mk)]
    for i in range(1, mk):
        for j in range(n):
            dp[i][j] = dp[i - 1][dp[i - 1][j]]

    #print(*dp, sep = '\n')

    pos = 0
    for b in range(mk):
        if k >> b & 1:
            pos = dp[b][pos]
    return pos + 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 218176
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	nums := map[int]int{}

	for i := 0; i < n; i++ {
		val := nextInt()

		if _, ok := nums[val]; ok {
			nums[val]++
		} else {
			nums[val] = 1
		}

		if _, ok := nums[val+1]; ok {
			nums[val+1]++
		} else {
			nums[val+1] = 1
		}

		if _, ok := nums[val-1]; ok {
			nums[val-1]++
		} else {
			nums[val-1] = 1
		}
	}

	max := 0
	for _, v := range nums {
		if max < v {
			max = v
		}
	}
	fmt.Println(max)
}

Measured memory_bytes: 6784
#include<iostream>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <numeric>
#include <vector>


using namespace std;

vector<int> v;
vector<int> v2;
int main(){
int N;
int a;
long long int sum=0;

scanf("%d",&N);
for(int i=0;i<N;i++){
	scanf("%d",&a);
	v.push_back(a);
}

for(int i=*min_element(v.begin(), v.end());i<=*max_element(v.begin(), v.end());i++){
	for(int i2=0;i2<N;i2++){
		sum+=((v[i2]-i)*(v[i2]-i));
	}
		v2.push_back(sum);
		sum=0;
}


printf("%d\n",*min_element(v2.begin(), v2.end()));
return 0;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        n:usize,u:Usize1,v:Usize1,
        ab:[(Usize1,Usize1);n-1],
    }
    let mut g = vec![Vec::new(); 202020];
    for &(a, b) in ab.iter() {
        g[a].push(b);
        g[b].push(a);
    }

    let mut fromu = vec![0; 202020];
    let mut fromv = vec![0; 202020];

    let mut q = VecDeque::new();
    q.push_back((u, 0));
    while let Some(iq) = q.pop_front() {
        let mut now = iq.0;
        let mut dist = iq.1;
        fromu[now] = dist;
        for &nx in g[now].iter() {
            if fromu[nx] == 0 && nx != u {
                q.push_back((nx, dist + 1));
            }
        }
    }
    dbg!("here");
    q.clear();
    q.push_back((v, 0));
    while let Some(iq) = q.pop_front() {
        let mut now = iq.0;
        let mut dist = iq.1;
        fromv[now] = dist;
        for &nx in g[now].iter() {
            if fromv[nx] == 0 && nx != v {
                q.push_back((nx, dist + 1));
            }
        }
    }
    dbg!("heres");
    let mut ma = 0;
    for i in 0..n {
        if fromu[i] < fromv[i] {
            ma = max(ma, fromv[i] - 1);
        }
    }
    println!("{}", ma);
}


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

#define int long long

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=n-1;i;i--)v[i]-=v[i-1];
  int m,k;cin>>m>>k;
  vector<int> a(m);
  for(int &p:a){cin>>p;p--;}
  vector<int> b(n);
  for(int i=0;i<n;i++)b[i]=i;
  for(int i=0;i<m;i++)swap(b[a[i]],b[a[i]+1]);
  while(k){
    if(k&1){
      vector<int>tmp(n);
      for(int i=0;i<n;i++)tmp[i]=v[b[i]];
      for(int i=0;i<n;i++)v[i]=tmp[i];
    }
    k>>=1;
    vector<int> tmp(n);
    for(int i=0;i<n;i++)tmp[i]=b[b[i]];
    for(int i=0;i<n;i++)b[i]=tmp[i];
  }
  cout<<v[0]<<endl;
  for(int i=1;i<n;i++){
    v[i]+=v[i-1];
    cout<<v[i]<<endl;
  }
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
#define allsortg(v)sort(v.begin(),v.end(),greater<int>());
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	rep(i, 10) {
		if (pow(2, i) > N) {
			cout << pow(2,i - 1) << "\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#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>;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

ll dp[200010];

int main(){
    int N; cin >> N;
    vector<int> h(N),a(N);
    rep(i,N) cin >> h[i];
    rep(i,N) cin >> a[i];

    SegmentTree<ll> seg(200010,[](ll a, ll b){return max(a,b);},0);

    rep(i,N){
        ll p = seg.query(0,h[i]);
        if(dp[h[i]] < p+a[i]){
            dp[h[i]] = p+a[i];
            seg.update(h[i],dp[h[i]]);
        }
    }
    ll ans = 0;
    rep(i,200010){
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;

}



Measured memory_bytes: 7552
N=int(input())
import sys
import math
ANS = sys.maxsize
i_max = math.ceil(N ** 0.5)

for i in range(1, i_max + 1):
  if N % i != 0:
    continue
  j = N // i
  ANS = min(i+j-2, ANS)


print(ANS)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  
  if(s.size() <= k) cout << s << endl;
  else{
    for(int i=0;i<k;i++) cout << s[i];
    cout << "..." << endl;
  }
}
   

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

#define _SI(arr) (sizeof(arr)/sizeof(arr[0])

int main() {
	ll x, a, b;
	cin >> x >> a >> b;
	
	if (abs(x - a) < abs(x - b))
	{
		cout << "A" << endl;
	}
	else
		cout << "B" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>=2){cout<<0<<endl;return 0;}
    ll ans=1;
    if(abs(n-m)==1){
        for(ll i=2;i<=n;i++){ans*=i;ans%=1000000007ll;}
        for(ll i=2;i<=m;i++){ans*=i;ans%=1000000007ll;}
    }else{
        for(ll i=2;i<=n;i++){ans*=i;ans%=1000000007ll;}
        for(ll i=2;i<=n;i++){ans*=i;ans%=1000000007ll;}
        ans*=2;ans%=1000000007ll;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
sm = sum(a)//2
mn = 10**10
ar = a[0]
su = a[-1]
for i in range(1,len(a)-1):
    if abs(sm - ar) < mn:
        mn = abs(sm - ar)
        mn_i = i
    ar += a[i]

if len(a) > 2:
    ar = sum(a[0:mn_i])
    su = sum(a[mn_i::])
    print(abs(ar-su))
else:
    print(abs(ar-su))


Measured memory_bytes: 24688
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }

        long[] acc = new long[N + 1];
        for (int i = 0; i < N; i++) {
            acc[i + 1] = acc[i] + a[i];
        }

        Map<Long, Integer> cnts = new HashMap<>();
        for (int i = 0; i <= N; i++) {
            int cnt = cnts.containsKey(acc[i]) ? cnts.get(acc[i]) : 0;
            cnts.put(acc[i], ++cnt);
        }

        long ans = 0;
        for (Map.Entry e : cnts.entrySet()) {
            int num = (int) e.getValue();
            ans += (long) num * (num - 1) / 2;
        }

        out.println(ans);
    }
}

Measured memory_bytes: 93868
import sys
from io import StringIO
import unittest


def resolve():
    n = int(input())
    # a, b = map(int, input().split())
    x = list(map(int, input().split()))
    ans = []

    for i in range(1, 101, 1):
        ans.append(
            sum([(i - xx) ** 2 for xx in x])
        )

    print(min(ans))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 4"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16236
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 2 * (1e5 + 1);
const int INF = 1e9 + 5;
const long long MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    int x;
    cin >> x;
    cout << (x < 1200 ? "ABC" : "ARC");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
typedef long long LL;
using namespace std;
 int main(){
    int p;
    int q;
    int r;
    int tmp;
    cin >> p >> q >> r;
    tmp = p+q+r;
    if(p>=q && p>=r){
        cout << tmp-p << endl;
    }else if(q>=r && q>=p){
        cout << tmp-q << endl;
    }else{
        cout << tmp-r << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long M){
	cout << N*(N-1)/2+M*(M-1)/2 << endl;
}

int main(){	
	long long N;
	long long M;
	scanf("%lld",&N);
	scanf("%lld",&M);
	solve(N, M);
	return 0;
}



Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll INF = 1e18 + 10 ;
int main(){
    fastio 
    ll n , k ; 
    cin >> n >> k ; 
    vector<pair<ll, ll> > v(n) ; 
    set<ll> s ; 
    for(ll i = 0; i < n; i++){
        cin >> v[i].second >> v[i].first ; 
        s.insert(v[i].second) ; 
    }
    sort(v.rbegin(), v.rend()) ;
    ll types = (ll) s.size() ; 
    ll L = 1, R = min(k,types) ; 
    auto solve = [&](ll mid){
        if ( mid > k ) return 0LL ; 
        set<ll> ss ; 
        ll c = mid ; 
        ll ans = 0 ;
        vector<bool> mark(n) ; 
        for(ll i = 0; i < n && c; i++){
            if ( ss.find(v[i].second) == ss.end() ){
                ans += v[i].first ; 
                ss.insert(v[i].second) ; 
                mark[i] = true ; 
                c--;
            }
        }
        c = k - mid ; 
        for(ll i = 0; i < n; i++){
            if ( !mark[i] && c ){
                ans += v[i].first ; 
                c--;
            }
        }
        return ans + mid * mid; 
    };
    ll ans = 0 ;
    while(L <= R){
        ll mid = L + (R - L) / 2 ;
        ll a = solve(mid) ;
        ll b = solve(mid + 1) ;
        if ( mid + 1 > min(k,types) ) {
            b = solve(mid - 1) ;
        }
        ans = max(a, b);
        if ( a < b ){
            L = mid + 1;
        }
        else R = mid - 1;
    }
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 9088
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, i, x;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        x = i;
        if(x % 3 == 0){
            printf(" %d", i);
        }else{
            while(x){
                if (x % 10 == 3){
                    printf(" %d", i);
                    break;
                }
                x /= 10;
            }
        }
    }
    printf("\n");
    return 0;
}



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

int main(){
  ll sum=0;
  string s;
  cin >> s;
  s='<'+s+'>';
  vector<ll> v(s.length()+1,0);
 v[0]=-1;v[s.length()]=-1;
  r(i,s.length()-1){
    if(s[i]=='<'&&s[i+1]=='<')v[i+1]=v[i]+1;
  }
  for(int i = s.length()-1;i>0;i--){
    if(s[i]=='>'&&s[i-1]=='>')v[i]=v[i+1]+1;
  }
  r(i,s.length()-1){
    if(s[i]=='<'&&s[i+1]=='>')v[i+1]=max(v[i]+1,v[i+2]+1);
  }
  r(i,s.length()-1)sum+=v[i+1];
  cout<<sum<<endl;
}

Measured memory_bytes: 4760