akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int V_MAX = 10;
int V,E;
vector<vector<int> > G(V_MAX);
int dfs(int cur, int vertex, set<int> st){
  st.insert(vertex);
  if(cur==V)return 1;
  int num = 0;
  for(int &e : G[vertex]){
    if(st.count(e))continue;
    num += dfs(cur+1, e, st);
  }
  return num;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> V >> E;
  rep(i,E){
    int x,y; cin >> x >> y;
    --x;--y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  cout << dfs(1,0,set<int>()) << endl;
  return 0;
}


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

int push(const vector<int>& a, int idx, int cnt) {
  if (cnt >= a.size()) return -1;
  if (idx == 1) return cnt;
  int next_idx = a.at(idx) - 1;
  cnt++;
  return push(a, next_idx, cnt);
}

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

  vector<int> a(N);
  rep(i, N) {
    cin >> a.at(i);
  }

  cout << push(a, 0, 0) << endl;
}



Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

// B

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());
		int Y = Integer.parseInt(sc.next());

		int[] Xn = new int[N];
		int[] Ym = new int[M];

		for(int i = 0; i < N; i++){
			Xn[i] = Integer.parseInt(sc.next());
		}

		for(int i = 0; i < M; i++){
			Ym[i] = Integer.parseInt(sc.next());
		}

		// 昇順にソート
		Arrays.sort(Xn);
		Arrays.sort(Ym);

		int Z = Ym[0];

		if((X < Z && Z <= Y) && (Xn[N-1] < Z)){
			System.out.println("No War");
		}else{
			System.out.println("War");
		}
	}
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

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; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    if (b >= a) cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <vector>
using namespace std;

int main() {
    int n;
    cin>>n;
    int a[2][105];
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    int c[105]={0};
    c[1]=a[0][0];
    for(int i=0;i<n;i++){
        c[1]+=a[1][i];
    }
    for(int i=2;i<n+1;i++){
        c[i]=c[i-1]+a[0][i-1]-a[1][i-2];
    }
    sort(c,c+105,greater<int>());
    cout<<c[0]<<endl;
    return 0;

 }

Measured memory_bytes: 256
import math

# for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
p = 1
r=0
m=math.pow(10,18)
if 0 in a:
    print(0)
else:
    for i in range(n):

        p = p * a[i]
        if p>m:
            r+=1
            break

    if r>0:
        print(-1)
    else:
        print(p)

Measured memory_bytes: 84560
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    int a[3];

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

    sort(a, a + 3);

    if (a[0] + a[1] == a[2]) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#define rep(i,a,b) for( int i=a;i<b;i++)
#define repr(i,a,b) for( int i=a;i>=b;i--)
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Anurag_Gupta ios_base::sync_with_stdio(0);
#define IIIT_ALLD cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Anurag_Gupta
    IIIT_ALLD

      int l,r,c,d;
      cin>>l>>r>>c>>d;

      int ans =0;

      int w = r/c;
      int g = (l-1)/c;


      ans +=max(0LL,(w-g));


     // cout<<ans<<" ";

       w = r/d;
       g = (l-1)/d;

      ans +=max(0LL,(w-g));


     // cout<<ans<<"\n";


      c = (c*d)/gcd(c,d);

       w = r/c;
       g = (l-1)/c;



      ans -=max(0LL,(w-g));

      cout<<(r-l+1)-ans<<"\n";









   
}


Measured memory_bytes: 256
use proconio::*;
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
    }
    let ans = (1..N + 1).filter(|&x| x % 5 != 0 && x % 3 != 0).sum::<usize>();
    // let mut ans: usize = 0;
    // for i in 1..N + 1 {
    //     if i % 3 == 0 || i % 5 == 0 {
    //         continue;
    //     }
    //     ans += i;
    // }
    println!("{}", ans);
}


Measured memory_bytes: 2152
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n<=111)
	cout<<111;
	else if(n<=222)
	cout<<222;
	else if(n<=333)
	cout<<333;
	else if(n<=444)
	cout<<444;
	else if(n<=555)
	cout<<555;
	else if(n<=666)
	cout<<666;
	else if(n<=777)
	cout<<777;
	else if(n<=888)
	cout<<888;
	else if(n<=999)
	cout<<999;
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

