akhauriyash/Code-Regression huggingface dataset:
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    a.clear();a.reserve(n);

    fo(i,n)
    {
        cin>>in;
        a.pb(in);
    }

    if(a.back()!=2)
    {
        cout<<-1<<endl;
        return 0;
    }

    // a.pop_back();
    reverse(all(a));
    l=2;
    r=2;

    lli pvr=2;
    for(auto x:a)
    {
        lli nl=((l+x-1)/x)*x,nr=(r/x)*x+x-1;
        dbg(l,r,x,nl,nr);

        if(nr<nl||(nl/x)*x<l||r<(nl/x)*x)
        {
            cout<<-1<<endl;
            return 0;
        }

        if((nr/x)*x<l||r<(nr/x)*x)
        {
            cout<<-1<<endl;
            return 0;
        }

        l=nl;
        r=nr;
        pvr=x;
    }

    cout<<l<<" "<<r<<endl;

}   aryanc403();
    return 0;
}


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)
using namespace std;
typedef unsigned char byte;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

using namespace std;


int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }

    string str;
    cin >> str;
    deque<char> dq;

    FOR(i, 0, str.size()) {
        char ch = str.at(i);
        if (ch == 'B') {
            if(!dq.empty())
                dq.pop_back();
        } else {
            dq.push_back(ch);
        }
    }

    while(!dq.empty()) {
        cout << dq.front();
        dq.pop_front();
    }

    cout << endl;
    return 0;
}


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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int amari=A;
  int amariB=C;
  while(true){
    amariB -= B;
    if(amariB<=0){
      break;
    }
    amari -= D;
    if(amari<=0){
      break;
    }
    
  }

  if(amari<=0){
    cout << "No" << endl;
  }
  if(amariB<=0){
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>

#include <fstream>

using namespace std;
typedef long long ll;
static const ll Z = 1 << 21;

#define rep(i,s,n)for(ll i = s;i<n;i++)

ll c[10000][10000];
bool v[10000];
ll N, M;
ll cnt = 0;

bool isVisitedAll() {
	bool valid = true;
	rep(i, 0, N) {
		valid &= v[i];
	}
	return valid;
}

void dfs(int id) {
	if (isVisitedAll()) {
		cnt++;
		return;
	}

	rep(i, 0, N) {
		if (id != i && c[id][i] != 0 && !v[i]) {
			v[i] = true;
			dfs(i);
			v[i] = false;
		}
	}
}

int main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		c[a - 1][b - 1] = 1;
		c[b - 1][a - 1] = 1;
	}

	v[0] = true;
	dfs(0);

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

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

int main(void)
{
    int N,M,ans = 0;
    string s;
    map<string,int> mp;
    cin >> N;

    rep(i, N){
        cin >> s;
        mp[s]++;
    }

    cin >> M;

    rep(i,M){
        cin >> s;
        mp[s]--;
    }

    for(auto x:mp){
        ans = max(ans,x.second);
    }

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

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
int n;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n;
    int ans=INT_MAX;
    for(int i=1; i<=n/2; i++)
    {
        int a=i, b=n-a, cur=0;
        while(a)cur+=a%10, a/=10;
        while(b)cur+=b%10, b/=10;
        ans=min(ans, cur);
    }
    cout<<ans<<"\n";
    return 0;
}


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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e5+5;

