akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let string = read();
    let yosoku_string_len = string.len() + 2 * 100000;
    let mut appended_to_start = Vec::with_capacity(yosoku_string_len / 2);
    let mut appended_to_end = Vec::with_capacity(yosoku_string_len / 2);
    let query_cnt = read().parse::<u64>().unwrap();
    let mut reversed = false;
    for _ in 0..query_cnt {
        let query = read_as_vec();
        let op = query[0].parse::<u64>().unwrap();
        if op == 1 {
            reversed = !reversed;
        } else { // op == 2
            let append_to_start = query[1].parse::<u64>().unwrap() == 1;
            let ch = query[2].chars().nth(0).unwrap();
            if reversed {
                // reversed ops
                if append_to_start {
                    appended_to_end.push(ch);
                } else {
                    appended_to_start.push(ch);
                }
            } else {
                // nature order
                if append_to_start {
                    appended_to_start.push(ch);
                } else {
                    appended_to_end.push(ch);
                }
            }
        }
    }

    let start = if !reversed { &appended_to_start } else { &appended_to_end };
    let end = if !reversed { &appended_to_end } else { &appended_to_start };

    let result_len = start.len() + string.len() + end.len();
    let mut build = String::with_capacity(result_len);
    for i in (0..start.len()).rev() {
        build.push(start[i]);
    }
    if !reversed {
        build.push_str(&string);
    } else {
        build.push_str(&string.chars().rev().collect::<String>())
    }
    for i in 0..end.len() {
        build.push(end[i]);
    }

    println!("{}", build);
}
fn read() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}
fn read_as_vec() -> std::vec::Vec<String> {
    read().split(' ').map(|s| s.to_string()).collect()
}


Measured memory_bytes: 6780
n, m = map(int, input().split())

a = [[0]+list(map(int, input().split()))]
for k in range(62):
    a.append([a[k][a[k][i]] for i in range(n+1)])

res = 1
for k in list(range(62))[::-1]:
    if m >= 2**k:
        res = a[k][res]
        m -= 2**k
print(res)

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

