akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, m, n) for(ll i = (ll)m; i < (ll)n; i++)
#define PER(i, m, n) for(ll i = (ll)m; i > (ll)n; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{	
    ll n;
    cin >> n;
    vector<ll> v(n);
    REP(i, 0, n) cin >> v[i];
    ll ans = 0;

    if(n >= 3){
        REP(i, 0, n-2){
            REP(j, i+1, n-1){
                REP(k, j+1, n){
                    //cout << v[i] << " " << v[j] << " " << v[k] << endl;
                    if(v[i] != v[j] && v[j] != v[k] && v[k] != v[i] && v[i] < v[j]+v[k] && v[j] < v[k]+v[i] && v[k] < v[j]+v[i]) ans++;
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>

void selectionSort(int);

int main(){
  int n;

  scanf("%d",&n);

  selectionSort(n);

  return 0;
}

void selectionSort(int n){
  int A[n], i, j, minj, v, count = 0;

  for(i = 0; i < n; i++)
    scanf("%d",&A[i]);
  
  for(i = 0; i <= n - 1; i++){
    minj = i;
    for(j = i; j <= n - 1; j++){
      if(A[j] < A[minj])
	minj = j;
    }
    
    v = A[i];
    A[i] = A[minj];
    A[minj] = v;
    if(A[i] != A[minj]){
      count++;
    }
  }
  for(i = 0; i < n; i++){
    printf("%d",A[i]);
    if(i != n - 1)
      printf(" ");
  }
  printf("\n%d\n",count);
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_N 10000
using namespace std;
int n;
int d[MAX_N];

struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {}
};
typedef pair<int, int> P;
vector<edge> G[MAX_N];

void Dijkstra(int start) {
	fill(d, d + n, INF);
	priority_queue<P, vector<P>, greater<P>> que;
	d[start] = 0;
	que.push(P(0, start));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 0, u, k; i < n; i++) {
		cin >> u >> k;
		for (int j = 0, v, c; j < k; j++) {
			cin >> v >> c;
			G[u].push_back(edge(v, c));
		}
	}
	Dijkstra(0);
	for (int i = 0; i < n; i++) {
		cout << i << ' ' << d[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 8048
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String base = sc.next();
            switch(base) {
              case "A":
                System.out.println("T");
                break;
              case "C":
                System.out.println("G");
                break;
              case "G":
                System.out.println("C");
                break;
              case "T":
                System.out.println("A");
                break;
            }
      }
}

Measured memory_bytes: 23124
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	//a copies of b and b copies of a
	int c;
	int d;
	int bb=b;
	int aa=a;
	int i=0;
	if(a>b){
    	while(a--){
    	    int k=pow(10,i);
    	    b=b*k;
    	    c+=b;
    	    i++;
    	    b=bb;
    	    
    	}
    	cout<<c<<endl;
	}
	else{
    	int j=0;
    	while(b--){
    	    int k=pow(10,j);
    	    a=a*k;
    	    d+=a;
    	    j++;
    	    a=aa;
    	}
    	cout<<d<<endl;
	}
// 	if(c>d){
// 	    cout<<d<<endl;
// 	}
// 	else{
// 	    cout<<c<<endl;
// 	}
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 105;
int L[N];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> L[i];

	int res = 0;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = i + 1; j <= n; ++j)
		{
			for (int k = j + 1; k <= n; ++k)
			{
				if (L[i] != L[j] && L[j] != L[k] && L[i] != L[k] && (L[i] + L[j]) > L[k] && abs(L[i] - L[j]) < L[k])
				{
					++res;
				}
			}
		}
	}

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


	return 0;
}

Measured memory_bytes: 3776
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Word
import qualified Data.ByteString as BSW
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST
--import qualified Data.Vector.Unboxed as U
--import qualified Data.Vector.Unboxed.Mutable as UM

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
lcsTable2 :: BS.ByteString -> BS.ByteString -> UArray (Int,Int) Word16
lcsTable2 s t = runSTUArray $ do
  let !m = BS.length s
      !n = BS.length t
      !n' = n+1
  arr <- newArray ((0,0),(m,n)) 0
  forM_ [m-1,m-2..0] $ \ !i -> do
    let !x = BSW.index s i
        loopY !j !v
          -- v = readArray arr (i,j+1)
          | j < 0 = return ()
          | otherwise = do
              let !y = BSW.index t j
              if x == y
                then do l2 <- readArray arr (i+1,j+1)
                        let !l = l2 + 1
                        writeArray arr (i,j) l
                        loopY (j-1) l
                else do l0 <- readArray arr (i+1,j)
                        let !l = max l0 v
                        writeArray arr (i,j) l
                        loopY (j-1) l
    loopY (n-1) 0
  return arr

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTable2 s t
      !m = BS.length s
      !n = BS.length t
      !n' = n+1
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | table ! (i+1,j) >= table ! (i,j+1) = recon (i+1) j
                  | otherwise = recon i (j+1)
        where x = BSW.index s i
              y = BSW.index t j
      (result, _) = BSW.unfoldrN (fromIntegral $ table ! (0,0)) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


Measured memory_bytes: 19324
D = int(input())
c = list(map(int, input().split()))
last = [0] * 26
ans = []
for d in range(1, D+1):
    s = list(map(int, input().split()))
    maxs = float('-inf')
    maxi = -1
    cumsump = 0
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        cumsump += tmp
    for i in range(26):
        tmp = -c[i] * (d - last[i])
        tmp2 = s[i] + cumsump - tmp
        if tmp2 > maxs:
            maxs = tmp2
            maxi = i
    ans += [maxi+1]
    last[maxi] = d
        
for a in ans:
    print(a)        

    



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



int main() {
  int n,x;

  int ans = 1;

  cin >> n >> x;

  vector<int> l(n);

  rep(i,n){
    cin >> l.at(i);
  }
  int total = 0;

  rep(i,n){
    total += l.at(i);
    if(total<=x){
      // cout << total << endl;
      ans ++;

    }
  }

  cout << ans;


}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int main(){
  int a[5],key;
  rep(i,5){
    cin >> a[i];
  }
  cin >> key;
  bool flag = true;
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      if(abs(a[i]-a[j])>key){
        flag = false;
        break;
      }
    }
  }

  if(flag) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char S[4];	
	scanf("%s",S); 
	int x = 0;
	for(int i = 0; i<3; i++)
	{
		if(S[i] == S[i+1]){
			x = 1;
		}
	} 
	if(x == 1){
		printf("Bad");
	}
	else{
		printf("Good");
	}
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,a,x=INT_MAX;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a;
        int z = 0;
        while(a%2 == 0){
            a = a/2;
            z++;
        }
        
        x = min(x, z);        
                
    }
    
    cout<< x <<endl;
}


