akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
int n,l[10000000],maxi=-1000,v=0;
cin >> n;
for(int i=0;i<n;i++){
  cin >> l[i];
  if(l[i]>maxi){
    maxi=l[i];
  }
  v+=l[i];
}
if(maxi<v-maxi){
  cout << "Yes" << endl;
}else{
  cout << "No" << endl;
}
} 


Measured memory_bytes: 256
n, A, B, C = map(int, input().split())
L = [int(input()) for i in range(n)]
inf = float('inf')

def dfs(i, a, b, c):
    if i == n:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return inf
        
    res0 = dfs(i + 1, a, b, c)
    res1 = dfs(i + 1, a + L[i], b, c) + 10
    res2 = dfs(i + 1, a, b + L[i], c) + 10
    res3 = dfs(i + 1, a, b, c + L[i]) + 10
    
    return min(res0, res1, res2, res3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
const int SIZE = 100100;
struct UnionFind{
	int par[SIZE],rank[SIZE];
	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]++;
		}	
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
}uf;
struct edge{
	int from,to,cost;
	edge(){}
	edge(int f,int t,int c):from(f),to(t),cost(c){}
	bool operator < (const edge a) const{
		return cost < a.cost;
	}
};
int cost(T a, T b){
	return min(abs(a.fi.fi-b.fi.fi),abs(a.fi.sec-b.fi.sec));
}
int N;
T x[100100];
vector<edge> es;
int main(){
	scanf("%d",&N);
	uf.init(N);
	for(int i=0;i<N;i++){
		scanf("%d %d",&x[i].fi.fi,&x[i].fi.sec);
		x[i].sec = i;
	}
	sort(x,x+N);
	for(int i=0;i<N-1;i++){
		es.pb(edge(x[i].sec,x[i+1].sec,cost(x[i],x[i+1])));
	}
	for(int i=0;i<N;i++){
		swap(x[i].fi.fi,x[i].fi.sec);
	}
	sort(x,x+N);
	for(int i=0;i<N-1;i++){
		es.pb(edge(x[i].sec,x[i+1].sec,cost(x[i],x[i+1])));
	}
	sort(es.begin(),es.end());
	ll ans = 0ll;
	for(int i=0;i<es.size();i++){
		int a = es[i].from;
		int b = es[i].to;
		int c = es[i].cost;
		if(uf.same(a,b))continue;
		uf.unite(a,b);
		ans += (ll)c;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>H>>W>>A;
    mat a(H,vec(W));
    vp grid(H*W);
    rep(i,H) {
        rep(j,W) {
            cin>>a[i][j];
            grid[--a[i][j]] = mp(i, j);
        }
    }
    mat cost(17,vec(H*W));
    ll cons = 0;
    rep(i,17){
        rep(j,H*W){
            if(i == 0){
                if(j + A < H*W){
                    cost[0][j] = abs(grid[j + A].fi - grid[j].fi) + abs(grid[j + A].se - grid[j].se);
                }else{
                    cost[0][j] = cons;
                }
            }else{
                if(j + (1LL << (i-1)) * A < H*W) {
                    ll hop = cost[i - 1][j], step = cost[i - 1][j + (1LL << (i - 1)) * A];
                    cost[i][j] = (step == cons) ? cons : hop + step;
                }else{
                    cost[i][j] = cons;
                }
            }
        }
    }
    /*rep(i,3){
        cout<<i<<endl;
        rep(j,H*W) cout<<cost[i][j]<<' ';
        cout<<endl;
    }*/
    cin>>Q;
    rep(i,Q){
        cin>>L>>R;
        --L; --R;
        ll num = (R - L) / A, ans = 0;
        //cout<<num<<endl;
        rep(j,17){
            if((num>>j)&1) {
                ans += cost[j][L];
                /*cout<<j<<' '<<cost[j][L]<<endl;
                cout<<cost[0][L]<<endl;
                cout<<cost[0][L+A]<<endl;
                cout<<cost[0][L+A*2]<<endl;*/
                L += (1LL << j) * A;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 15168
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string str,str2;
  getline(cin,str);
  int a=str.length();
  char ch=str[a-1];
  if(ch=='s')
    str+="es";
  else
    str+='s';
  cout<<str<<endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int>x(N);
  vector<int>y(N);
  vector<double>out(4);

  for(int i=0;i<N;i++){
    cin >> x[i];
  }
  for(int i=0;i<N;i++){
    cin >> y[i];
  }
  for(int i=0;i<3;i++){
    double sum = 0;
    for(int j=0;j<N;j++){
      sum += pow(abs(x[j]-y[j]), i+1);
    }
    out[i] = pow(sum, 1.0 / (i+1));
  }
  int val=0;
  for(int i=0;i<N;i++){
    val = max(val, abs(x[i] - y[i]));
    out[3] = val;
  }

  for(int i=0;i<4;i++){
    printf("%.10lf\n", out[i]);
  }


  return 0;
}

Measured memory_bytes: 1288
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define mp make_pair
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
static const ll INF = 1e17;

int main(){
  int n; ll k; cin >> n >> k;
  vector<ll> a(n);
  ll ub = 0;
  rep(i, n) {
    cin >> a[i];
    chmax(ub, a[i]);
  }

  ll lb = 0;
  while(ub - lb > 1){
    ll mid = (ub + lb)/2;
    ll cutcount = 0;
    rep(i, n){
      ll d = (a[i] - 1)/mid;
      cutcount += d;
    }
    if(cutcount > k) lb = mid;
    else ub = mid;
  }

  cout << ub << endl;
}


Measured memory_bytes: 4836
import java.util.*;

// ABC 18-C
// http://abc018.contest.atcoder.jp/tasks/abc018_3
 
public class Main {

	public static void main (String[] args) throws java.lang.Exception {
		Scanner in = new Scanner(System.in);
		
		int h = in.nextInt();
		int w = in.nextInt();

		long answer = Long.MAX_VALUE;

		// Divide vertically
		int dividedBy3 = w / 3;
		if (w % 3 == 0) {
			answer = 0;
		} else {
			answer = Math.min(answer, h);
		}

		// Divide vertically
		dividedBy3 = h / 3;
		if (h % 3 == 0) {
			answer = 0;
		} else {
			answer = Math.min(answer, w);
		}
		
		// Divide vertically first and divide horizontally in the first column
		long half = w / 2;
		for (long i = 1; i < h; i++) {
			long max = Math.max(Math.max(half * i, (w - half) * i), w * (h - i));
			long min = Math.min(Math.min(half * i, (w - half) * i), w * (h - i));
			answer = Math.min(answer, max - min);
		}
		
		// Divide horizontally first and divide vertically in the first row
		half = h / 2;
		for (long i = 1; i < w; i++) {
			long max = Math.max(Math.max(half * i, (h - half) * i), (w - i) * h);
			long min = Math.min(Math.min(half * i, (h - half) * i), (w - i) * h);
			
			answer = Math.min(answer, max - min);
		}
		
		System.out.println(answer);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k,sum=0;
	int arr[1005];
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>arr[i];
	sort(arr,arr+n);
	for(int i=0;i<k;i++)sum+=arr[i];
	cout<<sum;
}

Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var v = IntStream.range(0, n).map(i -> sc.nextInt()).toArray();
		sc.close();

		var count1 = new int[100000];
		var count2 = new int[100000];
		for (var i = 0; i < n; i++) {
			if (i % 2 == 0) {
				count1[v[i] - 1]++;
			} else {
				count2[v[i] - 1]++;
			}
		}

		var counts1 = new ArrayList<ValueCount>();
		var counts2 = new ArrayList<ValueCount>();
		for (var i = 0; i < count1.length; i++) {
			counts1.add(new Main().new ValueCount(i + 1, count1[i]));
		}
		for (var i = 0; i < count2.length; i++) {
			counts2.add(new Main().new ValueCount(i + 1, count2[i]));
		}
		Collections.sort(counts1);
		Collections.reverse(counts1);
		Collections.sort(counts2);
		Collections.reverse(counts2);
		var result = 0;
		if (counts1.get(0).getValue() == counts2.get(0).getValue()) {
			result = n - (counts1.get(0).getCount() + Math.max(counts1.get(1).getCount(), counts2.get(1).getCount()));
		} else {
			result = n - (counts1.get(0).getCount() + counts2.get(0).getCount());
		}
		System.out.println(result);
	}

	public class ValueCount implements Comparable<ValueCount> {
		private int value;
		private int count;

		public ValueCount(int value, int count) {
			this.value = value;
			this.count = count;
		}

		public int getValue() {
			return value;
		}

		public int getCount() {
			return count;
		}

		@Override
		public int compareTo(ValueCount target) {
			if (this.count > target.getCount()) {
				return 1;
			} else if (this.count < target.getCount()) {
				return -1;
			}

			return 0;
		}
	}
}


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

namespace ConsoleApplication18 {//a54
    class Program {
        static void Main(string[] args) {

            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            var result = Method(a, b);
            Console.WriteLine(result);
        }
        private static string Method(int a, int b) {

            string result = "";

            //1が一番強いので、1の場合13より上の14に。
            if (a == 1) {
                a = 14;
            }
            if(b == 1) {
                b = 14;
            }
            //判定
                if (a > b) {
                    result = "Alice";
                } else if (b > a) {
                    result = "Bob";
                } else {
                    result = "Draw";
                }
            return result;
        }
    }
}


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

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

bool check(string s) {

    int l = 0;
    int r = s.size()/2;

    while(r != s.size()) {
        if(s[l] != s[r]) {
            return false;
        }
        l++;
        r++;
    }

    return true;
}

vector<long long> fac(20 + 1);

void fact() {
    fac[0] = 1;
    for(int i = 1; i <= 20; i++) {
        fac[i] = fac[i - 1] * i;
    }
}

void solve() {
    int x;
    cin >> x;

    cout << !x << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    //fact();
    int t = 1;
    //cin >> t;

    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define fr(i,k,n) for(int i=k;i<n;i++)
#define read(x) cin>>x
#define ll long long int
#define mod 1000000007 
#define print(x) cout<<x<<endl
#define pb(x) push_back(x)
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
int main() { 
    fastIO;
     int t=1,n ;
     //cin>>t;
     while(t--){
         cin>>n ;
       vector<double>p(n );
      vector<vector<double>>dp(n,vector<double>(n+1,0));
      
      // int x=0,y=0;
       fr(i,0,n ){ 
        cin>>p[i];
        
       }
       double ans=0; 
       if(n==1)
         ans=p[0];
       dp[0][0]=(1-p[0]);
       dp[0][1]=p[0];
      fr(i,1,n)
         for(int j= 0;j<=i+1;j++){
          
           if(j<=i)
              dp[i][j]+=dp[i-1][j-1]*(p[i])+dp[i-1][j]*(1-p[i]);
           else if(j==0)
            dp[i][j]+=dp[i-1][j ]*(1-p[i]) ;
           else
             dp[i][j]+=dp[i-1][j-1]*(p[i]);
           if(i==n-1 && j>(n /2))
             ans+=dp[i][j];
          
        }
      cout<<setprecision(11)<< ans<<endl;}
	return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if(a==b && a!=c) dunk("Yes");
  else if(a==c && a!=b) dunk("Yes");
  else if(b==c && a!=b) dunk("Yes");
  else dunk("No");
}

Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
s = input()
n_group = 0
now = s[0]
cnt = 0
happy = 0
s += 'z'
for i in s:
	if now != i:
		n_group += 1
		if cnt > 1:
			happy += cnt - 1
		cnt = 1
	else:
		cnt += 1
	now = i

for i in range(k):
	if n_group > 2:
		n_group -= 2
		happy += 2
	else:
		happy += 1
if happy > n - 1:
	happy = n - 1
print (happy)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long
using namespace std;
signed main(void){
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i, n) {
        cin >> s[i];
    }
    string al = "abcdefghijklmnopqrstuvwxyz";
    int p=0;
    int min[28];
    REP(i,28) {
        min[i] = 50;
    }
    REP(i, 28) {
        REP(j, n) {
            REP(k, s[j].size()) {
                if(s[j][k] == al[i]) p++;
            }
            min[i] = fmin(min[i], p);
            p = 0;
        }
    }
    REP(i,28) {
        REP(j, min[i]) {
            cout << al[i];
        }
    }
    cout << endl;
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int m = 1001, M = -1;
  REP(i, N){
    int a; cin >> a;
    m = min(m, a);
    M = max(M, a);
  }
  int ans = M-m;
  cout << ans << endl;
}

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

int main()
{
	string s;
	cin>>s;
	for(int i=0;i<=s.size();i++)
	   if((s[i]-'0')==7)
	   {
	   	 cout<<"Yes";
	   	 return 0;
	   }
	   
	cout<<"No";
	
	return 0;
	
} 

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


int main() {
  int a,b;
  cin>>a>>b;
  if(a%2!=b%2)
    cout<<"IMPOSSIBLE"<<endl;
  else
  cout<<  (a+b)/2<<endl;
    
}

Measured memory_bytes: 256
n,m=map(int,input().split())
pyn=[]
for i in range(m):
    py=list(map(int,input().split()))
    py.append(i)
    pyn.append(py)

new_pyn=sorted(pyn)

cnt=1
i=1
j=0


while(j<m):
    if new_pyn[j][0] == i:
        new_pyn[j].append(cnt)
        cnt+=1
        j+=1

    else:
        cnt=1
        i+=1
final=sorted(new_pyn,key=lambda x:x[2])


for i in range(m):
    a=str(final[i][0])
    b=str(final[i][3])
    print(str(a.zfill(6))+str(b.zfill(6)))

Measured memory_bytes: 37008
fn main() {
    let weather = vec!["Sunny", "Cloudy", "Rainy"];
    let s: String = read();
    let mut index = 0;

    for &w in weather.iter() {
        if s == w { break; }
        index += 1;
    }

    println!("{}", weather[(index + 1) % 3]);
}

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


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

const int MAXN = 1e5 + 21;

int a[MAXN], b[MAXN];
int n;
long long ans;
pair <int, int> c[MAXN];

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i].first = a[i] + b[i];
		c[i].second = i;
	}

	sort(c, c + n);

	for (int i = n - 1; i >= 0; i -= 2)
		ans += a[c[i].second];
	for (int i = n - 2; i >= 0; i -= 2)
		ans -= b[c[i].second];
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1792
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

mod = 10**9+7 #出力の制限
N = 10**5 * 2
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

k,q = m()

d = l()


for i in range(q):
    n,x,mm = m()
    co = 0

    po = []
    for j in range(k):
        #po.append(d[j] % mm if d[j] % mm > 0 else mm)
        po.append(d[j] % mm)

    for j in range(k):
        if po[j] == 0:
            ccc = ((n-1)//k)
            if (n-1)%k >= j+1:
                ccc += 1
            co += ccc

    pp = sum(po) * ((n-1)//k)
    pp += x
    for j in range((n-1)%k):
        pp += po[j]
    
    co += (pp//mm) - (x//mm)
    
    print((n-co-1))






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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	long long comfort = 0;
	sort(a.rbegin(), a.rend());
	for (int i = 0; i < n - 1; i++) {
		comfort += a[(i + 1)/2];
	}
	cout << comfort;
}



Measured memory_bytes: 3996
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)  //最大公約数
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long power(long x, int n) { //x^n 計算量O(logn)
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

int choose(int n, int k) {
	return k == 0 ? 1 : (long long)choose(n - 1, k - 1) * n % MOD * power(k, MOD - 2) % MOD;
}

void bubble_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 0; i < n; i++)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = n - 1; j > i; j--)
		{
			if (a[j - 1] > a[j])
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
		printf("\n");
	}
}