int main(void){
    int w;
    int a, b;
    cin >> w >> a >> b;

    if(b > a + w){
        cout << b - a - w << endl;
    }
    else if ( a > b + w){
        cout << a - b - w << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
int to_int(const char c) {
	return c - 'a';
}
std::string next26(std::string str) {
	char max_char{ 0 };
	for (int i = str.size() - 1; i >= 0; --i) {
		if (str[i] < max_char) {
			char greater_min{ max_char };
			for (auto j = i + 1; j < str.size(); ++j) {
				if (str[i] < str[j] && greater_min > str[j]) {
					greater_min = str[j];
				}
			}
			auto res = str.substr(0, i);
			res.push_back(greater_min);
			return res;
		}
		else {
			max_char = str[i];
		}
	}
	return "-1";

}
std::string next(std::string str) {
	if (str.size() == 26) {
		return next26(str);
	}
	else {
		std::vector<bool> used(26, false);
		for (const auto &c : str) {
			used[to_int(c)] = true;
		}
		for (char c = 'a'; c <= 'z'; ++c) {
			if (!used[to_int(c)]) {
				str.push_back(c);
				return str;
			}
		}
	}
	return "-1";
}

int main() {
	std::string str;
	std::cin >> str;
	std::cout << next(str) << std::endl;
	return 0;
}

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

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
  
int main() {
  int n, ans;
  ans = 0;
  cin >> n;
  if (n % 10 == 0 && to_string(n)[0] == '1') {
    ans = 10;
  }
  else {
    ans = findSumOfDigits(n);
  }
  cout << ans << endl;
}

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

const int P = 1e9 + 7;
int upd(int x){return x + (x >> 31 & P);}
void inc(int &a , int b){a = upd(a + b - P);}
int sub(int a , int b){return upd(a - b);}
int dp[5003][5003][2] , sum[10003][2] , sum1[10003][2] , N , A , B;

int main(){
	cin >> N >> A >> B; dp[0][0][0] = 1; if(A > B) swap(A , B);
	for(int i = 1 ; i <= N ; ++i){
		if(i - A - 1 >= 0){int pre = i - A - 1; for(int j = 0 ; j <= pre ; ++j) for(int k = 0 ; k < 2 ; ++k) inc(sum[pre - j][k] , dp[pre][j][k]);}
		for(int j = 1 ; j <= i ; ++j)
			for(int k = 0 ; k < 2 ; ++k){
				inc(dp[i][j][k | (j >= B)] , dp[i - 1][j - 1][k]);
				inc(dp[i][j][k | (j >= B)] , sum[i - j][k]);
				inc(dp[i][1][k | (1 >= B)] , sub(sum1[i - j][k] , sum[i - j][k]));
			}
		int pre = i - 1; for(int j = 0 ; j <= pre ; ++j) for(int k = 0 ; k < 2 ; ++k) inc(sum1[pre - j][k] , dp[pre][j][k]);
	}
	int sum = 0;
	for(int i = 0 ; i <= N ; ++i)
		for(int j = 0 ; j <= i ; ++j)
			for(int k = 0 ; k < 2 ; ++k)
				if(k || (j + (N - i >= A ? N - i : 0) >= B))
					inc(sum , dp[i][j][k]);
	cout << sum; 
	return 0;
}

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

using namespace std;

int main(){
    int n,y=0,x=0;

   string s;
   cin>>s;
   for(int i=0;i<s.size();i++){
  if(s[i]=='A'&&x==0){
    x=1;
    y=i;
   }
    if(s[i]=='Z'){

    n=i;
   }
   }
   cout<<(n-y)+1<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  string ans;
  cin >> a >> b >> c >> d;
  while(1){
    c = c - b;
    if(c<=0){
      ans = "Yes";
      break;
    }
    a = a - d; 
    if(a<=0){
      ans ="No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n;
int a[maxx];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	bool flg = 1;
	for(int i = 1; i < n; i++) {
		if(a[i] == a[i + 1]) {
			flg = 0;
			break;
		}
	}
	if(flg) puts("YES");
	else puts("NO");
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n], p[n], q[n];
    rep(i, n) a[i] = i + 1;
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    int idx = 0, p_idx = 0, q_idx = 0;
    do {
        idx++;
        bool p_ok = true, q_ok = true;
        rep(i, n) if (a[i] != p[i]) p_ok = false;
        rep(i, n) if (a[i] != q[i]) q_ok = false;

        if (p_ok) p_idx = idx;
        if (q_ok) q_idx = idx;
    } while (next_permutation(a, a + n));

    cout << abs(p_idx - q_idx) << endl;
    return 0;
}


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

using namespace std;

int main() {
	int l,w,h;
	int kaisu;
	double taikaku;
	int hankei;

	while (cin >> l >> w >> h) {
		if (l == 0 && w == 0 && h == 0) {
			break;
		}
		taikaku = sqrt(pow(w,2) + pow(h,2));
		cin >> kaisu;
		for (int i = 0; i < kaisu; i++) {
			cin >> hankei;
			if ((double)hankei * 2.0 > taikaku) {
				cout << "OK" << endl;
			} else {
				cout << "NA" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
n = gets.to_i
a = gets.split.map(&:to_i)

h = Array.new(n, 0)
ans = 0
a.each_with_index do |e, i|
    if i - e >= 0
        ans += h[i - e]
    end

    if i + e < n
        h[i + e] += 1
    end
end

puts ans

Measured memory_bytes: 29080
n = int(input())
n_list = [int(i) for i in input().split()]
ans = 1
n_list.sort()
n_list = list(reversed(n_list))
if 0 in n_list:
    print(0)
else:
    for i in n_list:
        ans *= i
        if ans > 10 ** 18:
            ans = -1
            break
    print(ans)


Measured memory_bytes: 21648
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long i64;
using namespace std;

long long int H, W;

long long int min(long long int x, long long int y) {
	if (x < y) { return x; }
	return y;
}

long long int calc(long long int a, long long int b, long long int c) {
	vector<long long int > V;
	V.push_back(a);
	V.push_back(b);
	V.push_back(c);
		sort(V.begin(), V.end());
	return V[2] - V[0];
}

i64 sep(i64 cur, i64 h, i64 w)
{
	i64 mx, lo;
	if (h % 2 == 0 || w % 2 == 0) {
		mx = lo = h * w / 2;
	}
	else {
		mx = (h * w + min(h, w)) / 2;
		lo = h * w - mx;
	}
	return max({ 0LL, mx - cur, cur - lo, mx - lo });
}


int main(void) {

	cin >> H >> W;

	//for (H = 99990; H <= 100000; H++) {
		//for (int W = 4444; W <= 4468; W++) {

			long long int ans = H*W;
			//1
			long long int a, b, c;
			long long int value;
			for (a = 1; a <= W - 1; a++) {
				b = (W - a) / 2;
				c = W - a - b;
				value = calc(a*H, b*H, c*H);
				ans = min(ans, value);
			}


			//2
			for (a = 1; a <= H - 1; a++) {
				b = (H - a) / 2;
				c = H - a - b;
				value = calc(a*W, b*W, c*W);
				ans = min(ans, value);
			}


			//3
			a = H / 2;
			b = H - a;
			for (int x = 1; x <= W - 1; x++) {
				value = calc((long long int)x*H, a*(W - x), b*(W - x));
				//if (x == 33333) { cout << "H*x= " << (long long int) H*x << endl; }
				ans = min(ans, value);
			}



			//4
			a = W / 2;
			b = W - a;
			for (int x = 1; x <= H - 1; x++) {
				value = calc((long long int) W*x, a*(H - x), b*(H - x));
				ans = min(ans, value);
			}


			i64 ret = H * W;
			for (int i = 0; i <= H; ++i) {
				ret = min(ret, sep(i * W, H - i, W));
			}
			for (int i = 0; i <= W; ++i) {
				ret = min(ret, sep(i * H, W - i, H));
			}

			/*if (ans != ret) {
				cout << "=====";
				cout << "H= " << H << " W= " << W << "  " << ans << " " << ret << endl;
			}*/

/*		}
	}*/

			cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_checkpoints(void) {
	int n, m;
	int a[60], b[60];
	int c[60], d[60];
	int num = 1;
	long int min_distance = 200000000;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> c[i] >> d[i];
	}

	for (int i = 1; i <= n; i++) {
		min_distance = 200000000;
		num = 1;
		for (int j = 1; j <= m; j++) {
			int distance = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			//cout << min_distance<<" "<<distance << endl;
			if (distance < min_distance) {
				min_distance = distance;
				num = j;
			}
		}
		cout << num << endl;
	}

}

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

Measured memory_bytes: 3504
def main():
  user_in = input("")

  D, T, S = user_in.split(" ")
  need_time = float(D) / float(S)
  
  if(need_time <= int(T)):
  	print("Yes")
  else:
  	print("No")
  
 
if __name__ == "__main__":
  main()

Measured memory_bytes: 9180
#include<stdio.h>
#include<string.h>
int main(){
char A[200];
  int i,N,j,c1,c2;
  scanf("%s",&A);
  i=strlen(A);
  char B[200];
  strcpy(B,A);
  c1=0;
  if(i%2==0){
N=i/2;
    for(j=0;j<N;++j){
      if(B[j]!=B[i-j-1]){
c2=c1+1;
        c1=c2;
      }
    }
  }else{
N=(i-1)/2;
     for(j=0;j<=N;++j){
      if(A[j]!=A[i-j-1]){
c2=c1+1;
        c1=c2;
      }
    }
}
  printf("%d\n",c1);
}

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    LL h, w, a[3]; cin >> h >> w;
    LL ans = 1e18;

    a[0] = (h / 3) * w;
    a[1] = ((h - h / 3) / 2) * w;
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);


    a[0] = (h / 3) * w;
    a[1] = (h - h / 3) * (w / 2);
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);

    a[0] = ((h + 2) / 3) * w;
    a[1] = ((h - ((h + 2) / 3) / 2)) * w;
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);

    a[0] = ((h + 2) / 3) * w;
    a[1] = (h - ((h + 2) / 3)) * (w / 2);
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);

    swap(h, w);

    a[0] = (h / 3) * w;
    a[1] = ((h - h / 3) / 2) * w;
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);


    a[0] = (h / 3) * w;
    a[1] = (h - h / 3) * (w / 2);
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);

    a[0] = ((h + 2) / 3) * w;
    a[1] = ((h - ((h + 2) / 3) / 2)) * w;
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);

    a[0] = ((h + 2) / 3) * w;
    a[1] = (h - ((h + 2) / 3)) * (w / 2);
    a[2] = h * w - a[0] - a[1];
    sort(a, a + 3);
    ans = min(ans, a[2] - a[0]);
    
    cout << ans;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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

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

	vector<int> x(n), y(n), loop(n);
	rep(i, n) cin >> x[i] >> y[i];
	rep(i, n) loop[i] = i;
	long double ans = 0;
	int cnt = 0;
	do {
	  cnt++;
		rep(i,n-1) ans += sqrt((x[loop[i]] - x[loop[i + 1]])*(x[loop[i]] - x[loop[i + 1]]) + (y[loop[i]] - y[loop[i + 1]])*(y[loop[i]] - y[loop[i + 1]]));
	} while (next_permutation(loop.begin(), loop.end()));

		cout << setprecision(10) << ans / cnt << endl;
}