Measured memory_bytes: 3508
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll bc = b / c;
	ll bd = b / d;
	ll cd = lcm(c, d);
	ll bcd = b / cd;

	ll ac = a / c;
	ll ad = a / d;
	ll acd = a / cd;
	
	if (a % c != 0 && a % d != 0 && a % cd != 0) {
		cout << ((b - ((bc + bd) - bcd)) - (a - ((ac + ad) - acd)))+1 << endl;
	}
	else {
		cout << ((b - ((bc + bd) - bcd)) - (a - ((ac + ad) - acd)))<< endl;
	}
	return 0;

	
}

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

int main() {
  int n, c, k; cin >> n >> c >> k;
  int a[n]; 
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a+n);
  int ran = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[ran] + k< a[i]||i-ran+1>c) {
      ran = i;
      cnt++;
    }
  }
  cout << cnt+1 << endl;
  return 0;
}



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

using namespace std;

int main(){
    
    int n, t;
    vector<int> v;

    cin >> n >> t;

    for(int i = 0; i < n; i++){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        if(tmp2 <= t){
            v.emplace_back(tmp1);
        }
    }

    if(min_element(v.begin(), v.end()) == v.end()){
        cout << "TLE" << endl;
    }else{
        cout << *min_element(v.begin(), v.end()) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
n,m = gets.chomp.split(' ').map(&:to_i)
x = gets.chomp.split(' ').map(&:to_i).sort
if (n >= m)
  puts '0'
  exit
end
  
distances = []
for i in 1...m do
  distances << x[i] - x[i-1]
end

puts distances.sort.reverse[(n-1)..-1].inject(:+)

Measured memory_bytes: 11888
#include <iostream>
#include <vector>
using namespace std;
int AINT[800005];
int dp[200005];
void build(int nod,int st,int dr)
{
    if(st==dr)
    {
        AINT[nod]=dp[st];
        return ;
    }
    int mid=(st+dr)/2;
    build(nod*2,st,mid);
    build(nod*2+1,mid+1,dr);
    AINT[nod]=min(AINT[2*nod],AINT[2*nod+1]);
}
void u(int nod,int st,int dr,int pos,int val)
{
    if(dr<pos||st>pos)return ;
    if(st==dr){AINT[nod]=val;return ;}
    int mid=(st+dr)/2;
    u(nod*2,st,mid,pos,val);
    u(nod*2+1,mid+1,dr,pos,val);
    AINT[nod]=min(AINT[2*nod],AINT[2*nod+1]);
}
int q(int nod,int st,int dr,int S,int D)
{
    if(dr<S||st>D)return 1<<30;
    if(S<=st&&dr<=D)return AINT[nod];
    int mid=(st+dr)/2;
    return min(q(nod*2,st,mid,S,D),q(nod*2+1,mid+1,dr,S,D));
}
int N,Q;
vector<int> V[200005];
int B[200005],rez;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
        {cin>>B[i];rez+=!B[i];}
    cin>>Q;
    for(int i=1;i<=Q;i++)
    {
        int x,y;
        cin>>x>>y;
        V[x].push_back(y);
    }
    for(int i=1;i<=N+1;i++)dp[i]=1<<30;
    build(1,0,N+1);
    for(int i=0;i<N;i++)
    {
        vector<int> updates;
        for(auto it:V[i+1])
        {
            dp[it+1]=min(dp[it+1],q(1,0,N+1,i,it+1));
            updates.push_back(it+1);
        }
        dp[i+1]=min(dp[i],dp[i+1])+(B[i+1] ? 1:-1);///indiferent de ce o ales ceilalti,ei nu o luat in seama costul pozitiei i+1,asta facem noi aici
        updates.push_back(i+1);
        dp[i]=1<<30;updates.push_back(i);
        for(auto it:updates)
            u(1,0,N+1,it,dp[it]);
    }
    rez+=min(dp[N+1],dp[N]);
    cout<<rez;
    return 0;
}


Measured memory_bytes: 12544
#include<bits/stdc++.h>
using namespace std;
#define upd(x,y) x=(x+y>=mod?x+y-mod:x+y)
const int N=305;
int n,m,dp[N][N][N],mod;
int main()
{
	scanf("%d%d%d",&n,&m,&mod);
	dp[0][1][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=i;k>=0;k--)
			{
				if(k) upd(dp[i][j][k-1],dp[i][j][k]);
				else upd(dp[i][j+1][i],dp[i][j][k]);
				upd(dp[i+1][j][k],1ll*dp[i][j][k]*(k+1)%mod);
			}
		}
	}
	printf("%d\n",dp[n][m][0]);
	return 0;
}

