akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    //Bellman-Ford's Algorithm
    private static final int MAX = 99999;
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int V = scanner.nextInt();
        int E = scanner.nextInt();
        int src = scanner.nextInt();

        int[] dist = new int[V];
        int[][] edges = new int[E][3];

        for(int i = 0; i < V; ++i){
            dist[i] = MAX;
        }
        dist[src] = 0;

        for(int i = 0; i < E; ++i){
            int[] edge = new int[] {scanner.nextInt(), scanner.nextInt(), scanner.nextInt()};
            edges[i] = edge;
        }

        for(int i = 1; i < V; ++i){
            boolean update = false;
            for(int j = 0; j < E; ++j){
                int[] edge = edges[j];
                if(dist[edge[0]] != MAX && dist[edge[1]] > dist[edge[0]] + edge[2]){
                    dist[edge[1]] = dist[edge[0]] + edge[2];
                    update = true;
                }
            }

            if(!update){
                break;
            }
        }

        boolean containNegativeCycle = false;
        for(int j = 0; j < E; ++j){
            int[] edge = edges[j];
            if(dist[edge[0]] != MAX && dist[edge[1]] > dist[edge[0]] + edge[2]){
                containNegativeCycle = true;
                break;
            }
        }

        if(containNegativeCycle){
            System.out.println("NEGATIVE CYCLE");
            return;
        }

        for(int i = 0; i < V; ++i){
            System.out.println(dist[i] == MAX ? "INF" : dist[i]);
        }
    }
}

Measured memory_bytes: 37540
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;

static const double EPS = 1e-8;

int main(){
	map<string,string> button;
	button["1"] = "'"; button["11"] = ","; button["111"] = "."; button["1111"] = "!"; button["11111"] = "?";
	button["2"] = "a"; button["22"] = "b"; button["222"] = "c"; button["2222"] = "A"; button["22222"] = "B"; button["333333"] = "C";
	button["3"] = "d"; button["33"] = "e"; button["333"] = "f"; button["3333"] = "D"; button["33333"] = "E"; button["333333"] = "F";
	button["4"] = "g"; button["44"] = "h"; button["444"] = "i"; button["4444"] = "G"; button["44444"] = "H"; button["444444"] = "I";
	button["5"] = "j"; button["55"] = "k"; button["555"] = "l"; button["5555"] = "J"; button["55555"] = "K"; button["555555"] = "L";
	button["6"] = "m"; button["66"] = "n"; button["666"] = "o"; button["6666"] = "M"; button["66666"] = "N"; button["666666"] = "O";
	button["7"] = "p"; button["77"] = "q"; button["777"] = "r"; button["7777"] = "s"; button["77777"] = "P"; button["777777"] = "Q"; button["7777777"] = "R"; button["77777777"] = "S";
	button["8"] = "t"; button["88"] = "u"; button["888"] = "v"; button["8888"] = "T"; button["88888"] = "U"; button["888888"] = "V";
	button["9"] = "w"; button["99"] = "x"; button["999"] = "y"; button["9999"] = "z"; button["99999"] = "W"; button["999999"] = "X"; button["9999999"] = "Y"; button["99999999"] = "Z";

	string str;
	while(cin >> str){
		//if(cin.eof()) break;
		string res="";
		for(int i=0;i<str.size();){
			bool found = false;
			for(int len=8;len>=1;len--){
				if(button.find(str.substr(i,len)) != button.end()){
					res+=button[str.substr(i,len)];
					i+=len;
					found = true;
					break;
				}
			}
			if(!found){
				int c=0;
				for(int pos=0;;pos++){
					if(str[i+pos]=='0') c++;
					else break;
				}
				i+=c;
				while(--c) res.append(" "); 

			}
		}
		cout << res <<  endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  int c;
  if(b<10)c=a*10+b;
  else if(b<100)c=a*100+b;
  else c=a*1000+b;
  if ((int)pow((int)sqrt(c),2)==c)cout<<"Yes\n";
  else cout<<"No\n";
  //cout<<c;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
data = input().split(" ")
for i in range(N):
  data [i] = int(data[i])

count = 0
for i in range(N-1):
  if data[i] < data[i+1]:
    None
  else:
    count = count + data[i] - data[i+1]
    data[i+1] = data[i]
print(count)

Measured memory_bytes: 25004
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  int dp[n];
  for(int i=0;i<n;i++)
  dp[i]=1000000008;
  
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
  {
  	for(int j=1;j<=k;j++)
    {
    	if((i-j)>=0)
    	{
    	dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
        }
	}
  }
  cout<<dp[n-1]<<endl;
  return 0;
} 

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
  mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const ll MAXN = 12;
const ll MASK = (1 << MAXN);
const ll INF = 1e12;

void upd(ll& x, ll y) { x = min(x, y); }

int main() {
    cout << fixed << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n, m;
    cin >> n >> m;
    vl costs(m);
    vl masks(m);

    for (ll i = 0; i < m; ++i) {
        ll cnt;
        cin >> costs[i] >> cnt;
        for (ll j = 0; j < cnt; ++j) {
            ll bit;
            cin >> bit;
            --bit;
            masks[i] |= (1LL << bit);
        }
    }

    vvl dp(m + 1, vl(MASK + 10, +INF));
    dp[0][0] = 0;

    for (ll i = 0; i < m; ++i) {
        for (ll mask = 0; mask < MASK; ++mask) {
            upd(dp[i + 1][mask], dp[i][mask]);
            upd(dp[i + 1][mask | masks[i]], dp[i][mask] + costs[i]);
        }
    }
    ll ans = dp[m][(1 << n) - 1];
    cout << (ans == INF ? -1 : ans) << endl;

    print_time();
    return 0;
}




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

using namespace std;

const int N = 10;
int n;
string a, s1, s2;
vector<string> vc;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 1; i <= n; i++){
        a += (i + '0');
        s1 += '1';
        s2 += '1';
    }
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        s1[i - 1] = (x + '0');
    }
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        s2[i - 1] = (x + '0');
    }
    //cout << s1 << " " << s2 << '\n';
    do {
        vc.push_back(a);
    } while(next_permutation(a.begin(), a.end()));

    int pos1 = 1, pos2 = 1;
    for(auto x : vc){
        if(x == s1){
            break;
        }
        pos1++;
    }
    for(auto x : vc){
        if(x == s2){
            break;
        }
        pos2++;
    }
    cout << abs(pos1 - pos2) << '\n';
    return 0;
}

