akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
    const lines = input.split(/\n/);
    const n = Number(lines[0]);
    var area = [];
    lines.slice(1).forEach(line=>{
        area.push(
            line.split(/\s/).map(str=>{return Number(str)})
        );
    });
    var count = 0;
    for(var down = 0; down < n; down++){
        var sum = 0;
        for(var i = 0; i < n; i++){
            if(i <= down){
                sum += area[0][i];
            }
            if(i >= down){
                sum += area[1][i];
            }
        }
        count = Math.max(count,sum);
    }
    console.log(count);
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7756
#include <bits/stdc++.h>
using namespace std; 
int main(){
//  freopen("test.in","r",stdin);
//  freopen("test.out","w",stdout);
	int a,b;
	cin>>a>>b;
	if(a<=b*2) cout<<0;
	else cout<<a-b*2;
    return 0;
}


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

int compare_char(const void* left, const void* right) {
    char *left_char = (char *)left;
    char *right_char = (char *)right;

    return strcmp( left_char, right_char );
}

int main(void)
{
  	int	n;
  	char	s[200002][11];
  	int	i;
  	int	cnt;
  
  	scanf("%d\n", &n);

  	for(i=0; i<n; i++)
    {
      	scanf("%s\n", s[i]);
    }
    
  	qsort(s, n, sizeof(s[0]), compare_char);

  	cnt = 1;
  	for(i=0; i<n-1; i++)
    {
      	if (compare_char(s[i], s[i+1]) != 0)
          	cnt++;
    }
  
  	printf("%d", cnt);
  	return (0);
}

Measured memory_bytes: 5696
#include <iostream>
#include <stdio.h>
#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>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].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 = INT_MAX;
const ll MOD = 1e9+7;


ll gcd(ll x,ll y){
  return y==0? x:gcd(y,x%y);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  cout << s[0]<<s.length()-2<<s.back()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
  string s;
  int n,a,b;
  cin>>n>>a>>b;
  cout<<min(a,b)<<' '<<max(a+b-n,(int)0)<<endl;
}

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

int main(void)
{
  int t, n, a, b, s;
  while (cin >> t, t)
  {
    cin >> n;
    for (int i = s = 0; i < n; ++i)
    {
      cin >> a >> b;
      s += b-a;
    }
    if (s >= t)
      cout << "OK" << endl;
    else
      cout << t-s << endl;
  }
  return 0;
}

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

int main(){
	int n,k,q;
	cin>>n>>k>>q;
	vector<int> p(n,k-q);
	int temp;
	for (int i = 0; i < q; i++) {
		cin>>temp;
		p[temp-1]++;
	}
	for (int i = 0; i < n; i++) {
		if (p[i]>0) {
			cout<<"Yes"<<endl;
		}else {
			cout<<"No"<<endl;
		}
	}
}

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

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

#define MAXN 51
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {printf("0\n"); return 0;}
#define FAIL_1 {printf("-1\n"); return 0;}

int N;
LL K;
int A[MAXN][MAXN];
map<LL,LL> dp[MAXN][MAXN];

LL add(LL a, LL b) {
    return (a+b) % MOD;
}

LL solve(int i, int j, LL k) {
    if (k == 0) return (i == j);
    if (k == 1) return A[i][j];

    if (dp[i][j].find(k) != dp[i][j].end())
        return dp[i][j][k];

    int h = 0;
    //while((1LL<<(h+1)) < k) h++;
    while(((1LL<<h) & k) == 0) h++;

    LL &ret = dp[i][j][k] = 0;
    //LL ret = 0;
    for (int t = 0; t < N; t++) {
        ret = add(ret, dp[i][t][h] * solve(t,j,k-(1LL<<(h))));
        //printf("%d %d %d, dp = %lld, ret = %lld\n",i,t,h,dp[i][t][h], ret);
    }

    //printf("%d %d %lld, ret = %lld\n", i, j, k, ret);
    return ret;
}

int main(int argc, char **argv)
{
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    scanf("%d %lld", &N, &K);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++) {
            scanf("%d", &A[i][j]);
            if(A[i][j]) dp[i][j][0] = 1;
        }

    for (int k = 1; (1LL<<k) <= K; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int t = 0; t < N; t++) {
                    dp[i][j][k] = add(dp[i][j][k], (dp[i][t][k-1] * 
                                      dp[t][j][k-1]) % MOD);
                }
            }
        }
    }

    LL ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            //printf("%d %d\n", i, j);
            ans = add(ans, solve(i,j,K));
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 18816
N = int(input())
p = list(map(int, input().split()))

