akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
 
    token.parse().ok().expect("failed to parse token")
}
 
fn main() {
    let n: u8 = read();
    let m: usize = read();
    let mut map = HashMap::new();
    let mut flag = true;
 
    for _i in 0..m {
        let s: u8 = read();
        let c: u8 = read();
        let value = map.entry(s).or_insert(c);
        //同じ桁で異なる値が設定された場合
        if c != *value {
            flag = false;
        }
    }
 

    //答えを作れない場合
    if flag == false {
        println!("-1");
        return;
    }

    //1桁の場合
    if n == 1 && m != 0{
        print!("{}", map.get(&1).unwrap());
        return;
    }else if n == 1 {
        print!("0");
        return;
    }

    //2桁以上の場合

    //1桁目が未設定の場合
    if map.get(&1) == None {
        print!("1");
    //1桁目が0設定の場合
    } else if map.get(&1) == Some(&0) {
        println!("-1");
        return;
    //1桁目が0以外設定の場合
    } else {
        print!("{}", map.get(&1).unwrap());
    }

    for i in 2 .. n + 1 {
        if map.get(&i) == None {
            print!("0");
        } else {
            print!("{}", map.get(&i).unwrap());
        }
    }
 
}

Measured memory_bytes: 4352
import math

str = input().split()
a = int(str[0])
b = int(str[1])
h = int(str[2])
m = int(str[3])

theta = abs(h*30 + m/2 - m*6)
print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(theta))))

Measured memory_bytes: 9444
N,M = (int(i) for i in input().split())
s = [[int(i) for i in input().split()] for i in range(M)]
p = [int(i) for i in input().split()]
result2 = 0

for i in range(2 ** N):
    hoge = bin(i + 1)
    hoge = str(hoge)
    hoge = hoge[2:]
    hoge = hoge.zfill(len(str(bin((2 ** N)))) - 2)
    result = True
    for j in range(M):
        onon = 0
        for k in s[j][1:]:
            if hoge[k] == "1":
                onon += 1
        if onon % 2 != p[j]:
            result = False
    if result:
        result2 += 1
print(result2)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int[] time = new int[5];
    for (int i = 0; i < 5; i++) {
      time[i] = scanner.nextInt();
    }
    int minIdx = 0;
    int minMod = (time[0] - 1) % 10;
    for (int i = 1; i < 5; i++) {
      if ((time[i] - 1) % 10 < minMod) {
        minIdx = i;
        minMod = (time[i] - 1) % 10;
      }
    }
    int sum = 0;
    for (int i = 0; i < 5; i++) {
      if (i != minIdx) {
        sum += (time[i] + 9) / 10 * 10;
      }
    }
    sum += time[minIdx];
    System.out.println(sum);
  }

}


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

using ll = long long;
#define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))


int solve(int n, int a, int b) {
  int diff = abs(a-b);
  if(diff%2==0) return diff/2;
  if(diff == 1) return min(b-1, n-a);

  int right = n - b;
  int left = a - 1;
  if(right < left) {
    return right+1 + solve(n, a+right+1, n);
  } else {
    return left+1 + solve(n , 1, b-(left+1));
  }
}

/***** MAIN *****/
signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = solve(n, a, b);
  cout << ans;

  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (b-a&1) puts("IMPOSSIBLE");
  else cout << (b+a)/2 << '\n';  
  return 0;
}

Measured memory_bytes: 3720
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

int main() {
	string s;
	cin >> s;

	vector<int> vec(4);

	rep(i, s.size()) {
		vec[i] = (s[i]-'0');
	}
	

	for (int bit = 0; bit < (1 << 3); bit++) {
		int ans = vec[0];
		vector<char> vec2(3);
		rep(i, 3) {
			if (bit & (1 << i)) {
				ans += vec[i + 1];
				vec2[i] = '+';
			}
			else{
				ans -= vec[i + 1];
				vec2[i] = '-';
			}
		}
		if (ans == 7) {
			cout << vec[0];
			rep(i, 3) {
				cout << vec2[i]<<vec[i+1];
			}
			cout << "=7" << endl;
			break;

		}
	}
	
	return 0;
}

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