Measured memory_bytes: 113072
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> Int
solve n = length [x | x <- list 9, x <= n]

mklist 0 = [""]
mklist n = concat [['3':x, '5':x, '7':x] | x <- mklist (n-1)]

iMklist :: Int -> [Int]
iMklist n = [read x | x <- mklist n, elem '3' x, elem '5' x, elem '7' x]

list n = concat [iMklist k | k <- [1..n]]

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
  in solve n

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll i,j,k,n,pref=0,ans=0,c=0,c1=1;

    string number;
    cin>>number;
    //cin>>k;
  k=2019;
    unordered_map<ll,ll>ump;
    ump[c]++;
    for(i=number.length()-1;i>=0;i--)
    {
        c=c+(number[i]-'0')*c1;
        c%=k;
        c1=(c1*10)%k;
        ump[c]++;
    }
    for(i=0;i<=k-1;i++)
    {

        ans+=(ump[i]*(ump[i]-1))/2;
    }
    cout<<ans;


return 0;
}


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

using namespace std;

typedef long long int ll;

const ll MAXN = 1e5 + 5;
const ll mod = 1e9 + 7;

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

  ll n, m;
  cin >> n >> m;
  vector < ll > a(n + 1), b(m + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= m; i++) cin >> b[i];

  ll dp[n + 2][m + 2];
  for(int j = 0; j < m + 2; j++) dp[n + 1][j] = 0;
  for(int i = 0; i < n + 2; i++) dp[i][m + 1] = 0;

  for(int i = n; i > 0; i--){
    for(int j = m; j > 0; j--){
      if(a[i] == b[j]){
        dp[i][j] = 1 + dp[i + 1][j] + dp[i][j + 1];
      }
      else{
        dp[i][j] = dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1];
      }
      dp[i][j] = (dp[i][j] + mod) % mod;
      //cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
    }
  }

  cout << (dp[1][1] + 1) % mod << endl;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}

