akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<iostream> 
using namespace std;

#define fi first
#define se second

const int maxn = 1010;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
char mp[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn][maxn];
int n,m;

bool check(int x,int y) {
    if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
    return true;
}

int BFS() {
    queue<pair<int ,int> > q;
    q.push(make_pair(0,0));
    step[0][0] = 1;
    vis[0][0] = true;
    while (!q.empty()) {
        pair<int ,int> t = q.front();
        q.pop();
        for(int i = 0;i < 4;i++) {
            int tox = t.fi + Move[i][0];
            int toy = t.se + Move[i][1];
            if(tox == n - 1 && toy == m - 1) return step[t.fi][t.se] + 1;
            if(check(tox,toy)) {
                vis[tox][toy] = true;
                step[tox][toy] = step[t.fi][t.se] + 1;
                q.push(make_pair(tox,toy));
            }
        }
    }
    return -1;
}


int main(){
    cin>>n>>m;
    int cnt = 0;
    for(int i = 0;i < n;i++)
        for(int j = 0;j < m;j++) {
            cin>>mp[i][j];
            if(mp[i][j] == '#') cnt++;
        }
    int res = BFS();
    if(res == -1) {
        cout<<"-1"<<endl;
    } else {
        cout<<n*m - res - cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
	int a,b;
	do{
		scanf("%d%d",&a,&b);
	}while(a<1||b>100);
	
	if(a%3==0 || b%3==0 || (a+b)%3==0){
		printf("Possible\n");
	}else{
		printf("Impossible\n");
	}
	
	return 0;
}

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,M,K;
int A,B,C,T;

int S[3333];

signed main(){
    scanf("%lld%lld%lld",&N,&M,&K);
    scanf("%lld%lld%lld%lld",&A,&B,&C,&T);
    rep(i,M)scanf("%lld",&S[i]),S[i]--;
    S[M]=S[M-1]+1;
    vint v;
    int ans=0;
    rep(i,M){
        if(i*B>T)break;
        int t=0;
        for(int j=0;j<=K;j++){
            if(t==S[i+1]-S[i]||S[i]*B+t*C>T)break;
            int s=min(S[i+1]-S[i]-t,(T-S[i]*B-t*C)/A+1);
            if(j==0)ans+=s;
            else v.pb(s);
            t+=s;
        }
    }
    sort(all(v));reverse(all(v));
    for(int i=0;i<v.size()&&i<K-M;i++)ans+=v[i];
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 35884
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))


char ss[30010][9];
ll n,k;
char s[5010];
int main(){
	scanf("%s%lld",s,&k);
	n=strlen(s);
	ll cnt=0;
	rep(i,0,n)rep(j,1,6){
		rep(k,0,j)ss[cnt][k]=s[i+k];
		cnt++;
	}
	qsort(ss,cnt,9,strcmp);
	ll ans=0,i=0;
	while(ans<k){
		ll t=i;
		while(!strcmp(ss[i],ss[t]))t++;
		ans++;
		i=t;
	}
	puts(ss[i-1]);
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
	int h,w;
	cin>>h>>w;
	int n; cin>>n;
	float x=ceil((float)n/(float)max(h,w));
	cout<<x<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

int main(){
    string S; cin>>S;
    deque<char> X;
    rep(i,S.size()) X.pb(S.at(i));
    ll Q; cin>>Q;
    ll muki=1;
    rep(i,Q){
        ll T; cin>>T;
        if(T==1) muki=1-muki;
        else{
            ll F; cin>>F;
            char C; cin>>C;
            if((F+muki)%2) X.push_back(C);
            else X.push_front(C);
        }
    }
    ll N=X.size();
    if(muki) rep(i,N) cout<<X.at(i);
    else rep(i,N) cout<<X.at(N-1-i);
    cout<<endl;
}

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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
#define x first
#define y second
#define point pair<double,double>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}

//you don't know math, unless you can do math!
int l,n;
vector<int> cuts;
ll dp[1100][1100];

ll solve(int i, int j){
    ll &ret= dp[i][j];
    if(ret != -1)
        return ret;

    int cur= lower_bound(cuts.begin(), cuts.end(), i+1) - cuts.begin();
    if(cur == cuts.size() || cuts[cur] >= j)
        return ret= 0;



    ret= 10000000;
    while(cur < n && cuts[cur] < j){
        ret = min(ret, solve(i, cuts[cur]) + solve(cuts[cur], j) + j - i);
        cur++;
    }

    return ret;
}
int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n,m; cin>>n>>m;
    vector<vector<int>> adjList(n);

    int from, to;
    loop(i,m){
        cin>>from>>to;
        adjList[from-1].push_back(to-1);
        adjList[to-1].push_back(from-1);
    }


    loop(i,n){
        cout<<adjList[i].size()<<'\n';
    }
}


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