char s1[110];

int main()
{
	//fuck
	scanf("%s",s1);
	for(int i=0;i<strlen(s1);i++)
	{
		if(s1[i]==',')
		{
			s1[i]=' '; 
		}
	}
	printf("%s",s1);
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int a, b;

	std::cin >> a >> b;

	if (a < b)
	{
		std::cout << "a < b" << std::endl;
	}

	else if (a > b)
	{
		std::cout << "a > b" << std::endl;
	}

	else if (a == b)
	{
		std::cout << "a == b" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3028
n = int(input())
A = list(map(int,input().split()))

for i in range(n):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j = j-1
        A[j+1] = v
    for k in range(n-1):
        print(str(A[k]) + " ", end = "")
    print(str(A[n-1]))


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

const int INF = 100000000;

using namespace std;

int main(){
  int K;
  cin >> K;
  
  vector<int> rem(K, INF);
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  rem[1] = 1;
  pq.push({1, 1});
  
  while(pq.size()){
    auto [digits, node] = pq.top();
    pq.pop();
    
    if(rem[node] < digits) continue;
    
    if(digits + 1 < rem[(node + 1) % K]){
      rem[(node + 1) % K] = digits + 1;
      pq.push({digits + 1, (node + 1) % K});
    }
    
    if(digits < rem[node * 10 % K]){
      rem[node * 10 % K] = digits;
      pq.push({digits, node * 10 % K});
    }
  }
  
  cout << rem[0] << endl;
  
  return 0;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> s(h, vector<char>(w, '0'));
  rep(i, h) rep(j, w) cin >> s[i][j];

  vector<vector<int>> ans(h, vector<int>(w, 0));
  int kcur = 0;
  for(int i = 0; i < h; ++i){
    int cur = 0;
    for(int j = 0; j < w; ++j){
      if(s[i][j] == '#'){
        kcur++;
        cur = kcur;
      }
      if(ans[i][j] == 0){
        ans[i][j] = cur;
      }
    }
  }

  for(int i = 0; i < h; ++i){
    int cur = 0;
    for(int j = w-1; j >= 0; --j){
      if(s[i][j] == '#'){
        cur = ans[i][j];
      }
      if(ans[i][j] == 0){
        ans[i][j] = cur;
      }
    }
  }

  for(int j = 0; j < w; ++j){
    int cur = 0;
    for(int i = 0; i < h; ++i){
      if(ans[i][j] != 0){
        cur = ans[i][j];
      }
      if(ans[i][j] == 0){
        ans[i][j] = cur;
      }
    }
  }

  for(int j = 0; j < w; ++j){
    int cur = 0;
    for(int i = h-1; i >= 0; --i){
      if(ans[i][j] != 0){
        cur = ans[i][j];
      }
      if(ans[i][j] == 0){
        ans[i][j] = cur;
      }
    }
  }

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
	return 0;
}



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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n,k;
  cin>>k>>n;
  vector<ll> a(n);
  cin>>a;
  sort(a.begin(),a.end());
  ll ans = INF;
  a.emplace_back(k+a[0]);
  ll d = 0;
  rep(i,n)chmax(d,a[i+1]-a[i]);
  ll sum = 0;
  rep(i,n)sum+=a[i+1]-a[i];
  cout<< sum-d <<endl;

}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint
    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll N;
        cin>>N;
        vl a(N);
        map<ll,ll> fro;
        map<ll,ll> cou;
        vl vec;
        rep(i,N){
            cin>>a[i];
            if(fro[a[i]]==0){
                fro[a[i]]=i+1;
                vec.pb(a[i]);
            }
            cou[a[i]]++;
        }
        sort(rall(vec));
        ll i=1;
        vl Ans(N,0);
        ll num=0;
        while(i<Size(vec)){
            ll max=vec[i-1];
            ll next=vec[i];
            num+=cou[max];
            Ans[fro[max]-1]+=(max-next)*num;
            if(fro[max]<fro[next])fro[next]=fro[max];
            i++;
        }
        ll max=vec[Size(vec)-1];
        num+=cou[max];
        Ans[fro[max]-1]+=max*num;
        rep(i,N)cout<<Ans[i]<<endl;
    }

