akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second
#define PI (3.1415926535897932384)
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// 1次元vectorの出力
template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}

// 2次元vectorの出力
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main(void){
	int n,k; cin >> n >> k;
	mint ans;
	for(ll i=k; i<=n+1; i++){
		ll s = i * (i-1) /2;
		ll l = (n-i+1 + n) * i /2;
		ans += (l - s + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3544
#include <stdio.h>
#include <setjmp.h>

int hand[10], f=0;
jmp_buf buf;

int checkR(int n)
{
     int i, t;

     if(n==4) return 1;
    
     for(i=1; i<=9; i++)
	  if(hand[i]>=3){
	       hand[i]-=3;
	       t = checkR(n+1);
	       hand[i]+=3;
	       if(t) return 1;
	  }

     for(i=1; i<=9-2; i++)
	  if(hand[i] && hand[i+1] && hand[i+2]){
	       hand[i]--, hand[i+1]--, hand[i+2]--;
	       t = checkR(n+1);
	       hand[i]++, hand[i+1]++, hand[i+2]++;
	       if(t) return 1;
	  }

     return 0;
}

int check()
{
     int i, t;

     for(i=1; i<=9; i++)
	  if(hand[i]>4) return 0;

     for(i=1; i<=9; i++)
	  if(hand[i]>=2){
	       hand[i]-=2;
	       t = checkR(0);
	       hand[i]+=2;
	       if(t) return 1;
	  }

     return 0;
}

int main(void)
{
     int i, t;
     
     while(1){
	  f=0;
	  for(i=1; i<=9; i++)
	       hand[i]=0;

	  for(i=0; i<13; i++){
	       if(!~scanf("%1d",&t)) return 0;
	       hand[t]++;
	  }

	  for(i=1; i<=9; i++){
	       hand[i]++;
	       if(check()){
		    if(!f) f=1; else printf(" ");
		    printf("%d",i);
	       }
	       hand[i]--;
	  }
	  if(!f) printf("0");
	  
	  puts("");
     }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define float long double
#define ss second
#define ff first
typedef vector<int> vi;
#define pb push_back
pair<pair<int,char>,pair<int,int>> dp[3001][3001];

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b;
	cin >> a >> b;
	int sa,sb;
	sa = a.length();
	sb = b.length();

	for(int i = 0 ; i<sb ; i++ ){
        if(a[0] == b[i]) dp[0][i] = {{1,a[0]},{-1,-1}};
        else if(i>0) dp[0][i] = dp[0][i-1];
        else dp[0][i] = {{0,'!'},{-1,-1}};
	}
	for(int i = 1 ; i < sa ; i++){
        if(a[i] == b[0]) dp[i][0] = {{1,a[i]},{-1,-1}};
        else dp[i][0] = dp[i-1][0];
        for(int j = 1; j < sb ; j++){
            if(a[i] == b[j]) { dp[i][j] = {{dp[i-1][j-1].ff.ff+1,a[i]},{i-1,j-1}};}
            else if(dp[i][j-1].ff.ff>dp[i-1][j].ff.ff) dp[i][j] = {{dp[i][j-1].ff.ff,'!'},{i,j-1}};
            else dp[i][j] = {{dp[i-1][j].ff.ff,'!'},{i-1,j}};
        }
	}


    int x,y;
    string s;
    x =  sa -1;
    y = sb-1;
    while(x!=-1){
        if(dp[x][y].ff.ss!='!') s.pb(dp[x][y].ff.ss);
        int a,b;
        a = dp[x][y].ss.ff;
        b = dp[x][y].ss.ss;
        x = a; y = b;
    }
    reverse(s.begin(),s.end());
    cout << s ;
}


Measured memory_bytes: 281600
a,b,c = gets.chomp.split.map(&:to_i)
#6tooritamesu
# abc
task1 = 0 + (b-a).abs+(c-b).abs
# acb
task2 = 0 + (c-a).abs+(b-c).abs
# bac
task3 = 0 + (a-b).abs+(c-a).abs
# bca
task4 = 0 + (b-c).abs+(a-c).abs
# cab
task5 = 0 + (c-a).abs+(a-b).abs
# cba
task6 = 0 + (c-b).abs+(a-b).abs
ans = [task1,task2,task3,task4,task5,task6].min
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P, vector<P>, greater<P>> SPQ;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const ll inf = 1001001001001001;
const int INF = 1001001001;
const int mod = 1000000007;
const double pi = 3.14159265358979323846;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> void out(T a) { cout << a << endl; }
template<class T> void outp(T a) { cout << '(' << a.fi << ',' << a.se << ')' << endl; }
template<class T> void outvp(T v) { rep(i, v.size())outp(v[i]); }
template<class T> void outv(T v) { rep(i, v.size()) { if (i)cout << ' '; cout << v[i]; }cout << endl; }
template<class T> void outvv(T v) { rep(i, v.size()) { rep(j, v[i].size()) { if (j)cout << ' '; cout << v[i][j]; }cout << endl; } }
int main() {
  ll h,w,n,m; cin>>h>>w>>n; m=max(h,w);
  int ans;
  if(n%m==0) ans=n/m;
  else ans=n/m+1;
  cout<<ans<<endl;
}


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

int main() {
    std::string A, B;
    std::cin >> A >> B;

    if (A.size() > B.size()) {
        std::cout << "GREATER\n";
        return 0;
    } else if (A.size() < B.size()) {
        std::cout << "LESS\n";
        return 0;
    }

    for (size_t i = 0; i < A.size(); ++i) {
        if ((int)(A[i]) > (int)(B[i])) {
            std::cout << "GREATER\n";
            return 0;
        } else if ((int)(A[i]) < (int)(B[i])) {
            std::cout << "LESS\n";
            return 0;
        }
    }

    std::cout << "EQUAL\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int i,j;
    cin >> i >> j;
    
    string s;
    
    for(int n =0; n<j+2; n++){
    	cout << "#" ;
    }
    
    cout << endl;
    
    for(int n =0; n<i; n++){
    	cin >> s;
        cout << "#" << s << "#" <<endl;
    }
    
    for(int n = 0; n<j+2; n++){
    	cout << "#";
    }
    
    cout << endl;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int K, N; std::cin >> K >> N;
  std::vector<ll> A(N); rep(i,N) std::cin >> A[i];

  ll dmin = K-A[N-1] + A[0];
  for(int i=0; i<N-1; i++) {
    dmin = std::max(dmin, A[i+1]-A[i]);
  }
  std::cout << K - dmin << std::endl;
  return 0;
}



Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static  ll INF = 1e9;
using namespace std;

signed main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	string t=s;
	int stack=0;
	rep(i,n){
		if(s[i]=='(')++stack;
		else {
			if(stack==0){
				t.insert(t.begin(),'(');
			}
			else stack--;
		}
	}
	if(stack>0)rep(i,stack)t+=')';
	cout<<t<<endl;
	return 0;
}


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

const int MAX_N = 1<<15;

vector<int> sq;

void make() {
  for(int i = 0; i*i <= MAX_N; ++i) {
    sq.push_back(i*i);
  }
}

int solve(int n) {
  int res = 0;
  for(int i = 0; i < sq.size() && sq[i] <= n; ++i) {
    for(int j = i; j < sq.size() && sq[i]+sq[j] <= n; ++j) {
      for(int k = j; k < sq.size() && sq[i]+sq[j]+sq[k] <= n; ++k) {
	int t = n - (sq[i] + sq[j] + sq[k]);
	vector<int>::iterator it = lower_bound(sq.begin(), sq.end(), t);
	if(it == sq.end() || *it != t) continue;
	if(*it >= sq[k]) ++res;
      }
    }
  }
  return res;
}

int main() {
  make();
  int n;
  while((cin >> n) && n) cout << solve(n) << endl;
  return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int mx=0;
    for(int i=0; i<=k; ++i){
        for(int j=0; j<=k-i; ++j){
            if(i+j>n)continue;
            int sum=0;
            vector<int>ans;
            rep(l,i){
                ans.push_back(a[l]);
            }
            for(int l=n-1; l>n-1-j; --l){
                ans.push_back(a[l]);
            }
            sort(ans.begin(),ans.end());
            int y=k-i-j;
            rep(l,y){
                if(l>=ans.size())break;
                if(ans[l]<0)ans[l]=0;
            }
            rep(l,ans.size())sum+=ans[l];
            mx=max(mx,sum);
        }
    }
    cout<<mx<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
 
 
int main() {
    int h,a;
    int ans = 0;
    cin>>h>>a;
    if(h<=a)
        ans =1;
    
    else if(h%a==0)
        ans = h/a;
    
    else{
    for(int i = h ; i>0 ;i-=a)
        ans++;
    }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n = arr.shift().split(" ")[0] - 0;
var x = [];
for (var i = 1; i <= n; i++) x.push([i,-1*i]);
arr.forEach(function(v,i) {
   x[v-0-1][1]=i;
});
x.sort(function(a,b){
   return b[1]-a[1];
});
x=x.map(function(v){
   return v[0];
});
console.log(x.join("\n"));

Measured memory_bytes: 68712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    double L; cin >> L;
    double e = L / 3.0;
    double ans = e*e*e;
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
#include <bitset>
#include <queue>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007



// ice rink game


signed main(){

	int N;
	cin >> N;
	int a[123456];
	for (int i = 0; i < N; i++)
		cin >> a[i];

	int mi=2, ma=2;
	for (int i = N - 1; i >= 0; i--){
		// mi以上のa[i]の倍数
		mi = ceil((double)mi / a[i])*a[i];
		if (mi>ma){
			cout << -1 << endl;
			return 0;
		}
		// ma以上のa[i]の倍数+a[i]-1
		ma = (ma / a[i])*a[i]+(a[i]-1);
		if (mi == 0 || ma == a[i] - 1){
			cout << -1 << endl;
			return 0;
		}
		cerr << mi << " " << ma << endl;
	}
	cout << mi << " " << ma << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100002];

int main(){
          
    ll n; cin >> n;
    //memset(dp,-1, sizeof(dp)/sizeof(dp[0]));
    std::vector<ll> v(n);
    for(auto &x : v)cin >> x;
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for(int i = 2;i <= n - 1;i++){
        dp[i] = min(abs(v[i] - v[i - 1]) + dp[i - 1], abs(v[i] - v[i - 2]) + dp[i - 2]);
    }
    cout<< dp[n - 1];
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}


int main(){
  ll a,b; cin >> a >>b;
  
  cout << (a+b) % 24 << endl;
  
}

Measured memory_bytes: 3656
#include<stdio.h>

long long inp_t, inp_c, inp_n1, inp_n2, i1;

long long inp_a[200005];

long long readNumber() {
	long long temp_func;
	scanf("%lld", &temp_func);
	return temp_func;
};
long long printNumber(long long temp_func) {
	printf("%lld", temp_func);
	return 0;
};

bool caler() {
	
	for (long long i1f = inp_n1; i1f <= inp_n2; i1f++) {
		
		if (i1f % inp_c == 0) {
			
			return true;
			
		};
		
	};
	
	return false;
	
};

int main() {
	
	inp_c = readNumber();
	
	inp_n1 = readNumber();
	
	inp_n2 = readNumber();
	
	if (caler()) {
		
		printf("OK");
		
	} else {
		
		printf("NG");
		
	};
	
}

Measured memory_bytes: 1732
N = int(input())
A = [int(_) for _ in input().split()]

abs_lis = [0] * N
count_neg = 0

for n in range(N):
    abs_lis[n] = abs(A[n])
ans = sum(abs_lis)
if 0 in A:
    print(ans)
else:
    for n in range(N):
        if A[n] < 0:
            count_neg += 1
    if count_neg % 2 == 1:
        print(ans - 2 * min(abs_lis))
    else:
        print(ans)

Measured memory_bytes: 14412
#include<cstdio>
#include<algorithm>

using namespace std;

int ans, n;
int a[100010];

int main(){
	int i;
	scanf("%d", &n);
	for(i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(i = 1; i < n; ++i)
	if(a[i] == i){++ans; swap(a[i], a[i+1]);}
	ans += a[n] == n;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;
    vint p(n);
    rep(i, n) cin >> p[i];

    double ans = 0;

    vint sum(n+1, 0);
    srep(i, 1, n+1) sum[i] = sum[i-1] + p[i-1];

    rep(i, n-k+1) {
        double tmp = sum[i+k] - sum[i] + k;
        ans = max(ans, tmp);
    }

    printf("%.10f", ans/2.0);
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N; cin >> N;
	rep(i, 9) {
		int x = 111 * (i+1);
		if (x - N >= 0) {
			cout << x << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)(n); ++i)
#define rrep(i, j, n) for (int i = (int)(n)-1; j <= i; --i)

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  vector<bool> used(m * 2);
  vector<ll> one_cycle;

  int start = 0;
  ll now = x;
  rep(i, 0, m) {
    used[now] = true;
    one_cycle.push_back(now);
    now = now * now % m;
    if (used[now]) {
      rep(j, 0, one_cycle.size()) if (one_cycle[j] == now) {
        start = j;
        break;
      }
      break;
    }
  }

  ll s1 = 0, s2 = 0, loop = one_cycle.size() - start;
  rep(i, 0, start) s1 += one_cycle[i];
  rep(i, start, one_cycle.size()) s2 += one_cycle[i];
  ll ans = s1 + (n - start) / loop * s2;
  rep(i, 0, (n - start) % loop) {
    ans += now;
    now = now * now % m;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
vll d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sortc(string &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a == b && b != c) Yes();
  else if (c == b && b != a) Yes();
  else if (a == c && b != c) Yes();
  else No();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int X = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        scanner.close();

        int F = (X - A) / B;

        int Ans = X- A - B*F;
        
        System.out.println(Ans);
    }
}

Measured memory_bytes: 21844
open Printf
open Scanf

let id x = x

let c11, c12, c13 = scanf "%d %d %d " (fun x y z -> x, y, z)
let c21, c22, c23 = scanf "%d %d %d " (fun x y z -> x, y, z)
let c31, c32, c33 = scanf "%d %d %d"  (fun x y z -> x, y, z)

let () =
    for a1 = 0 to 100 do
        for a2 = 0 to 100 do
            for a3 = 0 to 100 do
                let b1 = c11 - a1 in
                let b2 = c22 - a2 in
                let b3 = c33 - a3 in
                if c21 = a2 + b1 && c31 = a3 + b1 &&
                   c12 = a1 + b2 && c13 = a1 + b3 &&
                   c23 = a2 + b3 && c32 = a3 + b2
                then
                    (print_endline "Yes"; exit 0)
            done
        done
    done;
    print_endline "No"


Measured memory_bytes: 384
#include<cstring>  
#include<string>  
#include<algorithm>  
#include<iostream>  
#include<cmath>  
#include<cstdlib>  
#include<ctime>  
#include<map>  
#include<queue>  
#include<vector>  
#include<stack>  
#include<set>  
#define pa pair<int,int>  
#define INF 0x3f3f3f3f  
#define inf 0x3f  
#define fi first  
#define se second  
#define mp make_pair  
#define ll long long  
#define ull unsigned long long  
#define pb push_back  
#define pause system("pause")  
  
using namespace std;  
  
inline ll read()  
{  
    long long f=1,sum=0;  
    char c=getchar();  
    while (c<'0' || c>'9')  
    {  
        if (c=='-') f=-1;  
        c=getchar();  
    }     
    while (c>='0' && c<='9')  
    {  
        sum=sum*10+c-'0';  
        c=getchar();  
    }  
    return sum*f;  
}  
int main()  
{  
    ll l=read(),r=read();  
    int ans=0;  
    while (r>=l) l*=2,ans++;   
    cout<<ans;  
    return 0;  
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int m1,d1,m2,d2;
    scanf("%d %d",&m1,&d1);
    scanf("%d %d",&m2,&d2);
    if(m1+1 == m2)
        printf("1\n");
    else
        printf("0\n");
    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

// I want to delete this stupid solution ;(
#define sandwich(x) [](auto a, auto b){return (x)(a, b);}

template <typename T>
using F2 = std::function<T(T,T)>;

template <typename T, int N, typename F = std::plus<T> >
struct SegmentTree{
    SegmentTree(T u, F f = F()){
        size = 1;
        while(size < N){
            size <<= 1;
        }

        unit = u;
        func = f;

        init();
    }
    void init(){
        for(int i=0;i<size;++i){
            data[i+size] = unit;
        }

        for(int i=size-1;i>0;--i){
            data[i] = func(data[i*2], data[i*2+1]);
        }
    }
    void update(int k, T v){
        k += size;
        data[k] = v;

        while(k > 1){
            k >>= 1;
            data[k] = func(data[k*2], data[k*2+1]);
        }
    }
    inline T at(int k){
        k += size;
        return data[k];
    }
    inline T query(int l, int r){
        return _query(l, r, 1, 0, size);
    }
    T _query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a){return unit;}
        if(a <= l && r <= b){return data[k];}
        int mid = (l + r) >> 1;
        return func(_query(a, b,   2*k,   l, mid),
                    _query(a, b, 2*k+1, mid, r  ));
    }

    T unit, data[N*4];
    int size;
    F func;
};

int N, Q;
int bs[200100];
vector<int> queries[200100];
SegmentTree<int, 200100, F2<int> > segtree(1001001001, sandwich(min));

// a[idx] = 1 から a[idx] = 0 に変えたときのハミング距離の変化量
int f(int idx){
    if(bs[idx] == 0){
        return -1;
    }
    return +1;
}

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

    std::cin >> N;

    // a[i] = 1 (i = 1, 2, ..., N) のときのハミング距離
    int cost1 = 0;
    for(int i=1;i<=N;++i){
        std::cin >> bs[i];
        if(bs[i] == 0){++cost1;}
    }

    std::cin >> Q;

    for(int i=0;i<Q;++i){
        int l, r;
        std::cin >> l >> r;

        queries[l].emplace_back(r);
    }

    segtree.update(1, 0);

    for(int i=1;i<=N;++i){
        sort(queries[i].begin(), queries[i].end());
        reverse(queries[i].begin(), queries[i].end());

        for(int r : queries[i]){
            segtree.update(r + 1, segtree.query(i, r + 1 + 1));
        }

        segtree.update(i + 1, min(segtree.at(i + 1), segtree.at(i) + f(i)));
    }

    int res = cost1 + segtree.query(N + 1, N + 3);
    std::cout << res << std::endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N,K;
  cin >> N >> K;
  int x[N];
  for(int i=0; i<N; i++) cin >> x[i];
  int sum=0;
  for(int i=0; i<N; i++){
  	sum = sum + min(abs(x[i]),abs(x[i]-K))*2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
function main(arg) {
    //最大は1000000
    var kazua = parseInt(arg.trim().split(" ")[0]);
    var kazub = parseInt(arg.trim().split(" ")[1]);

    var tasu = kazua - 1;
    var hiku = -tasu;

    var zenbu = tasu - hiku;
    var kotae = "";

    var min = parseInt(-1000000);
    var max = parseInt(1000000);

    if(kazua == 1){
       console.log(kazub);
    }else{
    for(var i = 0; i < zenbu+1 ; i++){
        var kazu = parseInt(kazub - tasu + i);
        if(kazu >= min  && kazu <= max){
            if(kotae == ""){
                kotae = "1";
               console.log(kazu);
            }else{
            console.log(" " + kazu);
            }
        }
    }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 9264
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
#define AC io()
const int mod = 1000000007;
//endregion

int n, a, b, c, ans;
bool flag;
vii arr[20];

int ndigit(int k) {
    int dig = 0;
    for (int i=0; i<16; i++) if (k & (1<<i)) dig++;
    return dig;
}

pls give {
    AC;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a;
        for (int j=0; j<a; j++) {
            cin >> b >> c;
            arr[i].pp(b-1, c);
        }
    }
    for (int i=0; i<(1<<n); i++) {
        flag = false;
        for (int j=0; j<n; j++) {
            if (!(i & (1<<j))) continue;
            for (auto k : arr[j]) {
                if (((i & (1 << k.first))>0) != k.second) {
                    flag = true;
                    break;
                }
            }
            if (flag) break;
        }
        if (!flag) {
            ans = max(ans, ndigit(i));
        }

    }
    cout << ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

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

		String S = sc.next();
		String T = sc.next();

		if(S.contains(T))
		{
			System.out.println(0);
		}
		else
		{
			char[] sArray = S.toCharArray();
			char[] tArray = T.toCharArray();

			int lengthDiff = S.length()-T.length() + 1;
			//System.out.println(String.format("lengthDiff = {0}", S.length()-T.length()));

			int maxSameCharCount = 0;

			for(int i=0; i<lengthDiff;i++)
			{
				int sameCharCounter=0;
				for(int j=0; j<tArray.length;j++)
				{
					//System.out.println("sArray[i+j]" + sArray[i+j]);
					//System.out.println("tArray[j]" + tArray[j]);

					if(sArray[i+j] == tArray[j]) sameCharCounter++;
				}

				if(maxSameCharCount < sameCharCounter)
				{
					maxSameCharCount = sameCharCounter;
				}
				//System.out.println();
			}

			System.out.println(T.length()-maxSameCharCount);
		}
	}
}


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

struct edge {
    int from, to;
};

using edges = vector<edge>;
using graph = vector<edges>;

void add_edge(graph& g, int from, int to) {
    g[from].push_back((edge){from, to});
}

void dfs(graph& g, int v, int i, vector<int>& id) {
    id[v] = i;
    for(auto e : g[v]) {
        int u = e.to;
        if(id[u] == -1) {
            dfs(g, u, i, id);
        }
    }
}

int main() {
    int N, K, L;
    cin >> N >> K >> L;
    graph r(N), l(N);
    for(int i=0; i<K; ++i) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        add_edge(r, p, q);
        add_edge(r, q, p);
    }
    for(int i=0; i<L; ++i) {
        int r, s;
        cin >> r >> s;
        r--; s--;
        add_edge(l, r, s);
        add_edge(l, s, r);
    }
    vector<int> idr(N, -1), idl(N, -1);
    int cntr=0, cntl=0;
    for(int i=0; i<N; ++i) {
        if(idr[i] == -1) {
            dfs(r, i, cntr++, idr);
        }
        if(idl[i] == -1) {
            dfs(l, i, cntl++, idl);
        }
    }
    map<pair<int, int>, int> m;
    for(int i=0; i<N; ++i) {
        m[make_pair(idr[i], idl[i])]++;
    }
    for(int i=0; i<N; ++i) {
        cout << m[make_pair(idr[i], idl[i])];
        if(i != N-1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}


Measured memory_bytes: 28800
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int N, M, C;
vector<int> B;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> C;
  B.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    vector<int> A(M);
    for (int j = 0; j < M; j++) {
      cin >> A[j];
    }

    int sum = C;
    for (int j = 0; j < M; j++) {
      sum += (A[j] * B[j]);
    }

    if (sum > 0) {
      ans++;
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  string s;cin>>s;
  ll n;cin>>n;
  int size = s.size();
  bool same = true;
  rep(i,size-1)same &= s[i] == s[i+1];
  if(same){
    print(size*n/2);
    return 0;
  }

  ll ans = 0;
  ll tmp = 1;
  rep(i,size-1){
    if(s[i] == s[i+1])tmp++;
    else ans += tmp/2,tmp = 1;
  }
  ans += tmp/2;
  ans *= n;

  if(s[0] == s[size-1]){
    int a,b;a=b=0;
    rep(i,size)if(s[i] == s[0])a++;else break;
    rep(i,size)if(s[size-1-i] == s[0])b++;else break;
    ans -= (a/2+b/2 - (a+b)/2)*(n-1);  
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    long n;
    long k;
    long res;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        k = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        a(n%k);
        System.out.println(res);
    }
    
    private void a(long a) {
        if (Math.abs(a - k) <= a) {
            a = Math.abs(a - k);
            a(a);
        } else {
            res = a;
            return;
        }
    }
}

Measured memory_bytes: 23892
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, m);
	int x = 1, y = n;
	if (n & 1)
	{
	    FOR (i, 1, m) cout << x++ << " " << y-- << endl;
	}
	
	else
	{
	    FOR (i, 1, min(m, (n/2)/2)) cout << x++ << " " << y-- << endl;
	    y--;
	    FOR (i, (n/2)/2 + 1, m) cout << x++ << " " << y-- << endl;
	}
}















Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  int a=N/2,b=(N+1)/2;
  cout<<a*b<<endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
int value[N][3],cur_pos[N];
ll cur_val;
struct Deal{
    int id,a,b;
    int gain()const{
        return value[id][b]-value[id][a];
    }
    bool operator<(const Deal &t)const{
        return gain() < t.gain();
    }
    bool valid()const{
        return cur_pos[id]==a;
    }
    void apply(){
        cur_val += gain();
        cur_pos[id] = b;
    }
};
priority_queue<Deal> deals[6];
void add_deals(int id){
    if(cur_pos[id] == 0){
        deals[0].push({id,0,1});
        deals[3].push({id,0,2});
    }
    if(cur_pos[id] == 1){
        deals[1].push({id,1,2});
        deals[5].push({id,1,0});
    }
    if(cur_pos[id] == 2){
        deals[2].push({id,2,0});
        deals[4].push({id,2,1});
    }
}
void fix_deals(){
    for(int i = 0; i < 6; ++i)
        while(!deals[i].empty() && !deals[i].top().valid())
            deals[i].pop();
}
void apply(vector<Deal> deals){
    for(deal : deals){
        deal.apply();
        add_deals(deal.id);
    }
}
int main(){
    int x,y,z,n;
    cin >> x >> y >> z;
    n = x+y+z;
    for(int i = 0; i < n; ++i){
        scanf("%d %d %d",&value[i][0],&value[i][1],&value[i][2]);
        if(i < x){
            cur_val += value[i][0];
            cur_pos[i] = 0;
        }
        else if(i < x+y){
            cur_val += value[i][1];
            cur_pos[i] = 1;
        }
        else{
            cur_val += value[i][2];
            cur_pos[i] = 2;
        }
        add_deals(i);
    }
    while(true){
        fix_deals();
        if(deals[0].top().gain()+deals[5].top().gain() > 0)
            apply({deals[0].top(),deals[5].top()});
        else if(deals[1].top().gain()+deals[4].top().gain() > 0)
            apply({deals[1].top(),deals[4].top()});
        else if(deals[2].top().gain()+deals[3].top().gain() > 0)
            apply({deals[2].top(),deals[3].top()});
        else if(deals[0].top().gain()+deals[1].top().gain()+deals[2].top().gain() > 0)
            apply({deals[0].top(),deals[1].top(),deals[2].top()});
        else if(deals[3].top().gain()+deals[4].top().gain()+deals[5].top().gain() > 0)
            apply({deals[3].top(),deals[4].top(),deals[5].top()});
        else
            break;
    }
    cout << cur_val << '\n';
}


Measured memory_bytes: 6196
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back

void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n,k,ans;
ll a[110000],b[110000];


int main(){
  cin>>n>>k;
  rep(i,n){
    cin>>a[i]>>b[i];
  }

  for(ll i=1;i<=(1LL<<30);i<<=1){
    if(k&i){
      ll sum=0,t=(k^i)|(i-1);
      rep(j,n){
        if((a[j]&t)==a[j])
          sum+=b[j];
      }
      ans=max(ans,sum);
    }
  }
  
  ll sum=0;
  rep(i,n){
    if((a[i]&k)==a[i])
      sum+=b[i];
  }
  ans=max(ans,sum);

  cout<<ans<<endl;
}


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

char March[5] {'M','A','R','C','H'};

int main() {

    map<char,long long int> m;

    int n;

    cin >> n;

    while(n--){
        string s;
        cin >> s;
        m[s[0]]++;
    }

    long long int ans = 0;

    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += m[March[i]] * m[March[j]] * m[March[k]];
            }
        }
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
n, a, b = list(map(int, input().split()))
res = 0


def sum_digit(num):
    res = 0
    while num > 0:
        res += int(num % 10)
        num = int(num / 10)
    return res


for i in range(1, n + 1):
    tmp = sum_digit(i)
    # print(tmp)
    if tmp >= a and tmp <= b:
        res += i

print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  map<string,int> m;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>s;
    m[s]++;
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d",m["AC"],m["WA"],m["TLE"],m["RE"]);
  return 0;
}

Measured memory_bytes: 3728
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Security.Cryptography;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int n = int.Parse(Console.ReadLine());
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

			Dictionary<long, long> hash = new Dictionary<long, long>();
			foreach (var i in a) {
				foreach (var j in PrimeFactorization(i).Distinct()) {
					//System.Diagnostics.Debug.Write($"{j} ");
					if (hash.ContainsKey(j)) {
						hash[j]++;
					} else {
						hash.Add(j, 1);
					}
				}
				//System.Diagnostics.Debug.WriteLine("");
			}

			string ans = "pairwise coprime";
			foreach (var item in hash) {
				if (item.Value != 1) {
					ans = "setwise coprime";
				}
				if (item.Value == n) {
					ans = "not coprime";
					break;
				}

			}
			Console.WriteLine(ans);
		}

		#region 素因数分解 long[] PrimeFactorization(long a)
		public static long[] PrimeFactorization(long a)
		{
			if (a < 2) { return new long[] { }; }

			List<long> ans = new List<long>();
			while (a % 2 == 0) {
				ans.Add(2);
				a /= 2;
			}
			for (int i = 3; i <= Math.Sqrt(a); i += 2) {
				while (a % i == 0) {
					ans.Add(i);
					a /= i;
				}
			}
			if (a > 1) {
				ans.Add(a);
			}
			return ans.ToArray();
		}
		#endregion
	}
}