Measured memory_bytes: 256
n,m=map(int, input().split())
A=[int(i) for i in input().split()]
tmp = min(A)
A.sort()
ab=[]
for i in range(m):
    b,c=map(int, input().split())
    if not c<tmp:
        ab.append([b, c])
ab.sort(key=lambda x:x[1], reverse = True)
f=False
a = 0
for i in range(len(ab)):
    for j in range(min(ab[i][0], n)):
        if A[a]>ab[i][1]:
            f=True
            break
        A[a]=ab[i][1]
        a+=1
        if a==n:
            f=True
            break
    if f==True:break
print(sum(A))


Measured memory_bytes: 25564
def solve(n ,l, r, A):
    res = 0
    for x in range(l, r+1):
        for i in range(n):
            if (not x%A[i]) :
                res += 0 if (i&1) else 1
                break
        else:
            res += 0 if (n&1) else 1
    return res



def main():
    ans = []
    while True:
        n, l, r = map(int, input().split())
        if (not n) and (not l) and (not r):
            break
        A = [int(input()) for i in range(n)]
        ans.append(solve(n,l,r,A))
    for i in ans:
        print(i)


main()


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<vector<int>> tree(N);
	vector<vector<int>> weight(N);
	rep(i, N-1) {
		int u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;
		tree[u].push_back(v);
		tree[v].push_back(u);
		weight[u].push_back(w);
		weight[v].push_back(w);
	}

	vector<int> color(N, -1); // 探索済みかどうかもかねる．
	queue<int> que;
	que.push(0);
	color[0] = 0;
	while(!que.empty()) {
		int target = que.front();
		que.pop();
		
		for(int i=0; i<tree[target].size(); i++) {
			if(color[tree[target][i]]!=-1) continue; // 着色済み
			if(weight[target][i]%2==0) color[tree[target][i]] = color[target];
			else color[tree[target][i]] = (color[target]+1)%2;
			que.push(tree[target][i]);
		}
	}

	rep(i, N) {
		cout << color[i] << endl;
	}

	return 0;
}

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

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  for (size_t i = 0; i < n; i++) cin >> x[i] >> u[i];
  double ans = 0.0;

  for (size_t i = 0; i < n; i++) {
    if (u[i] == "BTC")
      ans += 380000.0 * x[i];
    else if (u[i] == "JPY")
      ans += x[i];
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3620
/********************************************************************************
	
	Code by a weak man named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int mod = 1e9 + 7;

inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline int fsp(int x, int k = mod - 2) {
	int s = 1;
	while(k) {
		if(k & 1) s = 1LL * s * x % mod;
		x = 1LL * x * x % mod, k >>= 1;
	} return s;
}

int x[6], y[6];
int fac[2000010];
int ifac[2000010];

inline void init(int n) {
	fac[0] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod;
	ifac[n] = fsp(fac[n]);
	for(int i = n; i >= 1; i--) ifac[i - 1] = 1LL * ifac[i] * i % mod;
}

inline int C(int n, int m) { return 1LL * fac[n] * ifac[m] % mod * ifac[n - m] % mod; }

inline int f(int X, int Y) {
	int lx = X - x[1], rx = X - x[0], ly = Y - y[1], ry = Y - y[0];
	return Mod(Mod(C(rx + ry + 2, rx + 1) + C(lx + ly, lx)) + mod - Mod(C(rx + ly + 1, rx + 1) + C(lx + ry + 1, lx)));
}

inline int g(int X, int Y) {
	int lx = x[4] - X, rx = x[5] - X, ly = y[4] - Y, ry = y[5] - Y;
	return Mod(Mod(C(rx + ry + 2, rx + 1) + C(lx + ly, lx)) + mod - Mod(C(rx + ly + 1, rx + 1) + C(lx + ry + 1, lx)));
}

int main() {
#ifdef LOCAL
	FILE("");
#endif

	int mx = 0, my = 0;
	for(int i = 0; i < 6; i++) cin >> x[i], chkmax(mx, x[i]);
	for(int i = 0; i < 6; i++) cin >> y[i], chkmax(my, y[i]);
	init(mx + my);

	int res = 0;
	for(int X = x[2]; X <= x[3]; X++) {
		res = (res + 1LL * (X + y[3]) * f(X, y[3]) % mod * g(X, y[3] + 1)) % mod;
		res = (res + 1LL * (mod - X - y[2] + 1) * f(X, y[2] - 1) % mod * g(X, y[2])) % mod;
	}
	for(int Y = y[2]; Y <= y[3]; Y++) {
		res = (res + 1LL * (Y + x[3]) * f(x[3], Y) % mod * g(x[3] + 1, Y)) % mod;
		res = (res + 1LL * (mod - Y - x[2] + 1) * f(x[2] - 1, Y) % mod * g(x[2], Y)) % mod;
	} cout << res << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    
    cin>>k;
    
    cout<<n[k-1];

    return 0;
}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
int main(){
    int a,b,C;
    double rad;
    double c;
    double S,L,h;
    scanf("%d %d %d",&a,&b,&C);
    rad=C*3.14159265359/180;
     
    S=(a*b*sin(rad))/2;
    h=b*sin(rad);
    c=sqrt(a*a+b*b-2*a*b*cos(rad));
    L=a+b+c;
    printf("%lf\n",S);
    printf("%lf\n",L);
    printf("%lf\n",h); 
     
    return 0;
}

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

int main() {
    string a, b, c, ans="YES";
    cin >> a >> b >> c;
    if(a.at(a.size()-1) != b.at(0) || b.at(b.size()-1) != c.at(0)) {
        ans = "NO";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String csd = br.readLine();
      int total= 0;
      int[] area;
      IntStack stack1 = new IntStack(csd.length());
      Deque<int[]> stack2 = new ArrayDeque<>();

      for(int i=0,max=csd.length(); i<max; i++) {
        if(csd.charAt(i) == '\\') stack1.push(i);
        else if(csd.charAt(i) == '/' && !stack1.isEmpty()) {
          int s = stack1.pop();
          area = new int[]{s,i-s};
          total += area[1];
          while( (stack2.size())>0 && (stack2.peek()[0] > s)) {
            area[1] += stack2.pop()[1];
          }
          stack2.push(area);
        }
      }
      
      StringBuilder buf = new StringBuilder();
      buf.append(total).append('\n')
         .append(stack2.size());
      while(stack2.size() > 0) {
        buf.append(' ')
           .append(stack2.pollLast()[1]);
      }
      System.out.println(buf);
    }
    catch(IOException e) {
      System.err.println("IOException!");
    }
  }
}

class IntStack {
  int[] stack;
  int ite;

  public IntStack(int capacity) {
    stack = new int[capacity];
    ite = 0;
  }

  public void initialize() {
    ite = 0;
  }

  public int getIte() {
    return ite;
  }

  public boolean isEmpty() {
    return ite == 0;
  }

  public boolean isFull() {
    return ite >= stack.length-1;
  }

  public  boolean push(int x) {
    if(isFull()) return false;

    stack[++ite] = x;
    return true;
  }

  public int pop() {
    if(isEmpty()) return 0;

    return stack[ite--];

  }
}


Measured memory_bytes: 25400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,E,F,G,H,I,J,K,L,M,N,T,W,X,Y;
  string S;
  cin >>  N;
  vector<long long> vec(N);
  A=0;
  
  for (int i2=0;i2<N;i2++) {cin >> vec.at(i2);}
  sort(vec.begin(),vec.end());
  for (int i=0;i<N-2;i++) {
    for (int j=1+i;j<N-1;j++) {
	  
	  int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
      int right = N; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

      /* どんな二分探索でもここの書き方を変えずにできる！ */
      while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (vec.at(mid)>=vec.at(i)+vec.at(j)) right = mid;
        else left = mid;
      }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    
	  A+=(right-1-j);
	  
	}
  }
  cout << A << endl;
}

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

