akhauriyash/Code-Regression huggingface dataset:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    a = sorted(nl(), reverse=True)
    c = a[0]
    n -= 2
    for x in a[1:]:
        if n == 0:
            break
        if n == 1:
            c += x
            n -= 1
        else:
            c += x * 2
            n -= 2
    print(c)
    return

solve()


Measured memory_bytes: 31208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		int n = Integer.parseInt(tmpArray[0]);
		int m = Integer.parseInt(tmpArray[1]);

		Node[] array = new Node[n];

		for(int i = 0; i < n; i++){
			array[i] = new Node(i + 1);
		}

		for(int i = 0; i < m; i++){
			int index = Integer.parseInt(br.readLine()) - 1;

			array[index].priority = i;
		}

		Arrays.sort(array);

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

	}

}

class Node implements Comparable<Node>{
	int key;
	int priority = -1;

	Node(int key){
		this.key = key;
	}

	@Override
	public int compareTo(Node node) {
		return node.priority - this.priority;
	}
}



Measured memory_bytes: 74160
# -*- coding: utf-8 -*-
import sys

def main():
	N, M = map(int, input().split(" "))
	
	WU = WeightedUnionFind(N)
	ans = "Yes"
	for tmp in range(M):
		L, R, D = map(int, input().split(" "))
		L -= 1
		R -= 1
		if WU.is_same(L, R):
			if WU.diff(L, R) != D:
				ans = "No"
		else:
			WU.union(L, R, D)
	
	print(ans)
		
class WeightedUnionFind(object):
	def __init__(self, n=1):
		self.par = [i for i in range(n)]
		self.rank = [0 for _ in range(n)]
		# 親への重みを管理
		self.weight = [0 for _ in range(n)]
		
	# x が属するグループを探索
	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			y = self.find(self.par[x])
			# 親への重みを追加
			self.weight[x] += self.weight[self.par[x]]
			self.par[x] = y
			return self.par[x]
		
	# x と y のグループを結合
	def union(self, x, y, w):
		rx = self.find(x)
		ry = self.find(y)
		# xの木の高さ < yの木の高さ
		if self.rank[rx] < self.rank[ry]:
			self.par[rx] = ry
			self.weight[rx] = w - self.weight[x] + self.weight[y]
		# xの木の高さ ≧ yの木の高さ
		else:
			self.par[ry] = rx
			self.weight[ry] = -w - self.weight[y] + self.weight[x]
			# 木の高さが同じだった場合の処理
			if self.rank[rx] == self.rank[ry]:
				self.rank[rx] += 1
	
	# x と y が同じグループがどうか
	def is_same(self, x, y):
		return self.find(x) == self.find(y)
		
	# x から yへの重みは？
	def diff(self, x, y):
		return self.weight[x] - self.weight[y]
	
if __name__ == "__main__":
	main()
	

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        double n, d;
        cin >> n >> d;
        cout << int(ceil(n / (d * 2 + 1))) << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b < c+d){
    cout << "Right" << endl;
  }else if(a+b == c+d){
    cout << "Balanced" << endl;
  }else if(a+b > c+d){
    cout << "Left" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;

const int N=200005;

int n,a[N],b[N],pts[N],pre[N],nxt[N];
bool vis[N];
LL m;

int main()
{
	scanf("%d%lld",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=n;i>=1;i--)
	{
		nxt[i]=pre[a[i]];pre[a[i]]=i;
		if (!nxt[i]) pts[i]=i;
		else pts[i]=pts[nxt[i]+1];
	}
	if (pts[1]==0) return 0;
	int x=1,tot=0;
	while (1)
	{
		if (vis[x]) break;
		b[++tot]=x;
		vis[x]=1;
		if (x) x=pre[a[pts[x]]]+1;
		else x=1;
		if (x>n) x=0;
	}
	if (m>tot)
	{
		int l=1;
		while (b[l]!=x) l++,m--;
		m=(m-1)%(tot-l+1)+1;
		m+=l-1;
	}
	for (int i=pts[b[m]];i;i=pts[i+1]) printf("%d ",a[i]);
	return 0;
}

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

int A[100005], dp[100005];

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

    int N;
    cin >> N;

    cout << 1LL * N * (N-1) / 2 << "\n";
    return 0;
}


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

void a(){
    string s,t;
    cin >> s >> t;
    cout << t << s;
}

void b(){
    ll a,b,k;
    cin >> a >> b >> k;

    if(a<=k){
        cout << 0 << " ";
        if(b>= k-a){
            cout << b-(k-a);
        }else{
            cout << 0;
        }
    }else{
        cout << a-k << " " << b;
    }
}

void c(){
    ll x;
    cin >> x;
    vector<int> so;
    so.push_back(2);
    for (int i=3;i<x*x;i++) {
        auto it = so.begin();
        bool f = true;
        while(it!=so.end()){
            if(i%*it++==0){
                f=false;
                break;
            }
        }
      	if(*--it<x){
        	if(f) so.push_back(i);
        }else{
          	cout << *it;
        	break;
        } 
    }
}

