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

using namespace std;

using ll =  long long int;

#define int  long long int
#define mod  1000000007

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    
    cin >> n;
    
    int a[n];
    int b[n];
    
    for(int i = 0; i < n; ++i) {
    	cin >> a[i];
    }
    
    multiset<int> st , st1 , s;
    
    for(int i = 0; i < n; ++i) {
    	cin >> b[i];
    	
    	st.insert(b[i]);
    	st1.insert(b[i]);
    	s.insert(b[i]);
    }
    
    int ans1[n];
    int f = 0;
    
	for(int i = 0; i < n; ++i) {
		auto u = st.end();
		u--;
		
		auto v = st.begin();
		
		if((*u) != a[i]) {
			ans1[i] = (*u);
			st.erase(u);
		}
		else if((*v) != a[i]) {
			ans1[i] = (*v);
			st.erase(v);
		}
		else {
			f = 1;
			break;
		}
	}
    
    if(f == 0) {
    	cout << "Yes\n";
    
	    for(int i = 0; i < n; ++i) {
	    	cout << ans1[i] << " ";
	    }
	    
	    return 0;
    }
    else {
			f = 0;
			
			int ans3[n];
			
			for(int i = 0; i < n; ++i) {
				auto it=s.upper_bound(a[i]);
		        if(it!=s.end() && *it!=a[i]){
		            ans3[i]=*it;
		            s.erase(it);
		        }
		        else if(*(s.begin()) != a[i]){
		            ans3[i]=*(s.begin());
		            s.erase(s.begin());
		        }
		        else {
		        	cout << "No\n";
		        	return 0;
		        }
			}
			
			cout << "Yes\n";
    
		    for(int i = 0; i < n; ++i) {
		    	cout << ans3[i] << " ";
		    }
		    
		    return 0;
    }
    
    cout << "No\n";
  
    return 0;
}


Measured memory_bytes: 37952
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define VI vector<int>
#define VII vector<pair<int, int>>
#define PII pair<int, int>
#define MP make_pair
// #define log(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define log(fmt, ...)
// #define check(...) assert(##__VA_ARGS__)
#define check(...)

