akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
	int n,outCount,score,runnerCount,a[3];
	char s[8];
	scanf("%d",&n);
	while(n--)
	{
		outCount = score = runnerCount = 0;
		while(outCount<3)
		{
			scanf("%s",s);
			switch(s[1])
			{
			case 'I':
				(runnerCount<3 ? ++runnerCount : score++);
				break;
			case 'O':
				score += runnerCount+1, runnerCount=0;
				break;
			case 'U':
				++outCount;
				break;
			}
		}
		printf("%d\n",score);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define LL long long
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(x,l,r) for(int x=l,x##_=r;x<=x##_;x++)
#define FR(x,l,r) for(int x=l,x##_=r;x<x##_;x++)
#define DOR(x,r,l) for(int x=r,x##_=l;x>=x##_;x--)
using namespace std;
const int P=2019;
int n,m;
int main () {
	scanf("%d%d",&n,&m);
	LL ans=2019;
	if(m-n>=2019)ans=0;
	else FOR(i,n,m)FOR(j,i+1,m)ans=min(1LL*i*j%2019,ans);
	cout<<ans;
	return 0;
}


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

const int N = (int)2e7 + 123, MOD = (int)1e9 + 7;

int n, m, f[N], ans;

int bin_pow(int a , int b){
    if (b == 0) return 1ll;
    if (b % 2 == 1) return (bin_pow (a, b - 1) * a) % MOD;
    else {
        int x = bin_pow (a, b / 2);
        return (x * x) % MOD;
    }
}

int cnk (int n, int k) {
    if (n < k) return 0;
    int x = f[n];
    int y = (f[k] * f[n - k]) % MOD;
    return (x * bin_pow (y, MOD - 2)) % MOD;
}

main() {
    cin >> n >> m;
    f[0] = 1;
    for(int i = 1; i <= 2e7; ++i) {
        f[i] = f[i - 1] * i;
        f[i] %= MOD;
    }
    if ((n + m) % 3 != 0) cout << 0;
    else {
        int k = (n + m) / 3;
        if (n < k || m < k) cout << 0;
        else {
            cout << cnk(k, n - k);    
        }
    }
    return 0;
}

Measured memory_bytes: 156544
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

int main(){
	int N, K;
	cin >> N >> K;
	if(K == 1)	cout << 0 << endl;
	else cout << (N-K) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll comb[51][51];
ll c[51];
int main()
{
	int n, k, s, t; cin>>n>>k>>s>>t;
	int a[51];
	for(int i=0; i<n; i++) cin>>a[i];
	if((s&t)!=s){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0; i<=n; i++){
		comb[i][0]=comb[i][i]=1;
		for(int j=1; j<i; j++){
			comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=k; j++) c[i]+=comb[i][j];
	}
	vector<ll> vx;
	ll x0=(1ll<<n)-1;
	for(int i=0; i<18; i++){
		if(s&(1<<i)){
			ll y=0;
			for(int j=0; j<n; j++){
				if(a[j]&(1<<i)) y^=(1ll<<j);
			}
			x0&=y;
			continue;
		}else if(!(t&(1<<i))){
			ll y=0;
			for(int j=0; j<n; j++){
				if(!(a[j]&(1<<i))) y^=(1ll<<j);
			}
			x0&=y;
			continue;
		}
		ll x=0;
		for(int j=0; j<n; j++){
			if(a[j]&(1<<i)) x^=(1ll<<j);
		}
		vx.push_back(x);
	}
	if(x0==0){
		cout<<0<<endl;
		return 0;
	}
	int m=vx.size();
	ll ans=c[popcountll(x0)];
	for(int i=1; i<(1<<m); i++){
		for(int l=0; l<n; l++){
			if(!(x0&(1ll<<l))) continue;
			ll s=x0;
			for(int j=0; j<m; j++){
				if(!(i&(1<<j))) continue;
				if(vx[j]&(1ll<<l)){
					s&=vx[j];
				}else{
					s&=((1ll<<n)-1-vx[j]);
				}
			}
			bool dame=0;
			for(int p=0; p<l; p++){
				if(s&(1ll<<p)){
					dame=1; break;
				}
			}
			if(!dame){
				if(popcount(i)&1) ans-=c[popcountll(s)];
				else ans+=c[popcountll(s)];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
# ABC171C

def dog(n):
    abc = 'abcdefghijklmnopqrstuvwxyz'
    n -= 1
    pow = [0]
    cum = 0
    for i in range(1, 12):
        cum += 26**i
        pow.append(cum)
    for i in range(1, 12):
        if pow[i - 1] <= n <  pow[i]:
            break
    # print(i, pow[i-1], n, pow[i])
    dig = []
    n = n - pow[i - 1]
    # print(n)
    for j in range(i):
        n2 = n // 26
        dig.append(n % 26)
        n = n2
    str = [abc[i] for i in reversed(dig)]
    str = ''.join(str)
    print(str)

n = int(input())
dog(n)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b; cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;
}


Measured memory_bytes: 256
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
a=[]
b=[]
for a_i, b_i in ab:
    a.append(a_i)
    b.append(b_i)
a.sort()
b.sort()

import statistics
a_med=statistics.median(a)
b_med=statistics.median(b)

if n%2==0:
    ans=2*b_med-2*a_med+1
else:
    ans=b_med-a_med+1
print(int(ans))

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

int main() {
    int64_t X; cin >> X;
    auto f = [&](int64_t x) -> int64_t {
        return x * x * x * x * x;
    };
    vector<int64_t> V;
    map<int64_t, int64_t> ma, B;
    int64_t M = 1010;
    for(int64_t A = -M; A < M; ++A) {
        int64_t a = f(A);
        V.push_back(a);
        ma[a]++;
        B[a] = A;
    }
    for(auto &a : V) {
        if(ma[a - X]) {
            cout << B[a] << " " << B[a - X] << '\n';
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3960
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define NMAX    50000
#define MMAX    20

int *c;
int memo[MMAX][NMAX + 1];

int min2(int x, int y) {

    return x < y ? x : y;
}

// 0???m?¨????????????????????????£???n??????????????¨??????????????????????°?????????°???
int dp(int m, int n) {
    int rep;

    if( m < 0 ) return INT_MAX;
    if( memo[m][n] < INT_MAX ) return memo[m][n];

    if( n == 0 ) {
        rep = 0;
    } else if( n < c[m] ) {
        rep = dp(m - 1, n);
    } else {
        rep = min2(dp(m - 1, n), dp(m, n - c[m]) + 1);
    }
    
    return memo[m][n] = rep;
}

int main(void) {
    int n, m;
    int i, j;

    scanf("%d %d", &n, &m);
    c = (int *)malloc(sizeof(int) * m);
    for( i = 0; i < m; i++ ) {
        scanf("%d", c + i);
        for( j = 0; j <= NMAX; j++ ) {
            memo[i][j] = INT_MAX;
        }
    }
    printf("%d\n", dp(m - 1, n));

    free(c);

    return 0;
}

Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

int main()
{
  ll n,x;cin>>n>>x;
  ll kyori=0,ans=0;
  for(ll i=0;i<n;i++){
    ll keep;cin>>keep;
    kyori+=keep;
    ans++;
    if(kyori>x){
      cout<<ans<<endl;
      return 0;
    }
  }
  cout<<n+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define INF (1<<30)-1
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int h,w,a,b; cin >> h >> w >> a >> b;
  vector<vi> ans(h,vi(w));

  rep(i,b) rep(j,w-a) ans[i][j+a] = 1;
  rep(i,h-b) rep(j,a) ans[i+b][j] = 1;

  rep(i,h){
    rep(j,w) cout << ans[i][j];
    cout << endl;
  }
  // cout << "\n";
  return 0;
}


Measured memory_bytes: 7156
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
#include<math.h>

int main(void){
    int X;
    scanf("%d", &X);
    int limit = (int)sqrt(X);
    int i, j;
    double ans = 0;
    for(i=2; i<=limit; i++) {
        for(j=2; pow((double)i, (double)j) <= (double)X; j++) {
            if(pow((double)i, (double)j) > ans) {
                ans = pow((double)i, (double)j);
            }
        }
    }
    if(ans == 0) {
        printf("1\n");
        return 0;
    }
    printf("%d\n", (int)ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
template<class T>inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
const long long INF=1LL<<60;
const int MAX_N=110;
const int MAX_V=100100;

//入力
int N;
long long W;
long long w[MAX_N];
long long v[MAX_V];

//dpテーブル
long long dp[MAX_N][MAX_V];

int main(){
    cin>>N>>W;
    for(int i=0;i<N;i++){
        cin>>w[i]>>v[i];
    }
    for(int i=0;i<MAX_N;i++){
        for(int j=0;j<MAX_V;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int sum_v=0;sum_v<MAX_V;sum_v++){
            if(sum_v-v[i]>=0){
                chmin(dp[i+1][sum_v],dp[i][sum_v-v[i]]+w[i]);
            }
            chmin(dp[i+1][sum_v],dp[i][sum_v]);
        }
    }
    long long res=0;
    for(int sum_v=0;sum_v<MAX_V;sum_v++){
        if(dp[N][sum_v]<=W){
            res=sum_v;
        }
    }
    cout<<res<<endl;


    
}
  
  



Measured memory_bytes: 86272
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 200100;
int R[maxn];
void print(int A[], int n)
{
    for(int i = 0; i < n - 1; i++)
        cout << R[i] << ' ';
    cout << R[n-1] << endl;
}
void insertionSort(int A[], int n)
{
    print(A, n);
    for(int i = 1; i < n; i++)
    {
        int v = A[i];
        int j = i - 1;
        while( j >= 0 && A[j] > v)
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        print(A, n);
    }
}
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> R[i];
    insertionSort(R, n);
    return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll cnt[100010]={},n,ans=0;

int main(){
	ios::sync_with_stdio(false);
	int i,x,y,q;
	cin>>n;
	for(i=1;i<=n;++i){
		cin>>x;
		ans+=x;
		++cnt[x];
	}
	cin>>q;
	while(q--){
		cin>>x>>y;
		ans=ans-x*cnt[x]+y*cnt[x];
		cnt[y]+=cnt[x];
		cnt[x]=0;
		cout<<ans<<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 4388
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=200000+5;

int n,m,p,blo,len,id[maxn],cnt[maxn];
long long tmp,no[maxn],mp[maxn],ans[maxn],sum[maxn],power[maxn];

char s[maxn];

struct M{
int l,r,num;
friend bool operator < (M a,M b){
if(id[a.l]!=id[b.l])
return id[a.l]<id[b.l];
return a.r<b.r;
}
}q[maxn];

inline int read(void){
char ch=getchar();int x=0;
while(!(ch>='0'&&ch<='9')) ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x;
}

inline void change(int x,int val){
x=no[x];
if(cnt[x]>1) tmp-=1LL*cnt[x]*(cnt[x]-1)/2;
cnt[x]+=val;
if(cnt[x]>1) tmp+=1LL*cnt[x]*(cnt[x]-1)/2;
}

inline int check(char a){
int x=a-'0';
if(p==2){
if(x&1) return 0;
return 1;
}
else if(p==5){
if(x==0||x==5) return 1;
return 0;
}
return 0;
}

inline void solve1(void){
for(int i=1;i<=n;i++)
sum[i]=sum[i-1]+check(s[i])*i,no[i]=no[i-1]+check(s[i]);
for(int i=1,l,r;i<=m;i++)
l=1,r=n,printf("%lld\n",sum[r]-sum[l-1]-1LL*(no[r]-no[l-1])*(l-1));
}

signed main(void){

n = read(), p=read(),scanf("%s",s+1),m=1,n=strlen(s+1);blo=sqrt(n);
if(p==2||p==5) return solve1(),0;
for(int i=1;i<=n;i++) id[i]=(i-1)/blo+1;power[n]=1;
for(int i=1;i<=m;i++) q[i].l = 1,q[i].r= n+1,q[i].num=i;
for(int i=n-1;i>=1;i--) power[i]=1LL*power[i+1]*10%p;
for(int i=n;i>=1;i--)
no[i]=(no[i+1]+1LL*power[i]*(s[i]-'0')%p)%p,mp[i]=no[i];mp[n+1]=0;
sort(mp+1,mp+1+n+1);len=unique(mp+1,mp+n+1+1)-mp-1;sort(q+1,q+m+1);
for(int i=1;i<=n+1;i++) no[i]=lower_bound(mp+1,mp+len+1,no[i])-mp;
for(int i=1,l=1,r=0;i<=m;i++){
for(;l<q[i].l;l++) change(l  ,-1);
for(;l>q[i].l;l--) change(l-1, 1);
for(;r<q[i].r;r++) change(r+1, 1);
for(;r>q[i].r;r--) change(r  ,-1);
ans[q[i].num]=tmp;
}
for(int i=1;i<=m;i++)
printf("%lld\n",ans[i]);
return 0;
}

Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.nextLine();

		if(n.equals("SUN")){
			System.out.println("7");
		}else if(n.equals("MON")){
			System.out.println("6");
		}else if(n.equals("TUE")){
			System.out.println("5");
		}else if(n.equals("WED")){
			System.out.println("4");
		}else if(n.equals("THU")){
			System.out.println("3");
		}else if(n.equals("FRI")){
			System.out.println("2");
		}else if(n.equals("SAT")){
			System.out.println("1");
		}
	}
}

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

int main(void) {
	
	ll a;
	float b;

	cin >> a >> b;

	ll v;

	v = (a *(ll)(b * 100 + 0.5))/100;
	printf("%lld", v);

	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using vi = vector<long>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main(){
  long long n,m,l,sum;
  cin >> n >> m >>l;
  vvi a(n,vi(m));
  vvi b(m,vi(l));
  for(int i = 0;i<n;i++){
    for(int j = 0;j<m;j++){
      cin >> a.at(i).at(j);
    }
  }
  rep(j,m){
    rep(k,l){
      cin >> b.at(j).at(k);
    }
  }
  rep(i,n){
    rep(k,l){
      sum = 0;
      rep(j,m){
        sum += a[i][j]*b[j][k];
      }
      if(k != l-1){
        cout << sum << " ";
      }else{
        cout << sum << endl;
      }
    }
  }
  return 0;
}



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

#define get(a) scanf("%lld", &a);
#define print(a) printf("%lld",a)
#define println(a) printf("%lld\n",a)

#define do(i,a) for(long long i = 0; i < a; i++)
#define loop() for(;;) 
#define done return 0
long long n,ans;

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

int main() {
    get(n);
    do(i,n) do(j,n) do(k,n) {
        ans += gcd(gcd(i+1,j+1),k+1);
    }
    print(ans);
}

Measured memory_bytes: 3812
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

class edge {
public:
  i64 from;
  i64 to;
  i64 color;
  friend std::istream& operator>>(std::istream& is, edge& self) {
    is >> self.from >> self.to;
    --self.from;
    --self.to;
    return is;
  }
};

class directed_edge {
public:
  edge& indirected;
  bool inversed;
  directed_edge(edge& indirected, const bool& inversed) :
    indirected(indirected),
    inversed(inversed) {
  }
  i64 from() const {
    return this->inversed ? this->indirected.to : this->indirected.from;
  }
  i64 to() const {
    return this->inversed ? this->indirected.from : this->indirected.to;
  }
};

int main() {
  i64 N;
  std::cin >> N;
  std::vector<edge> edges;
  tools::read(edges, N - 1);

  std::vector<std::vector<directed_edge>> graph(N);
  for (edge& edge : edges) {
    graph[edge.from].emplace_back(edge, false);
    graph[edge.to].emplace_back(edge, true);
  }

  const i64 root = std::distance(graph.begin(), std::max_element(graph.begin(), graph.end(), [](const std::vector<directed_edge>& x, const std::vector<directed_edge>& y) {
    return x.size() < y.size();
  }));
  const i64 K = graph[root].size();

  std::vector<bool> planned_to_visit(N, false);
  planned_to_visit[root] = true;
  std::queue<i64> queue({root});
  std::vector<i64> vertex_colors(N, 0);
  while (!queue.empty()) {
    const i64 curr = queue.front();
    queue.pop();

    i64 next_color = 1;
    for (const directed_edge& edge : graph[curr]) {
      if (!planned_to_visit[edge.to()]) {
        if (next_color == vertex_colors[curr]) {
          ++next_color;
        }
        vertex_colors[edge.to()] = next_color;
        edge.indirected.color = next_color;
        ++next_color;

        queue.push(edge.to());
        planned_to_visit[edge.to()] = true;
      }
    }
  }

  std::cout << K << std::endl;
  for (const edge& edge : edges) {
    std::cout << edge.color << std::endl;
  }
  return 0;
}

Measured memory_bytes: 11136
package main

import (
	"fmt"
)

func main() {
	var x, y int64
	fmt.Scan(&x, &y)

	if x%y == 0 {
		fmt.Println(-1)
		return
	}

	var z int64
	for i := 2; z <= x*y; i++ {
		z = x * int64(i)
		if z%y > 0 {
			fmt.Println(z)
			return
		}
	}
	fmt.Println(-1)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

【Yesになるべき。NoでもACしたパターン】
4
(
)((
))((((
))))
*/

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

  ll N; cin >> N;
  ll L=0, R=0;
  vector<pair<ll,ll>> plus(0, {0,0}), minus(0, {0,0});
  rep(i, N){
    string S; cin>>S;
    ll q=0, p=0, ssz = S.size();
    for (ll j=0; j<ssz; j++){
      if (S[j] == '(')
        p++;
      else{
        if (p) p--;
        else q++;
      }
    }
    if (q==0)
      R += p;
    else if (p==0)
      L += q;
    else{
      ll tmp = p-q; //プラスなら '(' が回復
      if (tmp > 0)
        plus.push_back({q, p});
      else
        minus.push_back({q, p});
    }
  }
  bool ans = true;
  sort(all(plus));
  sort(all(minus));
  reverse(all(minus));
  ll psz = plus.size();
  //まず回復パターン。弱い攻撃から受ける
  rep(i, psz){
    R -= plus[i].first;
    if (R < 0){
      ans = false;
      break;
    }
    R += plus[i].second;
  }
  //防御パターン。大きい攻撃から受ける
  ll msz = minus.size();
  rep(i, msz){
    R -= minus[i].first;
    if (R < 0){
      ans = false;
      break;
    }
    R += minus[i].second;
  }
  R -= L;
  if (R != 0)
    ans = false;
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 7348
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int h,a;
int main(){
	ios::sync_with_stdio(false);
	cin>>h>>a;
	if (h%a==0) cout<<h/a<<endl;
	else cout<<(h/a)+1<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

signed main()
{ // #define int long long ?????????????????§scanf???????????¨???????????????????????\?????????????????????
    int N, M; cin >> N >> M;

    ll sum = 0;

    rep(i, N) {
        cout << "lst " << i << endl;
        int k; cin >> k;
        rep(j, k) {
            int tmp;
            cin >>tmp;
        }
        sum += k * (k - 1);
    }

    cout << "ans " << sum << endl;
}

Measured memory_bytes: 1280
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def main():
  n = I()
  a = [I() for _ in range(n)]
  dp = [inf]*n
  for i in range(n):
    r = br(dp,-a[i])
    dp[r] = -a[i]
  print(n-dp.count(inf))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 48476
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    
    ans += min(a,d), d-=a;
    if(d > 0) d -= b;
    if(d > 0) ans -= d;
    
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm> 
#include <cmath>
#include <numeric>
#include <queue>

using namespace std;


int main(void){
    // Your code here!
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<long long int> p(a);
    vector<long long int> q(b);
    vector<long long int> r(c);
    for(int i=0; i<a; i++) cin >> p[i];
    for(int i=0; i<b; i++) cin >> q[i];
    for(int i=0; i<c; i++) cin >> r[i];
    
    sort(p.begin(), p.end(), greater<long long int>());
    sort(q.begin(), q.end(), greater<long long int>());
    sort(r.begin(), r.end(), greater<long long int>());
    
    /*
    for(int i=0; i<a; i++) cout << p[i];
    for(int i=0; i<b; i++) cout << q[i];
    for(int i=0; i<c; i++) cout << r[i];
    */
    
    priority_queue<long long int, vector<long long int>, greater<long long int>> pq_p, pq_q;
    for(int i=0; i<x; i++) pq_p.push(p[i]);
    for(int i=0; i<y; i++) pq_q.push(q[i]);
    
    for(int i=0; i<c; i++) {
        if(pq_p.top() > pq_q.top()) {
            //緑を入れ替える
            if(pq_q.top() < r[i]) {
                pq_q.pop();
                pq_q.push(r[i]);
            }else {
                break;
            }
        } else {
            if(pq_p.top() < r[i]) {
                pq_p.pop();
                pq_p.push(r[i]);
            }else {
                break;
            }
        }
    }
    long long int sum = 0;
    while(!pq_p.empty()) {
        sum += pq_p.top();
        pq_p.pop();
    }
    while(!pq_q.empty()) {
        sum += pq_q.top();
        pq_q.pop();
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

const ll INF = 1e9;

struct edge
{
    int to;
    int cost;
};

vector<ll> dist(100010, INF);
vector<vector<edge>> G(100010, vector<edge>());

void dijkstra(const vector<vector<edge>> &G, int s)
{
    priority_queue<P,vector<P>,greater<P>> que;
    dist[s] = 0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        int d =  p.first;
        if(dist[v] < d) continue;
        for(auto e : G[v]) {
            if(dist[e.to] > dist[v]+e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to],e.to));
            }
        }
    }
}

int main()
{
    int V,E,r;
    cin >> V >> E >> r;
    REP(i,E) {
        int s,t,d;
        cin >> s >> t >> d;
        G[s].push_back(edge{t,d});
    }
    dijkstra(G,r);
    REP(i,V) {
        if(dist[i] == INF) cout << "INF" << endl;
        else cout << dist[i] << endl;
    } 
}



Measured memory_bytes: 13440
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
}


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

constexpr int64_t mod = 1000000007;
vector<int64_t> fact, inv;

int64_t power(int64_t n, int64_t k) {
  if (k == 0) return 1;
  int64_t res = power(n * n % mod, k / 2);
  if (k % 2) res = res * n % mod;
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % mod);
    inv.push_back(power(fact.at(i + 1), mod - 2));
  }
}

int64_t ncr(int64_t n, int64_t r) {
  if (r < 0 or n < r) return 0;
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}

int main() {
  int n, i0, i1, d;
  cin >> n;
  init(n + 1);
  vector<int> a(n + 1), v(n, -1);
  for (int i = 0; i <= n; i++) {
    cin >> a.at(i);
    if (v.at(a.at(i) - 1) != -1) {
      i1 = i;
      i0 = v.at(a.at(i) - 1);
      d = i1 - i0;
    }
    v.at(a.at(i) - 1) = i;
  }
  for (int k = 1; k <= n + 1; k++) {
    cout << (ncr(n + 1, k) - ncr(n - d, k - 1) + mod) % mod << endl;
  }
}


Measured memory_bytes: 3564
#include <stdio.h>
#define M 37

typedef struct TT{
    char suit;
    int value;
}T;

int N;
T card_s[M],card_b[M];

void BubbleSort(void){
    int i;
    for(i=0;i<N;i++){
        for(int j=N-1;j>i;j--){
            if(card_b[j].value < card_b[j-1].value){
                int a;
                char b;
                a = card_b[j].value;
                card_b[j].value = card_b[j-1].value;
                card_b[j-1].value = a;
                b= card_b[j].suit;
                card_b[j].suit=card_b[j-1].suit;
                card_b[j-1].suit=b;
            }
        }
    }
}

void SelectionSort(void){
    int i,minj,j;
    for(i=0;i<N;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(card_s[j].value < card_s[minj].value){
                minj=j;
            }
        }
        int a;
        char b;
        a=card_s[i].value;
        card_s[i].value=card_s[minj].value;
        card_s[minj].value=a;
        b=card_s[i].suit;
        card_s[i].suit=card_s[minj].suit;
        card_s[minj].suit=b;
    }
}

int main(void){
    int i,ct=0;
    char p;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%c%c%d",&p,&card_b[i].suit,&card_b[i].value);
        card_s[i].suit=card_b[i].suit;
        card_s[i].value = card_b[i].value;
    }
    BubbleSort();
    SelectionSort();
    for(i=0;i<N;i++){
        printf("%c%d",card_b[i].suit,card_b[i].value);
        if(i!=N-1)printf(" ");
    }
    printf("\nStable\n");

    for(i=0;i<N;i++){
        printf("%c%d",card_s[i].suit,card_s[i].value);
        if(i!=N-1)printf(" ");
    }
    for(i=0;i<N;i++){
        if(card_b[i].suit != card_s[i].suit){
            ct++;
        }
    }
    if(ct!=0)printf("\nNot stable\n");
    else printf("\nStable\n");
    return 0;
}



Measured memory_bytes: 2144
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
int a[214514];
signed main(){
	int n;
	cin>>n;
	if(n%2==1)c(0)
	else{
		int nn=n/10;
		int nnn=nn;
		int ans=0;
		rep(0,i,100){
			ans+=nn/5;
			nn=nn/5;
		}
		c(ans+nnn)
	}
}						


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;


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

    int ans = 0;
    for(int i = 0; i < n; i++){
        while(a[i]%2==0){
            a[i] = a[i]/2;
            ans++;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
def expand_result(result, h, t):
    if t <= 0:
        result.append(0)
    elif t == 1:
        result.append(abs(h[1] - h[0]))
    else:
        result.append(min(result[t - 1] + abs(h[t] - h[t - 1]), result[t - 2] + abs(h[t] - h[t - 2])))
    return result

n = int(input())
h = input().split(" ")
h = list(map(int, h))
result = []
for i in range(n):
    result = expand_result(result, h, i)
print(result[n - 1])

Measured memory_bytes: 13980
#include <stdio.h>

long N, x;
long cnt=0;

int main()
{
    scanf("%ld %ld", &N, &x);

    long a[N];
    for (int i=0; i<N; i++) scanf("%ld", a+i);

    if (a[0] > x)
    {
        cnt+=a[0]-x;
        a[0]=x;
    }

    for (int i=1; i<N; i++)
    {
        if (a[i-1]+a[i] > x)
        {
            cnt += a[i-1]+a[i]-x;
            a[i] = x - a[i-1];
        }
    }
    printf("%ld", cnt);

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <map> 
using namespace std;
int main() {
	int n, m, x, y, ans = 1, red = 1;
	cin >> n >> m;
	vector<int> v(n + 1, 1);
	map<int, int> may;
	may[1] = 1;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		v[x]--;
		v[y]++;
		if (may.count(x)) {
			if (!v[x]) may.erase(x);
			may[y] = v[y];
		}
	}
	cout << may.size();
	return 0;
}

Measured memory_bytes: 5376
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

struct unionfind{
  vector<int> par;
  unionfind(int n):par(n,-1){}
  void init(int n){par.assign(n,-1);}
  int root(int x){
    if(par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  bool issame(int x,int y){
    return root(x)==root(y);
  }
  bool merge(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(par[x]>par[y]) swap(x,y);
    par[x]+=par[y];
    par[y]=x;
    return true;
  }
  int size(int x){
    return -par[root(x)];
  }
};

int main(){
  int n,m; cin >> n >> m;
  unionfind uf(n);
  vector<pii> uni(m);
  rep(i,m){
    int a,b; cin >> a >> b;
    a-- ; b--;
    uni[i]=pii(a,b);
  }
  int ans=0;
  rep(i,m){
    uf.init(n);
    rep(j,m){
      if(i==j) continue;
      int a,b;
      tie(a,b)=uni[j];
      uf.merge(a,b);
    }
    if(uf.size(0)!=n) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, a, b;
  cin >> n >> a >> b;
  ll xx = n/(a+b); 
  ll rem = n - (xx*(a + b));
  ll ans = xx*a + min(a, rem);
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;

int main()
{
  int N, M;
  cin >> N >> M;
  cout << (N * (N - 1)) / 2 + (M * (M - 1)) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2002 , P = 1e9 + 7;
inline void pp(int &x,int d){if((x+=d)>=P)x-=P;}
int n , K , comb[N][N] , f[N][N] , g[N] , pw2[N];

int main(){
  cin >> n >> K;
  rep(i,0,n+1) rep(j,0,i+1) comb[i][j]=j?(comb[i-1][j-1]+comb[i-1][j])%P:1;
  pw2[0]=1;rep(i,1,n+1) pw2[i]=pw2[i-1]*2%P;
  g[0] = 1;
  rep(i,0,n+1) rep(j,0,n-i+1) f[i][j]=g[i+j],pp(g[i+j+1],f[i][j]);
  if(n == K) cout << f[n-1][0] << endl;
  else {
    int ans = 0;
    rep(m,2,n+1) {
      int sum = m - 2 , choose = n - K - 1;
      if(sum < choose) continue;
      int tmp = ll(comb[sum][choose]) * f[n-m][m-2-choose] % P * pw2[choose] % P;
      pp(ans , tmp);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 31744
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
const int N=105;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Min(int &x,int y){x=min(x,y);}
void Max(int &x,int y){x=max(x,y);}
int n,minn=2e9,maxn=-2e9;
int main(){
	int n=read();
	rep(i,1,n){int k=read();Min(minn,k),Max(maxn,k);}
	printf("%d\n",maxn-minn);
	return 0;
}

Measured memory_bytes: 256
a,b,c,n = tuple(int(x) for x in raw_input().split(' '))

ans = 0
for i in xrange(0, n/a+1):
  for j in xrange(0, n/b+1):
    k = (n - i*a - j*b)/c
    #print i,j,k,i*a+j*b+k*c
    if i*a+j*b+k*c == n and k >= 0:
      ans += 1
print ans


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

#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define clr(x) memset((x), 0, sizeof((x)));
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long i64;
typedef unsigned long long ull;

template<class T>
bool remin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool remax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

ll gcd(ll a, ll b) {
    a = abs(a);
    b = abs(b);
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

typedef ll ptdata;

struct pt {
    ptdata x, y;

    pt() { }

    pt(ptdata x, ptdata y) : x(x), y(y) { }

    inline pt operator-(const pt &r) const {
        return pt(x - r.x, y - r.y);
    }

    inline pt operator+(const pt &r) const {
        return pt(x + r.x, y + r.y);
    }

    inline pt operator*(const ptdata &r) const {
        return pt(x * r, y * r);
    }

    inline ptdata sqlen() const {
        return abs(x * x + y * y);
    }

    inline bool operator<(const pt &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }

    inline bool operator==(const pt &r) const {
        return x == r.x && y == r.y;
    }
};

ostream &operator<<(ostream &os, const pt &p) {
    return os << "(" << p.x << "," << p.y << ")";
}

inline ptdata cross(const pt &l, const pt &r) {
    return l.x * r.y - l.y * r.x;
}

inline ptdata dot(const pt &l, const pt &r) {
    return l.x * r.x + l.y * r.y;
}


ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

template<typename T>
inline T sqr(T x) {
    return x * x;
}


inline void solve() {
    int a = nxt();
    int b = nxt();
    if (a <= 0 && b >= 0) {
        cout << "Zero\n";
        return;
    }
    if (a > 0) {
        cout << "Positive\n";
        return;
    }
    a = -a;
    b = -b;
    swap(a, b);
    int cnt = b - a + 1;
    if (cnt & 1) {
        cout << "Negative\n";
    } else {
        cout << "Positive\n";
    }
}

void prepare() {

}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    prepare();

    int t = 1;
    //t = nxt();
    forn(i, t) {
        solve();
    }

    //cerr << "Time " << clock() / (double) CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 764
import Data.List
import Data.Ord

solve :: Int -> Int -> [Int] -> Int
solve n m xs
  | n >= m = 0
  | True = sum $ drop (n - 1) $ sortBy (comparing Down) $ map (\(x, y) -> x - y) $ zip rs xs
  where
    _:rs = xs


main :: IO()
main = do
  (n:m:_) <- fmap (\s -> read s :: Int) <$> words <$> getLine
  xs <- fmap (\s -> read s :: Int) <$> words <$> getLine
  print $ solve n m $ sort xs


Measured memory_bytes: 32636
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template

def main():
    n = int(input())
    abc = [list(map(int, input().split())) for _ in range(n)]

    a, b, c = 0, 0, 0
    for x, y, z in abc:
        a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z

    print(max(a, b, c))



if __name__ == "__main__":
    main()



Measured memory_bytes: 40452
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


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

typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	sort(a.begin(),a.end());

	double mid = a[n-1]/2.0;

	int d = 1e9;
	int ans=0;
	rep(i,n-1){
		if(abs(a[i]-mid) < d){ ans=a[i]; d=abs(a[i]-mid); }
	}
	cout << a[n-1] <<" "<< ans << endl;

	return 0;
}

Measured memory_bytes: 640
inf = float('inf')

N = int(input())
D = sorted(map(int,input().split()), reverse=True) + [0]
N += 1

for i in range(N):
    if i % 2 == 0:
        D[i] = 24 - D[i]

ans = inf
for i in range(N):
    for j in range(i+1, N):
        d = abs(D[i] - D[j])
        d = min(d, 24 - d)
        ans = min(ans, d)

print(ans)

Measured memory_bytes: 3064
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[100101];
int sum[1010];
int main()
{
	int n,i,ans=1;
	scanf("%d",&n);
	scanf("%s",a+1);
	for(i=1;i<=n;i++)
		sum[a[i]-'a']++;
	for(i=0;i<26;i++)
		ans=(long long)ans*(sum[i]+1)%1000000007;
	printf("%d\n",ans-1);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 384
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')

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

int main(){
    int n;
    cin >> n;
    int mi=inf;
    int ma=0;
    rep(i,n){
        int a;
        cin >> a;
        mi=min(mi,a);
        ma=max(ma,a);
    }
    cout << ma-mi << endl;
    return 0;
}

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

typedef long long lli;
typedef pair<lli,lli> pll;
typedef vector<lli> vcL;
typedef vector<pll> vPL;


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

	if ( n < 1200 ) cout << "ABC\n";
	else if ( n < 2800 ) cout << "ARC\n";
	else cout << "AGC\n";
}

int main() {
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}



Measured memory_bytes: 256