const int oo = 1e9;

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1), c(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(3, oo));
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    for (int i = 2; i <= n; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
    cout << *max_element(dp[n].begin(), dp[n].end());
}

int main() {
    #ifdef DEBUG
        freopen("solve.inp", "r", stdin);
        freopen("solve.out", "w", stdout);
    #endif
    solve();
    return 0;
}   

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define mod 1000000007;
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9)
    cout<<"hon";
    else if(n==3)
    cout<<"bon";
    else
    cout<<"pon";
    

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;

int calcTaste(int L, int i)
{
    return L + i - 1;
}

int main()
{
  int N, L;

  cin >> N >> L;

  std::vector<int> tastes(N);
  int totalTaste = 0;
  for (size_t i=0; i<N; i++) {
      tastes[i] = calcTaste(L, i+1);
      totalTaste += tastes[i];
  }

  int minDiff = std::numeric_limits<int>::max();
  int remainTasteWhenDiffIsMin = 0;
  for (size_t i=0; i<N; i++) {
      int remainTaste = totalTaste - tastes[i];
      int diff = abs(remainTaste - totalTaste);
      if (diff < minDiff) {
          remainTasteWhenDiffIsMin = remainTaste;
          minDiff = diff;
      }
  }
  cout << remainTasteWhenDiffIsMin << endl;

  return 0;
}



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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, Q;
	string S;
	vector<P> lr;

	cin >> N >> Q >> S;
	lr.resize(Q);
	for(int i = 0; i < Q; i++)
		cin >> lr[i].first >> lr[i].second;

	vector<llong> v(N+1,0);
	for(int i = 1; i < N; i++){
		v[i] = v[i-1];
		if(S[i-1] == 'A' && S[i] == 'C')
			v[i]++;
	}

	vector<llong> ans;
	for(auto x : lr){
		ans.push_back(v[x.second-1] - v[x.first-1]);
	}

	for(auto x : ans)
		cout << x << endl;

	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;

    int ret = 0;
    string prev, now;
    for (int i = 0; i < s.size(); i++) {
        now += s[i];
        if (prev != now)ret++, prev = now, now.clear();
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

    // メディアンを
    sort(B.begin(), B.end());
    long long x = B[N/2];

    // 答えを求める
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        res += max(x - B[i], -x + B[i]); // |A| = max(A, -A)
    }
    cout << res << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define prsp(v) loop(i,0,v.size())cout<<v[i],sp;nl;
#define prpsp(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S<<" , ";nl;
#define prnl(v) loop(i,0,v.size())cout<<v[i],nl;nl;
#define prpnl(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S,nl;nl;
#define MOD 1000000007
#define mod(n) (((n%MOD)+MOD)%MOD)
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int f,s;
    cin>>f;
    s = f%100;
    f /= 100;
    int fm=(1<=f && f<=12);
    int sm=(1<=s && s<=12);

    if( fm && sm )
    {
        cout<<"AMBIGUOUS";
    }
    else if( fm )
    {
        cout<<"MMYY";
    }
    else if( sm )
    {
        cout<<"YYMM";
    }
    else
    {
        cout<<"NA";
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a>d)
    cout<<d;
  else if(a+b>=d)
    cout<<a;
  else{
  cout<<a-(d-a-b);
  }
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
typedef long double f80;
#define all(x) x.begin(), x.end()

const int mod = 1e9 + 7;

map<string,int> m;