Measured memory_bytes: 2424
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

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

int sz[N];
int d[N];
int parent[N];


void dfs(int v, int par, int dist){
    d[v]=dist;
    sz[v]=1;
    for(auto u: g[v]){
        if(u==par) continue;
        dfs(u,v,dist+1);
        sz[v]+=sz[u];
        parent[u]=v;
    }
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    rep(i,1,n){
        int a,b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(1,-1,0);
    int x=(d[n]-1)/2;
    int z=n;
    //cout << x << " " << parent[n] << "\n";
    while(x>0){
        z=parent[z];
        x--;
    }
    //cout << d[n] << " " << z << "\n";
    if(sz[z]*2>=n) cout << "Snuke";
    else cout << "Fennec";
    return 0;
}

Measured memory_bytes: 11776
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A){
    ll nrOdd=0, nrEven=0;
    REP(i, N){
        if(A[i] % 2 == 0)
            nrEven ++;
        else
            nrOdd ++;
    }
    if(nrOdd % 2 == 0){
        cout << YES << endl;
    }
    else
        cout << NO << endl;
    
}

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


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        try (final Scanner sc = new Scanner(System.in)) {
            final int n = sc.nextInt();
            final int k = sc.nextInt();
            final String s = sc.next();

            final char first = s.charAt(0);
            final int[] cumulatives = new int[n + 1];
            int cSize = 0;
            cumulatives[cSize++] = 0;
            if (first == '0') {
                cumulatives[cSize++] = 0;
            }
            char prev = first;
            int len = 0;
            for (int i = 0; i < n; i++) {
                final char current = s.charAt(i);
                if (current != prev) {
                    cumulatives[cSize] = cumulatives[cSize - 1] + len;
                    cSize++;
                    len = 1;
                } else {
                    len += 1;
                }
                prev = current;
            }
            if (len > 0) {
                cumulatives[cSize] = cumulatives[cSize - 1] + len;
                cSize++;
            }
            int answer = 0;
            for (int left = 0, right = Math.min(left + 2 * k + 1, cSize - 1); left < cSize; left += 2, right = Math
                    .min(left + 2 * k + 1, cSize - 1)) {
                final int value = cumulatives[right] - cumulatives[left];
                answer = Math.max(answer, value);
            }
            System.out.println(answer);
        }
    }

}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep (i, n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll res = 0;
    int cur = 0;
    rep (i, n - 1) {
        res += a[cur];
        if (i % 2 == 0) cur++;
    } 
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 4768
#include<stdio.h>

int main(){
  int n,s[1000],i,j,num,k;

  while(1){
    num = 0;
    scanf("%d",&n);
    if(n == 0){
      break;
    }
    for(i = 0 ; i < n ; i++){
      scanf("%d",&s[i]);
    }
    for(i = 0 ; i < n ; i++){
      for(j = i ; j < n ; j++){
	if(s[i] > s[j]){
	  k = s[i];
	  s[i] = s[j];
	  s[j] = k;
	}
      }
    }
    for(i = 1 ; i < n - 1 ; i++){
      num += s[i];
    }
    num /= (n-2);
    printf("%d\n",num);
  }
  return 0;
}

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

  int A, B, C;
  cin >> A >> B >> C;
  
  bool x = A == B && A != C;
  bool y = B == C && B != A;
  bool z = C == A && C != B;
  
  if(x || y || z){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringTokenizer to = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(to.nextToken());
		int m = Integer.parseInt(to.nextToken());
		int[][] dp = new int[n + 1][n + 1];
		while (m-- > 0) {
			to = new StringTokenizer(reader.readLine());
			int a = Integer.parseInt(to.nextToken());
			int b = Integer.parseInt(to.nextToken());
			int x = Integer.parseInt(to.nextToken()) + 1;
			dp[a][b] = x;
		}
		int ans = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= i; j++) {
				dp[i][j] = Math.max(dp[i][j],
						Math.max(dp[i - 1][j], dp[i - 1][j - 1]) - 1);
				if (dp[i][j] > 0)
					ans++;
			}
		System.out.println(ans);
	}
}

