akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Solver extends Main{
	Solver(){

	}
}

class Main{
	int imax=Integer.MAX_VALUE;
	long lmax=Long.MAX_VALUE;
	public static void main(String[] args) throws FileNotFoundException{
		Scanner sc=new Scanner(System.in);
		int[] num=readlnI(sc," ");
		int[] adj=new int[num[0]];
		int[] data=new int[2];
		for(int i=0; i<num[1]; i++){
			data=readlnI(sc," ");
			adj[data[0]-1]+=1;
			adj[data[1]-1]+=1;
		}
		for(int a: adj) puts(a);
	}	
	
	//utility
	static int[] readlnI(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToInt(Integer::parseInt).toArray();
	}
	static long[] readlnL(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToLong(Long::parseLong).toArray();
	}
	static int readI(Scanner sc){
		return Integer.parseInt(sc.nextLine().trim());
	}
	static String[] readS(Scanner sc, String dl){
		return sc.nextLine().trim().split(dl);
	}
	static String nextS(Scanner sc){
		return sc.nextLine().trim();
	}
	@SuppressWarnings("unchecked")
	static <T> void puts(T... args){
		for(int i=0; i<args.length-1; i++){
			System.out.printf("%s ",args[i]);
		}
		System.out.println(args[args.length-1]);
	}
	static void puts(int[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void puts(long[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void tblSort(int[][] tbl){
		Arrays.sort(tbl, new Comparator<int[]>(){
			@Override
			public int compare(int[] a, int[] b){
				if(a[0]==b[0]){
					return b[1]-a[1];
				}else{
					return b[0]-a[0];
				}
			}
		});
	}
}


Measured memory_bytes: 28884
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}

int main(){
    int Q; cin >> Q;
    while(Q--) {
        ll A, B; cin >> A >> B;
        if(A==B) {
            cout << 2*(A-1) << endl;
            continue;
        }
        if(A>B) swap(A,B); // A<=B
        ll C = A*B;
        ll ub = A + B - 1;
        ll lb = A - 1;
        ll mid;
        while(ub-lb>1) {
            mid = (ub + lb) / 2;
            if(((mid+1)/2)*(mid+1-(mid+1)/2)<C) lb = mid;
            else ub = mid;
        }
        cout << lb-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    int N = S.size();

    if(count(S.begin(), S.end(), '0') == N || count(S.begin(), S.end(), '0') == 0) {
        cout << N << endl;
    } else {
        int low = 1;
        int high = N;
        while(high > low+1) {
            int mid = (low + high) / 2;
            if(count(S.end()-mid, S.begin()+mid, '0') == 2*mid-N || count(S.end()-mid, S.begin()+mid, '0') == 0) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low << endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end(), greater<int>());

  int alice = 0;
  int bob = 0;
  
  for(int j=0; j<N; j++){
    if(!(j&1)){
      alice += vec.at(j);
    } else {
      bob += vec.at(j);
    }
  }
  
  cout << alice - bob;

  return 0;
}

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

int main(){
  ll n , m;
  cin >> n >> m;
  vector<ll>a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(),a.end());
  
  vector<vector<ll>>b(m,vector<ll>(2));
  for(int i=0; i<m; i++) cin >> b[i][1] >> b[i][0];
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  
  ll x = 0;
  for(int i=0; i<m; i++){
    for(int j=0; j<b[i][1]; j++){
      if(a[x]>=b[i][0] || x==n) break;
      a[x]=b[i][0];
      x++;
    }
  }
  
  ll ans=0;
  for(int i=0; i<n; i++) ans+=a[i];
  
  cout << ans << endl;
  
  return 0;
  
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"


template <typename T, typename K> struct P {
	T a; K b;
};

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
vector <P <ll, ll> >prime_factorize( ll N );
ll pow( ll a, ll n );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
int main( void ){
	// initialize();
	int N, D;
	cin >> N >> D;
	D = 2 * D + 1;
	cout << N / D + (( N % D ) > 0 ) << endl;

}

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

/*
 * @fn eratosthenes
 * @brief O(NloglogN)~=(N)
 * @param N: その数まで
 * @return 0 or 1 の配列 (boolは都合が悪い)
 */
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}

/*
 * @fn prime_factorize
 * @brief O(√N): 素因数分解
 * @param N: 素因数分解する数
 * @return vec: (a: 素数, b: 個数)
 */
vector <P <ll, ll> >prime_factorize( ll N ){
	vector <P <ll, ll> > vec;
	int lim = sqrt( N ) + 1;
	rep( i, 2, N + 1 ){
		if (i >= lim){
			vec.push_back( P <ll, ll>{N, 1} );
			break;
		}
		if (N % i == 0){
			vec.push_back( P <ll, ll>{i, 0} );
			while(N % i == 0){
				N /= i;
				vec.back().b++;
			}
		}
	}
	return vec;
}
/*
 * @fn pow
 * @brief a^n
 * @param a: 基数
 * @param n: 指数
 */
ll pow( ll a, ll n ) {
	ll res = 1;
	while (n > 0){
		if (n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>

struct Vector {
        static const int VECSIZE = 200000 + 10;
        int A[VECSIZE];
        int top = -1;

        void pushBack(int v) {
                A[++top] = v;
        }

        int randomAccess(int i) {
                assert(i <= top);
                return A[i];
        }

        void popBack() {
                top--;
        }
};

int main()
{
        Vector vi;
        int q;
        std::cin >> q;
        while (q--) {
                int op;
                std::cin >> op;
                if (op == 0) {
                        int v;
                        std::cin >> v;
                        vi.pushBack(v);
                } else if (op == 1) {
                        int i;
                        std::cin >> i;
                        std::cout << vi.randomAccess(i) << std::endl;
                } else {
                        vi.popBack();
                }
        }

        return 0;
}


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

int main()
{

        int N;
        int K;
        cin >> N >> K;
        unsigned int H[N];
        for (int i = 0; i < N; ++i) {
                cin >> H[i];
        }
        sort(H, H+N, std::greater<int>());
        for (int i = 0; i < K; ++i) {
                if (i == N) {
                        break;
                }
                H[i] = 0;
        }
        long long num = 0;
        for (int  i = 0; i < N; ++i) {
                num += H[i];
        }
        cout << num << endl;

}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int ac=0,wa=0,tle=0,re=0;
	int j;
	for(j=0;j<n;j++)
	{
		string str;
		cin>>str;
		if(str=="AC")
		   ac++;
		else if(str=="WA")
		    wa++;
		else if(str=="TLE")
		    tle++;
		else
		   re++;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3644
n = input()
m = map(int, raw_input().split())
memo = [[0]*21 for i in range(n-1)]
memo[0][m[0]] = 1
for i in range(1,n-1):
    for k in range(21):
        if 0 <= k + m[i] <= 20:
            memo[i][k + m[i]] += memo[i-1][k]
        if 0 <= k - m[i] <= 20:
            memo[i][k - m[i]] += memo[i-1][k]
print memo[n-2][m[n-1]]

Measured memory_bytes: 6444
#include <iostream>
using namespace std;
int main()
{
    int i,j;
    int sum[101]={0};
    int m,n,a[101][101]={0};
    cin>>m>>n;
    for(i=0; i<m; i++){
        for(j=0; j<n; j++){
            cin>>a[i][j];
            a[i][n]=a[i][n]+a[i][j];
        }
    }
    for(j=0; j<=n; j++){
        for(i=0; i<m; i++){
            a[m][j]=a[m][j]+a[i][j];
        }
    }
    for(i=0; i<=m; i++){
        for(j=0; j<n; j++){
        cout<<a[i][j]<<" ";
        }
         cout<<a[i][n]<<endl;
    }
    return 0;

}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,u,v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> a(n-1),b(n-1);
  rep(i,n-1){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  vector<vector<int>> edge(n);
  rep(i,n-1){
    edge[a[i]].push_back(b[i]);
    edge[b[i]].push_back(a[i]);    
  }
  
  vector<bool> f(n,false);
  vector<int> da(n,0),dt(n,0);

  queue<pair<int,int>> qa;
  qa.push(make_pair(v,0));
  while(!qa.empty()){
    int node = qa.front().first;
    int cnt = qa.front().second;    
    qa.pop();
    f[node] = true;
    for(auto w:edge[node]){
      if(f[w]) continue;
      da[w]=cnt+1;
      qa.push(make_pair(w,cnt+1));
    }
  }

  f.assign(n,false);
  queue<pair<int,int>> qt;
  qt.push(make_pair(u,0));
  while(!qt.empty()){
    int node = qt.front().first;
    int cnt = qt.front().second;    
    qt.pop();
    f[node] = true;
    for(auto w:edge[node]){
      if(f[w]) continue;
      dt[w]=cnt+1;
      qt.push(make_pair(w,cnt+1));
    }
  }

  int res = 0;
  rep(i,n){
    if(dt[i]<da[i]){
      res = max(res,da[i]-1);
    }
  }

  cout << res << "\n";
  
  
  // rep(i,n){
  //   cout << i << ":" << da[i] << "\n";
  // }
  // rep(i,n){
  //   cout << i << ":" << dt[i] << "\n";
  // }  
  
  
  return 0;
}


Measured memory_bytes: 7552
n = [int(i) for i in input().split()]
child = n[0]
candy = n[1]

distribute_candy = sorted([int(i) for i in input().split()])
distribute_candy.sort()

delighted_child = 0

for j in range(child):
    if child - 1 == j:
        if distribute_candy[j] == candy:
            delighted_child += 1
            break
        else:
            break
    if candy - distribute_candy[j] >= 0:
        delighted_child += 1
        candy = candy - distribute_candy[j]

print(delighted_child)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 200005
//<<fixed << setprecision(9)

vi G[space];
bool vis[space];
int dfs(int n)
{
    int cnt=1;
    vis[n]=1;
    for(auto z:G[n])
    {
        if(!vis[z]) cnt+=dfs(z);
    }
    return cnt;
}
int main()
{
    int n,i,j,t;
    boost;

    int m;
    cin>>n>>m;

    rep(i,0,m)
    {
        int u,v;
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }
    int mx=0;
    rep(i,1,n+1)
    {
        if(!vis[i]) mx=max(mx,dfs(i));
    }
    cout<<mx;
    return 0;
}

Measured memory_bytes: 24076
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string S,T;
    string ans = "";
    cin >> S >> T;
    
    for ( int i = S.length()-T.length(); i >= 0; i-- ) {
        
        string s = S.substr( i, T.length() );
        
        bool is_match = true;
        for ( int j = 0; j < s.length(); j++ ) {
            if ( s[j] == '?' ) { continue; }
            if ( s[j] != T[j] ) { is_match = false; break; }
        }
        if ( is_match ) {            
            ans = S;
            ans.replace( i, T.length(), T );            
            break;
        }        
    }
    
    if ( ans.length() == 0 ) { cout << "UNRESTORABLE" << endl; }
    else {
        for ( int i = 0; i < ans.length(); i++ ) {
            if ( ans[i] == '?' ) { ans.replace( i, 1, "a" ); }
        }
        cout << ans << endl;
    }
    
    
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y)
{
    return x / gcd(x, y) * y;
}

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ret = b - (b / c + b / d - b / lcm(c, d));
    ret -= (a - 1) - ((a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d));
    cout << ret << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>?) {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val dolls = IntArray(n){ readLine()!!.toInt()}
    val count = IntArray(m){0}
    val sumCount = Array(m){IntArray(n){0} }
    for (i in dolls.indices) {
        count[dolls[i] - 1]++
        sumCount[dolls[i] - 1][i]++
        if (i > 0) for (j in sumCount.indices) {
            sumCount[j][i] += sumCount[j][i - 1]
        }
    }
    val memo = IntArray(1 shl m){Int.MAX_VALUE}
    memo[0] = 0
    for (i in memo.indices) {
        val left = (0 until m).filter{i and (1 shl it) != 0}.sumBy(count::get)
        for (j in 0 until m) if (i and (1 shl j) == 0) {
            val right = left + count[j] - 1
            val sum = if (left > 0) sumCount[j][right] - sumCount[j][left - 1] else sumCount[j][right]
            memo[i or (1 shl j)] = java.lang.Math.min(memo[i or (1 shl j)], memo[i] + (count[j] - sum))
        }
    }
    println(memo.last())
}


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

int main() {
  int n;
  cin >> n;
  for(int i = 1; i < 10; i++) {
    for(int j = 1; j < 10; j++) {
      if(i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <array>
#include <memory>

using namespace std;

#define Get(ty,...) ty __VA_ARGS__;cins(__VA_ARGS__);
#define GetArray(ty,v,n) vector<ty> v(n);cin_arr(v,n);
#define ci cin
#define co cout
#define en endl;
#define Arr(f, arr,pred) f(arr.begin(),arr.end(),pred)
#define ArrExpr(f, arr,expr) f(arr.begin(),arr.end(),[](auto x){return expr;})
#define Acc(init,arr,pred) accumulate(arr.begin(),arr.end(),init,pred)

void cins(){}

template<class Head,class... Tail>
void cins(Head& head,Tail&... tail) {
	cin >> head;
	cins(tail...);
}

template<class Arr>
void cin_arr(Arr& v,int n) {
	for (int i = 0; i < n; i++)
		cin >> v[i];
}

int ketaSum(int x, int n = 10000) {
	return n > 0 ?
		x / n + ketaSum((x / n != 0 ? x - (x / n) * n : x), n / 10)
		: 0;
}

int main() {
	Get(int, n, a, b);
	int sum = 0;
	for (int i=0; i <= n; i++) {
		int ketaSumR = ketaSum(i);
		if (a <= ketaSumR && b >= ketaSumR)
			sum += i;
	}
	co<<sum<<en
}




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

int main()
{
    int N,M,A1,sum=0,day;
    scanf("%d%d",&N,&M);

    for(int i=0;i<M;i++)
    {
        scanf("%d",&A1);
       sum=sum+A1;


    }
    if(sum<=N)
        {
            day=N-sum;
            printf("%d",day);
        }
        else{
            printf("-1");
        }

    return 0;

}


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

typedef pair<int,int> P;
const int INF = 500000000;

int main(){
    double n,m,sum = 0;
    cin >> n >> m;
    vector<double> v(n);
    for (int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    double low = sum /(4*m);
    int count = 0;
    for (int i = 0; i < n; i++){
        if (v[i] < low) continue;
        else count++;
    }
    if (count >= m){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main()
{
  int N, L;
  cin >> N >> L;

  int taste = 0;
  int abs_min = 100000;
  int eaten;
  for(int i = 0; i < N; i++){
    int score = (L + i);

    taste += score;

    if(abs_min > abs(score)){
      abs_min = abs(score);
      eaten = score;
    }
  }

  cout << (taste - eaten) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;

int N,A[200000],B[200000],res[200000];
vector<pair<int,int>>vtree[1<<19];
vector<int>v[200000];

int calc(int x){
	int t=0;
	x+=1<<18;
	while(x){
		t=max(vtree[x].back().first,t);
		x/=2;
	}
	return t;
}

void update(int l,int r,int val,int idx){
	l+=1<<18;
	r+=1<<18;
	while(l<=r){
		if(vtree[l].back().first<val){
			vtree[l].push_back({val,idx});
		}
		if(vtree[r].back().first<val){
			vtree[r].push_back({val,idx});
		}
		l=(l+1)/2;
		r=(r-1)/2;
	}
}

void erase(int l,int r,int idx){
	l+=1<<18;
	r+=1<<18;
	while(l<=r){
		if(vtree[l].back().second==idx){
			vtree[l].pop_back();
		}
		if(vtree[r].back().second==idx){
			vtree[r].pop_back();
		}
		l=(l+1)/2;
		r=(r-1)/2;
	}
}

void dfs(int x,int from){
	update(A[x]+1,(1<<18)-1,calc(A[x])+1,x);
	res[x]=calc((1<<18)-1);
	for(int i:v[x]){
		if(i==from)continue;
		dfs(i,x);
	}
	erase(A[x]+1,(1<<18)-1,x);
}

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		B[i]=A[i];
	}
	sort(B,B+N);
	for(int i=0;i<N;i++){
		A[i]=lower_bound(B,B+N,A[i])-B;
	}
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=0;i<(1<<19);i++){
		vtree[i].push_back({0,-1});
	}
	dfs(0,0);
	for(int i=0;i<N;i++){
		cout<<res[i]<<endl;
	}
}


Measured memory_bytes: 85524
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int n,l;
	
	cin >> n >> l;
	
	int a0 = l;
	int ae = l+n-1;
	int mini = 0;
	int ans = 0;
	
	//cout << "a0:" << a0 << ", ae:" << ae << endl;
	
	//両方正の場合
	if(a0 > 0 && ae > 0){
		
	//	cout << "pp" << endl;
		
		mini = min(a0,ae);
		ans = l*n+n*(n-1)/2-mini;
	} else if(a0 < 0 && ae < 0){
		
	//	cout << "mm" << endl;
		
		mini = max(a0,ae);
		ans = l*n+n*(n-1)/2-mini;
	} else {
		
	//	cout << "other" << endl;
		
		ans = l*n+n*(n-1)/2-mini;
	}
	
	cout << ans << endl;
	


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
main(){
    int a,b,c,d,e;
    scanf("%d", &a);
    b=a/100;
    if(b==1){
        c=(a-100)/10;
    }else{
        c=a/10;
    }
    d=a-b*100-c*10;
    e=b+c+d;
    printf("%d\n",e);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool flag = false;
  for (int i = 0; i < N; i++){
    char s;
    cin >> s;
    if (s == 'Y') flag = true;
  }
  if (flag) cout << "Four" << endl;
  else cout << "Three" << endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,pair<ll, ll>> P;

int d[111111][3];

void seica(ll start, vector<vector<int>> &v){
	REP(i, 111111)REP(j, 3)d[i][j] = INF;

	priority_queue<P, vector<P>, greater<P>> pq;
	d[start][0] = 0;

	pq.push(MP(0, MP(start, 0)));
	while(!pq.empty()){
		ll dist = pq.top().FI;
		ll node = pq.top().SE.FI;
		ll type = pq.top().SE.SE;
		pq.pop();
		if(dist > d[node][type])continue;

		REP(i, v[node].size()){
			if(d[v[node][i]][(type + 1)%3] > dist + 1) {
				d[v[node][i]][(type + 1)%3] = dist + 1;
				pq.push(MP(dist + 1, MP(v[node][i], (type + 1) % 3)));
			}
		}
	}
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	vector<vector<int>> v(111111);

	int n, m;cin >> n >> m;
	REP(i, m){
		ll a, b;
		cin >> a >> b;
		a--;b--;
		v[a].PB(b);
	}
	ll s, t;cin >> s >> t;
	s--;t--;
	seica(s, v);

	if(d[t][0] == INF)cout << -1 << endl;
	else cout << d[t][0] / 3 << endl;

	return 0;
}


Measured memory_bytes: 7540
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>

#define PI M_PI

typedef double Real;

Real to_radian(int degree)
{
	return degree / 180.0 * PI;
}

int main(void)
{
	Real x, y;
	int arg;
	int len, rot;
	
	x = 0.0;
	y = 0.0;
	arg = 90;
	while (scanf("%d,%d", &len, &rot), len != 0 || rot != 0){
		x += len * cos(to_radian(arg));
		y += len * sin(to_radian(arg));
		arg = (arg - rot + 360) % 360;
	}
	
	printf("%d\n%d\n", (int)x, (int)y);
	
	return (0);
}

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


int main() {

    int n; cin >> n;
    vector<int> a(n);
    vector<int> cnt(1e6+1);
    REP(i, n) {
        cin >> a[i];
        ++cnt[a[i]];
    }

    int ans = n;
    REP(i, n) {
        bool flag = false;
        if (a[i] != 1 and cnt[1]) {
            flag = true;
        }
        if (cnt[a[i]] > 1) {
            flag = true;
        }
        for (int b = 2; b * b <= a[i]; ++b) {
            if (a[i] % b) continue;
            if (cnt[b]) {
                flag = true;
                break;
            }
            if (cnt[a[i] / b]) {
                flag = true;
                break;
            }
        }
        if (flag) --ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8004
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;
int N, K;
const int MAX_N = 5100;
int ran[MAX_N+1];
int tmp[MAX_N+1];

bool compare_sa(int i, int j){
  if(ran[i] != ran[j]) return ran[i] < ran[j];
  else{
    int ri = (i+K<=N?ran[i+K]:-1);
    int rj = (j+K<=N?ran[j+K]:-1);
    return ri < rj;
  }
}
void construct_sa(string S, int *sa){
  N = S.length();
  for(int i=0;i<=N;i++){
    sa[i] = i;
    ran[i] = (i < N ? S[i]:-1);
  }
  for(K=1;K<=N;K*=2){
    sort(sa, sa+N+1, compare_sa);
    tmp[sa[0]] = 0;
    for(int i=1;i<=N;i++) tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1], sa[i])?1:0);
    for(int i=0;i<=N;i++) ran[i] = tmp[i];
  }
}
bool contain(string S, int *sa, string T){
  int a = 0, b = S.length();
  while(b - a > 1){
    int c = (a+b)/2;
    if(S.compare(sa[c], T.length(), T) < 0) a = c;
    else b = c;
  }
  return S.compare(sa[b], T.length(), T) == 0;
}
void construct_lcp(string S, int *sa, int *lcp){
  int n = S.length();
  for(int i=0;i<=n;i++) ran[sa[i]] = i;
  int h = 0;
  lcp[0] = 0;
  for(int i=0;i<n;i++){
    int j=sa[ran[i]-1];
    if(h>0) h--;
    for(;j+h<n&&i+h<n;h++){
      if(S[j+h]!=S[i+h]) break;
    }
    lcp[ran[i]-1] = h;
  }
}
int main(int argc, char const *argv[]) {
  string s;
  int ans = 0;
  std::cin >> N;
  std::cin >> s;
  int sa[MAX_N+1];
  int lcp[MAX_N+1];
  construct_sa(s, sa);
  construct_lcp(s, sa, lcp);
  lcp[N] = 0;
  /*
  for(int i=0;i<=N;i++){
    for(int j=sa[i];j<N;j++) std::cout << s[j];
    std::cout << " " << lcp[i] << '\n';
  }
  */
  for(int i=0;i<N;i++){
    int tmp=1000000007, pre = 0;
    for(int j=i;j<N;j++){
      tmp = min(tmp, lcp[j]);
      //std::cout << i << " " << j << " " << tmp << '\n';
      pre = max(pre, min(abs(sa[i]-sa[j+1]), tmp));
      //std::cout << sa[i] << " " << sa[j+1] << '\n';
      //std::cout << pre << '\n';
    }
    if(tmp>=10000) continue;
    ans = max(ans, pre);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 512
N = int(input())

xyh = []
for i in range(N):
    xyh.append(list(map(int, input().split())))

#
#すべての条件についてある入力からhを求める
#そのhについて、その他の条件をすべて満たせればOK
ans_x, ans_y, ans_h = -1,-1,-1
indexes = [i for i, x in enumerate(xyh) if x[2] > 0]

for cx in range(101):
    for cy in range(101):
        H = xyh[indexes[-1]][2] + abs(xyh[indexes[-1]][0] - cx) + abs(xyh[indexes[-1]][1] - cy)
        match = 1
        for i in range(N):
            h = H - abs(xyh[i][0] - cx) - abs(xyh[i][1] - cy)
            if xyh[i][2] > 0 and (h != xyh[i][2]):
                match = 0
            if xyh[i][2] == 0 and (H > (abs(xyh[i][0] - cx) + abs(xyh[i][1] - cy)) ):
                match = 0
        
        if match:
            ans_x = cx
            ans_y = cy
            ans_h = H
            
print(str(ans_x) + ' ' + str(ans_y) + ' ' + str(ans_h))

Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <cstring>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

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

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 5e3 + 4;
const double EPS = 1e-3;
const int mod = 1e9 + 7;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const double pi = 3.14159265359;

int a, b, h, m;

inline void read() {
    cin >> a >> b >> h >> m;
}

inline void solve() {
    cout << fixed << setprecision(10);
    double hh = 30 * h + 1. * m / 2;
    double mm = m * 6;

    double angle = fabs(hh - mm) * pi / 180;
    angle = min(angle, 2 * pi - angle);
    cout << sqrt(a * a + b * b - 2 * cos(angle) * a * b) << "\n";
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

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

    return 0;
}

Measured memory_bytes: 4248
/*
Hanit Banga
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 5, M = 100;

int ans[2*M + 5] = {0};

int f(int l, int r, int k, ll x);

int main()
{
	ll n;
	cin >> n;
	int smallest = f(1, M, M, n + 1);
	cout << 2 * (M - smallest + 1) << endl;
	for (int i = 1; i <= M; ++i)
		if (ans[i])
			cout << ans[i] << ' ';

	for (int i = smallest; i <= M; ++i)
		cout << i << ' ';
}

int f(int l, int r, int k, ll x)
{
	if (x == 1)
		return M;

	if (x % 2 == 0)
	{
		ans[r] = k;
		return min(f(l, r - 1, k - 1, x / 2), k);
	}

	ans[l] = k;
	return min(f(l + 1, r, k - 1, x - 1), k);
}

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

using namespace std;



void solver() {
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for(int i = 0; i < s.size(); ++i)
        cnt += (s[i] != t[i]);
    cout << cnt <<'\n';
}

int main() {

    ios_base :: sync_with_stdio(0); cin.tie(NULL);

    int t;
    //cin >> t;
    t = 1;

    while(t--)
        solver();

    return 0;
}

Measured memory_bytes: 3800
#include <stdio.h>
#include <stdlib.h>
#define START(a) (a>0?a:0)
int s,ans,ttt,a,b,c,t[1001][3001];
int main(void){
	for(a=0;a<=1000;a++){for(b=0;b<=3000;b++){t[a][b]=-1;}}
	while(scanf("%d",&s)!=EOF){
		ans=0;
		for(a=START(s-3000);a<=1000 && s>=a;a++){
			if(t[a][s-a]>0)ans+=t[a][s-a];
			else{
				ttt=0;
				for(b=START(s-a-2000);b<=1000 && s>=a+b;b++){ttt+=1001-abs(1000-(s-a-b));}
				t[a][s-a]=ttt;
				ans+=ttt;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 12332
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut ans = vec![0; n];

    for i in (1..n+1).rev() {
        let mut j = i;
        let mut sum = 0;
        while j <= n {
            sum += ans[j - 1];
            j += i;
        }

        if sum % 2 != a[i-1] {
            ans[i - 1] = 1;
        }
    }

    let mut ins = vec![];
    for i in 0..ans.len() {
        if ans[i] != 0 {
            ins.push(i+1);
        }
    }

    println!("{}", ins.len());

    for i in 0..ins.len() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ins[i]);
    }
    println!();
}


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

int main(void){
	string w, t, end="end_of_text";
	int count=0;
	cin >>t;
	for(int i=0; i<t.size(); i++){
		t[i]=tolower(t[i]);
	}
	while(1){
		cin >>w;
		if(w=="END_OF_TEXT"){
			break;
		}
		for(int i=0; i<w.size(); i++){
			w[i]=tolower(w[i]);
		}
		if(w==t){
			count++;
		}
		
	}
	cout <<count <<endl;
    return 0;
}

Measured memory_bytes: 1196
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <complex>
#define LL long long
using namespace std;
const int M = 1e3 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double PI = acos(-1);
const LL MAX=1e16+1000;
LL A[M];
int main() {
    LL n;
    while(cin>>n){
        if(n==0){
            printf("2\n1 1\n");
            continue;
        }
        for(int j=1;j<=50;j++){
            A[j]=49+n/50;
        }
        int m=n%50;
        for(int j=1;j<=50;j++){
            while(m&&A[j]+50<=MAX){
                A[j]+=50;
                for(int k=1;k<=50;k++){
                    if(k!=j) A[k]--;
                }
                m--;
            }
        }
        printf("50\n");
        for(int j=1;j<=50;j++) printf("%lld%c",A[j]," \n"[j==50]);
    }
    return 0;
}


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

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

    int res = 0;
    int h = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] >= h) {
            res++;
            h = H[i];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	Scanner in = new Scanner(System.in);
    	int i, k;
    	int a[];
    	a = new int[10];
    	a[0] = in.nextInt();
    	for(i = 1;i < 10;i++){
    		a[i] = in.nextInt();
    		if(a[0] < a[i]){
    			k = a[i];
    			a[i] = a[0];
    			a[0] = k;
    		}
    	}
    	System.out.println(a[0]);
    	for(i = 1;i < 10;i++){
    		if(a[1] < a[i]){
    			k = a[i];
    			a[i] = a[1];
    			a[1] = k;
    		}
    	}
    	System.out.println(a[1]);
    	for(i = 2;i < 10;i++){
    		if(a[2] < a[i]){
    			k = a[i];
    			a[i] = a[2];
    			a[2] = k;
    		}
    	}
    	System.out.println(a[2]);
    }
}

Measured memory_bytes: 17324
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    s = input()
    rgb = {"R":0,"G":0,"B":0}
    for i in s:
        rgb[i] += 1
    ans = 1
    for i in rgb.keys():
        ans *= rgb[i]
    for i in range(n-2):
        for j in range(i+1,n-1):
            k = j + (j-i)
            if k>=n:
                continue
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                ans -= 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9232
#include <iostream>
#include <string>
using namespace std;
int main(){
	double w;
	while(cin>>w){
		if(w<=48){cout<<"light fly"<<endl;
		}else if(48<w&&w<=51){cout<<"fly"<<endl;
		}else if(51<w&&w<=54){cout<<"bantam"<<endl;
		}else if(54<w&&w<=57){cout<<"feather"<<endl;
		}else if(57<w&&w<=60){cout<<"light"<<endl;
		}else if(60<w&&w<=64){cout<<"light welter"<<endl;
		}else if(64<w&&w<=69){cout<<"welter"<<endl;
		}else if(69<w&&w<=75){cout<<"light middle"<<endl;
		}else if(75<w&&w<=81){cout<<"middle"<<endl;
		}else if(81<w&&w<=91){cout<<"light heavy"<<endl;
		}else{cout<<"heavy"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3064
/*
  author:   Ziel
  created:  05.07.2020 17:38:55
*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define bpc __builtin_popcountl
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
struct chash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + RANDOM);
  }
};

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const db EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int32_t main() {
  fre("");
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
  int n;
  cin >> n;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    string x;
    cin >> x;
    m[x]++;
  }
  
  cout << "AC x " << m["AC"] << '\n';
  cout << "WA x " << m["WA"] << '\n';
  cout << "TLE x " << m["TLE"] << '\n';
  cout << "RE x " << m["RE"] << '\n';
  
  return 0;
}

// uniform_int_distribution<int>(l, r)(rng) -> random in range [l, r]
// assert(condition) -> if (condition == false) Runtime Error
// order_of_key(x) -> number of elements smaller than x
// *find_by_order(k) -> k-th element in 0-based indexation
// gp_hash_table<T, U, chash> -> fast unordered_map
// m.count(x) <-> (m.find(x) != m.end())


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;
ll num,t=1,ans;
ll cnt[2200];//记录余数的个数 
int main()
{
  cnt[0]=1;// 
  cin>>s;
  for(int i=s.size()-1;i>=0;i--)
  {
  	 num=(num+(s[i]-'0')*t)%2019;
  	 ans+=cnt[num];
  	 cnt[num]++;
	 t=t*10%2019; 
  }
   cout<<ans;
return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
const int p = 1e9 + 7;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> seq(n);
    for(auto &x : seq){
        cin>>x;
    }
    vector<int> dp(k+2);
    dp[0] = 1;
    for(int i=0;i<n;i++){
        for(int j=k,l=0,r=0;j>=0;--j){
            l = r;
            r = dp[j];
            dp[j] = dp[j+1] + dp[max(0, j-seq[i])] - l;  
            dp[j] >=p ? dp[j]-=p : dp[j];
            dp[j] < 0 ? dp[j]+=p : dp[j]; 
        }
    }
    cout<<dp[k]<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.size();
    if(s[l-1]==s[l-2] && s[l-3]==s[l-4])
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();

	vector<int> dr(n, n - 1), dl(n, 0);
	for (int i = n - 2; i >= 0; --i) {
		dr[i] = dr[i + 1];
		if (s[i] == 'L') { dr[i] = i; }
	}
	for (int i = 1; i < n; ++i) {
		dl[i] = dl[i - 1];
		if (s[i] == 'R') { dl[i] = i; }
	}

	vector<int> res(n, 0);
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'R') {
			int d = abs(i - dr[i]);
			if (d % 2 == 0) {
				res[dr[i]] += 1;
			} else {
				res[dr[i] - 1] += 1;
			}
		} else {
			int d = abs(i - dl[i]);
			if (d % 2 == 0) {
				res[dl[i]] += 1;
			} else {
				res[dl[i] + 1] += 1;
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << res[i] << (i < n - 1 ? " " : "\n");
	}

	return 0;
}


Measured memory_bytes: 1792
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

char read_op() {
    using namespace _buff;
    char c = getc();
    for (; c != '+' && c != '-'; c = getc()) {
        assert(~c);
    }
    return c;
}

template <typename T>
void chkmax(T &dp, const T &val) {
    if (val > dp) {
        dp = val;
    }
}

const size_t N = 1E5 + 5;

LL f[N][3];
int a[N];
char op[N];

int main() {
    int n = read();
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
        if (i < n) op[i] = read_op();
    }
    memset(f, 0xef, sizeof f);
    f[1][0] = a[1];
    for (int i = 1; i < n; ++i) {
        chkmax(f[i][1], f[i][2]);
        chkmax(f[i][0], f[i][1]);
        if (op[i] == '+') {
            for (int j = 0; j < 3; ++j) {
                f[i + 1][j] = f[i][j] + a[i + 1] * (j ^ 1 ? 1 : -1);
            }
        } else {
            for (int j = 0; j < 3; ++j) {
                LL tmp = f[i][j] + a[i + 1] * (j ^ 1 ? -1 : 1);
                chkmax(f[i + 1][j], tmp);
                if (j + 1 < 3) chkmax(f[i + 1][j + 1], tmp);
            }
        }
    }
    chkmax(f[n][1], f[n][2]);
    chkmax(f[n][0], f[n][1]);
    cout << f[n][0];
    return 0;
}


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

void main()
{
    auto S = readln.chomp.to!(char[]);
    writeln(S[0] == S[1] || S[1] == S[2] || S[2] == S[3] ? "Bad" : "Good");
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

      while (true){
        int x = sc.nextInt();
        int y = sc.nextInt();

          if (x == y && y == 0){
            break;
          }
          if (x <= y){
              System.out.println(x  + " " + y);
          } else {
            System.out.println(y  + " " + x);
          }
      }
  }
}



Measured memory_bytes: 35528
# -*- coding: utf-8 -*-
n = int(input())
ab = []
for _ in range(n):
    a,b = map(int, input().split())
    ab.append((a,b))

res = 0
for i in range(n-1,-1,-1):
    a,b = ab[i]
    a += res
    if a%b!=0:
        res += b-a%b
    # if b>=a:
    #     res += b-a
    # elif a%b==0:
    #     pass
    # else:
        # res += b-a%b
print(res)


Measured memory_bytes: 16588
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define pb push_back
#define INF 1e9
#define PI 3.1415926535
#define FOR(a,b) for(int a=0;a<b;a++)
#define FORN(a,m,n,p) for(int a=m;a<n;a+=p)
#define REP(a,m,n) for(int a=m;a<n;a++)
#define frestream freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define sz(a) a.size()
typedef long long ll;
using namespace std;

int main(){
	int n,x;
	int cnt=0;
	int l[101];
	vector<int> v;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	v.pb(0);
	for(int i=1;i<=n;i++){
		v.pb(v[i-1]+l[i-1]);
	}
	for(int i=0;i<v.size();i++){
		if(v[i]<=x)cnt++;
		else break;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256