akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int ans = 0;
  string s, t;
  cin >> s >> t;
  REP(i, s.size()) if(s[i] != t[i]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3844
#include <cstdio>

const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int ldays[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool isLeapYear(int year)
{
  if (year%400 == 0 || (year%4 == 0 && year%100 != 0))
    return true;
  return false;
}

int main()
{
  int y1, m1, d1, y2, m2, d2;
  while (~scanf("%d %d %d %d %d %d", &y1, &m1, &d1, &y2, &m2, &d2)) {
    if (y1 == -1 || m1 == -1 || d1 == -1 || y2 == -1 || m2 == -1 || d2 == -1)
      break;

    int start = 0, end = 0;
    for (int i = 1; i < y1; ++i) {
      if (isLeapYear(i))
	start += 366;
      else
	start += 365;
    }
    end = start;
    for (int i = y1; i < y2; ++i) {
      if (isLeapYear(i))
	end += 366;
      else
	end += 365;
    }

    for (int i = 1; i < m1; ++i) {
      if (isLeapYear(y1))
	  start += ldays[i];
      else
	start += days[i];
    }
    for (int i = 1; i < m2; ++i) {
      if (isLeapYear(y2))
	end += ldays[i];
      else
	end += days[i];
    }

    printf("%d\n", end+d2-start-d1);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<utility>
#include<vector>
#include<stack>
#include<algorithm>
#include<cmath>
#include<stdio.h>


using namespace std;

int main(){

	long long N,x,a[110],temp;
	long long ans=0;
	long long kei=0;

	cin >> N>>x;

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

		kei+=a[i];

	}

	sort(a,a+N);

	temp=x;


	for(int i=0; i<N; i++){

		if(temp >= a[i]){

			temp=temp-a[i];
			ans++;
		}

	

}
	
	if(kei <x) cout <<ans-1<<endl;

	else cout <<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n, a, b; cin >> n >> a >> b;
	ll t = a + b;
	
	cout << n / t * a + min(n % t, a) << '\n';

	


}




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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

    int n; std::cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        std::cin >> a[i];
    }
    ll ans = 1;
    sort(rng(a));
    if (a[0] == 0) {
        std::cout << 0 << "\n";
        return 0;
    }
    rep(i, n) {
        ll tmp = ans;
        ans *= a[i];
        if (tmp > ans || ans > 1'000'000'000'000'000'000) {
            std::cout << -1 << "\n";
            return 0;
        }
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 3996
#include<stdio.h>

int main(){
  while(1){
    int n, a = 0, b = 0, x, y, i;
    scanf("%d", &n);
    if(n == 0)return 0;
    for(i = 0;i < n;i++){
      scanf("%d%d",&x ,&y);
      if(x == y){
	a += x;
	b += y;
      }
      else if(x > y){
	a += x + y;
      }
      else if(x < y){
	b += x + y;
      }
    }
    printf("%d %d\n", a, b);
  }
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>

using namespace std;

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

struct Edge{
  int to,cost;
  Edge(int _to, int _cost):to(_to), cost(_cost){};
};

int minCost[101][11];
vector<Edge>edge[101];
static const int INF = INT_MAX;

int c,n,m,s,d;

int dijkstra(void){
  priority_queue<P, vector<P>,greater<P> >que;
  que.push(make_pair(0,make_pair(s,c))); 

  for(int i=0;i<101;i++)
    for(int j=0;j<11;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p=que.top();
    que.pop();

    for(int i=0;i<edge[p.second.first].size();i++){
      Edge e=edge[p.second.first][i];
      if(p.first+e.cost<minCost[e.to][p.second.second]){
	minCost[e.to][p.second.second]=p.first+e.cost;
	que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second)));
      }
    }

    if(p.second.second==0)continue;

    for(int j=0;j<edge[p.second.first].size();j++){
      Edge e=edge[p.second.first][j];
      if(p.first+e.cost/2<minCost[e.to][p.second.second-1]){
	minCost[e.to][p.second.second-1]=p.first+e.cost/2;
	que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1)));
      }
    }
  }
  int ans=INT_MAX;
  for(int i=0;i<11;i++)
    ans=min(minCost[d][i],ans);

  return ans;
}

int main(void){
  int a,b,f;

  while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){
    
    for(int i=0;i<=n;i++)edge[i].clear();

    for(int i=0;i<m;i++){
      cin >> a >> b >>f;
      edge[a].push_back(Edge(b,f));
      edge[b].push_back(Edge(a,f));
    }
    cout << dijkstra() << endl;
  }

  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = 1; i <= 1000; i++)
    if (i * k >= a && i * k <= b) {
      cout << "OK" << endl;
      return 0;
    }
  cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>