void selection_sort(int a[], int n)
{
	int i, j, tmp, min, key;

	for (i = 0; i < n - 1; i++)
	{
		min = i;
		key = a[i];

		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[min])
			{
				min = j;
				key = a[j];
			}
		}

		tmp = a[i];
		a[i] = a[min];
		a[min] = tmp;

		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

void insertion_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 1; i < n; i++)
	{
		j = i;

		while (j >= 1 && a[j - 1] > a[j])
		{
			tmp = a[j];
			a[j] = a[j - 1];
			a[j - 1] = tmp;
			j--;
		}
	}
}

void shell_sort(int a[], int n)
{
	int h, i, j;

	for (h = 1; h < n / 9; h = h * 3 + 1)
		;

	for (; h > 0; h /= 3)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (i = h; i < n; i++)
		{
			j = i;
			while (j >= h && a[j - h] > a[j])
			{
				swap(&a[j - h], &a[j]);
				j -= h;
			}
		}
		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

int partition(int a[], int l, int r)
{
	int i, j, pivot;

	i = l - 1;
	j = r;
	pivot = a[r];

	for (;;)
	{
		while (a[++i] < pivot)
			;
		while (i < j-- && pivot < a[j])
			;

		if (i >= j)
			break;

		swap(&a[i], &a[j]);
	}

	swap(&a[i], &a[r]);
	return i;
}

void quick_sort1(int a[], int l, int r)
{
	int v;

	if (l >= r)
		return;

	v = partition(a, l, r);

	quick_sort1(a, l, v - 1);
	quick_sort1(a, v + 1, r);
}

void quick_sort(int a[], int n)
{
	quick_sort1(a, 0, n - 1);
}

int keta(int a,int n)
{
	if (n == 1)
		return a % 10;

	for (int i = 0; i < n-1; i++)
		a /= 10;

	return a % 10;
}

int main() 
{
	int N, M, L, K;
	int a[100000];
	char S[5];

	scanf("%s", S);

	if (S[0] != S[1] || S[0] != S[2] || S[1] != S[2])
		printf("Yes");
	else
		printf("No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	int n = ri();
	int res = 0;
	FOR(i,n)res+=ri()-1;
	cout << res << endl;
	return 0;
}


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

using namespace std;

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

    int r_min = 1000;
    for (int i = 0; i + 2 < static_cast<int>(s.size()); i++) {
        int r = 100 * (s[i] - '0') + 10 * (s[i + 1] - '0') + (s[i + 2] - '0');
        if (r_min > abs(r - 753)) {
            r_min = abs(r - 753);
        }
    }

    cout << r_min << endl;
}


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

int main() {
  int k;
  cin >> k;
  int a, b;
  cin >> a >> b;
  for(int i = a; i < b+1; i++) {
    if(i % k == 0) {
      cout << "OK" << endl;
      break;
    }
    else if(i == b && i % k != 0) cout << "NG" << endl;
  }
} 

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

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

    int min = a[0], max = a[0];
    long total = 0;
    for (int i = 0; i < n; i++) {
        total += a[i];
        if (a[i] < min) {
            min = a[i];
        } else if (a[i] > max) {
            max = a[i];
        }
    }

    printf("%d %d %ld\n", min, max, total);

    return 0;
}


