akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#define N 2005
using namespace std;

int n,m, mx, c, s[N][N];
char a[N][N];
int main()
{
	int i, j;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		scanf ("%s", &a[i][1]);
	}
	for (i = 1; i<= n; i++) {
		c = 0;
		for (j = 1; j <= m; j++) {
			if (a[i][j] == '#') c = 0;
			else {
				c++;
				s[i][j] += c;
			}
		}
		c = 0;
		for (j = m; j >= 1; j--) {
			if (a[i][j] == '#') c = 0;
			else {
				c++;
				s[i][j] += c;
			}
		}
	}
	for (j = 1; j <= m; j++) {
		c = 0;
		for (i = 1; i <= n; i++) {
			if (a[i][j] == '#') c = 0;
			else {
				c++;
				s[i][j] += c;
			}
		}
		c = 0;
		for (i = n; i >= 1; i--) {
			if (a[i][j] == '#') c = 0;
			else {
				c++;
				s[i][j] += c;
			}
		}
	}
	for (i =1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			if (a[i][j] != '#') mx = max(mx, s[i][j] - 3);
		}
	}
	cout << mx;
    return 0;
}


Measured memory_bytes: 19840
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int A,B; cin >> A >> B;
    for (int i = 1; i <= 500000; i++) {
        int p = i*108/100 - i;
        int q = i*110/100 - i;
        if (p==A && q == B) {
            cout << i << ln;
            return 0;
        }
    }

    cout << -1 << ln;
}


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

int main() {
	int n; scanf("%d", &n);

	vector <vector <int> > g(n + 1);

	for(int i = 1; i < n; i++) {
		int a, b; scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int ans = 0;

	function < int(int, int) > dfs = [&] (int u, int p) {
		int a = 0, b = 0;
		for(int v : g[u]) {
			if(v != p) {
				int l = dfs(v, u);

				if(l > a) {
					b = a;
					a = l;
				}

				else if(l > b)
					b = l;
			}
		}

		ans = max(ans, a + b + 1);
		return a + 1;
	};

	dfs(1, -1);

	printf(2 - (ans % 3) == 0 ? "Second\n" : "First\n");
	return 0;
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;

  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 20; j++) {
      if (i * 4 + j * 7 == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int m,n,s,d;
    scanf("%d", &m);
    n=m;
    s=0;
    while (n!=0) {
        d = n % 10;
        n = n / 10;
        s = s + d;
    }
    if(m%s==0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MAX_V 100000
using namespace std;
int m,w[100001];
vector<int> vv[100001];
bool S[100001];
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];
int C[100001],F[100001],U[100001],ans;
bool UU[100001];

void DFS(int p,int pr){
  if(S[p])return;
  S[p]=1;
  for(int i=0;i<vv[p].size();i++){
    int np=vv[p][i];
    if(pr!=np){
      G[p].push_back(np);
      rG[np].push_back(p);
      DFS(np,p);
    }
  }
}

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++)if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++)if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
  for(int v=0;v<V;v++)if(!used[v])dfs(v);
  memset(used,0,sizeof(used));
  int k=0;
  for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],k++);
  return k;
}

bool DFS1(int p){
  if(U[p])return 0;
  U[p]=1;
  bool f=F[cmp[p]]>=2;
  for(int i=0;i<G[p].size();i++)
    f|=DFS1(G[p][i]);
  ans+=w[p]*f;
  return UU[p]=f;
}
bool UUU[100001];
int DFS2(int p){
  if(UUU[p])return 0;
  UUU[p]=1;
  int res=0;
  
  for(int i=0;i<G[p].size();i++)
    res=max(res,DFS2(G[p][i]));  
  return res+(UU[p]?0:w[p]);
}

int main(){
  cin>>V>>m;
  for(int i=0;i<V;i++)cin>>w[i];
  for(int j=0,a,b;j<m;j++){
    cin>>a>>b;a--,b--;
    vv[a].push_back(b),vv[b].push_back(a);
  }
  DFS(0,-1);
  int t=0;
  for(int i=0;i<V;i++)t+=w[i];
  scc();
  for(int i=0;i<V;i++)F[cmp[i]]++;
  DFS1(0);
  cout<<ans+DFS2(0)<<endl;
  return 0;
}

