akhauriyash/Code-Regression huggingface dataset:
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <time.h>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

int main(){
	int n;
	cin >> n;
	vector<P> da(n);
	rip(i,n,0) {
		int x,l;
		cin >> x >> l;
		da[i] = mpa(x+l,x-l);
	}
	sort(all(da));
	int ans = 1, fo = da[0].first;
	rip(i,n,0){
		if(fo <= da[i].second){
			ans ++;
			fo = da[i].first;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string input;
	cin >> input;
	int len = input.size();
	int num = pow(2, len - 1);
	vector<int> mask(len - 1);
	lint ans = 0;
	if (len == 1)
	{
		cout << input << endl;
		return;
	}
	for (int i = 0; i < len - 1; i++)
	{
		mask[i] = pow(2, i);
	}
	//cout << num << endl;
	for (int i = 0; i < num; i++)
	{
		int right = len - 1;
		for (int j = len - 1; 0 <= j; j--)
		{
			if (i & mask[j])
			{
				right = j;
			}
			//cout << (input[j] - '0') * (lint)(pow(10, right - j) + 0.1) << " " << right << " " << j << endl;
			ans += (input[j] - '0') * (lint)(pow(10, right - j) + 0.1);
		}
	}

	cout << ans << endl;

	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
integer N
integer,allocatable,dimension(:)::A
integer ans
read*,N
allocate(A(N))
read*,A

ans=A(1)
do i=2,N
  ans=gcd(ans,a(i))
end do

print"(i0)",ans

contains

pure function gcd(a,b)
integer,intent(in)::a,b
integer gcd
integer s,t
s=a
gcd=b

t=mod(s,gcd)
do while(t/=0)
  s=gcd
  gcd=t
  t=mod(s,gcd)
end do
end function gcd
end

Measured memory_bytes: 1152
for(map$q[$_]+=$q[$N]/@$N,@{/ /,push@
$`,$' for<>;++$N}for++$q[1]..<>;--$N;$a<($~=$q[$N]*($b-1-$_)/($#@||1))or$a=$~for@@){$b=1;$e[$N]=$b+=$_/@@for@@=@e[@$N]}print$a+$b

Measured memory_bytes: 108372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 

ll mod = 1000000007;

ll mmul(ll a, ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

ll mpow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll d = mpow(a, b / 2);
		return (d * d) % mod;
	}
	return (a * mpow(a, b - 1)) % mod;
}

ll mdiv(ll a, ll b) {
	return mmul(a, mpow(b, mod - 2));
}

int main()
{
    in(n);
    in(k);
    repin(a,n);
    ll ans = 0;
    rep(i,n){
        for(ll j = 0;j<i;j++){
            if(a[i]>a[j]){
                ans = ans%mod + mdiv(mmul(k-1,k),2);
            }
        }
        if(i+1>=n)continue;
        for(ll j = i+1;j<n;j++){
            if(a[i]>a[j]){
                ans = ans%mod + mdiv(mmul(k,k+1),2);
            }
        }
    }
    out(ans%mod);
}

Measured memory_bytes: 256
INF = 1e9

def width(r1, r2)
  r1 + r2 + Math::sqrt((r1 + r2) ** 2 - (r1 - r2).abs ** 2)
end

while list = gets
  box, *r = list.split.map(&:to_f)

  n = r.size
  all = (1 << n) - 1

  dp = Array.new(1 << n){Array.new(n, INF)}
  n.times do |i| dp[1 << i][i] = 2.0 * r[i] end
  (1 << n).times do |bit|
    n.times do |from|
      next if dp[bit][from] == INF
      n.times do |to|
        next if bit[to] == 1
        cost = dp[bit][from] - 2.0 * r[from] + width(r[from], r[to])
        next_bit = bit | (1 << to)
        dp[next_bit][to] = [dp[next_bit][to], cost].min
      end
    end
  end

  puts (dp[all].any?{|d| d <= box} ? "OK" : "NA")
end

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

int main() {
    string S; cin >> S;
    string ans = "Yes";
    auto s = S.begin();
    while (s != S.end())
    {
        if (*s == 'L') ans = "No";
        if (++s == S.end()) break;
        if (*s == 'R') ans = "No";
        s++;
    }
    cout << ans << endl;
}

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

signed main(){

    string s;
    s = s + "z";
    int k;
    cin >> s >> k;
    int len = 0;
    char num;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1') len++;
        else{
            num = s[i];
            break;
        }
    }

    if(len >= k) cout << 1 << endl;
    else cout << num << endl;
    return 0;
}

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;

int cnt = 0;
int n, m;
vector<int> graph[10];

void dfs(int visited[], int now, int num_visited)
{
    if (num_visited == n)
    {
        cnt++;
        return;
    }
    for (auto next : graph[now])
    {
        if (visited[next] == 1) continue;
        visited[next] = 1;
        dfs(visited, next, num_visited + 1);
        visited[next] = 0;
    }
}

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

    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    int visited[n];
    rep(i, n) visited[i] = 0;
    visited[0] = 1;
    dfs(visited, 0, 1);

    cout << cnt << endl;
    return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n;cin>>n;

	int now=1;
	int ct=0;
	for(int i=0; i<n; i++){
		int tmp=0;cin>>tmp;

		if(tmp==now){
			ct++;
			now++;
		}
	}
	if(ct==0){writeln(-1);return 0;}

	writeln(n-ct);

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int in;
    cin >> in;
    mp[in]++;
  }

  int ans = 0, e = 0;
  for(auto p : mp){
    if(p.second > 1){
      int tmp = p.second % 2;
      tmp = 2 - tmp;
      ans += p.second - tmp;
      if(tmp % 2 == 0){
        e++;
      }
    }
  }
  ans += (e+1)/2*2;
  cout << n-ans << endl;
  return 0;
}

Measured memory_bytes: 8168
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){
  int a,b,c,sum;
  while(1){
    cin >> a >> b >> c;
    if(a==-1 && b==-1 && c==-1) break;
    sum = a+b;
    if(a==-1 || b==-1){
      printf("F\n");
    }else if(sum >= 80){
      printf("A\n");
    }else if(sum >= 65 && sum < 80){
      printf("B\n");
    }else if(sum >= 50 && sum < 65){
      printf("C\n");
    }else if(sum >= 30 && sum < 50){
      if(c >= 50){
        printf("C\n");
      }else{
        printf("D\n");
      }
    }else{
      printf("F\n");
    }
  }
  return 0;
}



Measured memory_bytes: 3084
from numpy import*
h,*s=open(0)
h,w=int32(h.split())
s=int32([[u>'#'for u in t]for t in s])
a,b,c,d=eval('copy(s),'*4)
for i in range(w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in range(1,h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(amax(a+b+c+d)-3)

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

//#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 4005;
int n;
ll res, acu[256][MX];
string s;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> s;

	forn (i, n) {
		acu[s[i]][i] = 1;
		if (i) {
			acu['R'][i] += acu['R'][i - 1];
			acu['G'][i] += acu['G'][i - 1];
			acu['B'][i] += acu['B'][i - 1];
		}
	}

	forn (i, n) forr (j, i + 2, n - 1)
		if (s[i] != s[j]) {
			if ('R' != s[i] && 'R' != s[j]) {
				res += acu['R'][j] - acu['R'][i];
				if ((j - i) % 2 == 0 && s[(i + j) / 2] == 'R')
					res--;
			} else if ('G' != s[i] && 'G' != s[j]) {
				res += acu['G'][j] - acu['G'][i];
				if ((j - i) % 2 == 0 && s[(i + j) / 2] == 'G')
					res--;
			} else {
				res += acu['B'][j] - acu['B'][i];
				if ((j - i) % 2 == 0 && s[(i + j) / 2] == 'B')
					res--;
			}
		}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3744
# import bisect
from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    s = input()
    len_s = len(s)
    cnt = Counter(s)
    a_num = cnt["a"]
    b_num = cnt["b"]
    c_num = cnt["c"]

    least = min(a_num, b_num, c_num)

    if a_num - least <= 1 and b_num - least <= 1 and c_num - least <= 1:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 40048
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(has9(s));
    }
    
    public static String has9(String s) {
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == '9') {
                return "Yes";
            }
        }
        return "No";
    }
}


Measured memory_bytes: 21844
import math

N = int(input())

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,int(math.sqrt(N))+1):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)


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

int main(){
    long N;
    cin >> N;
    long A[N];
    for(long i = 0; i < N; i++) cin >> A[i];
    sort(A, A + N);
    bool C[1000001];
    fill(C, C + 1000001, false);
    for(long i = 0; i < N; i++){
        if(C[A[i]]) continue;
        if(i < N - 1 && A[i] == A[i + 1]) C[A[i]] = true;
        for(long j = 2; j * A[i] <= 1000000; j++){
            if(!C[j * A[i]]) C[j * A[i]] = true;
        }
    }
    long ans = 0;
    for(long i = 0; i < N; i++)
        if(!C[A[i]]) ans++;
    cout << ans << endl;
    return 0;
}

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;
#define int ll
// template ends here

int f(int N){
	int cnt, ans = 1;
	vector<int> po;
	for(int i = 2; i*i <= N; i++){
		if(N%i != 0) continue;
		cnt = 0;
		while(N%i == 0){
			cnt++;
			N /= i;
		}
		ans *= (cnt+1);
	}
	if(N != 1) ans *= 2;
	return ans;
}

void solve(){
	// code starts from here
	int N;
	cin >> N;
	int ans = 0;
	for(int c =1 ; c <= N; c++){
		ans += f(N-c);
	}
	cout << ans-2 << endl;
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

signed main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	startTime = clock();
	
	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}
	
	//cout << getCurrentTime() << endl;
	return 0;
}


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

using namespace std;

int count_char(string s,char x) {
    int count;
    for (auto c : s) {
        if ( c == x ) {
            count++;
        }
    }
    return count;
}

int main(){
    string s;
    cin >> s;
    cout << count_char(s,'2') << endl;
}


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

int main() {
  long long a=0,b=0,c=0,d=0,m=0,n=0,p=0,q=0;
  
  cin >> a;

  if(a>=30)
  {
     cout << "Yes";
  }
  else
  {
     cout << "No";
  }
  
 
	  
  
}


Measured memory_bytes: 3672
# ABC136B - Uneven Numbers
def main():
    n = int(input())
    d = len(str(n))
    if d == 6:
        ans = 9 + 900 + 90000
    elif d == 5:
        ans = 9 + 900 + n - 9999
    elif d == 4:
        ans = 9 + 900
    elif d == 3:
        ans = 9 + n - 99
    elif d == 2:
        ans = 9
    elif d == 1:
        ans = n
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
#define favorite 753

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

	int ans = INT_MAX;

	for(int i = 0; i < s.size() - 2; i++) {
		int num = stoi(s.substr(i, 3));
		ans = min(abs(num - favorite), ans);
	}

	cout << ans << endl;
}


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

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

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

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

void z_alg(string s, vll &v) {
	ll n = s.size();

	v[0] = n;
	ll i = 1, j = 0;
	while (i < n) {
		while (i + j < n && s[j] == s[i + j]) j++;
		v[i] = j;
		if (j == 0) {
			i++;
			continue;
		}
		ll k = 1;
		while (i + k < n && k + v[k] < j) {
			v[i + k] = v[k];
			k++;
		}
		i += k;
		j -= k;
	}
}

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

	ll n;
	string s;
	cin >> n >> s;

	vector<vll> v(n);
	for (ll i = 0; i < n; i++) {
		v[i].resize(n - i);
		string t = s.substr(i);
		z_alg(t, v[i]);
	}

	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n - i; j++) {
			ll x = min(j, v[i][j]);
			ans = max(ans, x);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 98176
#include <stdio.h>

int main() {
	int a, b, c, tmp, cnt;

	scanf("%d%d%d", &a, &b, &c);
	if (a > b)
		tmp = a, a = b, b = tmp;
	if (a > c)
		tmp = a, a = c, c = tmp;
	if (b > c)
		tmp = b, b = c, c = tmp;
	cnt = c - b;
	a += cnt;
	cnt += (c - a + 1) / 2;
	if ((c - a) % 2)
		cnt++;
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
def main():
    R,G,B,N=map(int,input().split())
    cnt=0
    for i in range(N//R+1):
        cnt+=sum([1 for j in range((N-i*R)//G+1) if i*R + j*G +((N-i*R-j*G)//B)*B==N])
    print(cnt)

main()

Measured memory_bytes: 3060
import java.util.*;

import static java.lang.Math.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int a = sc.nextInt();
        int v = sc.nextInt();
        int b = sc.nextInt();
        int w = sc.nextInt();
        int t = sc.nextInt();

        if (w >= v) {
            System.out.println("NO");
            return;
        }

        if (abs(a - b) / (double) t <= (double) abs(v - w)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 35760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solve(new Scanner(System.in));
	}
	
	public void solve(Scanner sc) {
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		
		if(n%2==1) n++;
		
		if(n/2 >= k) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#include <queue>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

const int inf = 1e9;
int n, m;
int pos[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
char mat[1005][1005];
int dist[1005][1005];

bool isValid(int x, int y)
{
	if(x < n && x >= 0 && y < m && y >= 0)
		return true;
	return false;
}

int main()
{
	FASTIO

	cin >> n >> m;
	
	int sx, sy;
	cin >> sx >> sy;
	sx --;
	sy --;

	int dx, dy;
	cin >> dx >> dy;
	dx --;
	dy --;

	for(int i = 0; i < n; i ++)
	{
		for(int j = 0; j < m; j ++)
			cin >> mat[i][j];
	}	

	for(int i = 0; i < n; i ++)
	{
		for(int j = 0; j < m; j ++)
			dist[i][j] = inf;
	}

	deque <pair<int, int>> q;
	if(mat[sx][sy] == '.')
	{
		q.push_front({sx, sy});
		dist[sx][sy] = 0;
	}

	while(! q.empty())
	{
		int curX = q.front().first;
		int curY = q.front().second;

		// debug2(curX, curY);
		q.pop_front();

		for(int i = 0; i < 4; i ++)
		{
			int newX = curX + pos[i][0];
			int newY = curY + pos[i][1];

			if(isValid(newX, newY) && mat[newX][newY] == '.')
			{
				if(dist[newX][newY] > dist[curX][curY])
				{
					dist[newX][newY] = dist[curX][curY];
					q.push_front({newX, newY});
				}
			}
		}

		for(int i = curX - 2; i <= curX + 2; i ++)
		{
			for(int j = curY - 2; j <= curY + 2; j ++)
			{
				if(isValid(i, j) && mat[i][j] == '.')
				{
					if(dist[i][j] > dist[curX][curY] + 1)
					{
						dist[i][j] = dist[curX][curY] + 1;
						q.push_back({i, j});
					}
				}
			}
		}
	}

	// for(int i = 0; i < n; i ++)
	// {
		// for(int j = 0; j < m; j ++)
			// cout << dist[i][j] << " ";
		// cout << endl;
	// }
	if(dist[dx][dy] == inf)
		cout << "-1" << endl;
	else
		cout << dist[dx][dy] << endl;
}

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

bool isOK(ll a, ll b, ll c){
    return (a+b > c && b+c >a && c+a > b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<ll> l(n); rep(i,n) cin >> l[i];
    ll ans = 0LL;
    for(int i = 0; i < n-2; ++i){
        for(int j = i+1; j < n-1; ++j){
            for(int k = j+1; k < n; ++k){
                if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
                if(isOK(l[i], l[j], l[k])) ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int n;
int is_in[200005] = {};

int count(int k) {
	int cnt = 0;
	// k+1の倍数で今まで入ったものをカウント
	for (int i = 2*k; i <= n; i+=k) {
		cnt += is_in[i];
		// if (is_in[i]) {
		// 	cnt++;
		// }
	}
	return cnt;
}
int main(){
	cin >>n;
	int A[200005] = {};
	

	rep(i,n){
		cin >> A[i+1];
	}

	int cnt = 0;
	for (int i = n; i>=1; i--) {
		is_in[i] = int(A[i] != count(i)%2);
		cnt += is_in[i];
		// if (A[i]) {
		// 	if (count(i)%2==0) {
		// 		is_in[i] = 1;
		// 		cnt++;
		// 	}
		// } else {
		// 	if (count(i)%2==1) {
		// 		is_in[i] = 1;
		// 		cnt++;
		// 	}
		// }
	}

	cout << cnt << endl;
	FOR(i,1,n+1) {
		if (is_in[i]) {
			cout << i << endl;
		}
	}
}

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

using namespace std;

#define INF (1<<29)

struct State {
    int c, x, y;
    
    State (int c, int x, int y) : c(c), x(x), y(y) {}

    bool operator < (const State &s) const {
        return c > s.c;
    }
};

int main()
{
    int R;
    while (cin >> R, R) {
        int W, H, sy, sx;
        vector<int> level[2];
        for (int i = 0; i < 2; i++) {
            cin >> W >> H >> sx >> sy;
            sy--; sx--;
            vector<vector<int>> a(H, vector<int>(W));
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    cin >> a[i][j];
                }
            }

            vector<vector<bool>> visited(H, vector<bool>(W, 0));
            visited[sy][sx] = 1;
            
            priority_queue<State> pq;
            pq.push(State(a[sy][sx], sx, sy));

            level[i].push_back(0);

            const int dx[] = {-1, +0, +1, +0};
            const int dy[] = {+0, -1, +0, +1};
            int maxi = 0;
            
            while (!pq.empty()) {
                State st = pq.top(); pq.pop();
                level[i].push_back(max(maxi, st.c));
                maxi = max(maxi, st.c);
                for (int j = 0; j < 4; j++) {
                    int nx = st.x + dx[j];
                    int ny = st.y + dy[j];
                    if (0 <= nx && nx < W && 0 <= ny && ny < H &&
                        !visited[ny][nx]) {
                        visited[ny][nx] = 1;
                        pq.push(State(a[ny][nx], nx, ny));
                    }
                }
            }
        }
        
        int res = INF;
        for (int i = 0; i <= R; i++) {
            int j = R - i;
            if ((int)level[0].size() <= i) continue;
            if ((int)level[1].size() <= j) continue;
            res = min(res, level[0][i] + level[1][j]);
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 7056
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	string a;
	ll k;
	cin>>a;
	cin>>k;
	ll len=a.size();
	if(len==1){
		cout<<k/2<<endl;
		return 0;
	}
	if(a[0]!=a[len-1]){
		ll cnt=0;
		for(int i=0;i+1<len;){
			if(a[i]==a[i+1]){
				cnt++;
				i+=2;
			}
			else{
				i++;
			}
		}
		cnt=k*cnt;
		cout<<cnt<<endl;		
	}
	else{
		ll cnt=0;
		ll d=0,d1=0,d2=0,i,j;
		char ss=a[0];
		for(i=0;a[i]==ss&&i<len;i++) d1++;
		for(j=len-1;a[j]==ss&&j>=0;j--) d2++;
		d=d1+d2;
		if(d==len*2){
			cnt=(d/2)*k;
			cout<<cnt/2<<endl;
			return 0;
		}
		if(d%2==0){
			for(int y=i;y+1<=j;y++){
				if(a[i]==a[i+1]){
					cnt++;
					y+=2;
				}
				else{
					y++;
				}				
			}
			cnt=cnt*k;
			cnt+=(d/2)*(k-1);
			cnt+=d1/2+d2/2;
			cout<<cnt<<endl;
		}else{
			for(int x=0;x+1<len;){
				if(a[x]==a[x+1]){
					cnt++;
					x+=2;
				}
				else{
					x++;
				}
			}
			cnt=k*cnt;
			cout<<cnt<<endl;		
		}
	}
	return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if((a==1 && b==2) || (a==2 && b==1)) cout << 3;
  else if((a==2 && b==3) || (a==3 && b==2)) cout << 1;
  else cout << 2;
  cout << endl;
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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


int main()
{
  int X;
  cin >> X;
  cout << lcm(360,X)/X << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    //blue input
    vector<string> blue(N);
    for(int i = 0; i < N; i++){
        cin >> blue.at(i);
    }
    int M;
    cin >> M;
    //red input
    vector<string> red(M);
    for(int i = 0; i < M; i++){
        cin >> red.at(i);
    }
    //counter
    vector<int> count(N);
    for(int i = 0; i < N ; i++){
        string a;
        a = blue.at(i);
        for(int n = 0; n < N; n++){
            if(a == blue.at(n)){
                count.at(i) += 1;
            }
        }
        for(int n = 0; n < M; n++){
            if(a == red.at(n)){
                count.at(i) -=1;
            }
        }
    }
    //max
    int ans;
    ans = count.at(0);
    for(int i = 0; i < N; i++){
        if(ans < count.at(i)){
            ans = count.at(i);
        }
    }
    if(ans < 0){
        ans = 0;
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    int S[13] = {}, H[13] = {}, C[13] = {}, D[13] = {};
    int temp;
    char tempS;

    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> tempS >> temp;

        switch(tempS){
            case 'S':
                S[temp-1] = 1;
                break;
            case 'H':
                H[temp-1] = 1;
                break;
            case 'C':
                C[temp-1] = 1;
                break;
            case 'D':
                D[temp-1] = 1;
                break;
        }
    }
    
    for(int i = 0; i < 13; i++){if(S[i] == 0){cout << "S " << i + 1 << endl;}}
    for(int i = 0; i < 13; i++){if(H[i] == 0){cout << "H " << i + 1 << endl;}}
    for(int i = 0; i < 13; i++){if(C[i] == 0){cout << "C " << i + 1 << endl;}}
    for(int i = 0; i < 13; i++){if(D[i] == 0){cout << "D " << i + 1 << endl;}}        
}



Measured memory_bytes: 3092
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,y ;
  cin >> n >> y ;  
  int res10000 = -1, res5000 = -1, res1000 = -1;
  
  for(int i=0;i<=n;i++){
    for(int j=0;j+i<=n;j++){
      int k = n-i-j;
        if(10000*i+5000*j+1000*k == y){
                res10000 = i;
                res5000 = j;
                res1000 = k;
        }
    }
  }
  
    // 答えを出力 (見つかっていなくても -1 -1 -1 になるので OK です)
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n;
  int count=0;
  int max=0;
  
  scanf("%d",&n);
  int ans=n;
  for(int i=1;i<=n;i++)
  {
    int tmp=i;
    //printf("%d\n",tmp);
    for(int j=0;j<i;j++)
    {
      if((tmp/2)!=0&&(tmp%2)==0){
        tmp=tmp/2;
        count++;
      }
      else{
        break;
      }
    }
    if(max<count){
      //printf("%d\n",count);
      max=count;
      ans=i;
    }
    count=0;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int c[100005];
int n,x,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>x,c[x]++;
	for(int i=0;i<=100000-2;i++) ans=max(ans,c[i]+c[i+1]+c[i+2]);
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 640
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <vector>
#include <string>
#include <queue>

using namespace std;

string s[33];

int vis[33][33];
int ans = 0;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

void calc(int sx, int sy, int mv) {
    queue <pair <int, pair<int, int> > > Q;
    Q.push(make_pair(1, make_pair(sx, sy)));
    while (!Q.empty()) {
        pair <int, pair <int, int> > p = Q.front();
        Q.pop();
        int x = p.second.first;
        int y = p.second.second;
        int nn = p.first;
        if (vis[x][y] == mv || s[x][y] == '#') {
            continue;
        }
        vis[x][y] = mv;
        ans = max(ans, nn);
        for (int i = 0; i < 4; i++) {
            Q.push(make_pair(nn + 1, make_pair(x + dx[i], y + dy[i])));
        }
    }

}

void solution() {
    int h, w;
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        cin >> s[i];
        s[i] = '#' + s[i] + '#';
    }
    s[0] = "#############################################################";
    s[h + 1] = s[0];
    int mv = 0;
    for (int sx = 1; sx <= h; sx++) {
        for (int sy = 1; sy <= w; sy++) {
            calc(sx, sy, ++mv);
        }
    }
    cout << --ans << endl;
}

/*-------------------*/

int main()
{
#ifdef Files
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    /*Test*/
    //freopen("input.txt", "w", stdout);

    double OcZ2X = clock();
#else
    //freopen("joke.in", "r", stdin);
    //freopen("joke.out", "w", stdout);
#endif

    solution();

#ifdef Time
    double P2HxQ = clock();
    printf("\n*** Total time = %.3f sec ***\n", (P2HxQ - OcZ2X) / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int []a = new int [3];
		
		int sum = 0;
		
		for(int i = 0 ; i < 3 ;i++) {
			a[i] = Integer.parseInt(sc.next());
			sum += a[i];
		}	
		
		
		String []s = new String [n];
		
		for(int i = 0 ; i < n ;i++) {
			s[i] = sc.next();
		}
		
		if(sum == 0) {
			System.out.println("No");
			return;
		}
		
		char []c = new char [n];
		
		for(int i = 0 ; i < n ;i++) {
			int p = s[i].charAt(0) - 'A';
			int q = s[i].charAt(1) - 'A';
			
			if(a[p] == 0 && a[q] == 0) {
				System.out.println("No");
				return;
			}
			
			else if(i != n-1 && a[p] == 1 && a[q] == 1) {
				int pn = s[i+1].charAt(0) - 'A';
				int qn = s[i+1].charAt(1) - 'A';
				if(p != pn && p != qn) {
					a[p]--;
					a[q]++;
					c[i] = (char)('A' + q);
				}
				else{
					a[p]++;
					a[q]--;
					c[i] = (char)('A' + p);
				}
			}
			
			else {
				if(a[p] >= a[q]) {
					a[p]--;
					a[q]++;
					c[i] = (char)('A' + q);
				}
				else {
					a[p]++;
					a[q]--;
				c[i] = (char)('A' + p);
				}
			}
		}
		
		System.out.println("Yes");
		for(int i = 0 ; i < n ;i++) {
			System.out.println(c[i]);
		}		
	
	}

}


Measured memory_bytes: 65364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void) {
	string s; cin >> s;
	string ans;
	rep(i, s.size()) if(i % 2 == 0) ans += s[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

int St[200005],Dr[200005],NewDr[200005],Seated[200005],Pax[200005]; //Pax-pers care sta pe scaun, Seated-daca sta pres pe un scaun
vector<int> Ind[200005];
priority_queue<pair<int,int> > Q;

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

    int n,m;
    cin>>n>>m;

    for(int i=1; i<=n; i++)
    {
        cin>>St[i]>>Dr[i];

        Ind[St[i]].push_back(i);
    }

    //pun prima data cele care o sa fie in partea stanga
    for(int i=m; i>=1; i--)
    {
        for(auto el:Ind[i])
            Q.push({Dr[el],el});

        if(!Q.empty())
        {
            Pax[i]=Q.top().second;
            Seated[Q.top().second]=1;
            Q.pop();
        }
    }

    //le pun cat mai la st posibil
    int ind=1;
    for(int i=1; i<=m; i++)
    {
        if(Pax[i])
        {
            Pax[ind]=Pax[i];

            if(ind!=i)
                Pax[i]=0;

            ind++;
        }
    }

    //le pun pe cele din dreapta
    ind=0;
    for(int i=1; i<=n; i++)
    {
        if(!Seated[i])
            NewDr[++ind]=Dr[i];
    }

    sort(NewDr+1,NewDr+ind+1);

    int poz=1;
    int rez=0;
    for(int i=1; i<=ind; i++)
    {
        poz=max(poz,NewDr[i]);

        while(poz<=m && Pax[poz])
            poz++;

        if(poz==m+1)
            rez++;
        else
            poz++;
    }

    cout<<rez<<"\n";
    return 0;
}


Measured memory_bytes: 13300
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int n,m ;cin>>n>>m;
  int l1,r1,l2,r2;
  if(m&1){
  	l1 = 1, r1 = m;
  	l2 = m+1, r2 = 2*m + 1;
  }
  else{
  	l1 = 1, r1 = m+1;
  	l2 = m+2, r2 = 2*m + 1;
  }
  while(l1<r1)
  	cout<<(l1++)<<" "<<(r1--)<<endl;
  while(l2<r2)
  	cout<<(l2++)<<" "<<(r2--)<<endl;
  return 0;
}

Measured memory_bytes: 3624
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        X: i64,
        Ms: [i64; N],
    }

    // まず全種類作る
    // その後に、できるだけ少ない材料で済むものをたくさん作る
    let mut rest = X;
    rest -= Ms.iter().sum::<i64>();
    let mut ans = N;

    let min_m: i64 = *Ms.iter().min().unwrap();

    ans += (rest / min_m) as usize;
    println!("{}", ans);
}


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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var M = int.Parse(inputs[1]);
        inputs = Console.ReadLine().Split(' ');
        var X = new int[M];
        for (int i = 0; i < M; i++)
        {
            X[i] = int.Parse(inputs[i]);
        }

        X = X.OrderBy(x => x).ToArray();
        var d = new int[M - 1];
        var sum = 0;
        for (int i = 0; i < d.Length; i++)
        {
            d[i] = Math.Abs(X[i + 1] - X[i]);
            sum += d[i];
        }


        d = d.OrderByDescending(dv => dv).ToArray();
        var maxLen = Math.Min(d.Length, N - 1);
        for (int i = 0; i < maxLen; i++)
        {
            sum -= d[i];
        }

        Console.WriteLine(sum);

    }


}



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

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define MAX_INT 2147483646


int main(void){
    // Your code here!
    int N,K;
    int h[200001],dp[200001];
    int i,j,tmp,tmpmin;
    
    scanf("%d %d",&N,&K);
    
    for(i=1;N>=i;i++){
        scanf("%d",&h[i]);
    }
    
    for(i=1;N>=i;i++){
        if(i==1){
            dp[i] = 0;
        }
        else if(i==2){
            dp[i] = abs(h[i]-h[i-1]);
        }
        else{
            
            tmpmin = MAX_INT;
            for(j=1;K>=j;j++){
                if(i-j<=0) break;
                tmp = dp[i-j] + abs(h[i]-h[i-j]);
                if(tmpmin > tmp) tmpmin = tmp;
            }
            dp[i] = tmpmin;
        }
    }
    
    printf("%d\n",dp[N]);
    
    return 0;   
}


Measured memory_bytes: 896
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%s" id

let () =
  if String.contains n '7' then
    Printf.printf "Yes\n"
  else Printf.printf "No\n"


Measured memory_bytes: 5344
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    // Here your code !
    double a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f) {
        double x = (c * e - b * f) / (a * e - b * d);
        double y = (a * f - c * d) / (a * e - b * d);
        x *= 1000; x = x + (x > 0 ? 0.5 : -0.5); x = (int)x;
        y *= 1000; y = y + (y > 0 ? 0.5 : -0.5); y = (int)y;
        //cout << %.3f %.3f\n << x / 1000 << y / 1000 << endl;
        cout << fixed << setprecision(3) << x /1000 << " " << y / 1000 <<endl;
    }
    return 0;
}

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

int main() {
	int N, k=0, min;
	string S;
	cin >> N >> S;
	for(int i=1;i<N;i++)if(S[i]=='E')k++;
	min = k;//i=0
	for(int i=1;i<N;i++){
		if(S[i-1]=='W')k++;
		if(S[i]=='E')k--;
		if(min>k)min=k;
	}
	cout << min << endl;
	return 0;
}
/*
<-W E->
*/

Measured memory_bytes: 900
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
v32 adj[LIM];
bool pos;
bool visited[LIM];
int col[LIM];

void dfs(int node){
	visited[node] = 1;
	forstl(r, adj[node]){
		if(visited[r]){
			if(col[r] == col[node]) pos = 0;
			continue;
		} 
		col[r] = 1 - col[node];
		dfs(r);
	}
}

int main(){
	fastio;

	cin>>n;
	forn(i,n){
		forn(j,n){
			char c; cin>>c;
			if(c == '1'){
				adj[i].pb(j);
			}
		}
	}

	pos = 1;
	dfs(0);
	if(!pos){
		cout<<-1<<ln;
		return 0;
	}

	int mxmx = 0;

	forn(k,n){
		int mx = 0;
		queue<int> q;
		q.push(k);
		int col[n] = {0};
		forn(i,n) col[i] = MOD;
		col[k] = 1;

		while(!q.empty()){
			int t = q.front();
			q.pop();
			forstl(r, adj[t]){
				if(col[r] != MOD) continue;
				col[r] = 1+col[t];
				q.push(r);
			}
		}
		forn(i,n) mx = max(mx, col[i]);
		mxmx = max(mxmx, mx);
	}

	
	cout<<mxmx<<ln;

	return 0;
}

Measured memory_bytes: 8488
#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 H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int h = H2-H1;
    int m = M2-M1;
    if(m < 0){
        m += 60;
        h--;
    }
    cout << h*60 + m - K << endl;
    return 0;
}

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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int	dp[1001][1001] = {};

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

	int maxl;

	string s1, s2;
	REP( i, n ) {
		cin >> s1 >> s2;
		s1 = ' ' + s1;
		s2 = ' ' + s2;
		maxl = 0;
		memset( dp, 0, sizeof( int ) );
		FOR( j, 1, s1.size() ) {
			FOR( k, 1, s2.size() ) {
				if( s1[j] == s2[k] ) {
					dp[j][k] = dp[j - 1][k - 1] + 1;
				} else {
					dp[j][k] = max( dp[j - 1][k], dp[j][k - 1] );
				}
				maxl = max( dp[j][k], maxl );
			}
		}

		cout << maxl << endl;
	}
}


Measured memory_bytes: 7108
#141d
from collections import deque
import bisect
import math

N,M = map(int, input().split()) #1≤N,M≤10^5
A_list = list(map(int, input().split()))

#→高額なものに割引券を使った方が良い
if len(A_list) > 1:
    A_list.sort(reverse=False)
    highest = A_list.pop()
    next_highest = A_list[-1]

    discounted_deque = deque()

    while 1:
        use_tickets = math.ceil(math.log(highest/next_highest)/math.log(2))
        if use_tickets == 0:
            use_tickets = 1
        elif use_tickets > M:
            use_tickets = M
            
        highest /= pow(2,use_tickets)
        M -= use_tickets
        
        if M!= 0:
            discounted_deque.appendleft(highest)
            
            if len(A_list) > 0:
                if A_list[-1] > discounted_deque[-1]:
                    highest = A_list.pop()
                else:
                    highest = discounted_deque.pop()
            else:
                highest = discounted_deque.pop()
                
            if len(A_list) > 0 and len(discounted_deque) > 0:
                if A_list[-1] > discounted_deque[-1]:
                    next_highest = A_list[-1]
                else:
                    next_highest = discounted_deque[-1]
            elif len(A_list) == 0 and len(discounted_deque) > 0:
                next_highest = discounted_deque[-1]
            elif len(A_list) > 0 and len(discounted_deque) == 0:
                next_highest = A_list[-1]
            
        else:
            A_list.append(highest)
            break

    A_list = [int(A) for A in A_list]
    discounted_list = [int(B) for B in discounted_deque]
    
    print(sum(A_list)+sum(discounted_list))
else:
    A_list[-1] = A_list[-1]//(pow(2,M))
    print(A_list[-1])


Measured memory_bytes: 92836
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;



void solve() {
	int a, b, c;
	cin >> a >> b >> c;

	cout << min(a * b, c) << endl;

}


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

	solve(); 
	return 0;
}

Measured memory_bytes: 256
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
 * ABC174 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
std::cout << std::setprecision(6) ;
cout << std::fixed;
ll mx=0;
ll l;
cin>>l;
double ans=(double)l/3;
ans=(double)ans*ans*ans;
cout<<ans;
}



/*
 * ||||


 */

Measured memory_bytes: 3784
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=1001;
vector<int> g[N*N];
int a[N][N];int in[N*N];
int col[N*N];
set<pair<int,int>> s;
set<int> av;
bool cyc=0;
int co(int i,int j)
{
  if(i>j)swap(i,j);
  return i*N+j;
}
void dfs(int node)
{
  col[node]=1;
  for(int u:g[node])
  {
    if(col[u]==0)
    {
      col[u]=1;dfs(u);
    }
    else if(col[u]==1){cyc=1;return;}
  }
  col[node]=2;
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif

  int n;
  cin>>n;
  int x,y;
  for(int i=1;i<=n;i++)
    for(int j=1;j<n;j++)
    {
      cin>>a[i][j];
    }

  for(int i=1;i<=n;i++)
    for(int j=1;j<n-1;j++)
    {

      int u=co(i,a[i][j]);
      int v=co(i,a[i][j+1]);
      if(s.find({u,v})!=s.end())continue;
      g[u].push_back(v);
     // if(v==co(1,2)){cout<<"here at i = "<<i<<" and j = "<<j<<"\n";}
      in[v]++;
      s.insert({u,v});
      av.insert(u);av.insert(v);
    }
    int ans=0;
    queue<int> q1,q2;
    for(auto i:av)if(in[i]==0)q2.push(i);
    for(auto i:av)
    {
      if(!cyc and col[i]==0)dfs(i);
    }
    if(cyc){puts("-1");return 0;}


   // cout<<in[co(3,4)]<<"\n";
    while(1)
    {
      q1=q2;
      while(!q2.empty())q2.pop();
      if(q1.empty())break;

      while(!q1.empty())
      {
        int x=q1.front();q1.pop();
        for(auto i:g[x])
        {
          in[i]--;
          if(in[i]==0)q2.push(i);
        }

      }
      ans++;
    }
    if(!ans)cout<<-1;
    else
    cout<<ans;



}

Measured memory_bytes: 150180