typedef struct infomation {
    std::string S;
    int count;
} judg;

int main() {
    int N, i, j;
    std::string S;
    std::vector<judg> ans = {
        {"AC", 0},
        {"WA", 0},
        {"TLE", 0},
        {"RE", 0}
    };

    std::cin >> N;

    for(i = 0; i < N; i++) {
        std::cin >> S;

        j = -1;
        while(S != ans.at(++j).S);
        ans.at(j).count++;
    }

    for(i = 0; i < 4; i++) {
        std::cout << ans.at(i).S << " x " << ans.at(i).count << std::endl; 
    }

    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll x,y; cin >> x >> y;
    ll a,b,c; cin >> a >> b >> c;
    vector<Pll> all;
    rep(i,a){
        ll p; cin >> p;
        all.emplace_back(Pll(p, 1));
    }
    rep(i,b){
        ll q; cin >> q;
        all.emplace_back(Pll(q, 2));
    }
    rep(i,c){
        ll r; cin >> r;
        all.emplace_back(Pll(r, 0));
    }

    sort(all(all), greater<Pll>());
    ll xc = 0, yc = 0, z = 0;
    ll ans = 0;
    for(auto i : all){
        if(i.second == 0){
            z++;
            ans += i.first;
        }
        if(i.second == 1){
            xc++;
            if(xc <= x)ans += i.first;
        }
        if(i.second == 2){
            yc++;
            if(yc <= y)ans += i.first;
        }
        if(xc >= x && yc + z == y)break;
        if(yc >= y && xc + z == x)break;
        if(xc <= x && yc <= y && xc + yc + z == x + y)break;
    }

    cout << ans << endl;
}

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


#define file "file"
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define DEBUG 0
#define dout if(DEBUG) cout

const int MAXN = 2e5 + 5;

vi g[MAXN];
int cnt[MAXN];

void update(int v){
    for(int i = 0; i < (int)g[v].size(); i++){
        int to = g[v][i];
        cnt[to]++;
    }
}

void solve(){
    int n, m;
    cin >> n >> m;
    int v, to;
    for(int i = 0; i < m; i++){
        scanf("%d%d", &v, &to);
        g[v].pb(to);
        g[to].pb(v);
    }
    update(1);
    update(n);
    for(int i = 2; i < n; i++){
        if(cnt[i] == 2){
            cout << "POSSIBLE";
            return;
        }
    }
    cout << "IMPOSSIBLE";
}

int main() {
    #ifdef NASTYA
        assert(freopen("input.txt", "r", stdin)); assert(freopen("output.txt", "w", stdout));
    #else
    // assert(freopen(file".in", "r", stdin)); assert(freopen(file".out", "w", stdout));
    #endif
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 12784
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _node_t {
	int key;
	struct _node_t *prev,*next;
} node_t;

void insert_front(node_t *_head,int _key) {
	node_t *new_node = (node_t*)malloc(sizeof(node_t));
	new_node->key = _key;
	new_node->prev = _head;
	new_node->next = _head->next;
	_head->next->prev = new_node;
	_head->next = new_node;
}

void delete_key(node_t *_head,node_t *_tail,int _key) {
	node_t *curr = _head->next;
	while (curr != _tail) {
		if (curr->key == _key) {
			curr->prev->next = curr->next;
			curr->next->prev = curr->prev;
			free(curr);
			break;
		}
		curr = curr->next;
	}
}

void delete_last(node_t *_tail) {
	node_t *delete_node = _tail->prev;
	_tail->prev->prev->next = _tail;
	_tail->prev = _tail->prev->prev;
	free(delete_node);
}

void output_list(node_t *_head,node_t *_tail) {
	node_t *node = _head->next;
	while (node != _tail) {
		printf("%d",node->key);
		printf(node->next == _tail ? "\n" : " ");
		node = node->next;
	}
}

int main(void) {
	int n;
	int i;
	char command[12];
	int key;
	node_t *head = (node_t*)malloc(sizeof(node_t));
	node_t *tail = (node_t*)malloc(sizeof(node_t));
	head->prev = tail->next = NULL;
	head->next = tail;
	tail->prev = head;
	scanf("%d",&n);
	for (i = 0;i != n;++i) {
		scanf("%s",command);
		if (strcmp(command,"insert") == 0) {
			scanf("%d",&key);
			insert_front(head,key);
		} else if (strcmp(command,"delete") == 0) {
			scanf("%d",&key);
			delete_key(head,tail,key);
		} else if (strcmp(command,"deleteFirst") == 0) {
			delete_key(head,tail,head->next->key);
		} else { // command == "deleteLast"
			delete_last(tail);
		}
	}
	output_list(head,tail);
	while (head->next != tail) {
		delete_key(head,tail,head->next->key);
	}
	free(head);
	free(tail);
	return 0;
}

Measured memory_bytes: 31788
import heapq
import sys
input=sys.stdin.readline
x,y,z,K=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)
q=[(-(A[0]+B[0]+C[0]),0,0,0)]
S=set()

