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

vector<long long> divisor(long long n){//nの約数列挙
    vector<long long> res;
    for(long long i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

typedef pair<long long, long long> P;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    map<long long, long long> m;
    sort(A.begin(), A.end());
    vector<int> ju(N, 0);
    for(int i = 0; i < N; i++){
        if(m.count(A[i])){
            ju[i] = -1;
            if(A[i - 1] == A[i]) ju[i - 1] = -1;
        }
        else{
            vector<long long> res = divisor(A[i]);
            for(long long t: res){
                if(m.count(t)){
                    ju[i] = -1;
                    break;
                }
            }
            m[A[i]]++;
        }
    }
    long long ans =0;
    for(int i = 0; i < N; i++){
        if(ju[i] == 0) ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 17968
N, Y = map(int, input().split())
counter = True
for i in range(N+1):
    for j in range(N - i+1):
        if j >= 0 and (N-i-j) >= 0 and counter:
            if 10**4*i + 5*10**3*j + 10**3*(N-i-j) == Y:
                #print(str(i)+" "+str(j)+" "+str(N-i-j))
                print(i, j, N-i-j)
                counter = False
        else:
            break
if counter:
    print("-1 -1 -1")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
int main() {
	int h, w; cin >> h >> w;
	map<char, int>cnt;
	for (char i = 'a'; i <= 'z'; i++) {
		cnt[i] = 0;
	}
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++) {
		char ch; cin >> ch;
		cnt[ch]++;
	}
	int mod[10] = {};
	for (char i = 'a'; i <= 'z'; i++)
		mod[cnt[i] % 4]++;
	if (h % 2 == 0 && w % 2 == 0) {
		if (mod[1] || mod[2] || mod[3])cout << "No\n";
		else cout << "Yes\n";
	}
	else if (h % 2 + w % 2 == 1) {
		int v;
		if (h % 2 == 0)v = h / 2;
		else v = w / 2;
		if (mod[1] || mod[3])cout << "No\n";
		else if (mod[2] > v)cout << "No\n";
		else cout << "Yes\n";
	}
	else {
		if (mod[1] == 1 && mod[3] == 0)cout << "Yes\n";
		else cout << "No\n";
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=1e5+10;
int n,l,t;
struct ant
{
    int x,w,id;
} ants[maxn];
int x[maxn],w[maxn],id[maxn],ans[maxn];
bool cmpant(const ant& A,const ant& B)
{
    if(A.x!=B.x) return A.x<B.x;else return A.w<B.w;
}
int main()
{
    scanf("%d%d%d",&n,&l,&t);
    for(int i=1;i<=n;i++) scanf("%d%d",x+i,w+i);
    for(int i=1;i<=n;i++)
    {
        ants[i].id=i;
        ants[i].w=w[i];
        if(w[i]==1) ants[i].x=(x[i]+t)%l;else ants[i].x=((x[i]-t)%l+l)%l;
    }
    sort(ants+1,ants+n+1,cmpant);
    vector<int> rev;
    int d;
    t*=2;
    if(w[1]==1)
    {
        for(int i=2;i<=n;i++) if(w[i]==2) rev.push_back(x[i]-x[1]);
        if(rev.size()==0) d=0;else
        {
            d=(t/l)*rev.size();
            t%=l;
            for(int i=0;i<rev.size();i++) if(rev[i]<t)d++;
        }
    } else
    {
        for(int i=n;i>1;i--) if(w[i]==1) rev.push_back(x[1]-x[i]+l);
        if(rev.size()==0) d=0;else
        {
            d=(t/l)*rev.size();
            t%=l;
            for(int i=0;i<rev.size();i++) if(rev[i]<t)d++;
        }
        d=-d;
    }
    int id1;
    for(int i=1;i<=n;i++) if(ants[i].id==1) id1=i;
    id[id1]=((1+d)%n+n)%n;
    for(int i=id1+1;i<=n;i++) id[i]=(id[i-1]+1)%n;
    id[1]=(id[n]+1)%n;
    for(int i=2;i<id1;i++) id[i]=(id[i-1]+1)%n;
    for(int i=1;i<=n;i++) if(id[i]>0) ans[id[i]]=ants[i].x;else ans[n]=ants[i].x;
    for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, smx = 0;
    cin >> n;
    bitset<(int)4e6 + 1> dp;
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        smx += a;
        dp |= dp << a;
    }
    for (int i = (smx + 1) / 2; i <= smx; i++) {
        if (dp[i]) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    #define int ll
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    vector<int> sum(n + 3, 0);
    for(int i = n - 1; i >= 0; --i) {
        sum[i] = (sum[i + 1] + a[i]) % MOD;
    }
    ll ans = 0;
    rep(i, n - 1) {
        ans = (ans + a[i] * sum[i + 1]) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6424
import java.io.*;
import java.util.*;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);

        System.out.println( solve() ? "YES" : "NO");
    }

    static boolean solve() {
        long sum = 0;
        for (int a : A) {
            sum += a;
        }

        long set;
        if( N % 2 == 0 ) {
            // 1 2 3 4 -> (1+4) * (4/2)
            set = ((long)N + 1) * (N / 2);

        } else {
            set = ((long)N/2 + 1) * N;
        }
        if( sum % set != 0 ) return false;

        long k = sum / set;

        long summ_diff = 0;
        int[] diff = new int[N];
        for (int i = 0; i < N-1; i++) {
            int d = A[i+1] - A[i];
            summ_diff += d;
            diff[i] = d;
        }
        summ_diff += A[0] - A[N-1];
        diff[N-1] = A[0] - A[N-1];
        if( summ_diff != 0 ) return false;

        int b_total = 0;
        for (int i = 0; i < N; i++) {
            // d = (k-b) + b*(1-N)
            // => b = (k-d)/N
            int d = diff[i];
            if( d > k ) return false; // b=0
            if( d < (long)(1-N) * k ) return false; // b=k

            long r = (k-d)%N;
            if( r != 0 ) return false;

            long b = (k-d)/N;
            b_total += b;
        }

        if( b_total != k ) return false;

        return true;
    }

    @SuppressWarnings("unused")
    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 38168
#include<stdio.h>
int main() {
	int x[10000],i=0,tmp=0,flg=0;
	while (flg == 0) {
		scanf("%d", &x[i]);
		if (x[i] == 0) flg = 1;
		i++;
	}
	tmp = i-1;
	for (i = 0;i < tmp;i++) {
		printf("Case %d: %d\n", i + 1, x[i]);
	}
	return 0;
}


Measured memory_bytes: 2056
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let mut a = read![[i64]];

    let (mi, &m) = a.iter().enumerate().max_by_key(|&(_, x)| x.abs()).unwrap();

    let mut ops = vec![];
    {
        let mut push = |x: usize, y: usize| {
            ops.push((x, y));

            let n = a[x];
            a[y] += n;
        };

        for i in 0..N {
            push(mi, i);
        }

        if m >= 0 {
            for i in 0..N - 1 {
                push(i, i + 1);
            }
        } else {
            for i in (0..N - 1).rev() {
                push(i + 1, i);
            }
        }
    }

    debug!(a);
    debug_assert!(ops.len() <= 2 * N);
    debug_assert!(a.windows(2).all(|w| w[0] <= w[1]));

    println!("{}", ops.len());
    for &(x, y) in &ops {
        println!("{} {}", x + 1, y + 1);
    }
}


Measured memory_bytes: 4352
/*
[aising2019] D - Nearest Card Game
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_Q = 1e5;

int N, Q;
int A[MAX_N];
int X[MAX_Q];
ll s1[MAX_N + 1], s2[MAX_N + 1];

ll query(int x) {
    int ng = -1;
    int ok = N;

    while (ok - ng > 1) {
        int m = (ok + ng) / 2;
        if (A[N - (m + 1) / 2 - 1] - x < x - A[N - m - 1]) {
            ok = m;
        } else {
            ng = m;
        }
    }

    return s1[N] - s1[N - (ok + 1) / 2] +
           (N % 2 == 0 ? s1[N - ok] - s2[N - ok] : s2[N - ok]);
}

void solve() {
    s1[0] = s2[0] = 0;
    for (int i = 0; i < N; i++) {
        s1[i + 1] += s1[i] + A[i];
        s2[i + 1] += s2[i] + (i % 2 == 0 ? A[i] : 0);
    }

    for (int i = 0; i < Q; i++) {
        cout << query(X[i]) << endl;
    }
}

int main() {
    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> X[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define INF 1e9+7
using namespace std;
using ll=long long int;
using pii=pair<int,int>;

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    vector<int> dp(n+1,0);
    for(int i=1;i<n;i++) {
        int temp; cin>>temp;
        dp[temp]++;
    }
    for(int i=1;i<=n;i++) {
        cout<<dp[i]<<endl;
    }
}



Measured memory_bytes: 3992
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<utility>
using namespace std;

int main(){
	int dw[]={0,1,-1,0};
	int dh[]={1,0,0,-1};
	int w,h;
	while(cin>>w>>h,w){
		vector<vector<int>> wallw(w-1,vector<int>(h));
		vector<vector<int>> wallh(w,vector<int>(h-1));
		for(int i=0;i<h;i++){
			for(int j=0;j<w-1;j++)
				cin>>wallw[j][i];
			if(i==h-1)
					break;
			for(int j=0;j<w;j++)
				cin>>wallh[j][i];
		}
		vector<vector<int> > been(w,vector<int>(h,0));
		queue<pair<pair<int,int> ,int> > q;
		q.push(make_pair(make_pair(0,0),0));
		while(!q.empty()){
			pair<int,int> p=q.front().first;
			int turn =q.front().second;
			if(p.first==w-1 && p.second==h-1){
				cout<<turn+1<<endl;
				break;
			}
			q.pop();

			been[p.first][p.second]=1;
			for(int i=0;i<4;i++){
					if(0<=p.first+dw[i] && p.first+dw[i]<w && 0<=p.second+dh[i] && p.second+dh[i]<h){
						if((((i==0 || i==3)&&wallh[p.first][p.second+(dh[i]-1)/2]==0) ||( (i==1|| i==2)&&wallw[p.first+(dw[i]-1)/2][p.second]==0) )&& !been[p.first+dw[i]][p.second+dh[i]])
							q.push(make_pair(make_pair(p.first+dw[i],p.second+dh[i]),turn+1)),been[p.first+dw[i]][p.second+dh[i]]=1;
					}
				

			}


		}
		if(q.empty())
			cout<<0<<endl;

	}


}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> K >> N;
  int mx = 0;
  int A[N];
  FOR(i,0,N) {
    cin >> A[i];
  }
  FOR(i,0,N-1) {
    mx = max(mx, A[i+1] - A[i]);
  }
  mx = max(mx, K - A[N-1] + A[0]);
  cout << K - mx << endl;
}


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

int main() {
  string S;
  cin >> S;
  
  int ans = 700;
  for(int i = 0;i < S.size();i++){
    if(S.at(i) == 'o')
      ans = ans + 100;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>> c(h);
    rep(i, h) c[i].resize(w, 0);
    int acnt = 0;
    
    rep(i, h * w) {
        int x = ((i / w % 2 == 1) ? (w - i % w - 1) : (i % w));
        int y = i / w;
        
        c[y][x] = acnt + 1;
        a[acnt]--;
        
        if (a[acnt] == 0) {
            acnt++;
        }
    }
    
    rep(y, h) {
        rep(x, w) {
            printf("%d%s", c[y][x], (x == (w - 1)) ? "\n" : " ");
        }
    }
    
    return 0;
}

Measured memory_bytes: 384
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var k = long.Parse(line[0]);
        var a = long.Parse(line[1]);
        var b = long.Parse(line[2]);
        if (a >= k) { Console.WriteLine(1); goto end; }
        if (a <= b) { Console.WriteLine(-1); goto end; }
        var ans = (2L * k - 2L * b - 1L) / (a - b);
        Console.WriteLine(ans % 2 == 0 ? ans + 1 : ans);
        end:;
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			long a = sc.nextLong();
			// 文字列の入力
			double pai = 3.141592;
			System.out.println((double) a * 2 * pai);
		}
	}

	/**
	 * 最小公倍数
	 */
	static long lcm(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return c / b;
	}

	/**
	 * 最大公約数
	 */
	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
}

Measured memory_bytes: 35884
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	string str;
	cin >> str;

	cout << str[0] << str.size()-2 << str[str.size()-1];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define fi first
#define se second
#define sz(a) ((int)a.size())

const int MAXN = 1e5+100;
const int MOD = 1e9+7;

int a[MAXN],b[MAXN];

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

    ll cnt = 0;

    for(int i=1;i<=n;++i){
        cin >> a[i];
    }
    for(int i=1;i<=n;++i){
        cin >> b[i];
        if(b[i]>a[i]){
            cnt+=(b[i]-a[i])/2;
        }
    }

    for(int i=1;i<=n;++i){
        if(b[i]<a[i]){
            int k = a[i] - b[i];
            if(cnt<k){
                cout <<"No\n";
                return;
            }
            cnt-=k;
        }
    }
    cout <<"Yes\n";
    return;



}

int main(){
    #ifdef tw
        freopen("input.txt","r",stdin);
    #endif // zxc

    int t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

typedef struct pp{
	char name[100];
	int time;
}P;

P Q[100005];
int head,tail,n;

void enqueue(P x)
{
	Q[tail]=x;
	tail=(tail+1)%100005;
}

P dequeue()
{
	P x=Q[head];
	head=(head+1)%100005;
	return x;
}

int min(int a,int b)
{
	return a<b?a:b;
}


int main ()
{
	int e=0,c;
	int i,q;
	P u;
	scanf ("%d %d",&n,&q);
	
	for (int i=1;i<=n;i++)
	{
		scanf ("%s",Q[i].name );
		scanf ("%d",&Q[i].time );
	}
	head=1;tail=n+1;

	while (head!=tail)
	{
		u=dequeue();
		c=min(q,u.time);
		u.time-=c;
		e+=c;
		if (u.time >0) enqueue(u);
		else printf ("%s %d\n",u.name ,e);
	}
}


Measured memory_bytes: 11872
n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1

for i in range(n):
    print(' '.join(map(str, graph[i])))


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

#define FILE_NAME "atcoder.agc026_c"
#define SZ(x) ((int) x.size())
#define pb push_back
#define ppb pop_back
#define x first
#define y second
#define mkp make_pair
#define show(x) cout << (#x) << ": " << x << endl

using namespace std;
// using namespace __gnu_pbds;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template<typename T> using Array = vector<T>;
template<typename T> using Matrix = Array<Array<T>>;
using Graph = Matrix<int>;

// template<typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T> bool relax(T& r, const T& x) {
    if (x < r) {
        r = x;
        return true;    
    }
    return false;
}

template<typename T> bool heavy(T& h, const T& x) {
    if (h < x) {
        h = x;
        return true;            
    }
    return false;
}

const int DX[8] = {-1, +1, +0, +0, +1, -1, +1, -1};
const int DY[8] = {+0, +0, -1, +1, +1, -1, -1, +1};

/************************************************************
* find_by_order(k) = iterator to (k)-th greatest element    *
* order_of_key(k) = counts number of strictly less elements *
*************************************************************/                                                           

signed main() {
#ifdef LOCAL
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<pair<string, string>, int> cnt;
    for (int mask = 0; mask < (1 << n); mask++) {
        string s0 = "", s1 = "";
        for (int i = 0; i < n; i++)
            if (mask & (1 << i))
                s0 += s[i];
            else
                s1 += s[i];
        reverse(s1.begin(), s1.end());
        cnt[mkp(s0, s1)]++;                                        
    }
    ll ans = 0;
    for (int submask = 0; submask < (1 << n); submask++) {
        ll mask = ((ll) submask << n);
        string s2 = "", s3 = "";
        for (int i = n; i < 2 * n; i++)
            if (mask & (1ll << i))                    
                s2 += s[i];
            else
                s3 += s[i];
        reverse(s3.begin(), s3.end());
        ans += cnt[mkp(s3, s2)];                    
    }
    cout << ans;
    return false;
}

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

using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> p_v(h + 2, vector<int>(w + 2, 0));
  vector<vector<int>> p_h(h + 2, vector<int>(w + 2, 0));
  
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      char c;
      cin >> c;
      if(c == '.'){
        p_v[i][j] = 1;
        p_h[i][j] = 1;
      }
    }
  }
  
  for(int i = 1; i <= h; i++){
    int left = 0;
    int sum = 0;
    for(int j = 1; j <= w + 1; j++){
      if(p_h[i][j] != 0){
        sum++;
      }else{
        for(int k = left + 1; k < j; k++){
          p_h[i][k] = sum;
        }
        sum = 0;
        left = j;
      }
    }
  }
  
  for(int j = 1; j <= w; j++){
    int up = 0;
    int sum = 0;
    for(int i = 1; i <= h + 1; i++){
      if(p_v[i][j] != 0){
        sum++;
      }else{
        for(int k = up + 1; k < i; k++){
          p_v[k][j] = sum;
        }
        sum = 0;
        up = i;
      }
    }
  }
  
  int max = 0;
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      int r = p_h[i][j] + p_v[i][j] - 1;
      if(r > max){
        max = r;
      }
    }
  }
  
  cout << max << endl;
  
  return 0;
}