Measured memory_bytes: 27980
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

hand=["" for _ in range(k)]
point=[0 for _ in range(k)]

for i in range(n):
    index=i%k
    #初めの手（制限なし）
    if index==i:
        if t[i]=="r":
            hand[index]="p"
            point[index]+=p
        elif t[i]=="s":
            hand[index]="r"
            point[index]+=r
        else:
            hand[index]="s"
            point[index]+=s
    #２番目以降の手
    else:
        if t[i]=="r":
            if hand[index]=="p":
                hand[index]="x"
            else:
                hand[index]="p"
                point[index]+=p
        elif t[i]=="s":
            if hand[index]=="r":
                hand[index]="x"
            else:
                hand[index]="r"
                point[index]+=r
        else:
            if hand[index]=="s":
                hand[index]="x"
            else:
                hand[index]="s"
                point[index]+=s

print(sum(point))

Measured memory_bytes: 13032
def passable(road):
    n=len(road)
    for i in range(n-1):
        block=road[i:i+2]
        if block=='##':
            return False
    return True

def safe_place(road):
    n=len(road)
    for i in range(n-2):
        block=road[i:i+3]
        if block=='...':
            return i+1
    return -1

def passEach(A,B,C,D,road):
    if passable(road[A:C+1]) and passable(road[B:D+1]):
        return True
    else:
        return False

def judge(A,B,C,D,S):
    if C<D:
        return passEach(A,B,C,D,S)
    else:
        S2=S[:B]+'#'+S[B+1:]
        if passable(S2[A:C+1]) and passable(S[B:D+1]):
            return True
        S3=S[:D]+'#'+S[D+1:]
        if passable(S3[A:C+1]) and passable(S[B:D+1]):
            return True
        safePlace=safe_place(S[B:D+1])
        if safePlace!=-1 and passEach(A,B,C,safePlace+B,S) and passEach(A,safePlace+B,C,D,S):
            return True
    return False

N,A,B,C,D=map(int,input().split())
S=input()
if judge(A-1,B-1,C-1,D-1,S):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4020
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){

  int N;
  cin >> N;
  int S0=0,S1=0,S2=0,S3=0;

  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    if(s=="AC") S0++;
    else if(s=="WA") S1++;
    else if(s=="TLE") S2++;
    else if(s=="RE") S3++;
  }

  cout << "AC x " << S0 << endl;
  cout << "WA x " << S1 << endl;
  cout << "TLE x " << S2 << endl;
  cout << "RE x " << S3 << endl;

  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
 
int n, m, head[maxn], cnt, dis[maxn], vis[maxn];
struct Graph{int to, nt, C;}e[maxn << 1];
struct Node {
	int dis, u;
	Node(int Dis = 0, int U = 0){dis = Dis; u = U;}
	bool operator < (const Node &t) const { return dis == t.dis ? u < t.u : dis < t.dis; }
};
set<int>S[maxn];
priority_queue<Node>q;
 
inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)){if(ch == '-')f = -1; ch = getchar();}
	while(isdigit(ch)){u = u * 10 + ch - 48; ch = getchar();} return u * f;
}
 
inline void ini(int x, int y, int C) {e[++cnt] = (Graph){y, head[x], C}; head[x] = cnt;}
 
inline void Dij(int s) {
	memset(dis, 0x3f, sizeof(dis));
	memset(vis, 0, sizeof(vis));
	dis[s] = 0; q.push(Node(dis[s], s));
	while(!q.empty()) {
		int now = q.top().u; q.pop();
		if(vis[now])continue; vis[now] = 1;
		for(register int i = head[now]; i; i = e[i].nt) {
			int v = e[i].to, w;
			w = S[now].count(e[i].C) ? 0 : 1;
			if(dis[v] > dis[now] + w) {
				dis[v] = dis[now] + w;
				q.push(Node(-dis[v], v));
				S[v].clear();
				S[v].insert(e[i].C);
			}
			else if(dis[v] == dis[now] + w) S[v].insert(e[i].C);
		}
	}
}
 
int main(){
	n = read(); m = read();
	for(register int i = 1; i <= m; i++){
		int x = read(), y = read(), C = read();
		ini(x, y, C); ini(y, x, C);
	}
	Dij(1);
	cout << (dis[n] == inf ? -1 : dis[n]);
	return 0;
}