int c2i(char c) {
    if (c == 'R') {
        return 0;
    } else if (c == 'G') {
        return 1;
    } else {
        return 2;
    }
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    int a[n];
    rep(i, 0, n) {
        a[i] = c2i(s[i]);
    }

    int suf[3][n + 1];
    rep(i, 0, 3) {
        fill_n(suf[i], n + 1, 0);
        suf[i][n] = 0;
        repi(j, n - 1, 0) {
            suf[i][j] = suf[i][j + 1];
            if (a[j] == i) {
                suf[i][j]++;
            }
        }
        rep(j, 0, n) {
            log("%d ", suf[i][j]);
        }
        log("\n");
    }
    ll ans = 0;
    rep(i, 0, n) {
        rep(j, i + 1, n) {
            if (a[i] == a[j]) {
                continue;
            }
            int third = 3 - a[i] - a[j];
            ans += suf[third][j + 1];
            int bad_k = j + (j - i);
            if (bad_k >= n) {
                continue;
            }
            if (a[bad_k] == third) {
                ans--;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 3196
from collections import Counter

N = int(input())
A = [int(a) for a in input().split()]
 
check = {}
 
if N % 2 == 0:
    for i in range(1, N, 2):
        check[i] = 2
else:
    check[0] = 1
 
    for i in range(2, N, 2):
        check[i] = 2
 
if check == Counter(A):
    print((2 ** (N // 2)) % (10 ** 9 + 7))
else:
    print(0)

Measured memory_bytes: 18272
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int x=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    sc.close();

    long counter=0;
    for(int i=0;i<n-1;i++){
      if(a[i]+a[i+1]>x){
        counter+=(a[i]+a[i+1]-x);
        if(a[i]<=x){
          a[i+1]=x-a[i];
        }else{
          a[i]=x;
          a[i+1]=0;
        }
      }
    }
    System.out.println(counter);
  }
}

Measured memory_bytes: 52332
import java.io.*;
import java.util.*;
  
public class Main extends PrintWriter {
  Main() { super(System.out, true); }
  Scanner sc = new Scanner(System.in);
  public static void main(String[] $) {
    Main o = new Main(); o.main(); o.flush();
  }
  
  void main(){
    String S = sc.next();
    String T = sc.next();
    println(T+S);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
typedef long long LL;
//#define int long long

//booooooooooooost
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/


signed main() {

	int N, K;
	vector<char> D;
	cin >> N >> K;
	REP(i, K) {
		char tmp;
		cin >> tmp;
		D.PSB(tmp);
	}

	while (1) {
		int flag = true;
		string s = to_string(N);
		REP(i, K) {
			if (find(ALL(s), D[i]) != s.end()) {
				flag = false;
			}
		}
		if (flag) break;
		++N;
	}

	cout << N << endl;


	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int count0=0;
  int count1=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0'){
      count0++;
    }else{
      count1++;
    }
  }
  int ans=2*min(count0,count1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

double ro (double d){
	int minus = 0;
	if (d < 0){
		d *= -1;
		minus = 1;
	}
	d = ((double)(int)(1000*d + 0.5)) / 1000;
	if (minus) d *= -1;
	return d;
}

int main(void) {
	int a, b, c, d, e, f;
	while (scanf ("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF){
		printf ("%.3f %.3f\n", 
			ro (((double)c*e - f*b) / (a*e - d*b)), 
			ro (((double)a*f - d*c) / (a*e - d*b)));
	}
	return 0;
}

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

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

const int mod = 1e9+7;

void addM(ll &a, ll b){
    a = (a % mod + b % mod) % mod;
}

void mulM(ll &a, ll b){
    a = (a % mod * b % mod) % mod;
}


ll dp[41][1 << 17] = {};
int n, x, y, z;

bool chk(ll t) {
	if (!(t & (1 << (x - 1))))return true;
	if (!(t & (1 << (x + y - 1))))return true;
	if (!(t & (1 << (x + y + z - 1))))return true;
	return false;
}

int main() {
	cin >> n >> x >> y >> z; 
    
    dp[0][0] = 1;	
    int m = x + y + z;
	REP(i, n) { // i番目の数列
		REP(j, (1 << m)) {  // 直近の和が0~mまでを考慮すれば十分
			REP(k, 10) { // 値をkにする

                // 直近m文字までをみれば十分
				ll nex = ((j << (k + 1)) + (1 << k)) % (1 << m);
				
                if (chk(nex)) addM(dp[i + 1][nex], dp[i][j]);
			}
		}
	}

	ll sum = 0;
	REP(j, (1 << m)) addM(sum, dp[n][j]);

	ll all = 1;
	REP(i, n) mulM(all, 10);

	cout << (all - sum + mod) % mod << endl;

	return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int h,w;
    cin >> w >> h;
    if(w==0) return 0;
    vector<vector<int>> field(h,vector<int>(w));
    vector<vector<bool>> searched(h,vector<bool>(w,false));
    char c;
    int sx,sy;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> c;
        if(c=='.'){
          field[i][j]=0;
        }else if(c=='#'){
          field[i][j]=1;
        }else{
          sx=j;
          sy=i;
          field[i][j]=0;
        }
      }
    }
    searched[sy][sx]=true;
    queue<pair<int,int>> bfs;
    bfs.push({sx,sy});
    int nx,ny,houkou[5]={0,1,0,-1,0};
    int count=1;
    while(!bfs.empty()){
      pair<int,int> now=bfs.front();
      bfs.pop();
      for(int i=0;i<4;i++){
        nx=now.first+houkou[i];
        ny=now.second+houkou[i+1];
        if(0<=nx&&nx<w&&0<=ny&&ny<h){
          if(!searched[ny][nx]&&field[ny][nx]==0){
            searched[ny][nx]=true;
            bfs.push({nx,ny});
            count++;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}



Measured memory_bytes: 3172
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

const int N = 3005;
const int MOD = 998244353;

int n, s, res, a[N], zacz[N], kon[N], cnt1[2][N], cnt2[2][N], wtf[N];

void calc(int l, int r) {
  if (l > r)
    return;
  if (l == r) {
    if (a[l] == s)
      res = (res+(n+1-r)*r)%MOD;
    return;
  }
  int mid = (l+r)/2;
  calc(l, mid);
  calc(mid+1, r);
  for (int i = 0; i <= s; ++i)
    cnt1[0][i] = cnt1[1][i] = cnt2[0][i] = cnt2[1][i] = 0;
  cnt2[0][0] = 1;
  for (int i = 0; i <= s; ++i)
    wtf[i] = 0;
  for (int i = mid+1; i <= r; ++i) {
    for (int j = 0; j <= s; ++j)
      cnt2[1][j] = cnt2[0][j];
    for (int j = s; j-a[i] >= 0; --j)
      cnt2[1][j] = (cnt2[1][j]+cnt2[0][j-a[i]])%MOD;
    for (int j = 1; j < s; ++j) {
      int ile = ((cnt2[1][j]-cnt2[0][j])%MOD+MOD)%MOD;
      wtf[j] = (wtf[j]+ile*(n+1-i))%MOD;
    }
    for (int j = 0; j <= s; ++j)
      cnt2[0][j] = cnt2[1][j];
  }
  cnt1[0][0] = 1;
  for (int i = mid; i >= l; --i) {
    for (int j = 0; j <= s; ++j)
      cnt1[1][j] = cnt1[0][j];
    for (int j = s; j-a[i] >= 0; --j)
      cnt1[1][j] = (cnt1[1][j]+cnt1[0][j-a[i]])%MOD;
    for (int ls = 1; ls < s; ++ls) {
      int ile = ((cnt1[1][ls]-cnt1[0][ls])%MOD+MOD)%MOD;
      ile = (ile*(i+1-1))%MOD;
      res = (res+ile*wtf[s-ls])%MOD;
    }
    for (int j = 0; j <= s; ++j)
      cnt1[0][j] = cnt1[1][j];
  }
}

signed main() {
  init_ios();
  cin >> n >> s;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  calc(1, n);
  cout<<res<<"\n";
}

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

const long long mod = 1e9 + 7;

int main() {
    int h, w; cin >> h >> w;
    vector<string> a(h);
    for (int i=0; i<h; ++i) cin >> a[i];
    string checker1 = "";
    for (int i=0; i<w; ++i) checker1 += '.';
    vector<bool> wh(h), ww(w);
    for (int i=0; i<h; ++i) {
        if (a[i] == checker1) wh[i] = true;
    }
    string checker2 = "";
    for (int i=0; i<h; ++i) checker2 += '.';
    for (int i=0; i<w; ++i) {
        string t = "";
        for (int j=0; j<h; ++j) {
            t += a[j][i];
        }
        if (t == checker2) ww[i] = true;
    }
    for (int i=0; i<h; ++i) {
        if (wh[i]) continue;
        for (int j=0; j<w; ++j) {
            if (ww[j]) continue;
            cout << a[i][j];
        }
        cout << endl;
    }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x[100000],y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> n >> a >> b;
       rep(i,n){
           cin >> x[i];
       }
       rep(i,n-1){
           ans+=min(a*(x[i+1]-x[i]),b);
       }
       Cout(ans);
return 0;
}


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

int main(){
  const int denomi = 1000000000+7;
  long int power=1;
  //整数入力
  int n;
  cin >> n;
  
  //大きい順にかけないとオーバーフロー起こす可能性あり?
  for(int i=n; i>=1; i--){
    power*=i;
    power%=denomi;
  }
  
  cout << power << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

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

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;

int main() {
	char s;

	cin >> s;

	if (s == 'A')cout << 'T' ;
	else if (s == 'T')cout << 'A';
	else if (s == 'G')cout << 'C';
	else if (s == 'C')cout << 'G';

	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string.h>
#include <utility>
#include <queue>
#include <stack>
#include <iomanip>
#include <ctype.h>
#include <map>
#include <set>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <sstream>
#include <math.h>
#include <time.h>
#include <iostream>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <tuple>
#include <cmath>
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>
#include <fstream>

using namespace std;

typedef long long LL;

#define FOR(i,n) for(int i = 0;i < n;i++)
#define MP make_pair
#define PB push_back
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define CLEAR(a) memset(a, 0, sizeof(a))
#define ERASE(a) memset(a, -1, sizeof(a))
#define INF 2000000007LL
#define y1 uu1
#define y2 uu2
const double EPS = 1E-12;
const double PI = acos(-1.0);
const LL mod = 1000000007;

using namespace std;

int n, T, x, y;
int dp[3005];
vector<PII> z;
int a[3005];
int b[3005];
int ans = 0;

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin >> n >> T;
  FOR(i, n) {
    cin >> x >> y;
    z.push_back(MP(x, y));
  }
  sort(ALL(z));
  FOR(i, n) {
    a[i] = z[i].first;
    b[i] = z[i].second;
  }

  ERASE(dp);
  dp[0] = 0;

  FOR(i, n) {
    for (int j = T - 1; j >= 0; j--) {
      if (dp[j] != -1) {
        int nv = dp[j] + b[i];
        if (j + a[i] >= T) {
          ans = max(ans, nv);
        } else {
          dp[j + a[i]] = max(dp[j + a[i]], nv);
        }
      }
    }
  }
  FOR(i,T) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import sys

read = sys.stdin.buffer.read

n,*x = list(map(int, read().split()))
x_sort = sorted(x)

mean_left = x_sort[n//2-1]
mean_right = x_sort[n//2]


for i in range(n):
  if x[i] <= mean_left:
    print(mean_right)
  elif x[i] >= mean_right:
    print(mean_left)

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

int main() {
	// your code goes here
	int N, i, count = 1;
	string a;
	cin >> N;
	vector <string> items;
	for(i=0; i<N; i++){
		cin >> a;
		items.push_back(a);
	}
	sort(items.begin(), items.end());
	a = items[0];
	for(i=1; i<N; i++)
	{
		if(a != items[i])
			count++;
		a = items[i];
	}
	// for(i=0; i<N; i++){
	// 	cout << items[i] << endl;
	// }
	cout << count;
	
	return 0;
}

Measured memory_bytes: 11592
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int A, B;
    std::cin >> A >> B;
    if (A + B > 23) { std::cout << A + B - 24 << std::endl; }
    else
    {
        std::cout << A + B << std::endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

static const int N = 100;

void trace(int A[],int n){
  int i;
  for(i=1;i<=n;i++){
    if(i>1)
      printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}


int main(){
  int n,i,j,key;
  int A[N+1];
  scanf("%d",&n);

  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);

  trace(A,n);

  for(j=2;j<=n;j++){

    key=A[j];
    i=j-1;

    while(i>0 && A[i]>key){
      A[i+1]=A[i];
	i--;
    }
    A[i+1]=key;

    trace(A,n); 
  }
  
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))


int main(){
    int n;  cin >> n;
    string s;   cin >> s;
    int rc=0, lc=0;
    
    REP(i, n){
        if(s[i]=='('){
            rc += 1;
        }else if(s[i]==')'){
            if(0<rc){
                rc -= 1;
            }else{
                lc += 1;
            }
        }
    }
    
    REP(i, lc) cout << '(';
    cout << s;
    REP(i, rc) cout << ')';
    cout << endl;



}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S = list(map(int, str(input())))

T0 = sum([s%2 == 1 for s in S[::2]]) + sum([s%2 == 0 for s in S[1::2]])
T1 = sum([s%2 == 0 for s in S[::2]]) + sum([s%2 == 1 for s in S[1::2]])
print(min(T0, T1))

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

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

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

  int zn = -1;
  rep(i, N) {
    int cnt = 0;
    while ((a[i] & 1) == 0) {
      a[i] /= 2;
      cnt++;
    }
    if (zn == -1) zn = cnt;
    else if (zn != cnt) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long lcm = 1;
  rep(i, N) {
    lcm = lcm * a[i] / gcd(lcm, a[i]);
    if (lcm > M) {
      cout << 0 << endl;
      return 0;
    }
  }

  rep(i, zn) lcm *= 2;

  if (M - lcm / 2 < 0) {
    cout << 0 << endl;
    return 0;
  }
  else cout << (M + lcm / 2) / lcm << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
int cal(int n,int m,int a[]){
  int i,j;
  int max=0;
  for(i=1; i<=n; i++){
    for(j=i+1; j<=n; j++){
      if(a[i]+a[j]<=m && max<a[i]+a[j]){
	max=a[i]+a[j];
      }
    }
  }
  if(max!=0){
    return max;
  }else if(n!=0 &&m!=0){
    max=-1;
    return max;
  }else{
    max=0;
    return max;
  }
}
int main(void){
  int i,j=1,k;
  int b[1000];
  while(1){
    int n;//品物の個数
    scanf("%d",&n);
    int m;//金額
    scanf("%d",&m);
    int a[n];
    if(n!=0 && m!=0){
      for(i=1; i<=n; i++){
	scanf("%d",&a[i]);
      }
      b[j]=cal(n,m,a);
      j++;
    }else{
      break;
    }
  }
  for(k=1; k<=j; k++){
    if(b[k]==-1){
      printf("NONE\n");
    }else if(b[k]!=0){
      printf("%d\n",b[k]);
    }else{
      break;
    }
  }
  return 0;
}




Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<numeric>

#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

string str;

int main() {
	cin >> str;

	if (str.substr(0, 4) == "2017") {
		str[3] = '8';
	}

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 256
fun dist(p: Double, q: Double): Double = Math.abs(Math.pow(p-q, 2.0))

fun main(args: Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(" ").map(String::toDouble)
    println(Math.sqrt(dist(x1, x2) + dist(y1, y2)))
}


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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define mp 					make_pair
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz 					size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = (1<<30)-1+(1<<30);
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 2e3+5;
int tg, lb, q, sum[4][MAXN][MAXN];
bool area[MAXN][MAXN];
char inp[MAXN];

int valid (int y, int x) {
	if (y<1 || y>tg) return 0;
	if (x<1 || x>lb) return 0;
	return 1;
}

void create() {
	for (int i=1; i<=tg; i++)
		for (int j=1; j<=lb; j++) {
			for (int k=0; k<4; k++)
				sum[k][i][j] = sum[k][i-1][j] + sum[k][i][j-1] - sum[k][i-1][j-1];
			if (area[i][j]) {
				sum[0][i][j] += area[i][j];
				sum[1][i][j] += area[i][j+1];
				sum[2][i][j] += area[i+1][j];
				if (area[i][j+1] && area[i+1][j]) {
//					printf ("%d %d\n", i,j);
					sum[3][i][j]++;
				}
			}
		}
//	printf ("%d %d %d\n", sum[0][tg][lb], sum[1][tg][lb], sum[2][tg][lb]);
}

int get (int id, int ya, int xa, int yb, int xb) {
	if (ya>yb || xa>xb) return 0;
	return sum[id][yb][xb] - sum[id][ya-1][xb] - sum[id][yb][xa-1] + sum[id][ya-1][xa-1];
}

int main() {
	setnul(area); setnul(sum);
	gi(tg); gi(lb); gi(q);
	for (int i=0; i<tg; i++) {
		scanf("%s", inp);
		for (int j=0; j<lb; j++) 
			area[i+1][j+1] = inp[j]=='1';
	}
	create();
	while (q--) {
		int xa, ya, xb, yb;
		gi(ya); gi(xa); gi(yb); gi(xb);
	//	printf ("%d %d %d\n", get(0,ya,xa,yb,xb), get(1,ya,xa,yb,xb-1), get(2,ya,xa,yb-1,xb));
		int ans = get(0,ya,xa,yb,xb) - get(1,ya,xa,yb,xb-1) - get(2,ya,xa,yb-1,xb);
		printf ("%d\n",ans);
	}
	return 0;
}



Measured memory_bytes: 68480
import math
import numpy as np
from fractions import gcd
import fractions
import collections

N = int(input())
T = [0] * N
for i in range(N):
    T[i] = int(input())

ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.gcd(ans, T[i])
print(ans)

Measured memory_bytes: 13520
// AOJ 2251 Merry Christmas
// 2018.3.6 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 2002
short hi[MAX], to[MAX][MAX];
char  seen[MAX];
short matchL[MAX], matchR[MAX];

int bpm(int u)
{
	int i, v;

	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		if (seen[v]) continue;
		seen[v] = 1;
		if (matchR[v] < 0 || bpm(matchR[v])) {
			matchL[u] = v, matchR[v] = u;
			return 1;
		}
	}
	return 0;
}

#define INF 0x10101010
typedef struct { int p, t; } T;
T pt[1002];
int dist[102][102];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(T *a, T *b) { return a->t - b->t; }

int main()
{
	int N, M, L, u, v, d, k;

	while (N = in()) {
		M = in(), L = in();
		memset(dist, INF, sizeof(dist));
		for (k = 0; k < N; k++) dist[k][k] = 0;
		for (k = 0; k < M; k++) {
			u = in(), v = in(), d = in();
			dist[u][v] = dist[v][u] = d;
		}
		for (k = 0; k < N; k++) {
			for (u = 0; u < N; u++) if (dist[u][k] != INF) {
				for (v = 0; v < N; v++) if (dist[k][v] != INF) {
					d = dist[u][k] + dist[k][v];
					if (dist[u][v] > d) dist[u][v] = d;
				}
			}
		}

		for (k = 0; k < L; k++) pt[k].p = in(), pt[k].t = in();

		qsort(pt, L, sizeof(T), cmp);
		memset(hi, 0, sizeof(hi));
		for (u = 0; u < L; u++) for (v = 0; v < L; v++) if (u != v) {
			if (dist[pt[u].p][pt[v].p] <= pt[v].t-pt[u].t) to[u][hi[u]++] = v+L;
		}

	    memset(matchL, -1, L << 2);
	    memset(matchR, -1, L << 2);
		k = L;
		for (u = 0; u < L; u++) {
			memset(seen, 0, L << 1);
			if (bpm(u)) k--;
		}
		printf("%d\n", k);
	}
	return 0;
}


Measured memory_bytes: 5708
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 2007;
int cnt[2][N][N], pref[2][N][N], suff[2][N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        int x, y;
        char c;
        cin >> x >> y >> c;

        int dx = x/k;
        int dy = y/k;

        bool t = c == 'W';
        t ^= (dx&1);
        t ^= (dy&1);

        x %= k;
        y %= k;

        //cout << x << ' ' << y << ' ' << t << endl;

        ++cnt[t][x][y];
    }
    
    for (int t = 0; t < 2; ++t) {
        for (int i = 0; i < k; ++i) 
            for (int j = 0; j < k; ++j)
                pref[t][i+1][j+1] = pref[t][i+1][j] + pref[t][i][j+1] - pref[t][i][j] + cnt[t][i][j];

        for (int i = k - 1; i >= 0; --i)
            for (int j = k - 1; j >= 0; --j)
                suff[t][i][j] = suff[t][i+1][j] + suff[t][i][j+1] - suff[t][i+1][j+1] + cnt[t][i][j];
    }   

    int ans = 0;
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
            for (int t = 0; t < 2; ++t) {
                ans = max(ans, pref[t][i][j] + suff[t][i][j] + (pref[t^1][k][k] - pref[t^1][i][j] - suff[t^1][i][j]));
            }   
        }   
    }

    cout << ans << endl;
}

Measured memory_bytes: 73760
#include <cstdio>

/*
[p^N] N! exp(Np) = N^N

************
*********
ooooooo
******
****
***
**

N! [q^{L...R}] \sum_{k=0}^R ([p^{M-1}] exp(p(q^{k+1} + q^{k+2} + ... + q^R)) (exp(p q^k) - 1)/p) ([p^{N-M}] exp(p (1 + q + q^2 + ... + q^{k-1})))
N! [q^{L...R}] \sum_{k=0}^R ([p^{M}] exp(pq^{k}/(1-q)) - exp(pq^{k+1}/(1-q))) ([p^{N-M}] exp(p (1-q^k) / (1-q)))
N! [q^{L...R}] \sum_{k=0}^R ((q^k/(1-q))^M - (q^{k+1}/(1-q))^M) / M! ((1-q^k) / (1-q))^{N-M} / (N-M)!
\binom{N}{M} [q^{L...R}] 1/(1-q)^N \sum_{k=0}^R (q^{kM} - q^{(k+1)M}) (1-q^k)^{N-M}
\binom{N}{M} [q^R] (1-q^{R-L+1})/(1-q) 1/(1-q)^N \sum_{k=0}^R (q^{kM} - q^{(k+1)M}) (1-q^k)^{N-M}
\binom{N}{M} [q^R] (1-q^{R-L+1}) 1/(1-q)^{N+1} \sum_{k=0}^R q^{kM)} (1- q^M) (1-q^k)^{N-M}
\binom{N}{M} [q^R] (1-q^{R-L+1}) (1-q^M)/(1-q)^{N+1} \sum_{k=0}^R q^{kM} (1-q^k)^{N-M}

N! [q^{L...R}] [p^N] exp(p (1 + q + q^2 + ... + q^R))
N! [q^{L...R}] 1/(1-q)^N / N!
[q^R] (1-q^{R-L+1})/(1-q) 1/(1-q)^N
[q^R] (1-q^{R-L+1}) 1/(1-q)^{N+1}
\binom{N+R}{R} - \binom{N+L-1}{L-1}
*/

constexpr int mod = 1000000007;
constexpr int MAX = 600000;
int fact[MAX+1];
int ifact[MAX+1];
long long int dp[MAX+1];

int pow(int x, int n){
  int r = 1;
  for(; n; n >>= 1){
    if(n&1) r = (long long) r * x % mod;
    x = (long long) x * x % mod;
  }
  return r;
}

int binom(int n, int k){
  return (long long) fact[n] * ifact[k] % mod * ifact[n-k] % mod;
}

int n, m, l, r;

int main(){
  fact[0] = 1;
  for(int i = 1; i <= MAX; i++) fact[i] = (long long) i * fact[i-1] % mod;
  ifact[MAX] = pow(fact[MAX], mod-2);
  for(int i = MAX-1; i >= 0; i--) ifact[i] = (long long) (i+1) * ifact[i+1] % mod;

  scanf("%d%d%d%d", &n, &m, &l, &r);

  for(int i = m; i <= r; i++){
    int tmp = (long long) ifact[i-m] * ifact[n-i] % mod;
    if((i-m)&1) tmp = mod-tmp;
    for(int j = 1; j * i <= r; j++){
      dp[j*i] += tmp;
    }
  }
  for(int i = r; i >= r-l+1; i--) dp[i] -= dp[i - (r-l+1)];
  for(int i = r; i >= m; i--) (dp[i] -= dp[i - m]) %= mod;
 
  int ans = 0;
  for(int i = 0; i <= r; i++){
    ans = (ans + (long long) dp[r - i] * fact[n+i] % mod * ifact[i]) % mod;
  }
  ans = (long long) ans * ifact[m] % mod;

  ans = binom(n + r, r) - ans;
  if(ans < 0) ans += mod;
  ans = ans - binom(n + l - 1, l - 1);
  if(ans < 0) ans += mod;
  if(ans < 0) ans += mod;
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 9472
def nyu():
    X= int(input())
    return X


def check(X ):
    sum = 0

    x = X

    sum = int(x / 500) * 1000 
    x = x % 500
 #   print("sum ",sum,"X",x)
    sum += int(x/5)*5
    print(sum)


            
X = nyu()
check(X)
#print(S)



Measured memory_bytes: 2940
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
mi = 0
zero = 0
for a in A:
  if a<0:
    mi+=1
  elif a==0:
    zero+=1
  else:
    break

plu = N-mi-zero
A_mi = A[0:mi:]
A_mi_rev = A_mi[::-1]
A_plu = A[mi+zero::]
A_plu_rev = A_plu[::-1]
num_mi = plu*mi
num_zero = (plu+mi)*zero+(zero*(zero-1))//2
r = max(A[-1]**2+10,A[0]**2+10)
l = A[0]*A[-1]-10
while l+1!=r:
  m = (l+r)//2
  num = 0
  if m>0:
    num+=num_mi+num_zero
    if num>=K:
      r=m
      continue
    cou=0
    for i in range(0,plu):
      while True:
        if cou>=plu-i-1:
          num+=plu-i-1
          break
        x = A_plu_rev[i]*A_plu[cou]
        if x<m:
          cou+=1
        else:
          num+=cou
          break
          
      if num>=K:
        break
    if num>=K:
      r=m
      continue
    cou = 0
    for i in range(0,mi):
      while True:
        if cou>=mi-i-1:
          num+=mi-i-1
          break
        x = A_mi[i]*A_mi_rev[cou]
        if x<m:
          cou+=1
        else:
          num+=cou
          break
          
      if num>=K:
        break

    if num>=K:
      r=m
    else:
      l=m
    
  elif m==0:
    num+=num_mi
    if num>=K:
      r=m
    else:
      l=m
  else:
    cou = 0
    for a in A_mi_rev:
      while True:
        if cou==plu:
          num+=cou
          break
        x = a*A_plu_rev[cou]
        if x<m:
          cou+=1
        else:
          num+=cou
          break
          
      if num>=K:
        break
    if num>=K:
      r = m
    else:
      l = m
      
print(l)

Measured memory_bytes: 90964
// http://kmjp.hatenablog.jp/entry/2018/03/20/0900

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted

int main(){

	ll N,ans=0;
	cin >> N;
	vector<ll> A(N),B(N),C(N);
	FOR(i,0,N)cin>>A[i];
	FOR(i,0,N)cin>>B[i];
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());

	FOR(i,0,29){
		FOR(x,0,N)C[x] = B[x]%(1<<(i+1));
		sort(C.begin(),C.end());
		ll tot = 0;
		FOR(x,0,N){
			ll y = A[x]%(1<<(i+1));
			tot += POSL(C,(1<<(i+1))-y)-POSL(C,(1<<(i))-y);
			tot += POSL(C,(1<<(i+2))-y)-POSL(C,3*(1<<(i))-y);
		}
		if(tot%2) ans += 1<<i;
	}
	cout << ans << endl;

}

Measured memory_bytes: 4992
#include<stdio.h>

int MAX = 501,FUGE=10000;
int SIZE=(1<<30);//１の３０乗

int main(){

  int n, i, j, num, sum, A[MAX][MAX], x, y, min, d[MAX], p[MAX], s[MAX];

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){

    for ( j = 0; j < n; j++ ){

      scanf("%d", &num);

      A[i][j] = num;

      if(num ==-1) A[i][j] = FUGE;//もしー１なら敢えて大きな数字とみなす  
    }
  }

  for ( i = 0; i < n; i++ ) {

    d[i] = SIZE;
    p[i] = -1;
    s[i] = 0;

  }
  d[0] = 0;

  while(1){

    min = MAX;
    x = -1;

    for ( i = 0; i < n; i++ )
      {
	if ( min > d[i] && ! s[i] )
	  {
	    x = i;
	    min = d[i];
	  }
      }

    if ( x == -1 ) break;

    s[x] = 1;


    for ( y = 0; y < n; y++ )
      {
	if ( !s[y] && A[x][y] != MAX )
	  {
	    if ( d[y] > A[x][y] )
	      {
		d[y] =  A[x][y];
		p[y] = x;
	      }
	  }
      }
  }

  sum = 0;

  for ( i = 0; i < n; i++ )
    {
      if ( p[i] != -1 ) sum += A[i][p[i]];
    }

  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 804
#include<iostream>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
int main() {
	int x, a;
	cin >> x >> a;
	if (x < a)cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;


int main(){
  string s; cin>>s;
  int n=s.size();
  int count=0;

  int i=1;
  while(i<s.size()){
    if(i==0||s[i]==s[i-1])i++;
    else{
      //cout<<i<<':'<<s.substr(0,i-1)<<'+'<<s.substr(i+1)<<endl;
      s=s.substr(0,i-1)+s.substr(i+1);
      count+=2;
      i--;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 724
import sys
input=sys.stdin.readline
n,t=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=t
for i in range(1,n):
  if a[i]-a[i-1]<t:
    ans+=a[i]-a[i-1]
  else:
    ans+=t
print(ans)

Measured memory_bytes: 30944
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String w = scan.next();
		int l = w.length();
		String message = "No";
		if(l % 2 == 0) {
			List<String> list = new ArrayList<String>();
			for(int i = 0; i < l; i++) {
				list.add(w.charAt(i) + "");
			}
			for(;(l - list.size()) % 2 == 0 && list.size() != 0;) {
				List<String> set = new ArrayList<>();
				Collections.addAll(set, list.get(0));
				list.removeAll(set);
			}
			if(list.size() == 0) {
				message = "Yes";
			}
		}
		System.out.println(message);
	}
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}


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

int main(){
  string s;cin>>s;
  stack<int> st;
  int sum=0;
  rep(i,s.size()){
    if(st.empty())st.push(s[i]);
    else if(st.top()!=s[i])sum++,st.pop();
    else st.push(s[i]);
  }
  cout<<sum*2<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  int sum=x-a;
  while(sum>0){
    sum-=b;
  }
  if(sum<0){
    sum+=b;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
H,W = map(int, input().split())
a = []
for h in range(H):
  a.append(list(map(int, input().split())))
ans = []
for h in range(H):
  for w in range(W-1):
    if a[h][w]&1:
      a[h][w  ] -= 1
      a[h][w+1] += 1
      ans.append([h+1,w+1,h+1,w+2])
for h in range(H-1):
  if a[h][W-1]&1:
    a[h  ][W-1] -= 1
    a[h+1][W-1] += 1
    ans.append([h+1,W,h+2,W])
print(len(ans))
for s in ans:
  print("{} {} {} {}".format(*s))


Measured memory_bytes: 29864
/*
        ####   ####
     ###    ###    ###
   ###    Bravery    ###
  ###  Determination  ###
   ##  Perseverance   ##
    ##   Integrity   ##
     ##  Patience   ##
      ## Kindness  ##
        ##Justice##
         ##     ##
           ## ##
             #
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int h1,m1,h2,m2,t;
int main(){
	cin>>h1>>m1>>h2>>m2>>t;
	cout<<(h2-h1)*60+(m2-m1)-t<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<sstream>

using namespace std;

string binary[] = {"0000","0001","0010","0011","0100","0101","0110","0111","1000",
		   "1001","1010","1011","1100","1101","1110","1111"};
string ss = "0123456789abcdef";

string toB(char c){
  for(int i = 0; i < ss.length(); i++){
    if(ss[i] == c) return binary[i];
  }
  return "error";
}

string make(string s){
  string ret = "";

  for(int i = 0; i < s.length(); i++){
    ret += toB(s[i]);
  }
  return ret;
}

string toInt(string s){
  int ans = 0;
  int base = 1;
  
  for(int i = s.length()-1; i >= 0; i--){
    if(s[i] == '1') ans+=base;
    base*=2;
  }
  ostringstream oss;
  oss << ans;
  return oss.str();
}

string toDou(string s){

  double tmp = 0;
  double base = 0.5;

  for(int i = 0; i < s.length(); i++){
     if(s[i] == '1') tmp+=base;
     base/=2;
  }
  
  string anss = "";

  if(tmp == 0) return "0";

  
  while(tmp){
    tmp *= 10;
    int now = (int)tmp;
    anss += ((int)tmp)+'0';
    tmp -= now;
  }
  
  return anss;
}

void solve(string s){
  char sign = s[0];
  string integer = s.substr(1,24);
  string decimal = s.substr(25);
 
  if(sign == '1') cout << "-";
  cout << toInt(integer) << "." << toDou(decimal) << endl;
}

int main(){

  int T;
  cin >> T;
  while(T--){
    string in;
    cin >> in;
    string s = make(in);
    solve(s);
  }
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    int N;
    cin >> N;
    vector<int> BplusA(N);
    vector<int> BminusA(N);
    rep(i,N) {
        int A;
        cin >> A;
        BplusA.at(i) = A + i + 1;
        BminusA.at(i) = -(A - i - 1);
    }
    SORT(BplusA);
    SORT(BminusA);
    ll ans = 0;
    rep(i,N) {
        auto low = lower_bound(BminusA.begin(), BminusA.end(), BplusA.at(i));
        auto up = upper_bound(BminusA.begin(), BminusA.end(), BplusA.at(i));
        ans += up-low;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4840
#include <stdio.h>
int main(){
    int n,m,l;
    int i,j,k;
    scanf("%d%d%d",&n,&m,&l);
    int a[100][100]={};//a[n-1][m-1]
    int b[100][100]={};//b[m-1][l-1]
    long long c[100][100]={};//c[n-1][l-1]
    
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            scanf("%d",&a[i][j]);
    
    for(i=0;i<m;i++)
        for(j=0;j<l;j++)
            scanf("%d",&b[i][j]);
    //c[n][l]  c[i][j]=a[i][k]*b[k][j] i (0~n-1) j (0~l-1) k(0~m-1)
    for(i=0;i<n;i++)
        for(j=0;j<l;j++)
            for(k=0;k<m;k++)
                c[i][j]+=a[i][k]*b[k][j];
    
    for(i=0;i<n;i++){
        printf("%ld",c[i][0]);
        for(j=1;j<l;j++)
            printf(" %ld",c[i][j]);
        printf("\n");
    }
}



Measured memory_bytes: 2124
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
//#define ll __int64
#define ll long long
#define P pair<ll,ll>
 
ll a,b;

int main(){
	cin>>a>>b;
	if(abs(a-b)<=1)cout<<"Brown"<<endl;
	else cout<<"Alice"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define MAXN 205
int c[MAXN];
int main(){__
	int x,n;
	cin >> x >> n;
	int mit = 101;
	for(int i=0; i <n; i++){
		int a;
		cin >>a;
		int dif = a - x;
		c[mit+dif] = 1;
	}
	if(!c[mit]){
		cout << x << endl;
		return 0;
	}

	int l = mit,r = mit;
	while(true){
		l--;
		if(c[l] == 0){
			int dif = l - mit;
			int num = x + dif;
			cout << num << endl;
			return 0;
		}
		r++;
		if(c[r] == 0){
			int dif = r-mit;
			int num = x+dif;
			cout << num << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

template <typename T>
struct towdimBIT
{
private:
	vector< vector<T> > array;
	const int n;
	const int m;
 
public:
	towdimBIT(int _n,int _m):
		array(_n+1,vector<T>(_m+1,0)), n(_n),m(_m){}
 
	// (1,1) ~ (x,y) ruisekiwa
	T sum(int x,int y) {
		T s = 0;
		for(int i=x;i>0;i-=i&(-i))
			for(int j=y;j>0;j-=j&(-j))
				s += array[i][j];
		return s;
	}

	// [(x1,y1),(x2,y2)] no souwa
	T sum(int x1,int y1,int x2,int y2){
		return sum(x2,y2) - sum(x1-1,y2) - sum(x2,y1-1) + sum(x1-1,y1-1);
	}
 
	void add(int x,int y,T k) {
		for(int i=x;i<=n;i+=i&(-i))
			for(int j=y;j<=m;j+=j&(-j))
				array[i][j] += k;
	}
};
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m,q;
	cin>>n>>m>>q;
	towdimBIT<int> J(n,m),I(n,m),O(n,m);

	FOR(i,0,n){
		string s;
		cin>>s;
		FOR(j,0,m){
			char x;
			x = s[j];
			if(x=='J')J.add(i+1,j+1,1);
			if(x=='I')I.add(i+1,j+1,1);
			if(x=='O')O.add(i+1,j+1,1);
		}
	}

	FOR(i,0,q){
		ll x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		cout<<J.sum(x1,y1,x2,y2)<<" ";
		cout<<O.sum(x1,y1,x2,y2)<<" ";
		cout<<I.sum(x1,y1,x2,y2)<<endl;
	}
}


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

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    for (auto& e : v) cin >> e;

    sort(rbegin(v), rend(v));
    for (int i = 0; i + 1 < n; i++) {
        for (int j = i; j < n; j++) {
            v[j] /= 2;
        }
    }

    cout << accumulate(begin(v), end(v), .0) << endl;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
c=[list(map(int, input().split())) for _ in range(10)]
A=[list(map(int, input().split())) for _ in range(h)]
o=[c[i][1] for i in range(10)]#初期状態として各iから直接1にいく場合の魔力を入れる
#print(c)
ans=0
#print(o)
for _ in range(10):#o[i],o[j]は更新されていくので、最低10回は回す（最長移動距離が10のため）
    for i in range(10):
        for j in range(10):
            o[i]=min(o[i],c[i][j]+o[j])#例えば4から1に行く場合、直接行くと9かかるが、4→9→1といくと4で済む。
    #print(o)
    
for s in range(h):
    for t in range(w):
        if A[s][t]!=-1:
            ans+=o[A[s][t]]
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, c = 0, B;
  cin >> N;
  vector<ll> A(N + 1);

  for (ll i = 0; i <= N; i++) {
    cin >> A[i];
  }
  for (ll i = 0; i < N; i++) {
    cin >> B;
    if (A[i] >= B) {
      c += B;
    } else {
      B -= A[i];
      c += A[i];
      if (A[i + 1] >= B) {
        c += B;
        A[i + 1] -= B;
      } else {
        c += A[i + 1];
        A[i + 1] = 0;
      }
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long double a,b;
	cin>>a>>b;
	cout<<(ll)(a*b);
	
	return 0;
}

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

int main() {
  int N, X, M=100000000, S=0; cin >> N >> X;
  for (int i=0; i<N; i++) {
    int m; cin >> m;
    S += m;
    if (M>m) M=m;
  }
  cout << N+(X-S)/M << endl;
}

Measured memory_bytes: 256
S = input()
l = len(S)
if l == 2:
    if S[0] == S[1]:
        print(1, 2)
        quit()
    else:
        print(-1, -1)
        quit()
else:
    for i in range(l-2):
        if S[i] == S[i+1]:
            print(i+1, i+2)
            quit()
        elif S[i+1] == S[i+2]:
            print(i+2, i+3)
            quit()
        elif S[i] == S[i+2]:
            print(i+1, i+3)
            quit()

print(-1, -1)

Measured memory_bytes: 3188