int main() {
    int x;
    cin>>x;
    vector<int> ret;
    for (int i=1; i*i<=x; i++) {
        if (x%i==0) {
            ret.push_back(i);
            if (i*i!=x) ret.push_back(x/i);
        }
    }
    sort(ret.begin(),ret.end());
    double r=pow((double)x,0.5);
    r=(int)r;
    for (int i=0; i<=r; i++) {
        for (int j=0; j<ret.size(); j++) {
            int b=i-ret[j];
            if (pow(i,5)-pow(b,5)==x) {
                cout<<i<<" "<<b<<endl;
                return 0;
            }
        }
    }
}   


Measured memory_bytes: 4120
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
	// your code goes here
	int n,c=0;
	cin>>n;
	while(n--)
	{
		int a,b;
		cin>>a>>b;
		if(a==b)
		c++;
		else
		c=0;
		if(c==3)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3604
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        if i%2==0:
            for j in range(w):
                if j%2==0:
                    print("#",end="")
                else:
                    print(".",end="")
            print()
        else:
            for j in range(w):
                if j%2==0:
                    print(".",end="")
                else:
                    print("#",end="")
            print()
            
    print()


Measured memory_bytes: 7008
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

bool isp(int n) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) return false;
	}
	return true;
}

int s[100001];

int main(int argc, char* argv[])
{
	for (int i = 3; i <= 100000; i++) {
		if (i % 2 == 0) s[i] = s[i - 1];
		else if (isp(i) && isp((i + 1) / 2)) {
			s[i] = s[i - 1] + 1;
		} else {
			s[i] = s[i - 1];
		}
	}

	int Q;
	scanf("%d", &Q);
	for (int i = 0; i < Q; i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", s[r] - s[l - 1]);
	}

	return 0;
}


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

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

void f(int K, vector<ll>& a) {
    for (int i = 1; i <= K; ++i) {
        for (int j = 2 * i; j <= K; j += i) {
            (a[i] += a[j]) %= MOD;
        }
    }
}

void inv_f(int K, vector<ll>& a) {
    for (int i = K; i >= 1; --i) {
        for (int j = 2 * i; j <= K; j += i) {
            (a[i] += MOD - a[j]) %= MOD;
        }
    }    
}

vector<ll> merge(int K, vector<ll> v1, vector<ll> v2) {
    if (v1.empty()) return v2;
    if (v2.empty()) return v1;

    f(K, v1);
    f(K, v2);

    vector<ll> res(K + 1, 0);
    for (int i = 1; i <= K; ++i) {
        res[i] = v1[i] * v2[i] % MOD;
    }

    inv_f(K, res);
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;

    vector<ll> memo;
    vector<ll> dp(K + 1, 1);
    while (n > 0) {
        if (n & 1) memo = merge(K, memo, dp);
        dp = merge(K, dp, dp);
        n >>= 1;
    }

    ll ans = 0;
    for (int i = 1; i <= K; ++i) {
        (ans += memo[i] * i % MOD) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7108
import java.util.*;

class Main {

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

    while (true) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      int s = sc.nextInt();
      if (x == 0 && y == 0 && s == 0) return;
      int max = 0;
      for (int i = 1; i < s; i++) {
        for (int j = 1; j < s; j++) {
          int a = i * (100 + x) / 100;
          int b = j * (100 + x) / 100;
          if (a + b == s) {
            a = i * (100 + y) / 100;
            b = j * (100 + y) / 100;
            if (a + b > max) max = a + b;
          }
        }
      }

      System.out.println(max);
    }
  }
}



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

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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}

ll cmb(ll x, ll y){
    if(y>x||y<0) return 0LL;
    ll c = 1;
    for(ll i = 0LL; i < y; i++) {
        c *= (x-i)%mod;
        c %= mod;
        c *= pow(i+1,mod-2,mod);
        c%= mod;
    }
    return c;
}

