akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>

using namespace std;

const int N = 2e3 + 5;

int n;
vector <int> g[N], d[N];

vector <int> bfs(int ver) {
    vector <int> d(n, -1);
    queue <int> que;
    que.push(ver);
    d[ver] = 0;
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int to : g[v]) {
            if (d[to] == -1) {
                d[to] = d[v] + 1;
                que.push(to);
            }
        }
    }
    return d;
}

int main() {
    cin >> n;
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
    for (int i = 0; i + 1 < n; i++) {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    vector <int> cnt(n);
    for (int i = 0; i < n; i++) {
        d[i] = bfs(i);
        for (int j = i + 1; j < n; j++) {
            cnt[ d[i][j] ]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << cnt[i] << endl;
    }
}


Measured memory_bytes: 16128
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[3001][3001];
string s;
int LCS(string &a,string &b,int n,int m)
{
    if(n==0 || m==0)
        return 0;
    else if(dp[n][m]!=-1)
        return dp[n][m];
    else if(a[n-1]==b[m-1])
        dp[n][m]=1 + LCS(a,b,n-1,m-1);
    else
        dp[n][m]=max(LCS(a,b,n-1,m),LCS(a,b,n,m-1));
    return dp[n][m];
}
int main()
{   memset(dp,-1,sizeof(dp));
    string a,b;
    cin>>a;
    cin>>b;
    int n=a.length();
    int m=b.length();
    LCS(a,b,n,m);
    while(n>0 && m>0)
    {
        if(a[n-1]==b[m-1])
        {
            s=s+a[n-1];
            n--;
            m--;
        }
        else if(dp[n-1][m]>dp[n][m-1])
            n--;
        else
            m--;
    }

   reverse(s.begin(),s.end());
   cout<<s;
   return 0;
}


Measured memory_bytes: 35968
N = int(input())
a = [0] * N
b = [0] * N

Ans = 0

for i in range(N):
    a[i], b[i] = map(int, input().split())

for i in range(N):
    for k in range(1, N-i):
        Ans += ((a[i]-a[i+k])**2 +(b[i]-b[i+k])**2)**0.5 

print(Ans*2/N)

Measured memory_bytes: 38384
int main()
{
    int A[3];
    int n5=0,n7=0;
    scanf("%d%d%d",&A[0],&A[1],&A[2]);
    for(int i=0;i<3;i++)
    {
        if(A[i]==5)n5++;
        if(A[i]==7)n7++;
    }
    if(n5==2&&n7==1)printf("YES");
    else printf("NO");
    return 0;
}


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

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


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	int m,n;
	void solve(){
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		int[][] road=new int[n+1][n+1];
		for(int i=0;i<m;i++){
			int a=sc.nextInt();
			int b=sc.nextInt();
			road[a][b]++;
			road[b][a]++;
		}
		for(int i=1;i<=n;i++){
			int count=0;
			for(int j=1;j<=n;j++){
				if(road[i][j]>0)count+=road[i][j];
			}
			System.out.println(count);
		}
		
	}
}


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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
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; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	ll n, k;
	cin >> n >> k;
	ll a = n%k;
	ll ans = min(a, k-a);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
 
int main(){ 
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  rep(i,n) cin >> a[i];
  rep(j,m) cin >> b[j];
  vector<ll> ca(n + 1, 0), cb(m + 1, 0);
  for (int i = 0; i < n; i++) ca[i + 1] = ca[i] + a[i];
  for (int i = 0; i < m; i++) cb[i + 1] = cb[i] + b[i];

  int res = 0;

  for (int i = 0; i <= n; i++) {
    ll x = k - ca[i];
    if (x < 0) break;
    int j = lower_bound(cb.begin(), cb.end(), x) - cb.begin();
    if (j == m + 1) j--;
    if (cb[j] > x) j = max(j - 1, 0);
    res = max(res, i + j);
  }
  cout << res << endl;
  return 0;
} 

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

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

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

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

int main()
{
    int R; cin >> R;
    cout << (double)2*R*M_PI << endl;
}

Measured memory_bytes: 3784
// Created by ahmed_drawy on 11/09/19.
///dp educational contest atcoder
#include <bits/stdc++.h>
#include <string.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)
#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define inf 0x3f3f3f3f
//#define dbg (v)    for(auto it : v)cout<<it<<' ';
typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;
const double EPS =1e-7;
const int OO = 1e6;
#define endl '\n'
#define cint(c) (int)c -'0';
#define itc(c) (char)c +'A';
bool sortpair( const pair<int , int> & x, const pair<int , int> & y){
    return  x.first != y.first ? x.first < y.first : x.second > y.second ;
}
int dcomp(double x , double y){
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}

void smile() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
  //  freopen("/home/tw3/Desktop/Desktop/training/in.txt", "r", stdin);
//    freopen("/home/tw3/Desktop/Desktop/training/out.txt" , "w" , stdout);
#endif
}
#define fastin smile()