Measured memory_bytes: 31744
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

ll D;
vi c;
vvi s;

ll value(vi t)
{
    ll S = 0;
    vi last(26);
    REP(i, t.size())
    {
        ll k = t[i];
        last[k] = i + 1;
        S += s[i][k];
        REP(j, 26)
        {
            S -= c[j] * (i + 1 - last[j]);
        }
    }
    return S;
}

int main()
{
    cin >> D;
    c.resize(26);
    REP(i, 26)
    {
        cin >> c[i];
    }
    s.assign(D, vi(26));
    REP(i, D)
    {
        REP(j, 26)
        {
            cin >> s[i][j];
        }
    }

    vi t;
    REP(i, D)
    {
        ii opt = {0, 0};
        REP(j, 26)
        {
            t.push_back(j);
            ll res = value(t);
            t.pop_back();
            if (res > opt.first)
            {
                opt = {res, j};
            }
        }
        t.push_back(opt.second);
    }
    FOR(x, t)
    {
        OUT(x + 1);
    }
}

Measured memory_bytes: 3768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

vector<Int> divisors[1080000];

Int sum[1080000];
Int sqsum[1080000];
Int allsum[1080000];
Int fact[1080000];
Int revfact[1080000];
Int rev[1080000];
Int mebius[1080000];
bool prime[1080000];

