akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

s_set = set(s)
t_set = set(t)
can = s_set | t_set

ans = 0
for c in can:
    num = s.count(c) - t.count(c)
    ans = max(ans, num)
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
//#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main(){
  int A,B,ans,temp;
  cin >> A >> B;
  if(A<B){
    ans = B + B - 1;
  }else if(A>B){
    ans = A + A - 1;
  }else{
    ans = A + A;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//17D8101003D 田野平 晃樹 TanoMero417 C++
#include <iostream>

using namespace std;

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

    return gcd(b,a%b);
}


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

    cout << gcd(a,b) << endl;
    
    return 0;
}

/*実行結果
15 16
*/


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, M, X;
  cin >> N >> M >> X;
  int C[13];
  int book[13][13];
  for (int i = 0; i < N; i ++) {
    cin >> C[i];
    for (int j = 0; j < M; j ++) {
      cin >> book[i][j];
    }
  }
  int ans = 1e9 + 7;
  for (int i = 0; i < 1 << N; i ++) {
    int i_ = i;
    vector<int>ok(M, 0);
    int di = 0;
    int cst = 0;
    for (int j = 0; j < N; j ++) {
      if (i_ % 2) {
        cst += C[j];
        for (int k = 0; k < M; k ++) {
          ok[k] += book[j][k];
        }
      }
      i_ /= 2;
    }
    for (int j = 0; j < M; j ++) {
      if (ok[j] >= X) di ++;
    }
    if (di == M) {
      ans = min(ans, cst);
    }
  }
  cout << ((ans == 1e9 + 7) ? -1 : ans) << endl;
}



Measured memory_bytes: 3652
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string N = Console.ReadLine();
            if (N[0] == N[1] && N[0] == N[2])
            {
                Console.WriteLine("Yes");
            }
            else if (N[1] == N[2] && N[1] == N[3])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 11092
while True:
    try:
        a, b, c, d, e, f = map(int, input().split())
    except:
        break
    y = (c*d-f*a) / (b*d-e*a)
    x = (c - b*y) / a
    print("{:.3f} {:.3f}".format(x, y))


Measured memory_bytes: 5608
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let h: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut dp = vec![1 << 30; 100100];
    dp[0] = 0;

    for i in 0..n {
        for j in 1..k + 1 {
            if i + j < n {
                dp[i + j] = min(dp[i + j], dp[i] + (h[i] - h[i + j]).abs());
            }
        }
    }
    
    println!("{}", dp[n - 1]);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
n, m, q  = map(int, input().split())
abcd  = [tuple(map(int, input().split())) for i in range(q)]

ans = 0

def check(A):
    global ans
    max_ = 0

    # 点数計算
    for (a, b, c, d) in abcd:
        if A[b-1] - A[a-1] == c:
            max_ += d

    # 最大値更新
    ans = max(ans, max_)

def suretu(A=[], st=1):
    # 再帰的に数字を1つずつ足してって数列生成
    for i in range(st, m+1):
        if len(A) == n: # 数列完成
            check(A)
            return
        else:
            suretu(A + [i], i)

    return ans

print(suretu())


Measured memory_bytes: 9140
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {

            var ab = ReadSplit();
            var a = ab[0];
            var b = ab[1];

            if (a == "H")
            {
                Println(b);
                return;
            }
            else
            {
                if (b == "H")
                    Println("D");
                else
                    Println("H");
            }
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << setprecision(15);
    cout << w*h*0.5 << " ";
    if(w /2 == x && h / 2 == y)cout << 1;
    else cout << 0;
}


Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
S = input()

if len(S) <= K:
	print(S)
else:
	print(S[:K]+"...")

Measured memory_bytes: 10044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    string S,T;
    cin >> S >> T;
    rep(i,N){
        cout << S[i] << T[i];
    }
    cout << endl;



}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++)
   cin>>a[i];
 long long int sum=0; 
 for(int i=1;i<n;i++)
 {
  if(a[i]<a[i-1])
  {
   sum=sum+a[i-1]-a[i];
    a[i]=a[i-1];
  }  
 }
   cout<<sum<<endl;
 return 0;
} 

Measured memory_bytes: 4276
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var values = input[0].split(' ');
    var a = parseInt(values[0], 16);
    var b = parseInt(values[1], 16);
    if (a < b) {
        console.log('<');
    }
    else if (a > b) {
        console.log('>');
    }
    else {
        console.log('=');
    }

    return 0;
}


Measured memory_bytes: 22332
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N,K;
void solve()
{
    vector < int > inp;
    int i,x,ans=0;
    for (i=0;i<N;i++)
    {
        cin>>x;
        inp.push_back(x);
    }
    sort(inp.begin(),inp.end());
    for (i=0;i<K;i++)
        ans+=inp[inp.size()-1-i];
    cout<<ans<<endl;
    inp.clear();
}
int main()
{
    while(cin>>N>>K)
        solve();
}

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

