akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll h, w;
    cin >> h >> w;
    string s[h];
    for(ll i = 0; i < h; i++)
        cin >> s[i];
    ll count = 0;
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++){
            if(s[i][j]=='#') count++;
        }
    }
    ll ans = 0;
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++){
            vector<vector<ll>> dist(h, vector<ll>(w,1e+9));
            vector<vector<ll>> use(h, vector<ll>(w,-1));
            queue<p> que;
            if(s[i][j]=='#') continue;
            que.push(p(i,j));
            use[i][j] = 1;
            dist[i][j] = 0;
            while(!que.empty()){
                p check = que.front();
                ll x = check.first, y = check.second;
                que.pop();
                //cout << x << " " << y << endl;
                for(ll k = 0; k < 4; k++){
                    //cout << i << endl;
                    ll a = x+dx[k]; ll b = y+dy[k];
                    if(a<0 || b<0 || a>=h || b>=w) continue;
                    if(use[a][b]!=-1) continue;
                    if(s[a][b]=='#') continue;
                    que.push(p(a,b));
                    dist[a][b] = min(dist[a][b], dist[x][y]+1);
                    use[a][b] = 1;
                }
                //use[x][y] = 1;
            }
            for(ll k = 0; k < h; k++){
                for(ll l = 0; l < w; l++){
                    if(s[k][l]== '.')
                        ans = max(ans, dist[k][l]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    j = 0
    if i < k:
        while i*(2**j) < k:
            j += 1
        ans += (1/n)*1/(2**j)
    else:
        ans += (1/n)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;cin>>n;
    if(n>888)cout<<999<<endl;
    else if(n>777)cout<<888<<endl;
    else if(n>666)cout<<777<<endl;
    else if(n>555)cout<<666<<endl;
    else if(n>444)cout<<555<<endl;
    else if(n>333)cout<<444<<endl;
    else if(n>222)cout<<333<<endl;
    else if(n>111)cout<<222<<endl;
    else cout<<111<<endl;
    return 0;
}



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

const int MAXV = 100 + 10;
const int INF = 1e9;

struct edge
{
    int to, cap, rev;
};

vector<edge> G[MAXV];
bool used[MAXV];
int n, m;
//??????????¢?????????????S??°T?????????CAP??????
void add_edge(int from, int to, int cap)
{
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size()-1});
}
//??????DFS???????¢???????
int dfs(int v, int t, int f)
{
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++)
    {
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0)
        {
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0)
            {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
//?±??§£S??°T????????§???
int max_flow(int s, int t)
{
    int flow = 0;
    while(1)
    {
        memset(used, 0, sizeof used);
        int f = dfs(s, t, INF);
        if(!f) return flow;
        flow += f;
    }
}

int main()
{
    while(~scanf("%d%d", &n, &m))
    {
        for(int i = 0; i < m; i++)
        {
            int tx, ty, cap;
            scanf("%d%d%d", &tx, &ty, &cap);
            add_edge(tx, ty, cap);
        }
        cout << max_flow(0, n-1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1276
#include<cstdio>
#include<iostream>
     
using namespace std;
    
int GCD(int a, int b){
  int ans;
  int big, small;
     
  big = a;
  small = b;
     
  while (big) {
    if (small > big) swap(big, small);
    big = big % small;
  }
  ans = small;

  return ans;
}
     
int LCM(int a, int b, int gcd) {
  int ans;
  
  ans = a / gcd * b;

  return ans;
}
     
     
     
     
int main(){
  int a, b;
  int gcd, lcm;

  while (cin >> a >> b) { 

    gcd = GCD(a, b);
    lcm = LCM(a, b, gcd);

    cout << gcd << " " << lcm << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> P(N);
    rep(i, N) cin >> P[i];
    
    vec<int> Q(N);
    rep(i, N) cin >> Q[i];

    vec<int> c(N);
    iota(all(c),1);

    int cnt = 0;
    int p;
    int q;
    do {
        ++cnt;
        if(equal(all(P),all(c))) p=cnt;
        if(equal(all(Q),all(c))) q=cnt;

    }while(next_permutation(all(c)));
    cout << abs(p-q) << endl;
}


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

#define endl '\n'
#define pi 3.1415926

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int A[N], count[N+10];
    A[0] = 0;
    for(int i = 0; i < N+10; ++i)
        count[i] = 0;
    for(int i = 1; i < N; i++) {
        cin >> A[i];
        count[A[i]]++;
    }
    for(int i = 0; i < N; i++) {
        cout << count[i+1] << endl;
    }
    return 0;
}

Measured memory_bytes: 5208
n = input()

def dfs(i, f, s):
    if i == 3:
        if s == 7:
            print(f+"=7")
            exit()
    else:
        dfs(i+1, f+"+"+n[i+1], s+int(n[i+1]))
        dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

dfs(0, n[0], int(n[0]))

Measured memory_bytes: 3064
s = input()

ACGT = ['A', 'C', 'G', 'T']

ans = 0
ans_max = 0
flg = False
for c in s:
    if c in ACGT:
        ans += 1
        flg = True
    elif flg:
        ans_max = max(ans_max, ans)
        ans = 0
        flg = False

ans_max = max(ans_max, ans)

print(ans_max)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//string binary = bitset<32>(n).to_string();  
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
   	lli n;
   	cin>>n;
   	lli a[n];
   	for(lli i=0;i<n;i++)cin>>a[i];
   	sort(a,a+n);
   //for(lli i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
    cout<<a[n/2]-a[n/2-1];



    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int a,b;
    	a = sc.nextInt();
    	b = sc.nextInt();
    	
    	if(a<b){
    		System.out.println("a < b");
    	}else if(a>b){
    		System.out.println("a > b");
    	}else{
    		System.out.println("a == b");
    	}
    	
    }
}

Measured memory_bytes: 26112
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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


signed main(void) {
    int i,j;
    int n,m;
    while(cin >> n >> m, n){
        vi l(n);
        vector<pii> h(n);
        rep(i,n)h[i].second = i;
        rep(i,m){
            int s,k;
            cin >> s >> k;
            rep(j,k){
                int t;
                cin >> t;
                t--;
                if(k == 1)l[t] += s;
                h[t].first += s;
            }
        }
        //rep(i,n)cout << l[i] << " " << h[i].first << " " << h[i].second << endl;
        sort(all(h));
        int ans = 0;
        rep(i,n){
            //cout << " " << i << " " << l[i] << " " << h[n-1].second << endl;
            if(h[n-1].second == i){
                ans = max(ans, h[n-2].first - l[i]);
            }else{
                ans = max(ans, h[n-1].first - l[i]);
            }
            //cout << ans << endl;
        }
        cout << ans+1 << endl;

    }
}



Measured memory_bytes: 3328
f=lambda:[*map(int,input().split())]
d=int(input())
c=f()
S=[]
for i in range(d): S+=[f()]
D=[0]*26
for i in range(d):
  t=-1
  for j in range(26):
    if t<S[i][j]+c[j]*(i+1-D[j]):
      t=S[i][j]+c[j]*(i+1-D[j])
      s=j
  D[s]=i+1
  print(s+1)

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<char> odd{'R','U','D'};
    vector<char> even{'L','U','D'};

    string s; cin >> s;

    bool flag = true;
    rep(i,s.size()) {
        bool flag2 = false;
        if(i%2==0) {
            for(auto val : odd) {
                if(val==s[i]) flag2 = true;
            }
        }else {
            for(auto val : even) {
                if(val==s[i]) flag2 = true;
            }
        }
        if(!flag2) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>



int main()
{
    int N, K;
    std::cin >> N >> K;
    std::string s;
    std::cin >> s;

    std::vector<int> chokuritsu;
    std::vector<int> sakadachi;
    int idx = 0;
    while(idx != s.length()){
        int count = 1;
        while(s[idx] == s[idx+1]){
            count++;
            idx++;
        }
        if(s[idx] == '1'){
            sakadachi.push_back(count);
        }else{
            chokuritsu.push_back(count);
        }
        idx++;
    }
    if(K >= chokuritsu.size()){
        std::cout << N << std::endl;
        return 0;
    }

    if(s[0] == '0'){
        int max = 0;
        for(int i = 0; i < chokuritsu.size()-K+1; ++i){
            int tmp = (i == 0) ? 0 : sakadachi[i-1];
            for(int j = 0; j < K; ++j){
                if(i+j < chokuritsu.size()) tmp += chokuritsu[i+j];
                if(i+j < sakadachi.size()) tmp += sakadachi[i+j];

            }
            if(max < tmp){
                max = tmp;
            }
        }
        std::cout << max << std::endl;
    return 0;
    }

        int max = 0;
        for(int i = 0; i < chokuritsu.size()-K+1; ++i){
            int tmp = 0;
            for(int j = 0; j < K; ++j){
                if(i+j < chokuritsu.size()) tmp += chokuritsu[i+j];
                if(i+j < sakadachi.size())tmp += sakadachi[i+j];

            }
            if(i+K < sakadachi.size()) tmp += sakadachi[i+K];
            if(max < tmp){
                max = tmp;
            }
        }
        std::cout << max << std::endl;
  

    return 0;
}


Measured memory_bytes: 1020
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let s: String = read();
    println!("{}", s.split("S").map(|x| x.len()).max().unwrap());
}

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

int f(int i){
	int ans = 0;
	while(0 < i){
		ans += i%10;
		i /= 10;
	}
	return ans;
}


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

	int ans = 0;
	rep(i, n+1){
		int tent = f(i);
		if(a <= tent && tent <= b)
			ans += i;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let n: usize = sc.read();
    let m: usize = sc.read();
    let q: usize = sc.read();
    let trains: Vec<(usize, usize)> = (0..m).map(|_| (sc.read(), sc.read())).collect();
    let qs: Vec<(usize, usize)> = (0..q).map(|_| (sc.read(), sc.read())).collect();
    let mut table = vec![vec![0; n + 1]; n + 1];
    for train in trains {
        table[train.0][train.1] += 1;
    }
    for i in (2..n+1).rev() {
        for j in 1..n + 1 {
            table[i-1][j] += table[i][j];
        }
    }
    for i in 1..n+1 {
        for j in 1..n  {
            table[i][j+1] += table[i][j];
        }
    }
    for q in qs {
        println!("{}", table[q.0][q.1]);
    }
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


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

int main() {
  
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  string x;

  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    cin >> t.at(i);
  }

  cin >> x;
  int lol = 0;

  for (int i = 0; i < n; i++) {
      if(x == s.at(i)) {
      lol = (i+1);
      break;
  } }

  int ans = 0;
  
  for (int i = lol; i < n; i++) {
    ans = ans + t.at(i);
      }

        cout << ans << endl;
}
    

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        String N = scan.next();
        int K = scan.nextInt();
        HashSet<Integer> dis = new HashSet<>();
        for (int i=0;i<K;i++) dis.add(scan.nextInt());
        int low = 0;
        while (dis.contains(low)) low++;

        int[] num = new int[N.length()];
        for (int i=0;i<num.length;i++) num[i] = N.charAt(i) - '0';
        String res = dfs(dis, 0, num, low);
        if (res != null) {
            System.out.println(res);
            return;
        }
        int first = low;
        if (first == 0) {
            first++;
            while (dis.contains(first)) first++;
        }
        System.out.print(first);
        for (int i=0;i<num.length;i++) System.out.print(low);
        System.out.println();
    }

    private static String dfs(HashSet<Integer> dis, int idx, int[] num, int low) {
        if (idx == num.length) return "";
        int i = num[idx];
        while (dis.contains(i)) i++;
        if (i > 9) return null;
        if (i == num[idx]) {
            String next = dfs(dis, idx + 1, num, low);
            if (next != null) return "" + i + next;
            i++;
            while (dis.contains(i)) i++;
            if (i > 9) return null;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(i);
        for (int j=0;j<num.length-idx-1;j++) sb.append(low);
        return sb.toString();
    }
}


Measured memory_bytes: 21844
#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>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    ll a;
    double b;
    cin >> a >> b;
    b *= 100;
    ll ib = b + 0.5;
    ll ans = a*ib;
    ans /= 100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<int> diff(n);
    for (int i=0;i<n;i++){
        if (i == n-1){
            diff[i] = k - a[n-1] + a[0];
        } else{
            diff[i] = a[i+1] - a[i];
        }
    }
    int maxIndex = max_element(diff.begin(),diff.end()) - diff.begin();
    // for (int i=0;i<n;i++){
    //     cout << diff[i] << "\n";
    // }
    // cout << "--------------";
    diff.erase(diff.begin()+maxIndex);
    int sum = 0;
    for (int i=0;i<n-1;i++){
        sum+=diff[i];
    }
    // for (int i=0;i<n-1;i++){
    //     cout << diff[i] << "\n";
    // }
    cout << sum;
    return 0;
}

Measured memory_bytes: 2424
#include <stdio.h>
#include <string.h>
#define max(a,b) (a>b?a:b)

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

void quick_sort(int a[],int l,int r)
{
    if(l>=r)return;
    int temp=a[l],i=l,j=r;
    //printf("%d  ",temp);
    while(i!=j){
        while(a[j]>=temp &&i<j)j--;
        while(a[i]<=temp &&i<j)i++;
        if(i<j)swap(&a[i],&a[j]);
    }
    swap(&a[l],&a[i]);
    quick_sort(a,l,i-1);
    quick_sort(a,i+1,r);
}

void merge(int arr[], int low, int mid, int high){
    int i, k;
    int *tmp = (int *)malloc((high-low+1)*sizeof(int));
    //申请空间，使其大小为两个
    int left_low = low;
    int left_high = mid;
    int right_low = mid + 1;
    int right_high = high;

    for(k=0; left_low<=left_high && right_low<=right_high; k++){  // 比较两个指针所指向的元素
        if(arr[left_low]<=arr[right_low]){
            tmp[k] = arr[left_low++];
        }else{
            tmp[k] = arr[right_low++];
        }
    }

    if(left_low <= left_high){  //若第一个序列有剩余，直接复制出来粘到合并序列尾
    //memcpy(tmp+k, arr+left_low, (left_high-left_low+l)*sizeof(int));
    for(i=left_low;i<=left_high;i++)
        tmp[k++] = arr[i];
    }

    if(right_low <= right_high){
    //若第二个序列有剩余，直接复制出来粘到合并序列尾
    //memcpy(tmp+k, arr+right_low, (right_high-right_low+1)*sizeof(int));
        for(i=right_low; i<=right_high; i++)
            tmp[k++] = arr[i];
    }

    for(i=0; i<high-low+1; i++)
        arr[low+i] = tmp[i];
    free(tmp);
    return;
}

void merge_sort(int arr[], unsigned int first, unsigned int last){
    int mid = 0;
    if(first<last){
        mid = (first+last)/2; /* 注意防止溢出 */
        /*mid = first/2 + last/2;*/
        //mid = (first & last) + ((first ^ last) >> 1);
        merge_sort(arr, first, mid);
        merge_sort(arr, mid+1,last);
        merge(arr,first,mid,last);
    }
    return;
}

int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    merge_sort(a,0,n-1);
//    for(int i=0;i<n;i++){
//        printf("%d ",a[i]);
//    }
    printf("%d",a[n/2]-a[n/2-1]);
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int a, b; cin >> a >> b;
  if (a <= 8 && b <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


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

int main(){
  int x, y;  cin >> x >> y;
  int d[] = {1, 0, 0, 1, 1}, ans = 1e9+1e5; // d[]は前で・後ろで反転をする・しないの2*2の組み合わせを作るための
  for(int i=0; i<4; i++){
    int xc = x;
    if(d[i])  xc = -xc;  // 前の反転

    if(xc > y && d[i+1] == 0)  continue; // 後ろで反転しないのにxcの方が大きい場合:xc=5 y=2
    xc += abs(abs(y) - abs(x));

    if(d[i+1])  xc = -xc; // 後ろの反転

    if(xc == y)  ans = min(ans, d[i]+d[i+1]+abs(abs(y) - abs(x)));
  }


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


Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>

using namespace std;

int main(void){
	int path[6][2] = {{3,4},{4,3},{1,4},{-1,5},{3,-1},{2,1}};
	int now;
	char ch;
	while(1){
		if((ch = getchar()) == '#'){
			break;
		}
		now = 0;
		while(ch != '\n'){
			if(path[now][ch - '0'] == -1){
				break;
			}
			now = path[now][ch - '0'];
			ch = getchar();
		}
		if(ch == '\n' && now == 1){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
			if(ch != '\n')
				while(getchar() != '\n');
		}
	}
	return 0;
}

Measured memory_bytes: 1112
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
//ios::sync_with_stdio(false);
//<< setprecision(5)
const int mod=1e9+7;
const llint big=1e12+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	//面倒なのでdpします
	int n,i,j;
	static double dp[40005][205];//dp
	int maxsp[40005];
	for(i=0;i<40005;i++){
		for(j=0;j<205;j++){dp[i][j]=-big;}
		maxsp[i]=200;
	}
	cin>>n;
	vector<int>t(n);
	vector<int>v(n);
	for(i=0;i<n;i++){cin>>t[i];}
	for(i=0;i<n;i++){cin>>v[i];}
	llint nowti=0;
	for(i=0;i<n;i++){
		for(j=nowti;j<=nowti+t[i]*2;j++){mineq(maxsp[j],v[i]*2);}
		nowti+=t[i]*2;
	}
	
	dp[0][0]=0;
	for(i=1;i<=nowti;i++){
		for(j=0;j<=maxsp[i];j++){
			if(j>0){maxeq(dp[i][j],dp[i-1][j-1]+j-0.5);}
			maxeq(dp[i][j],dp[i-1][j]+j);
			maxeq(dp[i][j],dp[i-1][j+1]+j+0.5);
		}
	}
	printf("%lf\n",dp[nowti][0]/4);
	return 0;
}

Measured memory_bytes: 64512
#include <bits/stdc++.h>
#define mem(a) memset(a,0,sizeof(a))
#define N 100010
#define ll long long int
using namespace std;
ll an[N];
struct Node{
  int to;
  ll cost;
};
vector<Node> v[N];
void dfs(int x,int fa){
  for(int i=0;i<v[x].size();i++){
    if(v[x][i].to==fa)
      continue;
    an[v[x][i].to]=an[x]+v[x][i].cost;
    dfs(v[x][i].to,x);
  }
}
int main(){
  int n;
  scanf("%d", &n);
  int x,y;
  ll z;
  for(int i=1;i<n;i++){
    scanf("%d%d%lld",&x,&y,&z);
    v[x].push_back({y,z});
    v[y].push_back({x,z});
  }
  int q,t;
  scanf("%d%d",&q,&t);
  dfs(t,-1);
  while(q--){
    scanf("%d%d",&x,&y);
    printf("%lld\n",an[x]+an[y]);
  }
  return 0;
}

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

int main() {
    long a,b,c,k;
    cin>>a>>b>>c>>k;
    long sum = 0;
    if(a>=k)
    {
        sum += k;
    }
    else if(a<k && a+b>=k)
    {
        sum += a;
    }
    else if(a+b<k && a+b+c>=k)
    {
        sum += (a-(k-b-a));
    }
    cout<<sum<<"\n";
	return 0;
}

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

using namespace std;

int N, M1, M2;
char cell[5][5][5];
char cccc[5][5][5];
int a[27], b[27];

int z;

int adj(int x, int y, int z)
{
  int ret = 0;
  for(int dz = -1; dz <= 1; dz++){
    for(int dy = -1; dy <= 1; dy++){
      for(int dx = -1; dx <= 1; dx++){
	if(dz != 0 || dy != 0 || dx != 0){
	  if(0 <= z+dz && z+dz < 5 &&
	     0 <= y+dy && y+dy < 5 &&
	     0 <= x+dx && x+dx < 5){
	    ret += (cccc[z+dz][y+dy][x+dx] == '1');
	  }
	}
      }
    }
  }
  return ret;
}

void dfs(int n)
{
  if(n == 0) return;
  
  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5; j++){
      for(int k = 0; k < 5; k++){
	cccc[i][j][k] = cell[i][j][k];
      }
    }
  }  
  
  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5; j++){
      for(int k = 0; k < 5; k++){
	int cre = adj(k, j, i);
	if(cccc[i][j][k] == '0'){
	  for(int l = 0; l < M1; l++){
	    if(cre == a[l]){
	      cell[i][j][k] = '1'; 
	      break;
	    }
	  }
	} else if(cccc[i][j][k] == '1'){
	  bool flag = false;
	  for(int l = 0; l < M2; l++){
	    if(cre == b[l]){
	      flag = true;
	      break;
	    }
	  }
	  if(!flag) cell[i][j][k] = '0';
	}
      }
    }
  }
  
  dfs(n-1);
}