int main() {
    ll N,M;
    cin>>N>>M;
    map<ll,ll> m;
    ll s = M;
    for(ll i = 2; i*i<M; i++){
        while(s%i==0){
            m[i]++;
            s/=i;
        }
    }
    if(s!=1) m[s]++;
    ll ans = 1LL;
    for(auto x:m){
        ans=(ans*cmb(x.second+N-1,x.second))%mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int d;
  cin>>d;
  string ans="";
  if(d==25)ans="Christmas";
  if(d==24)ans="Christmas Eve";
  if(d==23)ans="Christmas Eve Eve";
  if(d==22)ans="Christmas Eve Eve Eve";
  cout(ans);
 
  return 0;
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  int max = 0;
  while(K>0) {
    if (A>0) {
      max += 1;
      A--;
    } else if (B>0) {
      B--;
    } else {
      max -= 1;
      C--;
    }
    K--;
  }
  cout << max << endl;
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int f[n][10];
    int p[n][11];

    int f_num[n];

    for(int i=0; i<n; i++){
        f_num[i] = 0;
        for(int j=0; j<10; j++){
            cin >> f[i][j];
        }
    }

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

    int ans = -1e9-1;
    for (int i = 1; i < (1<<10); ++i) {
        int profit = 0;
        for (int j = 0; j < n; ++j) {
            int cnt = 0;
            for (int k = 0; k < 10; ++k) {
                cnt += (i>>k)&1 && f[j][k];
            }
            profit += p[j][cnt];
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    double r;
    while(cin >> r){
        printf("%.6f %.6f\n", r*r*M_PI, r*2*M_PI);
    }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int d,n;
    cin>>d>>n;
    if (n==100)
        cout<<(n+1)*(int)pow(100,d)<<endl;
    else
        cout<<n*(int)pow(100,d)<<endl;
}

Measured memory_bytes: 512
S = input()
tmp = ''.join(list(reversed(S)))
s = 0
ans = 'YES'

for i in range(len(S)):
    if tmp[s:i] == 'maerd' or tmp[s:i] == 'remaerd'or tmp[s:i] == 'esare' or tmp[s:i] == 'resare':
        s = i
        ans = 'YES'
        continue
    
    if len(tmp[s:i]) > 7:
        ans = 'NO'
        break
        
print(ans)

Measured memory_bytes: 9540
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) {
			cin >> s[i];
	}


	vii l(h, vi(w)), r(h, vi(w)), u(h, vi(w)), d(h, vi(w));

	for (int i = 0; i < h; i++) {
		if (s[i][0] == '.') r[i][0] = 1;
		for (int j = 1; j < w; j++) {
			if (s[i][j] == '.') r[i][j] = r[i][j - 1] + 1;
			else r[i][j] = 0;
		}
	}

	for (int i = 0; i < h; i++) {
		if (s[i][w - 1] == '.') l[i][w - 1] = 1;
		for (int j = w - 2; j >= 0; j--) {
			if (s[i][j] == '.') l[i][j] = l[i][j + 1] + 1;
			else l[i][j] = 0;
		}
	}

	for (int j = 0; j < w; j++) {
		if (s[0][j] == '.') d[0][j] = 1;
		for (int i = 1; i < h; i++) {
			if (s[i][j] == '.') d[i][j] = d[i - 1][j] + 1;
			else d[i][j] = 0;
		}
	}

	for (int j = 0; j < w; j++) {
		if (s[h - 1][j] == '.') u[h - 1][j] = 1;
		for (int i = h - 2; i >= 0; i--) {
			if (s[i][j] == '.') u[i][j] = u[i + 1][j] + 1;
			else u[i][j] = 0;
		}
	}

	int ans = -1;
	rep(i, h) {
		rep(j, w) {
			int t = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
			if (t > ans) ans = t;
		}
	}
	
	cout << ans << endl;

	/*rep(i, h) {
		rep(j, w) {
			cout << l[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	rep(i, h) {
		rep(j, w) {
			cout << r[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	rep(i, h) {
		rep(j, w) {
			cout << u[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	rep(i, h) {
		rep(j, w) {
			cout << d[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
*/}

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


int main() {
  int n, k, temp;
  std::vector<int> data;
  cin >> n >> k;
  for (int i=0; i < n; i++) {
    cin >> temp;
    data.push_back(temp);
  }
  std::sort(data.begin(), data.end());
  if (n < k) {
    cout << 0 << endl;
  } else {
    long long ans=0;
    for (int i=k; i < n; i++) {
      ans += data[n - 1 - i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1400
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int x,t;
	cin>>x>>t;
	cout<<max(1LL*0,x-t)<<endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K; string S; cin >> N >> S >> K; --K;
    for (int i=0;i<N;++i) if (S[i]!=S[K]) S[i]='*';
    cout << S << '\n';
}

Measured memory_bytes: 256
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 static int a_dist[];
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int K = sc.nextInt();
	        long ans =0;
	        long tmp=0;
	        long now=7;
	        for (int i=0 ; i<K+100; i++) {
	        	tmp=tmp+now;
	        	if(tmp%K==0) {
	        		System.out.println(i+1);
	        		return;
	        	}

	        	now=(now*10)%K;
	        }
	        System.out.println(-1);
		 }
		 
	}

Measured memory_bytes: 35708
#include<stdio.h>
int main(){
	int Nx,K[1000]={0},P[1000]={0},i,j;
	scanf("%d",&Nx);
	for(i=0;i<Nx;i++){
		scanf("%d %d",&K[i],&P[i]);
	}
	for(j=0;j<Nx;j++){
		if(K[j]%P[j]!=0){
			printf("%d\n",K[j]%P[j]);
		}else{
			printf("%d\n",P[j]);
		}
	}
	return 0;
}

Measured memory_bytes: 604
def main():
    N,T=map(int,input().split())
    t=list(map(int,input().split()))
    s = 0
    c = 0
    for t1 in t:
        c = max(c, t1)
        if c > t1:
            s += t1 - c + T
            c += t1 - c + T
        else:
            s += T
            c += T
    print(s)
    
if __name__ == "__main__":
    main()

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

int main(){
    long long A,B,C;
    cin>>A>>B>>C;
    long long ans = 10000000000;
    
    if(A % 2 * B % 2 * C % 2 == 0) ans = 0;
    else{
        long long tmp1,tmp2,tmp3;
        tmp1 = A*B;
        tmp2 = A*C;
        tmp3 = B*C;
        ans = min({tmp1,tmp2,tmp3});
    }

    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N;
  cin >> N;
  
  vector<int> A(N);
  
  for(auto& e : A)
  {
    cin >> e;
  }
  
  vector<int64_t> prefix_sums(N + 1);
  prefix_sums[0] = 0;
  
  for(int i = 0; i < N; ++i)
  {
    prefix_sums[i + 1] = prefix_sums[i] + A[i];
  }
  
  vector<vector<int64_t> > dp(N, vector<int64_t>(N));
  
  for(int i = 0; i < N - 1; ++i)
  {
    dp[i][i + 1] = A[i] + A[i + 1];
  }
  
  for(int dist = 3; dist <= N; ++dist)
  {
    for(int L = 0, R = dist - L - 1; R < N; ++L, ++R)
    {
      const int64_t range_sum{prefix_sums[R + 1] - prefix_sums[L]};
      int64_t temp{min(dp[L + 1][R], dp[L][R - 1])};
      
      for(int i = L + 1; i < R - 1; ++i)
      {
        temp = min(temp, dp[L][i] + dp[i + 1][R]);
      }
      
      dp[L][R] = temp + range_sum;
    }
  }
  
  cout << dp[0][N - 1] << "\n";
  
  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> vc;
    vector<int> vc2;
    int num;
    for (int i = 0; i < N; i++)
    {
        cin >> num;
        vc.push_back(num);
        vc2.push_back(num);
    }
    sort(vc.begin(), vc.end());
    int counter = 0;
    for (int i = 0; i < N; i++)
    {
        if(vc[i]!=vc2[i])counter++;
    }
    if (counter == 0)
    {
        cout << "YES" << endl;
    }else if (counter==2)
    {
        cout << "YES" << endl;
    }else
    {
        cout << "NO" << endl;
    }
    
    
    
    

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)
#define f first
#define se second
#define M 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<long long, long long>
#define vi vector<int>
#define ll long long

vector<pair<pair<ll,ll>,ll>>seg;
int inf=1e9;

pair<pair<ll,ll>,ll> find(int st,int l,int r,int l1,int r1){
    if(l1>r||r1<l){
        return mp(mp(0,0),0);
    }
    if(l1<=l&&r1>=r){
        return seg[st];
    }
    if(l==r){
        //cout<<seg[st].first.second<<" "<<seg[st].first.first<<" "<<seg[st].second<<endl;
        return seg[st];
        
    }
    
    int mid=(l+r)/2;
    pair<pair<ll,ll>,ll> v1=find(st*2,l,mid,l1,r1);
    pair<pair<ll,ll>,ll> v2=find(st*2+1,mid+1,r,l1,r1);
    ll k=min(v1.first.first,v2.first.second);
    v1.second=v2.second+v1.second+2*k;
    v1.first.first=v1.first.first+v2.first.first-k;
    v1.first.second=v1.first.second+v2.first.second-k;
    //cout<<v1.second<<" "<<l<<" "<<r<<endl;
    return v1;

}
void update(int st,int pos,int l,int r,char val){
    if(l==r){
        if(val=='('){
            seg[st].first.first=1;
        }else {
            seg[st].first.second=1;
        }
        
        return;
    }
    int mid=(l+r)/2;
    if(pos<=mid){
        update(st*2,pos,l,mid,val);
        
    }else {
        update(st*2+1,pos,mid+1,r,val);
        //seg[st]=min(seg[st*2+1],seg[st*2+2]);
    }
    ll k=min(seg[st*2].first.first,seg[st*2+1].first.second);
    seg[st].second=seg[st*2].second+seg[st*2+1].second+2*k;
    seg[st].first.first=seg[st*2].first.first+seg[st*2+1].first.first-k;
    seg[st].first.second=seg[st*2].first.second+seg[st*2+1].first.second-k;
}


int main(){
  ll n;
  cin>>n;
  string s;
  cin>>s;
  
  ll count[n+1][3]={0};
  for(int i=0;i<n;i++){
      if(s[i]=='R'){
          count[i][0]++;
      }else if(s[i]=='G'){
          count[i][1]++;
      }else{
          count[i][2]++;
      }
      if(i==0){
          continue;
      }
      for(int j=0;j<3;j++){
          count[i][j]+=count[i-1][j];
      }
  }
  

  
  ll ans=0;
  map<char,int>mm;
  mm['R']=0,mm['G']=1,mm['B']=2;
  for(int i=2;i<n;i++){
      for(int j=i-1;j>0;j--){
          int in1=mm[s[i]],in2=mm[s[j]],in3;
          
          if(in1==in2){
              continue;
          }
         // cout<<in1<<" "<<in2<<endl;
          if((in1==0&&in2==1)||(in1==1&&in2==0)){
              in3=2;
          }else if((in1==1&&in2==2)||(in1==2&&in2==1)){
              in3=0;
          }else {
              in3=1;
          }
         // cout<<in3<<endl;
          ans+=count[j-1][in3];
          if(j-(i-j)>=0){
              if(mm[s[j-(i-j)]]==in3){
                  ans--;
              }
          }
      }
  }
  cout<<ans;
} 


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

int main() {
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i;cin >> n >> m;
  if(n%2){
    for(i=1;i<=m;i++) cout << i << " " << n-i << "\n";
  } else {
    int s = (n-1)/2;
    for(i=1;i<=min(m,s/2);i++) cout << i << " " << n-i << "\n";
    for(i=s/2+1;i<=m;i++) cout << i << " " << n-i-1 << "\n";
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);++i)


using namespace std;

int main(){
int N;
cin >>N;
vector<int> A,C;
int all=0;
rep(i,N){
	int a;
cin >>a;
A.emplace_back(a);
}
rep(i,N){
	int b;
cin >>b;
all+=b;
}
rep(i,N-1){ 
	int c;
cin >>c;
C.emplace_back(c);
}
rep(i,N-1){
	if(A[i+1]-A[i]==1)all+=C[A[i]-1];
}
cout <<all<<endl;
return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

ans = 10**18

for i in range(2**N):
    count = 0
    maxh = 0
    money = 0
    for j in range(N):
        if i >> j & 1:
            count += 1
            if maxh < A[j]:
                maxh = A[j]
            else:
                money += maxh+1-A[j]
                maxh += 1
        else:
            maxh = max(maxh,A[j])
    if count >= K:
        ans = min(ans,money)

print(ans)

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

/*............................*/

#define uint uint64_t
#define mx 100001
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mp make_pair
#define pb push_back
#define inf INT_MAX
#define pi acos(-1)
#define eps 1e-8
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define input(ara, n)          \
   for (int i = 0; i < n; i++) \
   scanf("%d", &ara[i])
#define inputl(ara, n)                   \
   for (long long int i = 0; i < n; i++) \
   scanf("%lld", &ara[i])
#define pf(a) printf("%d\n", a);
#define pfl(a) printf("%lld\n", a);
#define pfi(a) printf("%d ", a);
#define pfll(a) printf("%lld ", a);
#define sc(a) scanf("%d", &a)
#define scc(a, b) scanf("%d %d", &a, &b)
#define sccdbl(a, b) scanf("%lf %lf", &a, &b)
#define sccc(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scccdbl(a, b, c) scanf("%lf %lf %lf", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define sccl(a, b) scanf("%lld %lld", &a, &b)
#define scccl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
using namespace std;
int main()
{
   // int t;
   // sc(t);
   // while (t--)
   // {

   // }
   int n;
   sc(n);
   int ara[n - 1], ar[n] = {0};
   input(ara, n - 1);
   ar[0] = ara[0];
   ll sum = ara[0];
   for (int i = 2; i < n; i++)
   {
      ar[i - 1] = min(ara[i - 2], ara[i - 1]);
      sum += ar[i - 1];
   }
   sum += ara[n - 2];
   pfl(sum);
   return 0;
}


Measured memory_bytes: 3708
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    HashMap<Long, ArrayList<Long>> map = new HashMap<Long, ArrayList<Long>>();
    for(int i = 0; i < n; i++) {
      long t = sc.nextLong();
      long d = sc.nextLong();
      if(map.containsKey(t)) {
        ArrayList<Long> list = map.get(t);
        list.add(d);
        map.put(t, list);
      } else {
        ArrayList<Long> list = new ArrayList<Long>();
        list.add(d);
        map.put(t, list);
      }
    }
    ArrayList<Long> list0 = new ArrayList<Long>();
    ArrayList<Long> list1 = new ArrayList<Long>();
    for(long key : map.keySet()) {
      ArrayList<Long> list = map.get(key);
      Collections.sort(list);
      list1.add(list.get(list.size() - 1));
      for(int i = 0; i < list.size() - 1; i++) {
        list0.add(list.get(i));
      }
    }
    Collections.sort(list0);
    Collections.sort(list1);

    PriorityQueue<Long> pq0 = new PriorityQueue<Long>();
    PriorityQueue<Long> pq1 = new PriorityQueue<Long>(Collections.reverseOrder());

    int p0 = list0.size() - 1;
    int p1 = list1.size() - 1;

    long oisisa = 0;

    for(int i = 0; i < k; i++) {
      if(p0 >= 0) {
        if(p1 >= 0) {
          if(list0.get(p0) >= list1.get(p1)) {
            pq0.add(list0.get(p0));
            oisisa += list0.get(p0);
            p0--;
          } else {
            oisisa += list1.get(p1);
            p1--;
          }
        } else {
          pq0.add(list0.get(p0));
          oisisa += list0.get(p0);
          p0--;
        }
      } else {
        oisisa += list1.get(p1);
        p1--;
      }
    }

    long syurui = (long)(list1.size() - 1 - p1);

    for(int i = p1; i >= 0; i--) {
      pq1.add(list1.get(i));
    }
    
    long ans = oisisa + (syurui * syurui);
    int t = (int)syurui;
    
    for(int i = (t + 1); i <= list1.size(); i++) {
      syurui++;
      if((pq0.size() >= 1) && (pq1.size() >= 1)) {
        long t0 = pq0.poll();
        long t1 = pq1.poll();
        oisisa -= t0;
        oisisa += t1;
        ans = Math.max(ans, (oisisa + (syurui * syurui)));
      } else {
        break;
      }
    }    

    System.out.println(ans);
  }
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int x=0, max = 0, n;
    string s;
    cin>>n>>s;
    for(auto v:s){
        if(v=='I'){
            x++;
        }
        else{
            x--;
        }
        if(x>max){
            max = x;
        }
    }

    cout<<max<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

ll n,c,x[100100]={0},v[100100]={0};
ll res=0;
ll sx[100100]={0},sv[100100]={0},a[100100]={0},b[100100]={0},rx[100100]={0};


signed main(){
    cin>>n>>c;
    for(int i=0;i<n;++i){
        cin>>x[i]>>v[i];
        sv[i+1]=sv[i]+v[i];
        rx[i]=c-x[i];
    }
    
    
    a[n-1]=max(0LL,v[n-1]-rx[n-1]),b[n-1]=max(0LL,v[n-1]-2*rx[n-1]);
    for(int i=n-2;i>=0;--i){
        a[i]=max(a[i+1],sv[n]-sv[i]-rx[i]);
        b[i]=max(b[i+1],sv[n]-sv[i]-2*rx[i]);
    }

    for(int i=0;i<=n;++i){
        ll t=sv[i];
        if(i==0){
            t+=a[0];
            res=max(res,t);
        }
        else{
            t-=x[i-1];
            ll s=t;
            int k=lower_bound(rx,rx+n,x[i-1],greater<ll>())-rx;
            if(k<n){
                if(i<=k)t=max(t,s+b[k]);
                else t=max(t,s+b[i]);
            }
            if(i<n)t=max(t,s+a[i]-x[i-1]);
            res=max(res,t);
        }
        //cout<<a[i]<<" "<<b[i]<<" "<<rx[i]<<endl;
    }

    cout<<res<<endl;



    

    return 0;
}

Measured memory_bytes: 5760
s = input()
flag = True
while s:
    if s[0:5] == "dream":
        s = s[5:]
        if s[0:2] == "er":
            if s[0:5] != "erase":
                s = s[2:]
    elif s[0:5] == "erase":
        s = s[5:]
        if s[0:1] == "r":
            if s[0:5] != "erase":
                s = s[1:]
    else:
        flag = False
        break
if flag == True:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3244
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  string S;cin>>S;
  vector<int> array(3);
  each(c,S){
    if(c=='a')array[0]++;
    if(c=='b')array[1]++;
    if(c=='c')array[2]++;
  }
  sort(ALL(array));
  if(array[2]-array[0]>1)print("NO");
  else print("YES");

}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop(i,b,n) for(int i=b;i<(n);++i)
#define each(e,v) for(auto &&e : v)

#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const double EPS = 1e-9;
const ll MOD = 1000000007;

template<typename A,typename B> inline void chmin(A &a,B b){ if(a>b) a=b; }
template<typename A,typename B> inline void chmax(A &a,B b){ if(a<b) a=b; }
template <typename T> inline void print(const T& x) { cout << x << endl; }

vector<ll> a;

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

    a = vector<ll>(n,0);
    rep(i,n) cin >> a[i];

    sort(a.begin(),a.end(), greater<ll>());

    ll sum = 0;
    for(int i=1; i<n; ++i){
        sum += a[i/2];
    }

    print(sum);

    return 0;
}