Measured memory_bytes: 201204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N,K,Y;
  int X =1;
  cin >> N >> K;
  Y=0;
  for (;N>Y; Y++){
    if(X<K){
      X*=2;
    }
    else{
      X+=K;
    }
  }
  cout << X <<endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vll a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  vll su(n+1);
  for(int i=0;i<n;++i) {
    su[i+1] = su[i] + a[i];
  }


  vvll dp(n, vll(n, LINF));
  for(int i=0;i<n;++i) {
    dp[i][i] = 0;
  }
  

  for(int i=1;i<n;++i) {
    for(int j=0;j<n-i;++j) {
      int k = j + i;
      for(int l=j;l<k;++l) {
        dp[j][k] = min(dp[j][k], dp[j][l] + dp[l+1][k] + (su[l+1] - su[j]) + (su[k+1] - su[l+1]));
      }
    }
  }


  cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

//initialization here
//

//
//initialization finish


// your function is here
//

//
// your function finished

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//

	int a,b;cin>>a>>b;
	int cnt=0;
	FOR(i,a,b+1)
	{
		if(i/10000 == i%10 && (i/1000)%10 == (i/10)%10)cnt++;
	}

	Print(cnt);
	//
	// your code finished


	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

to_east = 0
to_west = s.count('E', 1)
ans = to_east+to_west

for i in range(1, n):
  if s[i-1]=='W':
    to_east += 1
  if s[i]=='E':
    to_west -= 1
  ans = to_east+to_west if ans>to_east+to_west else ans
  
print(ans)



Measured memory_bytes: 3672
# コピペ https://atcoder.jp/contests/dwacon5th-prelims/submissions/7670569
# 自分の https://atcoder.jp/contests/dwacon5th-prelims/submissions/7822126
# とほぼ変わらないのに自分のものはTLEするので検証
n=int(input())
s=input()
q=int(input())
for i in list(map(int,input().split())):
    a=0
    v=[0,0,0]
    for j in range(n):
        if s[j]=="D":
            v[0]+=1
        elif s[j]=="M":
            v[1]+=1
            v[2]+=v[0]
        if j>=i:
            if s[j-i]=="D":
                v[0]-=1
                v[2]-=v[1]
            elif s[j-i]=="M":
                v[1]-=1
        if s[j]=="C":
            a+=v[2]
    print(a)

