akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=998244353;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x%big;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2)%big;
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

ll in(ll n){
  if(n==1)return 1;
  return exp(n,big-2);
}


int main(){
  ll n,m,k;cin >> n >> m >> k;
  vector<int> facin(n);
  ll l=1;
  facin[0]=1;
  rep2(i,1,n){
    l=(l*i)%big;
    facin[i]=in(l);
  }
  
  ll ans=0;
  rep(i,k+1){
    ans+=(((m*exp(m-1,n-i-1)%big)*l%big)*facin[i]%big)*facin[n-i-1]%big;
    ans%=big;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3956
a = int(input())
w_list = list(map(int,input().split()))
ans = abs(w_list[0] - sum(w_list[1:]))
for i in range(a):
    list_1 = w_list[:i+1]
    list_2 = w_list[i+1:]
    if abs(sum(list_2) - sum(list_1)) < ans:
        ans = abs(sum(list_2) - sum(list_1))
print(ans)

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

 
int main(){
    
    ll ans=0,n;
    cin>>n;
   
        ans=(n-1)*n/2;
        cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
typedef float fl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
int main()
{   
    fast;
    ll n,count;
    ld d;
    count=0;
    cin>>n>>d;
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)
        {
            count++;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

int main() {
	int k;
	vector <int> a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a.at(i);
	}
	cin >> k;

	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			if (a.at(j) - a.at(i) > k) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}

	cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
    mod = 10**9+7
    N = int(input())
    s1 = input()
    s2 = input()
    lis = []
    i=0
    while i<N-1:
        if s1[i]==s1[i+1]:
            lis.append(2)
            i += 2
        else:
            lis.append(1)
            i += 1
    if i==N-1:
        lis.append(1)
    if lis[0]==1:
        ans = 3
    else:
        ans = 6
    for i in range(len(lis)-1):
        if lis[i]==1:
            ans *= 2
            ans %= mod
        if lis[i]==2 and lis[i+1]==2:
            ans *=3
            ans %= mod
    return ans
print(solve())

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H, W, A, B;
  cin >> H >> W >> A >> B;
  vvl ANS = VVL(H, W, 0);
  REP(i, H) {
    REP(j, W) {
      if (i < B && j < A)
        ANS[i][j] = 1;
      if (i >= B && j >= A)
        ANS[i][j] = 1;
    }
  }
  REP(i, H) {
    REP(j, W) cout << ANS[i][j];
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 9088
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    As.sort()

    setA = set(As)
    setDel = set()

    cands = []

    for a in As:
        if a in setDel:
            continue

        i = 1
        while a*i <= As[-1]:
            if a*i in setA:
                setDel.add(a*i)
            i += 1

        cands.append(a)

    # 重複する数字を調べる
    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    ans = 0
    for x in cands:
        if dic[x] > 1:
            continue
        ans += 1

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 61752
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int n,d,i,j,k,cnt=0;
    scanf("%d%d",&n,&d);
    int a[n][d];
    for(i=0;i<n;i++){
        for(j=0;j<d;j++) scanf("%d",&a[i][j]);
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            int sum=0;
            for(k=0;k<d;k++){
                int tmp = abs(a[i][k]-a[j][k]);
                sum+=tmp*tmp;
            }
            for(k=0;k<=sum;k++){
                if(k*k==sum) cnt++;
            }
            
        }
    }
    printf("%d",cnt);
    return 0;
}

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

#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>

const ll mod=1e9+7;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n;
    sfi(n)

    int cnt=0;

    ll arr[n];
    f(i,0,n)
    	sfl(arr[i])

    sort(arr,arr+n);

    ll ans=arr[n-1];

    int var=n-2,temp=0;

    while(cnt<n-2)
    {
    	ans+=arr[var];
    	cnt++;
    	temp++;

    	if(temp==2)
    	{
    		temp=0;
    		var--;
    	}
    }

    pfln(ans)
    
    return 0;
}

Measured memory_bytes: 5396
#include <iostream>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>

unsigned long int GCD(unsigned long int m, unsigned long int n){
    unsigned long int r;
    while((r=m%n) != 0){
        m = n;
        n = r;
    }
    return n;
}
unsigned long int LCM(unsigned long int m, unsigned long int n){
    return (m*n)/GCD(m,n);
}

int main(int argc, char *argv[]){
    unsigned long int A, B, C, D;
    std::cin >> A >> B >> C >> D;
    unsigned long int lcm = LCM(C,D);
    unsigned long int MC = B/C - A/C + (A%C==0 ? 1 : 0);
    unsigned long int MD = B/D - A/D + (A%D==0 ? 1 : 0);
    unsigned long int MCD = B/lcm - A/lcm + (A%lcm==0 ? 1 : 0);
    std::cout << B-A+1 - MC - MD + MCD << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	while(cin >> n, n) {
		n = 1000 - n;
		int r = 0;
		r += n / 500; n %= 500;
		r += n / 100; n %= 100;
		r += n / 50; n %= 50;
		r += n / 10; n %= 10;
		r += n / 5; n %= 5;
		r += n;
		cout << r << endl;
	}
	return 0;
}

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

using namespace std;

int numDigits(long long num) {
  if (num == 0) {
    return 1;
  }
  int r = 0;
  do {
    r++;
    num /= 10;
  } while (num != 0);
  return r;
}

int helper(long long n) {
  int r = numDigits(n);
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      r = min(r, numDigits(n / i));
    }
  }
  return r;
}