int n , m;
const int N = 3000 +3;
ll dp[N][N];
string s, t;
ll lcs(int i , int j ){
    if(i == n || j ==m )
        return 0 ;
    ll &ret = dp[i][j];
    if(~ret)
        return ret;
    ret = 0;
    if(s[i] == t[j])
        ret =1 +  lcs(i+1 , j+1);
    else {
        ret = max(ret, lcs(i + 1, j));
        ret = max(ret, lcs(i, j + 1));
    }
    return ret;
}
string ans;
void build(int i , int j){
    if(i == n || j ==m )
        return  ;
    int  mx1 = 0, mx2 = 0  , mx3 = 0 ;

    if(s[i] == t[j]) {
       mx1 = 1+  lcs(i + 1, j + 1);
        cout << s[i];
        build(i+1, j+1);
        return ;
    }

    if(lcs(i+1 , j) > lcs(i , j+1))
        build(i+1, j);
    else build(i, j+1);
    return ;

}
int main() {
    fastin;
    cin >> s >> t;
    n = sz(s), m = sz(t);
    for (int i = 0; i <sz(s) ; ++i) {
        for (int j = 0; j <sz(t) ; ++j) {

        }
    }
    clr(dp , -1);
    lcs(0,0);
    build(0,0);


}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int N;
string s;