void init(){
    Int m = MOD;
    fact[0] = 1;
    revfact[0] = 1;
    rev[0] = 0;
    rev[1] = 1;
    for(Int i = 1;i < 1080000;i++){
        fact[i] = fact[i-1] * i % m;
        if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD;
        revfact[i] = revfact[i-1] * rev[i] % MOD;
    }
}

Int nCk(Int n, Int k){
    if(n < k)return 0;
    return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD;
}

Int n, a, ans;

int main(){
    init();
    fill(prime, prime + 1080000, true);
    prime[0] = prime[1] = false;
    for(int i = 1;i < 1080000;i++){
        for(int j = 1;j * i < 1080000;j++){
            divisors[i*j].push_back(i);
        }
    }
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a;
        for(int d:divisors[a]){
            sum[d] += a;sum[d] %= MOD;
            sqsum[d] += a*a%MOD;sqsum[d] %= MOD;
        }
    }
    for(int i = 1050000;i >= 1;i--){
        allsum[i] += (sum[i] * sum[i] % MOD - sqsum[i])%MOD;
        if(allsum[i] == 0)continue;
        for(int d:divisors[i]){
            if(d == i)continue;
            (allsum[d] -= allsum[i])%=MOD;
        }
        ans += allsum[i] * rev[i] % MOD;
        ans %= MOD;
    }
    ans *= rev[2];ans %= MOD;
    if(ans < 0)ans += MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 249088
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V[i];
  int ans = 0;
  
  for (int l = 0; l <= min(N, K); l++) {
    for (int r = 0; l+r <= min(N, K); r++) {
      if (l+r==0)continue;
      
      vector<int> v;
      int tmp = 0;
      for (int i = 0; i < l; i++) {
        v.push_back(V[i]);
        tmp += V[i];
      }
      for (int i = 0; i < r; i++) {
        v.push_back(V[N-1-i]);
        tmp += V[N-1-i];
      }
      
      sort(v.begin(), v.end());
      for (int i = 0; i < min((int)v.size(), K-l-r); i++) {
        if (v[i] >= 0) break;
        tmp -= v[i];
      }
      
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
class Bit:
    def __init__(self, n):
        self.n = n
        self.tree = [0]*(n+1)
        self.el = [0]*(n+1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1) )- 1
        return s

    def add(self, i, x):
        self.el[i] += x
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

class BitSet2:
    """ 座標圧縮が必要な場合 """
    def __init__(self, data, A=[]):
        """ BitSetに入り得る値を先読みした物を data に格納 """
        self.data = sorted(list(set(data)))
        self.n = len(self.data)
        self.p = Bit(self.n + 1)
        self.size = 0
        self.flip = 0
        self.code = {}
        self.decode = {}
        for i, b in enumerate(self.data):
            self.code[b] = i
            self.decode[i] = b
        for a in A:
            self.add(a)

    def add(self,x):
        self.p.add(self.code[x], 1)
        self.size += 1
        self.flip += self.size - self.p.sum(self.code[x]+1)

    def remove(self,x):
        self.p.add(x, -1)
        self.size -= 1

    def flip_counter(self):
        return self.flip



####################################################################################################

import sys
input = sys.stdin.readline
from itertools import accumulate
N, K = map(int, input().split())
A = []
for _ in range(N):
    A.append(int(input()))
S = [0] + list(accumulate(A))
T = []
for i, s in enumerate(S):
    T.append(s-K*i)
B = BitSet2(T,T)
print(N*(N+1)//2-B.flip_counter())

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

int main() {
  int N,M,Q;
  cin >> N >> M >> Q;
  int a[Q],b[Q],c[Q],d[Q];
  rep(i,Q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;b[i]--;
  }
  int arr[10];
  int ans=0;
  for(arr[0]=1;arr[0]<=M;arr[0]++)
  for(arr[1]=arr[0];arr[1]<=M;arr[1]++)
  for(arr[2]=arr[1];arr[2]<=M;arr[2]++)
  for(arr[3]=arr[2];arr[3]<=M;arr[3]++)
  for(arr[4]=arr[3];arr[4]<=M;arr[4]++)
  for(arr[5]=arr[4];arr[5]<=M;arr[5]++)
  for(arr[6]=arr[5];arr[6]<=M;arr[6]++)
  for(arr[7]=arr[6];arr[7]<=M;arr[7]++)
  for(arr[8]=arr[7];arr[8]<=M;arr[8]++)
  for(arr[9]=arr[8];arr[9]<=M;arr[9]++){
    int sum=0;
    rep(i,Q){
      if(arr[b[i]]-arr[a[i]]==c[i]) sum+=d[i];
    }
    ans=max(sum,ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
n=int(input())

A=list(map(int,input().split()))
sa=sum(A)-2*A[0]
S=[abs(sa)]
if n>2:
    for i in range(1,n-1):
        sa-=2*A[i]
        S.append(abs(sa))
    print(min(S))
         
else:
    a=A[0]
    b=A[1]
    print(abs(a-b))

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define rep(i,n)for(urs(n)i=0;i<(n);++i

int main(){
	int k,a,b;
    cin >> k >>a>> b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK";
            return 0;
        }
    }
cout << "NG";
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
using Q = pair<P,ll>;

/*
SegmentTree st(vector<ll> a,ll b);
で初期化．uは単位元(例:区間最小→INF，区間和→0，最大公約数→0)
mergeの中身を適宜書き換える
*/

class SegmentTree{
public:
    ll N, unit; 
    vector<ll> data, tree;
    SegmentTree(vector<ll> v, ll u){
        unit = u;
        data = v;
        ll n = data.size();
        N = 1;
        while(N<n)N*=2;
        tree = vector<ll>(N*2,u);
        build();
    }
    void build(){rep(i,N)update(i,data[i]);}
    void update(ll i, ll x){
        i += N-1;
        //tree[i]+=x;
        tree[i]=min(tree[i],x);
        while(i){
            i = (i-1)/2;
            tree[i]=merge(tree[i*2+1],tree[i*2+2]);
        }
    }
    ll query(ll start, ll end){return query(start, end, 0, 0, N);}
private:
    ll query(ll a, ll b, ll k, ll l, ll r){
        if(r<=a||b<=l)return unit;
        if(a<=l&&r<=b)return tree[k];
        else{
            ll lv = query(a,b,2*k+1,l,(l+r)/2);
            ll rb = query(a,b,2*k+2,(l+r)/2,r);
            return merge(lv,rb);
        }
    }
    ll merge(ll l, ll r){
        return min(l,r);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;cin>>n>>m;
    vector<Q> lrc(m);
    rep(i,m){
        ll l,r,c;cin>>l>>r>>c;
        lrc[i]={{r-1,l-1},c};
    }
    sort(lrc.begin(),lrc.end());
    ll idx = 0;
    vector<ll> dp(n,INF);dp[0]=0;
    bool flag = true;
    SegmentTree st(vector<ll>(n,INF), INF);
    st.update(0,0);

    //cout<<"min"<<st.query(0,n)<<endl;

    for(ll pos = 0; pos<n; pos++){
        ll mini = INF;
        
        if(lrc[idx].first.first!=pos)continue;
        while(lrc[idx].first.first==pos){
            //cout<<pos<<" "<<idx<<endl;
            mini = min(mini,st.query(lrc[idx].first.second,lrc[idx].first.first+1)+lrc[idx].second);
            //cout<<mini<<endl;
            idx++;
        }
        dp[pos]=mini;
        st.update(pos,mini);
    }
    if(dp[n-1]>INF/2)cout<<-1<<endl;
    else cout<<dp[n-1]<<endl;
    //rep(i,n)cout<<dp[i]<<" ";
    //cout<<idx;
    return 0;
}

Measured memory_bytes: 6912
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int H,W,N;
  cin >> H >> W >> N;

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

  vector<vector<int>> grid(H,vector<int>(W,0));

  int x = 0;
  int y = 0;
 
  int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};

  int index = 0;
  for(int i = 0;i < N;i++){
    for(int j = 0;j < a[i];j++){
      grid[y][x] = i + 1;
      if(x+dir[index][0] == W || x + dir[index][0] == -1 || y + dir[index][1] == H || y + dir[index][1] == -1 || grid[y+dir[index][1]][x+dir[index][0]] != 0){
	index = (index + 1) % 4;
      }
      x += dir[index][0];
      y += dir[index][1];
    }
  }

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      cout << grid[i][j] << " ";
    }
    cout << endl;
  }

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define ll long long
#define pb push_back
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define mod 1000000007
#define mod1 998244353
#define ff first
#define ss second
#define MAX 500005
#define N 200005
#define INF 1000000009
#define all(v) v.begin(), v.end()
#define sbit(a) __builtin_popcount(a)
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppl;
typedef map<ll, ll> mpll;
typedef map<vector<ll>, ll> mpvl;
ll power(ll x, ll y, ll p)
{
  ll res = 1;

  x = x % p;

  if (x == 0)
    return 0;
  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }

  return res;
}
bool cmp(pll x,pll y)
{
  return x.ff+x.ss>y.ff+y.ss;
}
bool cmp1(pll x,pll y)
{
  return x.ff-x.ss>y.ff-y.ss;
}
void solve()
{
  ll n;
  cin >> n;
  vector<pll> p(n);
  for (ll i = 0; i < n; i++)
  {
    cin >> p[i].ff >> p[i].ss;
  }
  // take out the mod//|x1-x2|+|y2-y1|//take cases
  ll ans=0;
  sort(all(p),cmp);
  ll g=(p[0].ff+p[0].ss)-(p[n-1].ff+p[n-1].ss);
  ans=max(ans,g);
  sort(all(p),cmp1);
  g=(p[0].ff-p[0].ss)-(p[n-1].ff-p[n-1].ss);
  ans=max(ans,g);
  cout<<ans<<endl;

}
int main()
{
  speed;
  ll kk;
  kk = 1;
  //cin >> kk;
  while (kk--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 6284
// longest-path.rs --- Longest Path
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(dp: &mut Vec<u32>, paths: &Vec<Vec<usize>>, i: usize) -> u32 {
    if dp[i] != 0 {
        return dp[i];
    }

    dp[i] = paths[i]
        .iter()
        .map(|&j| f(dp, paths, j))
        .max()
        .map_or(0, |l| l + 1);
    return dp[i];
}

fn main() {
    input! {
        n: usize,
        m: usize,
        edges: [(usize1, usize1); m],
    };

    let mut paths = vec![vec![]; n];
    let mut refs = vec![vec![]; n];
    for (x, y) in edges.into_iter() {
        paths[x].push(y);
        refs[y].push(x);
    }
    let mut dp = vec![0; n];

    let ans = refs
        .into_iter()
        .enumerate()
        .filter(|&(_, ref from)| from.is_empty())
        .map(|(i, _)| f(&mut dp, &paths, i))
        .max()
        .unwrap();
    println!("{}", ans);
}


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

namespace ABC061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            if (a <= c&& c <= b)
            {
                Console.WriteLine("Yes");
            }

            else
            {
                Console.WriteLine("No");
            }
       
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
N = str(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if int(N[-1]) in hon:
  print("hon")
elif int(N[-1]) in pon:
  print("pon")
elif int(N[-1]) in bon:
  print("bon")

Measured memory_bytes: 61780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const ll INF = 1LL << 58;

struct edge{
	ll from;
	ll to;
	ll cost;
};

vector<edge> G;

int main(){
	ll n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		ll a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		G.pb({a, b, -c});
	}
	ll d[1010];
	for(int i = 0; i < 1010; i++) d[i] = INF;
	d[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			edge e = G[j];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				if(i == n-1 && e.to == n-1){
					cout << "inf" << endl;
					return 0;
				}
			}
		}
	}
	cout << -d[n-1] << endl;
	return 0;
}


Measured memory_bytes: 384
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int N;
    cin >> N;

    string S;
    cin >> S;

    // 累積和
    vector<int> ACE(N);
    vector<int> ACW(N);

    if(S[0]=='E') ACE[0] = 1;
    if(S[0]=='W') ACW[0] = 1;
    FOR(i, 1, N){
        ACE[i] = ACE[i-1];
        if(S[i]=='E') ACE[i]++;

        ACW[i] = ACW[i-1];
        if(S[i]=='W') ACW[i]++;
    }

    int min_num = N;
    FOR(i, 0, N){
        int num = 0;
        if(i!=0){
            int leftStart = 0;
            int leftEnd = i - 1;
            num += ACW[leftEnd];
        }

        if(i!=N-1){
            int rightStart = i + 1;
            int rightEnd = N - 1;
            num += ACE[rightEnd] - ACE[rightStart-1];
        }
 
        min_num = min(min_num, num);
    }

    p(min_num);

    return 0;
}

Measured memory_bytes: 2964
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int A, B, C;

void MAIN() {
    scanf("%d%d%d", &A, &B, &C);
    bool yes = A == B && B == C;
    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int k, a, b;
    cin >> k >> a >> b;

    for ( long long int i = 0; i <= 1000; i++ ) {
        if ( k * i < a ) continue;
        if ( k * i > b ) break;
        cout << "OK" << endl;
        return 0;
    }

    cout << "NG" << endl;

    return 0;

}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
bool bl[123456];
signed main() {
	int n; cin >> n;
	vector<pair<int, pair<int, int>>> v;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		v.push_back(make_pair(a+b, make_pair(a, b)));
	}
	sort(v.begin(), v.end());
	int a = 0, b = 0;
	int k = n - 1;
	for (int i = 1; i <= n; i++) {
		if (i % 2) {
			a += v[k].second.first;
			k--;
		}
		else {
			int front = 0, back = k;
			while (back - front > 1) {
				int mid = (front + back) / 2;
				if (v[mid] == v[k]) {
					if (bl[mid])front = mid;
					back = mid;
				}
				else front = mid;
			}
			b += v[back].second.second;
			bl[back] = 1;
			while (bl[k])k--;
		}
	}
	cout << a - b << endl;
}