A = [i + 1 for i in range(N)]

a = 0
for i in range(N):
    if A[i] != p[i]:
        a += 1
ans = 0
if a > 2:
    ans = "NO"
else:
    ans = "YES"
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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


int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N) {
    rep(j, M) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }

  int ans = INF;
  vector<bool> use(M, true);
  rep(i, M) {
    vector<int> cnt(M);
    rep(j, N) {
      rep(k, M) {
        if (!use[A[j][k]])
          continue;
        cnt[A[j][k]]++;
        break;
      }
    }

    int max_sport;
    int max_num = 0;
    rep(j, M) {
      if (chmax(max_num, cnt[j]))
        max_sport = j;
    }

    chmin(ans, max_num);
    use[max_sport] = false;
  }
  cout << ans << endl;
}

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

bool haveStrawberry(std::vector<int> &line)
{
    const int w = line.size();
    for (int col = 0; col < w; col++) {
        if (line[col] != 0) {
            return true;
        }
    }

    return false;
}

void spread(std::vector<int> &line)
{
    const int w = line.size();
    int num = 0;
    for (int col = 0; col < w; col++) {
        if (line[col] != 0) {
            num = line[col];
            break;
        }
    }
    for (int col = 0; col < w; col++) {
        if (line[col] != 0) {
            num = line[col];
        }
        line[col] = num;
    }

    return;
}

void solve(std::vector<std::vector<int>> &s, std::vector<std::vector<int>> &a)
{
    const int h = s.size();
    const int w = s[0].size();
    int copy_from = 0;

    for (int row = 0; row < h; row++) {
        if (haveStrawberry(s[row])) {
            spread(a[row]);
            copy_from = row;
        }
    }

    for (int row = h - 1; row >= 0; row--) {
        if (!haveStrawberry(s[row])) {
            a[row] = a[copy_from];
        } else {
            copy_from = row;
        }
    }

    return;
}

int main(int argc, char *argv[])
{
    int h, w, k;
    std::vector<std::vector<int>> s;
    std::vector<std::vector<int>> a;

    std::cin >> h >> w >> k;

    s.resize(h);
    a.resize(h);
    int count = 1;
    for (int i = 0; i < h; i++) {
        std::string str;
        std::cin >> str;

        s[i].resize(w);
        a[i].resize(w);
        for (int j = 0; j < w; j++) {
            if (str[j] == '#') {
                s[i][j] = 1;
                a[i][j] = count++;
            } else {
                s[i][j] = 0;
                a[i][j] = 0;
            }
        }
    }

    solve(s, a);

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cout << a[i][j] << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}


Measured memory_bytes: 1536
a, b, h, m = gets.split.map(&:to_i)
time1 = 1.0 * (h*60 + m) /720
time2 = 1.0 * m /60
deg = (time1 - time2).abs
deg = 1 - deg if deg > 0.5
p ((a**2) + (b**2) - 2 * a * b * Math.cos(Math::PI * 2 * deg))**0.5


Measured memory_bytes: 14916
#include <stdio.h>
#include <ctype.h>
#define rep(i, n) for (i = 0; i < n; i++)

int count(char *str1, char *str2, int p, int q, int str2_size) {
    int flag, size, p_cp;
    int ans = 0;
    rep(p, 1000) {
        if (str1[p] == '\n') break;
        if (str1[p] == ' ') continue;
        flag = 0;
        size = 0;
        p_cp = p;
        while (1) {
            p_cp++;
            if (str1[p_cp] == ' ' || str1[p_cp] == '\n') {
                if (p_cp - p != str2_size) flag = 1;
                break;
            }
        }
        rep(q, str2_size) {
            // if (str2[q] == '\0') break;
            if (str2[q] != str1[q+p]) {
                flag = 1;
                break;
            } 
        }
        while (1) {
            if (str1[p] == '\n' || str1[p] == ' ') break;
            p++;
        }
        p--;
        if (flag) continue;
        ans++;
    }
    return ans;
}