void solve()
{
  //code begins from here//
  ll n,w;
  cin>>n>>w;
  vector <ll> dp(100001,I2);
  dp[0]=0;
  pll a[n];
  lop(i,n) cin>>a[i].S>>a[i].F;
  sort(a,a+n);
  lop(i,n)
  {
      for(ll j=100000;j>0;j--)
      {
          if(j-a[i].F>=0 && dp[j-a[i].F]!=I2) minn(dp[j],dp[j-a[i].F]+a[i].S);
      }
  }
  for(ll i=100000;i>0;i--)
  {
      if(dp[i]<=w)
      {
          cout<<i<<endl;return;
      }
  }
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
   // cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 3992
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

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

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


int main(){
	vector<ll> a(100001,0);
	ll n,q,ans=0;
	cin >> n;
	for(ll i=0;i<n;i++){
		ll tmp;
		cin >> tmp;
		a[tmp]++;
		ans+=tmp;
	}
	cin >> q;
	for(ll i=0;i<q;i++){
		ll b,c,tmp;
		cin >> b >> c;
		tmp = a[b];
		a[b]=0;
		a[c]+=tmp;
		ans+=(c-b)*tmp;
		cout << ans<<endl;
	}
}

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

int main(){
  long long int S; cin >>S;
  unsigned long long int X1=0, Y1=0, X2=1e9, Y2, X3=1, Y3;

  if(S>1e9) Y3 = S/X2 + 1;
  else Y3 = 1;

  if(S == 1e18) Y3 = 1e9;
  Y2 = X2*Y3 - S;

  cout << X1 << ' ' << Y1 << ' ' << X2 << ' ' << Y2 << ' ' << X3 << ' ' << Y3 << ' ' << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      double N = nextDouble();
      if(N % 2 == 1){
        myout((Math.floor(N / 2) + 1) / N);
      }else{
        myout(0.5);
      }
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33388
S=raw_input()

M=10**9+7

all=1
abc=0
ab=0
a=0

for x in S:
	if x=="A":
		a+=all
	if x=="B":
		ab+=a
	if x=="C":
		abc+=ab

	if x=="?":
		abc=abc*3+ab
		ab=ab*3+a
		a= a*3+all
		all*=3

	abc%=M
	ab%=M
	a%=M
	all%=M


print abc%M


Measured memory_bytes: 32492
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}

mint dp[100005][15];

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

  rep(i,S.size()){
    rep(j,13){
      if(S[i] == '?'){
        rep(k,10){
          if(i-1 >= 0){
            dp[i][(j*10+k)%13] += dp[i-1][j];
          }else{
            if(j==0) dp[i][(j*10+k)%13] += 1;
          }
        }
      }else{
        int k = S[i]-'0';
        if(i-1 >= 0){
          dp[i][(j*10+k)%13] += dp[i-1][j];
        }else{
          if(j==0) dp[i][(j*10+k)%13] += 1;
        }
      }
    }
  }

  cout << dp[S.size()-1][5] << endl;
  
  return 0;
}



