akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
p=list(map(int,input().split()))

for i in range(n):
    p[i]=(p[i]+1)/2#p[i]を期待値に変更
    
p_sum=[0]*n
ans=0
for i in range(n):
    if i==0:
        p_sum[i]=p[i]
        ans=p_sum[i]
    elif i<k:
        p_sum[i]=p_sum[i-1]+p[i]
        if p_sum[i]>ans:
            ans=p_sum[i]
    else:
        p_sum[i]=p_sum[i-1]+p[i]-p[i-k]
        if p_sum[i]>ans:
            ans=p_sum[i]
print(ans)

Measured memory_bytes: 76552
N = int(input())
A = sorted(map(int,input().split(" ")))
B = sorted(map(int,input().split(" ")))
C = sorted(map(int,input().split(" ")))

o = []
p = []

i = 0
k = 0
for j in range(N):
    while i < N and A[i] < B[j]:
        i = i + 1
    o.append(i)

    while k < N and B[j] >= C[k]:
        k = k + 1
    p.append(N-k)

sum = 0
for x in range(N):
    sum = sum + o[x] * p[x]

print(sum)

Measured memory_bytes: 23988
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC129
{
	class Program
	{
		static void Main(string[] args)
		{
			var HW = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			var H = HW[0];
			var W = HW[1];
			var S = ReadLines(H).Select(s => (s + "#").Select(c => c == '#' ? true : false).ToList()).ToList();
			S.Add(Enumerable.Repeat(true, W + 1).ToList());
			var ans = new int[H + 1, W + 1];

			for (var r = 0; r <= H; r++)
			{
				var start = 0;
				var end = 0;
				for (var c = 0; c <= W; c++)
				{
					end = c;
					if (S[r][c])
					{
						for (var i = start; i < end; i++)
						{
							ans[r, i] = end - start;
						}
						start = c + 1;
					}
				}
			}

			for (var c = 0; c <= W; c++)
			{
				var start = 0;
				var end = 0;
				for (var r = 0; r <= H; r++)
				{
					end = r;
					if (S[r][c])
					{
						for (var i = start; i < end; i++)
						{
							ans[i, c] += end - start - 1;
						}
						start = r + 1;
					}
				}
			}

			System.Console.WriteLine(ans.Cast<int>().Max());
		}

		static IEnumerable<string> ReadLines(int n) => Enumerable.Range(0, n).Select(_ => Console.ReadLine());
		static void WriteLines<T>(IEnumerable<T> obj) { foreach (var x in obj) Console.WriteLine(x); }
	}
}


Measured memory_bytes: 35820
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1

s = ri()

used = set()
ans = 1
while True:
    if s in used:
        break
    used.add(s)
    ans += 1
    s = f(s)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=1e2+5;