Measured memory_bytes: 44792
// ------------------------------------
// Date:2018/ 2/25
// Problem:ABC 049 Thin b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main()
{
  int H,W;
  char ch;
  cin >> H >> W;
  char C[252][252];
  memset(C,'.',sizeof(C));
  REP(hi,H) {
    REP(wi,W) {
      cin >> ch;
      C[2*hi][wi] = ch;
      C[2*hi+1][wi] = ch;
    }
  }
  REP(hi,2*H) {
    REP(wi,W) {
      cout << C[hi][wi];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int a[100100];
ll dp[100100];
int n; 
int main()
{
	cin>>n;
	REP(i,n)
		cin>>a[i];
	dp[0]=0;
	REP(i,n+5)
	{
		if(i)dp[i]=1000000007;
	 } 
	REP(i,n-1)
	{
		dp[i+1]=min(dp[i+1],abs(a[i+1]-a[i])+dp[i]);
		if(i!=n-2)
			dp[i+2]=min(dp[i+2],abs(a[i+2]-a[i])+dp[i]);
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using coord= pair<int, int>;
using idx= pair<coord, int>;

int BFS(const vector<string> &board, coord s, coord g){ // 辺の重みが0/1のときは両端キューを使って重み0の辺を辿るときpush_front, 重み1の辺を辿るときpush_backすると簡単にBFSできる。
  constexpr int TBC= INT_MAX;
  constexpr char block= '#';
  const int H= int(board.size());
  const int W= int(board.at(0).size());

  const vector<coord> diff0= {make_pair(0,-1), make_pair(-1,0), make_pair(1,0), make_pair(0,1) }; // 探索方向
  const vector<coord> diff1= {make_pair(-2,-2), make_pair(-1,-2), make_pair(0,-2), make_pair(1,-2), make_pair(2,-2),
                              make_pair(-2,-1), make_pair(-1,-1),                  make_pair(1,-1), make_pair(2,-1),
                              make_pair(-2, 0),                                                     make_pair(2, 0), 
                              make_pair(-2, 1), make_pair(-1, 1),                  make_pair(1, 1), make_pair(2, 1),
                              make_pair(-2, 2), make_pair(-1, 2), make_pair(0, 2), make_pair(1, 2), make_pair(2, 2)  
                              };

  vector<vector<int>> pushed(H, vector<int>(W, TBC));
  vector<vector<int>> popped(H, vector<int>(W, TBC));
  deque<idx> bfs;
  pushed.at(s.first).at(s.second)= 0;
  bfs.push_front(make_pair(s, 0));

  while( !bfs.empty() ){
    idx pd= bfs.front();
    auto [p, dist]= pd;
    auto [x, y]= p;
    bfs.pop_front();
    if(p==g){
      popped.at(x).at(y)= dist;
      break;
    }
    else if(popped.at(x).at(y) <= dist){
      continue;
    }
    else{
      popped.at(x).at(y)= dist;
      // 徒歩圏内
      for(const auto& [dx,dy]:diff0){
        if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
        else if(board.at(x+dx).at(y+dy)==block){
          continue;
        }
        else if(pushed.at(x+dx).at(y+dy) > dist){
          pushed.at(x+dx).at(y+dy)= dist;
          bfs.push_front(make_pair(make_pair(x+dx, y+dy), dist));
        }
      }
      // ワープ圏内
      for(const auto& [dx,dy]:diff1){
        if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
        else if(board.at(x+dx).at(y+dy)==block){
          continue;
        }
        else if(pushed.at(x+dx).at(y+dy) > dist+ 1){
          pushed.at(x+dx).at(y+dy)= dist+ 1;
          bfs.push_back(make_pair(make_pair(x+dx, y+dy), dist+ 1));
        }
      }
    }
  }

  int ans= (popped.at(g.first).at(g.second)==TBC) ? -1
                                                  : popped.at(g.first).at(g.second);

  return ans;
}


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

  int s1,s2,g1,g2;
  cin >> s1 >> s2 >> g1 >> g2;
  s1--; s2--; g1--; g2--; // 1-indexed -> 0-indexed
  const coord s= make_pair(s1, s2);
  const coord g= make_pair(g1, g2);

  vector<string> board(H);
  for(int h=0; h<H; h++){
    cin >> board.at(h);
  }

  int ans= BFS(board, s, g);
  
  cout << ans << endl;
}

Measured memory_bytes: 13644
"
3. ABC104C - All Green
リンク：　https://atcoder.jp/contests/abc104/tasks/abc104_c
"

# 入力
D, G = gets.split.map(&:to_i)
p = []
c = []
D.times do |i|
  p[i], c[i] = gets.split.map(&:to_i)
end

# Dでbit全探索
# i桁目をp[i]進報で表せば、得点の計算できそう
ans = 100000
(1 << D).times do |i|
  point = 0
  ma = -1
  gap = 0
  num = 0
  tmp = 0
  D.times do |j|
    # i[j]==1なら配点100(j+1)の問題を完全に解く
    if i[j] == 1
      point = point + 100*(j+1) * p[j] + c[j]
      num = num + p[j]
      if point >= G
        ans = [ans, num].min
      end
    else
      ma = [ma, j].max
    end
  end
  # ここまでで全問解く配点の問題は決まった
  # 目標までの差を出す
  gap = G - point
  if ma != -1 && gap > 0
  # 完全に解かない(i[j]==0なるjの最大値)もののうち、
  # 最も高い配点はmaに入ってる配点100(ma+1)点 
    tmp = (gap.to_f / (100*(ma+1)).to_f).ceil #その配点を何問解けば目標達成できるか
    if tmp <= p[ma]-1 # これを満たさない場合は、完全に解く選択がミスってる
      # ここに入ったってことは、maの問題をnumだけ中途半端に解けば目標達成できる
      num = num + tmp
      ans = [ans, num].min
    end
  end
end
puts ans

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

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i <= max(0, (int)(s.length() - t.length())); i++) {
        if (t == s.substr(i, t.length())) {
            cout << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3192
infty = 1000000000
count = 0

def merge(A, left, mid, right):
	global count
	L = A[left:mid]
	R = A[mid:right]
	L.append(infty)
	R.append(infty)
	i = 0
	j = 0
	for k in range(left, right):
		count += 1
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1


def mergeSort(A, left, right):
	if left + 1 < right:
		mid = (left + right) // 2
		mergeSort(A, left, mid)
		mergeSort(A, mid, right)
		merge(A, left, mid, right)


if __name__ == "__main__":
	n = int(input())
	S = list(map(int, input().split()))
	mergeSort(S, 0, n)
	print(' '.join(map(str, S)))
	print(count)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int64_t factorial(int64_t n) {
  if (n == 1) {
    return 1;
  }
  int64_t ans = factorial(n-1);
  return ans*n;
}
int64_t gcd(int64_t a, int64_t b) {
  if (a < b) {
    int64_t tmp = a;
    a = b;
    b = tmp;
  }
  int64_t r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

int main() {
  int64_t n;
  cin >> n;
  vector <int64_t> v(n);
  rep(i, n) cin >> v.at(i);
  int64_t ans = v.at(0);
  rep(i, n) ans = gcd(ans, v.at(i));
  cout << ans << endl;
}

Measured memory_bytes: 1024
A,B,C,X = int(input()),int(input()),int(input()),int(input())
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                count += 1
print(count)

Measured memory_bytes: 3060
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<long long> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


VI L, P, B;
LL p = 0;


void down_layer(LL n, LL x) {
	//cout << n << "(" << L[n] <<")" << " " << x << endl;
	if (x == L[n]) {
		p += P[n];
	} else if (1 < x && x < (L[n] - 1) / 2) {
		down_layer(n - 1, x - 1);
	} else if ((L[n] - 1) / 2 == x) {
		p += P[n - 1];
	} else if ((L[n] + 1) / 2 == x) {
		p += P[n - 1] + 1;
	} else if ((L[n] + 1) / 2 < x && x < L[n] - 1) {
		p += P[n - 1] + 1;
		down_layer(n - 1, x - ((L[n] + 1) / 2));
	} else if (x == L[n] - 1) {
		p += 2 * (P[n - 1]) + 1;
	} else 	if (x <= 1) {
		return;
	} else {
		//cout << "strange\n";
		return;
	}
}


int main() {
	LL N, X;
	cin >> N >> X;

	L.resize(51);
	P.resize(51);
	B.resize(51);
	L[0] = 1;
	P[0] = 1;
	B[0] = 0;
	FOR(i, 1, 51) {
		P[i] = P[i - 1] * 2 + 1;
		B[i] = B[i - 1] * 2 + 2;
		L[i] = P[i] + B[i];
	}

	down_layer(N, X);
	cout << p << endl;
	

	return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
x,y,a,b,c=map(int,sys.stdin.readline().split())
red=list(map(int,sys.stdin.readline().split()))
green=list(map(int,sys.stdin.readline().split()))
color=list(map(int,sys.stdin.readline().split()))
red.sort()
green.sort()
color.sort()
s=0
for i in range(a-x,a):
    s+=red[i]
for i in range(b-y,b):
    s+=green[i]
i,j,k=c-1,a-x,b-y
#print(red,'red')
#print(green,'green')
#print(color,'color')
#print(s,'s',x,'x',y,'y',i,'i',j,'j',k,'k')
while i>=0 and j<a and k<b:
    if color[i]>red[j] and color[i]>green[k]:
        if green[k]>red[j]:
            s-=red[j]
            s+=color[i]
            j+=1
            i-=1
            continue
        else:
            s-=green[k]
            s+=color[i]
            k+=1
            i-=1
            continue
    if color[i]>red[j]:
        s-=red[j]
        s+=color[i]
        i-=1
        j+=1
        continue
    if color[i]>green[k]:
        s-=green[k]
        s+=color[i]
        i-=1
        k+=1
        continue
    i-=1
if i==0:
    print(s)
else:
    while i>=0 and j<a:
        if color[i]>red[j]:
            s-=red[j]
            s+=color[i]
            i-=1
            j+=1
            continue
        i-=1
    while i>=0 and k<b:
        if color[i]>green[k]:
            s-=green[k]
            s+=color[i]
            i-=1
            k+=1
            continue
        i-=1
    print(s)
    
    


Measured memory_bytes: 92516
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>

using namespace std;

const int DIV = 1000000007;

void solve(int test, istream &in) {
    int h1, h2, m1, m2, k;
    in >> h1 >> m1 >> h2 >> m2 >> k;
    int t1 = h1 * 60 + m1;
    int t2 = h2 * 60 + m2;
    int t = t2 - t1;
    if (t < 0)
        t += 60 * 24;
    t -= k;
    printf("%d", t);
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
	return 0;
}



Measured memory_bytes: 3764
from math import gcd
from functools import reduce
k = int(input())

def f(num):
    return reduce(gcd, num)

ans = 0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += f((x,y,z))
print(ans)

Measured memory_bytes: 69596
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  
 
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll hashprime = (ll)31;
 
const int maxn = 5005;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ll h; cin >> h;
  	ll ans = 1;
    ll val = 1;
    while(h > 1){
       ans += (1LL << val);
       h = h >> 1LL;  
       val += 1LL;
    }
    cout << ans << '\n';
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#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
#include <cmath>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

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

	if (N == M) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}

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

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

  vector<int> mochi(n);
  for (int i = 0; i < n; i++) {
    cin >> mochi.at(i);
  }

  vector<int> unique;
  for (int i = 0; i < n; i++) {
    bool flag = true;
    for (int j = 0; j < unique.size(); j++) {
      if (mochi.at(i) == unique.at(j)) {
        flag = false;
      }
    }
    if (flag) {
      unique.push_back(mochi.at(i));
    }
  }
  cout << unique.size() << endl;
}

Measured memory_bytes: 256
/* ex4-2
   Sagzar1993  */

#include <stdio.h>
#include <math.h>

int main(void) {
    int hourLen, minuteLen, hour, minute;  //時針と分針の長さ、現在の時刻

    scanf("%d %d %d %d", &hourLen, &minuteLen, &hour, &minute); //入力を受け取る

    //０時ちょうどの時の針の角度を０として、現在の針の角度をそれぞれ求める
    double hourAng = (minute / 60.0) * (M_PI / 6) + (hour / 12.0) * (2 * M_PI);
    double minuteAng = (minute / 60.0) * (2 * M_PI);

    double angleDelta = hourAng - minuteAng;  //時針と分針のなす角(符号は任意)

    //余弦定理から辺の長さを求める
    double sideLen = sqrt(pow(hourLen, 2.0) + pow(minuteLen, 2.0) - 2 * hourLen * minuteLen * cos(angleDelta));

    printf("%.10f\n", sideLen); //相対誤差が10^-9以下になるように出力

    return 0;
}

Measured memory_bytes: 2532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int INF = 1e9;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    for (int i = 0; i < h; i++) cin >> s[i];
    ll ans = INF;
    for (int bit = 0; bit < (1 << h - 1); bit++) {
        ll cnt = __builtin_popcount(bit);
        int nb = bit | (1 << h - 1);
        vector<int> prev(10, 0);
        bool div = false;
        bool over = false;
        for (int j = 0; j < w; j++) {
            vector<int> cur(10);
            if (div) {
                cnt++;
                for (int i = 0; i < 10; i++) cur[i] = 0;
            } else {
                for (int i = 0; i < 10; i++) cur[i] = prev[i];
            }
            int idx = 0;
            for (int i = 0; i < h; i++) {
                if (s[i][j] == '1') cur[idx]++;
                if (cur[idx] > k) {
                    if (div){
                        over = true;
                        break;
                    } 
                    div = true;
                    break;
                }
                if (nb & (1 << i)) idx++;
                if (i == h - 1 && div) div = false;
            }
            if (over) break;
            if (div) {
                j--;
                continue;
            } else {
                for (int i = 0; i < 10; i++) prev[i] = cur[i];
            }
        }
        if (over) continue;
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Text;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            for (int i = -1000; i < 1000; i++)
            {
                for (int j = -1000; j < 1000; j++)
                {
                    if (X == (long)Math.Pow(i,5) - (long)Math.Pow(j, 5))
                    {
                        Console.WriteLine(i.ToString() + " " + j.ToString());
                        return;
                    }
                }
            }
        }
        
    }
}

Measured memory_bytes: 27792
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define ll long long
#define vpll vector<pair<ll,ll> >
#define vpii vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,b) memset(a , b , sizeof a );
#define M 1000000007
#define bs(a,b,x) binary_search(a,b,x)
template<typename T>
T fact(T n)
{
    // to find factorial
    return (n==1 || n==0) ? 1: n * fact(n - 1);
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
      int x,n;
      cin>>x>>n;
      if(n==0)
      {
          cout<<x<<endl;
          return 0;
      }
      int a[n];
      for(int i=0;i<n;i++) cin>>a[i];
      sort(a,a+n);
      int i=0;
      while(1)
      {
          if( !binary_search(a,a+n,x-i) )
          {
              cout<<x-i<<endl;
              break;
          }
          if( !binary_search(a,a+n,x+i) )
          {
              cout<<x+i<<endl;
              break;
          }
          i++;
      }
    
    return 0;
}



Measured memory_bytes: 3600
s = input()
x,y = map(int,input().split())
count = 0
d = []
s = s.split('T')
d = [len(x) for x in s]

if len(d) == 0:
    d.append(0)
if len(d) == 1:
    d.append(0)
dpx = [d[0]]
dpy = [d[1],-d[1]]
for i in range(2,len(d)):
    di = d[i]
    trans = set()
    if i%2==0:
        for xj in dpx:
            trans.add(xj+di)
            trans.add(xj-di)
        dpx = trans
    else:
        for yj in dpy:
            trans.add(yj+di)
            trans.add(yj-di)
        dpy = trans
ans = (x in dpx)&(y in dpy)

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3816
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    n = int(input())
    a = list(map(int,input().split()))
    d = {}
    for i in range(n):
        if not a[i] in d:
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    subans = 0
    for i in d.values():
        if i >= 2:
            subans += i*(i-1)//2
        else:
            continue
    for i in range(n):
        if d[a[i]] >= 2:
            print(subans-(d[a[i]]*(d[a[i]]-1)//2)+((d[a[i]]-1)*(d[a[i]]-2)//2))
        else:
            print(subans)

if __name__ == "__main__":
    main() #endline===============================================

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef long double ld;

//ある値がvector内の要素に含まれているか否か判定する
int vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance(vec.begin(), itr);
    if (index != vec.size()) { // 発見できたとき
        return 1;
    } else { // 発見できなかったとき
        return 0;
    }
}

struct edge_t {
    int dest;
    int weight;
};

struct vertex_t {
    vector<edge_t> edges;
    vector<int> weight;

    // for dijkstra
    bool done; // confirm or not
    int cost;  // now cost
    int from;

    bool operator<(const vertex_t &another) const { // priority --> min
        return another.cost < cost;                 // order(cost)
    }

    bool operator>(const vertex_t &another) const { // priority --> min
        return another.cost > cost;                 // order(cost)
    }

    bool operator==(const vertex_t &another) const {
        return another.cost == cost; // order(cost)
    }

    vertex_t() {
        cost = INF;
        done = false;
    }
};

int bellman_ford(vector<vertex_t> &graph, int size, int start) {
    int i, j, k, count = 0;
    bool flag = false;
    graph[start].cost = 0;
    REP(i, size) {
        REP(j, size) {
            vertex_t cur = graph[j];
            for (edge_t edge : cur.edges) {
                if (cur.cost + edge.weight < graph[edge.dest].cost) {
                    if (i == size - 1)
                        flag = true;
                    graph[edge.dest].cost = cur.cost + edge.weight;
                }
            }
        }
    }
    if (flag) {
        return 1;
    } else {
        return 0;
    }
}

class tree_t {
public:
    bool is_leaf;
    tree_t *right;
    tree_t *left;

    tree_t() {
        is_leaf = false;
        right = NULL;
        left = NULL;
    }
};

////////////////////////// let's code! /////////////////////////////

int i, j, k;

///// variables frequent to use /////

int main() {

    int a;
    string s;

    cin >> a >> s;

    if (a >= 3200) {
        cout << s;
    } else {
        cout << "red";
    }
};

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//

int n;
int a[15];

int solve(int i, int pro) {

    if (i == n) {
        if (pro == 0) return 1;
        return 0;
    }
    
    int res;
    if (a[i] % 2 == 0) res = solve(i+1, 0) + 2 * solve(i+1, pro);
    else res = 2 * solve(i+1, 0) + solve(i+1, pro);
    return res;
}



int main(void) {
    
    cin >> n;
    rep(i,n) cin >> a[i];
    out(solve(0, 1));
    
    return 0;
}






Measured memory_bytes: 256
#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 repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
const int mod = 1000000007;
const int INF = 1e12;
template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

double PI = acos(-1.0);
int x[110], y[110];
double p[210];

signed main(){
    int n;
    cin >> n;
    rep(i, 0, n){
        cin >> x[i] >> y[i];
    }
    rep(i, 0, n){
        int id = 0;
        rep(j, 0, n){
            if(i == j) continue;
            p[id++] = atan2(y[j] - y[i], x[j] - x[i]);
        }
        sort(p, p + id);
        rep(j, 0, id) p[j + id] = p[j] + 2 * PI;
        double res = 0.0;
        rep(j, 0, id){
            if(p[j + 1] - p[j] > PI) res = p[j + 1] - p[j] - PI;
            // res = max(res, p[j] + PI - p[(j + id - 1)]);
        }
        printf("%.10f\n", res / (2.0 * PI));
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int N;
vector<vector<Pii> > G;
bool ans[100010];

void dfs(int v,int p){
  for(Pii u:G[v])if(u.first!=p){
    ans[u.first] = ans[v]^(u.second&1);
    dfs(u.first,v);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  G.resize(N);
  repeat(i,N-1){
    int u,v,w;cin>>u>>v>>w;u--;v--;
    G[u].push_back({v,w});
    G[v].push_back({u,w});
  }
  dfs(0,-1);
  repeat(i,N){
    cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 7936
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] p = new int[m];
        int[] y = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        ArrayList<MM> mk = new ArrayList<>();
        HashMap<Integer, Integer> mm = new HashMap<>();
        for (int i = 0; i < m; i++) {
            mk.add(new MM(i, p[i], y[i]));
        }
        Collections.sort(mk);
        String[] out = new String[m];

        for (int i = 0; i < m; i++) {
            MM pk = mk.get(i);
            if (mm.containsKey(pk.p)) {
                out[pk.id] = String.format("%06d%06d", pk.p, mm.get(pk.p) + 1);
                mm.put(pk.p, mm.get(pk.p) + 1);
            } else {
                out[pk.id] = String.format("%06d%06d", pk.p, 1);
                mm.put(pk.p, 1);
            }
        }

        for (int i = 0; i < m; i++) {
            System.out.println(out[i]);
        }

    }

    static class MM implements Comparable<MM> {
        int id;
        int p;
        int y;

        MM(int a, int b, int c) {
            id = a;
            p = b;
            y = c;
        }

        @Override
        public int compareTo(MM o) {
            if (this.p == o.p)
                return this.y - o.y;
            return this.p - o.p;
        }
    }

}


Measured memory_bytes: 132992
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int xcomp(pair<LL, LL>& a, pair<LL, LL>& b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first < b.first;
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

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

	vector<bool> now(100001, false);
	now[0] = true;

	LL sum = 0;

	REP(i, N) {
		LL A;
		cin >> A;

		sum += A;

		vector<bool> next(now.size(), false);
		REP(j, now.size()) {
			if (now[j]) {
				if (j + A < next.size()) {
					next[j + A] = true;
				}
				if (j - A >= 0) {
					next[j - A] = true;
				}
				else {
					next[-(j - A)] = true;
				}
			}
		}

		REP(j, now.size()) {
			now[j] = next[j];
		}
	}

	LL hoge=1145141919;
	REP(i, now.size()) {
		if (now[i]) {
			hoge = i;
			break;
		}
	}

	if (sum % 2 == 0) {
		cout << (sum + hoge) / 2 << endl;
	}
	else {
		cout << (sum + hoge) / 2 << endl;
	}

}

Measured memory_bytes: 384
def z(x,y):
    if x > y:
        return(x-y)
    else:
        return(y-x)
N,X,Y = map(int,input().split())
X -= 1
Y -= 1
A = [0] * N
for i in range(N):
    for j in range(i+1,N):
        a = min(j-i,z(i,X) + 1 + z(j,Y))
        A[a] += 1
for i in range(N-1):
    print(A[i+1])

Measured memory_bytes: 48092
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
	string s;

	cin >> s;

	int table[3] = { 1,1 << 1,1 << 2 };

	int bias = (int)'a';

	int ans = 0;

	for (int i = 0; i < 3; i++)
	{
		ans |= table[s[i] - bias];
	}

	if (ans == (1 | 2 | 4))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LIM 1+2+4+8+16+32+64+128
using namespace std;
typedef long long int ll;
typedef struct{
  int per;
  int ko;
  int kyoda;
  int konoko;
}TRE;
typedef pair<int,int>P;
int main(){
  ll x;
  while(1){
    cin>>x;
    if(x==0){
      break;
    }
    for(int qq=0;qq<x;qq++){
      int x[8];
      for(int i=0;i<8;i++){
	cin>>x[i];
      }
      int a=0,b=0,c=0,d=0;
      a+=x[0]*x[4];
      b+=x[0]*x[5];
      c+=x[0]*x[6];
      d+=x[0]*x[7];     
      b+=x[1]*x[4];
      a-=x[1]*x[5];
      d+=x[1]*x[6];
      c-=x[1]*x[7];
      c+=x[2]*x[4];
      d-=x[2]*x[5];
      a-=x[2]*x[6];
      b+=x[2]*x[7];
      d+=x[3]*x[4];
      c+=x[3]*x[5];
      b-=x[3]*x[6];
      a-=x[3]*x[7];
      cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
    }
  }
  return(0);
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-10;
const int MOD = 1000000007;

#define X real()
#define Y imag()

typedef complex<double> P;
struct L{
	P p1, p2;
	L(P p1, P p2):p1(p1), p2(p2){}
	L(){}
};
istream& operator>>(istream &is, P &p) {
	double x, y;
	is >> x >> y;
	p = P(x, y);
	return is;
}
inline int sig(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
inline double norm(const P &p){return p.X*p.X+p.Y*p.Y;}
inline double inp(const P& a, const P& b){return (conj(a)*b).X;}
inline double outp(const P& a, const P& b){return (conj(a)*b).Y;}


int T;

int main(){
	ios::sync_with_stdio(false);
	cin >> T;
	while(T--){
		P p1, p2, p3, p4;
		cin >> p1 >> p2 >> p3 >> p4;
		puts(!sig(outp(p2-p1, (p4-p3))) ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1224