for n in range(K):
  p,i,j,k=heapq.heappop(q)
  print(-p)
  if i+1<x and ((i+1,j,k) not in S):
    S.add((i+1,j,k))
    heapq.heappush(q,(-(A[i+1]+B[j]+C[k]),i+1,j,k))
  if j+1<y and ((i,j+1,k) not in S):
    S.add((i,j+1,k))
    heapq.heappush(q,(-(A[i]+B[j+1]+C[k]),i,j+1,k))
  if k+1<z and ((i,j,k+1) not in S):
    S.add((i,j,k+1))
    heapq.heappush(q,(-(A[i]+B[j]+C[k+1]),i,j,k+1))

Measured memory_bytes: 4852
from collections import namedtuple

def main():
    Place = namedtuple('Place', ('x', 'y', 'h'))

    N = int(input())

    place = [None for _ in range(N)]
    for i in range(N):
        x, y, h = map(int,input().split())
        place[i] = Place(x,y,h)

    place = list(filter(lambda t:t.h != 0, place))
    place_len = len(place)
    if place_len == 1:
        print(place[0].x, place[0].y, place[0].h)
        return

    for cy in range(101):
        for cx in range(101):
            sc0 = place[0].h + abs(cx - place[0].x) + abs(cy - place[0].y)
            for i in range(1, place_len):
                sci = place[i].h + abs(cx - place[i].x) + abs(cy - place[i].y)
                if sc0 != sci:
                    break
            else:
                print(cx, cy, sc0)
                return

main()


Measured memory_bytes: 3436
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r, Xadd, Xsub, Yadd, Ysub;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	Xadd = x + r;
	Xsub = x - r;
	Yadd = y + r;
	Ysub = y - r;

	if (Xadd <= W && Xsub >= 0 && Yadd <= H && Ysub >= 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

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

int main(){
    string s,t;
	cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long ll;
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<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n;
int a[525252];

int ind[525252];

char s[525252];

int main(){
	scanf("%s",s);
	n = strlen(s)+1;

	fill(ind,ind+525252,0);
	REP(i,n-1){
		if(s[i]=='<'){
			ind[i+1]++;
		}else{
			ind[i]++;
		}
	}
	stack<int> S;
	REP(i,n)if(ind[i]==0){
		S.push(i);
	}
	while(S.size()){
		int i = S.top(); S.pop();
		a[i] = 0;
		if(i<n-1 && s[i]=='>')CHMAX(a[i], a[i+1]+1);
		if(i>0 && s[i-1]=='<')CHMAX(a[i], a[i-1]+1);
		if(i<n-1 && s[i]=='<'){
			ind[i+1]--;
			if(ind[i+1]==0)S.push(i+1);
		}
		if(i>0 && s[i-1]=='>'){
			ind[i-1]--;
			if(ind[i-1]==0)S.push(i-1);
		}
	}

	ll ans = 0;
	REP(i,n)ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,k;
bool vis[N][N];
int a[N][N];
queue<pair<int,int> >q;
int main()
{
    scanf("%d%d",&n,&k);
    if(k>(n-2)*(n-1)/2) {printf("-1\n");return 0;}
    for(int i=1;i<=n-2;i++)
    {
        if(k==0) break;
        for(int j=i+1;j<=n-1;j++)
        {
            k--;
            vis[i][j]=vis[j][i]=true;
            if(k==0) break;
        }
    }
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
    if(!vis[i][j]) q.push({i,j});
    printf("%d\n",q.size());
    while(!q.empty())
    {
        pair<int,int>now=q.front();q.pop();
        printf("%d %d\n",now.first,now.second);
    }
    /*for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        if(i==j) a[i][j]==0;
    else if(vis[i][j]) a[i][j]=9999;
    else a[i][j]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        for(int k=1;k<=n;k++)
        a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        if(a[i][j]==2) ans++;
    printf("%d\n",ans);*/
}


Measured memory_bytes: 384
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

const long long int MOD = 1e9 + 7;

long long int fast_power(std::vector<std::vector<long long int> > &X, long long int N, long long int n, std::vector<std::vector<long long int> > &ANS);
long long int mat_prod(std::vector<std::vector<long long int> > &M1, std::vector<std::vector<long long int> > &M2, long long int N, std::vector<std::vector<long long int> > &ANS);
int mat_copy(std::vector<std::vector<long long int> > &Orig, long long int size, std::vector<std::vector<long long int> > &Copy);


int main(){
  
  // read problem
  long long int N, K, tmp;
  scanf("%lld%lld", &N, &K);
  
  std::vector<std::vector<long long int> > a(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < N; j++){
      scanf("%lld", &tmp);
      a[i].push_back(tmp);
    }
  }
  
  std::vector<std::vector<long long int> > ANS(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < N; j++){
      ANS[i].push_back(0);
    }
  }
  
  fast_power(a, N, K, ANS);
  
  long long int ans = 0;
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < N; j++){
      ans += ANS[i][j];
      ans %= MOD;
    }
  }

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