const int K=1e5+5;
const int mod=1e9+7;
const ll inf=1e18+7;
int dp[N][K],s[N][K],n,k,a[N],sum[N];
int main()
{
    scanf("%d%d",&n,&k);
    forn(i,1,n){
        scanf("%d",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    dp[0][0]=1;
    forn(i,0,n){
        s[i][0]=1;
    }
    forn(i,0,n){
        forn(j,0,k){
            if(i!=0&&j<=sum[i]){
                if(j-a[i]-1>=0){dp[i][j]=(s[i-1][j]+(mod-s[i-1][j-a[i]-1])%mod)%mod;}
                else{dp[i][j]=s[i-1][j];}
            }
            if(j!=0)s[i][j]=(s[i][j-1]+dp[i][j])%mod;
            //printf("i:%d j:%d: dp[i][j]:%d s[i][j]:%d\n",i,j,dp[i][j],s[i][j]);
        }
    }
    printf("%d\n",dp[n][k]);
    return 0;
}


Measured memory_bytes: 82176
O = input()
E = input()
P = ""
if len(O) == len(E):
    for i in range(len(O)):
        P += O[i]+E[i]
    print(P)
else :
    for i in range(len(E)):
        P += O[i]+E[i]
    P += O[i+1]
    print(P)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>

#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define endl "\n"
#define INF (ll)ll_MAX

typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;

const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;

using namespace std;

void solve()
{    
    string s ;
    cin>>s;
    int c = 0 ;
    int i= 0 ;
    while(i<3){
        int tc = 0 ;
        if(s[i]=='R'){
            while(i<3 && s[i]=='R'){
                tc++;
                i++;
            }
        }
        else{
            i++;
        }
        c = max(c , tc) ;
    }
    cout<<c<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    //cout<<"helo";
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    //  cin>>t;

    while(t--)
    {
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b) {
    //a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
    }
  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
void Sieve(ll int n) 
{ 
    bool prime[10000000];
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Function to find gcd of array of 
// numbers 
int find(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 


//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
void reverse(string& str) 
{ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 

  
int main() {
    ll int p;
    cin>>p;
    string a[p];
    int l=0,m=0,n=0,o=0;
    for(int i=0;i<p;i++)
    {
        cin>>a[i];
        if(a[i]=="AC")
        {
            l++;
        }
        else if(a[i]=="TLE")
        {
            n++;
        }
        else if(a[i]=="WA")
        {
            m++;
        }
        else
        {
            o++;
        }
    }
    cout<<"AC"<<" "<<"x"<<" "<<l<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<m<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<n<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<o<<endl;
}



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

int main(){
  int K;
  cin >> K;
  string S;
  cin >> S;
  
  if (S.size() <= K){
    cout << S << endl;
  }
  else{
    
    for (int i = 0; i < K; i++){
      cout << S.at(i);
    }
    
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

template <typename F>
void forSubset(int s, F f)
{
    int sub = s;
    do {
        f(sub);
        sub = s & (sub - 1);
    } while (sub != s);
}

template <typename F>
void forComb(int n, int k, F f)
{
    int comb = (1 << k) - 1;
    while (comb < (1 << n)) {
        f(comb);

        int x = comb & -comb;
        int y = comb + x;
        comb = ((comb & ~y) / x >> 1) | y;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    rep(i, n) rep(j, n)
    {
        cin >> a[i][j];
    }

    vector<int64_t> p(1 << n);
    rep(s, 1 << n)
    {
        p[s] = 0;
        rep(i, n)
        {
            for (int j = i + 1; j < n; j++) {
                if (((s >> i) & 1) != 0 && ((s >> j) & 1) != 0) {
                    p[s] += a[i][j];
                }
            }
        }
    }

    vector<int64_t> dp(1 << n);
    dp[0] = 0;
    rep(i, n)
    {
        forComb(n, i + 1, [&](int comb) {
            dp[comb] = p[comb];
            forSubset(comb, [&](int sub) {
                if (sub != comb) {
                    dp[comb] = max(dp[comb], dp[sub] + dp[comb & ~sub]);
                }
            });
        });
    }

    cout << dp[(1 << n) - 1] << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

bool comp_pair(pair <int, int> a, pair <int, int> b)
{
    return (a.second < b.second) || (a.second == b.second && a.first < b.first); 
}

int main()
{
    int n, m;
    cin>>n>>m;
    int a, b;
    pair <int, int> p[m];
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        p[i] = make_pair(a,b);
    }
    vector < pair <int, int> > vec_p (p, p+m);
    sort(vec_p.begin(), vec_p.end(), comp_pair);
    
    int count =0;
    int cur_cut = -1;
    for(int i=0; i<m; i++)
    {
        if(vec_p[i].first >= cur_cut)
        {
            count++;
            cur_cut = vec_p[i].second;
        }
    }
    cout<<count<<endl;
    
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <set>

using namespace std;

inline int abs(int a){ return a >= 0 ? a : -a; }

typedef pair<int, int> pii;

class MyComparator {
public:
	bool operator()(pii &a, pii &b){
		if(a.first < b.first){ return true; }
		if(a.first > b.first){ return false; }
		return a.second < b.second;
	}
};

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		set<pii> field;
		while(n--){
			int x, y;
			cin >> x >> y;
			field.insert(pii(x, y));
		}
		int answer = 0;
		for(set<pii>::iterator i = field.begin(); i != field.end();){
			pii p1 = *i;
			for(set<pii>::iterator j = ++i; j != field.end(); j++){
				pii p2 = *j;
				int dx = abs(p1.first - p2.first), dy = abs(p1.second - p2.second);
				int size = dx * dy * 2 + (dx - dy) * (dx - dy);
				if(size > answer){
					if(
						field.find(pii(p1.first - dy, p1.second - dx)) != field.end() &&
						field.find(pii(p2.first - dy, p2.second - dx)) != field.end()
					){
						answer = size;
					}else if(
						field.find(pii(p1.first + dy, p1.second + dx)) != field.end() &&
						field.find(pii(p2.first + dy, p2.second + dx)) != field.end()
					){
						answer = size;
					}
				}
			}
		}
		printf("%d\n", answer);
	}
	return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool augument(vector<vector<int> >& flow, const vector<vector<int> >& capacity, int s, int g)
{
  int size = capacity.size();
  queue<int> q;
  vector<int> prev(size, -1);
  prev[s] = s;
  q.push(s);
  while (!q.empty()) {
    int n = q.front();
    q.pop();
    for (int i = 0; i < size; i++) {
      if (capacity[n][i] - flow[n][i] <= 0) continue;
      if (prev[i] != -1) continue;
      prev[i] = n;
      q.push(i);
      if (i == g) goto endloop;
    }
  }
endloop:
  if (prev[g] == -1) return false;
  for (int i = g; prev[i] != i; i = prev[i]) {
    ++flow[prev[i]][i];
    --flow[i][prev[i]];
  }
  return true;
}

pair<int, vector<vector<int> > >
maxflow(const vector<vector<int> >& capacity, int s, int g) {
  int size = capacity.size();
  vector<vector<int> > flow(size, vector<int>(size, 0));
  int ans = 0;
  while (augument(flow, capacity, s, g)) {
    ++ans;
  }
  return make_pair(ans, flow);
}

void bfs(vector<vector<int> >& flow, int start, int goal)
{
  const int N = flow.size();
  queue<int> q;
  vector<int> prev(N, -1);
  q.push(start);
  prev[start] = start;
  while (!q.empty()) {
    int n = q.front();
    q.pop();
    if (n == goal) {
      while (prev[n] != n) {
        flow[prev[n]][n] = flow[n][prev[n]] = 0;
        n = prev[n];
      }
      return;
    }
    for (int i = 0; i < N; i++) {
      if (flow[n][i] > 0 && prev[i] == -1) {
        prev[i] = n;
        q.push(i);
      }
    }
  }
}

int main()
{
  int N, E, Q;
  cin >> N >> E >> Q;
  vector<vector<int> > capacity(N, vector<int>(N, 0));
  for (int i = 0; i < E; i++) {
    int f, t;
    cin >> f >> t;
    --f;    --t;
    capacity[f][t] = capacity[t][f] = 1;
  }

  pair<int, vector<vector<int> > > r = maxflow(capacity, 0, N-1);
  int maxf = r.first;
  vector<vector<int> > flow = r.second;
  while (Q-- > 0) {
    int m, a, b;
    cin >> m >> a >> b;
    --a;    --b;
    if (m == 1) {
      capacity[a][b] = capacity[b][a] = 1;
    } else {
      capacity[a][b] = capacity[b][a] = 0;
      if (flow[a][b] != 0) {
        --maxf;
        if (flow[a][b] < 0) {
          swap(a, b);
        }
        flow[a][b] = flow[b][a] = 0;
        bfs(flow, 0, a);
        bfs(flow, b, N-1);
      }
    }
    if (augument(flow, capacity, 0, N-1)) {
      ++maxf;
    }

    cout << maxf << endl;
  }
  return 0;
}

Measured memory_bytes: 4860
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;
const int MAXN = 1000005;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;

struct Node {
    int x, y, dir;
    ll d;

    Node(int x, int y, int dir, ll d) : x(x), y(y), dir(dir), d(d) {}

    bool operator<(const Node &a) const {
        return d > a.d;
    }
};

string maze[MAXN];
int n, m, k, sx, sy, tx, ty, vis[MAXN * 4];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
ll dis[MAXN * 4];

inline int id(int x, int y, int d) {
    return (x * m + y) * 4 + d;
}

ll roundUp(ll x) {
    if (x % k == 0) return x;
    return (x / k + 1) * k;
}

void dijkstra() {
    priority_queue<Node> q;
    memset(dis, 0x3f, sizeof(dis));
    for (int i = 0; i < 4; ++i) {
        dis[id(sx, sy, i)] = 0;
        q.push(Node(sx, sy, i, 0));
    }
    while (!q.empty()) {
        Node u = q.top();
        q.pop();
        int x = u.x;
        int y = u.y;
        int dir = u.dir;
        ll d = u.d;
        if (vis[id(x, y, dir)]) {
            continue;
        }
        vis[id(x, y, dir)] = 1;
//        cout<<"pop"<<x<<" "<<y<<" "<<dir<<" "<<d<<endl;
        for (int i = 0; i < 4; ++i) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            ll nd = d + 1;
            if (xx >= 0 && xx < n && yy >= 0 && yy < m && maze[xx][yy]=='.') {
                if (dir != i) {
                    //换方向，先向上取整，再+1
                    nd = roundUp(d) + 1;
                }
                if (dis[id(xx, yy, i)] > nd) {
                    dis[id(xx, yy, i)] = nd;
                    q.push(Node(xx, yy, i, nd));
//                    cout<<"push"<<xx<<" "<<yy<<" "<<i<<" "<<nd<<endl;
                }
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> k >> sx >> sy >> tx >> ty;
    //下标从0开始用，都减一
    sx--, sy--, tx--, ty--;
    for (int i = 0; i < n; ++i) {
        cin >> maze[i];
    }
    dijkstra();
    ll ans = INF;
    for (int i = 0; i < 4; ++i) {
        ans = min(ans, dis[id(tx, ty, i)]);
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << roundUp(ans)/k << endl;
    }
    return 0;
}

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

int main()
{
	int w, h, n, cnt = 0, stt[2], gol[2], swap_a = 0, rem[2];
	cin >> w >> h >> n;
	cin >> stt[0] >> stt[1];
	for (int i = 1; i < n; i++) {
		cin >> gol[0] >> gol[1];
		swap_a = 0;
		if (stt[0] > gol[0] && stt[1] > gol[1]) {
			int swap = stt[0];
			stt[0] = gol[0];
			gol[0] = swap;
			swap = stt[1];
			stt[1] = gol[1];
			gol[1] = swap;
			/*cout << "swap" << endl;*/
			swap_a++;
			rem[0] = stt[0];
			rem[1] = stt[1];
		}
		if (stt[0] < gol[0] && stt[1] < gol[1]) {
			if (gol[0] - stt[0] >= gol[1] - stt[1]) {
				cnt += gol[1] - stt[1];
				stt[0] = stt[0] + gol[1] - stt[1];
				stt[1] = gol[1];
				/*cout << "naname_puturn1" <<" "<<gol[1]-stt[1]<< endl;*/
				
			}
			else {
				cnt += gol[0] - stt[0];
				stt[1] = stt[1] + gol[0] - stt[0];
				stt[0] = gol[0];
				/*cout << "naname_puturn0" <<" "<<gol[1]-stt[1]<< endl;*/
			
			}
		}
		/*cout << "now" << stt[0] << " " << stt[1] << endl;*/
		if (stt[0] <= gol[0]) {
			cnt += gol[0] - stt[0];
			/*cout << "yoko" << gol[0] - stt[0] << endl;*/
		}
		else {
			cnt += stt[0] - gol[0];
			/*cout << "yoko_minus" << stt[0] - gol[0] << endl;*/
		}
		if (stt[1] < gol[1]) {
			cnt += gol[1] - stt[1];
			/*cout << "tate" << gol[1] - stt[1] << endl;*/
		}
		else {
			cnt += stt[1] - gol[1];
			/*cout << "tate_minus" << stt[1] - gol[1] << endl;*/
		}
		if (swap_a != 0) {
			gol[0] = rem[0];
			gol[1] = rem[1];
		}
		stt[0] = gol[0];
		stt[1] = gol[1];
		
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	int max = 0;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(p[i]>max) max = p[i];
		ans += p[i];
	}
	cout << ans - max/2 << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

int main() {
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if (x1 == 0) cout << 1 << endl;
  if (x2 == 0) cout << 2 << endl;
  if (x3 == 0) cout << 3 << endl;
  if (x4 == 0) cout << 4 << endl;
  if (x5 == 0) cout << 5 << endl;
  return 0;
}

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

const ll mod = 1e18;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  __int128 ans = 1;
  rep(i, n) {
    ans *= a[i];
    if (ans > mod) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ll(ans) << endl;
  return 0;
}


Measured memory_bytes: 4048
from operator import itemgetter
n = int(input())
list_a = list(map(int, input().split()))

list_a2 = []
for i in range(n):
    list_a2.append([list_a[i], i+1])

list_a2 = sorted(list_a2, key = itemgetter(0))

print(" ".join(map(str, [x[1] for x in list_a2])))

Measured memory_bytes: 27580
#include <bits/stdc++.h>
using namespace std;
 
int p[202], q[202], cnt;
long long n;
     
void solve(long long n){
	if (!n) return;
   	if (~n & 1) 
		q[++q[0]] = cnt++, solve(n - 1);
   	else
   		p[++p[0]] = cnt++, solve(n >> 1);
}
    
int main(){
  	scanf("%lld", &n), solve(n), printf("%d\n", cnt + 100);
  	for (int i = 1; i <= q[0]; ++i) printf("%d ", cnt - q[i]);
  	for (int i = p[0]; i; --i) printf("%d ", cnt - p[i]);
   	for (int i = 1; i <= 100; ++i) printf("%d ", i);
 	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  ll T, A;
  cin >> T >> A;
  vl H(N);
  rep(i, N) cin >> H[i];

  ll dif = (ll)pow(10, 10);
  ll ans = -1;
  rep(i, N){
    if(dif > abs(1000*T - 6*H[i] - 1000*A)){
      ans = i + 1;
      dif = abs(1000*T - 6*H[i] - 1000*A);
    }
  }

  cout << ans << "\n";
  
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  int N,K;
  cin >> N >> K;
  double ans=0;
  for(int i=1;i<=N;i++){
    if(i>=K){
      ans+=(double)1/(double)N;
    }
    else if(i<K){
      int m=i;
      double pro=1;
      do{
        m*=2;
        pro/=(double)2;
      }while(m<K);
      ans+=pro/(double)N;
    }
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 3728
a,b,k = gets.split.map(&:to_i)
k.times do |i|
  na = a
  nb = b
  if i.even?
    na -= 1 if na.odd?
    na /= 2
    nb += na
  else
    nb -= 1 if nb.odd?
    nb /= 2
    na += nb
  end
  a = na
  b = nb
end
puts "#{a} #{b}"


Measured memory_bytes: 1788
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>

bool is_dot(uint64_t n, uint64_t m)
{
  return n == 1 && m == 1;
}

bool is_bar(uint64_t n, uint64_t m)
{
  return n == 1 || m == 1;
}

uint64_t max(uint64_t a, uint64_t b)
{
  return a > b ? a : b;
}

uint64_t bar_result(uint64_t n, uint64_t m)
{
  return max(n, m) - 2;
}

uint64_t cnt_corner(uint64_t n, uint64_t m)
{
  return 4;
}

uint64_t cnt_edge(uint64_t n, uint64_t m)
{
  return 2 * (n-2) + 2 * (m-2);
}

uint64_t cnt_center(uint64_t n, uint64_t m)
{
  return (n-2) * (m-2);
}

uint64_t get_result(uint64_t n, uint64_t m)
{
  if(is_dot(n, m)) {
    return 1;
  }
  if(is_bar(n, m)) {
    return bar_result(n, m);
  }
  //uint64_t ncorner = cnt_corner(n, m);
  //uint64_t nedge = cnt_edge(n, m);
  return cnt_center(n, m);
}

int main()
{
  int n, m;
  char lf;
  scanf("%d %d%c", &n, &m, &lf);
  printf("%" PRIu64 "\n", get_result(n, m));
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
 
using namespace std;
int MOD = 1000000007;
signed main(){
    int n,m;
    cin >> n >> m;
    int ans = 0;
    vector<pair<int,int>> p;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        p.push_back(MP(b,a));
    }
    SORT(p);
    int c = -1;
    rep(i,m){
        if(p[i].se >= c){
            ans++;
            c = p[i].fi;
        }
    }
    cout << ans << endl;
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://abc103.contest.atcoder.jp/tasks/abc103_d
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = c - a;
    int y = d - b;
    cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;
}


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

void print_vec(vector<int> &vec){
    for(int i=0; i<vec.size(); i++)
        cout << vec[i] << (i==vec.size()-1? "\n" : " ");
}

int main(){
    int N; cin >> N;
    vector<int> vec(N);
    
    for(auto &v: vec)
        cin >> v;
    
    print_vec(vec);
    for(int i=1; i<N; i++){
        int key = vec[i];
        int j = i-1;
        while(j>=0 && vec[j]>key){
            vec[j+1] = vec[j];
            j--;
        }
        vec[j+1] = key;
        print_vec(vec);
    }
    return 0;
}



Measured memory_bytes: 3068
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)

class edge:
    def __init__(self, to, cost):
        self.to, self.cost = to, cost

def main():
    N = int(input())
    g = defaultdict(list)
    for i in range(N-1):
        u, v, w = (int(_) for _ in input().split())
        g[u].append(edge(v, w))
        g[v].append(edge(u, w))

    color = [0] * (N+1)

    def dfs(ver):
        for e in g[ver]:
            if color[e.to] == 0 and e.cost%2 == 0:
                color[e.to] = color[ver]
                dfs(e.to)
            elif color[e.to] == 0 and e.cost%2 == 1:
                color[e.to] = (-1) * color[ver]
                dfs(e.to)
    color[1] = 1
    dfs(1)
    for i in range(1, N+1):
        if color[i] == -1: color[i] = 0
    print(*color[1:], sep='\n')
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 113588
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>

using namespace std;  typedef long long ll;
inline int qr(){
	int ret=0,f=0,c=getchar();
	while(!isdigit(c)) f|=c==45,c=getchar();
	while( isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
const int maxn=1e5+5;
const int inf=1e9;
struct E{
	int to,nx;
}e[maxn<<2];
int head[maxn],ans[maxn<<1],usd[maxn],n,m,cnt,D[maxn];
char col[maxn];
void add(int fr, int to){
	static int cnt=1;
	e[++cnt]=(E){to,head[fr]}; head[fr]=cnt;
	e[++cnt]=(E){fr,head[to]}; head[to]=cnt;
}
queue< int > q;

int main(){
	n=qr(); m=qr();
	for(int t=1;t<=n;++t)D[t]=qr();
	for(int t=1,a,b;t<=m;++t){
		a=qr(),b=qr(),add(a,b);
		if(D[a]==D[b]&&!col[a]&&!col[b]) q.emplace(a),q.emplace(b),col[a]='W',col[b]='B',ans[t]=D[a];
	}
	while(q.size()){
		int now=q.front(); q.pop();
		for(int t=head[now];t;t=e[t].nx)
			if(!col[e[t].to]&&D[e[t].to]>=D[now])
				col[e[t].to]="WB"[col[now]=='W'],ans[t>>1]=D[e[t].to],q.emplace(e[t].to);
	}
	for(int t=1;t<=n;++t)
		if(col[t]==0)
			return puts("-1"),0;
	puts(col+1);
	for(int t=1;t<=m;++t)
		printf("%d\n",ans[t]?ans[t]:inf);
	return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()



int main() {
    string s;
    cin >> s;
    reverse(all(s));
    vector<int> p(s.size() + 1, 0);
    int ten = 1;
    rep (i, s.size()) {
        p[i+1] = p[i] + ten * (s[i] - '0');
        p[i+1] %= 2019;
        ten *= 10;
        ten %= 2019;
    }
    map<int, int> m;
    rep (i, p.size()) {
        m[p[i]]++;
    }
    ll ans = 0;
    for (auto au: m) {
        ll val = au.second;
        ans += val * (val - 1) / 2;
    }
    cout << ans << endl;
}




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

int main() {
  int count = 0;
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N - 2; i++) {
    if (S[i] == 'A') {
      if (S[i + 1] == 'B') {
        if (S[i + 2] == 'C') {
          count++;
        }
        else {
          continue;
        }
      }
        else {
          continue;
        }
    }
        else {
          continue;
        } 
  }
  cout << count << endl;
}

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

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;
    cin >> s;
    int n = s.length();
    string t = s;
    reverse(s.begin(),s.end());
    if(s != t){
        cout << "No";
        return 0;
    }
    string t1 = s.substr(0,(n-1)/2);
    string t2 = t1;
    reverse(t1.begin(), t1.end());
    if(t1 != t2){
        cout << "No";
        return 0;
    }
    string t3 = s.substr((n+3)/2 - 1, n - (n+3)/2 +1);
    string t4 = t3;
    reverse(t3.begin(), t3.end());
    if(t3!= t4){
        cout << "No";
        return 0;
    }
    cout << "Yes";
    
}









Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >>a>>b>>c;
  if(a!=b&&a!=c){
    cout << a;
  }else{
  if(b!=a&&b!=c){
    cout << b;
  }else{
  cout << c; 
  }
  }
  return 0;
}

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

#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define vn(t,n,val) vector<t>(n,val)
#define vvn(t,r,c,val) vector<vector<t>>(r, vector<t>(c,val))
#define vvv(t) vector<vector<vector<t>>>
#define vvvn(t,l,b,h,val) vector<vector<vector<t>>>(l,vector<vector<t>>(b,vector<t>(h)))

int main() {
	sp;

	////////////////To Remove//////////////
	// freopen("../../input.txt", "r", stdin);
	// freopen("../../output.txt", "w", stdout);
	///////////////////////////////////////

	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;

	vector<int> red(a);
	vector<int> green(b);
	vector<int> colorless(c);

	for(auto& x: red) cin>>x;
	for(auto& x: green) cin>>x;
	for(auto& x: colorless) cin>>x;	

	sort(red.rbegin(), red.rend());
	sort(green.rbegin(), green.rend());
	// sort(colorless.rbegin(), colorless.rend());

	vector<long long> result_apples;
	for(int i = 0; i < min(x,a); ++i) result_apples.emplace_back(red[i]);
	for(int i = 0; i < min(y,b); ++i) result_apples.emplace_back(green[i]);
	for(int i = 0; i < c; ++i) result_apples.emplace_back(colorless[i]);

	sort(result_apples.rbegin(), result_apples.rend());
	cout<<accumulate(result_apples.begin(), result_apples.begin() + x + y, 0ll);

  	return 0;
}

Measured memory_bytes: 7152
#include<cstdio>
#include<algorithm>
#include<deque>

using namespace std;

typedef long long ll;

int main(){
	int n; scanf("%d", &n);
	int a[100000];
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);
	ll res = 0;
	for(int k = 0; k < 2; k++){
		deque<int> q;
		for(int i = 0; i < (n + 1) / 2; i++){
			if(i & 1){
				q.push_front(a[i]);
				if(i != n - i - 1) q.push_back(a[n - i - 1]);
			}
			else{
				q.push_back(a[i]);
				if(i != n - i - 1) q.push_front(a[n - i - 1]);
			}
		}
		ll sum = 0;
		for(int i = 0; i < n - 1; i++) sum += abs(q[i] - q[i + 1]);
		res = max(res, sum);
		reverse(a, a + n);
	}
	printf("%lld\n", res);
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   string s;
   cin >> s;
   ll a = stoll(s);

   int sum = 0;
   while (a > 0) {
      sum += a % 10;
      a /= 10;
   }

   int t = s[0]-'1' + (s.size()-1) * 9;
   cout << max(sum, t) << endl;

   return 0;
}

Measured memory_bytes: 256
import functools
[N, M] = [int(x) for x in input().split()]
XYZ = []
for i in range(N):
  XYZ.append([int(x) for x in input().split()])
result = 0
for x in range(-1, 2, 2):
  for y in range(-1, 2, 2):
    for z in range(-1, 2, 2):
      contribute = [x, y, z]
      score = [functools.reduce(lambda a, b: a + b, [xyz[i] * contribute[i] for i in range(3)]) for xyz in XYZ]
      score.sort(reverse=True)
      S = functools.reduce(lambda a, b: a + b, score[:M]) if M else 0
      result = max(result, S)
print(result)

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

int main()
{
    int n;
    cin >> n;
    int a, b, c, d;
    a = n / 1000 % 10;
    b = n / 100 % 10;
    c = n / 10 % 10;
    d = n % 10;
    if (((b == c) && (a == b)) || ((b == c) && (c == d)))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#define abs(a) ((a)<0 ? -(a):(a))
using namespace std;

int main(void){
  int N,delta=0;
  cin >> N;
  int t_=0,t,pos_x=0,pos_y=0,x,y;
  for(int i=0;i<N;i++){
    cin>>t>>x>>y;
    delta=abs(pos_x-x)+abs(pos_y-y);
    if(delta>t-t_ || (delta-t+t_)%2){
      cout << "No\n";
      return 0;
    }
    t_=t;
    pos_x=x;
    pos_y=y;
  }
  cout << "Yes\n";
  return 0;
}


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

int main() {
  while(1) {
    int maxi = -1, index;
    for(int i = 0, a, b; i < 5; ++i) {
      cin >> a >> b;
      if(a == 0 && b == 0) return 0;
      if(maxi < a+b) {
        maxi = a+b;
        index = i;
      }
    }
    cout << (char)('A'+index) << " " << maxi << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	long long int a,b,x,val,val2;
	cin>>a>>b>>x;
	if(x<b)
		{
			val=(a*x)/b;
			cout<<val;
			return 0;
		}
	else {
		val=(a*(b-1))/b;
		cout<<val;
	}
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

int main() {
	makei(n);
	vs w;
	rep(n) {
		makes(s);
		w.push_back(s);
	}
	rep(n - 1) {
		if (w[i].back() != w[i + 1].front()) {
			say("No");
			re;
		}
	}
	sort(all(w));
	rep(n - 1) {
		if (w[i] == w[i + 1]) {
			say("No");
			re;
		}
	}
	say("Yes");
}

Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

bool check(int i, int j, int r, int c, vector<vector<int>> &visited, vector<vector<char>> &v){
	return (i>=0 && i<r && j>=0 && j<c && visited[i][j]==INF && v[i][j]=='.');
}

int bfs(int i, int j, int r, int c, vector<vector<char>> &v)
{
    if(v[i][j] == '#')
        return 0;
	vector<vector<int>> visited(r, vector<int> (c, INF));
	visited[i][j] = 0;
	queue<pii> q;
	q.push(pii(i,j));
	while(!q.empty()){
		pii x = q.front();
        q.pop();
		rep(x_,-1,2){
			rep(y_,-1,2){
                if(abs(x_-y_)!=1)
                    continue;
				int x_new = x.fi+x_;
				int y_new = x.se+y_;
				if(check(x_new,y_new,r,c,visited,v)){
					visited[x_new][y_new]=visited[x.fi][x.se]+1;
					q.push(pii(x_new,y_new));
				}
			}
		}
	}
    
    /*rep(i,0,r)
    {
        rep(j,0,c)
        {
            cout<<visited[i][j]<<" ";
        }
        cout<<"\n";
    }
    cout<<"\n";*/
        
	int maxx = 0;
	rep(x,0,r)
    {
        rep(y,0,c)
        {
            if (v[x][y]=='#')
                continue;
            maxx = max(maxx, visited[x][y]);
        }
    }
	return maxx;
}

int main(){
	int n,m;
	cin>>n>>m;
	vector<vector<char>> v(n, vector<char> (m));
	rep(i,0,n)
		rep(j,0,m)
			cin>>v[i][j];
	int maxx = 0;
	rep(i,0,n){
		rep(j,0,m){
			maxx = max(maxx, bfs(i,j,n,m,v));
		}
	}
	cout<<maxx;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

from collections import deque


def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    ans = [0] * N

    for start_vertex in range(N):
        q = deque()
        distance_list = [float('inf')] * N

        def push(vertex, distance):
            if distance_list[vertex] != float('inf'):
                return
            q.append(vertex)
            distance_list[vertex] = distance

        push(start_vertex, 0)

        while len(q) != 0:
            vertex = q.popleft()
            distance = distance_list[vertex]

            if vertex - 1 >= 0:
                push(vertex - 1, distance + 1)
            if vertex + 1 < N:
                push(vertex + 1, distance + 1)
            if vertex == X:
                push(Y, distance + 1)
            if vertex == Y:
                push(X, distance + 1)

        for i in distance_list:
            ans[i] += 1

    print('\n'.join([str(i // 2) for i in ans[1:]]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 61044
// Author : SAGORIKA DAS
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define CLEAR(a) memset(a,0,sizeof a)
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fr freopen("input.txt", "r", stdin);
#define fw freopen("output.txt", "w", stdout);
#define debug(x) cerr << "#" << x <<"\n";
#define int long long 
typedef long long LL;
typedef pair<int,int> pii;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;

 main() {
    //fr;fw;
    int n, x;
    cin >> n;
    int sum = 0, ret = 0;
    REP(i,n) {
    	cin >> x;
    	sum += x;
    	if(x == 0){
    		ret += sum/2;
    		sum = 0;
    	}
    }
    ret += sum/2;
    cout << ret ;
    return 0;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;
  for(int i=s.size()-2;i>=0;i-=2){
    bool ok=true;
    for(int j=0;j<i/2;j++){
      // cout<<s[j]<<':'<<s[i/2+j]<<' ';
      if(s[j]!=s[i/2+j])ok=false;
    }
    // cout<<endl;
    if(ok){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

const string MINF = "-";

//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; }

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;}

void chmax(string &a, string b) {
  if (a == MINF) a = b;
  else if (a.size() < b.size()) a = b;
  else if (a.size() == b.size()) {
    if (a < b) a = b;
  }
}

long long match[10] = {-1,2,5,5,4,5,6,3,7,6};
string dp[10010];

int main () {
  int n, m;
  cin >> n >> m;
  vi a(m);
  rep(i,m) cin >> a[i];

  rep(i,10010) dp[i] = MINF;
  dp[0] = "";
  rep(i,n) {
    if (dp[i] == MINF) continue;
    for (auto A : a) {
      chmax(dp[i+match[A]], dp[i] + (char)('0'+A));
    }
  }

  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 43776
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
        int[] d = new int[n];
        for(int i=0;i<n;i++){
          d[i]=sc.nextInt();
        }
        //ソート
        Arrays.sort(d);
        int dec = d[(n/2)]-d[n/2-1];
        
		// 出力
		System.out.println(dec);
	}
  
    
}

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

int d[210];
int p[210];
int n;

int main(){
    memset(d,0,sizeof(d));
    memset(p,0,sizeof(p));
    d[105] = 8;
    p[105] = 1;

    for(int i=105; i<210; i++) {
        if(i%2==0){
            d[i] = 1;
        }
    }

    while(cin>>n){
        if(n<105){
            cout<<"0"<<endl;
            continue;
        }

        if(p[n]!=0){
            cout<<p[n]<<endl;
            continue;
        }
        else {
            for(int k=105; k<=n; k++){
                if(d[k]==8){
                    p[n]++;
                }
                else if(d[k]==0){
                    int sum = 2;
                    int sqrtn = sqrt(k);
                    for(int i=2; i<=sqrtn; i++) {
                        if(k%i==0){
                            if(i==k/i){
                                sum++;
                            }
                            else{
                                sum += 2;
                            }
                        }
                    }
                    d[k] = sum;

                    if(sum==8){
                        p[n]++;
                    }
                }
            }
            cout<<p[n]<<endl;

        }

    }
    return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws IOException{
		Scanner scan = null;
		int [][] point = new int[2][10];
		try{
			scan = new Scanner(System.in);
			for(int i = 0 ; i < point.length;i++)
				for(int j = 0; j < point[i].length;j++)
					point[i][j] = scan.nextInt();
			Arrays.sort(point[0]);
			Arrays.sort(point[1]);
			int[] sum = new int[2];
			for(int i = 9; i > 6;i--)
				for(int j = 0 ; j < sum.length;j++)
					sum[j] += point[j][i];
			System.out.printf("%d %d\n",sum[0],sum[1]);
		}finally{
			if(scan !=null)scan.close();
		}
	}
}

Measured memory_bytes: 17176
# ABC058C - 怪文書 / Dubious Document (ARC071C)
import sys
input = sys.stdin.readline

from string import ascii_lowercase


def main():
    N = int(input())
    S = tuple(input() for _ in range(N))
    ans = ""
    for i in ascii_lowercase:
        if all(i in s for s in S):
            ans += i * min(s.count(i) for s in S)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
using Tree = vector<pair<int, int>>;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
l = list(map(int,input().split()))

half = n>>1
lm = max(l)
lm = max([lm,k])
r = 1
cntlist = []
while(lm > 0):
    cnt = 0
    for i in range(len(l)):
        cnt += l[i]%2
        l[i] >>= 1
    cntlist.append(cnt)
    lm >>= 1
    r *= 2
r >>= 1
res = 0

cntlist = cntlist[::-1]

for x in cntlist:
    if(r>k):
        res += x*r
    elif(x>n-x):
        res += r*x
    else:
        res += (n-x)*r
        k -= r
    r >>= 1
print(res)



    


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

int main() {
  int N;
  cin >> N;
  int A,B = 0;
  int a[101];
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  
  sort(a,a + N, greater<int>());

   for(int i = 0; i < N; i++) {
     if(i % 2 == 0) { 
       A += a[i];
     }
     else {
       B += a[i];
     }
   }
     
    cout << A - B << endl;
}

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


def p_c():
    A, B, C, D = map(int, input().split())
    A -= 1
    gcd_value = gcd(max(C, D), min(C, D))
    lcm_value = C * D // gcd_value
    print(B - A - B // C + A // C - B // D + A // D + B // lcm_value - A // lcm_value)
    
p_c()

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

using namespace std;
typedef long long LL;

const int MAXN = 123456;
LL presum[MAXN];
vector<LL> line[MAXN];
map<LL, int> mp;

LL cal(LL cur, LL mod) {
   if (cur >= mod)
      return (cur - mod) % mod;
   else
      return (mod - cur) % mod;
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    int idx = 0;
    for (int i = 1; i <= N; i++) {
        int tmp;
        scanf("%d", &tmp);
        presum[i] = presum[i - 1] + tmp;
        presum[i] %= M;
        if (!mp.count(presum[i])) mp[presum[i]] = idx++;
        line[mp[presum[i]]].push_back(i);
    }
    LL ans = 0;
    for (int i = 1; i <= N; i++) {
        LL tmp = cal(-presum[i - 1], M);
        // printf("i = %d tmp = %lld\n", i, tmp);
        if (mp.count(tmp)) {
           LL cur = mp[tmp];
           auto low = lower_bound(line[cur].begin(), line[cur].end(), i);
           ans += LL(line[cur].end() - low);
           // printf("ans = %lld\n", ans);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 10240