int main() {
  long long n;
  cin >> n;
  cout << helper(n) << endl;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    
    vector<int> l(N);
    
    for(int i=0;i<N;i++){
        cin >> l[i];
    }
    
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    
    int ans = 0;
    
    for(int i=0;i<K;i++){
        ans += l[i];
    }
    
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/

#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second

#define what_is(x)     cerr << #x << " is " << x << endl;

///*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout << endl ;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
int ini()
{
    int x;
    scanf("%d",&x);
    return x;
}
long long inl()
{
    long long x;
    scanf("%lld",&x);
    return x;
}

const int N = (int) 3009;
const int inf = (int) 1e9 + 7;
const double pi=2* acos(0.0);
int dp[N][N];
bool vis[N][N];
string s,t;

int lcs(int i,int j)
{
    if(s[i]=='\0' or t[j]=='\0')
    {
        return 0;
    }
    if(vis[i][j])
        return dp[i][j];

    int res=0;
    if(s[i]==t[j])
    {
        res=lcs(i+1,j+1)+1;
    }
    else
    {
        int p1=lcs(i+1,j);
        int p2=lcs(i,j+1);

        res=max(p1,p2);
    }
    vis[i][j]=true;
    return dp[i][j]=res;
}
string ans="";
void print(int i,int j){
    if(s[i]=='\0' or t[j]=='\0'){
        cout<<ans<<endl;
        return;
    }
    if(s[i]==t[j]){
        ans+=s[i];
        print(i+1,j+1);
    }
    else{
        if(dp[i+1][j]>dp[i][j+1]){
            print(i+1,j);
        }
        else{
            print(i,j+1);
        }
    }

}
int main()
{


    cin>>s>>t;

    int l=lcs(0,0);
    print(0,0);
    return 0;
}





Measured memory_bytes: 44672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<int,int> P;

class UnionFind {
public:
	vector<int> par;//親の番号
  vector<int> rank;//木の深さ
  vector<int> size;//各グループの要素数uf.size[uf.find(1)]みたいな感じでfind経由忘れずに
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
            size[y]+=size[x];
        }else{
            par[y]=x;
            size[x]+=size[y];
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<int> p(n+1);
    FOR(i,1,n+1){
      cin>>p[i];
    }
    UnionFind uf(n);
    rep(i,m){
      int x,y;
      cin>>x>>y;
      uf.unite(x,y);
    }
    int ans=0;
    FOR(i,1,n+1){
      if(uf.same(i,p[i])){
        ans++;
      }
    }
    cout<<ans<<endl;
}

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

    bool ans = true;
    for(int i=0; i<S.size()/2; i++){
        if(S.at(i) != S.at(S.size()-i-1)){
            ans = false;
        }
    }

    string S_front = S.substr(0,(S.size()-1)/2);
    string S_back = S.substr((S.size()+3)/2-1,S.size());

    for(int i=0; i<S_front.size()/2; i++){
        if(S_front.at(i) != S_front.at(S_front.size()-i-1)){
            ans = false;
        }
    }
    for(int i=0; i<S_back.size()/2; i++){
        if(S_back.at(i) != S_back.at(S_back.size()-i-1)){
            ans = false;
        }
    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include <limits>
#include <numeric>
#include <type_traits>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)*/

//ここから書き始める
//実験

int main(){
	ll a,b, c, d;// A以上B以下のうち CでもDでも割り切れないものの個数	
	cin >> a>> b >> c >> d;
	ll ans = 0;
	ll whole = b - a +1  ;//考えられる個数 ここからcかdで割り切れる物の数を引くわけだ。
	ll revans = 0;
	// c 
	revans += b / c - (a-1) / c;
	// d
	revans += b / d - (a-1) / d;
	//c*d
	ll A =__gcd(c,d);
	ll G = c*d / A;
	revans -= b/G -(a-1)/G;
	ans = whole - revans ;
	cout<<ans<<endl;
}



Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==1:
    if a[0]!=0:
        print(0)
        exit()
    for i in range(n//2):
        if a[2*i+1]!=2*(i+1) or a[2*(i+1)]!=2*(i+1):
            print(0)
            exit()
    print(pow(2,n//2)%(10**9+7))
else:
    for i in range(n//2):
        if a[2*i]!=2*i+1 or a[2*i+1]!=2*i+1:
            print(0)
            exit()
    print(pow(2,n//2)%(10**9+7))

Measured memory_bytes: 14008
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		if(N-M==0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr ll MOD = 1000000007;

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

ll dp[2005][2005];
ll sum[2005][2005];

int main(int argc, char* argv[]) {
  ll n, m;
  cin >> n >> m;
  vec<ll> s(n), t(m);
  scan(s), scan(t);

  rep(i, 0, n) rep(j, 0, m) {
    if (s[i] == t[j]) {
      dp[i][j] = sum[i][j] + 1;
      dp[i][j] %= MOD;
    }

    sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i][j];
    sum[i + 1][j + 1] = mod(sum[i + 1][j + 1], MOD);
  }

  cout << sum[n][m] + 1 << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }

Measured memory_bytes: 62848
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
// constexpr auto mod = 1000000007;
using namespace std;

int main() {
  int N, K, X, Y;
  for (auto &&i : {&N, &K, &X, &Y}) {
    cin >> *i;
  }
  int answer = 0;
  REP(i, N) { answer += i < K ? X : Y; }
  cout << answer << endl;
  return 0;
}



Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto A = RDA(-1);

	auto cnt = new long[](N);
	foreach (i; 0..N-1)
	{
		++cnt[A[i]];
	}

	foreach (e; cnt)
		writeln(e);
	
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 12428
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,q,a;
    cin>>n>>k>>q;
    std::deque<int> deq(n,k);
    for (int i=0;i<q;i++) {
        cin>>a;
        deq[a-1]++;
    }
    for (int j=0;j<n;j++) {
        if (deq[j]-q<=0) {
            cout<<"No"<<endl;
        } else {
            cout<<"Yes"<<endl;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
// const int mod=1e9+7;
 const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 


int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2);
}
const int MAXN=6e3;
vector<int>  adj[MAXN];
bool cycle=false;
int visited[MAXN];
int color[MAXN];
// void dfs(int node)
// {
//     visited[node]=1;
//     for(auto i:adj[node])
//     {
//         if(visited[i.fi]==0)
//         {
//             visited[i.fi]=1;
//             color[i.se]=1;
//             dfs(i.fi);
//             visited[i.fi]=2;
//         }
//         else if(visited[i.fi]==1)
//         {
//             cycle=true;
//             color[i.se]=2;
//         }
//         else
//             color[i.se]=1;
//     }
//     visited[node]=2;
// }


signed main()

{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
       cout.tie(NULL);
     #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        }
     #endif
    auto clk=clock(); 
    // -------------------------------------Code starts here---------------------------------------------------------------------     
 
    int sum=0;
    int k;
    cin>>k;
    for(int a=1;a<=k;a++)
    {

        for(int b=1;b<=k;b++)
        {
            
            for(int c=1;c<=k;c++)
            {
                    sum+=__gcd(a, __gcd(b,c)); 
            }
        }
    }
    cout<<sum<<endl;
    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
 }


Measured memory_bytes: 3968
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)


N = int(input())
D = [int(x) for x in input().split()]
D.sort()

if N % 2 == 1:
    print(0)
    sys.exit()

if D[N // 2 - 1] == D[N // 2]:
    print(0)
else:
    ans = D[N // 2] - D[N // 2 - 1]
    print(ans)


Measured memory_bytes: 14900
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a,k) distance((v).begin(),(k)+upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a,k) distance((v).begin(),(k)+lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
ll binomial(ll N, ll K) {
  if(K < 0 || N < K) return 0;
  ll ret = 1;
  for(ll i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
void Main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int l=0;
  int r=0;
  string t;
  t.reserve(300);
  rep(i,n){
    if(s[i]=='('){
      l++; t+='(';
    }else{
      r++; t+=')';
    }
    if(r>l){
      t.insert(t.begin(),'(');
      r--;
    }
  }
  while(l>r){
    t+=')'; l--;
  }
  cout<<t<<endl;

} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
#include <stdio.h>

#define DATA_SET_MAX 50

int main()
{
    int H[DATA_SET_MAX];
    int W[DATA_SET_MAX];
    int cnt;
    int flag;

    for (int i = 0; i < DATA_SET_MAX; i++) {
        scanf("%d %d", &H[i], &W[i]);
        if ((H[i] == 0) && (W[i]== 0)) {
            cnt = i;
            break;
        }
        else {
            /* NOP */
        }

    }

    for (int i = 0; i < cnt; i++) {
        for (int h = 0; h < H[i]; h++) {
            if ((h % 2) == 0) {
                flag = 1;
            }
            else {
                flag = -1;
            }

            for (int w = 0; w < W[i]; w++) {
                

                if (flag == 1) {
                    printf("#");
                }
                else {
                    printf(".");
                }
                flag *= (-1);
            }
            printf("\n");
        }
        printf("\n");
    }

}


Measured memory_bytes: 2136
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 102
using namespace std;
bool mat[N][N];
int w, h, n;
int main() {
  cin>>w>>h>>n;
  memset(mat, false, sizeof(mat));
  for (int i = 0; i < n; ++i) {
  	int x,y,a;
    cin>>x>>y>>a;
    if (a == 1) {
    	for (int i = 0; i < x; ++i) {
        	for (int j = 0; j < h; ++j) {
            	mat[i][j] = true;
            }
        }
    } else if (a == 2) {
      for (int i = x; i < w; ++i) {
        	for (int j = 0; j < h; ++j) {
            	mat[i][j] = true;
            }
        }
    } else if (a == 3) {
      for (int i = 0; i < w; ++i) {
      	for (int j = 0; j < y; ++j) {
        	mat[i][j] = true;
        }
      }
    } else {
    	for (int i = 0; i < w; ++i) {
        	for (int j = y; j < h; ++j) {
            	mat[i][j] = true;
            }
        }
    }
  }
  int cnt=0;
  for (int i = 0; i < w; ++i) {
  	for (int j = 0; j < h; ++j) {
    	if (!mat[i][j]) cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

// グローバル変数


// 関数：


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N, M, counter;
	cin >> N;
	counter = 0;
	int H[21];
	for (int i=0; i<N; i++) {
		cin >> H[i];
		if (i == 0) {
			M = H[0];
			counter = counter + 1;
		}
		else if (H[i] >= M) {
			M = H[i];
			counter = counter + 1;
		}
	}
	
	cout << counter << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    map<int,int> cc;
    for(int i=1;i<=n;i++)
    {
        if(i<10)
        {
            cc[i]++;
            continue;
        }

        if(i%10==0)
        {
            continue;
        }
        string num=to_string(i);
        int p=(*num.begin()-'0')*10+(*(num.end()-1)-'0');
        if(p/10==p%10)
        {
            cc[p/10]++;
        }
        else
        {
            cc[p]++;

        }
        
        
    }
    ll ans=0;
    for(auto v:cc)
    {
        //cout<<v.first<<endl;
        int a=v.first;
        if(a<10)
        {
            ans+=v.second*v.second;
        }
        else
        {
            int b=(a/10)+(a%10)*10;
            ans+=v.second*cc[b];
        }
        
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3696
//666yuchen
//超越AC82
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
  cin>>a>>b>>c;
  for(int i=a;i<=a*1000;i+=a)
  if(i%b==c)
  {
  	cout<<"YES"<<endl;
  	return 0;
  }
  cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XY = [[] for _ in range(n)]
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = map(int, input().split())
            XY[i].append([x, y])

    res = 0
    for pattern in product([0, 1], repeat=n):
        for idx, p in enumerate(pattern):
            if p == 1:
                for x, y in XY[idx]:
                    if pattern[x - 1] != y:
                        break
                else:
                    continue
                break
        else:
            cnt = sum(pattern)
            res = max(res, cnt)

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
n,m = map(int,input().split())
ks = [list(map(int,input().split())) for _ in range(m)]
P = list(map(int,input().split()))

ans = 0
for p in range(2**n):
    num = format(p,'0'+str(n)+'b')
    light = 0
    for temp,i in zip(ks,range(1,m+1)):
        on = 0
        for s in temp[1:]:
            if num[s-1] == "1":
                on += 1
        if on%2 == P[i-1]:
            light += 1
    if light == m:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include<cstdio>

int main(){
	int S, h, m, s;
	0<=S&&S<86400;
	scanf("%d\n", &S);
	h=S/3600;
	m=(S%3600)/60;
	s=(S%3600)%60;
	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/ 
 
int sc1() {int x; scanf("%d", &x); return x;}
 
long long sc2() {long long x; scanf("%lld", &x); return x;}
 
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
 
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}
 

 
 
int solve() {
 

 	int n=Int;
 	int arr[n+1];
 	For(n) arr[i]=Int;

 	for(int i=0;i<n;i++){
 		if(arr[i]%2==0){
 			if(arr[i]%3==0 || arr[i]%5==0){

 			}
 			else {
 				cout<<"DENIED"<<endl;
 				return 0;
 			}
 		}
 	}
 	cout<<"APPROVED"<<endl;
	return 0;
}
 
 
 
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n+1, 0);
    ll s = 0;
    for(int i=1;i<=n;++i){
        cin >> a[i];
        s += a[i];
    }
    ll ans = 1LL<<60;
    for(int i=1;i<=n;++i) {
        a[i] += a[i-1];
        ans = min(ans, abs(a[i] - (s-a[i])));
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

#define ll signed long long


int main() {
  ll N, K;
  cin >> N >> K;
  N %= K;
  N = min (N, abs(K - N));
  cout << N << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	//~ #define LOCAL_INPUT_FILE
#else
	//~ #define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	static int64_t d0[3002][3002], da[3002][3002], db[3002][3002];
	int a, b, c, d; cin >> a >> b >> c >> d;
	const int mod = 998'244'353;
	d0[a][b] = 1;
	for (int i = a; i <= c; ++i) {
		for (int j = b; j <= d; ++j) {
			d0[i][j] %= mod;
			da[i][j] %= mod;
			db[i][j] %= mod;
			
			d0[i+1][j+1] += d0[i][j] * (i*j % mod) % mod;
			da[i+1][j] += d0[i][j] * j % mod;
			db[i][j+1] += d0[i][j] * i % mod;
			da[i+1][j] += da[i][j] * j % mod;
			db[i][j+1] += db[i][j] * i % mod;
			d0[i][j+1] += da[i][j] % mod;
			d0[i+1][j] += db[i][j] % mod;
		}
	}
	cout << (d0[c][d] + da[c][d] + db[c][d]) % mod << endl;
	return 0;
}


Measured memory_bytes: 214748
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
	int P, Q, R;
	cin >> P >> Q >> R;

	int A = max(P, Q);
	int B = max(A, R);

	cout << P + Q + R - B << endl;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int MAX=27,MAX2=1<<18;
const ll MOD=1000000007;
vector<int> group[MAX];
int seg[MAX2*2],pt[MAX],pt_end[MAX],cnt;
ll fin;
int n,odd;
char s[MAX2];
int get_len(int x,int y,int a,int b,int r){
    if(x<=a&&b<=y) return seg[r];
    if(y<=a||b<=x) return 0;
    return get_len(x,y,a,(a+b)/2,r*2)+get_len(x,y,(a+b)/2,b,r*2+1);
}
void update(int x){
    if(x==0) return;
    seg[x]++,update(x/2);
}
int main(){
    scanf(" %s",s);
    n=strlen(s);
    for(int i=0;i<n;i++){
        group[s[i]-'a'].push_back(i);
    }
    for(int i=0;i<26;i++) odd+=group[i].size()%2,pt_end[i]=group[i].size()/2;
    if(odd>1){
        printf("-1\n");
        return 0;
    }
    for(int i=0;i<n/2;i++){
        int idx=-1,idxl=100000007;
        for(int j=0;j<26;j++) if(pt[j]<pt_end[j]){
            int t=0,pt1=group[j][pt[j]],pt2=group[j][group[j].size()-1-pt[j]];
            t+=pt1-get_len(0,pt1,0,MAX2,1);
            t+=n-1-pt2-get_len(pt2,n,0,MAX2,1);
            if(idxl>t) idx=j,idxl=t;
        }
        fin+=(ll)idxl;
        update(MAX2+group[idx][pt[idx]]);
        update(MAX2+group[idx][group[idx].size()-1-pt[idx]]);
        pt[idx]++;
    }
    printf("%lld\n",fin);
}


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int N;

int main() {
  cin >> N;
  if (N < 1200) {
    cout << "ABC" << endl;
  } else if (N < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
}


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

int rot[][6] = {2, 6, 3, 4, 1, 5, 
		4, 2, 1, 6, 5, 3,
		3, 2, 6, 1, 5, 4,
		5, 1, 3, 4, 6, 2,
		1, 3, 5, 2, 4, 6,
		1, 4, 2, 5, 3, 6};
int dise[6];

void rotation(int r)
{
  int tmp[6];
  for (int i = 0; i < 6; i++) {
    tmp[i] = dise[rot[r][i] - 1];
  }
  for (int i = 0; i < 6; i++) {
    dise[i] = tmp[i];
  }
}

int main()
{
  map<string, int> m;
  m["North"] = 0, m["East"] = 1, m["West"] = 2, m["South"] = 3, m["Right"] = 4, m["Left"] = 5;
  int N;
  while (scanf("%d ", &N) == 1) {
    if (N == 0) {
      break;
    }
    for (int i = 0; i < 6; i++) {
      dise[i] = i + 1;
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
      string r;
      cin >> r;
      cin.ignore();
      rotation(m[r]);
      sum += dise[0];
    }
    printf("%d\n", sum + 1);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

#define mod 998244353
#define inf 0x7f7f7f7f
#define maxn 500005
#define N 300005
typedef long long ll;

inline int read()
{
    int x = 0;
    int f = 1;
    char c = getchar();
    while (c<'0' || c>'9')
    {    
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0'&&c <= '9')
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x*f;
}

//_scc[u]存u点所在强连通分量的标号,out[x]存标号为x的强连通分量的出度,
//cot[x]存标号为x的连通量的点的数目
ll a, b;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int is_ok(ll x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (!(x % i)) return 0;
    }
    return true;
}

int m, v[1000005], prime[1000004];

void primes() {
    memset(v, 0, sizeof(v));
    m = 0;
    for (int i = 2; i <= 1000000; i++) {
        if (!v[i]) {
            v[i] = i;
            prime[++m] = i;
        }
        for (int j = 1; j <= m; j++) {
            if (prime[j] > v[i] || prime[j] > 1000000 / i) break;
            v[i * prime[j]] = prime[j];
        }
    }
}
int cnt;
int main() {
    cin >> a >> b;
    ll k = gcd(a, b);
    primes();
    for (int i = 1;i <= m;i++) {
        int flag = 0;
        while (!(k %prime[i])) {
            k /= prime[i];
            flag = 1;
        }
        if (flag) cnt++;
    }
    if (is_ok(k) && k != 1) cnt++;
    cout << cnt + 1 << endl;
}   

Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
const constexpr int INF = 1e9;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;
struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};
const constexpr ll MOD = 1e9;


ll extGCD(ll a, ll b, ll& x, ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}
ll GCD(ll a, ll b){
    if(a<b) swap(a, b);
    if(b==0) return a;
    return GCD(b, a%b);
}
bool a[100010];
int main() {
    int N, K; cin >> N >> K;
    int cnt=0;
    int sum=1;
    while(cnt!=N){
        if(sum*2<sum+K){
            sum*=2;
        }else{
            sum+=K;
        }
        cnt++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
//Don't be late

package main

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

func willBeLate(d, t, s int) bool {

	return d <= s*t
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	t := sc.Text()
	return strconv.Atoi(t)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	d, _ := nextInt(sc)
	t, _ := nextInt(sc)
	s, _ := nextInt(sc)

	if willBeLate(d, t, s) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1776
#include<iostream>
#include<string.h>
#include<stdio.h>


int main() {
	int a;
	int b;

	scanf("%d", &a);
	
	int i = 0;
	int k = 0;
	for (i = 1; i <= 9; i++) {
		if (a % i == 0 && a / i <= 9) {
			k = 1;
			break;
		}
		
	}
	if (k == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}

}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<vector>
using std::cin;
using std::cout;
using std::vector;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b)
		cout<<"YES";
	else
		cout<<"NO";
}

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

int main(){
    int n,k;
    cin>>n>>k;
    
    int d;
    set<int> oks;
    rep(i,k){
        cin>>d;
        int hoge;
        for (int i = 0; i < d; i++){
            cin>>hoge;
            oks.insert(hoge);
        }
    }

    int ans=0;
    set<int>::iterator itr;
    for(int j=1;j<=n;j++){
        itr = oks.find(j);
        if(itr==oks.end()){
            ans++;
        }
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 3632