long long int fast_power(std::vector<std::vector<long long int> > &X, long long int N, long long int n, std::vector<std::vector<long long int> > &ANS){
  
  // prepare ANS as unit matrix
  std::vector<std::vector<long long int> > Ans_tmp(N), X_new(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < N; j++){
      ANS[i][j] = 0;
      Ans_tmp[i].push_back(0);
      X_new[i].push_back(0);
    }
  }
  for(long long int i = 0; i < N; i++){
    ANS[i][i] = 1;
  }

  // solve problem
  while(n > 0){
    if(n&1){
      mat_prod(ANS, X, N, Ans_tmp);
      mat_copy(Ans_tmp, N, ANS);
      //ANS = Ans_tmp;
    }
    mat_prod(X, X, N, X_new);
    mat_copy(X_new, N, X);
    //X = X_new;
    n = n>>1;
  }
  
  return 0;
}

long long int mat_prod(std::vector<std::vector<long long int> > &M1, std::vector<std::vector<long long int> > &M2, long long int size, std::vector<std::vector<long long int> > &ANS){
  for(long long int i = 0; i < size; i++){
    for(long long int j = 0; j < size; j++){
      ANS[i][j] = 0;
    }
  }
  for(long long int i = 0; i < size; i++){
    for(long long int k = 0; k < size; k++){
      for(long long int j = 0; j < size; j++){
        ANS[i][j] += M1[i][k] * M2[k][j];
        ANS[i][j] %= MOD;
      }
    }
  }
  
  return 0;
}

int mat_copy(std::vector<std::vector<long long int> > &Orig, long long int size, std::vector<std::vector<long long int> > &Copy){
  for(long long int i = 0; i < size; i++){
    for(long long int j = 0; j < size; j++){
      Copy[i][j] = Orig[i][j];
    }
  }
  return 0;
}



Measured memory_bytes: 384
a, b = map(int, input().split())

print('100 100')

flip = a > b

if flip:
    a, b = b, a

f = [['#' for _ in range(100)] for __ in range(100)]

i, j = (0, 0)

for _ in range(b-1):
    f[i][j+1] = '.'
    f[i+1][j+1] = '.'
    f[i+1][j] = '.'

    j += 2

    if j > 98:
        j = 0
        i += 2

i, j = (99, 0)

if b == 1:
    a += 1

for _ in range(a-1):
    f[i][j] = '.'
    j += 2

    if j > 98:
        j = 0
        i -= 2

if flip:
    for i in range(100):
        f[i] = list(map(lambda x: '.' if x == '#' else '#', f[i]))

for row in f:
    print(''.join(row))


Measured memory_bytes: 9156
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int H, W;
	cin >> H >> W;

	vector<string> image(H);
	rep(i, H) cin >> image[i];

	for (int i = 0; i < H; i++) {
		cout << image[i] << endl;
		cout << image[i] << endl;
	}

	return 0;
}

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

inline bool has3(int n){
	while(n != 0){
		if(n%10 == 3){
			return true;
		}
		n /= 10;
	}
	return false;
}