int main(){
  int x;
  cin >> x;
  int b=2;
  double max = 1;
  while(b*b<=x){
    int j=2;
    while(pow(b,j)<=x){
      if(max<pow(b,j)) max = pow(b,j);
      j++;
    }
    b++;
  }
  cout << max << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

vector<ll> solve(ll N, ll A, ll B) {
    vector<ll> res;

    for (ll i = B - 1; i >= 0; i--) {
        res.push_back(i);
    }

    if (A == 1) {
        return res;
    }

    ll rem = N - B;
    ll p = rem / (A - 1);
    ll b = rem % (A - 1);
    ll c = A - 1 - b;

    for (ll i = 0; i < b; i++) {
        ll size = res.size();
        for (ll j = 0; j < p + 1; j++) {
            res.push_back(size + p - j);
        }
    }

    for (ll i = 0; i < c; i++) {
        ll size = res.size();
        for (ll j = 0; j < p; j++) {
            res.push_back(size + p - 1 - j);
        }
    }

    return res;
}

vector<ll> solve2(ll N, ll A, ll B) {
    vector<ll> res;

    for (ll a = 0; a < A; a++) {
        for (ll b = B - 1; b >= 0; b--) {
            ll i = b * A + a;
            if (i >= N) {
                continue;
            }
            res.push_back(b * A + a);
        }
    }

    return res;
}

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

    ll N, A, B;
    cin >> N >> A >> B;

    vector<ll> ans;

    if (N <= A + B - 2 || N > A * B) {
        cout << -1 << endl;
        return 0;
    }

    ans = solve(N, A, B);

    for (ll i = 0; i < ans.size(); i++) {
        cout << ans[i] + 1 << " \n"[i == ans.size() - 1];
    }

    return 0;
}