int main()
{
  for(int s = 0; ; s++){
    cin >> N;
    if(N == 0) break;
    if(s > 0) cout << endl;
    for(int i = 0; i < 5; i++){
      for(int j = 0; j < 5; j++){
	for(int k = 0; k < 5; k++){
	  cin >> cell[i][j][k];
	}
      }
    }

    cin >> M1;
    for(int i = 0; i < M1; i++) cin >> a[i];

    cin >> M2;
    for(int i = 0; i < M2; i++) cin >> b[i];
    
    dfs(N);
    
    cout << "Case " << s+1 << ":" << endl;
    for(int i = 0; i < 5; i++){
      if(i > 0) cout << endl;
      for(int j = 0; j < 5; j++){
	for(int k = 0; k < 5; k++){
	  cout << cell[i][j][k];
	}
	cout << endl;
      }
    }
  } 
  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<algorithm>
#define max 100000

using namespace std;

int head, tail, a_size;

struct Ps {
	string name;
	int times;
};

Ps ps[max];

void enqueue(Ps p) {
	ps[tail] = p;
	++tail;
	tail %= max;
}

Ps dequenue() {
	Ps p = ps[head];
	++head;
	head %= max;
	return p;
}


int main() {
	int q_time,el_time=0,n_time;
	Ps ps_af;
	cin >> a_size >> q_time;
	for (int i = 1; i<=a_size; ++i) {
		cin >> ps[i].name >> ps[i].times;
	}
	head = 1;
	tail = a_size + 1;

	while (head != tail) {
		ps_af = dequenue();
		n_time = min(q_time, ps_af.times);
		ps_af.times -= n_time;
		el_time += n_time;
		if (ps_af.times > 0) enqueue(ps_af);
		else cout << ps_af.name << " " << el_time << endl;
	}
	return 0;
}

Measured memory_bytes: 5108
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int n;
    char s[100] = {};
    cin >> n >> s;

    int r = 0;
    for (int i = 0; i < n; i++) {
        if (memcmp(s + i, "ABC", 3) == 0) r++;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 1000

int lcs(char *,char *);
int maxi(int,int);

int main(){
  char c1[N],c2[N];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c1);
    scanf("%s",c2);
    printf("%d\n",lcs(c1,c2));
  }

  return 0;
}