Measured memory_bytes: 61672
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

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

  ll ktemp=K;
  int k[40]={};
  for(int i=39;i>=0;i--){
    if(ktemp>=(1LL << i)){
      ktemp=ktemp-(1LL << i);
      k[i]=1;
    }
  }

  int cnt[40]={};
  for(int i=0;i<N;i++){
    ll a;
    cin >> a;
    for(int j=39;j>=0;j--){
      if(a>=(1LL << j)){
        a=a-(1LL << j);
        cnt[j]++;
      }
    }
  }

  //for(int i=0;i<40;i++) printf("k[%2d]=%d\n",i,k[i]);
  //for(int i=0;i<40;i++) printf("cnt[%d]=%d\n",i,cnt[i]);



  ll ans=0LL;
  //X=Kを探索
  for(int i=0;i<40;i++){
    if(k[i]==1) ans+=(N-cnt[i])*(1LL << i);
    else ans+=cnt[i]*(1LL << i);
  }

  /*for(int i=39;i>=0;i--) cout << k[i];
  cout << endl;*/

  //X<Kを探索
  for(int i=39;i>=0;i--){
    if(k[i]==1){
      int x[40];
      for(int j=39;j>i;j--){
        x[j]=k[j];
      }
      x[i]=0;
      for(int j=0;j<i;j++){
        if(cnt[j]>N-cnt[j]) x[j]=0;
        else x[j]=1;
      }

      /*for(int j=39;j>=0;j--) cout << x[j];
      cout << endl;*/

      ll temp=0LL;
      for(int j=0;j<40;j++){
        if(x[j]==1) temp+=(N-cnt[j])*(1LL << j);
        else temp+=cnt[j]*(1LL << j);
      }

      ans=max(ans,temp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//Tariquzzaman Faisal
//_Faisal101_
//IUT_CSE'19
//190041101
 
#include<iostream>
#include<stdio.h>
#include<vector>
#include<deque>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<climits>
#include<cmath>
#include<iterator>
#include<set>
#define fileOut freopen("out.txt","w",stdout)
#define fileIn freopen("in.txt","r",stdout)
#define testcases ll TC,T; cin >> TC; for(T=1; T<=TC; T++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define INFLL 9223372036854775807
#define INF 2147483647
#define pi acos(-1.0)
#define ll long long
#define endll printf("\n")
#define CASE printf("Case %lld: ",T)
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define ull unsigned long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mid3(a,b,c) min(max(a,b),max(b,c),max(a,b))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define endl '\n'
#define ld long double
 
 
using namespace std;


int main(){
    ll n, k;
    cin >> n >> k;
    ll ara[n], maxValue = -1, numberIsPresent = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> ara[i];
        maxValue = max(maxValue, ara[i]);
        if(ara[i] == k){
            numberIsPresent = 1;
        }
    }
    sort(ara, ara+n);
    vector <ll> v;
    for (int i = 1; i < n; ++i)
    {
        v.push_back(__gcd(ara[i], ara[i-1]));
    }
    if(k > maxValue){
        cout<<"IMPOSSIBLE"<<endl;
    }
    else if(numberIsPresent){
        cout<<"POSSIBLE"<<endl;
    }
    else{
        ll gcd_diye_mod_hoy = 0;
        for (int i = 0; i < v.size(); ++i)
        {
            if(k%v[i] == 0){
                gcd_diye_mod_hoy = 1;
                break;
            }
        }
        if(gcd_diye_mod_hoy){
            cout<<"POSSIBLE"<<endl;
        }
        else{
            cout<<"IMPOSSIBLE"<<endl;
        }
    }
    
    return 0;
}


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

int main()
{
        int n,i,s=0;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++)
        {
                cin>>a[i];
                s+=a[i]-1;
        }
        cout<<s<<endl;
        return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> ans;
    for(int i = a; i < min(a+k, b+1); i++)ans.push_back(i);
    for(int i = max(a, b-k+1); i <= b; i++)ans.push_back(i);
    sort(all(ans));
    ans.erase(unique(all(ans)), ans.end());
    sort(all(ans));
    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  double x1, y1;
  cin >> x1 >> y1;
  double x2, y2;
  cin >> x2 >> y2;
  double x3, y3;
  cin >> x3 >> y3;
  double d1 = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
  double d2 = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
  double d3 = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  double A = acos(((x2 - x1) * (x3 - x1) + (y2 - y1) * (y3 - y1)) / (d2 * d3));
  double B = acos(((x3 - x2) * (x1 - x2) + (y3 - y2) * (y1 - y2)) / (d3 * d1));
  double C = acos(((x1 - x3) * (x2 - x3) + (y1 - y3) * (y2 - y3)) / (d1 * d2));
  double S = abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2;
  double h = 2 * S / min({d1, d2, d3});
  if (d1 >= d2 && d1 >= d3){
    cout << min(h / 2, d1 / (1 / tan(B / 2) + 1 / tan(C / 2) + 2)) << endl;
  } else if (d2 >= d3 && d2 >= d1){
    cout << min(h / 2, d2 / (1 / tan(C / 2) + 1 / tan(A / 2) + 2)) << endl;
  } else {
    cout << min(h / 2, d3 / (1 / tan(A / 2) + 1 / tan(B / 2) + 2)) << endl;
  }
}

Measured memory_bytes: 4112
function Main(s) {
  var a = 0, b = 0, c = 0;
  for(var i = 0; i < 3; i++){
    if(s[i] === "a")a = 1;
    if(s[i] === "b")b = 1;
    if(s[i] === "c")c = 1;
  }
  console.log(a + b + c === 3 ? "Yes" : "No");
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO 1e18
#define EPS 1e-6
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=5205;

int main()
{
    IO;
    int n;
    cin >> n;
    string a[3];
    for(int i=0;i<3;++i)
        cin >> a[i];
    int ans=0;
    for(int i=0;i<n;++i){
        set<char> st;
        for(int j=0;j<3;++j)st.insert(a[j][i]);
        ans+=(int)st.size()-1;
    }
    cout<<ans<<endl;
    re 0;
}

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

bool solve() {
    int M, Nmin, Nmax;
    cin >> M >> Nmin >> Nmax;
    if (M == 0 && Nmin == 0 && Nmax == 0) {
        return false;
    }
    int p[200];
    for (int j = 0; j < M; j++) {
        cin >> p[j];
    }

    int ind = Nmin-1;
    for (int j = Nmin; j < Nmax; ++j) {
        if (p[j]-p[j+1] >= p[ind]-p[ind+1]) {
            ind = j;
        }
    }
    cout << ind+1 << endl;
    return true;
}

int main() {
    for(;solve(););
    return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);


int main()
{
    int n;
    cin>>n;
    int arr[n];
    int sum=0;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        sum^=arr[i];

    }
    for(int i=0;i<n;i++)
        cout<<(sum^arr[i])<<" ";


    return 0;
}


Measured memory_bytes: 4416
#ABC128D-equeue.py

from sys import stdin

input = stdin.readline

N, K = list(map(int, input().split()))
VList = list(map(int, input().split()))
sumList = []

for i in range(min([K,N])+1):
    for j in range(min([K,N])-i+1):
        k = K -i -j
        myHand = [VList[n] for n in range(i)] + [VList[-m] for m in range(1,j+1)] + [0]
        myHand.sort(reverse=True)
        for _ in range(k):
            if myHand[-1] < 0:
                myHand.pop()
            else:
                break
        sumList.append(sum(myHand))


print(max(sumList))


Measured memory_bytes: 3188
n,k,*a=map(int,open(0).read().split())

from fractions import gcd


G=a[0]
for i in a:
    G=gcd(G,i)
    
A=max(a)
if k>A:
    print("IMPOSSIBLE")
    exit()
    
while A>0:
    if k==A:
        print("POSSIBLE")
        exit()
    A-=G
print("IMPOSSIBLE")

Measured memory_bytes: 76512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
   string s;
   std::cin >> s;
   int count=0;
   int ans=0;
   int i;
   for (i=0;i<s.size();i++){
       if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T') count++;
       else if(count>ans){
           ans=count;
           count=0;
       }
       else count=0;
       
   }
   if (ans<count)ans=count;
   std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	}
}