void solve() {

  int n;
  cin>>n;
  int ans = n*(n+1)*(n+2)/6;
  fr(_,2,n){
    int u,v;
    cin>>u>>v;
    if(u>v)
      swap(u,v);
    ans-=u*(n+1-v);
  }
  cout<<ans;
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   // cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

bool isPrime(int n) {
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;

	if (n % 2 == 0 || n % 3 == 0)
		return false;

	for (int i = 5; i * i <= n; i = i + 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	return true;
}

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


	while (true) {
		if (isPrime(x)) {
			printf("%d\n", x);
			break;
		}
		++x;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    H = list(map(int,input().split()))
    cnt = 0
    flg = 0
    for i in range(N):
        if cnt >= N-i:
            print(cnt)
            return
        if flg!=0:
            if i==flg:
                flg=0
            else:
                continue
        tmp=0
        for j in range(i,N-1):
            if H[j]>=H[j+1]:
                tmp+=1
            else:
                flg=j+1
                if cnt >= N-j+1:
                    print(cnt)
                    return
                break
        if cnt < tmp:
            cnt=tmp
    print(cnt)


if __name__ == '__main__':
    main()

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

int main() {
	
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    
      long long n,i,j,k,sum=0,count=0,ans=0,x=0,y=0,l,r,m;
      cin>>n;
      if(n>=30)
      cout<<"Yes";
      else
      cout<<"No";
	return 0;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
	int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21720
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n;
	ll x[200005] = {};
	ll y[100005] = {};
	ll z[100005] = {};
	cin >> n;
	cin >> a;
	for (int i = 0; i < n; i++)
	{
		cin >> b;
		if (x[b]==0)
		{
			c++;
		}
		x[b]++;
	}
	sort(x, x + 200000);
	b = 0;
	while (c>a)
	{
		if (x[b]!=0)
		{
			c--;
			ans+=x[b];
		}
		b++;
	}



	cout << ans << endl;
	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
using namespace std;

int w;
float N;

string s,ans;

void solve()
{
    if(s.size()%w==0)
    {
        N=s.size()/w;
    }
    else
    {
        N=int(s.size()/w)+1;
    }
    for(int i=0;i<N;i++)
    {
        ans += s[i*w];
    }
}
int main()
{
    cin >> s;
    cin >> w;
    solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

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

        for (int i = 0; i < S.length(); i += 2) {
            if (S.charAt(i) == 'L') {
                System.out.println("No");
                return;
            }
        }

        for (int i = 1; i < S.length(); i += 2) {
            if (S.charAt(i) == 'R') {
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }
}




Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
using namespace std;
int main(){

    int a,b,temp;
    int sum = 0;
    cin >> a >> b;

    if(a>b){
        temp = b;
        b = a;
        a = temp;
    }

    if( b-1 >= a){
        sum = b+b-1;
    }
    else{
        sum = a+b;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int k = sc.nextInt();
    char[][] grid = new char[h][w];
    for (int cntH = 0; cntH < h; cntH++) {
      grid[cntH] = sc.next().toCharArray();
    }

    int ans = 0;
    for (int maskR = 0; maskR < Math.pow(2, h); maskR++) {
      for (int maskC = 0; maskC < Math.pow(2, w); maskC++) {
        int black = 0;
        for (int r = 0; r < h; r++) {
          for (int c = 0; c < w; c++) {
            if (grid[r][c] == '#' && ((maskR >> r) & 1) == 0 && ((maskC >> c) & 1) == 0) {
              black++;
            }
          }
        }
        if (black == k) {
          ans++;
        }
      }
    }
    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 36076
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
    fastio;
    int a,p;
    cin >> a >> p;
    a*=3;
    a+=p;
    cout << a/2 << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H,W,sx,sy,gx,gy,d[1000][1000];
string s[1000];
main()
{
    cin>>H>>W;
    cin>>sx>>sy;
    cin>>gx>>gy;
    --sx;--sy;--gx;--gy;
    for(int i=0;i<H;++i)cin>>s[i];
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=H*W;
    d[sx][sy]=0;
    deque<pair<int,int>>q;
    q.push_back({sx,sy});
    while(!q.empty())
    {
        int x=q.front().first;
        int y=q.front().second;
        q.pop_front();
        for(int i=-2+x;i<=2+x;++i)for(int j=-2+y;j<=2+y;++j)
        {
            if(i<0||j<0||i>=H||j>=W||s[i][j]=='#')continue;
            if(abs(i-x)+abs(j-y)<=1&&d[i][j]>d[x][y])
            {
                d[i][j]=d[x][y];
                q.push_front({i,j});
            }else if(d[i][j]>d[x][y]+1)
            {
                d[i][j]=d[x][y]+1;
                q.push_back({i,j});
            }
        }
    }
    cout<<(d[gx][gy]==H*W?-1:d[gx][gy])<<endl;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N;
    while( cin >> N, N ){
        vector<set<int> > pe( N );
        set<int> ans;

        REP( i, N ){
            int M; cin >> M;
            REP( j, M ){
                int p; cin >> p;
                pe[i].insert( p );
            }

            ans.insert( i );
        }

        int K; cin >> K;
        vector<int> li( K );
        REP( i, K ){
            int l; cin >> l;
            li[i] = l;
        }


        REP( i, N ){
            REP( j, li.size() ){
                if( pe[i].find( li[j] ) != pe[i].end() ) continue;
                ans.erase( i );
            }
        }

        if( ans.size() == 1 ) for( auto v : ans ) cout << v + 1 << endl;
        else cout << -1 << endl;
    }
}



Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H1,M1,H2,M2,K;
  cin >> H1>>M1>>H2>>M2>>K;
  int a;
  a=(H2-H1)*60+(M2-M1)-K;
  cout <<a<<endl;
}

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

C = input()
firstW = -1
for i in range(N):
    if C[i] == "W":
        firstW = i
        break
for i in range(N-1,-1,-1):
    if C[i] == "R":
        firstR = i
        break

def checkR(ri,wi):
    for i in range(ri,wi,-1):
        if C[i] == "R":
            return i
    else:
        return -1

def checkW(ri,wi):
    for i in range(wi,ri):
        if C[i] == "W":
            return i
    else:
        return -1


if len(set(C)) == 1:
    print(0)
elif firstW > firstR:
    print(0)
else:
    ri = firstR
    wi = firstW
    cnt = 0
    while 1:
        wi = checkW(ri,wi+1)
        ri = checkR(ri-1,wi)
        if wi == -1 or ri == -1:
            break
        cnt += 1
    print(cnt+1)


        


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

using namespace std;

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

    int sum = 0;
    for (int i = 1; i < N + 1; i++)
    {
        sum += (i + L) - 1;
    }
    if (L >= 0)
    {
        sum -= (1 + L) - 1;
    } else if (N + (L - 1) < 0)
    {
        sum -= (N + L) - 1;
    }
    cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define TLE() cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms.\n";
const ll MOD = 1E9+7;
const ll IINF = 1E18;
const int INF = 1e9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
 
const int MX=3005;
int p,a[MX];
ll mod;
ll num[MX];
 
using poly=vector<ll>;
vector<poly> pf,sf;
 
poly polymul(const poly &left,const poly &right){
	poly res(MX,0);
	REP(i,sz(left))
		REP(j,sz(right))
			if (i+j<MX) (res[i+j]+=left[i]*right[j]%p)%=p;
	return res;
}
 
poly polyplus(const poly &left,const poly &right){
	poly res(MX,0);
	REP(i,p){
		if(i<sz(left)) (res[i]+=left[i])%=p;
		if(i<sz(right)) (res[i]+=right[i])%=p;
	}
	return res;
}
 
poly polydiv(poly P,int x){
	int k=sz(P);
	poly res(k-1,0);
	FORD(i,k-1,1){
		(P[i-1]+=x*P[i]%p)%=p;
		res[i-1]=P[i];
	}
	return res;
}

ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%mod;a=a*a%mod;p>>=1LL;} return res;}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>p;
  	mod=p;
	REP(i,p) cin>>a[i];
	poly init(MX,0);
	init[1]=1;
	FOR(i,1,p-1){
		poly mul={p-i,1};
		init=polymul(init,mul);
	}
	REP(i,p){
		num[i]=1;
		REP(j,p)
			if(i!=j) num[i]=num[i]*(i-j+p)%p;
	}
	poly res(MX,0);
	REP(i,p){
		if(!a[i]) continue;
		poly s=polydiv(init,i);
		poly tmp={fpow(num[i],p-2)};
		s=polymul(s,tmp);
		res=polyplus(res,s);
	}
	REP(i,p) cout<<res[i]<<' ';
	cout<<'\n';
}

Measured memory_bytes: 3756
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

L = list(sr())
MOD = 10 ** 9 + 7
bit_len = len(L)

dp_any = 1 # 1桁目が(0, 0)の組み合わせ, dp_any はi+1桁目がどんな数字でも条件を満たす
dp_spe = 2
for i in range(1, bit_len):
    x, y = dp_any, dp_spe
    if L[i] == '1':
        dp_any = x * 3 + y
        dp_spe = y * 2
    else:
        dp_any = x * 3
        dp_spe = y
    dp_any %= MOD
    dp_spe %= MOD

answer = (dp_any + dp_spe) % MOD
print(answer)


Measured memory_bytes: 3956
function main(arg) {
	arg = arg.split("\n")[0].split(" ").map(Number)
	var a = arg[0]
	var b = arg[1]
	var c = arg[2]

	var t = Math.floor(b / a)

	if (t < c) {
		console.log(t)
	} else {
		console.log(c)
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22076
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long x[200000], y[200000], n, H, W;
vector<long long>X, Y; vector<pair<long long, long long>>candidate;
long long dists(long long px, long long py) {
	vector<long long>RR; long long sum = 0;
	for (int i = 0; i < n; i++) {
		long long TT = abs(px - x[i]) + abs(py - y[i]);
		RR.push_back(TT); sum += TT;
	}
	sort(RR.begin(), RR.end());
	return sum * 2 - RR[RR.size() - 1];
}
int main() {
	cin >> H >> W >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; X.push_back(x[i]); Y.push_back(y[i]); }
	sort(X.begin(), X.end()); sort(Y.begin(), Y.end());
	vector<long long>HH, WW;
	if (n % 2 == 1) { HH.push_back(X[X.size() / 2]); WW.push_back(Y[Y.size() / 2]); }
	if (n % 2 == 0) {
		HH.push_back(X[X.size() / 2 - 1]); HH.push_back(X[X.size() / 2]);
		WW.push_back(Y[Y.size() / 2 - 1]); WW.push_back(Y[Y.size() / 2]);
	}
	unique(X.begin(), X.end()); unique(Y.begin(), Y.end());
	int pos1 = lower_bound(X.begin(), X.end(), HH[0]) - X.begin();
	int pos2 = lower_bound(Y.begin(), Y.end(), WW[0]) - Y.begin();
	int pos3 = 0, pos4 = 0;
	if (n % 2 == 0) {
		int pos1 = lower_bound(X.begin(), X.end(), HH[1]) - X.begin();
		int pos2 = lower_bound(Y.begin(), Y.end(), WW[1]) - Y.begin();
	}
	if (pos1 >= 1) { HH.push_back(X[pos1 - 1]); }
	if (pos1 < X.size() - 1 && n % 2 == 1) { HH.push_back(X[pos1 + 1]); }
	if (pos3 < X.size() - 1 && n % 2 == 0) { HH.push_back(X[pos3 + 1]); }
	if (pos2 >= 1) { WW.push_back(Y[pos2 - 1]); }
	if (pos2 < Y.size() - 1 && n % 2 == 1) { WW.push_back(Y[pos2 + 1]); }
	if (pos4 < Y.size() - 1 && n % 2 == 0) { WW.push_back(Y[pos4 + 1]); }
	for (int i = 0; i < HH.size(); i++) { for (int j = 0; j < WW.size(); j++)candidate.push_back(make_pair(HH[i], WW[j])); }
	long long minx = 999999999999999999LL, mx = 0, my = 0; sort(candidate.begin(), candidate.end());
	for (int i = 0; i < candidate.size(); i++) {
		long long UU = dists(candidate[i].first, candidate[i].second);
		if (minx > UU) { minx = UU; mx = candidate[i].first; my = candidate[i].second; }
	}
	cout << minx << endl << mx << ' ' << my << endl;
	return 0;
}

Measured memory_bytes: 7816
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(void)
{
	string str, lon = "", most = "";
	map <string, int> count;
	while (cin >> str)
	{
		if (str.size() > lon.size()) lon = str;
		count[str]++;
		if (count[most] < count[str]) most = str;
	}
	cout << most << " " << lon << endl;
	return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	string s;
	cin>>s;
	for(ll i=0;i<s.size();i++)
	{
		if(i%2==0)
			cout<<s[i];
	}
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

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

using namespace std;

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

    if(a<=8 && b<=8)
        cout<<"Yay!"<<endl;
    else
        cout<<":("<<endl;
}

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

    solve();

  return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
        while (true){
            c-=b;
            if (c<=0){
                System.out.println("Yes");
                break;
            }
            a-=d;
            if (a<=0){
                System.out.println("No");
                break;
            }

        }
    }


    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

int main(){
   int n,m;
   cin >> n >> m;
   vector<int> a(n);
   for(int i=0; i<n; i++){
       cin >> a[i];
   }
   sort(a.begin(),a.end(),greater<int>());
   ll sum=0;
   for(int i=0; i<n; i++){
       sum+=a[i];
   }
   if(a[m-1]*4*m<sum) cout << "No";
   else cout << "Yes";
   cout << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    a, b, h, m = input_to_int_map()

    # 度を求める
    # 長針
    tyoshin_do = (float(h) * 30.0) + (0.5 * m)
    # 短針
    tanshin_do = (6.0 * float(m))
    # 差
    do = abs(tyoshin_do - tanshin_do)

    import math

    return math.sqrt(math.pow(float(a), 2) + math.pow(float(b), 2) - (2.0 * a * b) * math.cos(math.radians(do)))


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9536
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for((i)=(l);(i)<=(r);(i)++)
#define drep(i,l,r) for((i)=(l);(i)>=(r);(i)--)
#define MOD 1000000007
#define ll long long
#define MAX(a,b) ((a)>(b)?(a):(b))
using namespace std;
int cmp(const void *a,const void *b){
  long long *A = (long long *)a;
  long long *B = (long long *)b;
  if (*A > *B) return -1;
  if (*A < *B) return 1;
  return 0;
}
int main(){
    ll n,m,i,buf;
	cin>>n>>m;
    priority_queue<ll> a;
    rep(i,0,n){
        cin>>buf;
        a.push(buf);
    }
    rep(i,0,m){
        buf=a.top();
        a.push(buf/2);
        a.pop();
    }
    ll ans=0;
    rep(i,0,n){
        buf=a.top();
        ans+=buf;
        a.pop();
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

int b[50],r[50],t[50];
int y;

double motori(int i){
    if(t[i]==1){
        return (double)y*r[i]/100 + 1;
    }else{
        return pow(1+(double)r[i]/100, y);
    }
}
int main(){
    int n;
    while(cin >> n, n){
        for(int i=0;i<n;i++){
            int x1,y1,z1,w1,x2,y2,z2,w2;
            scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&z1,&w1,&x2,&y2,&z2,&w2);
            printf("%d %d %d %d\n", x1*x2-y1*y2-z1*z2-w1*w2, x1*y2+y1*x2+z1*w2-w1*z2, x1*z2-y1*w2+z1*x2+w1*y2, x1*w2+y1*z2-z1*y2+w1*x2);
        }
    }

    return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();

        for (int i = 1; i <= n; i++) {
            int x = i;
            if (x % 3 == 0) {
                System.out.print(" " + i);
            } else {
                while (x != 0) {
                    if (x % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
                    x /= 10;
                }
            }
        }
        System.out.println();
    }

}

Measured memory_bytes: 28708
#include<bits/stdc++.h>
#define N 102
using namespace std;
int n, k, d, ans;
int a[N];
int main(){
	
	cin >> n >> k;
	while(k--){
		cin >> d;
		int num = 0;
		for(int i = 0; i < d; i++){
			cin >> num;
			a[num]++;
		}
	}
	for(int i = 1; i <= n; i++){
		if(a[i] == 0){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main()
{
  int A, B;
  int money = 0;
  cin >> A >> B;
  if(A <= 5){
    money = 0;
  }
  else if (A >= 6 and A <= 12){
    money = B / 2;
  }
  else {
    money = B;
  }
  cout << money << endl; 
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    vector<int> nl;
    int mx = 0;
    int n;
    while (scanf("%d ", &n) != EOF) {
        nl.push_back(n);
        mx = max(mx, n);
    }

    double r = sqrt(mx);

    list<int> sl;
    vector<int> primes;

    for (int i = 2; i <= mx; i++) {
        sl.push_back(i);
    }

    while (sl.front() <= r) {
        int p = sl.front();
        primes.push_back(p);
        sl.pop_front();

        auto i = sl.begin();
        while(i != sl.end()){
            if(*i % p == 0){
                i = sl.erase(i);
            }
            else {
                i++;
            }
        }
    }

    for (auto&& i : sl) {
        primes.push_back(i);
    }

    for (auto&& n : nl) {
        auto p = upper_bound(primes.begin(), primes.end(), n);
        printf("%d\n", p - primes.begin());
    }

    return 0;
}

Measured memory_bytes: 34280
#include <stdio.h>
int main(int argc, char *argv[])
{
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	if(b<=a) printf("delicious");
	else if(b-x<=a) printf("safe"); 
	else if(b-x>a) printf("dangerous"); 
	return 0;
}

Measured memory_bytes: 128
from math import sqrt
def F(A,B):
    A=len(str(A))
    B=len(str(B))-2
    return A if A>B else B
n=int(input())
o=[]
for a in range(1,int(sqrt(n))+1):
    b=n/a
    if b.is_integer():
        o.append(F(a,b))
print(o[-1])

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>

double dp[16][9];
char s,t,b;
int n,d[4]={-3,-1,3,1};

int main() {
	while(scanf("%d",&n),n) {
		scanf("\n%c %c %c",&s,&t,&b);s-='A',t-='A',b-='A';
		memset(dp,0,sizeof(dp));
		dp[0][s]=1;
		for(int i=0;i<=n-1;i++) {
			for(int j=0;j<9;j++) {
				for(int k=0;k<4;k++) {
					if((k==0&&j/3==0)||(k==1&&j%3==0)||(k==2&&j/3==2)||(k==3&&j%3==2)||(j+d[k])==b) {
						dp[i+1][j]+=dp[i][j]*0.25;
					}else {
						dp[i+1][j+d[k]]+=dp[i][j]*0.25;
					}
				}
			}
		}
		printf("%.8lf\n",dp[n][t]);
	}
}

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

int main(){

    int a, b, c=3;
    cin >> a >> b;
    while(c--){
        if(a*b*c % 2 != 0){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():

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

    V = []

    for i in range(n):
        s, t, x = map(int, input().split())
        V.append((s-x, x, 1)) #1: insert
        V.append((t-x, x, 0)) #0: delete

    D = []
    for i in range(q):
        d = int(input())
        V.append((d, i, 2)) #2: query

    V.sort(key=lambda x:(x[0], x[2]))
    se = set()
    hq = []
    import heapq
    heapq.heapify(hq)
    ans = [-1]*q
    for t, v, p in V:
        if p == 1:
            se.add(v)
            heapq.heappush(hq, v)
        elif p == 0:
            se.remove(v)
        else:
            while hq and hq[0] not in se:
                heapq.heappop(hq)
            if hq:
                ans[v] = hq[0]

    for i in range(q):
        print(ans[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 130308
import Control.Monad

solve _ t [] = t + 4
solve n t (x:xs) = solve n (max t $ (n+x-1) `div` x) xs

main :: IO ()
main = do
  n <- readLn :: IO Integer
  xs <- replicateM 5 $ readLn :: IO [Integer]

  print $ solve n 0 xs


Measured memory_bytes: 508
import java.util.*;
import java.io.*;
public class Main {
    static InputStreamReader r;
    public static void main(String[] args) throws Exception {
        r = new InputStreamReader(System.in);
        int N = nextInt();
        int W = nextInt();
        int dp[][] = new int[N+1][100001];
        for (int i = 0; i <= N; i++) {
            Arrays.fill(dp[i], 1000000001);
        }

        int ans = 0;
        for (int i = 1; i <= N; i++) {
            int wi = nextInt();
            int vi = nextInt();
            for (int j = 0; j <= 100000; j++) {
                if (j <= vi) {
                    dp[i][j] = Math.min(dp[i-1][j], wi);
                } else {
                    dp[i][j] = Math.min(dp[i-1][j], dp[i-1][j-vi]+wi);
                }

                if (dp[i][j] <= W) {
                    ans = Math.max(ans, j);
                } else {
                    break;
                }
            }
        }
        System.out.println(ans);
    }

    public static String nextString() throws Exception {
        String res = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            res += (char)c;
        }
        return res;
    }

    public static int nextInt() throws Exception {
        return Integer.parseInt(nextString());
    }

    public static long nextLong() throws Exception {
        return Long.parseLong(nextString());
    }
}


Measured memory_bytes: 81492
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
  cin >> A.at(i);
}
sort(A.begin(), A.end());
int min = A.at(0);
int max = A.at(N - 1);
cout << max - min << endl;

// Joker Maximum Drive
}

Measured memory_bytes: 256
#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 si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#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 vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
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 N,K;
    cin >> N >> K;
    int R,S,P;
    cin >> R >> S >> P;
    string T;
    cin >> T;
    
    int ans = 0;
    map<char,int> M;
    M['s'] = R;M['p'] = S;M['r'] = P;
    
    rep(i,min(N,K)){
        
        int ss = i;
        char rsp = 'a';
        while (ss < N) {
            
            if(rsp == T[ss]) rsp ='a';
            else{
                rsp = T[ss];
                ans += M[T[ss]];
            }
            ss += K;
        }
        
    }
    
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  int K;
  cin >> K;
  vector<vector<int>> M(K, vector<int>(2));
  for (int i = 0; i < K; i++) {
    cin >> M.at(i).at(0) >> M.at(i).at(1);
  }
  vector<ll> DP(N + 1, 0);
  DP.at(0) = 1;
  DP.at(1) = -1;
  for (int i = 0; i < N; i++) {
    DP.at(i) %= 998244353;
    for (int j = 0; j < K; j++) {
      if (i + M.at(j).at(0) < N) {
        DP.at(i + M.at(j).at(0)) += DP.at(i);
        DP.at(min(i + M.at(j).at(1) + 1, N)) -= DP.at(i);
      }
    }
    DP.at(i + 1) += DP.at(i);
  }
  DP.at(N - 1) += 998244353;
  DP.at(N - 1) %= 998244353;
  cout << DP.at(N - 1) << endl;
}
              
      

Measured memory_bytes: 4852
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

class TaskB {
 public:
  void solve(std::istream &in, std::ostream &out) {
    int N;
    in >> N;
    map<int, int> D;
    for (int i = 0; i < N; i++) {
      int d;
      in >> d;
      D[d]++;
    }

    int M;
    in >> M;

    bool ok = true;
    for (int i = 0; i < M; i++) {
      int t;
      in >> t;
      D[t]--;
      if (D[t] < 0) {
        ok = false;
      }
    }

    if (ok) {
      out << "YES";
    } else {
      out << "NO";
    }

  }
};


int main() {
  TaskB solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

int main() {
  string s, P;
  cin >> s >> P;
  s += s;
  for (int i = 0; i <= s.size() - P.size(); i ++) {
    if (s[i] == P[0]) {
      bool match = true;
      for (int j = i + 1, k = 1; j < i + P.size(); j++, k++) {
        if (s[j] != P[k]) {
          match = false;
          break;
        }
      }
      if (match) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll x,y ;
	cin >> x >> y ;
	ll cnt = 0 ;
	while(x<=y){
		cnt++ ;
		x *= 2 ;
	}
	cout << cnt << endl ;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
const int N = 2e5 + 123;
int main(){
    speed;
    int n;
    cin >> n;
    vi v(n + 1);
    vi dp(n + 1, 0);
    for(int i = 1; i <= n; ++i){
        cin >> v[i];
    }
    dp[1] = 0;
    dp[2] = abs(v[2] - v[1]);
    for(int i = 3; i <= n; ++i){
        dp[i] = min(dp[i - 2] + abs(v[i] - v[i - 2]), dp[i - 1] + abs(v[i] - v[i - 1]));
    }
    cout << dp[n];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
string s, s1;
int k;
int ans[3];
int main()
{
    while (cin >> s >> k)
    {
        s1 = s + s + s;
        for (int i = 1; i < s1.size(); i++)
        {
            if (s1[i] == s1[i - 1])
            {
                s1[i] = '.';
                ans[(i / s.size())]++;
            }
        }
        k--;
        long long res = ans[0];
        res += 1ll * (k + 1) / 2 * ans[1];
        res += 1ll * k / 2 * ans[2];
        cout << res << endl;
    }
}

Measured memory_bytes: 384
import static java.util.Comparator.*;

import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		ArrayList<Integer> list = new ArrayList<Integer>(){
			{
				add(a);
				add(b);
				add(c);
			}
		};
		list.sort(naturalOrder());
		System.out.println(list.get(0) + " " + list.get(1) + " " + list.get(2));
		scan.close();
	}
}

Measured memory_bytes: 26324