int main(){
	int n;
	cin >> n;
	for(int i = 3; i <= n; i++){
		if(i%3 == 0 || has3(i)){
			cout << " " << i;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3088
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, p) = i.read2::<usize, usize>();
    writeln!(o, "{}", solve(n, p)).unwrap();
}
fn solve(n: usize, mut p: usize) -> usize {
    if n == 1 {
        return p;
    }
    let mut result = 1;
    let end = (p as f64).powf(1.0 / n as f64) as usize + 1;
    for i in 2..end {
        let mut count = 0;
        while p % i == 0 {
            count += 1;
            p /= i;
        }
        if count > 0 {
            result *= i.pow((count / n) as u32);
            if p == 1 {
                break;
            }
        }
    }
    result
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4476
/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/


#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    vector <int> v;
    int n,i,x,sum=0,cn=0;
    cin >> n;
    for(i=0; i<2*n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    for(i=0; i<2*n; i+=2)
    {
        sum += v[i];

    }
    cout << sum << endl;
}

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


    solve();

}
/**
Test Case :

**/



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

const int MOD = 1e9 + 7;

struct mint {
  long long x;
  mint(long long x = 0) :x((x%MOD + MOD) % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 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 res(*this);
    return res /= a;
  }
};

int main() {
  int N; cin >> N;
  vector<long long> x(N); rep(i, N) cin >> x[i];
  vector<mint> f(N + 1);
  f[0] = 1;
  rep(i, N) {
    f[i + 1] = f[i] * (i + 1);
  }
  mint ans = 0;
  mint tmp = 0;
  for (int i = 1; i < N; i++) {
    ans *= i;
    tmp = tmp * i + f[i - 1];
    ans += tmp * (x[i] - x[i - 1]);
  }

  cout << ans.x << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  string s;cin>>s;
  int n=s.size();
  int a;
  rep(i,n){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  int z;
  rep(i,n){
    if(s[n-i-1]=='Z'){
      z=n-i-1;
      break;
    }
  }
  cout(z-a+1);

  return 0;
}

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

int main(){
    int r,c;
    cin >> r >> c;
    int t[r+1][c+1] = {0};
    
    for(int i = 0; i < r; i++){
        int sumx = 0;
        for(int j = 0; j < c; j++){
            cin >> t[i][j];
            sumx += t[i][j];
        }
        t[i][c] = sumx;
    }
    
    for(int i = 0; i <= c; i++){
        int sumy = 0;
        for(int j = 0; j < r; j++){
            sumy += t[j][i];
        }
        t[r][i] = sumy;
    }
    
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            cout << t[i][j];
            if(j != c) cout << " ";
            else cout << endl;
        }
    }
    return 0;
}


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

vector<int> par;

void init(int n){
    for(int i=0; i<n; i++) par.at(i) = i;
}

int root(int x){
    if(par.at(x) == x){
        return x;
    }else{
        return par.at(x) = root(par[x]);
    }
}

bool same(int x, int y){
    return root(x) == root(y);
}