int main(){
  string S; cin >> S;
  int count =0;
  string c;
  if(S[0] == '0'){
    for(int i = 0; i < S.size();i++){
      if(i % 2 == 0){
      c += "0";
    }
      else
      {
        c += "1";
      }
      
    }
  }
  else{
    for(int i = 0; i < S.size();i++){
      if(i % 2 == 0){
      c += "1";
    }
      else
      {
        c += "0";
      }
    }
  }
  for(int i = 0; i < S.size();i++){
    if(S[i] != c[i]){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N = 1e5 + 5, LIM = 1e5 + 1;
int n, cntodd[N], cnteven[N], mxodd[2], mxeven[2], oddnum[2], evennum[2];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	//There must be at least 2 types of numbers, so store the 2 maximums instead for each of them.
	//Check all combinations
	fw (i, 1, n + 1) {
		int x;
		cin >> x;
		if (i & 1) cntodd[x]++;
		else cnteven[x]++;
	}
	fw (x, 1, LIM) {
		if (cntodd[x] > mxodd[0]) {
			mxodd[1] = mxodd[0];
			oddnum[1] = oddnum[0];
			oddnum[0] = x;
			mxodd[0] = cntodd[x];
		} else if (cntodd[x] > mxodd[1]) {
			mxodd[1] = cntodd[x];
			oddnum[1] = x;
		}
		if (cnteven[x] > mxeven[0]) {
			mxeven[1] = mxeven[0];
			evennum[1] = evennum[0];
			evennum[0] = x;
			mxeven[0] = cnteven[x];
		} else if (cnteven[x] > mxeven[1]) {
			mxeven[1] = cnteven[x];
			evennum[1] = x;
		}
	}
	//cout << "mxodd["<<0<<"] = " << mxodd[0] << " 1 = " << mxodd[1] << "\n";
	if (evennum[0] != oddnum[0]) cout << n - mxodd[0] - mxeven[0];
	else {
		cout << n - max(mxodd[0] + mxeven[1], mxodd[1] + mxeven[0]);
	}
	return 0;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
P = list(map(lambda x: int(x) * (int(x) + 1) / 2 / int(x), input().split()))

S = sum(P[0:K])

ans = S
for s, a in zip(P[0: N - K], P[K: N]):
    S += a - s
    ans = max(ans, S)
print(ans)

Measured memory_bytes: 22884
import collections as c
import sys
N = int(input())
A = c.Counter(list(map(int, input().split())))

key = list(A.keys())
val = list(A.values())

quad = [key[i] for i in range(len(key)) if val[i] >= 4]
if len(quad) >= 1:
	quad = max(quad)
else:
	quad = 0

bi = sorted([key[i] for i in range(len(key)) if val[i] >= 2], reverse = True)
if len(bi) >= 2:
	bi_1 = bi[0]
	bi_2 = bi[1]
else:
	bi_1 = 0
	bi_2 = 0

print(max(quad**2, bi_1*bi_2))


Measured memory_bytes: 18592
using System;

public class p0025{
	p0025(){
		string str;
		string[] s1, s2;
		int s, t;
		
		while((str=Console.ReadLine ()) != null){
			s1 = str.Split(' ');
			str = Console.ReadLine();
			s2 = str.Split(' ');
			s = t = 0;
			for(int i = 0; i < 4; ++i) if(s1[i] == s2[i]) ++s;
			for(int i = 0; i < 4; ++i)
				for(int j = 0; j < 4; ++j)
					if(i != j && s1[i] == s2[j]) ++t;
			Console.WriteLine("{0} {1}", s, t);
		}
	}
	
	public static int Main(string[] args){
		new p0025();
		return 0;
	}
}

Measured memory_bytes: 5588
n = int(input())
a = list(map(int,input().split()))



def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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


sorted_a=sorted(a)
for i in range(n):
  if sorted_a[i]==sorted_a[i+1]:
    num = sorted_a[i]
    break

flag = True
for i in range(n+1):
  if a[i]==num:
    if flag:
      first = i
      flag = False
    else:
      second = i

#combination=[0]*(n+2)
#combination[0]=1
#for i in range(1,n+2):
#  combination[i] =combination[i-1]*(n+2-i)//i
#combination2=[0]*(n+2)
#combination2[0]=0
#combination2[1]=1
#for i in range(2,n+2):
#  combination2[i] =combination2[i-1]*(first+n-second+1-(i-1))//(i-1)

#for i in range(1,n+2):
  #ans = comb(n-1,i) + 2*comb(n-1,i-1)-comb(first+n-second,i-1) +comb(n-1,i-2)
  #ans = comb(n+1,i) - comb(first+n-second,i-1)
  #ans = (combination[i]%1000000007-combination2[i]%1000000007)%1000000007
  #print(ans)  
  
for i in range(1,n+2):
  ans = cmb(n+1,i,mod) - cmb(first+n-second,i-1,mod)
  print(ans%mod)

Measured memory_bytes: 22528
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxd = 1e5+10;
int n;
long double arr[maxd],ans;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%Lf",&arr[i]);    
    for(int i=1;i<=n;i++)
    {
        ans += 1.0/arr[i];
    }
    printf("%.10Lf",1.0/ans);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_NM 202
 
struct D{int r, h;};
 
bool compr(const D& d1, const D& d2){
  return d1.r < d2.r;
}
bool comph(const D& d1, const D& d2){
  return d1.h < d2.h;
}
 
int main(void){
  int n, m, dp[MAX_NM];
  D d[MAX_NM];
 
  while(cin >> n, n){
    for(int i = 0; i < n; i++) cin >> d[i].h >> d[i].r;
    cin >> m;
    for(int i = 0; i < m; i++) cin >> d[n+i].h >> d[n+i].r;
 
    int lis_r = 0, lis_h = 0;
    sort(d, d + n + m, compr);
 
    dp[0] = 1;
    for(int i = 1; i < n + m; i++){
      dp[i] = 1;
      for(int j = 0; j < i; j++){
        if(d[j].r < d[i].r && d[j].h < d[i].h){
          dp[i] = max(dp[i], dp[j] + 1);
        }
      }
    }
    lis_r = dp[n+m-1];
 
    sort(d, d + n + m, comph);
 
    dp[0] = 1;
    for(int i = 1; i < n + m; i++){
      dp[i] = 1;
      for(int j = 0; j < i; j++){
        if(d[j].r < d[i].r && d[j].h < d[i].h){
          dp[i] = max(dp[i], dp[j] + 1);
        }
      }
    }
    lis_h = dp[n+m-1];
 
    cout << max(lis_h, lis_r) << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    string S;
    cin >> S;
    if(S=="RRS"||S=="SRR"){
        cout << 2 << endl;
    }else if(S=="RRR"){
        cout << 3 << endl;
    }else if(S=="SSS"){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
        --a.at(i);
    }
    ll tmp = k;
    ll num = 0;
    while(tmp){
        tmp >>= 1;
        ++num;
    }
    vector<vector<ll>> dp(num,vector<ll>(n));
    for(i = 0;i < num;++i){
        rep(j,n){
            if(i == 0) dp.at(i).at(j) = a.at(j);
            else{
                dp.at(i).at(j) = dp.at(i-1).at(dp.at(i-1).at(j));
            }
        }
    }
    ll ans = 0;
    for(i = 0;i < num;++i){
        if(k & (1ll << i)) ans = dp.at(i).at(ans);
    }
    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 100076
def bfs(i, c):
    global V, C

    q = []
    j = i
    while True:
        if C[j] == -1:
            C[j] = c
            q += V[j]
        if len(q) == 0:
            break
        j = q.pop()

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"

Measured memory_bytes: 29128
// abc131d.cpp : Megalomania
#include <bits/stdc++.h>
using namespace std;

bool asc(pair<int,int> &a, pair<int,int> &b){
  return a.second<b.second;
}

int main(){
  int N; cin>>N;
  vector<pair<int,int>> jb;

  for(int i=0;i<N;i++){
    int a,b;cin>>a>>b;
    jb.push_back(make_pair(a,b));
  }

  sort(jb.begin(), jb.end(), asc);

  int a = 0, b = 0;
  for(int i=0;i<N;i++){
    a += jb[i].first;
    if(a>jb[i].second){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

}

Measured memory_bytes: 2420
'use strict'

const main = input => {
	const n = parseInt(input.trim(), 10)
	let maxNum = 0
	let maxCnt = -1

	for (let i = 1; i <= n; i++) {
		let tmpNum = i  
		let tmpCnt = 0

		while (true) {
			if (tmpNum % 2 === 1) break
			tmpNum /= 2
			tmpCnt++
		}

		if (tmpCnt > maxCnt) {
			maxNum = i
			maxCnt = tmpCnt
		}
	}

	console.log(maxNum)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    if(a<=b) return a;
    else return b;
}
int absol(int a)
{
	if(a>0) return a;
	else return -a;
}
int dp(int h[],int n)
{
    int a[n],i;
    if(n==0||n==1)
    {
        return 0;
    }
    if(n==2)
    {
        return h[1]-h[0];
    }
    a[0]=0;
    a[1]=absol(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
        a[i]=min(a[i-2]+absol(h[i]-h[i-2]),a[i-1]+absol(h[i]-h[i-1]));
    }
    return a[n-1];
}
int main()
{
    int n,i;
    cin>>n;
    int h[n];
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    int cost=dp(h,n);
    cout<<cost;
    return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define REP(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u32 N, M = 0;
  cin >> N >> M;

  vector<u64> H;
  u64 h;

  REP(i, N) {
    cin >> h;
    H.push_back(h);
  }

  vector<set<u32, greater<u32>>> t(N + 1);

  u32 a, b;

  REP(i, M) {
    cin >> a >> b;
    t[a - 1].insert(H[b - 1]);
    t[b - 1].insert(H[a - 1]);
  }

  u32 ans = 0;
  REP(n, N) {
    auto &s = t[n];
    if (s.size()) {
      auto it = s.begin();
      if (*it < H[n]) {
        ans++;
      }
    } else {
      ans++;
    }
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 18040
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}

const int MAXN=2005;
ll arr[MAXN];
int main()
{
	fast();
	ll ans=0,j,i,n;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>arr[i];
	sort(arr+1,arr+n+1);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			if(i>=j)
				continue;
			ans+=lower_bound(arr+1,arr+n+1,arr[i]+arr[j])-(arr+j)-1;
		}
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
    #include<vector>
    using namespace std;
    int main()
    {
        int N, K;
        cin >> N >> K;
        int count = 0;
        for(int i = 0; i < N; i++){
            int h;
            cin >> h;
            if (K <= h) {
                count++;
            }
        }
        cout << count;
        return 0;
    }

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

import sys
input=sys.stdin.readline

n=int(input())
arr=list(map(int,input().split()))
ans=0
for i in range(1,n):
    if arr[i]<arr[i-1]:
        ans+=arr[i-1]-arr[i]
        arr[i]=arr[i-1]
print(ans)


Measured memory_bytes: 31436
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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

int H, W;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int mp[500][500];
bool used[500][500];
ll col[2];

int dfs(int y, int x, int c)
{
  col[c]++;
  REP(i, 4) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
    if (used[ny][nx]) continue;
    if (mp[ny][nx] ^ mp[y][x] == 0) continue;
    used[ny][nx] = true;
    dfs(ny, nx, 1 - c);
  }
}

int main()
{
  cin >> H >> W;
  vector<pair<int, int>> vb;
  REP(i, H) {
    REP(j, W) {
      char c; cin >> c;
      if (c == '#') {
        vb.PB(MP(i, j));
        mp[i][j] = 1;
      } else mp[i][j] = 0;
    }
  }

  ll ans = 0;
  for (auto pos : vb) {
    if (used[pos.FI][pos.SE]) continue;
    col[0] = col[1] = 0;
    used[pos.FI][pos.SE] = true;
    dfs(pos.FI, pos.SE, 1);
    ans += col[0] * col[1];
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b < c+d){
    cout << "Right" << endl;
  }
  else if (a+b == c+d){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Left" << endl;
  }
}
    

Measured memory_bytes: 256
A, B, C = map(int, input().split())
ans = 0
while True:
    # print(A, B, C)
    if A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        if A == B == C:
            print(-1)
            exit()
        ans += 1
        tA = A
        tB = B
        tC = C
        A = tB//2 + tC//2
        B = tA//2 + tC//2
        C = tB//2 + tA//2
    else:
        print(ans)
        exit()
    


Measured memory_bytes: 38512
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
        Scanner scan = new Scanner(System.in);
        String[] dic = new String[10];
        dic[0] = " ";
        dic[1] = "',.!?";
        dic[2] = "abcABC";
        dic[3] = "defDEF";
        dic[4] = "ghiGHI";
        dic[5] = "jklJKL";
        dic[6] = "mnoMNO";
        dic[7] = "pqrsPQRS";
        dic[8] = "tuvTUV";
        dic[9] = "wxyzWXYZ";
        while(scan.hasNext()){
            String op = scan.nextLine();
            String ans = "";
            int t = 0;
            int prev = -1;
            int count = -1;
            for(int i = 0;i < op.length();i++){
            	t = op.charAt(i) - '0';
            	if(t == prev){
            		count++;
            	}else{
            		if(count >= 0 && prev == 0){
            			for(int j = 0;j < count;j++){
            				ans += " ";
            			}
            		}else if(count >= 0){
            			ans += dic[prev].charAt(count%dic[prev].length());
            		}
            		count = 0;
            		prev = t;
            	}
            }
            if(t != 0){
            	ans += dic[prev].charAt(count%dic[prev].length());
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 17596
#include <stdio.h>
int shop(int);
int main(void)
{
    int N,hold;
    scanf("%d",&N);
    hold = shop(N);
    switch(hold){
        case 0:
        printf("%d",0);
        break;
        case 1:
        printf("%d",(N/1000+1)*1000-N);
        break;
    }
    return 0;
}

int shop(int N)
{
        if(N%1000 == 0){
        return 0;
    }else{
        return 1;
    }
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int n,x;
    cin>>n>>x;
    vi v(n);
    rep(i,n)cin>>v[i];
    ll ans=0;
    if(v[0]>x){
        ans+=v[0]-x;
        v[0]=x;
    }
    for(int i=1;i<n;i++){
        int sum=v[i]+v[i-1];
        if(sum<=x)continue;
        int reduce=sum-x;
        ans+=reduce;
        v[i]-=reduce;
    }
    fin(ans);
    // rep(i,n)cout<<v[i]<<" ";
    // cout<<endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 768
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();
    let mut v: Vec<f64> = (0..n).map(|_| read()).collect();

    while v.len() >= 2 {
        v.sort_by(|a, b| a.partial_cmp(b).unwrap());
        v.reverse();
        let a = v.pop().unwrap();
        let b = v.pop().unwrap();
        v.push((a + b) / 2.0);
    }
    println!("{}", v[0]);
}


Measured memory_bytes: 4352
N, *A = map(int, open(0).read().split())
mod = 10**9 + 7

batch = 8
rg = tuple(range((63//batch)+1))
mask = (1<<batch) - 1
B = [[0]*(1<<batch) for _ in rg]
for a in A:
    for i in rg:
        B[i][a & mask] += 1
        a >>= batch

xr = [[] for _ in [0]*(1<<batch)]
for i in range(1<<batch):
    for j in range(i+1, 1<<batch):
        xr[i].append(i^j)

ans = 0
shift = 1
for b in B:
    x = sum(xr[i][j]*bi*bj for i, bi in enumerate(b) for j, bj in enumerate(b[i+1:]))
    x %= mod
    x *= shift
    x %= mod
    shift <<= batch
    shift %= mod
    ans += x
    ans %= mod
print(ans)

Measured memory_bytes: 49296
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
string S, ans;
string pat[4] ={ "SS", "SW", "WS", "WW" };

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

    rep(i, 4){
        ans = pat[i];
        for(int j=2; j<N; j++){
            if(ans[j-1] == 'S'){
                if(S[j-1] == 'o') ans += ans[j-2];
                else ans += (ans[j-2] == 'S' ? 'W' : 'S');
            }
            else{
                if(S[j-1] == 'x') ans += ans[j-2];
                else ans += (ans[j-2] == 'S' ? 'W' : 'S');
            }
        }
        bool flg = true;
        rep(j, N){
            if(ans[j] == 'S'){
                if(S[j] == 'o') flg &= (ans[(j-1+N)%N] == ans[(j+1)%N]);
                else flg &= (ans[(j-1+N)%N] != ans[(j+1)%N]);
            }
            else{
                if(S[j] == 'x') flg &= (ans[(j-1+N)%N] == ans[(j+1)%N]);
                else flg &= (ans[(j-1+N)%N] != ans[(j+1)%N]);
            }
        }
        if(flg){
            cout << ans << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 3760
#include <stdio.h>

int main()
{
	int n;
	char str[256];
	int red = 0;
	int blue = 0;

	scanf("%d", &n);
	scanf("%s", str);

	while(n--) {
		if (str[n] == 'R') {
			red++;
		} else {
			blue++;
		}
	}

	if (red > blue) {
		puts("Yes");
	} else {
		puts("No");
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    sort(a.begin(), a.end());

    if(n == 2) {
        cout << a[1] - a[0] << endl;
        return 0;
    }

    ll ans  = 0LL;
    if(n % 2) {
        for(int i=0;i<(n+1)/2-2;++i) {
            ans -= a[i]*2;
        }
        ans -= a[(n+1)/2-2] + a[(n+1)/2-1];
        for(int i=(n+1)/2;i<n;++i) {
            ans += a[i]*2;
        }

        ll tmp = 0LL;
        for(int i=0;i<n/2;++i) {
            tmp -= a[i]*2;
        }
        tmp += a[n/2] + a[n/2+1];
        for(int i=n/2+2;i<n;++i) {
            tmp += a[i]*2;
        }
        ans = max(ans, tmp);

    } else {
        for(int i=0;i<n/2-1;++i) {
            ans += 2 * (a[n-1-i] - a[i]);
        }
        ans += a[n/2] - a[n/2-1];

    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
count = 0
na, nb, nab = 0, 0, 0
for _ in range(n):
    s = input().strip()
    if s[0] == 'B' and s[-1] == 'A':
        nab += 1
    elif s[0] == 'B':
        nb += 1
    elif s[-1] == 'A':
        na += 1

    for i in range(len(s) - 1):
        if s[i:i+2] == 'AB':
            count += 1

if nab > 0:
    count += (nab - 1)
    if na > 0:
        na -= 1
        count += 1
    if nb > 0:
        nb -= 1
        count += 1

    count += min(na, nb)
else:
    count += min(na, nb)

print(count)

Measured memory_bytes: 46808
from collections import deque

while True:
  W, H = map(int, input().split())
  if W == 0 and H == 0:
    break
  
  wall_v = []
  wall_h = []

  wall_h.append([1] * W)
  for _ in range(H-1):
    vertical = list(map(int, input().split()))
    vertical.insert(0, 1)
    vertical.append(1)
    wall_v.append(vertical)
    wall_h.append(list(map(int, input().split())))
  vertical = list(map(int, input().split()))
  vertical.insert(0, 1)
  vertical.append(1)
  wall_v.append(vertical)
  wall_h.append([1] * W)

  q = deque()
  dist = [[0] * W for _ in range(H)]

  dist[0][0] = 1
  q.append([0, 0])

  while len(q) != 0:
    v = q.popleft()
    udlr = ([-1, 0], [1, 0], [0, -1], [0, 1])

    for move in udlr:
      if move == [-1, 0]:
        if wall_h[v[0]][v[1]] == 1:
          continue
      if move == [1, 0]:
        if wall_h[v[0]+1][v[1]] == 1:
          continue
      if move == [0, -1]:
        if wall_v[v[0]][v[1]] == 1:
          continue
      if move == [0, 1]:
        if wall_v[v[0]][v[1]+1] == 1:
          continue
      nv = [0, 0]
      nv[0], nv[1] = v[0] + move[0], v[1] + move[1]
      if dist[nv[0]][nv[1]] != 0:
        continue
      dist[nv[0]][nv[1]] = dist[v[0]][v[1]] + 1
      q.append(nv)

  print(dist[H-1][W-1])


Measured memory_bytes: 6024
#include <stdio.h>
#define N 44

int main(void){

  int n, i;
  int F[N+1];
  
  scanf("%d",&n); 
  F[0] = 1;
  F[1] = 1;
  for(i = 2;i <= n;i++)
    F[i] = F[i-1] + F[i-2];

  printf("%d\n", F[i-1]);
  
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }


ll fact(ll n){
if(n==0)return 1;
else return n*fact(n-1);
}
int main() {
    cout<<setprecision(16);
    int n;
    cin>>n;
    double x[n];
    double y[n];

    rep(i,n){
        cin>>x[i]>>y[i];
    }
    double ans = 0;
    double c = fact(n-1);
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            double a = (x[i]-x[j])*(x[i]-x[j]);
            double b = (y[i]-y[j])*(y[i]-y[j]);
            double k = sqrt(a+b);
            ans+=k*2*c;
        }
    }
    cout<<ans/fact(n)<<endl;



    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.regex.*;

// (5-(6/2/2+50*3/2/3*6/4)/9*2-(6/2/2+50*3/2/3*6)-36)*2-1=

class Main{
	static Pattern addsub = Pattern.compile("^(.*?)(-?\\d+)([+Z])(-?\\d+)(.*)$");
	static Pattern muldiv = Pattern.compile("^(.*?)(-?\\d+)([*/])(-?\\d+)(.*)$");

	static String process(String s){
		//analyze parens
		int bidx=s.indexOf("(");
		while(bidx!=-1){
			int count=1,eidx=bidx+1;
			for(;count!=0;eidx++){
				if(s.charAt(eidx)=='(')count++;
				if(s.charAt(eidx)==')')count--;
			}
			s=s.substring(0,bidx)+process(s.substring(bidx+1,eidx-1))+s.substring(eidx);
			bidx=s.indexOf("(");
		}

		//calc without parens
		Matcher m=muldiv.matcher(s);
		while(m.find()){
			if(m.group(3).equals("*"))
				s=m.group(1)+(Integer.parseInt(m.group(2))*Integer.parseInt(m.group(4)))+m.group(5);
			else
				s=m.group(1)+(Integer.parseInt(m.group(2))/Integer.parseInt(m.group(4)))+m.group(5);
			m=muldiv.matcher(s);
		}

		m=addsub.matcher(s);
		while(m.find()){
			if(m.group(3).equals("+"))
				s=m.group(1)+(Integer.parseInt(m.group(2))+Integer.parseInt(m.group(4)))+m.group(5);
			else
				s=m.group(1)+(Integer.parseInt(m.group(2))-Integer.parseInt(m.group(4)))+m.group(5);
			m=addsub.matcher(s);
		}
		return s;
	}

	public static void main(String[]z){
		Scanner x=new Scanner(System.in);
		int n=x.nextInt();for(;n>0;n--){
			String s=x.next().replaceAll("-","Z");
			System.out.println(process(s.substring(0,s.length()-1)));
		}
	}
}

Measured memory_bytes: 19132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    string ans = S;
    int size = (int)S.size();
    if (size > K)
    {
        string temp;
        temp = ans.substr(0, K);
        ans = temp + "...";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3128
import bisect
from math import ceil
n,d,a=map(int,input().split())
XH=[list(map(int,input().split())) for i in range(n)]
X=[XH[i][0] for i in range(n)]
XH.sort(key=lambda y:y[0])
X.sort()
damage=[0]*(n+1)
ans=0
for i,(x,h) in enumerate(XH):
  damage[i]+=damage[i-1]
  h-=damage[i]
  if h<=0:
    continue
  cnt=ceil(h/a)
  ans+=cnt
  damage[i]+=a*cnt
  br=bisect.bisect_right(X,x+d*2)
  damage[br]-=a*cnt
print(ans)

Measured memory_bytes: 61380
K = int(input())
now = 1
ans = 7
mod = 10 ** 9 + 7
for i in range(K + 1):
    if ans % K == 0:
        print(now)
        exit()
    now += 1
    # ans += 7 * 10 ** (i + 1)
    # ans %= 10 ** 9 + 7
    # ans += 7 * 10 ** (i + 1) % mod
    ans += 7 * pow(10, i + 1, K) % K


print('-1')

Measured memory_bytes: 9168
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(K):
        start = [0] * N
        end = [0] * N
        for j in range(N):
            if j - A[j] < 0:
                start[0] += 1
            else:
                start[j-A[j]] += 1
            if j + A[j] >= N:
                pass
            else:
                end[j+A[j]] += 1
        tmp = start[0]
        A[0] = tmp
        tmp_min = tmp
        for j in range(1, N):
            tmp += start[j]
            tmp -= end[j-1]
            A[j] = tmp
            tmp_min = min(tmp_min, tmp)
        if tmp_min >= N:
            break
    print(" ".join(map(str, A)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 173184
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, K, a[100], ans = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> a[i];
  sort(a, a + N, greater<int>());

  for (int i = 0; i < K; i++) {
    ans += a[i];
  }

  printf("%d\n", ans);
}


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

int main(){
    using namespace std;
    unsigned long N, A, B;
    cin >> N >> A >> B;
    if((A ^ B) & 1)cout << min(N - B + 1, A) + (B - A) / 2 << endl;
    else cout << (B - A) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
#define mod 100000
typedef long long int lli;
typedef pair<int,int> P;

int s[100000];
int a[100000];
int cnt[100000];

int main(){
	int n,m;
	cin >> n >> m;
	for(int i=1; i<n; ++i){
		cin >> s[i];
	}
	for(int i=1; i<=m; ++i){
		cin >> a[i];
	}
	long long int ans=0;
	int town=1;
	for(int i=1; i<n; ++i){
		cnt[i]=0;
	}
	for(int i=1; i<=m; ++i){
		if(a[i]<0){
			for(int j=town-1; j>=town+a[i]; --j){
				//ans+=s[j]%mod;
				++cnt[j];
			}
		} else {
			for(int j=town; j<town+a[i]; ++j){
				//ans+=s[j]%mod;
				++cnt[j];
			}
		}
		town+=a[i];
	}
	for(int i=1; i<n; ++i){
		ans+=s[i]*cnt[i]%mod;
	}
	cout << ans%mod << "\n";
}

Measured memory_bytes: 2332
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main()
{
	auto tokens = split(chomp(readln()));
	auto n = to!int(tokens[0]);
	auto m = to!int(tokens[1]);
	auto x = to!int(tokens[2]);
	auto y = to!int(tokens[3]);

	int[] a, b;
	foreach (token; split(chomp(readln())))
	{
		a ~= to!int(token);
	}
	a.sort();
	foreach (token; split(chomp(readln())))
	{
		b ~= to!int(token);
	}
	b.sort();

	bool isWar = !(a[$-1] < y && b[0] > x && a[$-1] < b[0]);
	
	writeln(isWar ? "War" : "No War");
	stdout.flush();
}

Measured memory_bytes: 256
def check(s):
    # print(s)
    for i in range(len(s)):
        if s[i] != s[len(s) - i - 1]:
            return False
    return True

def solve():
    s = input()
    if not check(s):
        return "No"
    # print(s[:(len(s) - 1) // 2 + 1], 111, (len(s) - 1) // 2 + 1, (len(s) + 3)// 2)
    if not (check(s[:(len(s) - 1) // 2])):
        return "No"
    if not check(s[(len(s) + 3)// 2 - 1:]):
        return "No"
    return "Yes"

print(solve())

Measured memory_bytes: 38256
//Heaplax
#include<bits/stdc++.h>
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
char s[30];
int n,ans;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	ans=15-n;
	for(int i=1;i<=n;++i)
		ans+=s[i]=='o';
	puts(ans>=8?"YES":"NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=1e6+6,INF=1e8;
int main(){
    string s; cin>>s;
    rep0(i,s.length()) if (s[i]=='?') cout<<'D'; else cout<<s[i];
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
  char s;
  cin >> s;
  if(isupper(s)){
    cout << "A" << endl;
  }
  else{
    cout << "a" << endl;
  }
  
}


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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;

int dp[N + 1];

int main() {
    int n;
    cin >> n;
    int h[n];
    for (int& x : h)
        cin >> x;
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    cout << dp[n - 1];
}



Measured memory_bytes: 1024
#d=日数, c=満足低下度, s=満足上昇度, t=コンテストの日程 
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]


res = 0
last = [0 for i in range(26)]
#old = t[dq[j][0] - 1]
#t[dq[0] - 1] = dq[1]
for day in range(d):
  t = s[day].index(max(s[day])) + 1
  m = s[day].index(max(s[day]))
  res += max(s[day])
  last[m] = day + 1
  #for i in range(26):
    #res -= c[i] * (day + 1 - last[i])
  combined1 = [x * (day + 1 - y) for (x, y) in zip(c, last)]
  res -= sum(combined1)
  #t[dq[j][0] - 1] = old
  print(t)

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

int main(){
  int N;
  cin>>N;
  vector<double> A(N);
  for(int i=0;i<N;++i){
    cin>>A.at(i);
  }

  double sum;
  for(int i=0;i<N;++i){
    sum=sum+(1/A.at(i));
  }

  printf("%lf\n",1/sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

struct edge
{
  int to, cost;
};
typedef std::vector<std::vector<edge>> graph;
const ll MOD = 1000000007;
using namespace std;

int main()
{
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  int a = 0, b = 0, c = 0;
  char turn = 'a';
  while (a <= sa.length() && b <= sb.length() && c <= sc.length())
  {
    switch (turn)
    {
    case 'a':
      turn = sa[a];
      a++;
      break;
    case 'b':
      turn = sb[b];
      b++;
      break;
    case 'c':
      turn = sc[c];
      c++;
      break;
    default:
      cout << a << " " << b << " " << c << endl;
      break;
    }
  }
  if (a > sa.length())
  {
    cout << "A" << endl;
  }
  else if (b > sb.length())
  {
    cout << "B" << endl;
  }
  else if (c > sc.length())
  {
    cout << "C" << endl;
  }
}


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

ll dp[107][MAXN];

int main()
{
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#endif
    int n, m;
    fill(*dp, *dp + 107 * MAXN, -1);
    scanf("%d%d", &n, &m);
    for (int i = 0; i != n; ++i) {
        ll w, v;
        scanf("%lld%lld", &w, &v);
        dp[i][0] = m;
        if (i) {
            for (int j = 0; j != MAXN; ++j) {
                if (j < v) {
                    dp[i][j] = dp[i - 1][j];
                    continue;
                }
                if (dp[i - 1][j - v]) {
                    dp[i][j] = max(dp[i - 1][j - v] - w, dp[i - 1][j]);
                }
            }
        } else {
            dp[0][v] = m - w;
        }
    }
    for (int i = MAXN - 1; i != -1; --i)
        if (dp[n - 1][i] != -1)
            printf("%d\n", i), exit(0);
}

Measured memory_bytes: 92160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX / 5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl


signed main() {
	int n, m;
	cin >> n >> m;
	vector<int>x(n);
	vector<int>y(m);
	rep(i, n) {
		cin >> x[i];
		//x[i] += INF;
	}
	rep(i, m) {
		cin >> y[i];
		//y[i] += INF;
	}
	sort(x);
	sort(y);
	reverse(x);
	reverse(y);
	int X = 0, Y = 0;
	rep(i, n) {
		X += x[i] * (n - 2 * i - 1);
		X %= MOD;
		X += MOD;
	}
	rep(i, m) {
		Y += y[i] * (m - 2 * i - 1);
		Y %= MOD;
		Y += MOD;
	}
	cout << (X * Y)%MOD << endl;
}

Measured memory_bytes: 4796