Measured memory_bytes: 6384
//start:
//finish:
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long ll;
ll a[maxn*4],flag[maxn*4]; 
int n,Q;
void down(int x,int l,int r){
	int mid=(l+r)/2;
	if(!flag[x])return;
	flag[x*2]=flag[x];flag[x*2+1]=flag[x];
	a[x*2]=1ll*flag[x]*(mid-l+1);
	a[x*2+1]=1ll*flag[x]*(r-mid);
	flag[x]=0;
}
ll query(int x,int l,int r,int tx,int ty){
	if(l>=tx && r<=ty)return a[x];
	down(x,l,r);
	ll ret=0,mid=(l+r)>>1;
	if(mid>=tx)ret+=query(x*2,l,mid,tx,ty);
	if(mid<ty)ret+=query(x*2+1,mid+1,r,tx,ty);
	return ret;
}
void modify(int x,int l,int r,int tx,int ty,ll val){
	if(l>=tx && r<=ty){
		flag[x]=val;
		a[x]=1ll*(r-l+1)*val;return;
	}
	int mid=(l+r)/2;down(x,l,r);
	if(mid>=tx)modify(x*2,l,mid,tx,ty,val);
	if(mid<ty)modify(x*2+1,mid+1,r,tx,ty,val);
	a[x]=a[x*2]+a[x*2+1];
}