signed main()
{
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    fr(i ,1, n) {
        string s;
        cin >> s;
        sort(all(s));
        m[s]++;
    }
    ll ans = 0;
    for(auto x : m) {
        ans += ((ll)x.se * (x.se - 1)) / 2;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int n,m,x;
	int cost[100];
	int ans=0;
	fill(cost,cost+100,0);
	cin>>n>>m>>x;
	x--;
	for(int i=0;i<m;i++)
	{
		int a;
		cin>>a;
		a--;
		cost[a]=1;
	}
	for(int i=1;i<n;i++)
	{
		cost[i]+=cost[i-1];
	}

	ans = min(cost[x],cost[n-1]-cost[x]);
	cout<<ans<<endl;
	return 0;
}

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

#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef tuple<int, int, int> TP;
typedef vector<int> VI;
typedef double T;
typedef vector<T> VT;
typedef vector<VT> VVT;

const LL MOD = 1e9 + 7;
const double EPS = 1e-10;
mt19937 rng(7); // random generator using 7 for seed
const int MAXN = 1e5 + 10;

int w[MAXN], v[MAXN];
LL dp[101][MAXN];

int main() {
    int N, W;
    scanf("%d%d", &N, &W);
    for(int i=0;i<N;i++) {
        scanf("%d%d",&w[i], &v[i]);
    }
    for(int i=0;i<N;i++) {
        for(int j=0;j<=W;j++) {
            if(i-1>=0) {
                dp[i][j] = max(dp[i-1][j], (j-w[i]>=0)?dp[i-1][j-w[i]]+v[i]:0);
            } else {
                if(j>=w[i])dp[i][j] = v[i];
            }
        }
    }
    printf("%lld\n", dp[N-1][W]);
}

Measured memory_bytes: 78336
mod = 10**9+7

n,k = map(int, input().split())
count = 0
for i in range(n+1-k+1):
    j = k+i
    count += (((2*n-(j-1))*(j)//2 - (j-1)*(j)//2) + 1)
    count = count % mod
print(count)

Measured memory_bytes: 63524
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define ANS_DC(x)			cout <<  x << endl
#define V_TYPE				int
#define INF					1e4+1

using namespace std;
typedef long long ll;
typedef vector<V_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	if (s[k - 1] == 'A') s.replace(k-1, 1, "a");
	else if (s[k - 1] == 'B') s.replace(k-1, 1, "b");
	else if (s[k - 1] == 'C') s.replace(k-1, 1, "c");

	ANS_DC(s);
	return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

k = int(input())
s = input()

if len(s) <= k:
    print(s)
else:
    print(s[:k] + "...")

Measured memory_bytes: 67724
#include <bits/stdc++.h>
using namespace std;
int main () {
  int H, W;
  cin >> H >> W;
  char a;
  int count = 0;
  for(int i = 0; i < H * W; i++){
    cin >> a;
    if(a == '#')count++;
  }
  cout << (count == H + W - 1?"Possible":"Impossible") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N;
    cin >> N;
    cout << N / 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* Starry Sky Tree */
//0-index

struct StarrySkyTree{
  typedef ll Type;
  int segn2;
  vector<Type> data, s_data;

  StarrySkyTree(int n) {
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, 0);
    s_data.assign(segn2*2, 0);
  }

  //get value of [a,b)
  Type query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(r <= a || b <= l) return LLINF; //大きさに注意
    if(a <= l && r <= b) return data[k] + s_data[k];
    return min(query(a, b, l, (l+r)/2, k*2+1), query(a, b, (l+r)/2 , r, k*2+2)) + s_data[k];
  }

  //add x to [a,b)
  Type add(int a, int b, Type x, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b)
      s_data[k] += x;
    else if(a < r && l < b)
      data[k] = min(add(a, b, x, l, (l+r)/2, k*2+1), add(a, b, x, (l+r)/2, r, k*2+2));

    return data[k] + s_data[k];
  }

  Type val(int x){
    Type res = 0;
    x += segn2 - 1;

    while(x){
      res += s_data[x];
      x = (x-1)/2;
    }

    return res;
  }

  void add(int a, Type x){
    a += segn2 - 1;
    s_data[a] += x;

    while(a){
      a = (a-1)/2;
      data[a] = min(data[a*2+1] + s_data[a*2+1], data[a*2+2] + s_data[a*2+2]);
    }
  }
};

int main(){
  int N, A, B, p;

  scanf("%d%d%d", &N, &A, &B);

  StarrySkyTree seg(N+1);

  for(int i=0;i<N;i++){
    scanf("%d", &p);

    seg.add(p, seg.query(0, p) - seg.val(p));
    seg.add(0, p, A);
    seg.add(p+1, N+1, B);
  }

  ll ans = seg.query(0, N+1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 405;
const int MAXM = 100005;

int N, M;
int x[MAXM], y[MAXM];
bool cons[MAXN], bio[MAXN];
int when[MAXN][MAXN];

void load() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", x + i, y + i);
		x[i]--; 
		y[i]--;
	}
}

bool process(int t) {
	memset(bio, false, sizeof bio);
	bio[t] = true;
	when[t][t] = M;
	for (int i = M - 1; i >= 0; i--)
		if (bio[x[i]] || bio[y[i]]) {
			if (bio[x[i]] && bio[y[i]])
				return false;
			if (bio[y[i]])
				swap(x[i], y[i]);
			bio[y[i]] = true;
			when[t][y[i]] = i;
		}
	return true;
}

bool cmp(int l, int r) {
	if (!cons[l] || !cons[r])
		return false;
	for (int i = 0; i < N; i++)
		if (when[l][i] != -1 && when[r][i] != -1 && when[l][i] != when[r][i])
			return false;
	return true;
}

int solve() {
	memset(when, -1, sizeof when);
	for (int i = 0; i < N; i++)
		cons[i] = process(i);
		
	int sol = 0;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < i; j++)
			sol += cmp(i, j);
			
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

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

using namespace std;

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

	vector<pair<int, int>> process;
	long long ans = a[n - 1];
	long long tmp = a[0];
	for (int i = 1; i < n - 1; i++) {
		if (a[i] > 0) {
			process.emplace_back(tmp, a[i]);
			tmp -= a[i];
		} else {
			process.emplace_back(ans, a[i]);
			ans -= a[i];
		}
	}
	process.emplace_back(ans, tmp);

	cout << ans - tmp << endl;
	for (int i = 0; i < process.size(); i++) {
		cout << process[i].first << " " << process[i].second << endl;
	}

	return 0;
}