Measured memory_bytes: 4780
#include<stdio.h>
int main()
{
	int r,g,b;
	
	scanf("%d%d%d",&r,&g,&b);
	
	if((r*100+g*10+b)%4==0){
		puts("YES");
	}else{
		puts("NO");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <bitset>
#include <functional>
#include <tuple>
#include <complex>
#include <chrono>
#include <climits>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
default_random_engine generator;
// mt19937 rnd(1);

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);      

    int n, k;
    cin >> n >> k;  

    string s;
    cin >> s;

    char c = 'z';
    for (int i = 0; i < n; ++i) {
        c = min(c, s[i]);
    }

    if (k >= 15) {
        string res;
        for (int i = 0; i < n; ++i) {
            res += c;
        }
        cout << res << endl;
        return 0;
    }

    vector<string> cand;

    for (int i = 0; i < n; ++i) {
        if (s[i] != c) {
            continue;
        }
        string t = s.substr(i, n - i);
        for (int i = n - 1; i >= 0 && sz(t) < n; --i) {
            t += s[i];
        }

        int m = 0;
        while (m < sz(t) && t[m] == c) {
            ++m;
        }

        string res;
        for (int i = 0; i < min(n, (m << (k - 1))); ++i) {
            res += c;
        }
        for (int i = m; i < n && sz(res) < n; ++i) {
            res += t[i];
        }

        // cout << t << endl;
        // cout << res << endl;
        // cout << endl;
        cand.push_back(res);
    }
    sort(all(cand));

    cout << cand[0] << endl;

}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct edge{
    int to;
    lint cap;
    int rev;
};