Measured memory_bytes: 118164
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>

#define oo 2000000001
#define MAX_N 200000

using namespace std;

int A[MAX_N + 1];

int main()
{
    int N;

    scanf("%d", &N);
    if(N % 1000 == 0)
        printf("0");
    else
        printf("%d", 1000 - N % 1000);

    return 0;
}


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

int main(){
  int n; cin >>n;
  vector<ll> a(n);
  rep(i,n) cin >>a[i];
  sort(a.begin(), a.end());
  if(n%3!=0) {
    if(a[n-1]==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  int m=n/3;
  if(a[0]==a[m-1]&&a[m]==a[2*m-1]&&a[2*m]==a[n-1]){
    int x=a[0], y=a[m], z=a[2*m];
    int xy=x^y;
    if(xy==z) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  return 0;
}

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

int main(void){
    int S, h, m, s;
    cin >> S;
    h=S/3600;
    m=(S-3600*h)/60;
    s=S%60;
    
    cout << h;
    cout << ":";
    cout << m;
    cout << ":";
    cout << s;
    cout << endl;
}


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

int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int P=max(max(A,B),C);
  int Q=A+B+C-P;
  
  for (int i=0;i<K;i++){
    P=P+P;
  }
  
  cout<<P+Q<<endl;
  return 0;
}
    
    

Measured memory_bytes: 256
from functools import reduce
from math import gcd

n = int(input())
A = list(map(int, input().split()))
maxA = 10**6+5

def furui(x):
    memo = [0]*(x+1)
    for i in range(2, x+1):
        if memo[i]: continue
        memo[i] = i
        for j in range(i*i, x+1, i):
            if memo[j]: continue
            memo[j] = i
    return memo

memo = furui(maxA)
tf = [True]*(maxA)
for a in A:
    if a == 1: continue
    pfct = []
    while a > 1:
        pfct.append(memo[a])
        a //= memo[a]

    for b in set(pfct):
        if not tf[b]:
            break
        tf[b] = False
    else:
        continue
    break
else:
    print('pairwise coprime')
    exit()

if reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 196992
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def gcd(a, b):
    # a,bの最大公約数D
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    # a,bの最小公倍数
    return a * b // gcd(a, b)


def main():
    A, B, C, D = map(int, input().split())

    b = B // C + B // D - B // lcm(C, D)
    a = (A - 1) // C + (A - 1) // D - (A - 1) // lcm(C, D)

    print(B - A + 1 - (b - a))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060