int main(){
	scanf("%d%d",&n,&Q);
	while(Q--){
		int x;ll y;
		scanf("%d%lld",&x,&y);
		if(x==1){
			modify(1,1,n,1,1,query(1,1,n,x,x)+y);
			continue;
		}
		if(query(1,1,n,x-1,x-1)-query(1,1,n,x,x)>=y){
			modify(1,1,n,x,x,query(1,1,n,x,x)+y);continue;
		}
		int l=2,r=x,pos;
		while(l<=r){
			int mid=(l+r)/2;
			if(query(1,1,n,mid-1,mid-1)*(x-mid+1)-query(1,1,n,mid,x)<=y){
				pos=mid;r=mid-1;
			}
			else{
				l=mid+1;
			}
		}
	//	cout<<" "<<pos<<" "<<query(1,1,n,1,1)<<endl;
		ll val=query(1,1,n,pos-1,pos-1);
		ll he=query(1,1,n,pos,x);
		modify(1,1,n,pos,x,val);
		y-=val*(x-pos+1)-he;
		int num=x-pos+2;
		if(y/num){
			modify(1,1,n,pos-1,x,val+y/num);
		}
		if(y%num){
			modify(1,1,n,pos-1,pos-2+y%num,val+y/num+1);
		}
	}
	for(int i=1;i<=n;i++){
		printf("%lld\n",query(1,1,n,i,i));
	}
	return 0;
}

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

int inf = (1 << 30);
int mod = 1e9;
long long long_inf = (1LL << 60);