int n;
vector<lint> a;
vector< vector<edge> > g;
int level[102], iter[102];

void add_edge(int from, int to, lint cap){
    g[from].push_back({to, cap, (int)g[to].size()});
    g[to].push_back({from, 0LL, (int)g[from].size() - 1});
    return;
}

void bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto &e : g[v]){
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
    return;
}

lint dfs(int v, int t, lint f){
    if(v == t){
        return f;
    }
    for(int &i = iter[v], i_len = g[v].size() ; i < i_len ; ++i){
        edge &e = g[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            lint d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                g[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

lint max_flow(int s, int t){
    lint flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0){
            return flow;
        }
        memset(iter, 0, sizeof(iter));
        lint f;
        while((f = dfs(s, t, LLINF)) > 0){
            flow += f;
        }
    }
    return flow;
}

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

    cin >> n;

    a.resize(n + 1);
    g.resize(n + 2);
    lint ans = 0;
    reps(i, n){
        cin >> a[i];
        if(a[i] <= 0LL){
            add_edge(0, i, -a[i]);
        }else{
            add_edge(i, n + 1, a[i]);
            ans += a[i];
        }
        for(int j = i * 2 ; j <= n ; j += i){
            add_edge(i, j, LLINF);
        }
    }

    ans -= max_flow(0, n + 1);
    cout << ans << endl;

    return 0;
}

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

int main()
{
	int energy;

	while (std::cin >> energy, energy)
	{
		int sol = 1e+9;

		for (int z = 0; z * z * z <= energy; z++)
		{
			for (int y = 0, yMax = energy - z * z * z; y * y <= yMax; y++)
			{
			//	int y = ::sqrt(energy - z * z * z);
				sol = std::min(sol, z + y + (energy - z * z * z - y * y));
			}
		}

		std::cout << sol << std::endl;
	}

	return(0);
}

Measured memory_bytes: 1160
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG /GCC環境下で[]による配列要素参照のエラーを出す
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
  int n,m;
  cin>>n>>m;
  vector<bitset<10>>vec(m);
  vector<int>k(m);
  vector<int>p(m);
  rep(i,m){
     cin>>k.at(i);
     rep(j,k.at(i)){
       int pos;
       cin>>pos;
       vec.at(i).set(pos-1,1);
     }
  }
  //cout<<vec.at(0)<<vec.at(1)<<endl;
  rep(i,m){
    cin>>p.at(i);
  }
  int sum =0;
  for(int tmp =0;tmp<(1<<n);tmp++){
    bitset<10>cnt(tmp);
    rep(i,m){
      int match = (vec.at(i)&cnt).count();
      if((match%2)!=p.at(i)){
        goto SKIP;
      }
    }
    sum+=1;
    //cout<<"hit:"<<cnt<<endl;
    SKIP:
    int alias;
    //cout<<cnt<<endl;
  }
    cout<<sum<<endl;
}   

  

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRInT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int) (v).size()