Measured memory_bytes: 3188
a, b, k = map(int, input().split())

for i in range(k):
	if i % 2 == 0:
		if a % 2 == 1:
			a -= 1
		b += a//2
		a = a//2
	else:
		if b % 2 == 1:
			b -= 1
		a += b//2
		b = b//2

print(a,b)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mxn 19
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using  namespace std;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	ll n,i;
	cin>>n;
	ll a[n],s=0,ans=0;
	for(i=0;i<n;i++){
		cin>>a[i];
		ans+=(s*a[i]);
		ans%=mod;
		s+=a[i];
		s%=mod;
	}
	cout<<ans;
}


Measured memory_bytes: 5172
#include <stdio.h>
int main(){
	int a,b,c,d,e;
	int f;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	if(a<=40){
		a=40;
	}
	if(b<=40){
		b=40;
	}
	if(c<=40){
		c=40;
	}
	if(d<=40){
		d=40;
	}
	if(e<=40){
		e=40;
	}
	f=(a+b+c+d+e)/5;
	printf("%d\n",f);
	return 0;
}


Measured memory_bytes: 2060
cnt = 0

def insertionSort(A, n, g):
    global cnt
    for i in xrange(g, n):
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v


def shellSort(A, n):
    G = [1]
    while G[-1]*3+1 < n:
        G.append(G[-1]*3 + 1)

    for i in xrange(len(G)-1, -1, -1):
        insertionSort(A, n, G[i])

    G.reverse()

    print len(G)
    print " ".join(map(str, G))
    print cnt


N = int(raw_input())
L = [int(raw_input()) for i in xrange(N)]

shellSort(L, N)


for i in L:
    print i

Measured memory_bytes: 38028
var
    a,b,len,i: Integer;
    s:String;

begin
    readln(a,b);
    len:=a+b+1;
    readln(s);
    if s[a+1]<>'-' then
    begin
        writeln('No');
        readln;
        exit;
    end;
    for i := 1 to a do
    begin
        if not ((s[i]>='0') and (s[i]<='9')) then
        begin
            writeln('No');
            readln;
            exit;
        end;
    end; 
    for i := a+2 to len do 
    begin
        if not ((s[i]>='0') and (s[i]<='9')) then
        begin
            writeln('No');
            readln;
            exit;
        end;
    end;
    writeln('Yes');
    readln;