Measured memory_bytes: 12160
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*

*/


ll n,a[3010],largest[3010][3010],smallest[3010][3010];

ll f(bool player,ll l,ll r){
	if(l>r)return 0;
	if(player){
		if(largest[l][r]!=-1e18){
			return largest[l][r];
		}else{
			return largest[l][r] = max(f(!player,l+1,r)+a[l], f(!player,l,r-1)+a[r]);
		}
	}else{
		if(smallest[l][r]!=1e18){
			return smallest[l][r];
		}else{
			return smallest[l][r] = min(f(!player,l+1,r)-a[l], f(!player,l,r-1)-a[r]);
		}
	}
	return 0;
}

int main(void){
	cin>>n;
	rep(i,n)cin>>a[i];
	//
	rep(i,n)rep(j,n)largest[i][j]=-1e18;
	rep(i,n)rep(j,n)smallest[i][j]=1e18;
	//
	cout<<f(true,0,n-1)<<endl;
	return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  //main
  int N; cin >> N;
  string S; cin >> S;
  int L = S.length();
  vector<int> v(L);
  
  FOR(i,L){ v[i] = S[i]-'A'; }
  FOR(i,L){ v[i] = (v[i]+N)%26; }
  string ans = "";
  FOR(i,L){ ans += 'A'+v[i]; }
  
  // output
  cout << ans << endl;
                       
  return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N, K;
    ll res = 0;
    cin >> N >> K;
    deque<int> dq;
    for(int i = 0; i < N; i++){
        int v;
        cin >> v;
        dq.push_back(v);
    }
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if(i + j > K || i + j > N) continue;
            auto dq_copy = dq;
            int re = K - i - j;
            vector<int> hou;
            int idx = 0;
            while(i != idx){
                hou.push_back(dq_copy.front());
                dq_copy.pop_front();
                idx++;
            }
            idx = 0;
            while(j != idx){
                hou.push_back(dq_copy.back());
                dq_copy.pop_back();
                idx++;
            }
            ll ans = 0;
            sort(hou.begin(), hou.end());
            int s = hou.size();
            for(int k = 0; k < s; k++){
                if(hou[k] >= 0  || re == 0) ans += hou[k];
                else re--;
            }
            res = max(res, ans);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll BIG_MOD = ll(1e9)+7;
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = BIG_MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= BIG_MOD;
	if (u < 0) { u += BIG_MOD; }
	return u;
}
// 順列
ll permutation(ll n, ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % BIG_MOD; }
	return result;
}
// 組み合わせ
ll combination(ll n, ll m) {
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++) { div = (div * i) % BIG_MOD; }
	return (p * modinv(div)) % BIG_MOD;
}

int main() {
	int R;
	cin >> R;
	
	cout << fixed << setprecision(10) << (2*R*M_PI) << endl;
  return 0;
}


Measured memory_bytes: 3804
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    s = readline().strip()
    t = readline().strip()
    ls = len(s)
    lt = len(t)

    if ls < lt:
        print("UNRESTORABLE")
        exit()

    ind = -1
    for i in range(ls-lt+1):
        flag = True
        for j,t_ in enumerate(t):
            if s[i+j] == "?":
                continue
            if t_ != s[i+j]:
                flag = False
        if flag:
            ind = i
    
    if ind == -1:
        print("UNRESTORABLE")
        exit()
    
    ans = s[:ind] + t + s[ind+lt:]
    ans = ans.replace("?", "a")
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
# coding: utf-8
N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
    L=list(map(int,input().split()))
    C.append(L[0])
    A.append(L[1:])