#define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define shandom_ruffle random_shuffle
#define funoredered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using funordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

constexpr int InF = 0x3f3f3f3f;
constexpr int nInF = 0xc0c0c0c0;
constexpr double EPS = 1e-8;
constexpr ll MOD = 1000000007LL;

template <typename T>
using ordered_set = 
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll modPow( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

inline int cmp_double( double x, double y, double tol = EPS) {
    return (x <= y + tol) ? ( x + tol < y) ? -1 : 0 : 1;
}

constexpr int ms = 3010;

long long dp[ms][ms];

int main()
{
	ios::sync_with_stdio(0); cin.tie(NULL);
    int n;
    cin >> n;
    vll V(n);
    
    for(auto& x : V) cin >> x;
    if(n == 1) {
        cout << V[0] << endl;
        return 0;
    }
    for(int i = 0; i < n - 1; ++i) {
        dp[i][i + 1] = max( V[i], V[i + 1]) - min(V[i], V[i + 1]); 
    }

    for(int i = 3; i <= n; ++i) {
        for(int st = 0; st + i - 1 < n; ++st) {
            dp[st][i + st - 1] = max( V[st] - dp[st + 1][i + st - 1], V[i + st - 1] - dp[st][i + st - 2] );
        }
    }
    
    cout << dp[0][n - 1] << endl;
    
    return 0;
}



Measured memory_bytes: 70016
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.1415926535897932384626;
long long int mod = 998244353;
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//abcのbed乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sumxor,sum,ans;
ll a,b,c,d,e,f,g,h,w,v;
ll x[800005],y[800005],z[900005];
ll dp[800005];


int main(){	
	cin>>n>>k;
	//if(n>=2001){
	//	return 0;
	//}
	for(i=0;i<n;i++){
		cin>>x[i];
		sum += x[i];
	}
	y[0] = x[0];
	for(i=1;i<n;i++){
		y[i] = y[i-1] + x[i];
	}
	dp[0] = 5;
	for(i=1;i<=2*n;i++){
		dp[i] = 2*i + 3;
	}
	ans = INF;
	for(j=1;j<=(n+5)/2;j++){
		sum = j * k;
		
		num = n-1;
		a = 0;
		while(num >= j){
			sum += dp[a] * (y[num] - y[num - j]);
			num -= j;
			a++;
		}
		sum += dp[a] * y[num];
		// J個ごとに和を取ろうぜ！
		if(sum < 0){
			sum = INF;
		}

		
		ans = min(ans,sum);
	}


	p(ans + k * n);
	
	return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int n,i,ima=0;
  cin>>n;
  long long int a[n],b[n];
  for(i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  for(i=n-1;i>=0;i--){
    ima+=b[i]-((a[i]+ima-1+b[i])%b[i]+1);
  }
  cout<<ima;
}

Measured memory_bytes: 1792