akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Collections.Generic;

namespace ABC100A
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var A = ss.Next(int.Parse);
            var B = ss.Next(int.Parse);
            var ans = A <= 8 && B <= 8;
            sw.WriteLine(ans ? "Yay!" : ":(");
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 11220
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine
getString = readString <$> BS.getLine

simulate as bs k n
  | as' == bs' = 2 * n - k
  | otherwise = simulate as bs (k -1) n
  where
    as' = drop (n - k) as
    bs' = take k bs

main = do
  n <- getInt
  [s] <- getString
  [t] <- getString
  print $ simulate s t n n


Measured memory_bytes: 3776
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
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);
        BTripleDots solver = new BTripleDots();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTripleDots {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            String s = in.next();
            if (s.length() <= k) {
                out.println(s);
                return;
            }
            out.println(s.substring(0, k) + "...");
        }

    }

    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: 25604
#include <stdio.h>
#include <string.h>

int main(void)
{
    char num[5];
    
    scanf("%s", num);
    
    int i, l;
    
    l = strlen(num);
    
    for(i = 0; i < l; i++) {
        if(num[i] == '1') {
            printf("9");
        } else {
            printf("1");
        }
    }
    
    
    printf("\n");
    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> x(n);
    for (auto &c : x) cin >> c;
    int ans = INF;
    for (int p = 0; p <= 100; p++) {
        int now = 0;
        for (auto &c : x) {
            now += (c - p) * (c - p);
        }
        ans = min(ans, now);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	char ch;
	cin>>ch;
	if(ch=='A')
		cout<<"T"<<endl;
	else if(ch=='T')
		cout<<"A"<<endl;
	else if(ch=='C')
		cout<<"G"<<endl;
	else
		cout<<"C"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define EPS 0.0001

int cnt[26];
int main() {
	int N, K;
	cin >> N >> K;
	REP(i, 0, N) {
		string buf;
		cin >> buf;

		++cnt[buf[0] - 'A'];
	}

	int sum = 0;
	bool flg = true;
	while (flg) {
		flg = false;
		int prog = 0;
		sort(cnt, cnt + 26, greater<int>());
		REP(i, 0, 26) {
			if (cnt[i] > 0) {
				--cnt[i];
				++prog;
			}
			if (prog == K) {
				flg = true;
				++sum;
				break;
			}
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  static string[] map;
  static int H;
  static int W;
        static void Main(string[] args)
        {
          //入力を受け取る
          var XY = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
          var X = XY[0];
          var Y = XY[1];
          var count = 0;
          
          while(X <= Y){
            count++;
            X = 2*X;
          }
          
          Console.WriteLine(count);
        }
}


Measured memory_bytes: 13268
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int h,w;

    cin >> h >> w;
	vector<string> s(h);
    for (int i = 0; i < h; i++){
		cin >> s[i];
    }

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

    bool can = true;
    for (int i = 0; i < h; i++){
        for (int k = 0; k < w; k++){
            if (s[i][k] != '#'){
                continue;
            }
            int cnt = 0;
            bool found = false;
            for (int p = 0; p < 4; p++){
                const int x = k + dx[p];
                const int y = i + dy[p];
                if (x >= 0 && x < w && y >= 0 && y < h){
                    if (s[y][x] == '#'){
                        found = true;
                    }
                }
            }
            if (found != true){
                cout << "No" << endl;
                exit(0);
            }
        }
    }

    cout << "Yes" << endl;
    /*if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    */
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<tgmath.h>
using namespace std;

void insertionSort(int a[],int n){
    for (int i = 1; i < n; i++)
    {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v) 
        {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for (int i = 0; i < n; i++)
        {
            cout << a[i];
            if(i != n-1) cout << " ";
            else cout << endl;
        }
    }
}

int main(){
    int a[100];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if(i != n-1) cout << " ";
        else cout << endl;
    }
    insertionSort(a,n);
}


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

int main(){
int x,y,s,max=0;
cin >> x;
cin >> y;
cin >> s;
do
	{
	for(int i=1;i<s;i++)
		for(int j=1;j<s;j++)
			if(i*(100+x)/100+j*(100+x)/100==s&&i*(100+y)/100+j*(100+y)/100>max)
				max=i*(100+y)/100+j*(100+y)/100;
	cout << max << endl;
	max=0;
	cin >> x;
	cin >> y;
	cin >> s;
	}
while (x+y+s>0);
return 0;
}

Measured memory_bytes: 1160
/**
*    created: 21.06.2020 01:18:00
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> r(n);
    int a, b;
    rep(i,m) {
        cin >> a >> b;
        r[a-1]++;
        r[b-1]++;
    }
    rep(i,n) cout << r[i] << endl;
    return 0;
}

Measured memory_bytes: 3648
class DP:

    def __init__(self, n):
        self.memo = [{} for _ in range(n+1)]
        self.end = n
        self.mod = 10 ** 9 + 7

    def dp(self, cur, last3):
    
        if last3 in self.memo[cur]:
            return self.memo[cur][last3]
        if cur == self.end:
            return 1
        
        ret = 0
        for c in 'ACTG':
            if self.is_ok(last3 + c):
                ret = (ret + self.dp(cur + 1, last3[1:] + c)) % self.mod

        self.memo[cur][last3] = ret
        return ret

    def is_ok(self, last4):
        
        for i in range(4):
            t = list(last4)
            if i < 3:
                t[i], t[i+1] = t[i+1], t[i]
            if ''.join(t).count('AGC') > 0:
                return False
        return True


def main():

    n = int(input())
    solver = DP(n)

    print(solver.dp(0, 'CCC'))


main()


Measured memory_bytes: 3844
#include<iostream>
#include<map>

using namespace std;

map<long long,long long> Map;

int main ()
{
    long long n,i,x,sum=0,res=0;

    cin>>n;

    Map[0]=1;

    for(i=0;i<n;i++)
    {
        cin>>x;

        sum+=x;

        res+=Map[sum];
        Map[sum]++;
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 12800
main :: IO ()
main = do
  a <- readLn
  b <- readLn
  c <- readLn
  x <- readLn
  print . length $ [ 1 | a1 <- [0..a], b1 <- [0..b], c1 <- [0..c], a1*500+b1*100+c1*50==x ]

Measured memory_bytes: 1020
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
i = 0
B = []
b = [A[0]]
zouka = 0
f = True
while i < N-1:
    if A[i] == A[i+1]:
        b.append(A[i])
        i += 1
        continue

    if zouka == 0:
        if A[i] < A[i+1]:
            zouka = 1
        else:
            zouka = -1

    if A[i] < A[i+1]: #増加
        if zouka == 1:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            zouka = 0
            
    else: #減少
        if zouka == 1:
            B.append(b)
            b = [A[i+1]]
            zouka = 0
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))


Measured memory_bytes: 63596
def resolve():
    '''
    code here
    '''
    line = input()

    cnt = 1
    prev = line[0]

    if len(line) == 1:
        res = 0
    else:
        for item in line[1:]:
            if item == prev:
                pass
            else:
                cnt += 1
            prev = item
        res = cnt -1
    print(res)

if __name__ == "__main__":
    resolve()


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


using namespace std;

struct Node{
  Node *right;
  Node *left;
  Node *parent;
  int key;
};

Node *root ,*NIL;

Node* find(Node *u ,int key){
  while(u!=NIL && key!=u->key){
    if(key < u->key){
      u=u->left;
    }else
      u=u->right;
  }
  return u;
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z = (Node *) malloc(sizeof(Node));

  z->key = k;
  z->left = NIL;
  z->right = NIL;


  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }


}

void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  string com;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    cin>>com;
    if ( com=="insert" ){
      cin>>x;
      insert(x);
    } else if ( com == "print" ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(com=="find"){
      cin>>x;
      Node *a=find(root ,x);
      if(a!=NIL)
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }
  }

  return 0;
}



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

int N, X;
int P[51];
int L[51];

int dfs(int n, int x) {
  // cout << n << " " << x << endl;
  if ( L[n] <= x ) return P[n];
  if ( n < 0 || x == 0 ) return 0;  

  int add = (x >= (L[n]+1)/2);
  if ( x > (L[n]+1)/2 ) return dfs(n-1, L[n-1]) + dfs(n-1, x-(L[n]+1)/2) + add;  
  else return dfs(n-1, x-1) + add;
}

signed main() {
  cin >> N >> X;

  P[0] = 1LL;
  L[0] = 1LL;  
  for ( int i = 1; i < 51; i++ ) {
    P[i] = 2LL*P[i-1]+1LL;
    L[i] = 2LL*L[i-1]+3LL;    
  }

  /*for ( int i = 0; i < 4; i++ ) {
    cout << P[i] << " " << L[i] << endl;
    }*/

  cout << dfs(N, X) << endl;

  return 0;
}


Measured memory_bytes: 3560
lst1 = [1, 3, 5, 7, 8, 10, 12]
lst1_s = list(map(str, lst1))
lst2 = str([4, 6, 9, 11])
lst2_s = list(map(str, lst2))
lst3 = str([2])
lst3_s = list(map(str, lst3))

num = input().split()
a, b = num

if (a in lst1_s and b in lst1_s):
    print('Yes')
elif(a in lst2_s and b in lst2_s):
    print('Yes')
elif(a in lst3_s and b in lst3_s):
    print('Yes')
else:
    print('No')
        

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	ll a,b;
	cin>>a>>b;
	string s;cin>>s;
	bool ok = true;
	for(int i=0;i<s.length();i++)
		if(i==a)
			ok&=s[i]=='-';
		else 
			ok &= (s[i]>='0' && s[i]<='9');
	puts(ok?"Yes":"No");





}


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


void solve(long long A, long long B){
    long long ans;
    ans = max(A+A-1, B+B-1);
    ans = max(ans, A+B);
    cout << ans << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    cin >> A;
    long long B;
    cin >> B;
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include<cstdio>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(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 repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	char  s[128],t[128];
	scanf("%s %s",s,t);
	int ans=0;
	sort(s,s+strlen(s));
	sort(t,t+strlen(t),greater<char>());
	clog<<s<<" "<<t<<endl;
	ans=strcmp(s,t);
	printf("%s\n",ans<=-1?"Yes":"No");
}

Measured memory_bytes: 3764
#include <iostream>
using namespace std;
bool prime[60001];

int main(void) {
  for (int i = 0; i <= 60000; i++) {
    prime[i] = true;
  }
  prime[0] = prime[1] = false;

  for (int i = 2; i <= 60000; i++) {
    if (prime[i]) {
      for (int j = 2; i * j <= 60000; j++) {
	prime[i*j] = false;
      }
    }
  }

  int n;
  while (cin >> n) {
    for (int i = n - 1; i >= 0; i--) {
      if (prime[i]) {
	cout << i << " ";
	break;
      }
    }
    for (int i = n + 1; i <= 60000; i++) {
      if (prime[i]) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#define N 100000

struct Node{int r,l,in;};
struct Node T[N];

int n , length[N];

int depth(int , int);

int main(){
  int i,id,k,c,j,l,in;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    T[i].r = -1;
    T[i].l = -1;
    T[i].in = -1;
  }
  
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&id,&k);
    for(j = 0 ; j < k ;j++){
      scanf("%d",&c);
      if(j == 0) T[id].l = c;
      else T[l].in = c;
      l = c;
      T[c].r = id;
    }
  }
  for(i = 0 ; i < n ; i++)
    if(T[i].r == -1) in = i;
  
  depth(in , 0);
  
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d,", i , T[i].r , length[i]);
    printf(" ");
    if(T[i].r == -1) printf("root, [");
    else if(T[i].l == -1) printf("leaf, [");
    else printf("internal node, [");
    c=T[i].l;
    while(c != -1){
      if(c == T[i].l)printf("%d",c);
      c = T[c].in;
      if(c != -1)printf(", %d",c);
     
     
    }
    printf("]\n");
  }
  return 0;
}

int depth(int u, int q){
  length[u] = q;
  if(T[u].in != -1) depth(T[u].in , q);
  if(T[u].l != -1) depth(T[u].l , q+1);
}

Measured memory_bytes: 5296
n=int(input())
A=list(map(int,input().split()))
x=0
y=0
z=0
ans=1
for a in A:
    c=0
    X,Y,Z=x,y,z
    if a==x:
        x+=1
        c+=1
    if a==y:
        c+=1
        if a!=X:
            y+=1
    if a==z:
        c+=1
        if a!=X and a!=Y:
            z+=1
    ans=ans*c%1000000007
print(ans)

Measured memory_bytes: 13964
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    bool flag = 0;
    if (a == b && a != c) flag = 1;
    if (a == c && a != b) flag = 1;
    if (b == c && a != b) flag = 1;
    if (flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  int64_t b_only = 0;
  int64_t a_only = 0;
  int64_t b_and_a = 0;
  int64_t result = 0;
  for (int64_t i = 0; i < N; ++i) {
    string s;
    cin >> s;
    for (int64_t j = 0; j <= static_cast<int64_t>(s.length()) - 2; ++j) {
      if (s.c_str()[j] == 'A' && s.c_str()[j + 1] == 'B') {
        ++result;
      }
    }
    if (s.c_str()[0] == 'B' && s.c_str()[static_cast<int64_t>(s.length()) - 1] == 'A') {
      ++b_and_a;
    } else if (s.c_str()[0] == 'B') {
      ++b_only;
    } else if (s.c_str()[static_cast<int64_t>(s.length()) - 1] == 'A') {
      ++a_only;
    }
  }
  result += max(b_and_a - 1, static_cast<int64_t>(0));
  if (b_and_a > 0) {
    if (b_only > 0) {
      ++result;
      --b_only;
    }
    if (a_only > 0) {
      ++result;
      --a_only;
    }
  }
  result += min(b_only, a_only);
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 508
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    string x;
    cin>>x;
    int ith = 0;
    int ans = 0;
    for(int i = 0; i < x.size() ; i++){
        if(x[i] == 'W'){
            ans += i - ith;
            ith++;
        }
    }
    cout<<ans<<endl;

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
vector<P> to[100001];
ll d[100001]={};
ll n,q,k;
void dfs(int i,int par){
    for(auto x:to[i]){
        if(x.first!=par){
            d[x.first]=d[i]+x.second;
            dfs(x.first,i);
        }
    }
}
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        to[a].push_back(P(b,c));
        to[b].push_back(P(a,c));
    }
    cin>>q>>k;
    dfs(k,-1);
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        cout<<d[x]+d[y]<<endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  
  int count=0;
  
  for(int i=1;i<n-1;i++){
    if(p.at(i-1) > p.at(i) && p.at(i) > p.at(i+1) || p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1)){
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long H = GetLong();
		long W = GetLong();

		WriteLine(Min(solve(H, W), solve(W, H)));
	}

	private long solve(long H, long W)
	{
		long min = long.MaxValue;
		for(long i = 1; i <= H - 1; i++)
		{
			var S = new long[3];
			S[0] = (H - i) * W;

			if(i >= 2)
			{
				S[1] = (i / 2) * W;
				S[2] = (i - i / 2) * W;
				chmin(ref min, S.Max() - S.Min());
			}

			if(W >= 2)
			{
				S[1] = i * (W / 2);
				S[2] = i * (W - W / 2);
				chmin(ref min, S.Max() - S.Min());
			}			
		}
		return min;
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 40844
#include <vector>
#include <algorithm>
#include <limits.h>
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#define MOD 1000000007
typedef  long long int  lli;
using namespace std;
bool increasing_check(int a[],int n)
{
    for(int i=0;i<n;i++) {
        if(a[i]==i){}
        else return false;
    }
    return true;
}
int findMex(int a[],int n)
{
    map<int,int> mp;
    for(int i=0;i<n;i++)
    {
        mp[a[i]]++;
    }
    for(int i=0;i<=n;i++)
    {
        if(mp.find(i)==mp.end())  return i;
    }
}
int unfixed_point(int a[],int n)
{
    for(int i=0;i<n;i++)
    {
        if(a[i]!=i) return i;
    }
}
int main() {
    int t; t=1;
    while(t--) {
    double n; cin>>n;
   cout<<ceil(n/1000)*1000-n<<"\n";

    }
    return 0;
}


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

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

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

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  double n;
  cin>>n;
  int ans=round(n/2);
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void DFS(int p, int cur, vector<vector<pair<int, ll>>> &V, vector<ll> &D, ll sum){
  D[cur] = sum;
  rep(i, 0, V[cur].size()){
    if(V[cur][i].first == p) continue;
    DFS(cur, V[cur][i].first, V, D, sum + V[cur][i].second);
  }
}

void Main() {
  int N; cin >> N;
  vector<vector<pair<int, ll>>> V(N);
  rep(i, 0, N - 1){
    int a, b, c; cin >> a >> b >> c; a--; b--;
    V[a].push_back(make_pair(b, c));
    V[b].push_back(make_pair(a, c));
  }
  int Q, K; cin >> Q >> K; K--;
  vector<ll> D(N, 0);
  DFS(-1, K, V, D, 0);
  rep(q, 0, Q){
    int x, y; cin >> x >> y; x--; y--;
    cout << D[x] + D[y] << endl;
  }
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 25216
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

string vs[] = {"147", "28", "369"};
int state, foot;
const int LEFT = 0;
const int MID = 1;
const int RIGHT = 2;

const int LFOOT = 0;
const int RFOOT = 1;

int calc(string s, int init) {
    int state = -1, foot = init, ret = 0, temp = 0;
    rep(turn,0,s.length()) {
        rep(i,0,3) if(vs[i].find(s[turn]) != string::npos) temp = i;
        bool changed = false;
        if(state != -1) {
            if(foot == LFOOT && state > temp) ret++, changed = true;
            if(foot == RFOOT && state < temp) ret++, changed = true;
        }
        state = temp;
        if(!changed) foot ^= 1;
    }
    return ret;
}

signed main() {
    string s;
    while(cin >> s, s != "#") {
        int c1 = calc(s, 0);
        int c2 = calc(s, 1);
        cout << min(c1, c2) << endl;
    }
    return 0;
}

Measured memory_bytes: 3312
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a * b > c* d) {
		cout << a * b << endl;
	}
	else {
		cout << c * d << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

// ソートしたい値（A, B）で構成された構造体
struct Info {
	long long valA;
	long long valB;

	Info(long long A, long long B) {
		valA = A;
		valB = B;
	}
};

// ソートするための比較演算子
bool cmp(const Info& a, const Info& b) {
	if (a.valA == b.valA) {
		return a.valB < b.valB;
	}
	else {
		return a.valA < b.valA;
	}
}

int main() {

	int N, M;
	cin >> N >> M;

	vector<Info> val(N, Info(0, 0));
	long long A, B;
	for (int i = 0; i < N; i++) {
		cin >> A >> B;
		val[i] = Info(A, B);
	}

	sort(val.begin(), val.end(), cmp);

	long long ans = 0;
	int sum = 0;
	int ind = 0;
	while (sum < M) {
		if ((M - sum) > val[ind].valB) {
			ans += val[ind].valA * val[ind].valB;
		}
		else {
			ans += val[ind].valA * (M - sum);
		}
		sum += val[ind].valB;
		ind += 1;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  int n,i,count=0,score;
  scanf("%d",&n);
  int a[n+1],c[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=0;i<n;i++){
    scanf("%d",&score);
    count+=score;
  }
  for(i=0;i<n-1;i++)
    scanf("%d",&c[i]);
  for(i=0;i<n-1;i++){
    if(a[i]==a[i+1]-1)
      count+=c[a[i]-1];
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { 
    return mint(-x);
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { 
    (x *= a.x) %= mod; 
    return *this;
  }
  mint operator+(const mint a) const { 
    return mint(*this) += a;
  }
  mint operator-(const mint a) const { 
    return mint(*this) -= a;
  }
  mint operator*(const mint a) const { 
    return mint(*this) *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return *this *= a.inv();
  }
  mint operator/(const mint a) const {
    return mint(*this) /= a;
  }
};
istream& operator>>(istream& is, mint& a) { 
  return is >> a.x;
}
ostream& operator<<(ostream& os, const mint& a) { 
  return os << a.x;
}

mint f(int n){
  if(n==0) return 1;
  mint x = f(n/2);
  x *= x;
  if(n % 2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  mint ans = f(n);
  ans -= 1;
  ans -= choose(n,a);
  ans -= choose(n,b);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3672
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

vector<P> res;

int main(void){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(res.size()==n-1)break;
			string str="";
			for(int k=0;k<n;k++){
				if(i==k || j==k)str+='1';
				else str+='0';
			}
			cout << "? " << str << endl;
			int v;
			scanf("%d",&v);
			if(v!=0)res.push_back(P(i,j));
		}
	}
	string res2="! ";
	for(int i=0;i<res.size();i++){
		res2+='(';
		string num="";
		while(res[i].first>0){
			num+=(res[i].first%10+'0');
			res[i].first/=10;
		}
		if(num.size()==0)num+='0';
		reverse(num.begin(),num.end());
		res2+=num;
		res2+=',';
		num="";
		while(res[i].second>0){
			num+=(res[i].second%10+'0');
			res[i].second/=10;
		}
		if(num.size()==0)num+='0';
		reverse(num.begin(),num.end());
		res2+=num;
		res2+=')';
		if(i+1!=res.size())res2+=' ';
	}
	cout << res2 << endl;
	return 0;
}


Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<long long> vll;

int main()
{
	//ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  double r;
  cin>>r;
  cout<<2*3.1416*r<<endl;
   return 0;
}


Measured memory_bytes: 3788
#=============================================================================
# ABC133 B
#=============================================================================
import itertools
import math
N,D=map(int,input().split())
id=[i for i in range(N)]
point=[list(map(int,input().split())) for _ in range(N)]
comb=itertools.combinations(id,2)
cnt=0
for p,q in comb:
    Squ=0
    for k in range(D):
        Squ+=(point[p][k]-point[q][k])**2
    if math.ceil(Squ**0.5)==Squ**0.5:
        cnt+=1
print(cnt)

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

// 解法 -> 順番に埋めて行って偶数列を反転させる
int main(){
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>> grid(h, vector<int>(w, -1));
    vector<int> lg;
    rep(i, a.size()){
        rep(j, a[i]){
            lg.push_back(i + 1);
        }
    }
    int idx = 0;

    // h * wに格納する
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            grid[i][j] = lg[idx];
            idx++;
        }
    }
    // 偶数列を反転させる
    for(int i = 0; i < h; i++){
        if(i % 2 == 1){
            reverse(grid[i].begin(), grid[i].end());
        }
    }

    rep(i, h){
        rep(j, w){
            if(j) cout << " ";
            cout << grid[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int ans = (a+b+c+d+e+f) - min(a, min(b, min(c, d))) - min(e, f);
  cout << ans << endl;
}


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

int main() {
  int n,m;
  int l=0;
  cin >> n >> m;
  vector<int>a(n);
  for(int i=0;i<n;i++){
  cin >> a.at(i);
    if(a.at(i)>=m){
    l++;
    }
  }
  cout << l << endl; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define D(i,n) for (int i=(n); i-->0;)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream& operator<<(ostream& os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i]; return os;}
const bool debug = 1;

int sumOf(string s) {
    int sum = 0;
    for (char c : s)
        sum += c-'0';
    return sum;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //int n; cin>>n;
    string s; cin>>s;
    int n = S(s);
    int ma = sumOf(s);
    F(i,S(s)) {
        MA(ma, sumOf(s.substr(0,i+1))-1 + 9*(n-1-i));
    }
    cout << ma << endl;
}

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

#define int long long
signed main(){
  int x;
  cin>>x;
  for(int i=0;i<=x;i++){
    if(i*(i+1)/2>=x){
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
X=int(input())
n=10**6+1
primes=set(range(2,n+1))
for i in range(2,int(n**0.5+1)):
  primes.difference_update(range(i*2,n+1,i))
primes=list(primes)
for i in range(X,n):
  if i in primes:
    print(i)
    break

Measured memory_bytes: 83932
#include <iostream>
#include <iomanip>
#include <ios>
#include <sstream>
#include <cstdio>

#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <regex>
#include <utility>
#include <random>

#include <cstddef>
#include <cstdint>
#include <cfloat>
#include <limits>

#include <array>
#include <bitset>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <valarray>
#include <vector>
#include <deque>
#include <forward_list>

#define FOR(i, a, b) for(auto i{a}; i < (b); ++i)
#define RFOR(i, a, b) for(auto i{(b)-1};i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) std::begin(a), std::end(a)
#define CAST static_cast

template<typename T>
constexpr bool in_range(T const &l, T const &a, T const &u){ return l < a && a < u; };
constexpr double inf {std::numeric_limits<double>::infinity()};

#define FAST_TYPE
#ifdef FAST_TYPE
using i32 = std::int_fast32_t;  using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t;
#else
using i32 = std::int_least32_t;  using i64 = std::int_least64_t;
using u32 = std::uint_least32_t; using u64 = std::uint_least64_t;
#endif

using imx = std::intmax_t;
using umx = std::uintmax_t;

using namespace std;

u32 sub_abs(i32 left, i32 right) { return abs(left - right); }

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

  i32 N;
  cin >> N;

  vector<i32> omori(N);

  for (auto& W : omori) cin >> W;

  auto left = omori[0];
  auto right = accumulate(next(begin(omori)), end(omori), 0);
  i32 result_T;

  REP (T, omori.size() - 1) {
    auto WT1 = omori[T + 1];
    result_T = sub_abs(left, right);

    if (result_T > sub_abs(left + WT1, right - WT1)) {
      left += WT1;
      right -= WT1;
    }
    else break;
  }

  cout << result_T << endl;

  return 0;
}

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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n;cin>>n;
	n=n%10;
	if(n==2||n==4||n==5||n==7||n==9) cout<<"hon\n";
	else 
	if(n==0||n==1||n==6||n==8) cout<<"pon\n";
	else cout<<"bon\n";
	
	
return 0;
}



Measured memory_bytes: 3648
from sys import stdin
input = stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)
a = sum(A)

for i in range(N):
    if A[i] < a / (4 * M):
        print("No")
        exit()

    if i >= M - 1:
        print("Yes")
        exit()


Measured memory_bytes: 3060
class Unionfind():
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        while(self.table[x] >= 0):
            x = self.table[x]
        return x

    def same(self, x, y):
        xp = self.find(x)
        yp = self.find(y)
        return xp == yp

    def union(self, x, y):
        xp = self.find(x)
        yp = self.find(y)
        if xp != yp:
            if self.table[xp] < self.table[yp]:
                self.table[xp] += self.table[yp]
                self.table[yp] = xp
            else:
                self.table[yp] += self.table[xp]
                self.table[xp] = yp
    
    def print(self):
        ret = {}
        for i in range(len(self.table)):
            p = self.find(i)
            if p not in ret:
                ret[p] = {i}
            else:
                ret[p].add(i)
        print(ret)

    def size(self, x):
        p = self.find(x)
        return -self.table[p]

n, m, k = map(int, input().split())
u = Unionfind(n)
friend = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    u.union(a-1, b-1)
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
block = [[] for _ in range(n)]
for _ in range(k):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

answer = []
for i in range(n):
    ans = u.size(i) - 1
    for e in block[i]:
        if u.same(i, e):
            ans -= 1
    answer.append(ans - len(friend[i]))
print(*answer)

Measured memory_bytes: 47216
using System;
using System.Collections.Generic;
/*using System.Linq;
using System.Text;
using System.Threading.Tasks;*/

class Program
{
    static void Main(string[] args)
    {
        int hs = int.Parse(Console.ReadLine());
        int h = hs / 3600;
        int m = (hs % 3600) / 60;
        int s = (hs % 3600) % 60;
        Console.WriteLine(h +":"+ m +":"+s);
    }
}

Measured memory_bytes: 9168
from itertools import product
n = int(input())
F = [tuple(map(int, input().split()))for _ in range(n)]
P = [tuple(map(int, input().split()))for _ in range(n)]
INF = 10**18
ans = -INF
for schedule in product([0, 1], repeat=10):
    if 1 not in schedule:
        continue
    p_sum = 0
    for i, f in enumerate(F):
        cnt = 0
        for x, y in zip(schedule, f):
            if x == y == 1:
                cnt += 1
        p_sum += P[i][cnt]
    if ans < p_sum:
        ans = p_sum
print(ans)


Measured memory_bytes: 3064
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut m = 1000;
    let mut k = 0;
    for i in 0..n - 1 {
        if a[i] > a[i + 1] {
            m += k * a[i];
            k = 0;
        } else {
            let x = m / a[i];
            m -= x * a[i];
            k += x;
        }
    }
    m += k * a[n - 1];
    println!("{}", m);
}


Measured memory_bytes: 2108