ans=-1
for i in range(2**N):
    skill=[0 for i in range(M)]
    cost=0
    flg=True
    for j in range(N):
        if i >> j &1:
            cost+=C[j]
            for k in range(M):
                skill[k]+=A[j][k]
    
    for k in range(M):
        if skill[k]<X:
            flg=False
    if flg:
        if ans==-1:
            ans=cost
        else:
            ans=min(ans,cost)

print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int k, q;
  ll d[5252];
  cin>>k>>q;
  REP(i, k){
    cin>>d[i];
  }
  while(q--){
    ll n, x, m;
    cin>>n>>x>>m;
    --n;
    x%=m;
    ll b[5252];
    ll sum=0;
    int zero=0;
    REP(i, k){
      b[i]=d[i]%m;
      sum+=b[i];
      zero+=(b[i]==0);
    }
    ll cnt=(x+sum*(n/k))/m;
    // DEBUG(cnt);
    ll ans=n/k*k-(cnt+zero*(n/k));
    // DEBUG(ans);
    ll cur=(x+sum%m*(n/k))%m;
    REP(i, n%k){
      ll tmp=(cur+b[i])%m;
      // DEBUG(cur);
      // DEBUG(tmp);
      if(cur<tmp){
        ++ans;
      }
      cur=tmp;
    }
    cout<<ans<<'\n';
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ALL(V) V.begin(), V.end()
using namespace std;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

struct Coor {
    double x, y;
    Coor(double x, double y) : x(x), y(y) {}
};

V<Coor> v(3, Coor(0, 0));

Coor rel(const Coor &c1, const Coor &c2) {
    return Coor(c1.x - c2.x, c1.y - c2.y);
}

double calc_s() {
    Coor c1 = rel(v[0], v[2]);
    Coor c2 = rel(v[1], v[2]);
    double ret = abs(c1.x * c2.y - c1.y * c2.x);
    return ret / 2;
}

double calc_len(const Coor &c1, const Coor &c2) {
    Coor tmp = rel(c1, c2);
    return sqrt(pow(tmp.x, 2) + pow(tmp.y, 2));
}

int main() {
    for(auto &e : v) cin >> e.x >> e.y;
    double S = calc_s();
    double lsum = 0;
    double lmax = 0;
    for(ll i = 0; i < 3; i++) {
        double tmp = calc_len(v[i], v[(i + 1) % 3]);
        lsum += tmp;
        lmax = max(lmax, tmp);
    }
    double r = 2 * S / lsum;
    double ok = 0, ng = 1e9;
    for(ll i = 0; i < 100; i++) {
        double mid = (ok + ng) / 2;
        if(lmax * (1 - mid / r) >= 2 * mid) ok = mid;
        else ng = mid;
    }
    printf("%.20f\n", ok);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

class UnionFind {
private:
    int n;
    vector<int> par;
    vector<int> rank;
public:
    UnionFind(int n) : n(n), par(n), rank(n) { REP(i, n) par[i] = i, rank[i] = 0; }
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) { return find(x) == find(y); }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
    int size() const { return n; }
};

int N, M, A[50], B[50];

bool same(UnionFind u1, UnionFind u2) {
    map<int, int> rel;
    FOR(i, 1, N + 1) {
        if (rel[u1.find(i)] == 0) {
            rel[u1.find(i)] = u2.find(i);
        }
        else {
            if (rel[u1.find(i)] != u2.find(i)) return false;
        }
    }
    return true;
}

int main() {
    cin >> N >> M;
    REP(i, M) cin >> A[i] >> B[i];
    UnionFind uf = UnionFind(N + 1);
    REP(i, M) uf.unite(A[i], B[i]);

    int ans = 0;
    REP(i, M) {
        UnionFind ufp = UnionFind(N + 1);
        REP(j, M) {
            if (j == i) continue;
            ufp.unite(A[j], B[j]);
        }
        if (!same(uf, ufp)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input().strip())
W = list(map(int, input().strip().split()))

l = 0
r = sum(W)
min_diff = r

for w in W:
  l += w
  r -= w
  min_diff = min(min_diff, abs(l - r))
  if l > r:
    break

print(min_diff)

Measured memory_bytes: 3060
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2 - (y2 - y1);
    int y3 = y2 + (x2 - x1);
    int x4 = x3 - (y3 - y2);
    int y4 = y3 + (x3 - x2);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in xrange(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i + 1


def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q+1, r)

def getMarkOrder(A):
    d = defaultdict(list)
    for x in A:
        d[x[1]].append(x[0])
    return d

n = int(raw_input())
A = []
for i in xrange(n):
    X = raw_input().split()
    A.append((X[0], int(X[1])))
B = getMarkOrder(A)
quickSort(A, 0, n-1)
C = getMarkOrder(A)
print 'Stable' if B == C else 'Not stable'
for x in A:
    print x[0], x[1]

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

vector<int> distX = {-1, -1, 0, 1, 1, 1, 0, -1};
vector<int> distY = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) {
        cin >> S.at(i);
    }

    rep(i, H) {
        rep(j, W) {
            if (S.at(i).at(j) == '.') {
                // 周りに何個「#」があるか調べる
                int count = 0;
                rep(k, 8) {
                    int aroundY = i + distY.at(k);
                    int aroundX = j + distX.at(k);
                    if (aroundX < 0 || W - 1 < aroundX) continue;
                    if (aroundY < 0 || H - 1 < aroundY) continue;
                    if (S.at(aroundY).at(aroundX) == '#') count++;
                }
                S.at(i).at(j) = (char)('0' + count);
            }
        }
    }

    rep(i, H) {
        cout << S.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
X = [ list(map(int, input().split())) for _ in range(N) ]

sq_list = [ (n+1)**2 for n in range(400)]
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        sq_d = sum([ (X[i][k] - X[j][k])**2 for k in range(D)] )
        if sq_d in sq_list:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define P pair<int,int> 
signed main(){
    int n,m;cin>>n>>m;
    vector<int> a(m);
    vector<int> b(m);
    rep(i,m)cin>>a[i]>>b[i];
    sort(all(a));
    sort(all(b));
    cout<<(((b[0]-a[a.size()-1])<0)?0:(b[0]-a[a.size()-1]+1));
    return 0;

}

Measured memory_bytes: 1024
int main(void){
    int i=0;
    int j=0;
    
    int t[9<<14]={};
    int max=0;
    int scn=0;
    
    for(;~scanf("%d",&t[i]);i++){
        if(i && t[i]>max)max=t[i];
    }
    for(j=1;j<t[0]+1;j++){
        if(abs(t[j]-max/2)<abs(scn-max/2))scn=t[j];
    }
    printf("%d %d",max,scn);
}

Measured memory_bytes: 2280
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=5*1e5+1000;
const int SIZE2=5010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
 
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////////////////
void init(){
 
}
LL solve(){
	LL A,B,C,K;
	cin >> A >> B >> C >>K;
	if(K%2==0) return A-B;
	else return B-A;
}
signed main(){
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 13184
#include<iostream>
#include<algorithm>
#include<queue>
using lint=int64_t;
using namespace std;

int main()
{
	int N,M;
	priority_queue<lint> que;

	cin >> N >> M;
	for(int i=0;i<N;i++)
	{
		lint A;
		cin >> A;
		que.push(A);
	}
	
	for(int i=0;i<M;i++)
	{
		lint tmp=que.top();
		que.pop();
		que.push(tmp/2);
	}

	lint ans=0;
	while(!que.empty())
	{
		ans+=que.top();
		que.pop();
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1400
n,m = map(int, input().split())
l = list(map(int,list(input()[::-1])))
safe = [-1]*(n+1)
r = n
for i in range(n,-1,-1):
    if l[i]:
        continue
    if r-i > m:
        r = i+m
        while l[r]:
            r -= 1
        if r == i:
            print(-1)
            exit()
    safe[i] = r
dice = list()
cur = 0
while cur < n:
    dice.append(safe[cur]-cur)
    cur = safe[cur]
print(" ".join(map(str,dice[::-1])))


Measured memory_bytes: 15640
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	if(a=="----"){
		cout<<-4<<endl;
	}
	else if(a=="+---"||a=="-+--"||a=="--+-"||a=="---+"){
		cout<<-2<<endl;
	}
	else if(a=="-+++"||a=="+-++"||a=="++-+"||a=="+++-"){
		cout<<2<<endl;
	}
	else if(a=="++++"){
		cout<<4<<endl;
	}
	else{
		cout<<0<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int w, h, x, y; cin >> w >> h >> x >> y;
	int m = w * h;
	cout << fixed << setprecision(6) << m / 2.0 << " ";
	if (w % 2 == 0 && w / 2 == x && h % 2 == 0 && h / 2 == y) {
		cout << 1 << '\n';
	} else {
		cout << 0 << '\n';
	}
}


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

int main() {
  int r, g, b, n, triplets = 0;
  cin >> r >> g >> b >>n;
  for (int i = 0; i <= n / r; ++i) {
    for (int j = 0; j <= n / g; ++j) {
      int t = n - i * r - j * g;
      if (t < 0) break;
      if (t % b == 0) ++triplets;
    }
  }
  cout << triplets << '\n';
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
using namespace std;
//#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vint A,B;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
		B.pb(a);
	}
	sort(B.begin(),B.end());
	//cout<<B[N/2-1]<<endl;
	for(int i=0;i<N;i++){
		if(A[i]<=B[N/2-1])
			cout<<B[N/2]<<endl;
		else
			cout<<B[N/2-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3948
# This file is a "Hello, world!" in Python language by CPython for wandbox.
iipt=lambda:int(input())
miipt=lambda:list(map(int, input().split()))
from pprint import pprint
r=[]
n=m=0
def solven(k, i):
    # k: 各材料の余ってるかどうかbit
    # i: i以降のレシピを足していこう
    # return 足せるレシピ数のmax
    if i==n:
        return -1 if k else 0
    s1=solven(k^r[i], i+1)
    if s1!=-1:
        s1+=1
    return max(s1, solven(k, i+1))


while True:
    n,m=miipt()
    if n==m==0:
        break
    r=[int(input(), 2) for i in range(n)]
    #print(r)

    if n<22:
        print(solven(0,0))
    else:
        dp={} # dp[k]=材料のあまり具合kで作れるレシピ数
        dp[0]=0
        for i in range(n):
            dp_=dp.copy()
            for k, v in dp_.items():
                if k^r[i] in dp:
                    dp[k^r[i]]=max(dp[k^r[i]], v+1)
                else:
                    dp[k^r[i]]=v+1
            #pprint(dp)
        print(dp[0])







Measured memory_bytes: 139440
def main():
    N = int(input())
    C = list(map(int, input().split()))
    C.sort()
    MOD = 10 ** 9 + 7
    two = [0] * (N + 1)
    two[0] = 1
    for i in range(N):
        two[i+1] = two[i] * 2
        two[i+1] %= MOD
    ans = 0
    for i in range(N):
        l = i
        r = N - 1 - i
        now = two[r]
        if r != 0:
            now += two[r-1] * r
        now *= two[l]
        now %= MOD
        now *= C[i]
        ans += now
        ans %= MOD

    ans *= two[N]
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 89036