int maxi(int a,int b){
  if(a > b)return a;

  else return b;
}

int lcs(char X[],char Y[]){
  int c[N+1][N+1];
  int m = strlen(X);
  int n = strlen(Y);
  int maxl = 0;
  int i,j;
  
  for(i=0;i<=m;i++) c[i][0] = 0;
  for(j=1;j<=n;j++) c[0][j] = 0;

  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(X[i] == Y[j]){
        c[i+1][j+1] = c[i][j] + 1;
      }
      else{
        c[i+1][j+1] = maxi(c[i][j+1],c[i+1][j]);
      }
      maxl = maxi(maxl,c[i+1][j+1]);
    }
  }

  return maxl;
}



Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N+1,MAX_I);
  rep(i,N-1)cin >> v[i+1];
  int sum = 0;
  rep(i,N) sum += min(v[i],v[i+1]);
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long

int main() {
    
    ll n;
    cin >> n;
    ll ans=1e12;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0) {
            ll ans1=i+n/i;
            ans=min(ans,ans1);
        }
    }
   
     cout << ans-2 << endl;
   
}

Measured memory_bytes: 256
# 75 = 5 * 5 * 3
# 3 * 5 * 5, 3 * 25, 5 * 15, 75


n = int(input())

div = [0] * (n + 1)
for i in range(2, n + 1):
    j = 2
    while j * j <= i:
        while i % j == 0:
            div[j] += 1
            i //= j
        j += 1
    if i != 1:
        div[i] += 1

