akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<pair<ll,ll>> v;
        multiset<ll> s[4];
        for(i =0 ; i < n; i++){
            ll x, y;
            cin >> x >> y;
            v.pb({ x, y});
            s[0].insert(x + y);
            s[1].insert(x - y);
            s[2].insert(-x + y);
            s[3].insert(-x - y);
        }
        ll ans = 0;
        for(i = 0; i < n; i++){
            ll v1, v2, v3, v4;
            ll x, y;
            x = v[i].ff;
            y = v[i].ss;
            s[0].erase(s[0].find(x + y));
            s[1].erase(s[1].find(x - y));
            s[2].erase(s[2].find(-x + y));
            s[3].erase(s[3].find(-x - y));
            ll curr;
            curr = x + y + *prev(s[3].end());
            curr = max(curr, x - y + *prev(s[2].end()));
            curr = max(curr, -x + y + *prev(s[1].end()));
            curr = max(curr, -x - y + *prev(s[0].end()));
            ans = max(ans, curr);
            s[0].insert(x + y);
            s[1].insert(x - y);
            s[2].insert(-x + y);
            s[3].insert(-x - y);
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 43968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] v = new int[N];
		for(int i = 0; i < N ; i++) {
			v[i] = sc.nextInt();
		}

		int[] c = new int[N];
		for(int i = 0; i < N ; i++) {
			c[i] = sc.nextInt();
		}

		sc.close();

		int answer = 0;

		for(int i = 0 ; i < N ;i ++) {
			if(v[i] > c[i]) {
				answer += v[i] -c[i];
			}
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 21844
K = int(input())

X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(X[K-1])

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

/* I'm too stupid to solve this problem */

using namespace std;
#define PI 3.14159265359
#define eps 1e-7
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
const int INF = 1<<29;
typedef unsigned long long ull;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int n;

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
    cout.tie(NULL);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);	
    
    cin >> n;

    if(n==1)
        cout << "Hello World\n";
    else{
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
    }

    return 0;
}


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