int main(){

    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vector<int> unite;
    if(S.front() == '0') unite.emplace_back(0);
    for(int i = 0; i < S.length(); i++){
        int count = 0;
        for(int j = i; S[i] == S[j]; j++){
            count++;
            i = j;
        }
        unite.emplace_back(count);
    }
    if(S.back() == '0') unite.emplace_back(0);

    vector<int> csum(unite.size() + 1, 0);
    for(int i = 0; i < unite.size(); i++) csum[i + 1] = csum[i] + unite[i];

    int ans = 0;
    for(int left = 0; left < csum.size(); left += 2){
        int right = left + (2 * K + 1);
        if(right >= csum.size()) right = csum.size() - 1;
        ans = max(ans, csum[right] - csum[left]);
    }

    if(ans == -1) cout << N << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
int main(){
	int n,m;
	while(~getII(n,m)){
		int ans=0;
		ans+=n*(n-1);
		ans+=m*(m-1);
		printf("%d\n",ans/2);
	}
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    f = LI()
    a.sort()
    f.sort(reverse = True)
    M = 0
    for i in range(n):
        M = max(M,a[i]*f[i])
    l = -1
    r = M
    while r-l > 1:
        m = (l+r)>>1
        s = 0
        for i in range(n):
            p = m//f[i]
            s += max(0,a[i]-p)
            if s > k:
                l = m
                break
        else:
            r = m
    print(r)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 106572
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

typedef long long ll;

int depth(int i, map<int, vector<int>> &child) {

  vector<int> &childs = child[i];

  if( childs.empty() ) { return 0; }

  // それぞれの子のトーナメントの深さをもとめる。
  vector<int> dc; // depth of childs
  for(auto c: childs) {
    dc.push_back( depth(c, child) );
  }

  // 深さが浅い人と先に対戦する。
  sort(dc.begin(), dc.end());

  int res = 0;
  int cn = dc.size();           // number of child
  for(int k = 0; k < cn; k++) {
    res = max(res, dc[k] + cn - k);
  }

  return res;

}

 int main() {

   int N;
   cin >> N;

   // child[i] == (i に負けた人たち)
   map< int, vector<int>  > child;
   for(int i = 2; i <= N; i++ ) {
     int p;
     cin >> p;
     child[p].push_back(i);
   }

   cout << depth(1, child) << "\n";

   return 0;
 }



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

int main() {
  int N, a, b, c; 
  cin >> N;
  c = 0;
  for (int i=0; i<N; i++) {
    cin >>a >>b;
    c += (b-a)+1;
  }
  cout << c <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  long long int a, b;
  scanf("%lld %lld", &a, &b);
  if(a < b){
    long long int sw = a;
    a = b;
    b = sw;
  }
  long long int r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  long long int rb = sqrt(b);
  int ans = 1;
  if(b % 2 == 0){
    ans++;
  }
  while(b % 2 == 0){
    b /= 2;
  }
  for(long long int i = 3; i < rb; i += 2){
    if(b % i == 0){
      ans++;
    }
    while(b % i == 0){
      b /= i;
    }
    if(b == 1){
      break;
    }
  }
  if(b != 1){  //ルートbまで割り切れなかったら残りは素数
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
a =list(map(int,input().split()))
b =list(map(int,input().split()))
dif = []
for i in range(N):
	dif.append(a[i]-b[i])
dif.sort()
if sum(dif) < 0:
	print(-1)
else:
	Count1 = 0
	Sum1 = 0
	for i in range(N):
		if dif[i] < 0:
			Count1 += 1
			Sum1 += dif[i]
		else:
			c = Count1
			break
	Sum2 = 0
	for i in range(N-c):
		if  Sum2 < (-1)*Sum1:
			Sum2 += dif[N-i-1]
			Count1 += 1
		else:
			break
	print(Count1)


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

int main(){
    int a, b, d, r;
    double f;

    scanf("%d %d", &a, &b);

    d = a/b;
    r = a%b;
    f = (double)a/(double)b;

    printf("%d %d %f", d, r, f);

    return 0;
}


Measured memory_bytes: 2756
N = int(input())
a = set()
lst = []
for i in range(N):
    s = input()
    a.add(s)
    lst.append(s)
if len(a) != N:
    print('No')
    exit()
for i in range(N-1):
    if lst[i][-1] == lst[i+1][0]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll k,c = 0;
    cin >> s >> k;
    rep(i,s.length()){
        if (s[i] == '1') c++;
        else break;
    }
    if (c == s.length() || c >= k) PRINT(1);
    else PRINT(s[c]);
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


int N;
int A[100010];


signed main(){
    cin >> N;
    int ans = 0;
    int cnt = 0;
    int m = INF;
    rep(i, 0, N){
        cin >> A[i];
        if(A[i] < 0) cnt++;
        chmin(m, abs(A[i]));
        ans += abs(A[i]);
    }

    if(cnt%2) cout << ans-2*m << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

ll T[110];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);
    int N;
    cin >> N;
    map<int, int> mp;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for (auto e : mp)
    {
        if (e.second % 2 != 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n,ans;

	while( cin >> n ){
		ans = 0;
		if(n<=36){
			for(int a=0 ; a<=9 ; a++){
				for(int b=0 ; b<=9 ; b++){
					for(int c=0 ; c<=9 ; c++){
						for(int d=0 ; d<=9 ; d++){
							if((a+b+c+d)==n){
								ans++;
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}  

Measured memory_bytes: 3064
n,m = map(int, input().split())
lst = []
cnt = []

for i in range(n):
    k = list(map(int, input().split()))
    for j in k[1:]:
        lst.append(j)
    
for i in range(1, m+1):
    cnt.append(lst.count(i))

print(cnt.count(n))

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int W[105];
    for(int i= 0; i < N; ++i){
        cin >> W[i];
    }
    
    int pre = 0; 
    int back = 0;
    int ans = 999999;

    for(int i = 0; i <= N; i++){
        for(int j = 0; j < i; j++){ 
            pre += W[j];
        }
    
        for(int k = i; k < N; k++){
            back += W[k];
        }

        
        if(ans > abs(pre - back)){
            ans = abs(pre - back);
        }

        pre = 0;
        back = 0;
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define DEC(i,a,b) for(int i=(a);i>=(b);--i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<typename T,typename U> inline bool smax(T&x,const U&y){return y>x?(x=y,1):0;}
template<typename T,typename U> inline bool smin(T&x,const U&y){return y<x?(x=y,1):0;}
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second
inline int read(){
	int w=0,p=0;char c;
	while(!isdigit(c=getchar()))if(c=='-')p=1;
	while(isdigit(c))w=(w<<1)+(w<<3)+(c^'0'),c=getchar();
	return p?-w:w;
}
const int N=3e5+7;
char s[N];
int n,d[N];
int main(){
	n=read();
	scanf("%s",s+1);
	REP(i,1,n){
		d[i]=d[i-1]+(s[i]=='E'?1:0);
	}
	int ans=N;
	REP(i,1,n)smin(ans,i-1-d[i-1]+d[n]-d[i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1664
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	int A, B, cnt = 0;
	cin >> A >> B;

	for (int i = A; i <= B; i++) {

		if (i - (i % 10000) == (i % 10) * 10000 && (i - i % 1000) - (i - i % 10000) == (i % 100 - i % 10) * 100)cnt++;

	}
	cout << cnt << endl;

	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 v  = vector<ll>;
using P  = pair<ll,ll>;

int main(){
    int n,k;
    string s;
    cin >>n>>s>>k;
    k--;
    rep(i,n){
      if(s[i]==s[k])cout << s[i];
      else cout << "*";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n, w;
	cin>>n>>w;
	vector< vector<int> > h( n+1, vector<int> (2) );
	for( int i=1 ; i<= n; i++ )
		cin>>h[i][0]>>h[i][1];

	vector< vector<long long > > dp( n+1, vector<long long> (w+1) );

	long long result = 0 ;
	for( int i=1 ; i<=n ; i++ )
	{
		for( int j=1 ; j<=w ; j++ )
		{
			// if( j-h[i][0] == 0 )
			// 	dp[i][j] = h[i][1];
			if(  j-h[i][0] >= 0 )
				dp[i][j] = max(dp[i-1][ j-h[i][0] ] + h[i][1], dp[i-1][j]);
			else 
				dp[i][j] = dp[i-1][j];
			result = max(result, dp[i][j]);
		}
	}
	cout<<result;
	return 0 ;

}

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

int main()
{
	int n,i;
	cin>>n;
	vector<int> a(n);
	map<int,long long> cnt;
	
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	
	long long ret=0;
	map<int,long long>::iterator p;
	
	for(p=cnt.begin();p!=cnt.end();p++)
	{
		ret+=(p->second-1)*p->second/2;
	}
	
	for(int k=0;k<n;++k)
	{
		long long n=cnt[a[k]];
		long long tmp=ret-(n-1)*n/2+(n-2)*(n-1)/2;
		cout<<tmp<<"\n";
	}
	return 0;
}

Measured memory_bytes: 10240
#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) << " "
int main(void){
    int a,b;cin>>a>>b;
    if(a>=10||b>=10){co("-1");return 0;}
    a*b==0?co("-1"):co(a*b);
}



Measured memory_bytes: 256
N, M = map(int, input().split())
shop = []
for i in range(N):
    a, b = map(int, input().split())
    shop.append([a, b])
shop.sort(key=lambda x: x[0])

amount = 0
quantity = 0
for s in shop:
    if quantity + s[1] < M:
        amount += s[0] * s[1]
        quantity += s[1]
    else:
        amount += (M - quantity) * s[0]
        quantity = M
        break

print(amount)

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

int main() {
	// your code goes here
     long long int n,d;
     cin>>n>>d;
     long long int c=0;
     while(n--)
     {
     	long long int x,y;
     	cin>>x>>y;
     	long long int sum=x*x+y*y;
     	long long int sum2=ceil(sqrt(sum));
     	if(sum2<=d)
     	 c++;
     }
    cout<<c;
	return 0;
}

Measured memory_bytes: 3740
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    int A, B;
    cin >> A >> B;
    if(A == B) cout << "Draw" << endl;
    else if(A == 1) cout << "Alice" << endl;
    else if(B == 1) cout << "Bob" << endl;
    else if(A > B) cout << "Alice" << endl;
    else cout << "Bob" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

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


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

const ll MOD = 1000000007;
const ll INF = 1000000000;

int h[105];
ll ans = 0;



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

    int t = 0;
    ll ans = 0;
    ll sum = 0;

    for (int s = 0; s < n; s++){
        while (t < n && (sum ^ a[t]) == (sum + a[t])){
            sum += a[t++];
        }
        ans += t - s;
        if (s == t) t++;
        sum -= a[s];
    }

    cout << ans << endl;
    
}



Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner( System.in );
        int len = scanner.nextInt();
        int[] arr = new int[100001];
        long total = 0;
        for (int count = 0; count < len; count++) {
            int num = scanner.nextInt();
            arr[num]++;
            total += num;
        }
 
        int queries = scanner.nextInt();
        for (int count = 0; count < queries; count++) {
            int num = scanner.nextInt();
            int replace = scanner.nextInt();
            if( arr[num] != 0 ){
                arr[replace] += arr[num];
                total += ( replace - num ) *  arr[num];
                arr[num] = 0;
            }
            System.out.println(total);
        }
        scanner.close();
    }
}

Measured memory_bytes: 60532