i3 = i5 = i15 = i25 = i75 = 0
for _, v in enumerate(div):
    if v >= 74:
        i75 += 1
    if v >= 24:
        i25 += 1
    if v >= 14:
        i15 += 1
    if v >= 4:
        i5 += 1
    if v >= 2:
        i3 += 1
ans = i75
ans += i25 * (i3 - 1)
ans += i15 * (i5 - 1)
ans += (i5 - 1) * i5 // 2 * (i3 - 2)
print(ans)


Measured memory_bytes: 9116
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
A = Counter(A)
A2 = [i for i,j in A.items() if j >= 2]
A2.sort(reverse = True)
A4 = [i for i,j in A.items() if j >= 4]
A4.sort(reverse = True)

H,W = 0,0

for i in range(len(A2)):
  if H == 0:
    H = A2[i]
  else:
    W = A2[i]
    break

for j in range(len(A4)):
  if A4[j] >= H:
    H,W = A4[j],A4[j]
  elif A4[j] >= W:
    W = A4[j]
  break

print(H*W)

Measured memory_bytes: 18592
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

a.sort(reverse=True)

print(sum(a[::2]) - sum(a[1::2]))

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


int main(){

int k;
cin>>k;

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

}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
  vector<int>H;
  int n,k;
  cin >> n >> k;
  int h[n];
  int ans;
  for(int i=0;i<n;i++){
    cin >> h[i];
    H.push_back(h[i]);
  }
  sort(H.begin(), H.end());
  ans = pow(10,9);
  for(int i=0;i<n-k+1;i++){
    if(ans > H[i+k-1]-H[i]){
      ans = H[i+k-1]-H[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1148
package main

import (
	"container/heap"
	"fmt"
)

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	h := &IntHeap{}
	heap.Init(h)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		heap.Push(h, a)
	}
	for i := 0; i < m; i++ {
		v := heap.Pop(h)
		heap.Push(h, v.(int)/2)
	}
	var ret int64
	for h.Len() > 0 {
		ret += int64(heap.Pop(h).(int))
	}
	fmt.Println(ret)
}


Measured memory_bytes: 6528
/* ****revpro**** */
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  100005
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;  
//#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
signed main()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
   // freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output1.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		string s;
		cin>>s;
		ll cnt=0;
		rep(i,2,n){
			if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C'){
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = 0;
		String b = stdIn.next();
		char[] a = new char[4];
		for (int j = 0; j < 4; j++) {
			a[j] = b.charAt(j);
		}
		for (int i = 0; i < 4; i++) {
			if (a[i] == '+') 
				N = N + 1;
			else
				N = N - 1;
		}


		System.out.print(N);
	}
}

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