Int used[100010][20];
Int mem[100010][20];
Int dfs(Int idx, Int x){
  if(idx == N) return x == 5;
  if(used[idx][x]++) return mem[idx][x];

  Int res = 0;
  for(Int i=0;i<10;i++){
    if(s[idx] != '?' && s[idx] != i + '0') continue;
    Int nx = (x * 10 + i) % 13;
    res += dfs(idx + 1, nx);
    res %= mod;
  }
  return mem[idx][x] = res;
}
signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>s;
  N = s.size();

  Int ans = dfs(0, 0);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 39504
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

    int N;
    cin >> N;

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

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

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

    long long ab = 0, bc = 0;
    long long ans = 0;

    for (int i = 0; i < N; i++){
        
        int num1 = ab;
        for (int j = num1; j < N; j++){
            if (b[i] > a[j]){
                ab ++;
            }else{
                break;
            }
        }

        int num2 = bc;
        for (int j = num2; j < N; j++){
            if (b[i] >= c[j]){
                bc ++;
            }else{
                break;
            }
        }
        
        ans += ab * (N - bc);

    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll x; cin >> x; ll now = 0; ll ans = 1e10;
 
  rep(i,6){
    rep(j,6){
      rep(k,6){
        rep(l,6){
          rep(m,6){
            rep(n,3){
              
              rep(o,9){
                rep(p,9){
                  rep(q,9){
                    rep(r,9){
                      rep(s,2){
                        now = 6*i+36*j+216*k+1296*l+7776*m
                          +46656*n+
                          9*o+81*p+729*q+6561*r+59049*s;
                        if(now <= x){
                          ans = min(ans,i+j+k+l+m+n+o+p+q+r+s+
                                    x-now);
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

vector<lint> divisor(lint n) {
	vector<lint> ret;
	for (lint i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.emplace_back(i);
			if (i * i != n) ret.emplace_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	return ret;
}

lint gcd(lint a, lint b) { return b ? gcd(b, a%b) : a; }

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	lint N;
	cin >> N;

	vector<lint> div = divisor(N);

	lint ans = 0;
	for (int i = 1, len = (int)div.size(); i < len; i++) {

		if (N / (div[i] - 1) == N % (div[i] - 1)) ans += div[i] - 1;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))

c=[0]*(10**6+5)

isPairwise=True
isSetwise=True
for i in range(N):
    c[A[i]]+=1

for i in range(2,1000005):
    cnt=0
    for j in range(i,1000005,i):
        cnt+=c[j]
    
    if cnt>1:
        isPairwise=False

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

g=0
for i in range(N):
    g=gcd(g,A[i])
if g>1:
    isSetwise=False

if isPairwise:
    print('pairwise coprime')
elif isSetwise:
    print('setwise coprime')
else:
    print('not coprime')

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

long long x, y, s, m=1e9;
int main() {
	scanf("%lld", &s);
	x = (m - s % m) % m;
	y = (s + x) / m;
	printf("0 0 %lld 1 %lld %lld", m, x, y);
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
  
  int flag=1;
  ll sum=0;
  int flag1=0;
  ll tot=0;
  ll ans=0;
  map<int,int>m;
  vi v;
  set<int>st;
  string s;
  scl(n);
  if(n==1)
  {
  	cout<<0;
  }
  else {
  	n--;
  	ans=n*(n+1)/2;
  	cout<<ans;
  }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pl;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

int main(){

  string s;
  cin >> s;

  if(s.length()%2) s=s+'p';

  int ct=0;
  rep(i,s.length()){
    if(s[i]=='g') ct++;
  }


  cout << (ct-(s.length()-ct))/2 <<endl;
  return 0;
}


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

using namespace std;

using Weight=int;
struct Edge{
    int src,dst;
    Weight weight;
    Edge(int src,int dst,Weight weight):
    src(src),dst(dst),weight(weight){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else if(e.src!=f.src)return e.src<f.src;
    else return e.dst<f.dst;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;

void dfs(int v,int d,int c,const Graph &g,vector<int>&iro,vector<int>&memo){
    if(memo[v]>=d)return;
    memo[v]=d;
    if(iro[v]==0)iro[v]=c;
    for(auto x:g[v]){
        dfs(x.dst,d-1,c,g,iro,memo);
    }
    return;
}

int main(){
    int n,m;cin>>n>>m;
    Graph g(n);
    for(int i=0;i<m;++i){
        int s,t;cin>>s>>t;
        g[s-1].emplace_back(s-1,t-1,1);
        g[t-1].emplace_back(t-1,s-1,1);
    }
    int q;cin>>q;
    vector<int>v(q),d(q),c(q);
    for(int i=0;i<q;++i){
        cin>>v[i]>>d[i]>>c[i];
    }
    vector<int>memo(n,-1),iro(n,0);
    for(int i=q-1;i>=0;--i){
        dfs(v[i]-1,d[i],c[i],g,iro,memo);
    }
    for(int i=0;i<n;++i){
        cout<<iro[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 9268
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;

typedef long long ll;

int main(){
    int n;
    ll k;
    cin >> n >> k;

    vector<ll> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];

    if(k == 0){
        cout << accumulate(a.begin(), a.end(), 0ll) << endl;
        return 0;
    }

    // 0の数
    vector<int> cnt(50, 0);
    for(int i = 0; i < 50; i++){
        for(int j = 0; j < n; j++){
            if(((a[j]>>i)&1)==0)    cnt[i]++; 
        }
    }

    vector<vector<ll>> dp(50, vector<ll>(2, 0ll));

    ll t = 48;
    while( ((k>>t)&1) == 0 ){
        // kの力が及ばない高bit域ではkは0を取るしかない
        dp[t][0] = dp[t][1] = (1ll<<t) * (n-cnt[t]);
        dp[t][0] += dp[t+1][0];
        dp[t][1] += dp[t+1][1];
        t--;
    } 

    // 0 -> even, 1 -> less
    dp[t][0] = (1ll<<t) * cnt[t] + dp[t+1][0];
    dp[t][1] = (1ll<<t) * (n-cnt[t]) + dp[t+1][1];

    for(t--; t >= 0; t--){
        ll zero = (1ll<<t) * (n-cnt[t]);
        ll one = (1ll<<t) * cnt[t];

        if((k>>t)&1){
            dp[t][0] = dp[t+1][0] + one;
            dp[t][1] = max(dp[t+1][1] + max(zero, one), dp[t+1][0]+zero);
        }else{
            dp[t][0] = dp[t+1][0] + zero;
            dp[t][1] = dp[t+1][1] + max(one, zero);
        }
    }

    cout << max(dp[0][0], dp[0][1]) << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


string s;
int lgt;

ll summary;

int dfs(ll current, ll sum, int idx) {
	if (idx == lgt) {
		summary += current;
		summary += sum;
		return 0;
	}
	ll i = int(s[idx] - 48);

	dfs(i, sum+current, idx + 1);

	dfs(current * 10 + i, sum, idx + 1);

	return 0;
}

void solve() {
	ll ind = ll(s[0] - 48);
	dfs(ind,0,1);
	print(summary);
}


int main() {
	cin >> s;
	lgt = s.size();

	solve();



	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		long[] a = new long[5];
		
		long n = s.nextLong();
		
		a[0] = s.nextLong();
		a[1] = s.nextLong();
		a[2] = s.nextLong();
		a[3] = s.nextLong();
		a[4] = s.nextLong();
		
		long min = a[0];
		for (int i=0; i < 5 ; i++ ) {
			min = Math.min(min, a[i]);
		}
		if(min >= n) {
			System.out.println(5);
			return;
		}
		long neck = ( n + min - 1) / min;
		

		System.out.println (neck + 4);
		
		s.close();
		
	}

}

Measured memory_bytes: 23764
# n 個の整数が与えられます。
# この中に、何種類の異なる値があるでしょうか。

# 与えられる整数の数を取得
n = gets.chomp.to_i

# 与えられた整数を1つずつ格納する配列を宣言し、格納
nums = Array.new
n.times do |i|
    input = gets.to_i
    nums[i] = input
end

# 既に格納されている値を、再び格納しない配列を宣言し、与えられた整数を格納
nums_diff = Array.new
n.times do |i|
    unless nums_diff.include?(nums[i])
        nums_diff << nums[i]
    end
end

# 結果を出力
puts nums_diff.count

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

int main()
{
    int costmin = 1e7 + 5;
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    for (int x = 1; x <= 100; x++)
    {
        int cost = 0;
        for (int i = 0; i < n; i++)
            cost += ((v[i] - x) * (v[i] - x));
        costmin = min(costmin, cost);
    }
    cout << costmin;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr double INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

double N;
double A[100],B[100];
bool used[10];
double ans = 0.0,cnt = 0.0;

void dfs(int X){
    bool end = 1;
    REP(i,N) if(!used[i] && i != X) end = 0;
    if(end){
        ans += cnt;
        return;
    }
    used[X] = 1;
    REP(i,N){
        if(used[i]) continue;
        double Q = abs(A[X] - A[i]),P = abs(B[X] - B[i]);
        cnt += sqrt((Q*Q+P*P));
        dfs(i);
        cnt -= sqrt((Q*Q+P*P));
    }
    used[X] = 0;
}

signed main() {cout << setprecision(20);
    cin.tie(0);
	ios::sync_with_stdio(false);cin >> N;
    double C = 1;
    REPP(i,1,N+1) C *= i;
    REP(i,N){
        cin >> A[i] >> B[i];
    }
    REP(i,N) dfs(i);
    cout << ans/C << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
li = list(map(int, input().split()))
li_a = sorted(li)
if k == 0:
  print(sum(li_a))
elif k >= n:
  print(0)
else:
  for i in range(k):
    li_a.pop()
  print(sum(li_a))

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

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

    ll ans = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        while(a%2 == 0) {
            a /= 2;
            ans++;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)

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

	map<string, int32_t> mp;
	string s;
	for (uint32_t i = 0; i < n; i++) {
		cin >> s;
		mp[s]++;
	}

	uint32_t m;
	cin >> m;
	for (uint32_t i = 0; i < m; i++) {
		cin >> s;
		mp[s]--;
	}

	int32_t result = 0;
	for (auto p : mp) {
		result = max(result, p.second);
	}
	printf("%d\n", result);
	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define ll long long
    const ll maxn=2e5+10;
     
     
    int main() {
    	fast;
    	ll n,k,i,j;
    	cin>>n>>k;
    	if(k>n) cout<<min(n,abs(n-k))<<endl;
    	else if(n%k==0) cout<<"0"<<endl;
    	else if(n%k!=0)
    	{
    		cout<<min(abs(n-(n/k+1)*k),abs(n-(n/k)*k))<<endl;
    	}
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define iton for(long long i=0;i<n;i++)
#define jtom for(long long j=0;j<m;j++)
#define itok for(long long i=0;i<k;i++)
void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<string> v;
    iton
    {
        string s;
        cin>>s;
        v.push_back(s);
    }

    long long dp[n][m];
    iton
        jtom
            if(v[i][j]=='#')
                dp[i][j]= 0;

    dp[0][0]=1;
    for(long long i=1;i<m;i++)
    {   
        if(v[0][i]!='#')
        dp[0][i] = dp[0][i-1];
    }
    for(long long i=1;i<n;i++)
    {   
        if(v[i][0]!='#')
        dp[i][0] = dp[i-1][0];
    }
    ll mod = 1e9+7;
    for(long long i=1;i<n;i++)
    {
        for(long long j=1;j<m;j++)
        {   
            if(v[i][j]=='.')
            {
                dp[i][j]  = (dp[i-1][j] + dp[i][j-1]) %mod  ;
            } 
            else 
            dp[i][j] = 0;
        }
    }
    // for(long long i=0;i<n;i++)
    // {
    //     for(long long j=0;j<m;j++)
    //     {   
    //         cout<<dp[i][j]<<" ";  
    //     }
    //     cout<<endl;
    // }
    cout<<dp[n-1][m-1]%mod;
    cout<<'\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    solve();
}


Measured memory_bytes: 9088
# Save snuk

# 方針: sからiまでに円を用いて行く最小コストと、iからt(tから)iまでスヌークでいく最小コストを求める

import heapq

def dijkstra(n:int,graph,s):
    # n: ノード数
    # graph: エッジの {x0:[(w1,y1),(w2,y2),...],x1:[...]} リストの中はタプルにする
    # s: 基準となるノード ノードsからの最短距離を求める
    
    d = [float('inf')] * n  # ノードsからの距離
    notvisited = [True] * n # 訪れていない、すなわち決定していない頂点
    vertex_list = []        # 次に訪れる頂点の候補リスト

    # sに合わせて初期化
    d[s] = 0
    notvisited[s] = False
    [heapq.heappush(vertex_list,v) for v in graph[s]] # 候補リストの初期化

    while len(vertex_list):
        minedge = heapq.heappop(vertex_list) # 決定していない頂点のうちsからの距離が最小のものを基準とする
        vertex = minedge[1]
        if notvisited[vertex]:
            d[vertex] = minedge[0]
            notvisited[vertex] = False # 距離決定

            # 基準となる頂点からと連結している頂点をみて、次の頂点の候補リストを更新
            for e in graph[vertex]: 
                next_vertex = e[1]
                if notvisited[next_vertex]:
                    heapq.heappush(vertex_list,(d[vertex]+e[0],next_vertex)) # 候補リストに頂点を追加
    
    return d



n,m,s,t = map(int,input().split())
graph_a = {x:[] for x in range(n)}
graph_b = {x:[] for x in range(n)}
money = 10**15

for _ in range(m):
    u,v,a,b = map(int,input().split())
    u-=1
    v-=1
    graph_a[u].append((a,v))
    graph_a[v].append((a,u))
    graph_b[u].append((b,v))
    graph_b[v].append((b,u))

d_a = dijkstra(n,graph_a,s-1) # sから円を使ったときの最短距離
d_b = dijkstra(n,graph_b,t-1) # tからスヌークを使ったときの最短距離

min_list = [float('inf')] * n # 最後からi番目以降で両替した場合の最小値
min_list[0] = d_a[-1] + d_b[-1]
for i in range(1,n):
    x = d_a[n-i-1] + d_b[n-i-1]
    if x < min_list[i-1]:
        min_list[i] = x
    else:
        min_list[i] = min_list[i-1]

for i in range(n):
    print(money-min_list[-(i+1)])



Measured memory_bytes: 97776
import java.util.Scanner;

public class Main {
	
	public static final char cDir[] = {
		'U', 'R', 'D', 'L'
	};
	
	public static final int pDir[][] = {
		{0, -1}, {1, 0}, {0, 1}, {-1, 0}
	};
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		
		while(scan.hasNext()){
			char map[][] = new char [9][5];
			boolean neighbor[][][] = new boolean [5][5][4];
			int hand[] = {0, 0};	//現在の座標
			int iDir = 1;			//cDir や pDirに対応している。
			String answer = new String();
			
			//入力処理
			for(int i=0; i<9; i++){
				map[i] = scan.next().toCharArray();
			}
			
			//neighbor初期化
			for(int i=0; i<5; ++i){
				for(int j=0; j<5; ++j){
					//Up
					neighbor[i][j][0] = 0<=(i*2-1) ? (map[i*2 -1][j] == '1') : false;
					//Right
					neighbor[i][j][1] = j<(5-1) ? (map[i*2][j] == '1') : false;
					//Down
					neighbor[i][j][2] = (i*2+1)<9 ? (map[i*2+1][j] == '1') : false;
					//Left
					neighbor[i][j][3] = 0<=(j-1) ? (map[i*2][j-1] == '1') : false; 
				}
			}
			
			//本体
			int x=0, y=0;
			while(true){
				//探索
				x = hand[0]; y = hand[1];
				if(neighbor[y][x][(iDir+3)%4]){
					iDir = (iDir+3)%4;
				}else if(neighbor[y][x][(iDir+0)%4]){
					iDir = (iDir+0)%4;
				}else if(neighbor[y][x][(iDir+1)%4]){
					iDir = (iDir+1)%4;
				}else{
					iDir = (iDir+2)%4;	//逆戻り
				}
				
				//結果処理
				hand[0] += pDir[iDir][0];
				hand[1] += pDir[iDir][1];
				answer += cDir[iDir];
				//動いた先が点Aだったらループから抜ける。
				if(hand[0]==0 && hand[1]==0){
					break;
				}
			}
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 11000
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      int n,m,k;cin>>n>>m>>k;char arr[n][m];
      char brr[n][m];
      ll x=1;
      f(i,0,n)
      x*=2;
      x-=1;
      ll y=1;
      f(i,0,m)
      y*=2;
      y-=1;
      f(i,0,n)
      f(j,0,m)
      {cin>>arr[i][j];brr[i][j]=arr[i][j];}
      int ans=0;
      f(i,0,x+1)
      {
        f(j,0,y+1)
        {
          vii r,c;
          ll v=1,ind=0;
          while(v<=i)
          {
            if((v&i)!=0)
            {
              r.pb(ind);
            }
            v<<=1;ind++;
          }
          v=1,ind=0;
          while(v<=j)
          {
            if((v&j)!=0)
            c.pb(ind);
            v<<=1;ind++;
          }
          dbg(r);dbg(c);
          f(k,0,si(r))
          {
            int row=r[k];
            f(kk,0,m)
            brr[row][kk]='.';
          }
          f(k,0,si(c))
          {
            int col=c[k];
            f(kk,0,n)
            brr[kk][col]='.';
          }
          int cnt=0;
          f(ii,0,n)
          f(jj,0,m)
          if(brr[ii][jj]=='#')
          cnt++;
          if(cnt==k)
          ans++;
          f(ii,0,n)
          f(jj,0,m)
          brr[ii][jj]=arr[ii][jj];

        }
      }
      cout<<ans;
    }    
} 


Measured memory_bytes: 3648
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x2 = x.copy() + [X]
x2 = sorted(x2)
diffs = []
for i in range(1, len(x2)):
    diffs.append(x2[i] - x2[i - 1])
if len(diffs) == 1:
    print(diffs[0])
else:
    diffs_gcd = gcd(diffs[0], diffs[1])
    for i in range(2, len(diffs)):
        diffs_gcd = gcd(diffs_gcd, diffs[i])
    print(diffs_gcd)

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

int main(){
  int A, B;
  scanf("%d%d", &A, &B);
  if(A <= 9 && B <= 9){
    printf("%d\n", A * B);
  }
  else{
    printf("-1\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int n,m;
char s[2005][2005];
int q,x1,x2,y1,y2;
int sum1[2005][2005],sum2[2005][2005],sum3[2005][2005],sum4[2005][2005],sum5[2005][2005];
int main() {
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            sum1[i][j]=sum1[i][j-1]+sum1[i-1][j]-sum1[i-1][j-1];
            sum2[i][j]=sum2[i][j-1]+sum2[i-1][j]-sum2[i-1][j-1];
            sum3[i][j]=sum3[i][j-1]+sum3[i-1][j]-sum3[i-1][j-1];
            sum4[i][j]=sum4[i][j-1]+(s[i][j]=='1'&&s[i-1][j]=='1'?1:0);
            sum5[i][j]=sum5[i-1][j]+(s[i][j]=='1'&&s[i][j-1]=='1'?1:0);
            if (s[i][j]=='1') {
                sum1[i][j]++;
                if (s[i][j]==s[i-1][j]) sum2[i][j]++;
                if (s[i][j]==s[i][j-1]) sum3[i][j]++;
            }
        }
    }
    for(;q--;) {
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        int ans1=sum1[x2][y2]-sum1[x1-1][y2]-sum1[x2][y1-1]+sum1[x1-1][y1-1];
        int ans2=sum2[x2][y2]-sum2[x1-1][y2]-sum2[x2][y1-1]+sum2[x1-1][y1-1];
        int ans3=sum3[x2][y2]-sum3[x1-1][y2]-sum3[x2][y1-1]+sum3[x1-1][y1-1];
        int ans4=sum4[x1][y2]-sum4[x1][y1-1];
        int ans5=sum5[x2][y1]-sum5[x1-1][y1];
        printf("%d\n",ans1-ans2-ans3+ans4+ans5);
    }
    return 0;
}

Measured memory_bytes: 84224
import java.io.*;
import java.util.*;
public class Main {
  public static void main(String[] args) throws Exception {
    String line = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    line = br.readLine();
    int size = Integer.parseInt(line);
    long res = 0;
    for (int i = 0; i < size; i ++) {
      line = br.readLine();
      String data[] = line.split(" ");
      long start = Long.parseLong(data[0]);
      long end = Long.parseLong(data[1]);
      res = res + (end - start) + 1;
    }
    System.out.println(res);
  }
}

Measured memory_bytes: 21460
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define in insert
#define int ll
using namespace std;
using namespace __gnu_pbds;
 
const ll N =(3e5+5);
const ll MOD = 998244353;
const ll INF = 1e16;
const ll LOG = 25;
 
 
long long binpow(long long a, long long b) {
    // a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
ld maxvolume(ld s) 
{ 
    // finding length 
    ld length = s / 3; 
  
    s -= length; 
  
    // finding breadth 
    ld breadth = s / 2; 
  
    // finding height 
    ld height = s - breadth; 
  
    return length * breadth * height; 
} 
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
        ld l;
        cin >> l;
   cout <<fixed<<setprecision(10)<< maxvolume(l)<<endl;
}
/*
for(int i =1;i<=m;i++){
        for(int j = 1;j<=i;j++){
            cout<<"ELEMENTS : " << i << " , " << "ROUNDED DOWN : " << j << " DP VALUE : "<< dp[i][j] << endl;
        }
    }
*/

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=50;
int n;
int dd;
vector<int> pre,mid,post;
int l,r;
int pos;
void rec(int l,int r)
{
    if(l>=r) return;
    int root=pre[pos++];
    int m=distance(mid.begin(),find(mid.begin(),mid.end(),root));
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&dd);
        pre.push_back(dd);
    }
    for(int i=0; i<n; i++)
    {
        scanf("%d",&dd);
        mid.push_back(dd);
    }
    pos=0;
    rec(0,pre.size());
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        printf("%d",post[i]);
    }
    printf("\n");


    return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <vector>
#include <string>
// #include <algorithm>
// #include <map>
// #include <set>
// #include <cmath>

using namespace std;
typedef unsigned long long ull;


int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int start = s.find_first_of('A');
    int end = s.find_last_of('Z');
    cout << end - start + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
//main関数

#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        m[x-1]=i;
    }
    for(auto p:m){
        cout<<p.second+1<<" ";
    }
}

Measured memory_bytes: 5504
from collections import Counter

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

mod = 998244353

if d[0] != 0:
    print(0)
    exit()

d.sort()
ma = d[-1]

c = Counter(d)
if c[0] > 1:
    print(0)
    exit()

ans = 1
pre = 1
for i in range(ma+1):
    if c[i] == 0:
        print(0)
        exit()
    ans *= pow(pre, c[i], mod)
    ans %= mod
    pre = c[i]

print(ans)




Measured memory_bytes: 19936
import java.io.*;
import java.util.*;
import java.util.function.IntPredicate;
 
public class Main{
	int X;
	public void solve(){
		X = nextInt();
		out.println(lowerBound(0, X + 1, v -> {
			int cur = X;
			int vv = v;
			while(cur > 0 && vv > 0){
				if(cur >= vv){
					cur -= vv;
					vv = Math.min(cur, vv - 1);
				}else{
					vv = cur;
				}
			}
			return cur == 0;
		}));
	}

	public int lowerBound(int begin, int end, IntPredicate check){
		int l = begin - 1;
		int r = end;
		while(r - l > 1){
			int m = (r + l) / 2;
			if(check.test(m)){
				r = m;
			}else{
				l = m;
			}
		}
		return r;
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

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

int main()
{
  int n;
  for(;cin>>n;)
    {
      int edge[n][n],m;
      cin>>m;
	for(int i=0;i<n;i++)
	  for(int j=0;j<n;j++)
	    {
	      if(i==j)
		edge[i][j]=0;
	      else
		edge[i][j]=1000000;
	    }
      for(int i=0;i<m;i++)
	{
	  char ch;
	  int a,b,c,d;
	  cin>>a>>ch>>b>>ch>>c>>ch>>d;
	  a--;b--;
	  edge[a][b]=c;
	  edge[b][a]=d;
	}
      for(int k=0;k<n;k++)
	for(int i=0;i<n;i++)
	  for(int j=0;j<n;j++)
	    edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
      /*   
      for(int i=0;i<n;i++,cout<<endl)
	  for(int j=0;j<n;j++)
	    cout<<edge[i][j]<<" ";
      */
      int a,b,c,d;
      char ch;
      cin>>a>>ch>>b>>ch>>c>>ch>>d;
      a--;b--;
      cout<<c-d-edge[a][b]-edge[b][a]<<endl;
      
    }
}

Measured memory_bytes: 1160
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;

int main(){
    char a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a==b||b==c||c==d){
        cout << "Bad";
    }
    else cout << "Good";
}

Measured memory_bytes: 256
#include<iostream>

int main(){
    
    size_t a, b;

    std::cin >> a >> b;

    if(a >= 6 && a <= 12){
        std::cout << b / 2 << std::endl;
    }else if(a < 6){
        std::cout << 0 << std::endl;
    }else{
        std::cout << b << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#include <deque>
#include<sstream>

using namespace std;
typedef long long int lli;

const int INF = 100100100;

int main()
{
    int n, k, x, y;

    cin >> n >> k >> x >> y;

    int a = (n < k) ? n : k;
    int b = (n < k) ? 0 : n - k;


    cout << x * a + y * b << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>

using namespace std;

int main() {
	long ans = 0;
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N;i++) {
		cin >> a[i];
	}

	for (int i = 0;i < N;i++) {
		ans += (a[i] - 1);
		//cout << m << "mod" << a[i] << "  " << m % a[i] << endl;
	}
	//cout << "m=" << m << " " << ans << endl;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
    int a[(int)2e5+10];
    int b[(int)2e5+10];
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    /*
    ios::sync_with_stdio(0);
    */
    int n;
    cin>>n;
    int i;
    fo(i,n)
    {
        scanf("%d",&a[i]);
    }
    int d=0;
    if (a[n-1]>n-1)
    {
        d=1;
    }
    ll o=a[n-1];
    ro(i,n-1)
    {
        if (a[i]>i)
        {
            d=1;
        }
        if (a[i]>=a[i+1])
        {
            o+=a[i];
        }
        else
        {
            if (a[i]!=a[i+1]-1)
            {
                d=1;
            }
        }
    }
    if (d)
    {
        cout<<-1;
    }
    else
    {
        cout<<o;
    }
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    string a,b;
    cin>>a>>b;
    char c,d,e,f,g,h;
    c=a[0];
    d=a[1];
    e=a[2];
    f=b[2];
    g=b[1];
    h=b[0];
    if(c==f && d==g && e==h){
        cout<<"YES";
    }
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1001
#define M 1000000007

int c[N][N] = {0};
char s[N][N];

int main()
{		
	int a, b, i, j, i0, j0, t;
	
	scanf("%d%d", &a, &b);
	for(i = 1; i <= a; i++) scanf("%s", s[i] + 1);
	for(i = 1, i0 = 0, c[0][1] = 1; i <= a; i0 = i++){
		for(j = 1, j0 = 0; j <= b; j0 = j++){
			if(s[i][j] == '#') continue;
			t = c[i][j0] + c[i0][j];
			if(t >= M) t -= M;
			c[i][j] = t;
		}
	}
	printf("%d\n", c[a][b]);
				
	return 0;
}

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

int main() {
  int n,m;
  cin >>n>>m;
  vector<int> count(n,0);
  vector<vector<int>> totori(m,vector<int>(2));
  
  for (int i = 0; i < m ; i++) {
    for (int j = 0; j < 2 ; j++) {
      cin >>totori [i][j];
    }
  }
    for (int i = 0; i < m ; i++) {
    for (int j = 0; j < 2 ; j++) {
     int rorona=totori[i][j];
      count[rorona-1]++;
    }
  }


    
    
    
    
    for(int i=0;i<n;i++) cout<<count[i]<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int min = 1000; int max = 0;
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			if(a < min) min = a;
			if(a > max) max = a;
		}
		System.out.println(max - min);
	}
}


Measured memory_bytes: 21972