int main(void) {
    char W[11] = {'\0'};
    char T[1001] = {'\0'};
    int i, j;
    int ans_sum = 0;
    int W_size = 0;
    
    scanf("%s", W);
    rep(i, 10) {
        if (W[i] == '\0') break;
        W_size++;
    }

    while (fgets(T, sizeof(T), stdin) != NULL) {
        char *p;
        for (p = T; *p; p++) *p = tolower(*p);
        ans_sum += count(T, W, i, j, W_size);
    }
    printf("%d\n",ans_sum);
    return 0;
}


Measured memory_bytes: 2056
#include <stdio.h>
#include <stdlib.h>
int main(void){
    long n,m,t,ans;
    scanf("%ld %ld",&n,&m);
    int cnt=0;
    if(n*2>=m){
        ans=m/2;
    }else{
        m=m-n*2;
        t=m/4;
        ans=n+t;
    }
printf("%ld\n",ans);
    return 0;
    }

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N1, N2, N3, N4;
    cin >> N1 >> N2 >> N3 >> N4;
    vector<ll> N{N1,N2,N3,N4};
    sort(N.begin(), N.end());
    if ( N[0]==1
      && N[1]==4
      && N[2]==7
      && N[3]==9
      ){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;

//cout << fixed << setprecision(10);
int searchint(string s, int suuji, int k, int n) {
	int t = 0;
	for (int i = k;i < n;i++) {
		if (s[i] - '0' == suuji) {
			t = 1;
			return i;
		}

	}if (t == 0)return -1;

}

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

	int fir[10], sec[10], thi[10];
	int ans=0;

	for (int j1 = 0;j1 < 10;j1++) {

		fir[j1] = searchint(s, j1, 0, n);
		sec[j1] = fir[j1];
		thi[j1] = fir[j1];
	}
	int seca, thia;

	for (int j1 = 0;j1 < 10;j1++) {
		if (fir[j1] == -1)continue;
		else {
			for (int j2 = 0; j2 < 10;j2++) {
				if (sec[j1] == -1)continue;
				else if (sec[j2] > fir[j1]) {
					for (int j3 = 0; j3 < 10;j3++) {
						if (thi[j3] == -1)continue;
						else if (thi[j3] > sec[j2]) { ans++; }
						else {
							thia = searchint(s, j3, sec[j2] + 1, n);
							if (thia == -1)continue;
							else { ans++; }
						}
					}
				}
				else {
					seca = searchint(s, j2, fir[j1] + 1, n);
					if (seca == -1)continue;
					else {
						for (int j3 = 0; j3 < 10;j3++) {
							if (thi[j3] == -1)continue;
							else if (thi[j3] > seca) { ans++; }
							else {
								thia = searchint(s, j3, seca + 1, n);
								if (thia == -1)continue;
								else { ans++; }
							}
						}
					}
				}
			}
		}
	}

	printf("%d",ans);
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
N,M = map(int,input().split())



def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)

def size(x):
    return -par[find(x)]

a = [0]*M
b = [0]*M
for i in range(M):
    a[i], b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1

# 一つの辺以外を繋いでその辺の両端の点が同じ集合に属していたらその辺は橋ではない
ans = 0
for i in range(M):
    par = [-1] * (N + 1)
    for j in range(M):
        if i != j:
            unite(a[j],b[j])
    if not same(a[i],b[i]):
        ans += 1
print(ans)


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

int main()
{
  int n;
  cin >> n;
  int a = to_string(n).size();
  int ans = 0;
  for (int i = 1; i <= n; i++)
  {
    string b = to_string(i);
    if (b.size() % 2 == 1)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

	
			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long x = inputArray[1];
			var ames = retreiveLongArray();

			long count = 0;
			long taberu;

			//最初の箱をx以下にしておく
			taberu = Math.Max(0,ames[0] - x);
			count += taberu;
			var previous = ames[0] - taberu;
			for (long i = 1; i < N; i++) {
				var goukei = previous + ames[i];
				//必ずi番目の箱から食べるようにする
				taberu = Math.Max(0, goukei-x);
				count += taberu;
				previous = ames[i] - taberu;
			}

			//答えの出力
			var ans = count;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}

Measured memory_bytes: 29404
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    int N=0;
    cin >> N;
    int count=0;
    if(N/100==7){
        count++;
    }
    if(N/10%10==7){
        count++;
    }
    if(N%10==7){
        count ++;
    }
    if(count>0)
    cout << "Yes" << endl;
    else cout << "No"<<endl;
}

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