int main() {
	const ll MOD = 1e9 + 7;
	int n, m;
	cin >> n >> m;
	vector<ll> x(n + 1);
	vector<ll> y(m + 1);
	for (int i = 1; i <= n; i++) cin >> x[i];
	for (int i = 1; i <= m; i++) cin >> y[i];

	ll sum_x = 0, sum_y = 0;
	for (int i = 1; i <= n; i++) {
		ll tmp = (i - 1) * x[i] - (n - i) * x[i];
		sum_x = (sum_x + (tmp + MOD) % MOD) % MOD;
	}
	for (int i = 1; i <= m; i++) {
		ll tmp = (i - 1) * y[i] - (m - i) * y[i];
		sum_y = (sum_y + (tmp + MOD) % MOD) % MOD;
	}

	ll res = (sum_x * sum_y) % MOD;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

long long kai(int n) {
	long long ans = 1;
	for (int i = 1; i <= n; i++) {
		ans *= i;
		ans %= MOD;
	}
	return ans;
}




int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	char *t = new char[q];
	char *d = new char[q];
	for (int i = 0; i < q; i++) {
		cin >> t[i] >> d[i];
	}

	int min = -1;
	int max = n;
	for (int i = 0; i < n; i++) {
		int mid = (min + max) / 2;
		int temp = mid;
		int flag = 0;
		for (int j = 0; j < q; j++) {
			if (s[temp] == t[j]) {
				if (d[j] == 'R') {
					temp++;
				}
				else {
					temp--;
				}
			}
			if (temp < 0) {
				min = mid;
				flag = 1;
				break;
			}
			else if (temp == n) {
				break;
			}
		}
		if (flag == 0) {
			max = mid;
		}
		if (abs(max - min) == 1) {
			break;
		}
	}
	int total = min + 1;
	min = -1;
	max = n;
	for (int i = 0; i < n; i++) {
		int mid = (min + max) / 2;
		int temp = mid;
		int flag = 0;
		for (int j = 0; j < q; j++) {
			if (s[temp] == t[j]) {
				if (d[j] == 'R') {
					temp++;
				}
				else {
					temp--;
				}
			}
			if (temp >n-1) {
				max = mid;
				flag = 1;
				break;
			}
			else if (temp < 0) {
				break;
			}
		}
		if (flag == 0) {
			min = mid;
		}
		if (abs(max - min) == 1) {
			break;
		}
	}

	total += n - max;
	
	cout << n-total;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

const int MOD = 1e9+7;

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    vector<ll> sum(N+1,0);
    REPR(i,N-1){
        sum[i] = sum[i+1] + A[i];
        sum[i] %= MOD;
    }

    ll ans = 0;
    REP(i,N-1){
        ans += A[i] * sum[i+1];
        ans %= MOD;
    }

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

Measured memory_bytes: 6412
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 char S[300005];
 int N;
 int sum_ecount=0;
 int sum_wcount=0;
 int ecount=0;
 int wcount=0;
 int ans=30000000;
 cin>>N;
 cin>>S;
 for(int i=0; i<strlen(S); i++){
  if(S[i]=='W')++sum_wcount;
  else ++sum_ecount;
 }
 
 for(int i=0; i<strlen(S); i++){
  if(S[i]=='E'){
     ans=min(ans,(sum_ecount-1-ecount)+(wcount));
     ecount++;
  }
  else{
     ans=min(ans,(sum_ecount-ecount)+(wcount));
     wcount++;
  } 
 }
 std::cout<<ans<<std::endl;
}
     
     