Measured memory_bytes: 15860
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int pt = 0, px = 0, py = 0;
    bool ok = true;
    for(int i = 0; i < n; i++){
        int t, x, y;
        cin >> t >> x >> y;
        int len = abs(x - px) + abs(y - py);
        if(len > t - pt){
            ok = false;
        }
        if((len & 1) != (t - pt & 1)){
            ok = false;
        }
        pt = t;
        px = x;
        py = y;
    }
    cout << (ok ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 888
N, K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*N 
dp[0] = 0

for i in range(N):
    for k in range(1,K+1):
        if i+k < N:
            dp[i+k] = min(dp[i+k],abs(h[i] - h[i+k]) + dp[i])

print(dp[-1])


Measured memory_bytes: 55264
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edges[a].append(b)
        edges[b].append(a)

    C = list(map(int, input().split()))
    C.sort(reverse=True)

    s = sum(C[1:])
    ans = [None] * N

    # c, node
    q = deque([(0, 0)])
    ans[0] = C[0]
    visited = [False] * N
    visited[0] = True
    used = [False] * N
    used[0] = True

    while q:
        c, node = q.popleft()

        for j in edges[node]:
            if visited[j]:
                continue

            for k in range(c + 1, N):
                if used[k]:
                    continue
                else:
                    next_c = k
                    break

            visited[j] = True
            used[next_c] = True
            ans[j] = C[next_c]
            q.append((next_c, j))

    print(s)
    print(*ans, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 12452
#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);

const int P = 998244353;

int u[3], v[3];

void mul(int &a, int b) {
    a = (ll)a * b % P;
}

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;
    cin >> n;
    string s;
    cin >> s;

    int cnt = 1;
    for (int i = 0; i < 3 * n; ++i) {
        int x = (s[i] == 'R' ? 0 : (s[i] == 'G' ? 1 : 2));
        if (v[x] != 0) {
            mul(cnt, v[x]);
            --v[x];
            continue;
        }
        int y = (1 + x) % 3, z = (2 + x) % 3;
        if (u[y] > 0) {
            mul(cnt, u[y]);
            --u[y];
            ++v[z];
            continue;
        }
        if (u[z] > 0) {
            mul(cnt, u[z]);
            --u[z];
            ++v[y];
            continue;
        }
        ++u[x];
    }
    for (int i = 1; i <= n; ++i) {
        mul(cnt, i);
    }

    cout << cnt << endl;


}


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

main()
{
    int n,k,d,x,ans=0;
    cin>>n>>k;
    vector<int>g[105];
    for(int i=1;i<=k;i++){
        cin>>d;
        while(d--){
            cin>>x;
            g[x].push_back(i);
        }
    }
    for(int i=1;i<=n;i++)
        if(!g[i].size()) ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int maxi = 5e5+5, n;
vector<int>  val(maxi), ano(maxi);
vector<vector<int>> node;

void init(){
    long long hei = ceil(log2(n));
    hei = 2*pow(2, hei);
    node.clear();
    node.resize(hei);
    unordered_map<int, int> tmp;
    for (int i=n; i; i--){
        if (tmp.find(val[i])==tmp.end())
            ano[i] = n+1;
        else ano[i] = tmp[val[i]];
        tmp[val[i]] = i;
    }
}
vector<int> merge(vector<int> &a, vector<int> &b){
    vector<int> to_ret;
    int i = 0, j = 0;
    while (i<a.size() && j<b.size())
        if (a[i]<b[j]) to_ret.emplace_back(a[i++]);
        else to_ret.emplace_back(b[j++]);
    while (i<a.size()) to_ret.emplace_back(a[i++]);
    while (j<b.size()) to_ret.emplace_back(b[j++]);
    return to_ret;
}

void build(int cur, int start, int end){
    if (start==end) {
        node[cur].emplace_back(ano[start+1]);
        return;
    }
    int mid = (start+end)/2;
    build(2*cur, start, mid);
    build(2*cur+1, mid+1, end);
    node[cur] = merge(node[2*cur], node[2*cur+1]);
}

int query(int cur, int l, int r, int rl, int rr, int k){
    if (rr<l || r<rl)
        return 0;
    if (l>=rl && r<=rr)
        return node[cur].size()-(upper_bound(node[cur].begin(), node[cur].end(), k)-node[cur].begin());
    int mid = (l+r)/2;
    return query(2*cur, l, mid, rl, rr, k)+query(2*cur+1, mid+1, r, rl, rr, k);
}

int solve2(int l, int r){
    r = min(r, n);
    return query(1, 0, n-1, l-1, r-1, r);
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int l, r;
    int q;
    cin>> n >> q ;
    for (int j=1; j<=n; j++)
        cin >> val[j];
    init();
    build(1, 0, n-1);
    while (q--){
        cin>> l >> r;
        cout << solve2(l, r) << "\n";
    }
}


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

int main() {
	int N; cin >> N;
	vector<string> vs(N);
	cout << 0 << endl;
	cin >> vs[0];
	int ok=0, ng=N, mid=0;
	while(vs[mid]!="Vacant"){
	    mid=(ok+ng)/2;
	    cout << mid << endl;
	    cin >> vs[mid];
	    if((vs[ok]==vs[mid])^((mid-ok)&(1<<0))) ok=mid;
	    else ng=mid;
	}
	return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int cnt = 0;

    for (int i = a; i <= b; i++) {
        if (i%10==i/10000 && i/10%10==i/1000%10) {
            cnt += 1;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3616
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int q;
    cin >> q;
    deque<int> dq;
    while (q--) {
        int t;
        cin >> t;
        if (t == 0) {
            int d, x;
            cin >> d >> x;
            if (d == 0) {
                dq.push_front(x);
            } else {
                dq.push_back(x);
            }
        } else if (t == 1) {
            int p;
            cin >> p;
            cout << dq[p] << endl;
        } else {
            int d;
            cin >> d;
            if (d == 0) {
                dq.pop_front();
            } else {
                dq.pop_back();
            }
        }
    }
}



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

inline int power(int a, int b) {
	int res = 1;
	while(b > 0) {
		if(b & 1) {
			res = res * a;
		}
		a = a * a;
		b >>= 1;
	}
	return res;
}


vector<int> bisa;

int main() {
	int n;
	cin >> n;
	bisa.push_back(1);
	for(int i = 2; i < n; ++i) {
		for(int j = 2; power(j, i) <= n; ++j) {
			bisa.push_back(power(j, i));
		}
	}
	sort(bisa.rbegin(), bisa.rend());
	cout << bisa[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

using ll = long long;
using pii = pair<int, int>;

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

	ll h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << "1\n";
	}
	else
		cout << (h * w + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
set <int> st;
set <char> stc;
string s;
int buc[26];
int main(int argc,char const* argv[])
{
  memset(buc,0,sizeof(buc));
  cin >> s;
  if(s=="zyxwvutsrqponmlkjihgfedcba")
    {
      cout << -1 << endl;
      return 0;
    }
  if(int(s.size())!=26)
    {
      for(int i=0;i<int(s.size());i++)
	{
	  buc[int(s[i]-'a')]++;
	}
      for(int i=0;i<26;i++)
	{
	  if(buc[i]==0)
	    {
	      s+=char('a'+i);
	      break;
	    }
	}
      cout << s << endl;
      return 0;
    }
  else
    {
      int index=25;
      for(int i=25;i>0;i--)
	{
	  if(s[i]<s[i-1])index=i-1;
	  else break;
	}
      string parts=s.substr(index);
      s=s.substr(0,index);
      sort(parts.begin(),parts.end());
      for(int i=0;i<parts.size();i++)
	{
	  if(parts[i]>s[int(s.size()-1)])
	    {
	      s[int(s.size()-1)]=parts[i];
	      break;
	    }
	}
      cout << s << endl;
      return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> v(n);
    map<int, int> m;
    rep(i, n)
    {
        cin >> v[i];
    }
    rep(i,1<<n){
        int s = 0;
        rep(j,n){
            if(i&(1<<j)){
                s+=v[j];
            }
        }
        m[s]++;
    }
    int q;
    cin >> q;
    rep(i,q){
        int x;
        cin >> x;
        if(m[x]){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
   // freopen("coins.in", "r", stdin);
   // freopen("coins.out", "w", stdout);
	int a;
cin >> a;
int ans=0;
while(a){
ans+=a%10;
a/=10;
}
cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // #define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max();

// RMQ
template<class T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree(int n_ = 0) : n(n_){
        n = 1;
        while(n < n_) n <<= 1;
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        dump(v,w,l,r);
        if(v >= (int)dat.size()) return inf;
        if(r - l == w){
            return dat[v];
        }
        if(r <= l) return inf;
        T res = inf;
        res = std::min(res, query(v*2, w/2, l, min(r, w/2)));
        res = std::min(res, query(v*2+1, w/2, max(0, l-w/2), r-w/2));
        return res;
    }
    void update(int i, T x){
        i += n;
        dat[i] = x;
        while(i != 1){
            dat[i>>1] = min(dat[i], dat[i^1]);
            i /= 2;
        }
    }
    T query(int l, int r){
        return query(1,n,l,r);
    }
    size_t size() const {
        return n;
    }
};

int main(){
    int n, q;
    while(cin >> n >> q){
        SegmentTree<int> st(n);
        rep(i,q){
            char c;
            int x, y;
            cin >> c >> x >> y;
            if(c == '0'){
                st.update(x,y);
            } else {
                cout << st.query(x,y+1) << endl;
            }
        }
    }
}

Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int n, k;
  cin >> n >> k;
  if (k > (n - 1) * (n - 2) / 2) {
    cout << -1 << endl;
    return 0;
  }

  int m = n - 1;
  vector<pair<int, int>> e;
  rep(i, m) {
    e.push_back({1, i + 2});
  }

  k = (n - 1) * (n - 2) / 2 - k;
  m += k;
  int u = 2, v = 3;
  rep(i, k) {
    e.push_back({u, v});
    v++;
    if (v == n + 1) {
      u++;
      v = u + 1;
    }
  }

  cout << m << endl;
  rep(i, m) cout << e[i].first << " " << e[i].second << endl;



  
  return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       long n = sc.nextLong();
       int A = sc.nextInt();
       int B = sc.nextInt();
       
//       String S = sc.next();
//       String T = sc.next();
//       char[] s = S.toCharArray();
//       char[] t = T.toCharArray();
       
       long bunsi1=1;
       long bunbo1=1;
       for(int i=0;i<A;i++) {
    	   bunsi1=bunsi1*(n-i)%mod;
    	   bunbo1=bunbo1*modinv(i+1)%mod;
       }
       long bunsi2=1;
       long bunbo2=1;
       for(int i=0;i<B;i++) {
    	   bunsi2=(bunsi2*(n-i))%mod;
    	   bunbo2=bunbo2*modinv(i+1)%mod;
       }
    	   
       long sub1=(bunsi1*bunbo1)%mod;
       long sub2=(bunsi2*bunbo2)%mod;
       long ans=((pow(2,n)-1-sub1-sub2)+2*mod)%mod;
       System.out.println(ans);
   }

	public static long pow(long a,long n) {
	    long res=1;
	    while (n>0) {
	        if ((n-n/2*2)==1) {
	            res=(res*a)%mod;
	        }
	        a=(a*a)%mod;
	        n>>=1;
	    }
	    return res;
	}
 
	public static long modinv(long n) {
		return pow(n, mod-2)%mod;
	}


}

Measured memory_bytes: 22736
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    INF = float('inf')
    MAX_V = 10 ** 3 * N
    dp = [INF] * (MAX_V + 1)
    dp[0] = 0
    for i in range(N):
        for j in range(MAX_V - v[i], -1, -1):
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i])
    ret = 0
    for j in range(MAX_V + 1):
        if dp[j] <= W:
            ret = max(ret, j)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]" 
    v = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 70732
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;

#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ

signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
        cin >>  a[i];
        sum+=a[i];
    }
    vector<int> x;
    for(int i=1;i*i<=sum;i++){
        if(sum%i==0){
            x.pb(i);
            x.pb(sum/i);
        }
    }
    int ans=1;
    for(int u:x){
        vector<int> aMOD(n);
        rep(i,n){
            aMOD[i]=(a[i]+u)%u;
        }
        sort(ALL(aMOD));
        ll left[n],right[n];
        left[0]=aMOD[0];
        right[n-1]=(u-aMOD[n-1]);
        rep(i,n-1){
            left[i+1]=left[i]+aMOD[i+1];
            right[n-i-2]=right[n-i-1]+(u-aMOD[n-i-2]);
        }
        rep(i,n-1){
            if(left[i]==right[i+1]&&left[i]<=k) chmax(ans,u);
        }
        if(left[n-1]==0||right[0]==0) chmax(ans,u);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3680
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
  long long x, y, len=0, a;
  scanf("%lld %lld %lld", &x, &y, &len);
  a=x;
  while(a<=y){
    len++;
    a*=2;
  }
  printf("%lld\n", len);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int k[] = new int[m];
        for (int i = 0; i < m; i++) {
            StringBuilder s = new StringBuilder("0000000000".substring(0, n));
            int x = Integer.parseInt(sc.next());
            for (int j = 0; j < x; j++) {
                int y = Integer.parseInt(sc.next());
                s.replace(y - 1, y, "1");
            }
            k[i] = Integer.parseInt(s.toString(), 2);
        }
        int p[] = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int ans = 0;
        for (int i = 0; i < Math.pow(2, n); i++) {
            int f = 1;
            for (int j = 0; j < m; j++) {
                String bin = Integer.toBinaryString(i & k[j]);
                int c = 0;
                for (int v = 0; v < bin.length(); v++) {
                    if (bin.substring(v, v + 1).equals("1")) {
                        c++;
                    }
                }
                if (c % 2 != p[j]) {
                    f = 0;
                    break;
                }
            }
            ans += f;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N, M;
    scan(N, M);
    vector<int> a(N);
    scan(a);
    vector<pair<int, int>> b(M);
    REP(i, M) scan(b[i].second, b[i].first);

    ll ans = 0;
    SORT(a);
    RSORT(b);
    int now = 0;

    REP(i, N) {
        if (b[now].second == 0)
            now++;
        if (a[i] < b[now].first && now < M) {
            ans += b[now].first;
            b[now].second--;
        } else {
            ans += a[i];
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 1408
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	LL K;
	cin >> K;
	if(K%2==0){
		if(1+K/2<=1e16){
			cout << 2 << endl;
			cout << 1+K/2 << " " << 1+K/2 << endl;
			return 0;
		}
	}
	else{
		if(1+(K+1)/2+1<=1e16){
			cout << 2 << endl;
			cout << 1+(K+1)/2-2 << " " << 1+(K+1)/2+1 << endl;
			return 0;
		}
	}

	LL U;
	if(K%50==0){
		U=K;
	}
	else{
		U=K+50-K%50;
	}
	vector<LL> v;
	for(int i=0;i<50;i++){
		v.push_back(49+U/50);
	}
	for(int i=0;i<U-K;i++){
		sort(v.begin(),v.end());
		for(int j=0;j<48;j++){
			v[j]++;
		}
		v[49]-=50;
	}
	cout << 50 << endl;

	auto sp="";
	for(int i=0;i<50;i++){
		cout << sp << v[i];
		sp=" ";
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int nmax=40,abmax=10,inf = 1000000;
int a[nmax],b[nmax],c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];
int main(void){
    int n,ma,mb;
    cin >> n >> ma >> mb;
    for(int i=0;i<n;++i){
        cin >> a[i] >> b[i] >> c[i];
}
    for(int i = 0; i <= n; ++i){
        for(int ca = 0; ca <= nmax*abmax; ++ca){
            for(int cb = 0; cb <= nmax*abmax; ++cb){
                dp[i][ca][cb]=inf;
} }
    }
    dp[0][0][0]=0;

for(int i=0;i<n;++i){
for(int ca = 0; ca <= nmax*abmax; ++ca){
            for(int cb = 0; cb <= nmax*abmax; ++cb){
                if(dp[i][ca][cb]==inf) continue;
                dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
} }
}
    int ans=inf;
    for(int ca = 1; ca <= nmax*abmax; ++ca){
        for(int cb = 1; cb <= nmax*abmax; ++cb){
            if(ca*mb==cb*ma) ans=min(ans,dp[n][ca][cb]);
} }
    if(ans==inf) ans=-1;
    cout << ans << endl;
return 0; }


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

using namespace std;

int main(void)
{
  string s1;
  string s2;
  int n1,n2 = 0;
  string incolor;

  cin >> s1 >> s2;
  cin >> n1 >> n2;
  cin >> incolor;
  
//  cout << s1 << " " << s2 << " " << n1 << " " << n2 << " " << incolor << "\n";
  
  if(incolor == s1){
    n1--;
//    printf("red\n");
  }else if(incolor == s2){
//    printf("blue\n");
    n2--;
  }else{
//    printf("error\n");
  }
  
  cout << n1 << " " << n2 << "\n";
}


Measured memory_bytes: 256
from collections import deque
S = deque(list(input()))
Q = int(input())
cnt = 0
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        cnt += 1
    elif query[1] == '1':
        if cnt % 2 == 0:
            S.appendleft(query[2])
        else:
            S.append(query[2])
    else:
        if cnt % 2 == 0:
            S.append(query[2])
        else:
            S.appendleft(query[2])
if cnt % 2 != 0:
    S.reverse()
print(''.join(S))


Measured memory_bytes: 8676
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    vector<string> s(3);
    cin>>s[0]>>s[1]>>s[2];
    int t = 0;
    vector<int> i(3);
    while(1){
        if(s[t].size() == i[t]){
            cout << char('A' + t) << endl;
            break;
        }
        t = s[t][i[t]++]-'a';
    }
}

Measured memory_bytes: 3572
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int m=sc.nextInt();
    if(m%1000==0){
      System.out.println("0");
    }else{
      System.out.println((m/1000+1)*1000-m);
    }
  }
}


Measured memory_bytes: 35756
mod = 10**9+7
L = input()
ans = 0
n = len(L)
c1 = 0
for c in L:
    n -= 1
    if c=="1":
        ans += pow(3, n, mod) * pow(2, c1, mod)
        c1 += 1
        ans %= mod
ans += pow(2, c1, mod)
ans %= mod
print(ans)


Measured memory_bytes: 3316
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

    ll i,j,h;
    ll N,K;
    ll temp;
    ll ans = 1;
    vector<ll> aa;
    ll count_minus=0;
   cin >> N>>K;
    rep(i,N){
        cin >> temp;
        aa.push_back(temp);
        if(temp<0){
            count_minus++;
        }
    }
//cout<<aa[0]<<endl;

if(N == K){
    rep(i,N){
        ans = ans*aa[i]%MOD;

    }
    if(ans<0){
        ans = MOD + ans;
        }
    cout << ans <<endl;
    return 0;
}



    if(( N == count_minus && K%2==1)|| (N==K && count_minus%2==1)   ){
        //cout << "a"<<endl;
        rep(i,N){
            aa[i] = abs(aa[i]);
        }
        sort(aa.begin(),aa.end());
        rep(i,K){
            ans = ans*aa[i]%MOD;
        }
        ans = -ans;
        if(ans<0){
        ans = MOD + ans;
        }
        cout << ans<<endl;
        return 0;
    }

    sort(aa.begin(),aa.end(),greater<int>());
    ll back_count = 0;
    ll mae_count = 0;
    ll count = K;

//cout<<aa[0]<<endl;

    while(1){
        if(count == 0){
            break;
        }else if(count ==1){

           
            ans = ans*aa[mae_count]%MOD;
            break;
            
        }

        if(aa[N-1-back_count]<0 &&aa[N-1-back_count-1]<0 ){
            if(aa[N-1-back_count]*aa[N-1-back_count-1]>=aa[mae_count]*aa[mae_count+1]){
                ans=ans*aa[N-1-back_count]%MOD;
                ans=ans*aa[N-1-back_count-1]%MOD;
                back_count +=2;
                count -=2;
            }else{
                if(count==3 && aa[mae_count+2]<0){
                    ans=ans*aa[N-1-back_count]%MOD;
                    ans=ans*aa[N-1-back_count-1]%MOD;
                    back_count +=2;
                    count -=2;
                }else{

                    ans=ans*aa[mae_count]%MOD;
                    ans=ans*aa[mae_count+1]%MOD;
                    mae_count+=2;
                    count -=2;
                }
            }
        }else{
            ans=ans*aa[mae_count]%MOD;
            ans=ans*aa[mae_count+1]%MOD;
            mae_count+=2;
            count -=2;
        }
    }



    if(ans<0){
        ans = MOD + ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4852