int main(){
  int A,B,cnt=0;
  cin >> A >> B;
  for(int i=A;i<=B;++i){
    string s = to_string(i);
    if(s.at(0)==s.at(4)&&s.at(1)==s.at(3)){
      ++cnt;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 100000000
#define NUM 1000000007
#define all(x) begin(x), end(x)

int main() {
	int n;
	cin >> n;
	VI d(n);
	for (int i = 0; i < n; i++) cin >> d[i];
	sort(all(d));

	int cnt = 1;
	for (int i = 0; i < n-1; i++) {
		if (d[i] < d[i + 1]) {
			cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),M=in(),X=in(),Y=in();
	vector<ll> x(N+1),y(M+1);
	REP(i,N){
		x[i]=in();
	}
	x[N]=X;
	REP(i,M){
		y[i]=in();
	}
	y[M]=Y;
	sort(ALL(x));
	sort(ALL(y));
	
	cout << (x.back()<y.front() ? "No War" : "War") << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define MOD = 1000000007;
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N; cin >>N;
    vector<int> B(N+1);
    B[0] = B[N] = INT_MAX;
    rep1(i, N) {
        cin >> B[i];
    }

    int ans = 0;
    rep1(i, N+1) {
        ans += min(B[i], B[i-1]);        
    }    

    cout << ans << endl;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

            Console.WriteLine($"{array.Min()} {array.Max()} {array.Sum()}");
        }
    }
}



Measured memory_bytes: 18888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(), k  =sc.nextInt();
		
		int ans= k;
		for(int i=1;i<n;i++){
			ans *= k-1;
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn dfs(adj: &[Vec<usize>], x: usize, y: usize, r: usize) -> usize {
    let mut sum = 0;
    if r > 0 {
        for v in &adj[x] {
            if *v != y {
                sum += dfs(adj, *v, x, r - 1);
            }
        }
    }
    return sum + 1;
}

fn main() {
    let n: usize = get();
    let k: usize = get();
    let mut e: Vec<(usize, usize)> = Vec::new();
    let mut adj: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0 .. n - 1 {
        let x: usize = get();
        let y: usize = get();
        e.push((x - 1, y - 1));
        adj[x - 1].push(y - 1);
        adj[y - 1].push(x - 1);
    }
    let mut ma = 0;
    if k % 2 == 0 {
        for v in 0 .. n {
            ma = max(ma, dfs(&adj, v, n, k / 2));
        }
    } else {
        for (x, y) in e {
            ma = max(ma, dfs(&adj, x, y, k / 2) + dfs(&adj, y, x, k / 2));
        }
    }
    println!("{}", n - ma);
}


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

int main() {
	int h, w;
	cin >> h >> w;
	char c[100][100];
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> c[i][j];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)
			cout << c[i][j];
		cout << endl;
		for (int j = 0; j < w; j++)
			cout << c[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define pii pair<int, int>
#define min3(a,b,c) min(a, min(b, c))
#define max3(a,b,c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mex 200005
vector<int> adj[mex];
int vis[mex];

inline int dfs(int u)
{
    vis[u]=1;
    int ans=1;
    for(int v : adj[u]){
        if(vis[v]!=1) ans+=dfs(v);
    }
    return ans;
}

signed main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n,m; cin>>n>>m;
    for(int i=0;i<m;i++){
        int u,v; cin>>u>>v;
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(vis[i]==0) ans=max(ans,dfs(i));
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 25456
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int l,r,d;
	// nyuryoku
	cin >> l >> r >> d;
	int ans = 0;
	// keisan
	for(int i=l;i<=r;i++){
		if(i%d == 0) ans++;
	}
	// syutsuryoku
	cout << ans;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 100100100;

int main() {
  int N, M, a, b, c, d;
  cin >> N >> M;
  vector<pint> starts(N);
  rep(i, 0, N) {
    cin >> a >> b;
    starts[i] = pint(a, b);
  }
  vector<pint> goals(M);
  rep(i, 0, M) {
    cin >> c >> d;
    goals[i] = pint(c, d);
  }

  rep(i, 0, N) {
    int x1 = starts[i].first, y1 = starts[i].second;
    int ans = 1, mi = abs(x1 - goals[0].first) + abs(y1 - goals[0].second);
    rep(j, 1, M) {
      int x2 = goals[j].first, y2 = goals[j].second;
      int m = abs(x1 - x2) + abs(y1 - y2);
      if (mi > m) {
        mi = m;
        ans = j + 1;
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3600
//Maze Master

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

vector<string> pictureframe(vector<string> md,char fm){
    int w=md[0].size();
    int h=md.size();
    string s(w+2,fm);
    vector<string>picfm(h+2,s);
    rep(i,1,h+1)rep(j,1,w+1)picfm[i][j]=md[i-1][j-1];
    return picfm;
}

signed main (){
    int h,w,ans=0;cin>>h>>w;
    vecrep(h,a,string);
    a=pictureframe(a,'#');
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    queue<p>q;
    rep(i,1,h+1){
        rep(j,1,w+1){
            if(a[i][j]=='#')continue;
            q.push(mp(i,j));
            vector<vector<int>>dist(h+2,vector<int>(w+2,-1));
            dist[i][j]=0;
            while(!q.empty()){
                p t = q.front();
                q.pop();
                rep(i,0,4){
                    if(a[t.first+dy[i]][t.second+dx[i]]=='#'||dist[t.first+dy[i]][t.second+dx[i]]!=-1)continue;
                    dist[t.first+dy[i]][t.second+dx[i]]=dist[t.first][t.second]+1;
                    q.push(mp(t.first+dy[i],t.second+dx[i]));
                    ans=max(ans,dist[t.first+dy[i]][t.second+dx[i]]);
                }
            }
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void)
{
	int a,b,c,z;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b && a==c){
		z=1;
	}else if(a!=b && a!=c && b!=c){
		z=3;
	}else{
		z=2;
	}
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 128
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

a = make_divisors(N)
b = make_divisors(N-1)
cnt = 0
for i in a:
    if i == 1:
        continue
    k = N
    while k % i == 0:
        k //= i
    if k % i == 1:
        cnt += 1
ans = len(b) - 1 + cnt
print(ans)

Measured memory_bytes: 3316
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    al = A.pop(-1)
    ar = A.pop(-1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.append(tmp)
    N -= 1
elif A[0] > 0 and A[-1] > 0:
    al = A.pop(0)
    ar = A.pop(0)
    tmp = al - ar
    ans_op.append([al, ar])
    A.insert(0, tmp)
    N -= 1
tmp = A.pop(-1)
if N >= 2:
    tmpl = A.pop(0)
else:
    tmpl = 0
    
for i in range(N-2):
    if A[-1] <= 0:
        ar = A.pop(-1)
        ans_op.append([tmp, ar])
        tmp = tmp - ar
    else:
        ans_op.append([tmpl, tmp])
        tmpl = tmpl - tmp
        tmp = A.pop(-1)
        # A.insert(0, tmp)
ans_op.append([tmp, tmpl])
print(tmp-tmpl)
for op in ans_op:
    print(op[0], op[1])


Measured memory_bytes: 68380
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define MX 500009 
#define INF 100000000009
using namespace std;
 
int main(){
    string s;
    cin>>s;
    ll k=1,forek=0;
    ll ans=0;
    rep(i,s.size()-1){
        if(s[i]==s[i+1])k++;
        else{
            if(s[i]=='<'){
                ans+=(k*(k+1))/2;
                forek=k;
                k=1;
            }else{
                ans+=(k*(k+1))/2;
                ans-=min(k,forek);
                forek=0;
                k=1;
            }
        }
    }
    int i=s.size()-1;
    if(s[i]=='<'){
            ans+=(k*(k+1))/2;
        }else{
            ans+=(k*(k+1))/2;
            ans-=min(k,forek);
        }
    cout<<ans<<endl;
    return 0;    
}

Measured memory_bytes: 900
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int maxv=-1000000000,minv,R[n];
    for(int i=0;i<n;i++){
        cin>>R[i];
    }
    minv=R[0];
    for(int j=1;j<n;j++){
        maxv=max(maxv,R[j]-minv);
        minv=min(minv,R[j]);
    }
    cout<<maxv<<endl;
    return 0;
}



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

int main()
{
ll n ;
cin >> n ;
map<ll,ll> m;
ll sum=0;
rep(i, n){
  ll a;
  cin >> a;
  m[a]++;
  sum+=a;
}
ll q ;
cin >> q ;

rep(i,q){
  ll b , c ;
  cin >> b >> c ;
  sum+=-b*m[b]+c*m[b];
  m[c]+=m[b];
  m[b]=0;
  cout << sum << endl;
  
}

return 0;
}

Measured memory_bytes: 9364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

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


Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st S;
  ci(S);
  ll a = 0;
  rep(bit, 1 << sz(S) - 1){
    ll c = 0;
    rep(i, sz(S) - 1){
      ll b = 0;
      if(bit >> i & 1 == 1){
        repi(j, c, i + 1){
          b *= 10;
          b += S.at(j) - 48;
          c = i + 1;
        }
      }
      a += b;
    }
    ll b = 0;
    repi(j, c, sz(S)){
      b *= 10;
      b += S.at(j) - 48;
    }
    a += b;
  }
  co(a);
}

Measured memory_bytes: 256
N = int(input())
W = []
flag = 0
for i in range(N):
    tmp = input()
    if tmp in W:
        flag = 1
    W.append(tmp)

if flag:
    print("No")
    exit()
    
ans = "Yes"

for i in range(N):
    tmp = W[i]
    if i != 0:
        if tmp[0] != l:
            ans = "No"
            break
    l = tmp[-1]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
/*
int par[50];
int rank_[50];
void init(int n){
  for(int i = 0; i < n; ++i){
    par[i] = i;
    rank_[i] = 0;
  }
}

int find(int x){
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  if(rank_[x] < rank_[y]) par[x] = y;
  else{
    par[y] = x;
    if(rank_[x] == rank_[y]) ++rank_[x];
  }
}


int main(){
  int n;
  while(cin >> n, n){
    vector< vector<int> > V(31);
    int f, d;
    for(int i = 0; i < n; ++i){
      cin >> f;
      for(int j = 0; j < f; ++j){
	cin >> d;
	V[d].push_back(i);
      }
    }
    for(int i = 0; i < 30; ++i){
      cout << i << "??\??? ";
      for(int j = 0; j < V[i].size(); ++j){
	cout << V[i][j] << " ";
      }
      cout << endl;
    }
    init(n);
    bool g = false;
    for(int i = 1; i < 32; ++i){
      if(i > 30){
	cout << -1 << endl;
	break;
      }
      int s = V[i].size();
      for(int j = 1; j < s; ++j)
	unite(V[i][0],V[i][j]);
      g = true;
      for(int j = 1; j < n; ++j){
	if(find(0) != find(j)){
	  g = false;
	}
      }
      for(int j = 0; j < n; ++j) cout << par[j] << " ";
      cout << endl;
      if(g){
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}
*/

int main(){
  int n;
  while(cin >> n, n){
    vector< vector<int> > V(31);
    int f, d;
    for(int i = 0; i < n; ++i){
      cin >> f;
      for(int j = 0; j < f; ++j){
	cin >> d;
	V[d].push_back(i);
      }
    }
    bool M[n][n];
    for(int i = 0; i < n; ++i){
      fill(M[i],M[i]+n,false);
      M[i][i] = true;
    }
    bool g = false;
    for(int i = 0; i < 31; ++i){
      bool t[n];
      fill(t,t+n,false);
      for(int j = 0; j < (int)V[i].size(); ++j){
	for(int k = 0; k < n; ++k){
	  t[k] |= M[V[i][j]][k];
	}
      }
      g = true;
      for(int j = 0; j < n; ++j)
	g &= t[j];
      if(g){
	cout << i << endl;
	break;
      }else{
	for(int j = 0; j < (int)V[i].size(); ++j){
	  for(int k = 0; k < n; ++k){
	    M[V[i][j]][k] = t[k];
	  }
	}
      }
    }
    if(!g) cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <algorithm>

#define MAX_R 1000000000

using namespace std;

int main() {
	int n, a, R = 0, ans = -MAX_R;
	cin >> n;
	cin >> R;
	for (int i = 1; i < n; i++) {
		cin >> a;
		ans = max(a - R, ans);
		if (R > a)
			R = a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    bool flag = false;
    for(int i = 0;i < n;i++)
    {
        char a;
        cin >> a;
        if(a == 'Y')
        {
            flag = true;
        }
    }
    if(flag)
    {
        cout << "Four\n";
    }
    else
    {
        cout << "Three\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            double a = scan.nextDouble();
            double l = scan.nextDouble();
            double x = scan.nextDouble();
            System.out.printf("%.9f\n",Helon(a,l,l) + 2*Helon(l,(l+x)/2.0,(l+x)/2.0));
        }
    }
    
    public static double Helon(double a,double b,double c){
    	double m = 0;
    	double s = (a+b+c)/2.0;
    	m = Math.sqrt(s*(s-a)*(s-b)*(s-c));
    	return m;
    }
}

Measured memory_bytes: 37812
def solve(l, s, t):
    queue = [(1, 0), (0, 1)]

    def gcd(a, b):
        r = a % b
        if r:
            d = a // b
            sb = queue.pop()
            sa = queue.pop()
            queue.append(sb)
            queue.append(tuple(x - d * y for x, y in zip(sa, sb)))
            return gcd(b, r)
        else:
            return b

    ls, lt = len(s), len(t)
    if ls > lt:
        s, t, ls, lt = t, s, lt, ls
    if (s * (lt // ls + 1) * 2)[:lt * 2] > t * 2:
        s, t, ls, lt = t, s, lt, ls
    g = gcd(ls, lt)
    l //= g
    ls //= g
    lt //= g
    a, b = queue[-1]
    a *= l
    b *= l
    k = b // ls
    b -= ls * k
    a += lt * k
    return s * a + t * b


l = int(input())
s = input()
t = input()
print(solve(l, s, t))


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int H, W, K; cin >> H >> W >> K;
  vector<vector<int>> c(H, vector<int>(W, 0));
  int kuro = 0;
  rep(i, H) rep(j, W) {
    char s; cin >> s;
    if(s == '#') {
      c[i][j] = 1;
      kuro++;
    }
  }
  
  int ans = 0;
  rep(i, (1<<H)) rep(j, (1<<W)) {
    vector<vector<int>> cc = c;
    bitset<6> ib = i;
    bitset<6> jb = j;
    int k = 0;
    rep(h, H) rep(w, W) if(c[h][w] == 1 && (ib.test(h) || jb.test(w))) k++;
    if(kuro-k == K) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
/*    auto start = high_resolution_clock::now();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cout << "\nduration="<<duration.count()/1e6 << endl;
*/
const ll inf=1e18;
void solve(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while (a>0&&c>0) {
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
        }
        /* code */
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    while(t--){
        solve();
    }
}


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

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

int main()
{
    int N, Y; cin >> N >> Y;
    if(Y - 1000 * N < 0)
        cout << -1 << " " << -1 << " " << -1 << endl;
    else{
        bool flag = true;
        REP(x, N + 1){
            REP(y, N - x + 1)
                if(flag && 9000 * x + 4000 * y == Y - 1000 * N){
                    cout << x << " " << y << " " << N - x - y << endl;
                    flag = false;
                }
        }
        if(flag)
            cout << -1 << " " << -1 << " " << -1 << endl;
    }

    return 0;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	ll ans = INF;
	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	REP(i, n){
		ll small = 0;
		ll large = 0;
		REP(j, n){
			if(j <= i)small += v[j];
			else large += v[j];
		}
		ans = min(ans, abs(large - small));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace

main :: IO ()
main = readLine >>= main'
    where
        main' [n, k] = readContents n >>= print . solve k

solve :: Int -> [[Int]] -> Int
solve k xys = minimum [(xmax - xmin) * (ymax - ymin) | xmax <- xs, xmin <- xs, ymax <- ys, ymin <- ys, xmin < xmax, ymin < ymax, satisfy xmin xmax ymin ymax vs]
    where
        vs = map (\[x, y] -> (x, y)) xys 
        (xs, ys) = unzip vs

        satisfy xmin xmax ymin ymax = (>= k) . length . filter ff
            where
                ff (x, y) = xmin <= x && x <= xmax && ymin <= y && y <= ymax

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

int main() {
  int N, K;
  cin >> N >> K;
  cout << ((N+1)/2 >= K ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	int N;
	cin >> N;

	vector<pair<int, ll>> eda[100001];
	rep(i, N - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		eda[a].push_back(make_pair(b, c));
		eda[b].push_back(make_pair(a, c));
	}

	ll kyori[100001] = {};

	int Q, K;
	cin >> Q >> K;

	vector<pair<int, ll>> que;
	que.push_back(make_pair(K, 0));

	while (que.size()) {
		vector<pair<int, ll>> que2;
		for (auto itr : que) {
			if (kyori[itr.first] == 0) {
				kyori[itr.first] = itr.second;
				for (auto itr2 : eda[itr.first]) {
					que2.push_back(make_pair(itr2.first, itr.second + itr2.second));
				}
			}
		}
		que = que2;
	}

	rep(i, Q) {
		int X, Y;
		cin >> X >> Y;
		co(kyori[X] + kyori[Y]);
	}

	Would you please return 0;
}

Measured memory_bytes: 13780
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
  int in[3];
  for(int i=0; i<3; i++) {
    cin >> in[i];
  }

  int n = 0;
  if(in[0] >= in[2]) {
    cout << n << endl;
  } else if(in[0]+in[1]-in[2] >= 0) {
    cout << abs(in[2]-in[0]) << endl;
  } else {
    cout << "NA" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>
int main(void)
{
  int a, non_taxed_price_a, max_non_taxed_price_a, min_non_taxed_price_a,
    b, non_taxed_price_b, max_non_taxed_price_b, min_non_taxed_price_b,
    i, ans;

  // 標準入力からの値取得
  scanf("%d %d", &a, &b);

  // 計算
  max_non_taxed_price_a = (int)((float)a / 8.0 * 100.0);
  for (i = max_non_taxed_price_a; ; i++) {
    if (((int)((float)i / 100.0 * 8.0)) > a) {
      max_non_taxed_price_a = i - 1;
      break;
    }
  }
  min_non_taxed_price_a = (int)((float)a / 8.0 * 100.0);
  for (i = min_non_taxed_price_a; ; i--) {
    if (((int)((float)i / 100.0 * 8.0)) < a) {
      min_non_taxed_price_a = i + 1;
      break;
    }
  }

  max_non_taxed_price_b = (int)((float)b / 10.0 * 100.0);
  for (i = max_non_taxed_price_b; ; i++) {
    if (((int)((float)i / 100.0 * 10.0)) > b) {
      max_non_taxed_price_b = i - 1;
      break;
    }
  }
  min_non_taxed_price_b = (int)((float)b / 10.0 * 100.0);
  for (i = min_non_taxed_price_b; ; i--) {
    if (((int)((float)i / 100.0 * 10.0)) < b) {
      min_non_taxed_price_b = i + 1;
      break;
    }
  }

  ans = -1;
  if (min_non_taxed_price_b <= max_non_taxed_price_a &&
    min_non_taxed_price_a <= min_non_taxed_price_b) {
    ans = min_non_taxed_price_b;
  } else if (min_non_taxed_price_a <= max_non_taxed_price_b &&
    min_non_taxed_price_b <= min_non_taxed_price_a) {
    ans = min_non_taxed_price_a;
  }

  // 出力
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
N = int(input())
S = list(input())

d = S.count('D')
i = S.count('I')
cnt = 0
cntold = 0
for n in range(N):
    if S[n] == 'D':
        cnt -= 1
    else:
        cnt += 1
    
    if cnt > cntold:
        cntold = cnt
print(cntold)

Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    int r;
    while(cin>>r)
    {
        cout<<(double)r*1.0*acos(-1)*2<<endl;
    }
    return 0;
}


Measured memory_bytes: 3228
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
using namespace std;
typedef long long ll;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 15; ++i)
		for (int j = 0; j < 25; ++j)
			if (n == 7 * i + 4 * j) {
				printf("Yes\n");
				return 0;
			}
	printf("No\n");
	return 0;
}

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

int n;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		if(floor(i*(1.08)) == n){
			printf("%d\n",i);
			return 0;
		}
	}
	printf(":(\n");
	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 MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);
  // 得票数をあらかじめ 4 * m 倍しておく
  int bai = 4 * m;
  int total = 0;
  rep(i, n) {
    int tmp;
    cin>>tmp;
    tmp *= bai;
    vec[i] = tmp;
    total += tmp;
  }
  int bound = total / bai;
  int eligible = 0;
  rep(i, n) {
    if (vec[i] >= bound) {
      eligible++;
    }
  }

  if (m <= eligible) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class ConsoleApp1
{

    public static void Main()
    {
        var cou = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
            .Select(x => int.Parse(x)).ToArray();
        var b = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
            .Select(x => int.Parse(x)).ToArray();
        var lists = new List<int>();
        for (int i = 1; i < cou + 1; i++)
        {
            int num = 0;

            for (int a_i = 0; a_i < i; a_i++)
            {
                num += a[a_i];
            }
            for (int b_i = i -1; b_i < cou; b_i++)
            {
                num += b[b_i];
            }
            
            lists.Add(num);
        }
        Console.WriteLine(lists.OrderByDescending(x =>x).First());
        Console.ReadKey();
    }
}


Measured memory_bytes: 13396