Measured memory_bytes: 512
H, W = map(int, input().split())
def keisan1(H, W):
    kotae = 10**9
    for h in range(1, H):
        SA = h*W
            
        if W % 2 == 0:
            SB = (H-h) * (W//2)
            SC = (H-h) * (W//2)
        else:
            SB = (H-h) * (W//2)
            SC = (H-h) * ((W//2)+1)
        kotae = min(kotae, abs(max(SA, SB, SC)-min(SA, SB, SC)))
    
    return kotae
        
def keisan2(H, W):
    kotae=10**9
    if H >= 3:
        for h in range(1, H):
            SA = h*W
            
            if (H-h) % 2 == 0:
                SB = W*((H-h)//2)
                SC = W*((H-h)//2)
            else:
                SB = W*((H-h)//2)
                SC = W*(((H-h)//2)+1)
            kotae = min(kotae, abs(max(SA, SB, SC)-min(SA, SB, SC)))
    else:
        kotae = 10**9
    
    return kotae
        
print(min(keisan1(H, W), keisan1(W, H), keisan2(H, W), keisan2(W, H)))

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

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

    string s;
    cin >> s;

    int b=0, w=0, bb=0, ww=0, ans=1000000;

    for (int i=0; i<n; i++) {
        if (s.at(i) == '.') w++;
        else b++;
    }

    for (int i=0; i<n; i++) {
        if (s.at(i) == '.') {
            ww++;
        } else { 
            bb++;
        }
        if (ans > bb + w - ww) ans = bb + w - ww;
    }

    if (ans > w) ans = w;

    if (ans < 1000000){
        cout << ans << endl;
    } else cout << 0 << endl;
}

Measured memory_bytes: 640
use std::collections::BTreeSet;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: u64 = sc.read();
    let mut divisors = vec![];
    for d in 1.. {
        if d * d > n {
            break;
        }
        if n % d == 0 {
            divisors.push(d);
            divisors.push(n / d);
        }
    }

    let mut set = BTreeSet::new();
    for r in divisors.into_iter() {
        let m = (n / r) - 1;
        if m > 0 && n / m == n % m {
            set.insert(m);
        }
    }

    let sum = set.into_iter().sum::<u64>();
    println!("{}", sum);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int32_t main()
{

    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    sort(arr,arr+n);

    int sum=0;
    for(int i=0;i<k;i++){
        sum+=arr[i];
    }

    cout<<sum<<endl;

    return 0;
}

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

#define PI (3.14159265358979323846)

int main(void)
{
	double x = 0.0, y = 0.0;
	int now = 90;
	int spin;
	int add_m;
	
	while (1){
		scanf("%d%*c%d", &add_m, &spin);
		
		if (add_m == 0 && spin == 0) break;
		
		y += (double)add_m * sin((double)now / 180.0 * PI);
		x += (double)add_m * cos((double)now / 180.0 * PI);
		
		now -= spin;
		if (now < 0) now += 360;
		else if (now > 360) now -= 360;
	}
	
	printf("%d\n%d\n", (int)x, (int)y);
	
	return (0);
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(1000000000)
import math
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    A = lmis()
    l = 1
    for a in A:
        l = lcm(l, a)
    print(sum(l//a for a in A) % N1097)


main()


Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int a, b, x;
    cin >> a >> b >> x;

  	if(a <= x && a+b >= x)
    	cout << "YES" << endl;
	else
      	cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 20;

int ile[maxN];
char T[maxN];
int n;

int cfPar(int n, int k)
{
	return ile[n] == ile[k] + ile[n-k];
}

int check()
{
	int ret = 0;
	FOR(i, 0, n)
		if (T[i] == '1' and cfPar(n-1, i))
			ret ^= 1;
	return ret;
}

void ans(int n)
{
	printf("%d\n", n);
	exit(0);
}
 
int main()
{
	scanf ("%d", &n);
	scanf ("%s", T);
	
	FOR(i, 0, n)
	{
		T[i]--;
		for (int j=2; j<=i; j*=2)
			ile[i] += i/j;
	}
	
	if (check())
		ans(1);
		
	if (count(T, T+n, '1') != 0)
		ans(0);
	
	FOR(i, 0, n)
		if (T[i] == '2')
			T[i] = '1';
	
	ans(check() * 2);
	assert(false);
}


Measured memory_bytes: 5120
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  ll t1,t2;
  cin>>t1>>t2;
  ll a1,b1,a2,b2;
  cin>>a1>>b1>>a2>>b2;
  if(a1<a2){
      swap(a1,a2);swap(b1,b2);
  }
   if(a1==a2){
      cout<<"infinity"<<endl;
      return 0;
  }
  if(a1*t1+b1*t2<=a2*t1+b2*t2){
      if(a1*t1+b1*t2==a2*t1+b2*t2){
        cout<<"infinity"<<endl;
        return 0;
      }
      else{
          ll d=(a2*t1+b2*t2)-(a1*t1+b1*t2);
         // cout<<d<<endl;
          ll ans=(a1-a2)*t1/d*2+1-((a1-a2)*t1%d==0);
         cout<<ans<<endl;
      }
  }
  else{
      cout<<0<<endl;
  }
}



Measured memory_bytes: 256