void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return;
    par.at(x) = y;
}

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    par.resize(N);
    init(N);
    vector<int> A(M), B(M), C(K), D(K);
    for(int i=0; i<M; i++) cin >> A.at(i) >> B.at(i);
    for(int i=0; i<K; i++) cin >> C.at(i) >> D.at(i);

    for(int i=0; i<M; i++) unite(A.at(i) - 1, B.at(i) - 1);

    vector<int> group_cnt(N, 0);
    for(int i=0; i<N; i++) group_cnt.at(root(i))++;

    vector<int> friend_cnt(N, 0);
    for(int i=0; i<M; i++){
        friend_cnt.at(A.at(i) - 1)++;
        friend_cnt.at(B.at(i) - 1)++;
    }
    
    vector<int> block_cnt(N, 0);
    for(int i=0; i<K; i++){
        int Ci = C.at(i) - 1, Di = D.at(i) - 1;
        if(same(Ci, Di)){
            block_cnt.at(Ci)++;
            block_cnt.at(Di)++;
        }
    }

    for(int i=0; i<N; i++){
        cout << group_cnt.at(root(i)) - friend_cnt.at(i) - block_cnt.at(i) - 1;
        if(i < N - 1) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 6892
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

int n;

const int maxn = 1e6 + 5;

int trie[maxn][2];
char s[maxn];
long long L;
int tot;
bool vis[maxn];
void insert(char *str, int len){
    int cur = 0;
    for(int i = 0;i < len;i++){
        int ch = str[i] - '0'; 
        if(trie[cur][ch] == -1){
            trie[cur][ch] = ++tot;
            memset(trie[tot], -1, sizeof(trie[tot]));
        }
        cur = trie[cur][ch];
    }
    vis[tot] = true;
}

long long dfs(int u, long long depth){
    //cout << u << " " << depth << endl;
    if(u == -1){
        long long tmp = L + 1 - depth;
        return (tmp & (-tmp));
    }
    if(vis[u]){
        return 0;
    } 
    long long ans = 0;
    ans ^= dfs(trie[u][0], depth + 1);
    ans ^= dfs(trie[u][1], depth + 1);
    return ans;
}


int main(){
    cin >> n >> L;
    tot = 0;
    memset(trie[tot], -1, sizeof(trie[tot]));
    memset(vis, false, sizeof(vis));
    for(int i = 1;i <= n;i++){
        scanf("%s", s);
        int len = strlen(s);
        insert(s, len);
    }
    long long res = dfs(0, 0);
    if(res != 0){
        cout << "Alice" << endl;
    }else{
        cout << "Bob" << endl;
    }
    return 0;
}


Measured memory_bytes: 6528
fn main() {
    let n = read::<usize>();
    let mut red: Vec<(usize, usize)> = Vec::new();
    let mut blue: Vec<(usize, usize)> = Vec::new();
    for _ in 0..n {
        let (x, y) = read_tuple();
        red.push((x, y));
    }
    for _ in 0..n {
        let (x, y) = read_tuple();
        blue.push((x, y));
    }

    println!("{}", solve(red, blue));
}

const INF: usize = 1000;

fn solve(mut red: Vec<(usize, usize)>, mut blue: Vec<(usize, usize)>) -> usize {
    red.sort_by(|a, b| b.0.cmp(&a.0)); // desc
    blue.sort_by(|a, b| a.0.cmp(&b.0)); // asc

    let mut cnt = 0;
    for i in 0..red.len() {
        let (a, b) = (red[i].0, red[i].1);

        let mut ymin = INF;
        let mut index = INF;
        for j in 0..blue.len() {
            let (c, d) = (blue[j].0, blue[j].1);
            if a < c && b < d {
                if d < ymin {
                    ymin = d;
                    index = j;
                }
            }
        }

        if index != INF {
            cnt += 1;
            blue[index] = (INF, INF);
        }
    }
    cnt
}

#[test]
fn test1() {
    let red = vec![(2, 0), (3, 1), (1, 3)];
    let blue = vec![(4, 2), (0, 4), (5, 5)];
    assert_eq!(2, solve(red, blue));
}

#[test]
fn test2() {
    let red = vec![(0, 0), (1, 1), (5, 2)];
    let blue = vec![(2, 3), (3, 4), (4, 5)];
    assert_eq!(2, solve(red, blue));
}

#[test]
fn test3() {
    let red = vec![(2, 2), (3, 3)];
    let blue = vec![(0, 0), (1, 1)];
    assert_eq!(0, solve(red, blue));
}

#[test]
fn test4() {
    let red = vec![(0, 0), (7, 3), (2, 2), (4, 8), (1, 6)];
    let blue = vec![(8, 5), (6, 9), (5, 4), (9, 1), (3, 7)];
    assert_eq!(5, solve(red, blue));
}

#[test]
fn test5() {
    let red = vec![(0, 0), (1, 1), (5, 5), (6, 6), (7, 7)];
    let blue = vec![(2, 2), (3, 3), (4, 4), (8, 8), (9, 9)];
    assert_eq!(4, solve(red, blue));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_tuple() -> (usize, usize) {
    let v = read_vec::<usize>();
    (v[0], v[1])
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string s, t;
	
	cin >> s >> t;
	
	reverse(s.begin(), s.end());
	
	if (s == t) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(void){
  int N, M, C;
  cin>>N>>M>>C;
  int B[M], A[N][M];
  for(int i(0);i<M;i++){
    cin>>B[i];
  }
  for(int i(0);i<N;i++){
    for(int j(0);j<M;j++){
      cin>>A[i][j];
    }
  }
  int s(0);
  int c(0);
  for(int i(0);i<N;i++){
    for(int j(0);j<M;j++){
      s+=A[i][j]*B[j];
    }
    s+=C;
    if(s>0)c++;
    s=0;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    char ch;
    int x,c[26]= {0};
 
    while(scanf("%c",&ch)!=EOF)
    {
        if(ch>='A' && ch<='Z')
        {
            x=ch-'A';
            c[x]+=1;
        }
        else if(ch>='a' && ch<='z')
        {
            x=ch-'a';
            c[x]+=1;
        }
    }
 
    for(x=0,ch='a'; x<26; x++,ch++)
    {
        printf("%c : %d\n",ch,c[x]);
    }
    return 0;
}


Measured memory_bytes: 2088
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
  int a,b;scanf("%d %d",&a,&b);
  string s;cin >> s;
  if(s.size() == a + b + 1 and s[a] == '-'){
      for(int i = 0;i < s.size();i++){
          if(i != a and s[i] == '-'){
              cout << "No" << endl;
              return 0;
          }
      }
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




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

	cout << (N+1)/2 << endl;
}

Measured memory_bytes: 384
N, T = [int(i) for i in input().split()]
Cost = [[int(i) for i in input().split()] for j in range(N)]
tmp = []
for c, t in Cost:
    if t <= T:
        tmp.append(c)
ans = 'TLE' if len(tmp) == 0 else min(tmp)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int M;

int main() {
  ll dSum = 0, d = 0;
  cin >> M;
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    dSum += a * b;
    d += b;
  }
  cout << (dSum - 1) / 9 + d - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        final int C = sc.nextInt();
        int[][] A = new int[3][C+1];
        int[][] D = new int[C+1][C+1];
        int[][] B = new int[3][C+1];
        int ans = Integer.MAX_VALUE;
        for(int i = 1;i <= C;i++)   for(int j = 1;j <= C;j++)   D[i][j] = sc.nextInt();
        for(int i = 1;i <= N;i++){
            for(int j = 1;j <= N;j++){
                int r = (i+j)%3;
                int cij = sc.nextInt();
                A[r][cij]++;
            }
        }
        for(int i = 0;i < 3;i++){
            for(int j = 1;j <= C;j++){
                for(int k = 1;k <= C;k++){
                    B[i][j] += D[k][j]*A[i][k];
                }
            }
        }
        for(int i = 1;i <= C;i++){
            for(int j = 1;j <= C;j++){
                for(int k = 1;k <= C;k++){
                    if(i != j && i != k && j != k){
                        ans = Math.min(ans, B[0][i]+B[1][j]+B[2][k]);
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 78060
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int ans = 0;
    for(int i=0; i<2; ++i){
        int h, w;
        cin >> h >> w;
        ans = max(ans, h * w);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 105;
const int MAXV = 2 * MAXN * MAXN;
const LL INF = (LL)1e9 + 5;
const LL MOD = 1000000007;
 
struct Flow {
    struct Edge{
        int to,cap,rev;
        Edge(int a,int b,int c) {
        	to = a; cap = b; rev = c;
		}
    };
	// IMPORETANT, MAXV != MAXN
    vector<Edge> G[MAXV];
    int V, flow[MAXV];
    void init(int _V){
        V = _V;
        for(int i=0; i<=V; i++) G[i].clear();
    }
 
    void add_edge(int f,int t,int c, bool directed){
    	int s1 = G[f].size(), s2 = G[t].size();
        G[f].push_back(Edge(t,c,s2));
		G[t].push_back(Edge(f,c*!directed,s1));
    }
 
    int dfs(int v, int t) {
        if(v == t) return flow[t];
        for(Edge &e : G[v]){
            if(e.cap==0||flow[e.to]!=-1) continue;
            flow[e.to] = min(flow[v], e.cap);
            int f = dfs(e.to, t);
            if (f!=0) {
                e.cap -= f;
                G[e.to][e.rev].cap += f;
                return f;
            }
        }
        return 0;
    }
 
    int max_flow(int s,int t){
        int ans = 0, add = 0;
        do {
        	fill(flow,flow+V+1,-1);
        	flow[s] = INF;
        	add = dfs(s, t);
        	ans += add;
		} while (add != 0);
        return ans;
    }
};
 
int R, C, sr, sc, tr, tc;
char mp[MAXN][MAXN];
Flow mf;
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
 
	cin >> R >> C;
	
	mf.init(R + C + 5);
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			int u = i, v = j + R;
			char ch;
			cin >> ch;
			mp[i][j] = ch;
			if (ch == 'o') {
				mf.add_edge(u, v, 1, false);
			}
			else if (ch == 'S') {
				mf.add_edge(u, v, INF, false);
				sr = i;
				sc = j;
			}
			else if (ch == 'T') {
				mf.add_edge(u, v, INF, false);
				tr = i;
				tc = j;
			}
		}
	}
	
	if (sr == tr || sc == tc) {
		cout << "-1\n";
		return 0;
	}
	
	int ans = mf.max_flow(sr, tr);
	cout << ans << '\n';
 
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include<list>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N;
llong A[100100];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	llong a = 0;
	for (int i = 0; i < N; i++) {
		a = A[i] - a;
	}

	a /= 2;

	for (int i = 0; i < N; i++) {
		cout << 2 * a << '\n';
		a = A[i] - a;
	}
	return 0;
}

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

int gcd(int x,int y){
    if(y==0)return x;
    x=x%y;
    gcd(y,x);
}
main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0;
    rep(i,n) {
        cin>>a[i];
        sum=sum+a[i];
    }
    int sum1=0;
    rep(i,n){
        sum1+=a[i];
        if(sum1>=(sum/2))break;
    }
    int sum2=0;
    for(int i=n-1;i>0;i--){
        sum2+=a[i];
        if(sum2>=(sum/2))break;
    }
    int b=min(sum1,sum2);
    cout<<2*b-sum<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		double[] p = new double[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextDouble();
		}

		double ret = 0;
		double max = 0;
		for (int i = 0; i < k; i++) {
			ret += (1.0 + p[i]) / 2.0;
		}
		max = ret;
		for (int i = k; i < n; i++) {
			ret -= (1.0 + p[i - k]) / 2.0;
			ret += (1.0 + p[i]) / 2.0;
			max = Math.max(max, ret);
		}
		System.out.println(max);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 160424
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M, K = MAP()
A = [0] + LIST()
B = LIST()

a = list(accumulate(A))
b = list(accumulate(B))

ans = 0
for i in range(N+1):
	if a[i] <= K:
		ans = max(ans, i + bisect(b, K-a[i]))
print(ans)


Measured memory_bytes: 130780
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = (int) 2e5 + 100;
vector <int> g[2][N];

int h[2][N];
int up[2][N];
bool mark[N];
int s[2];

int smallDist(int t, int a, int b)
{
    int ans = 0;
    while (ans < 3 && a != b)
    {
        if (h[t][a] > h[t][b])
        {
            a = up[t][a];
            ans++;
        }
        else
        {
            b = up[t][b];
            ans++;
        }
    }
    if (ans < 3 && a != b) throw;
    return ans;
}


void dfs(int t, int v, int par, int ch)
{
    h[t][v] = ch;
    up[t][v] = par;
    for (int to : g[t][v])
    {
        if (to == par)
            continue;
        dfs(t, to, v, ch + 1);
    }
}

int n;

void readG(int t)
{
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        g[t][a].push_back(b);
        g[t][b].push_back(a);
    }
    dfs(t, s[t], s[t], 0);
}

int answer = 0;

void dfsAns(int v, int par)
{
    answer = max(answer, h[1][v]);
    if (mark[v])
    {
        answer = N;
        return;
    }
    for (int to : g[0][v])
    {
        if (to == par)
            continue;
        answer = max(answer, h[1][to]);
        if (h[0][to] < h[1][to])
            dfsAns(to, v);
    }
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    scanf("%d%d%d", &n, &s[0], &s[1]);
    s[0]--;
    s[1]--;

    readG(0);
    readG(1);

    for (int v = 0; v < n; v++)
        for (int to : g[0][v])
        {
            //eprintf("%d %d : %d\n", v, to, smallDist(1, v, to));
            if (smallDist(1, v, to) >= 3)
            {
                mark[v] = true;
                mark[to] = true;
            }
        }

    dfsAns(s[0], s[0]);

    if (answer >= N)
        answer = -1;
    else
        answer *= 2;
    printf("%d\n", answer);


	return 0;
}




Measured memory_bytes: 36860
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node
{
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key)
{
    Node *cur = nil->next;
    while (cur != nil && cur->key != key)
    {
        cur = cur->next;
    }
    return cur;
}

void init()
{
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList()
{
    Node *cur = nil->next;
    int isf = 0;
    while ( 1 )
    {
        if (cur == nil ) break;
        if (isf++ > 0 ) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t)
{
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst()
{
    deleteNode(nil->next);
}

void deleteLast()
{
    deleteNode(nil->prev);
}

void deletekey(int key)
{
    deleteNode(listSearch(key));
}

void insert(int key)
{
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next=x;
    x->prev = nil;
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++)
    {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') 
        { 
            insert(key); np++; size++;
        }
        else if (com[0] == 'd')
        {
            if (strlen(com) > 6)
            {
                if (com[6] == 'F')
                {
                    deleteFirst();
                } 
                else if (com[6] == 'L')
                {
                    deleteLast();
                }
            }
            else
            {
                deletekey(key);
                nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}


Measured memory_bytes: 34012
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i) = 0; i < (n); i++)

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  rep(i, k){
    if(i % 2 == 0){
      if(a % 2) a--;
      a /= 2;
      b += a;
    }
    else {
      if(b % 2) b--;
      b /= 2;
      a += b;
    }
  }
  cout << a << " " << b << endl;
}	

Measured memory_bytes: 256