Measured memory_bytes: 27392
n, m = map(int, input().split())
A = []
b = []
for _ in range(n):
    A.append(list(map(int, input().split())))
for _ in range(m):
    b.append(int(input()))
    
C = [0 for _ in range(n)]

for i in range(n):
    for j in range(m):
        C[i] += A[i][j] * b[j]

for c in C:
    print(c)


Measured memory_bytes: 6024
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define mod 1000000009

int main(){
  ios_base::sync_with_stdio(0);
  int t=1;  
  //cin>>t;
  while(t--){
    int n,x;
    cin >> x >> n;
    set<int> s;
    for(int i=0; i<n; i++){
      int temp;
      cin>>temp;
      s.insert(temp);
    }
    int ans = 1000;
    for(int i=0; ; ++i){
      if(!s.count(x-i)){
        ans = x-i;
        break;
      }
      else if(!s.count(x+i)){
        ans = x+i;
        break;
      }
    }
  cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3636
h, w = gets.split(" ").map(&:to_i)
ss = []
h.times do
  ss << gets.chomp.chars
end

h.times do |i|
  w.times do |j|
    next if ss[i][j] == "."
    tmp = ss[i][j]
    rem = 4
    flag = false

    if ss[i][j] == "#"
      ss[i][j] = "x"
      rem -= 1
    end
    if (i > 0) && ss[i-1][j] == "#" || ss[i-1][j] == "x"
      ss[i-1][j] = "x"
      rem -= 1
      flag = true
    end
    if (j > 0) && ss[i][j-1] == "#" || ss[i][j-1] == "x"
      ss[i][j-1] = "x"
      rem -= 1
      flag = true
    end
    if (ss[i][j+1] == "#") || ss[i][j+1] == "x" && rem >= 3
      ss[i][j+1] = "x"
      rem -= 1
      flag = true
    end
    if ss[i+1] && (ss[i+1][j] == "#" || ss[i+1][j] == "x") && rem >= 3
      ss[i+1][j] = "x"
      rem -= 1
      flag = true
    end

    if !flag
      ss[i][j] = tmp
    end
  end
end

ss.each do |s|
  s.each do |c|
    if c == "#"
      puts "No"
      exit
    end
  end
end

puts "Yes"

Measured memory_bytes: 2044
from sys import stdin
prize=["null","one pair","two pair","three card",
        "straight","full house","four card"]

for line in stdin:
    hand = map(int,line.split(","))
    x = sorted(list(set(hand)))
    a = len(x)
    b = max([hand.count(e) for e in x])
    if b==4: p=6
    elif b==3:
        if a==2: p=5
        else: p=3
    elif b==2:
        if a==3: p=2
        else: p=1
    elif b==1:
        e = x[0]
        if x==[1,10,11,12,13] or x==range(e,e+5): p=4
        else: p=0
    print prize[p]

Measured memory_bytes: 4236
N = gets.to_i
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
arr = []
N.times do |n|
  arr.push((x[n] - y[n]).abs)
end
puts arr.sum
puts Math.sqrt(arr.map {|a| a ** 2}.sum)
puts Math.cbrt(arr.map {|a| a ** 3}.sum)
puts arr.max


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<pii> a(n);
	rep(i,n){
		cin >> a.at(i).first;
		a.at(i).second = i + 1;
	}
	sort(all(a));
	rep(i,n){
		if(i == n - 1) cout << a.at(i).second << endl;
		else cout << a.at(i).second << " ";
	}
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = asin(1) * 2;

int n;
ld x[100], y[100];

ld getR (ld xc, ld yc) {
    ld r = 0.0;
    FOR(i, 1, n) {
        ld d = (x[i]-xc)*(x[i]-xc) + (y[i]-yc)*(y[i]-yc);
        r = max(d, r);
    }
    return r;
}

ld f (ld xc) {
    ld le = 0.0, ri = 1000.0;
    REP(200) {
        ld mid1 = le+(ri-le)/3, mid2 = ri-(ri-le)/3;
        if (getR(xc,mid1) < getR(xc,mid2)) ri = mid2;
        else le = mid1;
    }
    return getR(xc,le);
}

int main()
{
    FAST_IO;

    cin >> n;
    FOR(i, 1, n) cin >> x[i] >> y[i];

    ld le = 0.0, ri = 1000.0;
    REP(200) {
        ld mid1 = le+(ri-le)/3, mid2 = ri-(ri-le)/3;
        if (f(mid1) < f(mid2)) ri = mid2;
        else le = mid1;
    }

    cout << fixed << setprecision(15) << sqrt(f(le)) << endl;

    return 0;
}


Measured memory_bytes: 384
def gcd(a,b):
  a = int(a)
  b = int(b)
  r = (int)(a%b)
  while(r!=0):
    a=(int)(b)
    b=(int)(r)
    r=(int)(a%b)
  return b
def lcm(a,b):
    return int((a*b)//gcd(a,b))
n = int(input())
ans = int(input())
for i in range(n-1):
  num = int(input())
  ans = lcm(max(ans,num),min(ans,num))
print(int(ans))


Measured memory_bytes: 3064
p=print
b=0
for e in iter(input,'0 0'):
 if b:p()
 b=f=1;s,t=map(int,e.split())
 for y in range(s,t+1):
  if(y%4==0)*(y%100)or y%400==0:p(y);f=0
 f and p('NA')


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

bool proceed(vector<int64>& A) {
  int mini = INF;
  vector<int64> B(A.size(), 0);
  REP(i, A.size()) {
    int64 l = max((int64)0, i - A[i]);
    int64 r = min((int64)A.size(), i + A[i] + 1);
    B[l]++;
    if (r < B.size()) B[r]--;
  }
  REP(i, B.size()) {
    if (i > 0) B[i] += B[i-1];
    chmin(mini, B[i]);
  }
  swap(A, B);
  return mini == B.size();
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, K;
	cin >> N >> K;
	vector<int64> A(N);
	REP(i, N) {
	  cin >> A[i];
	}
	REP(i, K) {
	  if (proceed(A)) break;
	}
	REP(i, N) {
	  cout << A[i] << " ";
	}
	cout << endl;
}


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

int main()
{
  int a, b, m, min_v;
  cin >> a >> b >> m;
  vector<int> as(a), bs(b);
  for (int i = 0; i < a; i++)
  {
    cin >> as[i];
  }
  for (int i = 0; i < b; i++)
  {
    cin >> bs[i];
  }
  min_v = *min_element(as.begin(), as.end()) + *min_element(bs.begin(), bs.end());
  for (int i = 0; i < m; i++)
  {
    int x, y, c;
    cin >> x >> y >> c;
    int v = as[x - 1] + bs[y - 1] - c;
    if (v < 0)
    {
      v = 0;
    }
    if (v < min_v)
    {
      min_v = v;
    }
  }
  cout << min_v << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;

  int max = A;
  if (max < B) max = B;
  if (max < C) max = C;

  cout << A + B + C - max + max * 10 << endl;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

using ld = long double;

const int N = 3e3 + 7;
int n;
ld rozk[N];
ld pom[N];

int main() {
    scanf("%d", &n);
    rozk[0] = 1.;
    for (int i = 1; i <= n; ++i) {
        ld p;
        scanf("%Lf", &p);
        
        for (int j = 0; j < i; ++j) {
            pom[j + 1] += p * rozk[j];
            pom[j] += (1.0 - p) * rozk[j];
        }
        
        for (int j = 0; j <= i; ++j) {
            rozk[j] = pom[j];
            pom[j] = 0.;
        }
    }
    
    ld wyn = 0.;
    for (int i = 0; i <= n; ++i) {
        if (i > n - i) wyn += rozk[i];
    }
    printf("%.12lf\n", (double) wyn);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;

template <typename T, size_t H, size_t W>
using matrix = array<array<T, W>, H>;
template <typename T, size_t A, size_t B, size_t C>
matrix<T, A, C> operator * (matrix<T, A, B> const & a, matrix<T, B, C> const & b) {
    matrix<T, A, C> c = {};
    REP (y, A) REP (z, B) REP (x, C) c[y][x] += a[y][z] * b[z][x];
    return c;
}
template <typename T, size_t H, size_t W>
array<T, H> operator * (matrix<T, H, W> const & a, array<T, W> const & b) {
    array<T, H> c = {};
    REP (y, H) REP (z, W) c[y] += a[y][z] * b[z];
    return c;
}
template <typename T, size_t N>
matrix<T, N, N> unit_matrix() {
    matrix<T, N, N> a = {};
    REP (i, N) a[i][i] = 1;
    return a;
}
template <typename T, size_t N>
matrix<T, N, N> powmat(matrix<T, N, N> x, ll k) {
    matrix<T, N, N> y = unit_matrix<T, N>();
    for (; k; k >>= 1) {
        if (k & 1) y = y * x;
        x = x * x;
    }
    return y;
}

template <typename T>
T solve1(int a, int b, int c, ll k) {
    matrix<T, 3, 3> f = {{
        {{ 0, 1, 1 }},
        {{ 1, 0, 1 }},
        {{ 1, 1, 0 }},
    }};
    array<T, 3> x = {{ (T)a, (T)b, (T)c }};
    array<T, 3> y = powmat(f, k) * x;
    return y[0] - y[1];
}
ll solve(int a, int b, int c, ll k) {
    auto x = solve1<long double>(a, b, c, k);
    if (abs(x) > 1e18 * 1.1) return LLONG_MAX;
    auto y = solve1<ll>(a, b, c, k);
    if (abs(y) > 1e18) return LLONG_MAX;
    return y;
}

int main() {
    int a, b, c; ll k; cin >> a >> b >> c >> k;
    ll ans = solve(a, b, c, k);
    if (ans == LLONG_MAX) {
        cout << "Unfair" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import bisect as bi

n = int(input())
s = input()
arr = [[] for i in range(10)]

for i in range(n):
  num = int(s[i])
  arr[num].append(i)

count = 0
for i in range(1000):
  index = 0
  s_num = str(i).zfill(3)
  s1 = int(s_num[0])
  if len(arr[s1]) == 0:
    continue
  else:
    index = arr[s1][0]
  
  s2 = int(s_num[1])
  if len(arr[s2]) == 0 or index >= arr[s2][-1]:
    continue
  
  tmp = bi.bisect_right(arr[s2], index)
  index = arr[s2][tmp]
  
  s3 = int(s_num[2])
  if len(arr[s3]) == 0 or index >= arr[s3][-1]:
    continue
  
  count += 1
  
print(count)
    

Measured memory_bytes: 4456
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  string xmas = "Christmas";
  string s;
  if(n==24){
    s = " Eve";
  }else if(n==23){
    s = " Eve Eve";
  }else if(n==22){
    s = " Eve Eve Eve";
  }
  cout << xmas << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
char a[100005];
int x=0,y=0,ans=0;
int main()
{
    cin>>a;
    for (int i=0;i<sizeof(a);i++)
     if (x==y){x++; if(a[i]=='p') ans--;}    
     else{y++; if(a[i]=='g') ans++;}    
    printf("%d\n",ans);                    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  int D;
  cin >>N>>D;
  int data[N][D];
  rep(i,N) {
    rep(j,D) {
      cin>>data[i][j];
    }
  }
  int count=0;
  int counting=0;
  
  rep(i,N-1) {
repl(j,i+1,N) {
   
  rep(k,D) {
count +=(data[i][k]-data[j][k])*(data[i][k]-data[j][k]);
  }
  
    
  double A=sqrt(count);
  double B=floor(A);
  count=0;
  
  
  
  
  
  
  
  
  if(A==B) {
counting++;
  }

}
  }
  
  cout<<counting<< endl;
}

 

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

ll vs[10];

int main(void) {
  REP(i, 3) {
    cin >> vs[i];
  }
  int k;
  cin >> k;
  sort(vs, vs + 3);
  REP(i, k) {
    vs[2] *= 2LL;
  }
  ll res = vs[0] + vs[1] + vs[2];
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main() {
	string s;
	cin >> s;
	int counter = 1;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s.at(i) != s.at(i + 1)) counter++;
	}
	cout << counter - 1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {

  int year,month,day;


  while(scanf("%d %d %d",&year,&month,&day)!=EOF) {

    if(year<1868) {

      printf("pre-meiji\n");

    } else if(year==1868) {

      if(month<9) printf("pre-meiji\n");

      else if(month==9 && day<8) printf("pre-meiji\n");

      else printf("meiji 1 %d %d\n",month,day);

    } else if(year<1912) {

      printf("meiji %d %d %d\n",year-1867,month,day);

    } else if(year==1912) {

      if(month<7) printf("meiji 45 %d %d\n",month,day);

      else if(month==7 && day<30) printf("meiji 45 %d %d\n",month,day);

      else printf("taisho 1 %d %d\n",month,day);

    } else if(year<1926) {

      printf("taisho %d %d %d\n",year-1911,month,day);

    } else if(year==1926) {

      if(month<12) printf("taisho 15 %d %d\n",month,day);

      else if(month==12 && day<25) printf("taisho 15 %d %d\n",month,day);

      else printf("showa 1 %d %d\n",month,day);
    
    } else if(year<1989) {

      printf("showa %d %d %d\n",year-1925,month,day);

    } else if(year==1989) {

      if(month==1 && day<8) printf("showa 64 %d %d\n",month,day);

      else printf("heisei 1 %d %d\n",month,day);

    } else {

      printf("heisei %d %d %d\n",year-1988,month,day);

    }

  }

  return 0;

}

Measured memory_bytes: 0
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean isOK = true;
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int i = 1; i <= n; i++) {
            int checking = sc.nextInt();
            if (checking % 2 == 0) {
                if (!((checking % 3 == 0)||(checking % 5 == 0))) {
                    isOK = false;
                }
            }
        }
        if (isOK) {
            System.out.println("APPROVED");
        } else {
            System.out.println("DENIED");
        }
    }
}

Measured memory_bytes: 23636
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int k, x;
  cin >> k >> x;
  for (int i = x - (k - 1); i < x + k; i++) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
n, d=map(int, input().split())
x=[list(map(int, input().split())) for i in range(n)]

import numpy as np

res=0

for i in range(n-1):
	for j in range(i+1,n):
		dis=0
		for k in range(d):
			dis+=(x[i][k]-x[j][k])**2
		if np.sqrt(dis).is_integer():
			res+=1

print(res)

Measured memory_bytes: 12520