bool is_prime(int x){
    if(x<=1) return false;
    for (int i=2;i*i<=x;i++) {
        if(x%i==0) return false;
    }
    return true;
}
void c_ans(){
    int x;
    cin >> x;
    while(!is_prime(x)) x++;
    cout << x;
}


int main()
{
    c_ans();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int num[30];
int main()
{
    string s;
    cin>>s;
    for(int i=0;s[i];i++){
        num[s[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        if(num[i]%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


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


int dfs(int y, int x, vector<VI>& ice){
    ice[y][x] = 0;
    int res = 0;
    rep(i, 0, 4){
        int Y = y+dy[i];
        int X = x+dx[i];
        if(isin(Y, 0, n) and isin(X, 0, m) and ice[Y][X]) chmax(res, dfs(Y, X, ice));
    }
    ice[y][x] = 1;
    return res+1;
}


signed main(){
    while(cin >> m >> n, m+n){
        vector<VI> ice(n, VI(m));
        rep(i, 0, n) rep(j, 0, m) cin >> ice[i][j];
        int ans = 0;
        rep(i, 0, n) rep(j, 0, m) if(ice[i][j]) chmax(ans, dfs(i, j, ice));
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3172
import numpy as np
import types
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
Xi = 1
for x in Xs:
  for d in range(N):
    a = np.array(x)
    b = np.array(Xs[d])
    l = np.linalg.norm(a-b)
    if l.is_integer() and l>0:
      result.append(l)
print(int(len(list(result))/2))


Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;cin>>N;
    string S,T;cin>>S>>T;
    for(int i=0;i<N;i++){
        for(int j=0;j<N-i;j++){
            if(S[j+i]!=T[j]){
                break;
            }
            else if(j==N-i-1){
                cout<<N+i;
                return 0;
            }
        }
    }
    cout<<2*N<<endl;
    return 0;
}


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

int main(){
	int N,M;
  cin>>N;
  vector<int> time(N);
  int sum=0;
  
  for(int i=0;i<N;i++){
    cin>>time.at(i);
    sum+=time.at(i);
  }

  cin>>M;
  vector<int> drink(2);
  for(int i=0;i<M;i++){
    cin>>drink.at(0)>>drink.at(1);
 	 for(int j=0;j<N;j++){
    	if(drink.at(0)-1==j)
          cout<<sum-time.at(j)+drink.at(1)<<endl;
     }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FOOR(i,a,b) for(int i=a;i<=b;i++)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int N;
VE A[100001];
int D[100001];
int DD[100001];
bool F[100001];
bool FF[100001];
int main(){
  cin>>N;
  FOR(i,0,N-1){
    int a,b;
    cin>>a>>b;
    A[a].PB(b);
    A[b].PB(a);
  }
  queue<int> que;
  que.push(1);
  while(que.size()){
    int x=que.front();
    que.pop();
    FOR(i,0,(int)A[x].size()){
      if(!F[A[x][i]]){
        D[A[x][i]]=D[x]+1;
        F[A[x][i]]=true;
        que.push(A[x][i]);
      }
    }
  }
  que.push(N);
  while(que.size()){
    int x=que.front();
    que.pop();
    FOR(i,0,(int)A[x].size()){
      if(!FF[A[x][i]]){
        DD[A[x][i]]=DD[x]+1;
        FF[A[x][i]]=true;
        que.push(A[x][i]);
      }
    }
  }
  int FE=0,SU=0;
  FOR(i,1,N+1){
    (D[i]<=DD[i]?FE++:SU++);
  }
  cout<<(FE>SU?"Fennec":"Snuke")<<endl;
  return 0;
}


Measured memory_bytes: 6784
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    int n,q;
    cin >> n>> q;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> pi(n+1,-1);
    vector<vector<int>> ps(n);
    rep(i,n){
        int l = pi[a[i]];
        if (l != -1) ps[l].push_back(i);
        pi[a[i]] = i;
    }//赤矢印
    vector<vector<P>> qs(n);//青点
    rep(qi,q) {
        int l, r;
        cin >> l >> r;
        --l; --r;
        qs[l].emplace_back(r,qi);
    }
    vector<int> ans(q);
    BIT<int> d(n);
    for (int x = n-1; x >= 0; --x) {//平面走査
        for (int y : ps[x]) d.add(y,1);
        for (P query : qs[x]) {
            int r = query.first, i = query.second;
            ans[i] = (r-x+1) - d.sum(r);
        }      
    }
    rep(i,q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 60004
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_108
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            long zeroCnt = 0, halfCnt = 0;
            for (int i = 1; i <= n; i++)
            {
                if (i % k == 0) zeroCnt++;
                if (i % k == k / 2) halfCnt++;
            }
            if (k % 2 != 0) halfCnt = 0;

            Console.WriteLine(zeroCnt * zeroCnt * zeroCnt
                + halfCnt * halfCnt * halfCnt);
        }
    }
}


Measured memory_bytes: 11092
R, G, B, N = list(map(int, input().strip().split()))

boxes = [R, G, B]
boxes.sort()
boxes.reverse()

ans = 0
for  a in range(1 + N // boxes[0]):
    for b in range(1 + (N - a*boxes[0]) // boxes[1]):
        if((N - a*boxes[0] - b*boxes[1]) % boxes[2] == 0):
            ans += 1  
print(ans)

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

int main(){
    ll n, k;
    ll ans;
    bool flag=false;
    cin >> n >> k;
    ans = min(n%k, abs(n%k-k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
const long long mod=1e9+7;
typedef pair<int,int> p;
int n,m;
long long ans=0,dp[310][310][310];
vector<p>vec[310];
void update(long long &x,long long y){x=(x+y)%mod;}
 
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,l,r,x;i<=m;i++){
		scanf("%d%d%d",&l,&r,&x);
		vec[r].push_back(p(l,x));
	}
	dp[1][0][0]=1;
	for(int i=1;i<=n;i++){
		int t=vec[i].size()-1,l,x;
		for(int j=0;j<i;j++)
		  for(int k=0;k<=max(0,j-1);k++)
		    for(int p=0;p<=t;p++){
		    	l=vec[i][p].first;x=vec[i][p].second;
				if(x==1&&j>=l)dp[i][j][k]=0;
				else if(x==2&&(k>=l||j<l))dp[i][j][k]=0;
				else if(x==3&&k<l)dp[i][j][k]=0;
		    }
		for(int j=0;j<i;j++)
		  for(int k=0;k<=max(0,j-1);k++){
		  	dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%mod;
		  	dp[i+1][i][k]=(dp[i+1][i][k]+dp[i][j][k])%mod;
		  	dp[i+1][i][j]=(dp[i+1][i][j]+dp[i][j][k])%mod;
		  }
	}
	for(int i=0;i<n;i++)
	  for(int j=0;j<=max(0,i-1);j++)
	    ans=(ans+dp[n][i][j])%mod;
	printf("%lld",((ans+mod)%mod*3)%mod);
	return 0;
}

Measured memory_bytes: 225536
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
	ll n,q;
	cin >> n;
	ll sum = 0;
	vector<ll> A(100000,0);
	vector<ll> S;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		A[k]++;
		sum += k;
	}

	cin >> q;
	for (int i = 0; i < q; i++) {
		ll b, c;
		cin >> b >> c;
		sum += A[b] * c - A[b] * b;
		S.emplace_back(sum);
		A[c] += A[b];
		A[b] = 0;
	}
	for (int i = 0; i < S.size(); i++) {
		cout << S[i] << endl;
	}
	return 0;
	
}


Measured memory_bytes: 5056
def mat_mul(A, B):
    C = [[0]*len(B[0]) for _ in range(len(A))]
    
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(A[0])):
                C[i][j] += A[i][k]*B[k][j]
                C[i][j] %= MOD
    
    return C

def mat_pow(A, n):
    res = [[0]*len(A) for _ in range(len(A))]
    
    for i in range(len(A)):
        res[i][i] = 1
    
    while n>0:
        if n&1:
            res = mat_mul(res, A)
        
        n >>= 1
        A = mat_mul(A, A)
    
    return res

N, K = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
MOD = 10**9+7
res = mat_pow(a, K)
ans = 0

for i in range(N):
    for j in range(N):
        ans += res[i][j]
        ans %= MOD

print(ans)

Measured memory_bytes: 42172
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r, c;

    r = sc.nextInt();
    c = sc.nextInt();

    int[][] ans = new int[r + 1][c + 1];
    for (int i = 0; i < r; i++)
      for (int j = 0; j < c; j++)
        ans[i][j] = sc.nextInt();

    for (int i = 0; i < r; i++)
      for (int j = 0; j < c; j++)
        ans[i][c] += ans[i][j];

    for (int i = 0; i < c; i++) {
      for (int j = 0; j < r; j++) {
        ans[r][i] += ans[j][i];
      }
      ans[r][c] += ans[r][i];
    }

    for (int i = 0; i < r + 1; i++) {
      for (int j = 0; j < c + 1; j++) {
        System.out.print(ans[i][j]);
        if (j != c)
          System.out.print(" ");
      }
      System.out.println();
    }
  }
}

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

using namespace std;

int main(void)
{
	string s;
	bool y=false,m=false,d=false;

	cin>>s;

	int j = atoi(s.c_str());
	if(j<=2019) y=true;
	for(int i=0;i<5;i++){
		s[i]=s[i+5];
		s[i+5]='\0';
	}


	int k = atoi(s.c_str());
	if(y&&k<5) m=true;
	for(int i=0;i<3;i++){
		s[i]=s[i+3];
		s[i+3]='\0';
	}

	int t = atoi(s.c_str());
	if(y&&m&&t<=30) d=true;

	if(y&&m&&d) cout<<"Heisei"<<endl;
	else cout<<"TBD"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin >> n;
 int i=1;
 int count =0;
 while(i<=n)
 {
     int x = i;
     int c = 0;
     while(x>0)
     {
         x/=10;
         c++;
     }
     if(c%2)
        count++;
        i++;
 }
 cout << count;
}


Measured memory_bytes: 256
public class Main{
    public static void main(String[] args){
	for(int i = 1 ; i <= 9 ; i++){
	    for(int j = 1 ; j <= 9 ; j++){
		System.out.printf("%dx%d=%d\n" ,i,j,i*j);
	    }
	}
    }
}

Measured memory_bytes: 17968
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define mp(x,y) make_pair(x,y)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int,int>
#define INF 1<<29
#define MAX 101010
using namespace std;

int a[MAX],p[MAX/2];

void solve(){
 int n;
 for(;;){
  cin>>n;
  if(!n) break;
  int ans=0;
  FOR(i,n) cin>>a[i];
  for(int i=0;2*i+1<n;i++){
   if(a[2*i]==a[2*i+1]){
    p[i]=a[2*i];
    continue;
   }
   p[i]=a[2*i+1];
   int t=i-1;
   while(t>=0&&p[t]!=p[i]) p[t--]=p[i];
  }
  for(int i=0;2*i+1<n;i++){
   ans+=(p[i]^1)<<1;
  }
  if(n&1&&a[n-1]==0) ans++;
  cout<<ans<<endl;
 }
}

int main(){
 solve();
 return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>
#include <string.h>
//prototype
int main(void);

int main(void){

  char s_str[101];
  char p_str[101];
  char judge_str[100];
  int s_len, p_len;
  int i, j, k;

  scanf("%s %s", s_str, p_str);

  //Get the length of a string
  s_len = strlen(s_str);
  p_len = strlen(p_str);


  //Judge by the number of p_len
  for(i = 0; i < s_len; i++) {
    for(j = 0; j < p_len; j++) {
      k = i + j;
      //greater than s_len
      if(k >= s_len){
        k -= s_len;
      }
      judge_str[j] = s_str[k];
    }

    judge_str[j] = '\0';  //terminal character

    //found the same string
    if(strcmp(judge_str, p_str) == 0) {
      printf("Yes\n");
      return 0;
    }
  }
  //not found the same string
  printf("No\n");

  return 0;
}



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

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

Node *nil;

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

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

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

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

int main(){
    init();
    int cmdn, key;
    scanf("%d", &cmdn);
    for (int i = 0; i < cmdn; i++) {
        char cmd[20];
        scanf("%s%d", cmd, &key);
        if (cmd[6] == 'F') {
            deleteFirst();
        }
        else if (cmd[6] == 'L') {
            deleteLast();
        }
        else {
            if (cmd[0] == 'i') {
                insert(key);
            }
            else if (cmd[0] == 'd') {
                deleteKey(key);
            }
        }
    }
    printList();
    return 0;
}


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

bool kaibun(string a){
    string a_for,a_back;
    for(int i=0;i<a.size();i++){
        a_for += a[i];
    }
    for(int i=a.size()-1;i>=0;i--){
        a_back += a[i];
    }

    if(a_for==a_back) return true;
    else return false;
}

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

    int n = (s.size()-1)/2;

    string s1 = s.substr(0,n);
    string s2 = s.substr(n+1,n);

    if(kaibun(s) && kaibun(s1) && kaibun(s2)){
        cout << "Yes" << endl;
        return 0;
    }else{
        cout << "No" << endl;
        return 0;
    }

}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int N,M;
vector<vector<pair<int,int>>> E;
vector<int> dist;
vector<bool> visited;

bool dfs(int n,int d) {
    if (visited[n] && d != dist[n]) return false;
    if (visited[n] && d == dist[n]) return true;

    visited[n] = true;
    dist[n] = d;
    REP(i,E[n].size()) {
        if ( ! dfs(E[n][i].fi , d + E[n][i].se) ) return false;
    }
    return true;
}

int main (void) {
    cin>>N>>M;
    E.resize(N);
    dist.resize(N);
    visited.resize(N);
    fill(ALL(dist),-inf);
    fill(ALL(visited),false);
    REP(i,M) {
        int l,r,d;
        cin>>l>>r>>d;
        l--;r--;
        E[l].pb(make_pair(r,d));
        E[r].pb(make_pair(l,-d));
    }
    REP(i,N) {
        if (!visited[i]) {
            if (!dfs(i,0)) {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 11008
N,A=map(int,input().split())
x=list(map(int,input().split()))
x=[i-A for i in x]
dp=[[0]*50*N*2 for i in range(N+1)]
dp[0][50*N]=1
for i in range(1,N+1):
    for j in range(50*N*2):
        n=j-x[i-1]
        if n>=0 and n<50*N*2:
            dp[i][j]=dp[i-1][j]+dp[i-1][n]
        else:
            dp[i][j]=dp[i-1][j]
    #else:
        #print(dp[i])

print(dp[N][50*N]-1)

Measured memory_bytes: 5612
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

int a[2][100000+5];
int main() {
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i%2][(int)(i/2)]);

    vector< pair<int,int> > tmp[2];
    for (int i = 0; i < 2; i++) {
        sort(a[i], a[i] + n/2);
        //for (int j = 0; j < n/2; j++) printf("%d\n", a[i][j]);

        int c = 0;
        int m = a[i][0];
        for (int j = 0; j <= n/2; j++) {
            if (j == n/2) {
                tmp[i].push_back(make_pair(c, m));
            }else if (m != a[i][j]) {
                tmp[i].push_back(make_pair(c, m));
                m = a[i][j];
                c = 1;
            } else {
                c++;
            }
        }

        sort(tmp[i].begin(), tmp[i].end(), greater< pair<int,int> >());
        //printf("1st - %d %d\n", tmp[i][0].first, tmp[i][0].second);
        //printf("2nd - %d %d\n", tmp[i][1].first, tmp[i][1].second);
    }

    int ans;
    if (tmp[0][0].second != tmp[1][0].second) {
        ans = n - tmp[0][0].first - tmp[1][0].first;
    } else {
        ans = n;
        if (tmp[0].size() == 1 && tmp[1].size() == 1) {
            ans = n/2;
        } else {
            for (int i = 0; i < 2; i++) {
                if (tmp[i].size() == 1) continue;
                for (int j = 1; j < tmp[i].size(); j++) {
                    if (tmp[i][j].second != tmp[(i+1)%2][0].second) {
                        ans = min(ans, n - tmp[(i+1)%2][0].first - tmp[i][j].first);
                        break;
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <vector>

#define INF 1 << 21

using namespace std;

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

    int N, M;
    int dist[100][100];
    
    for (int i = 0; i < 100; ++i) {
        for (int j = 0; j < 100; ++j) {
            dist[i][j] = i == j ? 0 : INF;
        }
    }

    cin >> N >> M;
    int a[M], b[M], c[M];
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i];
        --b[i];
        dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
    }

    //Warshall-Floyd Algorithm
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = M;
    for (int i = 0; i < M; ++i) {
        bool is_shortest = false;
        for (int j = 0; j < N; ++j) {
            if(dist[j][a[i]]+c[i] == dist[j][b[i]])
                is_shortest=true;
        }
        if(is_shortest)
            ans--;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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


int main(void)
{

	int n;
	cin >> n;
	vector<int> a(n);

	rep(i, n) cin >> a[i];

	vector<int> before(n + 1);  //iまでの最大値
	vector<int> after(n + 1);  //i以降の最大値


	before[0] = 0;

	for (int i = 1; i < n; i++) before[i] = max(before[i - 1], a[i - 1]);

	after[n-1] = 0;

	for (int i = n - 2; i >= 0; i--) after[i] = max(after[i + 1], a[i +1]);



	rep(i, n)
	{
		cout << max(before[i], after[i]) << endl;
	}
}



Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)
const int MAX = INT_MAX;
using namespace std;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}



int main() {

    int N = in();
    
    multiset<ll> mst;
    
    
    ll temp;
    
    for(auto i = 0; i<N; i++){
        temp = lin();
        
        mst.insert(temp);
    }
    
    ll pre = -1;
    unsigned long long count = 0;
    
    for(auto it = mst.begin(); it != mst.end(); it++){
        
        if (*it == pre) continue;
        
        if (*it > mst.count(*it)){
            count +=  mst.count(*it); ///減らしても帳尻が合わないなら全て消す
        }else{
            count += mst.count(*it) - *it;    /// 余っている分を減らす。
        }
    
        pre = *it;
        
    }
    
    cout << count << endl;
    
    return 0;
}


                          
                        




Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii();
    ll ret=0;
    REP(i,1,N+1){
        ll a=ii();
        if(i%2==1&&a%2==1){
            ret++;
        }
    }
    oie(ret);

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll a,b,c;
int32_t main(){
CODE_START;
cin>>a>>b>>c;
if(a-b==b-c){
    rc("YES");
}else rc("NO");
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int q1, b, c1, c2, q2;
	while (scanf("%d %d %d %d %d", &q1, &b, &c1, &c2, &q2), q1)
	{
		int aizu = 0, normal;
		for (int i = min(q2, b/c1); i > 0; --i)
		{
			int t = (b - i*c1) / c2;
			if (i + t >= q1)
			{
				aizu = i;
				normal = t;
				break;
			}
		}
		if (aizu)
			printf("%d %d\n", aizu, normal);
		else
			puts("NA");
	}

	return 0;
}

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

using namespace std;

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

int64_t s[100'000];

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        cin >> s[i];
    }

    int64_t result = -1e15;
    for (int c = 1; c <= n - 1; c++) {
        int r = (n - 1) % c;
        int a = r;
        int64_t score = 0;
        for (int i = a; i <= n - 1; i += c) {
            score += s[i];
        }
        for (int i = c; i <= n - 1 - r; i += c) {
            score += s[i];
        }

        for (int a = r + c; a <= n - 1; a += c) {
            score -= s[a - c];
            score -= s[n - 1 - (a - c)];
            if (r != 0 || 2 * a - c >= n - 1) {
                result = max(result, score);
            }
        }
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1024
# include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 100005;
# define INF 1000000001
# define MOD 1000000007
# define pb push_back
# define mp make_pair
typedef pair<int, int> Pi;

int a[20], b[20], c[20];
struct Node{
    int v, id;
}node[20];
int n;

bool check() {
    for (int i = 0; i < n-1; ++i) if (node[i].v > node[i+1].v) return false;
    return true;
}
int sol() {
    int res = 0;
    for (int i = 0; i < n; ++i) for (int j = i+1; j < n; ++j) {
        if (node[i].id > node[j].id) ++res;
    }
    return res;
}
int main ()
{
    int ans = INF;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    int top = (1<<n)-1;
    for (int i = 0; i <= top; ++i) {
        for (int j = 0; j < n; ++j) {
            if ((i>>j)&1) c[j] = 1, node[j].v = b[j+1], node[j].id = j;
            else c[j] = 0, node[j].v = a[j+1], node[j].id = j;
        }
        bool flag = true;
        for (int j = 0; j < n; ++j) {
            int mi = 100, p = j;
            for (int k = j; k < n; ++k) {
                if (mi > node[k].v && abs(node[k].id - j) % 2 == c[node[k].id]) {
                    mi = node[k].v;
                    p = k;
                }
                else if (mi == node[k].v && abs(node[k].id - j) % 2 == c[node[k].id]) {
                    if (node[p].id > node[k].id) p = k;
                }
            }
            if (mi == 100) {
                flag = false;
                break;
            }
            else swap(node[j], node[p]);
        }
        if (flag == false) continue;
        if (check()) {
            //puts("H");
            //for (int j = 0; j < n; ++j) cout << node[j].v << " ";
            //cout << endl;
            //if (sol() == 0) cout << node[0].id << " " << node[1].id << endl;
            ans = min(ans, sol());
        }
    }
    printf(ans == INF ? "-1" : "%d\n", ans);
    return 0;
}


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

#define rep(i, n) for(int i=0;i<n;i++)
#define REPR(i, n) for(int i=n;i>0;i--)
#define FOR(i, j, n) for(int i=j;i<n;i++)
#define COUT(n) cout<<n<<"\n"

typedef long long ll;
const int INF = 1e9;

ll dot(ll n, ll *x, vector<ll> y){
    ll ans = 0;
    rep(i, n){
        ans += x[i] * y[i];
    }
    return ans;
}

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

    ll n; cin >> n;
    ll a[n], ans[n];
    rep(i, n) cin >> a[i];
/*
    vector<ll> tmp(n*n);
    rep(i, n){
        rep(j, n){
            if (j%2 == 1) tmp[i*n + j]=-1;
            else tmp[i*n + j] = 1;
        }
    }

    rep(i, n){
        ans[i] = dot(n, a, vector<ll>(tmp.begin()+ n*n - n - i, tmp.begin()+n*n - i));
    }*/

    int tmp = 0;
    rep(i, n) tmp = a[i] - tmp;

    ans[0] = tmp/2;

    for (int i=1; i<n-1; i++){
        ans[i] = a[i-1] - ans[i - 1];
    }
    ans[n-1] = a[n-1] - ans[0];
    rep(i, n) cout << 2 * ans[i] << " ";
    COUT("");

    return 0;
} 

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s, d; Weight w;
	Edge() {};
	Edge(int s, int d, Weight w) : s(s), d(d), w(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	Graph g(N);
	vector<int> deg(N);
	vector<int> a(N), b(N); rep(i, 0, N) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
		addEdge(g, a[i], b[i]);
		deg[a[i]]++;
		deg[b[i]]++;
	}

	vector<int> prev(N, -1);
	int v = -1;
	function<bool(int, int)> dfs = [&](int u, int p) {
		prev[u] = p;
		for (auto &e : g[u]) {
			if (e.d == p)continue;
			if (prev[e.d] != -1) {
				prev[e.d] = u;
				v = u;
				return true;
			}
			if (dfs(e.d, u))
				return true;
		}
		return false;
	};

	dfs(0, -1);

	vector<bool> is_cycle(N);
	vector<int> cycle = { v };
	while (cycle.front() != prev[cycle.back()])
		cycle.push_back(prev[cycle.back()]);
	dump(cycle);
	for (auto u : cycle) {
		is_cycle[u] = true;
	}


	auto query = [&](int c, int d) {
		if (!is_cycle[c] || !is_cycle[d]) {
			cout << 1 << endl;
		}
		else {
			cout << 2 << endl;
		}
	};
	int Q; cin >> Q;
	rep(q, 0, Q) {
		int c, d; cin >> c >> d; c--, d--;
		query(c, d);
	}

	//rep(i, 0, N) {
	//	rep(j, i + 1, N) {
	//		query(i, j);
	//	}
	//}
	return 0;
}


Measured memory_bytes: 16748
f[168],z[]={24,23,25,12,36,11,13,35,37,22,26,48},x,s,m;main(y){for(;s?++f[y*12+x+z[--s]]:~scanf("%d,%d,%d",&x,&y,&s)?s=s*4+1:0;);for(x=100,s=23;++s<142;s%12<10?m=fmax(m,f[s]),f[s]&&--x:0);x=!printf("%d\n%d\n",x,m);}

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

#define debug(...) fprintf(stderr,__VA_ARGS__)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
const int MAXN=120;
const double eps= 1e-12, PI= acos(-1.0);
int dcmp(double a){	if ( fabs(a)<eps) return 0; return a<0 ? -1 :1;}
struct Point{
	double x, y;
	int id;
	Point operator+(const Point &rhs) const{
		return (Point){x+rhs.x, y+rhs.y};
	}
	Point operator-(const Point &rhs) const{
		return (Point){x-rhs.x, y-rhs.y};
	}
	bool operator<(const Point &rhs) const{
		if ( dcmp(x-rhs.x) !=0) return dcmp(x-rhs.x)<0;
		return dcmp(y-rhs.y)<0;
	}
} p[MAXN], ch[MAXN];

double Cross(Point a, Point b){ return a.x*b.y- a.y*b.x;}
void ConvexHull(Point *p, int n , Point *ch,int &m);
int n,m;
double ans[MAXN];
int main(){
	scanf("%d", &n);
	for (int i=0; i<n; i++){
		scanf("%lf%lf", &p[i].x, &p[i].y); 
		p[i].id= i; ans[i] = 0;
	}
	if ( n==2){
		printf("0.5\n0.5\n");return 0;
	}
	ConvexHull(p, n, ch,m);
	
	for (int i=0; i<m; i++){
		Point pre= ch[i]-ch[(i-1+m)%m], suc= ch[(i+1)%m]-ch[i];
		#ifdef che
		debug("when ch[%d]=(%.3lf, %.3lf), prevector=(%.3lf, %.3lf), sucvector=(%.3lf, %.3lf)\n",
				i,ch[i].x, ch[i].y, pre.x, pre.y, suc.x, suc.y);
		debug("\narcpre= %.7lf, arcsuc= %.7lf\n", atan2(-pre.x,pre.y),atan2( -suc.x,suc.y));
		#endif
		double arc= atan2( -suc.x,suc.y)-atan2(-pre.x,pre.y);
		if ( dcmp(arc)==-1)arc+= 2*PI;
		ans[ ch[i].id] = arc/(2*PI);
	}
	for (int i=0; i<n; i++) printf("%.9lf\n", ans[i]);
	return 0;
}

void ConvexHull(Point *p, int n , Point *ch,int &m){
	sort(p, p+n);
	m=0;
	ch[m++] = p[0]; ch[m++] = p[1];
	for (int i=2; i<n; i++){
		while ( m>=2 && dcmp(Cross(p[i]-ch[m-2], ch[m-1]-ch[m-2]))>=0) --m;
		ch[m++]= p[i];
	}
	int k=m;
	for (int i=n-1; i>=0; i--){
		while (m>k && dcmp(Cross(p[i]-ch[m-2], ch[m-1]-ch[m-2]))>=0) --m;
		ch[m++] = p[i];
	}
	--m;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int w,h;
bool fie[100][100];

int dfs(int y,int x,bool used[100][100]){
	
	int dy[]={1,0,-1,0};
	int dx[]={0,1,0,-1};

	int ret = 0;
	rep(i,4){
		int ddx = x+dx[i];
		int ddy = y+dy[i];
		if( ddx>=0 && ddy>=0 && ddx<w && ddy<h && used[ddy][ddx]==false && fie[ddy][ddx]==1 ){
			used[ddy][ddx]=true;
			ret = max(ret,dfs(ddy,ddx,used)+1);
			used[ddy][ddx]=false;
		}
	}
	return ret;
}

int main(){
	while(cin>>w>>h&&(w||h)){
		
		rep(i,h){
			rep(j,w){
				cin>>fie[i][j];
			}
		}
		
		int ans = 0;
		rep(i,h){
			rep(j,w){
				if(fie[i][j]==0)continue;
				bool used[100][100]={};
				used[i][j]=true;
				ans = max(ans,1+dfs(i,j,used));
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3124
import java.io.*;
        import java.util.Scanner;

public class Main{
    public static void main(String []args) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        int  a = sc.nextInt();
        int  b = sc.nextInt();
        int  c = sc.nextInt();
        int x = b/a;
        if(x>c)
            System.out.println(c);
        else
            System.out.println(x);

    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long ans=LLONG_MAX;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,i+n/i-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

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

string dp[10100];
int match[10] = {2,5,5,4,5,6,3,7,6};

int main(){
    int N,M;cin >> N >> M;
    vector<int> A(M);
    rep(i,M){
        cin >> A[i];
    }
    rep(i,10100)dp[i]="-";
    dp[0]="";
    
    for(int i=0;i<N;i++){
        if(dp[i]=="-")continue;
        for(auto a:A){
            chmax(dp[i+match[a-1]],dp[i]+(char)('0'+a));
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 44928
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 100010;
 
int a[N];
 
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	int ans = 0, nowm = 1e9;
	for(int i = 1; i < n; i++)
	{
		if(a[n] % 2 == 0)
		{
			if(abs(a[i] - a[n] / 2) < nowm)
			{
				nowm = abs(a[i] - a[n] / 2);
				ans = a[i];
			}
		}
		else
		{
			if(abs(a[i] - a[n] / 2) < nowm)
			{
				nowm = abs(a[i] - a[n] / 2);
				ans = a[i];
			}
			if(abs(a[i] - (a[n] / 2 + 1)) < nowm)
			{
				nowm = abs(a[i] - (a[n] / 2 + 1));
				ans = a[i];
			}
		}
	}
	printf("%d %d\n", a[n], ans);
}

Measured memory_bytes: 640
#include <cstdio>
using namespace std;

int main()
{
	int N,num[8],s[8];
	while(scanf("%d", &N), N)
	{
		for(int i=1; i<=N; i++)
			scanf("%d%d", &num[i], &s[i]);
		
		int dp[1001]={0};
		dp[0]=1;
		
		for(int i=1; i<=N; i++)
		{
			bool c[1001]={0};
			c[0]=1;
			for(int j=0; j<s[i]; j++)
			for(int k=1000; k>=0; k--)
			{
				if(k+num[i]>1000) continue;
				if(c[k]!=0) c[k+num[i]]=1;
			}
			
			for(int k=1000; k>=0; k--)
			for(int j=1; j<=s[i]*num[i]; j++)
			{
				if(k+j>1000) continue;
				if(c[j]!=0) dp[k+j]+=dp[k];
			}
		}
		
		int M;
		scanf("%d", &M);
		while(M--)
		{
			int t;
			scanf("%d", &t);
			printf("%d\n", dp[t]);
		}
	}
}

Measured memory_bytes: 0
#include <stdio.h>
int Adj[101][101];

int main()
{
  int n;
  int u,k;
  int v;
  int i,j;


  //number of vertices
  scanf("%d",&n);
  
  //adjacency list

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

    scanf("%d%d",&u,&k);

    for(j=0;j<k;j++){
      
      //v1,v2,v3,.....vk
      scanf("%d",&v);
      
      Adj[u][v]=1;
    }
  }
  
  //output
  for(i=1;i<=n;i++){
    
    for(j=1;j<=n;j++){
      
      if(j>1) printf(" ");
      
      printf("%d",Adj[i][j]);
    }printf("\n");
  }
  return 0;
}

Measured memory_bytes: 640
import Control.Monad
import Control.Applicative
import Data.List

-- String, Int, Char, IO
-- putStrLn
-- e.g.
-- 1
-- [a] <- map read . words <$> getLine => [1] -> a == 1
-- 1
-- a <- readLn
-- 1 2 3
-- lst <- map read . words <$> getLine => [1, 2, 3]
-- 1 2 3
-- [l, m, n] <- map read . words <$. getLine :: IO [Int] => [1, 2, 3]
-- 'a'
-- c <- getChar => c == 'a'

main :: IO()
main = do
  n <- getLine
  let ans = if n!!0 == '9' || n!!1 == '9' then "Yes" else "No"
  putStrLn ans


Measured memory_bytes: 380
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

bool isPalindrome(int k) {
	stringstream ss;
	ss << k;
	string s(ss.str());
	int n = s.length();
	for (int i = 0; i < n/2; i++) {
		if (s[i] != s[n-i-1])
			return false;
	}
	return true;
}

int main() {
	int n;
	cin >> n;
	int min = 10000000, res = 0;
	for (int i = 0; i < 100000; i++) {
		if (isPalindrome(i) and abs(n-i) < min) {
			min = abs(n-i);
			res = i;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<algorithm>
using namespace std;

#define MAXN 100
int N;
int L[MAXN*2+1];

int main(){
    scanf("%d",&N);
    for(int i=1;i<=2*N;i++)
        scanf("%d",&L[i]);
    sort(L+1,L+2*N+1);
    int Ans=0;
    for(int i=1;i<=2*N;i+=2)
        Ans+=L[i];
    printf("%d",Ans);
}


Measured memory_bytes: 128