akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b ? "true" : "false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vector<bool> v) {
	string res;
	for(int i = 0; i < (int) v.size(); i++)
		res += char('0' + v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	for(int i = 0; i < S; i++)
		res += char('0' + b[i]);
	return res;
}

template<class T> string to_string(T v) {
    bool f = 1;
    string res;
    for(auto& x : v) {
		if(!f)
			res += ' ';
		f = 0;
		res += to_string(x);
	}
    return res;
}
 
void DBG() {
	cerr << "]" << endl;
}

template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

void solve() {
	int n;
	cin >> n;
	long long mod = 1e9 + 7;
	vector<long long> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	long long sm = a[0], ans = 0;
	for(int i = 1; i < n; i++){
		(ans += a[i] * sm) %= mod;
		(sm += a[i]) %= mod;
	}
	cout << ans << '\n';
}	
 
int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
 	
	int t = 1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 4780
#include <stdio.h>

#define A 0
#define X 1
#define Y 2
#define Z 3
#define W 4
#define B 5
#define NA 6

int map[6][2] = {
    {X, Y},
    {NA, Z},
    {X, NA},
    {W, B},
    {B, Y},
    {Y, X}
};

int main(void)
{
    char path[110];
    int i;
    int city;
    
    while (1){
        scanf("%s", path);
        if (path[0] == '#'){
            break;
        }
        
        city = A;
        i = 0;
        while (path[i] != '\0'){
            if (map[city][path[i] - '0'] == NA){
                break;
            }
            city = map[city][path[i] - '0'];
            i++;
        }
        if (city == B){
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    return (0);
}

Measured memory_bytes: 524
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int mod=1e9+7;
 
int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
	return res;
	}
const int N=100005;
int col[N];
vi adj[N];
map<pi,int>mp;
void dfs(int v,int p)
{
	if(p!=-1)
	{
		if(mp[{v,p}]&1){
			col[v]=1-col[p];
			}
			else col[v]=col[p];
		}
		for(auto i:adj[v])
		{
			if(i!=p)dfs(i,v);
			}
	}
 
void solve()
{
	int n;
	cin>>n;
	col[0]=1;
	for(int i=0;i<n-1;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		mp[{x,y}]=z;
		mp[{y,x}]=z;
		}
		dfs(0,-1);
		for(int i=0;i<n;i++)cout<<col[i]<<'\n';
	}
   
	
	
 
int main()
{   
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
    while(t--)
	{
        solve();
		}
	
	}

Measured memory_bytes: 22400
//   PIGMEISTER™   //

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

#define ll long long
#define ld long double
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define PI (ld)3.141592653589793238
#define MAX 100005

int main()
{
    jaldi;
    
    ll n, k;
    cin >> n >> k;
    ll a[n];
    sidha (i, 0, n) cin >> a[i];
    ll ans = 0;
    sort(a, a+n);
    sidha (i, 0, k) ans += a[i];
    cout << ans;
    
    return 0;
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false


long long int fact(int n){
    if(n==1){
        return 1;
    }else{
        return n* fact(n-1);
    } 
}
int main(){
    int n;
    cin>>n;
    cout<<fact(n)<<endl;
    return 0;
}

Measured memory_bytes: 3032
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(int.Parse).ToArray();

        var ans = Enumerable.Range(0, N - 1).SelectMany(i => Enumerable.Range(i + 1, N - i - 1).Select(j => Math.Abs(A[i] - A[j]))).Max();

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28316
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef  long long int ll;
using namespace std;
const int M=1e9+7;
const int N=1e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll ans[N];
int main()
{
    ll n;cin>>n;
    ll a[n+1];
    for(ll i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    ans[2]=abs(a[1]-a[2]);
    for(ll i=3;i<=n;++i)
    {
        ans[i]=min(abs(a[i-1]-a[i])+ans[i-1],abs(a[i-2]-a[i])+ans[i-2]);
    }
    cout<<ans[n];
}

Measured memory_bytes: 5024
#include <iostream>
#include <string.h>
using namespace std;

int main(){
      char S[15];
      cin >> S;
      int size = strlen(S);
      int O = 0,X = 0;
      for(int i =0;S[i]!='\0';i++){
            if(S[i] == 'o'){
                  O++;
            }else if(S[i] == 'x'){
                  X++;
            }
      }
      if(O + (15-size) >= 8){
            cout << "YES" << endl;
      }else{
            cout << "NO" << endl;
      }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a[3][3],i,j;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            scanf("%d",&a[i][j]);
    }
    if((a[0][0]+a[1][1]+a[2][2])*2==(a[1][0]+a[2][0]+a[2][1]+a[0][1]+a[0][2]+a[1][2]))
    {
        printf("Yes\n");
    }
    else printf("No\n");

}


Measured memory_bytes: 128
//57
#include<iostream>
#include<vector>
#include<bitset>
#include<queue>

using namespace std;

struct S{
  int t,v;
};

int main(){
  for(int n;cin>>n,n;){
    int v=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	int b;
	cin>>b;
	v|=b<<i*n+j;
      }
    }
    queue<S> que;
    S is={0,v};
    que.push(is);
    static bitset<1<<25> s;
    s.reset();
    s.set(v);
    for(;;){
      S c=que.front();
      if(c.v==0)break;
      que.pop();
      int j,k;
      for(j=0;j<n;j++){
	for(k=0;k<n;k++){
	  if(c.v>>j*n+k&1)goto next;
	}
      }
    next:
      for(int l=j;l<n;l++){
	for(int m=k;m<n;m++){
	  int nv=c.v;
	  for(int o=j;o<=l;o++){
	    for(int p=k;p<=m;p++){
	      nv^=1<<o*n+p;
	    }
	  }
	  if(s.test(nv))continue;
	  s.set(nv);
	  S ns={c.t+1,nv};
	  que.push(ns);
	}
      }
    }
    for(int i=0;i<que.front().t;i++){
      cout<<"myon";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 5960
n, w, k = [int(i) for i in input().split()]
l = []
cnt = 0
for _ in range(n):
  l.append(list(input()))
import itertools
for w_ in itertools.product((True, False), repeat=w):
  for n_ in itertools.product((True, False), repeat=n):
    cnt_ = 0
    for i in range(w):
      for j in range(n):
        if w_[i] and n_[j] and l[j][i] == '#':
          cnt_ += 1
    if cnt_ == k:
      cnt += 1
print(cnt)

Measured memory_bytes: 9132
#include <iostream>

#include <math.h>
using namespace std;

int main()
{
    int h,w;
    
    cin >> h;
    cin >> w;
    int k[w];
    int a[w];
    int b[h][w];
    int n = 0;
    for(int i = 0; i<w;i++){
        k[i]=0;
    }
    for(int i = 0; i<h-1;i++){
        for(int j = 0;j<w;j++){
            cin >> a[j];
            if((k[j]+a[j])%2==1){
                b[i][j]=1;
                k[j]=1;
                n++;
            }else{
                b[i][j]=0;
                k[j]=0;
                
            }
        }
    }
    for(int j = 0;j<w-1;j++){
        cin >> a[j];
        if((k[j]+a[j])%2==1){
            if(k[j+1]==0){
                k[j+1]=1;

            }else{
                k[j+1]=0;
            }
            b[h-1][j]=1;
            n++;
        }else{
            b[h-1][j]=0;
        }
    }
    cout << n << endl;
    for(int i = 0;i<h-1;i++){
        for(int j = 0; j<w;j++){
            if(b[i][j]==1){
                cout << i+1 << " " << j+1 << " " << i+2 << " " << j+1<< endl;
            }
        }
    }
    for(int j = 0; j<w-1;j++){
        if(b[h-1][j]==1){
            cout << h << " " << j+1 << " " << h << " " << j+2 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3072
fun main(args: Array<String>) {
    val N = nextInt()
    val S = next().map{ it == 'W' }.toMutableList()
    val L = 2 * N
    for (n in 1..L) {
        if ((L-n) % 2 == 1) S[n-1] = !S[n-1]
    }
//System.err.println(S.map{if (it) 'W' else 'B'}.joinToString(separator = ""))
    var l = 0L
    var ans = 1L
    val MOD = 1000000007L
    S.forEach {
        if (it) l++ else {
            ans *= l
            ans %= MOD
            l--
        }
    }
    for (n in 2..N) {
        ans *= n
        ans %= MOD
    }
    println(if (l == 0L) ans else 0)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())


Measured memory_bytes: 39212
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string n; cin>>n;
  for(int i=0; i<n.size(); i++){
    if(n[i]=='1')n.replace(i,1,"9");
    else if(n[i]=='9')n.replace(i,1,"1");
  }
  cout << n << endl;
}

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

int main() {
  unsigned long long a,b,x;
  cin >> a >> b >> x;

  unsigned long long ans, mod, st, ed, mod2;
  mod = a % x;
  if (mod == 0) {
    st = a;
  } else {
    st = a + (x - mod);
  }

  mod2 = b % x;
  ed = b - mod2;

  // cout << st << " " << ed << endl;
  if (st > ed) {
    ans = 0;
  } else {
    ans = (ed - st) / x;
    ans += 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 888
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    ans = 1

    if 0 in set(a_lst):
        ans = 0
    else:
        for a in a_lst:
            ans *= a
            if ans > 10 ** 18:
                ans = -1
                break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 102268
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N , M , count = 0;
    cin >> N >> M;
    vector<int> X(M) , Y(M - 1);
    for(int i = 0; i < M; i++) {
        cin >> X[i];
    }
    sort(X.begin() , X.end());
    for(int i = 0; i < M - 1; i++) {
        Y[i] = X[i + 1] - X[i];
    }
    sort(Y.begin(), Y.end());
    for(int i = 0; i < max(0 , M - N); i++) {
        count += Y[i];
    }
    cout << count << endl;
}

Measured memory_bytes: 3984
N = gets.to_i

ans = Hash.new(0) # 0で初期化したhash

1.upto Math.sqrt(N).floor do |x|
  1.upto Math.sqrt(N).floor do |y|
    1.upto Math.sqrt(N).floor do |z|
      pol = x*x + y*y + z*z + x*y + y*z + z*x
      if pol > N
      	next
      end
      ans[pol] += 1
    end
  end
end

N.times do |i|
  puts ans[i+1]
end



Measured memory_bytes: 14708
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a;
    string s;
    cin >> a >> s;
    if(a >= 3200){
        print(s);
    }else{
        print("red");
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define PI 3.14159265358979323846

ll div_ceil(ll n,ll k)
{
	return (n+k-1)/k;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	cout<<div_ceil(n,1000)*1000-n<<Endl;
	return 0;
}

Measured memory_bytes: 3628
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

ll fp(ll x,ll y){
	if(y == 0)
		return 1;
	ll temp = fp(x,y / 2);
	if(y&1)
		return mul(temp,mul(temp,x,MOD),MOD);
	else
		return mul(temp,temp,MOD);
}

int main()
{
	FASTIO;
	ll n,k;
	cin >> n >> k;
	v64 arr(n,0);
	for(int i = 0;i < n;i++)
		cin >> arr[i];
	v64 cnt1(n,0),cnt2(n,0);
	for(int i = 0;i < n;i++){
		//build cnt1
		int cnt = 0;
		for(int j = i - 1;j >= 0;j--)
			if(arr[j] < arr[i]) cnt++;
		cnt1[i] = cnt;
		//build cnt2
		cnt = 0;
		for(int j = i + 1;j < n;j++)
			if(arr[j] < arr[i]) cnt++;
		cnt2[i] = cnt;
	}
	ll ans = 0;
	for(int i = 0;i < n;i++)
		for(int j = i + 1;j < n;j++)
			if(arr[i] > arr[j]) ans++;
	ans = mul(ans,k,MOD);
	ll inv_2 = fp(2,MOD - 2) % MOD;
	for(int i = 0;i < n;i++){
		ll temp1 = add(cnt1[i],cnt2[i],MOD);
		ll temp2 = mul(k,k-1,MOD);
		temp2 = mul(temp2,inv_2,MOD);
		temp1 = mul(temp2,temp1,MOD);
		ans = add(ans,temp1,MOD);
	}
	cout << ans << ln;
	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
# t字
def kawa(W, H):
    s_3 = H*W
    for h in range(1, H+1):
        s_a = h*W
        s_b = (H-h)//2 * W
        s_c = H*W - s_a - s_b
        s_3 = min(s_3, max(s_a, s_b, s_c) - min(s_a, s_b, s_c))
    return s_3

def t(W, H):
    s_t = H*W
    for h in range(1, H+1):
        s_a = h*W
        s_b = (H-h)*(W//2)
        s_c = H*W - s_a - s_b
        s_t = min(s_t, max(s_a, s_b, s_c)-min(s_a, s_b, s_c))
    return s_t

sa1 = kawa(H, W)
sa2 = kawa(W, H)
sa3 = t(W, H)
sa4 = t(H, W)
print(min(sa1, sa2, sa3, sa4))


Measured memory_bytes: 73516
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,K = inpl()
vv = inpl()

ans = 0
for lnum in range(K+1):
    for rnum  in range(K-lnum+1):
        if lnum + rnum > N:
            continue
        torukazu = vv[:lnum] + vv[N-rnum:]
        torukazu.sort()
        #print(' ' , torukazu,lnum,rnum)
        for sute in range(K-lnum-rnum+1):
            #print(torukazu[sute:])
            tmp = sum(torukazu[sute:])
            ans = max(tmp,ans)

print(ans)


Measured memory_bytes: 4336
n,a,b=map(int,input().split())
apb=a+b
s=list(input())
juni=0
kokunai=0
kaigai=0
for i in s:
  if i=='a':
    kokunai+=1
    if kokunai+kaigai<=apb:
      print('Yes')
    else:
      print('No')
  elif i=='b':
    kaigai+=1
    if kokunai+kaigai<=apb and b>=kaigai:
      print('Yes')
    else:
      kaigai-=1
      print('No')
  else:
    print('No')

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

int main() {

  int N;
  cin >> N;

  long long answer = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      answer += i;
    }
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 3624
#include<iostream>
#include<math.h>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<string>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
typedef long long ll;
using namespace std;

int main()
{
    
    ios_base:: sync_with_stdio(0);
    cin.tie();
    cout.tie(0);
    int n , m;
    cin >> n >> m;
    int c;
    cin >> c;
    vector<pair<int , int >> a(c);
    for(int i = 0;  i < c; i++)
    {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    sort(a.rbegin(), a.rend());
    //  cout << "\n";
    int arr[n][m];
    int cnt = n * m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            arr[i][j] = 0;
    int k = 0;
    int curi = 0 , curj = 0;
   
   // while(k != c)
    for(int i = 0 ; i < n; i++)
    {
       if(i % 2 == 0) for(int j = 0; j < m; j++)
        {
            if(a[k].first)
            {
                arr[i][j] = a[k].second;
                a[k].first--;
            }
            else
            {
                k++;
                if(a[k].first)
                {
                    arr[i][j] = a[k].second;
                    a[k].first--;
                }
            }
        }
        else
            for(int j = m - 1; j >= 0; j--)
            {
                if(a[k].first)
                {
                    arr[i][j] = a[k].second;
                    a[k].first--;
                }
                else
                {
                    k++;
                    if(a[k].first)
                    {
                        arr[i][j] = a[k].second;
                        a[k].first--;
                    }
                }

            }

    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cout << arr[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}

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

using LL = long long;
using Point = pair<int, int>;
using Interval = pair<int, int>;
using Event = pair<int, bool>;
const bool IN = false;
const bool OUT = true;

int N, K;
string S;

LL loop(auto& p) {
  set<Point> s(begin(p), end(p));
  LL res = 0;
  for(auto i: s) {
    auto x = i.first, y = i.second;
    if(s.count({x+1, y}) && s.count({x, y+1}) && s.count({x+1, y+1})) ++res;
  }
  return res;
}

LL solve(auto& p, int a, int b) {
  // vectorize
  map<Point, set<Interval>> vec;
  for(auto i: p) {
    auto k = i.first / a;
    auto x = i.first % a;
    auto y = i.second - b * k;
    if(x < 0) {
      --k;
      x += a;
      y += b;
    }
    vec[{x, y}].emplace(k, k + K - 1);
  }

  // merge
  map<Point, set<Event>> event;
  for(auto& i: vec) {
    auto cur = begin(i.second);
    auto l = cur->first, h = cur->second;
    for(auto pre = cur++; pre != end(i.second); pre = cur++) {
      if(cur == end(i.second)) {
        event[i.first].emplace(l, IN);
        event[i.first].emplace(h, OUT);
        break;
      }
      if(cur->first - 1 <= pre->second) h = cur->second;
      else {
        event[i.first].emplace(l, IN);
        event[i.first].emplace(h, OUT);
        l = cur->first;
        h = cur->second;
      }
    }
  }

  // intersect
  LL res = 0;
  for(auto i: event) {
    auto cur = i.first;
    multiset<Event> q;
    for(auto neighbor: {cur, {cur.first + 1, cur.second}, {cur.first + 1, cur.second + 1}, {cur.first, cur.second + 1}}) {
      auto dif = 0;
      if(neighbor.first >= a) {dif = 1; neighbor = {neighbor.first - a, neighbor.second - b};}
      if(!event.count(neighbor)) break;
      for(auto e: event[neighbor]) q.emplace(e.first - dif, e.second);
    }
    // count
    auto cnt = 0, begin = 0;
    for(auto e: q) {
      if(e.second == IN) {
        ++cnt;
        begin = e.first;
      } else {
        if(cnt == 4) res += e.first - begin + 1;
        --cnt;
      }
    }
  }
  return res;
}

LL solve() {
  // simulate
  auto x = 0, y = 0;
  vector<Point> p;
  p.emplace_back(x, y);
  for(auto i: S) {
    x += (i=='E') - (i=='W');
    y += (i=='N') - (i=='S');
    p.emplace_back(x, y);
  }

  if(x == 0 && y == 0) return loop(p);

  if(x == 0) {swap(x, y); for(auto& i: p) swap(i.first, i.second);}
  if(x < 0) {x *= -1; for(auto& i: p) i.first *= -1;}
  return solve(p, x, y);
}

int main() {
  cin >> N >> K >> S;
  cout << solve() << endl;
}

Measured memory_bytes: 36448
#include<iostream>
using namespace std;
int main()
{
    int N;
    long long ans = 0;
    cin >> N;
    for (int i = 1; i <= N; i++)
        if ((i % 3 != 0) && (i % 5 != 0))
            ans += i;
    cout << ans;
    return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    static bool isprime[1000001];
    isprime[2]=true;
    for(int i=3; i<1000000; i+=2) isprime[i]=true;
    for(int i=3; i<1000; i+=2){
        if(!isprime[i]) continue;
        int d=i+i;
        for(int j=i+d; j<1000000; j+=d)isprime[j]=false;
    }
    int n;
    while(cin>>n){
        int ans=0;
        for(int i=2; i<=n; ++i) if(isprime[i]) ++ans;
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fo(i,n) for(i=0;i<n;i++)
#define fO(i,n) for(i=0;i<=n;i++)
#define fox(i,x,n) for(i=x;i<n;i++)
#define foX(i,x,n) for(i=x;i<=n;i++)
#define Sort(v) sort(v.begin(),v.end())
void test()
{
	cout<<"thakur"<<endl;
}
const int mod = 1000000007;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,x,i;
	int dp[100001];
	memset(dp,0,sizeof(dp));
	cin>>n;
	vi v;
	fo(i,n){cin>>x;v.pb(x);}
	dp[1] = abs(v[1] - v[0]);
	for(i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]),dp[i-2] + abs(v[i] -v[i-2]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4236
N = int(input())
cost = [0,0,0,0,0]
for i in range(5):
    cost[i] = int(input())
mini = min(cost)

if mini >= N:
    print(5)
elif N % mini == 0:
    print(4+N//mini)
else:
    print(6+(N-mini)//mini)


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

int main()
{
    string s;
    cin >> s;
        
    for (int i = 0; i < s.size(); i++) {
        int flag = 0;
        for (int j = 0; j < s.size(); j++) {
            if (s[i] == s[j]) flag++;
        }
        if (flag % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 384
// AtCoder ABC129: B - Balance
// 2019.9.4 bal4u

#include <stdio.h>

int s[103];

#define ABS(a)  ((a)>=0?(a):-(a))

int main()
{
	int i, d, ans, N, W;
	
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &W), s[i] = s[i-1] + W;
	ans = 10000000;
	for (i = 1; i <= N; i++) {
		d = s[N] - (s[i] << 1);
		if (ABS(d) < ans) ans = ABS(d);
	} 
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

template<typename M, typename N>
istream& operator>>(istream&is, pair<M,N> & p){is >> p.first >> p.second; return is;}
template<typename M>
istream& operator>>(istream&is, vector<M> & v){for(auto &it:v) is >> it; return is; }
template<typename M>
istream& operator>>(istream&is, vector<vector<M>> & v){for(auto &it:v) is >> it; return is; }
template<typename M, typename N>
ostream& operator<<(ostream&os, const pair<M,N> &p){os << p.fi << ' ' << p.se << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<M> &v){for(auto it: v)os << it << ' ';cout << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<vector<M>> &v){for(auto it: v)os << it;return os;}

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e9;
const int mod=1000000007;
//const int mod=998244353;

int n,m,k;
const int N=2010;






int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin >> n;
    vpi v(n);
    cin >> v;
    vector<priority_queue<ll, vll>> pq(4);
    ll ans=0;
    for(int i=0 ;i<n; i++){
        if(i){
            ans=max({ans, pq[0].top()-(v[i].fi+v[i].se), pq[1].top()-v[i].fi+v[i].se, pq[2].top()+v[i].fi-v[i].se, pq[3].top()+v[i].fi+v[i].se});
        }
        pq[0].push(v[i].fi+v[i].se);
        pq[1].push(v[i].fi-v[i].se);
        pq[2].push(-v[i].fi+v[i].se);
        pq[3].push(-v[i].fi-v[i].se);
    }
    cout << ans << el;
    return 0;
}







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

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

    int n;
    cin >> n;

    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            if(i * 4 + j * 7 == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

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

using namespace std;


int main() {
    int n ; cin>>n;
    vector<int>num(100002);
    long long sum = 0;
    for(int i = 0 ; i < n; ++i){
        int x; cin>>x;
        sum += x;
        num[x]++;
    }
    int q; cin>>q;
    for(;q--;){
        int b ,c; cin>>b>>c;
        long long now = sum - (long long)num[b] * b + (long long)num[b] * c;
        cout<<now<<endl;
        sum = now;
        num[c] += num[b];
        num[b] = 0;
    }
    return 0;
}

Measured memory_bytes: 3788
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<set<int>> bits(20);
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < 20; k++)
      if (a[i] & (1 << k))
        bits[k].insert(i);
  }
  vector<int> left(n);
  left[0] = 0;
  for (int i = 1; i < n; i++) {
    int maxL = -1;
    for (int k = 0; k < 20; k++) {
      if (a[i] & (1 << k)) {
        auto it = bits[k].find(i);
        if (it == bits[k].begin())
          continue;
        it--;
        maxL = max(maxL, *it);
      }
    }
    left[i] = maxL + 1;
  }
  long long ans = 0;
  vector<int> dp(n);
  dp[0] = 0;
  ans += dp[0] + 1;
  for (int i = 1; i < n; i++) {
    dp[i] = max(left[i], dp[i - 1]);
    ans += (i - dp[i]) + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 97152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
ll sum[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,K;cin>>N>>K;
    
    for(ll i=K;i>=1;i--){
        sum[i]=rui(K/i,N);
        
        for(ll j=2;i*j<=K;j++){
            sum[i]+=mod;
            sum[i]-=sum[i*j];
            sum[i]%=mod;
        }
    }
    
    ll ans=0;
    
    for(ll i=1;i<=K;i++){
        ans+=sum[i]*i%mod;
        ans%=mod;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 4412
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    double second_moment, first_moment, score, std;

    while (cin >> n)
    {
        if (n == 0)
        {
            break;
        }
        first_moment = 0.0;
        second_moment = 0.0;
        for (int i = 0; i < n; ++i)
        {
            cin >> score;
            first_moment += score;
            second_moment += score * score;
        }
        first_moment /= n;
        second_moment /= n;
        std = sqrt(second_moment - first_moment * first_moment);
        printf("%10.8f\n", std);
    }
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[55],b[55],c[55],d[55];
int A[15],ans=0;
int n,m,q;
void dfs(int id,int num){
    if(id==n+1){ //更新答案. 
		int sum=0;
		for(int i=1;i<=q;i++)
			if(A[b[i]]-A[a[i]]==c[i]) sum+=d[i];
		ans=max(ans,sum); 
		return;
	}
	for(int i=num;i<=m;i++){ //非递减序列. 
		A[id]=i;
		dfs(id+1,i);
	}
}
int main(){
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(1,1);
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			System.out.println((N + 1000 - 1) / 1000 * 1000 - N);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32624
#include<iostream>
using namespace std;
int N;
int S[10][10];
int A[5][2]={{1,0},{0,1},{-1,0},{0,-1},{0,0}};
int B[9][2]={{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1},{0,0}};
int C[13][2]={{2,0},{0,-2},{-2,0},{0,2},{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1},{0,0}};
int cnt;
bool dfs(int x,int y,int id,int t)
{
	if(id==N)
	{
		return cnt==0;
	}
	if(t==0)
	{
		int k;
		for(k=0;k<5;k++)
		{
			int tx=x+A[k][0],ty=y+A[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)
			{
				if(S[tx][ty]==0)break;
				S[tx][ty]--;
				cnt--;
			}
		}
		if(k==5)
		{
			if(dfs(x,y,id+1,t))
			{
				cout<<y<<" "<<x<<" "<<1<<endl;
				return true;
			}
		}
		for(;k--;)
		{
			int tx=x+A[k][0],ty=y+A[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)S[tx][ty]++,cnt++;
		}
		return dfs(x,y,id,t+1);
	}
	else if(t==1)
	{
		int k;
		for(k=0;k<9;k++)
		{
			int tx=x+B[k][0],ty=y+B[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)
			{
				if(S[tx][ty]==0)break;
				S[tx][ty]--;
				cnt--;
			}
		}
		if(k==9)
		{
			if(dfs(x,y,id+1,t))
			{
				cout<<y<<" "<<x<<" "<<2<<endl;
				return true;
			}
		}
		for(;k--;)
		{
			int tx=x+B[k][0],ty=y+B[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)S[tx][ty]++,cnt++;
		}
		return dfs(x,y,id,t+1);
	}
	else if(t==2)
	{
		int k;
		for(k=0;k<13;k++)
		{
			int tx=x+C[k][0],ty=y+C[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)
			{
				if(S[tx][ty]==0)break;
				S[tx][ty]--;
				cnt--;
			}
		}
		if(k==13)
		{
			if(dfs(x,y,id+1,t))
			{
				cout<<y<<" "<<x<<" "<<3<<endl;
				return true;
			}
		}
		for(;k--;)
		{
			int tx=x+C[k][0],ty=y+C[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)S[tx][ty]++,cnt++;
		}
		if(x>=2)
		{
			if(S[x-2][y]>0)return false;
		}
		return dfs(y==9?x+1:x,y==9?0:y+1,id,0);
	}
}
main()
{
	cin>>N;
	for(int i=0;i<10;i++)for(int j=0;j<10;j++)
	{
		cin>>S[i][j];
		cnt+=S[i][j];
	}
	dfs(0,0,0,0);
}



Measured memory_bytes: 3116
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000+7
using namespace std;
typedef long long ll;

int main(){
  string S; cin >> S;
  vector<bool> dp(S.size()+1, false);
  dp[0]=true;
  rep(i, 0, S.size()){
    if(!dp[i])  continue;
    if(i+5<=S.size()&&S.substr(i, 5)=="dream")  dp[i+5]=true;
    if(i+7<=S.size()&&S.substr(i, 7)=="dreamer")  dp[i+7]=true;
    if(i+5<=S.size()&&S.substr(i, 5)=="erase")  dp[i+5]=true;
    if(i+6<=S.size()&&S.substr(i, 6)=="eraser")  dp[i+6]=true;
  }
  if(dp[S.size()]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
// @gaurav_512
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'
 
ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//
 
 
void solve()
{
	string s, t;
	cin >> s >> t;
	int slen = s.size(), tlen = t.size();
	vector<vector<int>>dp(slen+1,vector<int>(tlen+1,0));
	for(int i=1; i<=slen; i++)
	{
		for(int j=1; j<=tlen; j++)
		{
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if(s[i-1]==t[j-1])
				dp[i][j] = max(dp[i][j], 1+dp[i-1][j-1]);
		}
	}
	string lcs = "";
	int i=slen, j=tlen;
	while(i!=0 && j!=0)
	{
		if(s[i-1] == t[j-1])
		{
			lcs += s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j] == dp[i][j])
			i--;
		else
			j--;
	}
	reverse(all(lcs));
	cout << lcs;
}
 
int main()
{
	fastio;
//    int T;
//    cin>>T;
//    while(T--)
        solve();
	return 0;
}

Measured memory_bytes: 38556
#include <iostream>
#include <string>

class Node {
 public:
  int value;
  Node *prev;
  Node *next;
  Node(int value, Node *prev, Node *next) {
    this->value = value;
    this->prev = prev;
    this->next = next;
  };
};

class DoubleLinkedList {
  Node dummy;

 public:
  DoubleLinkedList() : dummy(Node(0, nullptr, nullptr)) {
    this->dummy.prev = &this->dummy;
    this->dummy.next = &this->dummy;
  }

  void insertElement(int num) {
    Node *newNode = new Node(num, &this->dummy, this->dummy.next);
    this->dummy.next->prev = newNode;
    this->dummy.next = newNode;
  }

  void deleteElement(int num) {
    auto node = this->dummy.next;
    while (node != &this->dummy) {
      if (node->value == num) {
        node->prev->next = node->next;
        node->next->prev = node->prev;
        delete node;
        return;
      }
      node = node->next;
    }
  }

  void deleteFirst() {
    auto first = this->dummy.next;
    auto second = first->next;
    if (first == &this->dummy) return;
    second->prev = &this->dummy;
    this->dummy.next = second;
    delete first;
  }
  void deleteLast() {
    auto last = this->dummy.prev;
    auto second = last->prev;
    if (last == &this->dummy) return;
    second->next = &this->dummy;
    this->dummy.prev = second;
    delete last;
  }

  void print() {
    auto node = this->dummy.next;
    while (node != &this->dummy) {
      std::cout << node->value << (node->next == &this->dummy ? "\n" : " ");
      node = node->next;
    }
  }
};

int main() {
  int n;
  scanf("%d", &n);
  auto list = DoubleLinkedList();
  for (int i = 0; i < n; i++) {
    char sbuf[20];
    int num;
    scanf("%s %d", sbuf, &num);
    std::string command = sbuf;

    if (command == "deleteFirst") {
      list.deleteFirst();
    } else if (command == "deleteLast") {
      list.deleteLast();
    } else if (command == "insert") {
      list.insertElement(num);
    } else if (command == "delete") {
      list.deleteElement(num);
    }
  }
  list.print();
  return 0;
}



Measured memory_bytes: 34492
#include <stdio.h>

int main(){
  int a,b,sum;
  char op;

  while(1){
    if(op=='?') break;
    scanf("%d %c %d",&a,&op,&b);

    if(op=='+') sum = a+b;
    else if(op=='-') sum = a-b;
    else if(op=='*') sum = a*b;
    else if(op=='/') sum = a/b;
    else return 0;
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    rep(i, 3001) rep(j, 3001) {
        if (n - i * r - j * g < 0) continue;
        if ((n - i * r - j * g) % b == 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  #define int long long
  int a;
  string b;
  cin >> a >> b;
  int b1 = b.at(0) - '0';
  int b2 = b.at(2) - '0';
  int b3 = b.at(3) - '0';
  int nb = b1 * 100 + b2 * 10 + b3;
  cout << a * nb / 100 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

vector<pair<int, int>> primeFactorization(int n) {
    int k = n;
    vector<pair<int, int>> ret;
    for (int i = 2; i <= sqrt(n); i++) {
        int cnt = 0;
        while(k % i == 0) {
            k /= i; // 重複を許さないならここを while に
            cnt++;
        }
        if (cnt) ret.push_back({i, cnt});
    }
    if(k > 1) ret.push_back({k, 1});
    return ret;
}

const int MAX = 210000;

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

Int combination_mod(Int n, Int r) {
    if(n < r) return 0;
    if(r == 0 || r == n) return 1;
    Int a = fac[n];
    Int b = fac[n-r];
    Int c = fac[r];

    Int x = a, y = (b * c) % MOD;
    return ( x * mod_pow(y, MOD-2) ) % MOD;
}

int main(){
    cin.tie(0);
    
    COMinit();
    int N, M;
    cin >> N >> M;
    Int ans = 1;
    auto factor = primeFactorization(M);
    for (int i = 0; i < factor.size(); i++){
        int cnt = factor[i].second;
        Int tmp = combination_mod(N+cnt-1, cnt);
        tmp %= MOD;
        ans = (ans * tmp) % MOD;
    }
    cout << ans << endl;
} 


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Program{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        var num = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
        var temp = new List<int>();
        int q = int.Parse(Console.ReadLine());
        for(int i=0; i<q; i++){
            int[] line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            temp = num
                .Take(line[0])
                .Concat(num.Skip(line[1]).Take(line[2]-line[1]))
                .Concat(num.Skip(line[0]).Take(line[1]-line[0]))
                .Concat(num.Skip(line[2]).Take(n-line[2]))
                .ToList();
            Swap(ref num, ref temp);
        }
        Console.WriteLine(string.Join(" ",num));
    }
    public static void Swap<T>(ref T a, ref T b){
        var t = a;
        a = b;
        b = t;
    }
}



Measured memory_bytes: 22404
#include<stdio.h>
int main(void){
  int h,w,k;
  scanf("%d%d%d",&h,&w,&k);
  char s[7][7];
  int black=0;
  int r[7],c[7];
  //printf("%d %d %d\n",h,w,k);
  for(int i=0;i<h;i++){r[i]=0;
               scanf("%s",s[i]);
    			
    for(int j=0;j<w;j++){c[j]=0;
    //  printf("%c",s[i][j]);
      if(s[i][j]=='#')black++;
    }
    //printf("\n");       
  }
  int wb=black;
  int ans=0;
  
  for(int i=0;i<(1<<h);i++){int rc=0;
for(int j=0;j<h;j++){
if(i&(1<<j)){
  //printf("行%d　",j);
          r[rc++]=j;
        }
    }
   for(int a=0;a<(1<<w);a++){int cc=0;
for(int b=0;b<w;b++){
if(a&(1<<b)){//printf("列%d",b);
          c[cc++]=b;
        }
    }
                             
//       printf("\n");
              int list[h][w];
             for(int a=0;a<h;a++){
for(int b=0;b<w;b++){
list[a][b]=0;
        }
     }
     for(int x=0;x<rc;x++){
for(int y=0;y<w;y++){
  //printf("%c",s[r[x]][y]);
if(s[r[x]][y]=='#'&&list[r[x]][y]==0){
wb--;
              list[r[x]][y]=1;
            }
        }
    //   printf("\n");
     }
     for(int x=0;x<h;x++){
for(int y=0;y<cc;y++){
  //printf("%c",s[x][c[y]]);
if(s[x][c[y]]=='#'&&list[x][c[y]]==0){
wb--;
              list[x][c[y]]=1;
            }
        }
      // printf("\n");
     }
     if(wb==k)ans++;
     wb=black;
    
   }
  }
 // printf("%d\n",black);
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1732