int main()
{
  int N,K;
  
  scanf("%d %d",&N,&K);
  
  
  int a[100]={0};
  
  for(int i=0;i<K;i++)
  {
    int d;
    scanf("%d",&d);
    for(int j=0;j<d;j++)
    {
      int tmp;
      scanf("%d",&tmp);
      a[tmp-1]++;
    }
  }
  
  int ans=0;
  for(int i=0;i<N;i++)
  {
    if(a[i]==0)
      ans++;
  }
  printf("%d",ans);
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=2;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	char str[N];int a[N],b[N],cnt[4],ans[4];
	int C[N];
	void main()
	{
		C[0]=0;fo(i,1,N-1){ int tmp=i;C[i]=C[i-1];while(tmp%2==0) tmp/=2,C[i]++; }
		int n=qread();scanf("%s",str+1);fo(i,1,n) a[i]=str[i]-'0';
		fo(i,0,n-2) b[i]=abs(a[1+i]-a[2+i]),cnt[b[i]]++;
		if(cnt[1]) {fo(i,0,n-2) b[i]=(b[i]==2?0:b[i]);ans[0]=0,ans[1]=1;}
		else {fo(i,0,n-2) b[i]=(b[i]==2?1:b[i]);ans[0]=0,ans[1]=2;}
		int ret=0;fo(i,0,n-2) if( C[n-2]-C[n-2-i]-C[i]==0 ) ret^=b[i];
		write(ans[ret]);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

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

using namespace std;

struct Task
{
    int cost;
    int limit;
};

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

    vector<Task> tasks(n);

    for (auto& task : tasks)
    {
        cin >> task.cost >> task.limit;
    }

    sort(tasks.begin(), tasks.end(), [](const auto& lhs, const auto& rhs){
        return lhs.limit < rhs.limit;
    });

    int s = 0;

    for (const auto& task : tasks)
    {
        s += task.cost;

        if (s > task.limit)
        {
            cout << "No";

            return 0;
        }
    }

    cout << "Yes";

    return 0;
}

Measured memory_bytes: 1920
n = gets.to_i
s = gets.split.map(&:to_i)
$co = 0

class Array
  def merge_sort
    merge = ->(a, b) {
      result = []
      while a.size > 0 and b.size > 0
        result << if a[0] < b[0]
          a.shift
        else
          $co += a.size
          b.shift
        end
      end
      result + a + b
    }
    
    l = length
    return self if l <= 1
    q = l / 2
    merge.(self[0...q].merge_sort, self[q..-1].merge_sort)
  end
end

s.merge_sort
puts $co



Measured memory_bytes: 47120
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

long merge_cnt(vector<int> &a) {
    if (a.size() <= 1) {
        return 0;
    }
    
    long cnt = 0;
    vector<int> b(a.begin(), a.begin()+ a.size() / 2);
    vector<int> c(a.begin()+ a.size() /2, a.end());
    
    cnt += merge_cnt(b);
    cnt += merge_cnt(c);
    
    int ai = 0, bi = 0, ci = 0;
    
    while (ai < a.size()) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += a.size() / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main(void){
    int length;
    long num;
    vector<int> a;
    
    cin >> length;
    for(int i = 0;i < length;++i){
        int n;
        cin >> n;
        a.push_back(n);
    }
    num = merge_cnt(a);
    printf("%ld\n",num);
}


Measured memory_bytes: 5160
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
 
class Dtest {
    static void Main(string[] args) {
        String n = Console.ReadLine();
        int rtn = 0;
        int len1 = int.Parse(n.Substring(n.Length - 1, 1));
        int len2 = 0;
        bool flg = false;
        for (int i = n.Length - 2; i >= 0; i--){
            len2 = int.Parse(n.Substring(i, 1));

            if (len1 == 5 && len2 > 4 || len1 > 5) {
                flg = true;
            } else {
                flg = false;
            }

            if (len1 > 5){
               rtn += 10 - len1;
            } else {
               rtn += len1;
            }
            len1 = len2;
            if (flg) {len1++;}
        }
        if (len1 > 5){
           rtn += 11 - len1;
        } else {
           rtn += len1;
        }
        Console.WriteLine(rtn);
    }
}

Measured memory_bytes: 18912
n = int(input())
b = list(map(int, input().split()))

c = sorted(b)

for i in range(n):
    if b[i] > i + 1:
        print(-1)
        exit()

ans = []

for i in range(n):
    s = b[i]
    ans.insert(s-1, s)

print(*ans) 

Measured memory_bytes: 38384
N = int(raw_input())
A = map(long, raw_input().split())
ans = 0
s = 0L
S = [0L]
for a in A:
  s += a
  S.append(s)
S.sort()
c = S[0]
n = 1
for s in S[1:]:
  if c == s:
    n += 1
  else:
    ans += n*(n-1)/2
    n = 1
    c = s
ans += n*(n-1)/2
#for i in range(N):
#  for j in range(N+1)[i+1:]:
#    if sum(A[i:j]) == 0:
#      ans += 1
print ans


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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(vector<A> v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= 1000; i++) {
    double ans = (double)i;
    if (floor(ans * 0.08) == a && floor(ans * 0.1) == b) {
      debug(round(ans * 0.08));
      cout << ans << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main(){
    int n, x;
    cin >> n >> x;
    int m[110];
    int min = 1100;
    int total = 0;
    for(int i = 0; i < n; i++){
        cin >> m[i];
        if(m[i] < min) min = m[i];
        total += m[i];
    }

    cout << n + (x -total)/min << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int N = S.size();
  bool ans = true;
  for(int i=0;i<(N-1)/2;i++){
    if(S.at(i) != S.at(N-1-i)){
      ans = false;
      break;
  }
  }
  for(int j=0;j<(N-1)/4; j++){
    if(S.at(j) != S.at((N-1)/2-1-j)){
      ans = false;
      break;
    }
  }
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
cnt = [0] * (m + 1)

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

ans = 0
for i in range(m+1):
    if cnt[i] == n:
        ans += 1

print(ans)


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 1 , 0 } ;
const int dy[] = { 0 , 1 , 0 , -1 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

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

    map < string , int > h ;

    for ( int i=0 ; i < n ; i ++ )
    {
        string s ;
        cin >> s ;

        h[s] ++ ;
    }

    int m = 0 ;

    for ( auto &i : h )
    {
        m = max ( m , i.S ) ;
    }

    for ( auto &i : h )
    {
        if ( i.S == m )
            cout << i.F , line ;
    }
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
#define fi           first
#define se           second
#define ll           long long
#define pb           push_back
#define mp           make_pair
#define pll          pair<ll,ll>
#define pii          pair<int,int>
#define all(x)       (x).begin(),(x).end()
#define isWorking()  cout<<"Wroking"<<endl
#define FOR(i,x,y)   for(int i=x; i<y; i++)
#define SORT(x)      sort(x.begin(),x.end())
#define PRINT(ok)    cout<<(ok? "YES":"NO")<<endl
#define Fast_Input   ios_base :: sync_with_stdio(false), cin.tie(NULL);
typedef vector < int > VI;
const ll mod= 1e9+7,INF=1e18,mx= 5e6+5,mn=100;
int testCase=1,cas=0;

int main() {
    Fast_Input

    //cin>>testCase;
    while(testCase--){
        int sx,sy,tx,ty;
        cin>>sx>>sy>>tx>>ty;
        string ans="";

        for(int i=sy; i<ty; i++) ans+='U';
        for(int i=sx; i<tx; i++) ans+='R';

        //cout<<ans<<endl;

        for(int i=ty; i>sy; i--) ans+='D';
        for(int i=tx; i>sx; i--) ans+='L';

        ans+='L';
        for(int i=sy; i<=ty; i++) ans+='U';
        for(int i=sx; i<=tx; i++) ans+='R';
        ans+='D';

        ans+='R';
        for(int i=ty; i>=sy; i--) ans+='D';
        for(int i=tx; i>=sx; i--) ans+='L';
        ans+='U';

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <ctime>
#include <numeric>
#include <fstream>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const long double pi=acos(-1.0);
int dx[]={0,1,0,-1,1,1,-1,-1,0},dy[]={1,0,-1,0,1,-1,1,-1,0};



main(){
  ll n;
  cin>>n;
  int ans=0;
  ll t=1;

  while(t<n){
    ++ans;
    t*=3;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 0
#include<iostream>
  
int const MAXN = 3000;
int const MOD = 1000000007;

char s[MAXN];

int N;
int dp[2][MAXN];

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

  for(int i = 0; i < N; ++i) dp[0][i] = 1;

  for(int j = 0; j < N-1; ++j) {
    if(s[j] == '>') {
      dp[(j+1)%2][N-j-2] = dp[j%2][N-j-1];
      for(int i = N-j-3; i >= 0; --i) {
        dp[(j+1)%2][i] = (dp[(j+1)%2][i+1] + dp[j%2][i+1])%MOD;
      }
    } else {
      dp[(j+1)%2][0] = dp[j%2][0];
      for(int i = 1; i < N-j-1; ++i) {
        dp[(j+1)%2][i] = (dp[(j+1)%2][i-1] + dp[j%2][i])%MOD;
      }
    }
  }
  std::cout << dp[(N-1)%2][0] << std::endl;
  return 0;
}

Measured memory_bytes: 256
import math
# from functools import reduce

# def gcd(*numbers):
#     return reduce(math.gcd, numbers)

k = int(input())

sum = 0
for p in range(k):
    for q in range(k):
        n = math.gcd(p + 1, q + 1)
        for r in range(k):
            sum += math.gcd(n, r + 1)
print(sum)

Measured memory_bytes: 9180
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>

#define p(a, b) pair<a, b>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,a,b;
    cin >> x >> a >> b;
    x -= a;
    while(x>= b)
        x-=b;
    cout << x;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
using Graph = vector<vector<int>>;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  Real a,b,h,m,t;
  cin>>a>>b>>h>>m;
  if(((60*h+m)-m*12)*2==720){
    cout<<a+b;
  }
  else{t=a*a+b*b-a*b*2*cos(2*M_PI*((60*h+m)/720.0-m/60.0));
  cout << fixed << setprecision(20) <<sqrt(t);
}
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

const int MAX=200010;


int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    string s;
    cin >> n >> s;
    reverse(s.begin(),s.end());
    int cnt=0;
    rep(i,n) {
        if (s[i]=='1') ++cnt;
    }
    vector<ll> b1(n),b2(n);
    b1[0]=1,b2[0]=1;
    ll s1=0,s2=0;
    if (cnt-1>0) {
        rep(i,n-1) b1[i+1]=(2*b1[i])%(cnt-1);
        rep(i,n) {
            if (s[i]=='1') s1=(s1+b1[i])%(cnt-1);
        }
    }
    rep(i,n-1) b2[i+1]=(2*b2[i])%(cnt+1); 
    rep(i,n) {
        if (s[i]=='1') s2=(s2+b2[i])%(cnt+1);
    }
    vector<int> p(200010);
    repr(i,1,200010) {
        int j=i,m=0;
        while (j>0) {
            if (j%2==1) ++m;
            j/=2;
        }
        p[i]=p[i%m]+1;
    }
    invrep(i,n) {
        int ans=0;
        if (s[i]=='1') {
            if (cnt>1) {
                ll tmp=(s1+(cnt-1)-b1[i])%(cnt-1);
                ans=p[tmp]+1;
            }
        } else {
            ll tmp=(s2+b2[i])%(cnt+1);
            ans=p[tmp]+1; 
        }
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 7580
<?php
fscanf(STDIN, "%d %d", $n, $x);
$l = explode(' ', trim(fgets(STDIN)));
$p = 0;
for ($i = 0; $i < $n; $i++) {
	$p += $l[$i];
	if ($p > $x) break;
}
echo $i + 1;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;
}


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

int n, ans[105], hold;
string s;

void add(int hold){
    for (int i = 0; i < 105; i++){
        ans[i] += hold;
        hold = ans[i] / 10;
        ans[i] %= 10;
        if (!hold) break;
    }
}

int main() {
    cin >> s;
    for (int i = s.length()-1; i >= 0; i--){
        n = s[i]-'0';
        n += hold;
        hold = n / 10;
        n %= 10;
        if (n < 5) add(n);
        else if (n > 5){
            add(10-n);
            hold += 1;
        }
        else{
            if (i != 0 && s[i-1]-'0' >= 5){
                add(10-n);
                hold += 1;
            }
            else add(n);
        }
    }
    add(hold);
    bool flag = false;
    for (int i = 104; i >= 0; i--){
        if (ans[i] != 0) flag = true;
        if (flag) cout << ans[i];
    }
    cout << "\n";
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//nCr
long long Comb (long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);
  
  for(int i=0;N!=0;i++){
    if(i==0){
      cout<<2;cout<<" ";
      N--;
    }
    else if( is_prime(5*i+1)){
      cout<<5*i+1;cout<<" ";
      N--;
    }
  }
  
}

Measured memory_bytes: 256
N, K = [int(x) for x in input().split()]

array = []
count = 0
for i in range(N):
    array.append(tuple(map(int, input().split())))

array.sort()
K -= 1
for tup in array:
    if K < tup[1]:
        print(tup[0])
        break
    else:
        K -= tup[1]

Measured memory_bytes: 16972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
int f[N];
int g[N];
int F(int x)
{
    return x == f[x] ? x : f[x] = F(f[x]);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        f[i] = i;
    for (int i = 1; i <= m; ++i)
    {
        int u, v;
        cin >> u >> v;
        f[F(u)] = F(v);
    }
    int ans = 1;
    for (int i = 1; i <= n; ++i)
        ++g[F(i)];
    for (int i = 1; i <= n; ++i)
        ans = max(ans, g[i]);
    cout << ans;
}

Measured memory_bytes: 10644
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        arr: [usize; n],
    }

    let mut cnt = (n-1)/(k-1)+1;
    if n % k == 0 || k==2 { cnt -= 1; }
    println!("{}", cnt)
}

Measured memory_bytes: 3248
import math

def prity(mat):
    for i in range(len(mat)):
        for j in range(len(mat[0])):
            print(mat[i][j], end='')
        print()
        
def tile_a(i, j, mat):
    assert mat[i][j] == '.' and mat[i][j+1] == '.'
    mat[i][j] = '<'
    mat[i][j+1] = '>'
    
def tile_b(i, j, mat):
    assert mat[i][j] == '.' and mat[i+1][j] == '.'
    mat[i][j] = '^'
    mat[i+1][j] = 'v'
    
N, M, A, B = [int(_) for _ in input().split()]
a, b = A, B

mat = [['.' for j in range(M)] for i in range(N)]

if N % 2 == 1:
    i = N - 1 #tile last row
    for w in range(M // 2):
        if a > 0:
            j = 2 * w + (M % 2)            
            tile_a(i, j, mat)
            a -= 1

if M % 2 == 1:
    j = M - 1 # tile last column
    for h in range(N // 2):
        if b > 0:
            i = 2 * h
            tile_b(i, j, mat)
            b -= 1
            
height = N // 2
width = M // 2

skip_lst = []
if N % 2 == 1 and M % 2 == 1 and a % 2 == 1 and b % 2 == 1:
    tile_a(2 * (height - 1), 0, mat)
    tile_b(2 * (height - 1) + 1, 0, mat)
    a -= 1
    b -= 1
    skip_lst.append((2 * (height - 1), 0))
    
for h in range(height):
    for w in range(width):
        i = 2 * h
        j = 2 * w
        
        if not((i, j) in skip_lst):
            if a > 1:
                tile_a(i, j, mat)
                tile_a(i + 1, j, mat)
                a -= 2
            elif a == 1:
                tile_a(i, j, mat)
                a -= 1
            elif b > 1:
                tile_b(i, j, mat)
                tile_b(i, j + 1, mat)
                b -= 2
            elif b == 1:
                tile_b(i, j, mat)
                b -= 1
                
if a == 0 and b == 0:
    print("YES")
    prity(mat)
else:
    print("NO")

Measured memory_bytes: 14324
# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())

ac = np.zeros(n)
wa = np.zeros(n)

for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    if ac[p] == 1:
        continue
    if s == "WA":
        wa[p] += 1
    else:
        ac[p] = 1

acc = 0
wac = 0
for a, w in zip(ac, wa):
    if a == 1:
        acc += 1
        wac += w

print(acc, int(wac))


Measured memory_bytes: 13896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main(){
    int N, Q; cin >> N >> Q;
    map<int,int> q;
  	rep(i,N-1){
      int a, b;
      cin >> a >> b;
      q[b] = a;
    }
  
  	int c[N]; rep(i,N) c[i+1] = 0;
    rep(j,Q){
      int p, x;
      cin >> p >> x;
      c[p] += x;
    }
    
    for(int i=2; i<=N; i++) c[i] += c[q[i]];
  
    rep(i,N) cout << c[i+1] << " ";

}

Measured memory_bytes: 12544
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    readln.chomp.to!int;
    int x, y, z;
    long r = 1;
    foreach (a; readln.split.to!(int[])) {
        long d;
        if (a == x) ++d;
        if (a == y) ++d;
        if (a == z) ++d;

        r = (r * d) % P;
        
        if (a == x) {
            ++x;
        } else if (a == y) {
            ++y;
        } else {
            ++z;
        }
    }
    writeln(r);
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};


const ll MOD = 998244353;

class Combination_Mod{
    public:
        Combination_Mod(long long MAX, long long MOD) : fact(MAX + 1), inv(MAX + 1), finv(MAX + 1), MAX(MAX + 1), MOD(MOD){
            init();
        }

        void init(){
            fact[0] = fact[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for(long long i = 2; i < MAX; ++i){
                fact[i] = fact[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD % i] *  (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
            }
        }

        long long value(long long n, long long r){
            if(n < r || n < 0 || r < 0) return 0;
            return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD;
        }

    private:
        vector<long long> fact;
        vector<long long> inv;
        vector<long long> finv;
        const long long MAX;
        const long long MOD;
};

ll N, M, K;

signed main(){
    cin >> N >> M >> K;
    Combination_Mod cm(200010, MOD);
    ll ans = 0;
    ll p = 1;
    REP(i, N - K - 1) p = (p * (M - 1)) % MOD;
    for(ll k = K; k >= 0; k--){
        ll x = M * p % MOD;
        p = (p * (M - 1)) % MOD;
        x = (x * cm.value(N - 1, k)) % MOD;
        ans = (ans + x) % MOD;
    }
    PRINT(ans);
    return 0;
    return 0;
}

Measured memory_bytes: 7988
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
string s;
int ans=0;
for(int i=0; i<3; i++)
{
    cin>>s[i];
    if(s[i]=='1') ++ans;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


template<class T> struct PrimalDual {
  struct Edge {
    int to, rev;
    T cap, cost;
  };
  const int n;
  const T inf = numeric_limits<T>::max();
  VV<Edge> g;
  V<T> pot, dist;
  V<> pv, pe;
  PrimalDual(int n) : n(n), g(n), pot(n), dist(n), pv(n), pe(n) {}
  void add_edge(int from, int to, T cap, T cost) {
    assert(from != to);
    assert(cap >= 0);
    assert(cost >= 0);
    g[from].emplace_back(Edge{to, (int) g[to].size(), cap, cost});
    g[to].emplace_back(Edge{from, (int) g[from].size() - 1, 0, -cost});
  }
  void dijkstra(int s) {
    using P = pair<T, int>;
    priority_queue< P, V<P>, greater<P> > pque;
    fill(begin(dist), end(dist), inf);
    pque.emplace(dist[s] = 0, s);
    while (!pque.empty()) {
      T d; int v;
      tie(d, v) = pque.top(); pque.pop();
      if (d > dist[v]) continue;
      for (int i = 0; i < g[v].size(); ++i) {
        const Edge& e = g[v][i];
        if (e.cap <= 0 or dist[e.to] <= dist[v] + e.cost - (pot[e.to] - pot[v])) continue;
        pv[e.to] = v;
        pe[e.to] = i;
        pque.emplace(dist[e.to] = dist[v] + e.cost - (pot[e.to] - pot[v]), e.to);
      }
    }
  }
  T min_cost_flow(int s, int t, T f) {
    assert(s != t);
    assert(f >= 0);
    T res = 0;
    fill(begin(pot), end(pot), 0);
    while (f > 0) {
      dijkstra(s);
      if (dist[t] == inf) return -1;
      for (int v = 0; v < n; ++v) pot[v] += dist[v];
      T d = f;
      for (int v = t; v != s; v = pv[v]) {
        d = min(d, g[pv[v]][pe[v]].cap);
      }
      f -= d;
      res += d * pot[t];
      for (int v = t; v != s; v = pv[v]) {
        Edge& e = g[pv[v]][pe[v]];
        e.cap -= d;
        g[v][e.rev].cap += d;
      }
    }
    return res;
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m, f; cin >> n >> m >> f;
  PrimalDual<int> pd(n);
  for (int i = 0; i < m; ++i) {
    int from, to, cap, cost; cin >> from >> to >> cap >> cost;
    pd.add_edge(from, to, cap, cost);
  }
  cout << pd.min_cost_flow(0, n - 1, f) << '\n';
}


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

using namespace std;

vector<int> m = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int dp[5050][10050];

int main() {
    int N, M, A;
    cin >> N >> M;

    vector<int> v;

    for(int i = 0; i < M; i++) {
        cin >> A;
        v.emplace_back(A);
    }

    sort(v.begin(), v.end(), greater<int>());

    dp[0][0] = 1;

    for(int i = 0; i < 5050; i++) {
        for(int j = 0; j <= N; j++) {
            if(dp[i][j] == 0) {
                continue;
            }

            for(int k: v) {
                if(j+m[k] <= N) {
                    dp[i+1][j+m[k]] = 1;
                }
            }
        }
    }

    int d = 0;
    for(int i = 0; i < 5050; i++) {
        if(dp[i][N]) {
            d = max(d, i);
        }
    }

    for(int i = d; i > 0; i--) {
        int x = -1;
        for(int k: v) {
            if(N-m[k] >= 0 && dp[i-1][N-m[k]]) {
                x = max(x, k);
            }
        }
        N -= m[x];
        cout << x;
    }
    cout << endl;
}

Measured memory_bytes: 179328
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	string s;
	cin>>s;
	if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])){
		cout<<"Yes"<<endl;
	}else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=200005;

int tree[4*MAXN],lazy[4*MAXN],A[MAXN];
vector<int> pos[MAXN];

void updatenode(int now,int L,int R,int val){
	tree[now]+=val;
	lazy[now]+=val;
}

void pushdown(int now,int L,int R){
	int mid=(L+R)/2;
	updatenode(2*now,L,mid,lazy[now]);
	updatenode(2*now+1,mid+1,R,lazy[now]);
	lazy[now]=0;
}

void build(int now,int L,int R){
	if(L==R){
		tree[now]=A[L];
		return;
	}
	int mid=(L+R)/2;
	build(2*now,L,mid);
	build(2*now+1,mid+1,R);
	tree[now]=max(tree[2*now],tree[2*now+1]);
}

int query(int now,int L,int R,int x,int y){
	if(L>=x && R<=y)return tree[now];
	if(L>y || R<x)return INT_MIN;
	pushdown(now,L,R);
	int mid=(L+R)/2;
	return max(query(2*now,L,mid,x,y),query(2*now+1,mid+1,R,x,y));
}

void update(int now,int L,int R,int x,int y,int val){
	if(L>=x && R<=y){
		updatenode(now,L,R,val);
		return;
	}
	if(L>y || R<x)return;
	int mid=(L+R)/2;
	pushdown(now,L,R);
	update(2*now,L,mid,x,y,val);
	update(2*now+1,mid+1,R,x,y,val);
	tree[now]=max(tree[2*now],tree[2*now+1]);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,m,l,r;
	cin >> n >> m;
	int ans=n-m;
	for(int i=1;i<=n;i++){
		cin >> l >> r;
		pos[l].push_back(r);
	}
	for(int i=0;i<=m+1;i++)A[i]=-m+i-1;
	build(1,0,m+1);
	for(int i=0;i<=m+1;i++){
		if(i)update(1,0,m+1,0,m+1,-1);
		for(auto isi : pos[i])update(1,0,m+1,1,isi,1);
		ans=max(ans,query(1,0,m+1,i+2,m+1));
	}
	cout << max(ans,0) << endl;
	return 0;
}



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

int main() {
  int n, x, min=32, count=0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int j = x; j%2 == 0; j=j/2) {
      count++;
    }
    if (count < min) {
      min = count;
    }
    count = 0;
  }

  std::cout << min << '\n';

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int read()
{
    char c;
    int f = 1;
    c = getchar();
    while(!isdigit(c) ) c = getchar();
    int sum = 0;
    while(isdigit(c)){
        sum = sum * 10 + c-'0';
        c = getchar();
    }
    return sum;
}
const int maxn = 2e5+5;
const int INF = 0x3f3f3f3f;
int black[maxn], white[maxn];
int main()
{
    string s;
    int n;
    cin >> n >> s; int cnt = 0;
    for(int i=1; i<=n+1; i++){
        if(i<=n)
        if(s[i-1] == '#') black[i] = black[i-1] + 1;
        else black[i] = black[i-1];
        else black[i] = black[i-1];
    }
    for(int j=n; j>=1; j--){
        if(j-1 >= 0 )
        if(s[j-1] == '.') white[j] = white[j+1] + 1;
        else white[j] = white[j+1];
        else white[j-1] = white[j];
    }
//    for(int i=1; i<=n; i++) cout << black[i] << " ";
//    cout << endl;
//    for(int i=1; i<=n; i++) cout << white[i] << " ";
//    cout << endl;
    int ans = INF;
    for(int i=0; i<=n; i++){
        ans = min(ans, black[i]+white[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2180
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	ST = input()
	ST = ST[:-1]
	STS = ST.split()
	A,B = inputMap()
	U = input()
	U = U[:-1]

	if U == STS[0]:
		A -= 1
	else:
		B -= 1

	print("{} {}".format(A,B))

if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
import sys
import bisect
import collections
import fractions
import heapq


def slove():
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    t = 0
    for i in range(n):
        if a[i] < 0:
            cnt += 1
        a[i] = abs(a[i])
        t += a[i]
    a.sort()
    if cnt % 2 == 0:
        print(t)
    else:
        print(t - abs(a[0]) * 2)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 90348
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int x = abs(A - B);
	x -= 1;
	if (x % 2 == 0) {
		cout << "Borys" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
int bp(int pow, int n){
    int d = 1;
    while(n)
    {
        if(n%2==1)d=(d*pow)%mod;
        pow=(pow*pow)%mod;
        n/=2;
    }
    return d;
}
void solve(){
    int n, m, sum = 0;
    cin>>n>>m;
    for(int i = 0; i < m; i++){
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum>n)cout<<"-1\n";
    else cout<<n-sum;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  int a[N];
  ll b[N];
  ll tot = 0;
  rep(i,N) {
    cin >> a[i];
    if (i==0) b[i] = a[i];
    else b[i] = b[i-1] + a[i];
    tot += abs(a[i]);
  }

  ll retval = tot;
  rep(i,N-1){
    retval = min(retval, abs(b[N-1]-2*b[i]));
  }
  cout << retval << endl;
  

  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 5928
#include<stdio.h>
int main()
{
	int n,s,t,x,y;
	for(;scanf("%d",&n)&&n!=0;printf("%d %d\n",x,y))
		for(x=0,y=0;n-->0;)
		{
			scanf("%d %d",&s,&t);
			if(s==t)
				x+=s,y+=t;
			else
				if(s>t)x+=s+t;
			else
				y+=s+t;
		}
	return 0;
}

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

using namespace std;

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

    int h1 , m1 , h2 , m2 , k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int mins;
    if (h1 == h2) {
        mins = m2 - m1;
    } else {
        mins = (h2 - h1 - 1) * 60 + (60 - m1) + m2;
    }

    cout << max(0 , mins - k);
}


Measured memory_bytes: 3636
include Math
a, b, c = gets.split.map(&:to_i)

c = c * PI / 180
S = 0.5 * a * b * sin(c)
L = a + b + (((a**2) + (b**2)) - 2 * a * b * cos(c))**0.5
h = b * sin(c)
puts S, L, h

Measured memory_bytes: 8964
#include<cmath>
#include<iostream>
#include<cstdio>
#include <string>
using namespace std;

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

	sum = b / c - a / c;
	if (a % c == 0) {
		sum += 1;
	}
	cout << sum <<endl;


	return 0;


}


Measured memory_bytes: 256
def A(i,x):
 while i<=n:t[i]+=x;i+=i&-i
n,q,*c=map(int,open(0).read().split())
a=[0]*q
j,*b=t=[0]*9**6
for i in sorted(range(q),key=lambda x:c[x+x-~n]):
 while j<c[i+i-~n]:d=c[j];j+=1;A(b[d]+1,1);b[d]=j;A(j+1,-1)
 l=c[i+i+n]
 while l:a[i]+=t[l];l-=l&-l
print(*a)

Measured memory_bytes: 300424
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
*/

ll mp[5000] = {0};
vector<ll> rt[2000];
queue<ll> ans;
bool rp(ll pos)
{
	mp[pos] = 1;
	int al = 0;
	int al_num = 0;
	for(ll i=0;i<rt[pos].size();++i)
	{
		if(mp[rt[pos][i]]==1)
		{
			al_num = rt[pos][i];
			al ++;
		}
		mp[rt[pos][i]]+=2;
	}
	if(al==1)
	{
		ans.push(al_num);
		return false;
	}

	for(ll i=0;i<rt[pos].size();++i)
	{
		if(mp[rt[pos][i]]==2)
		{
			mp[rt[pos][i]] = 1;
			if(!rp(rt[pos][i]))
			{
				ans.push(rt[pos][i]);
				return false;
			}
			mp[rt[pos][i]] = 2;
		}
	}
	for(ll i=0;i<rt[pos].size();++i)
	{
		mp[rt[pos][i]]-=2;
	}
	mp[pos] = 0;
	return true;
}
int main()
{
	string S;
	ll i,j,k,a,b;
	ll N,M,K;
	cin >> S>> K;
	ll s_len = S.size();
	j = 0;
	k = 0;
	a=-1;
	for(i=1;i<s_len-1;++i)
	{
		if(S[i]==S[i-1] &&S[i]!=S[i+1])
		{
			if(j==0)
			{
				a=i;
				continue;
			}
			k += ((i-j+1)/2);
		}
		else if(S[i]!=S[i-1])
		{
			if(i==1)
				a=0;
			j=i;
		}
	}
	k*=K;
	if(S[s_len-1]!=S[s_len-2])
		j=s_len-1;
	if(a == -1)
	{
		k=(s_len*K)/2;
	}
	else if(S[s_len-1]==S[0])
	{
		k += ((s_len-j+1+a)/2)*(K-1);
		k += (a+1)/2;
		k += (s_len-j)/2;
	}
	else
	{
		k += ((s_len-j)/2)*(K);
		k += ((a+1)/2)*(K);
	}
	cout << k << endl;

	return 0;
}




















Measured memory_bytes: 256