Measured memory_bytes: 3272
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e3 + 5, M = 1e5 + 5;


int main(){
    IO;
    int n;
    cin >> n;
    priority_queue<long double> pq;
    for(int i = 0 ; i < n ; ++i){
        long double x;
        cin >> x;
        pq.emplace(-x);
    }
    while(pq.size() >= 2){
        long double a = -pq.top(); pq.pop();
        long double b = -pq.top(); pq.pop();
        pq.emplace((a + b) / -2.0L);
    }
    cout << fixed << setprecision(12) << -pq.top() << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CPoll solver = new CPoll();
        solver.solve(1, in, out);
        out.close();
    }

    static class CPoll {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            ArrayList<String> s = new ArrayList<>();
            int n = in.nextInt();
            HashMap<String, Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                String temp = in.next();
                if (map.containsKey(temp)) map.put(temp, map.get(temp) + 1);
                else map.put(temp, 1);
            }
            int max = -1;
            for (int x : map.values()) max = Math.max(max, x);
            for (String x : map.keySet()) if (map.get(x) == max) s.add(x);
            Collections.sort(s);
            for (String x : s) out.println(x);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 66504
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> count;
  ll prefix[n + 1];
  memset(prefix, 0, sizeof(prefix));
  count[prefix[0]] = 1;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    prefix[i + 1] = prefix[i] + a[i];
    count[prefix[i + 1]] += 1;
  }
  map<ll, ll>::iterator it;
  ll ans = 0;
  ll second = 0;
  for (it = count.begin(); it != count.end(); it++) {
    second = it->second;
    for (ll i = second - 1; i >= 0; i--) {
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
using System;

namespace AtCoder
{
    public static class AtCoder
    {
        public static void Main()
        {
            var n = Console.ReadLine();
            int len = n.Length;
            string s = n.Substring(len - 1, 1);

            switch (s)
            {
                case "2":
                case "4":
                case "5":
                case "7":
                case "9":
                    Console.WriteLine("hon");
                    break;
                case "0":
                case "1":
                case "6":
                case "8":
                    Console.WriteLine("pon");
                    break;
                default:
                    Console.WriteLine("bon");
                    break;
            }
        }
    }
}

Measured memory_bytes: 25884
from collections import Counter
N=int(input())
A=list(map(int,input().split(' ')))
A_count = Counter(A)
S=sum([i*(i-1)//2 for i in A_count.values()])
A_dic = {k:v*(v-1)//2-(v-1)*(v-2)//2 for k,v in A_count.items()}
for i in A:
    print(S-A_dic[i])

Measured memory_bytes: 32032
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
using namespace std;
#define ll long long int

int main(void)
{
	int a, b, d, g, count = 0;
	
	vector<int> vec{1, 2, 3};
	map<char, int> mp;
	cin >> a;
	cin >> b;
	for (int i = 0;i < 3;i++)
	{
		if (vec[i] != a && vec[i] != b)
			cout << vec[i] << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


template<class T, class Comp=std::less<T>>
struct ConvexHullTrick {
public:
    ConvexHullTrick(const Comp &comp = Comp()) : comp(comp) {};

    void add_line(T slope, T intercept) {
        Line line(slope, intercept);
        while (lines.size() >= 2) {
            if (check_valid(*(lines.end() - 2), lines.back(), line)) break;
            lines.pop_back();
        }
        lines.emplace_back(slope, intercept);
    }

    T evaluate(T x) {
        assert(!lines.empty());

        int lo = -1, hi = (int)lines.size() - 1;
        while (hi - lo > 1) {
            int mid = lo + (hi - lo) / 2;
            T v1 = evaluate(lines[mid], x);
            T v2 = evaluate(lines[mid + 1], x);
            if (comp(v1, v2)) hi = mid;
            else lo = mid;
        }
        return evaluate(lines[hi], x);
    }

private:
public:
    const Comp comp;
    using Line = std::pair<T, T>;
    std::vector<Line> lines;

    T check_valid(Line l1, Line l2, Line l3) {
        if (l1.first < l3.first) std::swap(l1, l3);
        T lhs = (l3.second - l2.second)*(l2.first - l1.first);
        T rhs = (l2.second - l1.second)*(l3.first - l2.first);
        return lhs < rhs;
    }

    T evaluate(const Line &line, T x) {
        return line.first*x + line.second;
    }
};


int main() {
    int n; long long c; std::cin >> n >> c;
    std::vector<long long> h(n);
    for (int i = 0; i < n; i++) std::cin >> h[i];
    ConvexHullTrick<long long> cht;
    cht.add_line(-2*h[0], h[0] * h[0] + c);
    for (int i = 1; i < n - 1; i++) {
        long long v = h[i] * h[i] + cht.evaluate(h[i]);
        v += h[i] * h[i] + c;
        cht.add_line(-2*h[i], v);
    }
    std::cout << h[n - 1]*h[n - 1] + cht.evaluate(h[n - 1]) << std::endl;
    return 0;
}


Measured memory_bytes: 7792
#include <iostream>

using namespace std;

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

	if(a == 3){
		cout << "YES" << endl;
	}else if(a == 5){
		cout << "YES" << endl;
	}else if(a == 7){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

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

	stack<char> stk;

	REP(i, N) {
		if (stk.empty()) {
			stk.push(S[i]);
		}
		else {
			//cout << stk.top() << endl;
			if (S[i] == ')' && stk.top() == '(') {
				stk.pop();
			}
			else {
				stk.push(S[i]);
			}
		}
	}

	while(!stk.empty()) {
		if (stk.top() == '(') {
			S.push_back(')');
		}
		else if (stk.top() == ')') {
			S.insert(0, "(");
		}
		stk.pop();
	}

	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[ans_a-i-1]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            time += arr_b[cnt_b]
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)



Measured memory_bytes: 110980
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
char s[N];
char t[N];
int q;
int a , b , c , d;
int s1[N];
int s2[N];
int main(){
	scanf("%s" , s + 1);
	s1[0] = 0;
	for(int i = 1 ; s[i] ; ++i){
		s1[i] = s1[i - 1] + s[i] - 'A' + 1;
	}
	scanf("%s" , t + 1);
	s2[0] = 0;
	for(int i = 1 ; t[i] ; ++i){
		s2[i] = s2[i - 1] + t[i] - 'A' + 1;
	}
	scanf("%d" , &q);
	while(q--){
		scanf("%d %d %d %d" , &a , &b , &c , &d);
		if(((s1[b] - s1[a - 1]) % 3) == ((s2[d] - s2[c - 1]) % 3)){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
}

Measured memory_bytes: 1536
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [a, b, c] <- readIntList
  putStrLn $ show c ++ " " ++ show a ++ " " ++ show b


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;


ll gcd(ll a, ll b)   //Function to find gcd of two numbers
{
    if (a == 0)
    return b;
    return gcd(b % a, a);
}

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

    int n;
    cin>>n;
    
    vector<pair<int,int>>arr;

   
    bool flag=false;

    for(int i=0;i<n;i++)
    {
         int x,y;   
       cin>>x>>y;
      
       arr.push_back({x,y});
    }

     int ans=0;

    for(int i=0;i<n;i++)
    {
        if(arr[i].first==arr[i].second)
        {
            int cnt=0;

            while((arr[i].first==arr[i].second )&& i<n)
            {
                cnt++;
                i++;
            }
             
            ans  = max(ans,cnt);
            i--;

        }
    }

    if(ans>=3)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;


    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main(){
 int A,B;
 cin >> A >> B;
  
 int sum = 0;
 for(int i = 0 ; i < 2 ;i++){
  if(A >B){
    sum += A;
    A--;
  } 
  else{
    sum += B;
    B--;  
  }
 }
  
  cout << sum <<endl;
 return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[10086],x,i,j=0,t=0;
	char as[100086];
	gets(as);
	x=strlen(as);
	for(i=0;i<x;i++)
	{
		if(as[i]=='C')
		t=1;
		if(as[i]=='F'&&t==1)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
	
	
}

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

int main() {
    int x, n;
    cin >> x >> n;
    int p[n];
    rep (i, n) {
        cin >> p[i];

    }
    int i = 0;
    while (1) {
        bool flag = true;
        int a = x - i;
        for (int j = 0; j < n; j++) {    
            if (a == p[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << a << endl;
            return 0;
        }
        flag = true;
        a = x + i;
        for (int j = 0; j < n; j++) {    
            if (a == p[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << a << endl;
            return 0;
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int A = stdIn.nextInt();
        int B = stdIn.nextInt();
        int T = stdIn.nextInt();
        int sum = 0;
        for (int time = A; time < T + 0.5; time += A) {
            sum += B;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21588
import Data.List
import Control.Applicative
import Control.Monad
main = solve

solve :: IO ()
solve = do
    n <- fmap (read :: String -> Int) . words <$> getLine
    printResult n

printResult :: [Int] -> IO ()
printResult n
    | x == 0 && y == 0 = return ()
    | otherwise = do
        putStrLn $ show (min x y) ++ " " ++ show (max x y)
        solve
    where x = n !! 0
          y = n !! 1

Measured memory_bytes: 4124
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in);){
            while(true){
                int n = sc.nextInt();
                if(n== 0)break;
                int[]scores = new int[n];
                int sum=0;
                double sum2=0;
                for(int i=0;i<scores.length;i++){
                    scores[i] = sc.nextInt();
                    sum += scores[i];
                }
                double ave= (double)sum/n,var = 0;
                double[]scores2 = new double[n];
                for(int i=0;i<scores.length;i++){
                    scores2[i] = (scores[i] - ave)*(scores[i] - ave);
                    sum2 += scores2[i];
                }
                var = sum2 /n;
                System.out.println(Math.sqrt(var));
            }
        }
    }
}


Measured memory_bytes: 31548
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
 
	int n;
	long long d, a;
	cin >> n >> d >> a;
	vector<pair<long long, long long>> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i].first >> v[i].second;
	}
	sort(v.begin(), v.end());
	queue<long long> q, p;
	long long cur = 0;
	long long ans = 0;
	for(auto i : v) {
		while(!q.empty() and q.front() < i.first - 2*d) {
			q.pop();
			cur -= p.front();
			p.pop();
		}
		if(i.second <= cur) continue;
		long long req = (i.second - cur)/a;
		if((i.second - cur) % a != 0) req++;
		cur += req * a;
		ans += req;
		q.push(i.first);
		p.push(req*a);
	}
	cout << ans << '\n';
 
	return 0;
}

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
import sys
# from collections import defaultdict, deque
from math import log10, sqrt, ceil
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    
    n, m = [int(x) for x in input().split()]
    a = []
    for i in range(n):
        a.append(input())
    b = []
    for i in range(m):
        b.append(input())

    ok = 0
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            f = 1
            for x in range(m):
                for y in range(m):
                    if a[i+x][j+y] != b[x][y]:
                        f = 0
            ok |= f


    if ok:
        print("Yes")
    else:
        print("No")
        




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)
100000007
"""



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> W(N);
  REP(i, N) cin >> W[i];
  int ans = 1e9;
  REP(i, N) {
    int s1 = 0;
    int s2 = 0;
    REP(j, i + 1) { s1 += W[j]; }
    FOR(k, i + 1, N) { s2 += W[k]; }
    ans = min(ans, abs(s1 - s2));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int>data(n);
	map<int, int>Omp;
	map<int, int>Emp;
	for (int i = 0; i < n; i++) {
		cin >> data[i];
		if (i % 2 == 0) {
			Omp[data[i]]++;
		}
		else {
			Emp[data[i]]++;
		}
	}
	int OM, Om, EM, Em, On, En;
	OM = EM = Om = Em = 0;
	auto check = Omp.end();
	check--;
	for (auto it = Omp.begin(); it != Omp.end(); ++it) {
		if (OM <= it->second) {
			OM = it->second;
			On = it->first;
		}
		if (it == check) {
			Omp[On] = 0;
		}
	}
	for (auto it = Omp.begin(); it != Omp.end(); ++it) {
		chmax(Om, it->second);
	}
	check = Emp.end();
	check--;
	for (auto it = Emp.begin(); it != Emp.end(); ++it) {
		if (EM <= it->second) {
			EM = it->second;
			En = it->first;
		}
		if (it == check) {
			Emp[En] = 0;
		}
	}
	for (auto it = Emp.begin(); it != Emp.end(); ++it) {
		chmax(Em, it->second);
	}
	if (On == En) {
		cout << min(n - (OM + Em), n - (EM + Om)) << endl;
	}
	else {
		cout << n - (OM + EM) << endl;
	}
}


Measured memory_bytes: 5376
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r+=p[:x]+q[:y]
r.sort(reverse=True)
ans=0
for i in range(x+y):
    ans+=r[i]
print(ans)


Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(string s, long long K){
	string str1 = "~", str2 = "~", str3 = "~", str4 = "~", str5 = "~";
	string now = "";
	ll N = s.length();
	rep(i, N) {
		now = "";
		for(ll j = i; j < N; j++) {
			now += s[j];
			// cout << now << endl;
			if (now == str1 || now == str2 || now == str3 || now == str4 || now == str5) continue;
			if (now < str1) {
				str5 = str4;
				str4 = str3;
				str3 = str2;
				str2 = str1;
				str1 = now;
			} else if (now < str2) {
				str5 = str4;
				str4 = str3;
				str3 = str2;
				str2 = now;
			} else if (now < str3) {
				str5 = str4;
				str4 = str3;
				str3 = now;
			} else if (now < str4) {
				str5 = str4;
				str4 = now;
			} else if (now < str5) {
				str5 = now;
			} 
		}
	}
	// cout << str1 << endl;
	// cout << str2 << endl;
	// cout << str3 << endl;
	// cout << str4 << endl;
	// cout << str5 << endl;
	if (K == 1) cout << str1 << endl;
	if (K == 2) cout << str2 << endl;
	if (K == 3) cout << str3 << endl;
	if (K == 4) cout << str4 << endl;
	if (K == 5) cout << str5 << endl;
}

int main(){	
	long long K;
	string s;
	cin >> s;
	scanf("%lld",&K);
	solve(s, K);
	return 0;
}



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

int main() {
  string S;
  cin >> S;
  bool flag = true;
  for (int i = 0; i < S.size(); i += 2) {
    if (S.at(i) == 'L') {
      flag = false;
    }
  }
  for (int i = 0; i + 1 < S.size(); i += 2) {  
    if (S.at(i + 1) == 'R') {
      flag = false;
    }
  }
  
  if (flag == true) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256