Measured memory_bytes: 4852
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	k := intScanner()
	a := intSliceScanner(n)
	as := make([]int, n+1)
	for i := 0; i < n; i++ {
		as[i+1] = a[i] + as[i]
	}
	x := make([]int, 0, n*(n+1)/2)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n+1; j++ {
			x = append(x, as[j]-as[i])
		}
	}
	ans := 0
	for i := 42; i >= 0; i-- {
		y := make([]int, 0, len(x))
		for j := 0; j < len(x); j++ {
			if (x[j]>>uint(i))&1 == 1 {
				y = append(y, x[j])
			}
		}
		if len(y) >= k {
			ans += 1 << uint(i)
			x = make([]int, len(y))
			copy(x, y)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<s.size();j++)
			{
				if(s[j]=='F')
				{
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 100100;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL<<60;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main() {
  ll n,w;
  cin>>n>>w;
  ll we[n],val[n];
  for(int i=0;i<n;i++){
    cin>>we[i]>>val[i];
  }
  ll dp[110][MAX];
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(ll j=0;j<=w;j++){
      if(j>=we[i]){
        dp[i+1][j]=max(dp[i+1][j],dp[i][j-we[i]]+val[i]);
      }
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    }
  }
  cout<<dp[n][w]<<endl;
}


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

int main() {
  long long a,b;
  cin >> a >> b;
  long long s;
  for(int i=1; i<=b; i++){
    if(a*i%b == 0){
      s = a*i;
      break;
    }
  }
  cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int N;
  int i,a[150];
  int flag=0;
  
  do {
  scanf("%d",&N);
  } while (N<1 || N > 100);
  
  for(i=0;i<N;i++){
    do {
    	scanf("%d",&a[i]);
    } while (a[i]<1 || a[i] > 1000);
      
    if((a[i] % 2 != 0) || (a[i] % 3 == 0) || (a[i] % 5 == 0))
      flag++;
  }
  if(flag==N)
    printf("APPROVED\n");
  else
    printf("DENIED\n");
  
  return 0;
}

Measured memory_bytes: 128