end.

Measured memory_bytes: 128
//============================================================================
// Name        : template.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a;
	cin >> a;
	cout << (a + pow(a, 2) + pow(a, 3)) << endl;
	return 0;
}


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

const long long MAX = 10000000;  // TLEならば小さくする
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {

	ll x, y; cin >> x >> y;
	if ((x + y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
    ll  m = (2 * x - y) / 3;
    ll n = (-x + 2 * y) / 3;
    COMinit(); // 前処理
    cout << COM(m + n, m) << endl;
}

Measured memory_bytes: 238016
using System;
using System.Collections.Generic;
using System.Linq;

namespace codefestival_2016_final_d
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] remain = new int[x[1]];
			Dictionary<int, int>[] cards = new Dictionary<int, int>[x[1]];
			for (int i = 0; i < x[1]; i++) cards[i] = new Dictionary<int, int>();
			for (int i = 0; i < x[0]; i++)
			{
				int n = a[i] % x[1];
				remain[n]++;
				if (!cards[n].ContainsKey(a[i])) cards[n][a[i]] = 0;
				cards[n][a[i]]++;
			}
			int ret = 0;
			for (int i = 0; i < x[1]; i++)
			{
				int min = 0;
				if (i == 0 || i == x[1] - i)
				{
					min = remain[i] / 2;
				}
				else
				{
					min = Math.Min(remain[i], remain[x[1] - i]);
				}
				ret += min;
				remain[i] -= min; remain[(x[1] - i) % x[1]] -= min;
				int same = 0;
				foreach (var card in cards[i])
				{
					same += card.Value / 2;
				}
				ret += Math.Min(remain[i] / 2, same);
				remain[i] -= Math.Min(remain[i] / 2, same) * 2;
			}
			Console.WriteLine(ret);
		}
	}
}

Measured memory_bytes: 38716
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 200005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int arr[N];

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, k; cin>>n>>k;
    int ans = 0;
    For(i, k, n+2){
        int val = ((n+1-i)*i)+1;
        ans += val;
        ans %= MOD;
    }
    cout<<ans;
    return 0;
}





Measured memory_bytes: 3640
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

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

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

function Main(input) {

    const n = parseInt(input[0], 10);
    const v = input[1].split(' ').map(function(value) { return parseInt(value, 10); });
    const c = input[2].split(' ').map(function(value) { return parseInt(value, 10); });

    let ans = 0;
    for (let i = 0; i < n; i++) {
        if (v[i] > c[i]) {
            ans += (v[i] - c[i]);
        }
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 7500
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,r;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n;
    vl v(n);cin>>v;
    vl a(n,0);
    a[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;i++)a[i]=min(a[i-1]+abs(v[i]-v[i-1]),a[i-2]+abs(v[i]-v[i-2]));
    cout<<a[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9+5;

int main(){
    int n,k;
    cin>>n>>k;
    
    vector<int> dp(n+1,INF); //min cost to reach i dp[i].
    
    vector<int> h(n);
    for(int i=0; i<n; i++) cin>>h[i];
    
    dp[0]=0;
    
    for(int i=1; i<n; ++i){
        for(int j=i-1; j>=0; --j){
            if(i-j>k) break;
            dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
        }
        //cout<<dp[i]<<" ";
    }
    cout<<dp[n-1];
    
}

Measured memory_bytes: 3948
#include <iostream>

constexpr int INF = 1 << 25;

void solve() {
    int k;
    std::cin >> k;

    int p = 7 % k;
    for (int i = 1; i <= INF; ++i) {
        if (p == 0) {
            std::cout << i << "\n";
            return;
        }
        p = (p * 10 + 7) % k;
    }

    std::cout << -1 << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3656
# 解説AC(のつもり)
# 自力AC時、嘘解法だったのでやり直し
s = gets.chomp
t = gets.chomp
s_replace = {}
t_replace = {}
n = s.length
ok = true
for i in 0...n do
  if s_replace.include?(s[i])
    if s_replace[s[i]] != t[i]
      ok = false
      break
    end
  else
    s_replace[s[i]] = t[i]
  end
  if t_replace.include?(t[i])
    if t_replace[t[i]] != s[i]
      ok = false
      break
    end
  else
    t_replace[t[i]] = s[i]
  end
end
puts ok ? "Yes" : "No"


Measured memory_bytes: 2628
#include "bits/stdc++.h"
using namespace std;

int f(int x) {
	int c = 1;
	int sum = 0;
	int ret = 0;
	while(sum <= x) {
		sum += c;
		c++;
	}
	c--;
	return c - 1;
}

int main()
{ 
	long long int n;
	cin >> n;
	int ans = 0;
	for(int j = 2; j <= (int) sqrt(n); j++) {
		if(n % j) continue;
		int cnt = 0;
		while(n % j == 0) cnt++ , n /= j;
		ans += f(cnt);
	}
	if(n != 1) ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    vector<int> a(5);
    REP(i,5) cin >> a[i];
    int k; cin >> k;
    REP(i,5) {
        for (int j = i+1; j < 5; ++j) {
            if (a[j]-a[i] > k) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

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

string add_root(string root, string direct, int count) {
  for (int i = 0; i < count; i++) {
    root = root + direct;
  }
  return root;
}


int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  string r;
  r = add_root(r, "R", dx);
  r = add_root(r, "U", dy);
  r = add_root(r, "L", dx);
  r = add_root(r, "D", dy + 1);
  r = add_root(r, "R", dx + 1);
  r = add_root(r, "U", dy + 1);
  r = add_root(r, "L", 1);
  r = add_root(r, "U", 1);
  r = add_root(r, "L", dx + 1);
  r = add_root(r, "D", dy + 1);
  r = add_root(r, "R", 1);
  
  cout << r << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

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

    cout << a*b/2 << endl;
    return 0;
}

Measured memory_bytes: 256
s=list(list(input())[::-1])
t=list(list(input())[::-1])
s_len=len(s)
t_len=len(t)
for i in range(s_len-t_len+1):
    for j in range(t_len):
        if s[i+j]!="?" and t[j]!=s[i+j]:
            break
    else:
        s[i:i+t_len]=t 
        for k in range(s_len):
            if s[k]=="?":
                s[k]="a"
        print("".join(s[::-1]))
        exit()
print("UNRESTORABLE")

Measured memory_bytes: 9140
#include<iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if (a+b>=c)
	 cout<<"Yes"<<endl;
	 else
	 cout<<"No"<<endl;
	
}

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

public class Main {
    public static void main(String[] args) throws IOException{
        abc042a();
        //abc042b();
        //abc042c();        
    }
    public static void abc042a() throws IOException{
        Scanner scan = new Scanner(System.in);
 
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        
        if(a*b*c == 175 && a+b+c == 17){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 10068
# include <bits/stdc++.h>
# define rr register
const int N=200010,INF=0x3f3f3f3f;
int cnt[N];
int n;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
int main(void){
	n=read();
	for(rr int i=1;i<n;++i){
		++cnt[read()];
	}
	for(rr int i=1;i<=n;++i){
		printf("%d\n",cnt[i]);
	}
	return 0;
}


Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int a[3] = {3,5,7};
vector<int> v,t;
void permute(int n){
	if(n >= 10) return;

	vector<int> temp;
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < int(t.size()); j++){
			v.push_back(t[j]*10 + a[i]);
			temp.push_back(t[j]*10 + a[i]); 
		}
	}
	t = temp;
	temp.clear();
	permute(n+1);
}
int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, r, x, count = 0;
	t.push_back(0);
	cin >> n;
	permute(1);
	
	for(int i = 0; i < (int)v.size(); i++){
		set<int> s;
		x = v[i];
		if(x <= n){
		while(x){
			r = x%10;
			x /= 10;
			s.insert(r);
		}
		if(s.size() == 3) count++;
		}
	}
	cout << count ;

}

Measured memory_bytes: 768
n = int(input())
s = input()

# west to east
num = 0
w2e = [0] * len(s)
prev = s[0]
for ix in range(1, len(s)):
    if prev == 'W':
        num += 1
        w2e[ix] = num
    else:
        w2e[ix] = num
    
    prev = s[ix]

# print("w2e", w2e)

# east to west
num = 0
e2w = [0] * len(s)
prev = s[len(s)-1]

for ix in range(len(s)-2, -1, -1):
    if prev == 'E':
        num += 1
        e2w[ix] = num
    else:
        e2w[ix] = num

    prev = s[ix]

# print("e2w", e2w)

# solve

minv = 2**32
for ix in range(0, n):
    cand = w2e[ix] + e2w[ix]
    if minv > cand:
        minv = cand

print(minv)


Measured memory_bytes: 17592
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<int> G[MAX_N];
int flag[MAX_N];
bool ok;

void dfs(int u,int k)
{
    flag[u] = k;
    if(ok){
        return;
    }
    rep(i,G[u].size()){
        if(flag[G[u][i]] == -1){
            dfs(G[u][i],k^1);
            if(ok){
                return;
            }
        }else if(flag[G[u][i]] == k){
            ok = true;
            return;
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        G[a-1].pb(b-1),G[b-1].pb(a-1);
    }
    rep(i,n){
        flag[i] = -1;
    }
    ok = false;
    dfs(0,0);
    ll zero = 0,one = 0;
    rep(i,n){
        if(flag[i] == 0){
            zero++;
        }else{
            one++;
        }
    }
    if(ok){
        cout << (ll)n*(n-1)/2 - m << endl;
    }else{
        cout << zero*one - m << endl;
    }
    return 0;
}


Measured memory_bytes: 6528
import sys
n, y = map(int, input().split())
a = y//10000
b = (y-a*10000)//5000
c = (y-a*10000-b*5000)//1000
if not (a+b+c<=n<=y//1000):
    print(-1, -1, -1)
    sys.exit()
for i in range(a, -1, -1):
    for j in range(b+2*(a-i), -1, -1):
        k = (y-i*10000-j*5000)//1000
        if n==i+j+k:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Measured memory_bytes: 3064
//
//  main.c
//  procon
//
//  Created by Lee, Chanyeong | Naru | MSDD on 2017. 10. 16..
//  Copyright © 2017년 Lee, Chanyeong | Naru | MSDD. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int a;
    scanf("%d", &a);
//    printf("%d", a);
    int calculate = 1;
    
    int i = 0;
    while (calculate <= a) {
        calculate *= 2;
    }
    
    printf("%d", calculate/2);
    
    return 0;
}


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

using namespace std;

int64_t modpow(int64_t a, int64_t b, int64_t MOD) {
	int64_t ret = 1;
	while (b > 0) {
		if (b & 1) { (ret *= a) %= MOD; }
		(a *= a) %= MOD;
		b >>= 1;
	}
	return ret % MOD;
}

int main() {
	constexpr Int MOD = 1e9 + 7;
	Int N, K;
	cin >> N >> K;

	vector<Int> sum(K + 1, 0);
	for (Int i = K; i > 0; --i) {
		sum[i] = modpow(K / i, N, MOD);
		for (Int j = i + i; j <= K; j += i) {
			sum[i] = (sum[i] - sum[j] + MOD) % MOD;
		}
	}

	Int ans = 0;
	for (Int i = 1; i <= K; ++i) {
		(ans += i * sum[i]) %= MOD;
	}
	cout << ans % MOD << endl;

	return 0;
}


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

int main(){
	long long n;
	cin >> n;
	int ans=0;
	for(long long i=2;i*i<=n;i++)
      if(n%i==0){
		int cnt=0;
		while(n%i==0)n/=i,cnt++;
		for(int j=1;j<=cnt;j++){
			cnt-=j;
			ans++;
		}
	}
	if(n!=1)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 3656
program kadai
implicit none
integer  ::  n,x,i,ans,d
integer,allocatable  ::  l(:)

read(*,*) n,x
allocate(l(n))
read(*,*) l

ans=1
d=0
do i=1,n
    if(d+l(i)>x) then
        write(*,*) ans
        stop
    end if
    d=d+l(i)
    ans=ans+1
end do
write(*,*) ans

end program kadai

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

int main(){
    int N, L;
    string buf;
    priority_queue<string, vector<string>, greater<string>> S;
    cin >> N >> L;
    for(int i = 0; i < N; ++i){
        cin >> buf;
        S.push(buf);
    }
    while(!S.empty()){
        cout << S.top();
        S.pop();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
#include <iostream>
#include <map>
#include <vector>
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  map<int, int> mp;
  ll ans = 0;
  int a;
  FOR(i, N) {
    cin >> a;
    mp[a] += 1;
    ans += a;
  }

  int Q;
  cin >> Q;
  FOR(i, Q) {
    ll b, c;
    cin >> b >> c;
    // cがmp[b]個増え、bがmp[b]個減る
    ans += c * mp[b] - b * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    /*
    for (auto e : mp) {
      cout << "\t" << e.first << " " << e.second << endl;
    }
    */
    cout << ans << "\n";
  }

  return 0;
}

Measured memory_bytes: 8004
/*#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define PI 3.1415926535897932
 
using namespace std;

int main () {
	double a, b, c;
	scanf ("%lf%lf%lf", &a, &b, &c);
	c /= a;
	bool flag = c > (a * b * 0.5);
	if (flag) c = (a * b - c);
	double k = c * 2.0 / b;
	double ret = atan (k / b);
	ret *= 360;
	ret /= (PI * 2.0);
	printf ("%.6lf\n", ret);
	return 0;
}*/
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define PI 3.1415926535897932
#define ld long double
 
using namespace std;
 
inline ld calc (ld a, ld b, ld c, ld v) {
	v /= a;
	ld d = (v * 2.0 / c);
	ld ret = atan (c / d);
	ret *= 360;
	ret /= (2 * PI);
	return ret;
}

inline void calc2 (ld a, ld b, ld c) {
	c /= a;
	c = a * b - c;
	double d = c * 2.0 / a;
	double ret = atan (d / a);
	ret *= 360;
	ret /= (2 * PI);
	printf ("%.7lf\n", ret);
}

int main () {
	ld a, b, c;
	cin >> a >> b >> c;
	if (c > a * a * b * 0.5){
		calc2 (a, b, c);
		return 0;
	}
	ld ans = calc (a, a, b, c);
	double tmp = ans;
	printf ("%.7lf\n", tmp);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define ll long long
#define int long long
#define ld long double
#define pii pair <int , int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const int maxn = 3000 + 10 , N = 1e5 + 5 , SQ = 600 , base = 1999 , mod = 1e9 + 7 , INF = 1e18 , lg = 17;

int dp[maxn][maxn] , c1 , c2;
pii par[maxn][maxn];
string s , t;

int32_t main() {
    FAST
    cin >> s >> t;
    c1 = s.size() , c2 = t.size();

    for (int i = 1; i <= c1; ++i) {
        for (int j = 1; j <= c2; ++j) {
            if(s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                par[i][j] =  {i - 1 , j - 1};
            }
            if(dp[i - 1][j] > dp[i][j]) {
                dp[i][j] = dp[i - 1][j];
                par[i][j] = {i - 1 , j};
            }
            if(dp[i][j - 1] > dp[i][j]) {
                dp[i][j] = dp[i][j - 1];
                par[i][j] = {i , j - 1};
            }
        }
    }

    string ans = "";

    while(c1 && c2) {
        int x = par[c1][c2].F , y = par[c1][c2].S;
        if(s[c1 - 1] == t[c2 - 1]) {
            ans += s[c1 - 1];
        }
        c1 = x , c2 = y;
    }

    reverse(ans.begin() , ans.end());
    cout << ans << '\n';
 }


Measured memory_bytes: 215168