akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 2010
#define mod 1000000007
using namespace std;
int n, k, f[N][N], s[N], ans;
int main(){
	scanf("%d%d", &n, &k);
	memset(f, 0, sizeof(f)); f[0][n+1]=1;
	s[n+1]=1; for(int i=n; i; i--)s[i]=(s[i+1]+f[0][i])%mod;
	for(int i=1; i<=k-1; i++){
		for(int j=1; j<=n+1-i; j++)f[i][j]=s[j];
		s[n+1]=f[i][n+1]; for(int j=n; j; j--)s[j]=(s[j+1]+f[i][j])%mod;
	}
	ans=0; for(int i=2; i<=n+1; i++)ans=(ans+f[k-1][i])%mod;
	for(int i=1; i<=n-k-1; i++)ans=ans*2%mod;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 16000
# -*- coding: utf-8 -*-
import sys

def main():
	N, Y = map(int, input().split(" "))
	
	if Y % 1000 > 0:
		print("-1 -1 -1")
		sys.exit()
	
	for i in range(0, N+1):
		for j in range(0, N+1):
			if N < i + j:
				continue
			k = N - i - j
			if i + j + k == N and k >= 0:
				if (i * 10000) + (j * 5000) + (k * 1000) == Y:
					print("{} {} {}".format(i, j, k))
					sys.exit()
					
	print("-1 -1 -1")
	
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <vector>
#include <string>
 
#define ft first
#define sd second
 
using namespace std;
 
typedef pair<int,int> P;
 
map<int, P> mpp;
 
void preorder(int p)
{
  cout << " " << p;
  if(mpp[p].ft != -1) preorder(mpp[p].ft);
  if(mpp[p].sd != -1) preorder(mpp[p].sd);
}
 
void inorder(int p)
{
  if(mpp[p].ft != -1) inorder(mpp[p].ft);
  cout << " " << p;
  if(mpp[p].sd != -1) inorder(mpp[p].sd);
}
 
void postorder(int p)
{
  if(mpp[p].ft != -1) postorder(mpp[p].ft);
  if(mpp[p].sd != -1) postorder(mpp[p].sd);
  cout << " " << p;
}
 
int rootcheck(vector<int> vec)
{
  bool f;
 
  for(int i = 0; i < vec.size(); ++i){
    f = false;
    for(map<int, P>::iterator it = mpp.begin(); it != mpp.end() && !f; ++it)
      f = (it->sd.ft == vec[i] || it->sd.sd == vec[i]);
    if(!f) return vec[i];
  }
 
  return 0;
}
 
int main()
{
  int n, s, t, u, m;
  vector<int> vec;
 
  while(cin>>n && n){
    m = -1;
    while(n--){
      cin >> s >> t >> u;
      mpp[s] = P(t, u);
      vec.push_back(s);
    }
    m = rootcheck(vec);
 
    cout << "Preorder" << endl;
    preorder(m);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(m);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(m);
    cout << endl;
 
    mpp.clear();
  }
 
  return 0;
}


Measured memory_bytes: 3152
n=int(input())
A=list(map(int,input().split()))
s=0
ans=0
mod=10**9+7

for i in range(n):
    s+=A[i]

for i in range(0,n-1):
    s-=A[i]
    s%=mod
    ans+=(A[i]*s)
    ans%=mod
print(ans%(10**9+7))

Measured memory_bytes: 31560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> cnt(n);
    for (int x : a) cnt[x]++;

    if (n % 2 == 1 && cnt[0] != 1) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = n % 2 + 1; i < n; i += 2) {
        if (cnt[i] != 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ipow(2, n / 2) << endl;
    return 0;
}

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

const int N = 1e5;

int a[N + 1];
int n, p, q;

bool pred(int nq) {
  long long pleft = nq;
  for (int i = 0; i < n; i++) {
    long long qdh = a[i] - 1LL * nq * q;
    if (qdh >= 0) {
      pleft -= (qdh + (p - q - 1)) / (p - q);
    }
  }
  return pleft >= 0;
}

int main() {
  cin >> n >> p >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  int lo = 0, hi = 1e9;
  
  while (lo < hi) {
    int m = lo + (hi - lo) / 2;
    if (pred(m)) {
        hi = m;
    } else {
        lo = m + 1;
    }
  }
  
  cout << lo << endl;
  
  return 0;
}


Measured memory_bytes: 3996
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
MOD = 10 ** 9 + 7
digit = 0

while A.any():
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD))
    ans %= MOD
    A >>= 1
    digit += 1

print(ans)



Measured memory_bytes: 48820
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;
typedef long long ll;

using namespace std;

void solve() {
    int N  = 3;
    vector<int> vec(N);
    REP(i, N) cin >> vec[i];

    sort(vec.begin(), vec.end());

    int ans = 0;
    int diff;
    if (vec[1] != vec[2]) {
        diff = vec[2] - vec[1];
        if (diff % 2 == 0) {
            ans += diff / 2;
        } else {
            ans += (diff - 1) / 2;
            ans += 1;
            vec[0] += 1;
        }
    }
    vec[1] = vec[2];

    diff = vec[1] - vec[0];
    if (diff % 2 == 0) {
        ans += diff / 2;
    } else {
        ans += (diff + 1) / 2;
        ans += 1;
    }
    print(ans);
    
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] H = new int[N];
		for(int i=0; i<N; i++)
			H[i] = sc.nextInt();

		int ans = 0;
		int cur = 0;
		for(int i=N-1; i>0; i--) {
			if(H[i-1]>=H[i]) {
				cur++;
				ans = Math.max(ans, cur);
			} else {
				cur = 0;
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub&~y)/x)>>1) | y;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, k;
  cin >> n >> k;
  if(k == 0) return 0;
  for(int bit = (1<<k)-1; bit < (1<<n); bit = next_combination(bit)) {
    cout << bit << ":";
    rep(i, n) if((bit>>i)&1) cout << " " << i;
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define vs vector<string>
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define fs first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
const ll INF = 1e18L + 5;
int main() {
    ll N,W;
    cin>>N>>W;
    vi wt(N);
    vi val(N);
    ll sum_val = 0;
    for(ll i=0;i<N;i++){
        cin>>wt[i]>>val[i];
        sum_val += val[i];
    }

    vi dp(sum_val+1,INF);
    dp[0] = 0;
    for(ll i=0;i<N;i++){
        for(ll j=(sum_val-val[i]);j>=0;j--){
            dp[j+val[i]] = min(dp[j+val[i]],dp[j]+wt[i]);
        }
    }

    ll answer = 0;

    for(ll i=0;i<=sum_val;i++){
        if(dp[i]<=W){
            answer = max(answer,i);
        }
    }
    cout<<answer<<endl;
}




Measured memory_bytes: 1024
from collections import defaultdict
from math import factorial
if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    words = defaultdict(lambda: 0)
    for i in range(n):
        words[''.join(sorted(input()))] += 1
    sum = 0
    for word in words:
        sum += int(factorial(words[word]) / (factorial(2) * factorial(abs(words[word] - 2))))
    print(sum)


Measured memory_bytes: 18232
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>

using namespace std;


/* define */
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define REP(i, n) for ( int i = 0; i < (n) ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}

/* main */

int main() {
	int n, i, ans[100000] = {};
	cin >> n;
	if (n == 0) cout << 0 << endl;
	for(i = 0; n; i++) {
		ans[i] = abs(n % 2);
		n = (ans[i] - n) / 2;
	}
	for(int j = i - 1; j >= 0; j--) cout << ans[j];
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    string SS[4]={"Sunny", "Cloudy", "Rainy", "Sunny"};
    for(int i=0; i<3; i++){
        if(s==SS[i]) cout << SS[i+1] << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <limits>
#include <string>

using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.length();
    int T[N+1] = {};
    long long m[2019] = {};
    m[0] = 1;
    T[N] = 0;
    int ten = 1;
    for(int i=N-1; i>=0; --i){
        int ai = (int) (S[i] - '0');
        //cout << ai << endl;
        //cout << i << " " << S[i] << endl;
        if(ai>9 || ai<0){
            cout << "ai range error" << endl;
            return -1;
        }
        T[i] = T[i+1] + ten * ai;
        T[i] %= 2019;
        ten*=10;
        ten%=2019;
        //cout << T[i+1] << " " << ai << " " << T[i] << endl;
        m[T[i]]++;
    }
    int ans=0;
    for(int k=0; k<2019; ++k){
        ans += m[k] * (m[k]-1) / 2;
    }
    cout << ans << endl;
    return 0;
}

//int main(){
//    string S;
//    cin >> S;
//    //cout << S << endl;
//    int keta = S.length();
//    //cout << keta <<endl;
//    int i = 0;
//    int j = 0;
//    int count = 0;
//    for(j=keta-1; j>=0; --j){
//        i = j-3;
//        while(i>=0){
//            long long tmp;
//            string tmpp;
//            //cout << "i" << i <<"j" << j << endl;
//            int len = j - i + 1;
//            tmpp = S.substr(i, len);
//            //cout << tmpp << "tmpp" << endl;
//            tmp = stoll(tmpp);
//            //cout << tmp << "tmp" << endl;
//            if(tmp%2019==0){
//                count++;
//                i = i-4;
//            }
//            else{
//                i--;
//            }
//
//        }
//    }
//    cout << count << endl;
//
//    return 0;
//}

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

long long N;

void dfs(long long cur,int use,long long &cnt){
    if(cur>N) return;
    if(use == 0b111) cnt++;

    dfs(cur*10+7,use|0b001,cnt);
    dfs(cur*10+5,use|0b010,cnt);
    dfs(cur*10+3,use|0b100,cnt);
}

int main(){
    cin >> N;
    long long ans=0;
    dfs(0,0,ans);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);
using namespace std;
//typedef long long ll;
int main()
{
   // OJ;
long double a,b;
cin>>a>>b;
ll int ans=a*b;
  cout<<ans;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a=0,b;cin>>n;b=n;
    while(1){
        if(n){
            a+=n%10;
            n/=10;
        }
        else break;
    }
    if(b%a) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

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

using namespace std;

using ll = long long;

int main(void){
    ll n;
    ll ans = 0;

    cin >> n;

    vector<ll> a(n,0),l(n,0);
    
    for(int i=0; i<n; i++){
        cin >> a[i];

        l[i] = a[i] + (i>=1?l[i-1]:0);
    }
    double center = l[n-1]/2.0;
    ll center_2 = l[n-1];
    auto right = upper_bound(l.begin(), l.end(), center);
    
    auto target = right;

    if(right != l.begin()){
        if(*right - center > center - *(right-1)){
            target = right-1;
        }
    }

    ans = abs(*target*2 - center_2);
  
    cout << ans << endl;
}

Measured memory_bytes: 3968
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	ll a,b,c,d;
	ll o=0,p=0;

	cin>>a>>b>>c>>d;

	o=a*b;
	p=c*d;

	if(o<p){
		cout<<p<<endl;
	}else{
		cout<<o<<endl;
	}

	return 0;


}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(c)  c.begin(), c.end()
#define vb vector<bool>
#define vll vector<ll>
#define vi vector<int>
#define vp vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define lb "\n"
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define INF 1000000007
#define MAX LLONG_MAX
#define PI 3.14159265358
ll max(ll x,ll y){if(x>y)return x;else return y;}
ll min(ll x,ll y){if(x>y)return y;else return x;}
ll dp[3001][3001];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
      #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
   ll i,j,k,n,m;
   string s,t;
   vector<char> ans;
   cin>>s>>t;
   n=s.size(),m=t.size();
   rep(i,1,n+1)
   rep(j,1,m+1)
   {
       if(s[i-1]==t[j-1])
        dp[i][j]=dp[i-1][j-1]+1;
       else
        dp[i][j]=max(dp[i-1][j-1],max(dp[i][j-1],dp[i-1][j]));
   }
   //cout<<dp[n][m];
   i=n,j=m;
   while((i>0)&&(j>0))
   {
       if(dp[i][j]==dp[i-1][j-1])
           i--,j--;
       else if(dp[i][j]==dp[i][j-1])
           j--;
       else if(dp[i][j]==dp[i-1][j])
           i--;
       else
       {
           ans.pb(s[i-1]);
           i--,j--;
       }
   }
   if(!ans.empty())
   {
   i=ans.size()-1;
   while(i>=0)
   {
    cout<<ans[i];
    i--;
   }
   }
   else
    cout<<" ";
}


Measured memory_bytes: 70656
#include<iostream>
using namespace std;
#define M 101
#define I 100000000
int main(){
    int n,p[M],m[M][M],i,j,k,t;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>p[i-1]>>p[i];
    }
    for(i=1;i<=n;i++)m[i][i]=0;
    for(i=2;i<=n;i++){
        for(j=1;j<=n-i+1;j++){
            t=i+j-1;
            m[j][t]=I;
            for(k=j;k<=t-1;k++){
                m[j][t]=min(m[j][t],m[j][k]+m[k+1][t]+p[j-1]*p[k]*p[t]);
            }
        }
    }
    cout<<m[1][n]<<endl;
    return 0;
}


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

#define int long long
#define reps(i,s,n) for(ll (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,n+1)
#define repst(i,s,n) reps(i,s,n+1)
#define reprt(i,n,t) for(ll (i)=(n);(i)>=t;--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<n;++i){cout<<x[i]<<(i==n-1?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 順送りボタンのみで明るさをaからbにすると、a<=bならb-a回、a>bならm-a+b回ボタンを押す必要がある
// まとめると(m+b-a)%m回と書ける
// またaとbの間(bは含む)にxがあるときのみお気に入りボタンを押した方が得で、そのときはボタンを1+(m+b-x)%m回押すことになる
// お気に入りの明るさをxからx+1にするとどうなるか？
// 1) b==xのとき お気に入りボタンを1回押すだけでよかったのが順送りボタンを(m+x-a)%m回押さないといけなくなる
// 2) aとbの間(両端を含まない)にxがあるとき 順送りボタンを押す回数が1回減る
// 3) その他 変わらない
// まとめると、a[i+1]がxであるi全てについて(m+a[i+1]-a[i])%m-1回増え、a[i]とa[i+1]の間にxがあるようなiの数回減る
// b[i]:前者の和 c[i]:後者の累積和 を事前に求めて、x==1のときだけ素直に計算すれば、あとは⇡のようにx=2,3,...の場合もO(1)で計算できる

int n, m, a[114514], b[114514], c[114514], t, r;

signed main() {
	cin >> n >> m;
	rep(i,n) cin >> a[i];
	rep(i,n-1) {
		b[a[i+1]] += (m+a[i+1]-a[i])%m - 1;
		if (a[i]<a[i+1]) c[a[i]+1]++, c[a[i+1]]--;
		else c[a[i]+1]++, c[0]++, c[a[i+1]]--;
	}
	rep(i,m) c[i+1] += c[i];
	// x==1の場合を求める
	rep(i,n-1) t += min((m+a[i+1]-a[i])%m, 1+(m+a[i+1]-1)%m);
	r = t;
	// xを1増やしつつ答えを更新してく
	repst(x,2,m) {
		t = t + b[x-1] - c[x-1];
		chmin(r, t);
	}
	cout << r << ln;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(bf.readLine());
		while(n-->0){
			String n1=bf.readLine();
			String n2=bf.readLine();
			int[][] a = new int[3][81];
			if(n1.length()>80||n2.length()>80){
				System.out.println("overflow");
				continue;
			}
			for(int i=0;i<81;i++)a[0][i]=a[1][i]=a[2][i]=0;
			for(int i=81-n1.length(),j=0;i<81;i++,j++)a[0][i]=Integer.parseInt(n1.substring(j,j+1));
			for(int i=81-n2.length(),j=0;i<81;i++,j++)a[1][i]=Integer.parseInt(n2.substring(j,j+1));
			for(int i=80;i>0;i--){
				a[2][i]+=a[0][i]+a[1][i];
				if(a[2][i]>=10){a[2][i]-=10;a[2][i-1]++;}
			}
			if(a[2][0]>0){
				System.out.println("overflow");
			}else{
				int i=0;
				while(i<80&&a[2][++i]==0);
				while(i<81)System.out.print(a[2][i++]);
				System.out.print("\n");
			}
		}
	}
}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec g(nmax);





void solve()
{
    
    int n,a,b;
    cin>>n>>a>>b;
    int aa=0;
    int bb=0;
    aa=a*(n-1)+b;
    bb=a+b*(n-1);
    cout<<max(0LL,bb-aa+1)<<endl;

}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve();
}

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

A,B,C = [],[],[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append((i,a+b))
    
C = sorted(C,key=lambda x:x[1],reverse=True)

ans = 0
for i in range(N):
    if i%2==0:
        ans += A[C[i][0]]
    else:
        ans -= B[C[i][0]]
        
print(ans)

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll INF=1LL<<60;
const int MOD=998244353;
const int N=2e5+5;



int main(){
    int N, K; cin >> N >> K;
    ll R, S, P; cin >> R >> S >> P;
    vi score(3);
    score[0]=P, score[1]=R, score[2]=S;
    string T; cin >> T;
    vi cnt(3, 0);
    vector<vector<vector<ll>>> dp(K, vector<vector<ll>>((N-1)/K+1, vector<ll>(4, 0)));
    vector<ll> end(K);
    for(int i=0; i<N; i++){
        int val;
        switch (T[i]){
            case 'r' : 
                val=0;
                break;
            case 's' :
                val=1;
                break;
            case 'p' :
                val=2;
                break;
        }
        if(i < K){
            dp[i%K][i/K][val]=score[val];
        }
        else{
            if(dp[i%K][i/K-1][val] != 0) dp[i%K][i/K][3]=dp[i%K][i/K-1][val];
            else{
                for(int j=0; j<4; j++){
                    dp[i%K][i/K][val]=max(dp[i%K][i/K][val], dp[i%K][i/K-1][j]+score[val]);
                }
            } 
        }
        end[i%K]=max(dp[i%K][i/K][val], dp[i%K][i/K][3]);
    }
    ll res=0;
    for(int i=0; i<K; i++){
        res+=end[i];
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(a) fixed << setprecision(a)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   long double n,cnt=3.0;
   cin>>n;

   cout<<Fixed(10)<<(n/cnt)*(n/cnt)*(n/cnt)<<'\n';
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())

test = [[a,b,c]]
count = 0
while a%2 == b%2 == c%2 == 0:
    at = a
    bt = b
    ct = c
    a = bt//2 + ct//2
    b = ct//2 + at//2
    c = at//2 + bt//2
    count+=1
    if [a,b,c] in test:
        count = -1
        print(count)
        break
    else:
        test.append([a,b,c])
if count != -1:
    print(count)


Measured memory_bytes: 3064
implicit none
integer(8) :: i,j,k,n

read(5,*) n

!DIR$ SIMD
do i = int(3*n/4),1,-1
  do j = int(3*n/4), 3500
      do k = i, j
          if(4*i*j*k==n*(i*j+j*k+k*i)) then
          goto 100
          endif
enddo
enddo
enddo

100 write(6,"(i0,1x,i0,1x,i0)") i,j,k
end


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define INF 1e+18L
#define pb push_back
#define ll long long
#define vi vector<int>

int main()
{
    FASTIO
    int n;
    cin >> n;
    vector<char> s(n);
    ll r = 0, g = 0, b = 0;
    rep(i,0,n)
    {
        cin >> s[i];
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;
    }
    ll ans = r*g*b;
    rep(i,0,n-2)
    {
        rep(k,i,n)
        {
            if(s[i] != s[k])
            {
                if((i+k)%2 == 0)
                {
                    if(s[i] != s[(i+k)/2] && s[(i+k)/2] != s[k]) ans--;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;   
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
static class Program
{
	static int[] ReadInts(this TextReader reader) => reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	static IEnumerable<int[]> ReadInts(this TextReader reader, int count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadInts();
	}

	static IEnumerable<long[]> ReadLongs(this TextReader reader, long count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
	}
	
	public static void Main(string[] args)
	{
		var input = Console.In.ReadInts();
		Console.WriteLine("{0} {1} {2}", input[2], input[0], input[1]);
	}
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a-b <= c)
			System.out.println(c-(a-b));
		else
			System.out.println(0);
		
        sc.close();
	}
}

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

int main() {
  int n, m, x;
  scanf("%d %d %d", &n, &m, &x);
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    for (int j = 0; j < m; j++)
      scanf("%d", &a[i][j]);
  }

  int ans = -1;
  for (int i = 0; i < (1 << n); i++) {
    int t = i;
    vector<bool> u(n);
    for (int j = 0; j < n; j++) {
      u[j] = t & 1;
      t >>= 1;
    }

    int s = 0;
    vector<int> levels(m);
    for (int j = 0; j < n; j++)
      if (u[j]) {
        s += c[j];
        for (int k = 0; k < m; k++)
          levels[k] += a[j][k];
      }

    bool succ = true;
    for (int j = 0; j < m; j++)
      succ = succ && (levels[j] >= x);
    
    if (succ && (ans == -1 || s < ans))
      ans = s;
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 3792
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
int main()
{
	ll n; cin>>n;
	map<string,ll>m;
	map<string,ll>::iterator y;
	ff(0,n)
	{
		string s;
		cin>>s;
		m[s]++;
	}
/*	for(y=m.begin();y!=m.end();y++)
	{
		cout<<y->first<<" "<<y->second<<endl;
	}*/
/*	for(auto &x:m)
	{
		cout<<x.first<<" "<<x.second<<endl;
	}*/
	ll max=0;
	for(auto &x:m)
	{
		ll v=x.second;
		if(v>max) max=v;
	}
	for(auto &x:m)
	{
		if(x.second==max)cout<<x.first<<endl;
	}
	
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }


void func(long long A, long double B){

}

int main(){

    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    long double C = static_cast<long double>(A) * B;
    ll D = floorl(C);
    cout << D << endl;
    return 0;
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////



int main() {
  //  ios::sync_with_stdio(false);cin.tie(0);
    
    ll n;cin>>n;
    ll a[n],b[n];rep(i,0,n-1)cin>>a[i];
    rep(i,0,n-1)cin>>b[i];
    ll ans=0;
    rep(k,1,29){
        ll p=(ll)1<<k;
        ll c[n],d[n];
        rep(i,0,n-1){
            d[i]=b[i]%p;
            c[i]=a[i]%p;
        }
        sort(d,d+n);
        ll sum=0;
        rep(i,0,n-1){
            sum+=lower_bound(d,d+n,p-c[i])-lower_bound(d,d+n,p/2-c[i]);
            sum+=lower_bound(d,d+n,2*p-c[i])-lower_bound(d,d+n,3*p/2-c[i]);
        }
        if(sum%2)ans+=1<<(k-1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  }
  
}


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

using namespace std;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

int main(){

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

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

    int k, s;

    cin >> k >> s;

    int t = 0;

    for(int i = 0; i <= k; ++i){
        for(int j = 0; j <= k; ++j)
            if(s - i - j <= k && s >= i + j)
                ++t;
    }

    cout << t;

    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++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
 
int main() {
int n,k;
cin >> n >> k;
vector<int> a(n);
rep(i,n) cin >> a.at(i);
vector<int> b,c;
rep(i,n){
  if(i<n-k)b.push_back(a.at(i));
}
  rep(i,n){
  if(i<n-k)c.push_back(a.at(i+k));
}


rep(i,n-k){
  if(b.at(i)<c.at(i))cout << "Yes" << endl;
  else cout <<"No" << endl;
}



}

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

int main(){
    long a,b,k;
    cin >> a >> b >> k;
    for(int i=1; i<=k; i++){
        if(i%2!=0){
            if(a%2!=0) a--;
            a /= 2;
            b += a;
        } else {
            if(b%2!=0) b--;
            b /=2;
            a += b;
        }
    }
    cout << a << " " << b <<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int N = sc.nextInt();
     int K = sc.nextInt();
     double p = 0, phold = 1.0;
     int point;
     for (int i =1;i<=N;i++){
       point = i;
       phold = 1.0/N;
       while(point<K){
         point *= 2;
         phold = phold/2.0;
       }
       p += phold;
     }
     System.out.println(p);
   }
}


Measured memory_bytes: 21972
import math


def solve(N, TXYs):
    now = 0
    p = (0, 0)
    for t, x, y in TXYs:
        td = t - now
        dd = abs(p[0] - x) + abs(p[1] - y)
        if td % 2 != dd % 2 or td < dd:
            return "No"
        now = t
        p = (x, y)
    return "Yes"

if __name__ == "__main__":
    N = int(input())
    TXYs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, TXYs))


Measured memory_bytes: 17308
from collections import defaultdict

n,m = map(int,input().split())
A = list(map(int,input().split()))

dic = defaultdict(int)
dic[0] += 1
cum = 0

for i in range(n):  
  cum += A[i]
  dic[cum%m] += 1
  
ans = 0  
for v in dic.values():
  ans += v*(v-1)//2
  
print(ans)  

Measured memory_bytes: 14636
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <limits>
using namespace std;

double inf = numeric_limits<double>::infinity();

int main() {
    long n, m;
    cin >> n >> m;
    
    if (2 * n - m >= 0) {
        cout << m / 2 << endl;
    } else {
        cout << (m - 2 * n) / 4 + n << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define vv vector<lli>
#define vp vector<pair<lli,lli>>
#define vpp vector<pair<lli,pair<lli,lli>>>
#define lims(w) (w).begin(),(w).end()
#define rlims(w) (w).rbegin(),(w).rend()
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(lli i=a;i<b;i++)
#define ff first
#define ss second
#define sz(a) (lli)(a.size())
lli inf = (1e18 + 2);

int main()
{
	string s;
	cin>>s;

	if(s == "SSS")
		cout<<"0"<<endl;
	else if(s == "RRR")
		cout<<"3"<<endl;
	else if(s == "RSS" || s == "SRS" || s == "SSR")
		cout<<"1"<<endl;
	else if(s == "RRS" || s == "SRR")
		cout<<"2"<<endl;
	else
		cout<<"1"<<endl;

	return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=924844033;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head
 
const int N=2010;
int comb[N][N],p[N],q[N],c[N],u,n,k;
void mul(int x) {
	int v=x/2+1;
	rep(i,0,v) q[i]=comb[x-i][i];
	rep(i,0,u+v) c[i]=0;
	rep(i,0,u) rep(j,0,v) c[i+j]=(c[i+j]+(ll)p[i]*q[j])%mod;
	rep(i,0,u+v) p[i]=c[i]; u=u+v-1;
}
int main() {
	p[0]=1; u=1;
	scanf("%d%d",&n,&k);
	comb[0][0]=1;
	rep(i,1,n+1) {
		comb[i][0]=comb[i][i]=1;
		rep(j,1,i) comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
	}
	rep(i,0,k) {
		int c=i,cnt=0;
		while (c<n) c+=k,cnt++;
		mul(cnt);
		mul(cnt);
	}
	ll sg=1,ret=0;
	if (n%2==1) sg=-1;
	rep(i,0,n+1) {
		ret=(ret+sg*p[n-i])%mod;
		sg=-sg*(i+1)%mod;
	}
	if (ret<0) ret+=mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
int ans=2019;
int main()
{
	int l,r;
	cin>>l>>r;
	r-=max(0,(r-l-2019)/2019)*2019;
	for (int i=l;i<=r;i++) 
	    for (int j=i+1;j<=r;j++)
	    {
	    	ans=min(ans,(i%2019)*(j%2019)%2019);
	    	if (ans==0) 
	    	{
	    		cout<<ans<<endl;
	    		exit(0);
	    	}
	    }
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    // fastIO();
    
    int a, b, c, d, n, ans = 0;
    cin >> a >> b >> c >> d >> n;
    c = min({4*a, 2*b, c});
    
    if (n & 1) ans += c, --n;
    ans += n/2 * min({2*c, d});
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>


class data
{
private:
    int number;
    int data;

public:

    void set_number(int num) 
    {
        this->number = num;
    }

    void set_data(int dat) 
    {
        if (dat == 0) {
            this->number = 0;
        } else {
            this->data = dat;
        }
    }

    int get_number(void) 
    {
        return number;
    }

    int get_data(void)
    {
        return data;
    }

};

int main(void)
{
    data dataset;
    int num;

    for (num = 1; num > 0; ++num) {   
        int data;
        dataset.set_number(num);
        std::cin >> data;        
        dataset.set_data(data);
        if (dataset.get_number() == 0) {
            break;
        } else {
            std::cout << "Case " << dataset.get_number() << ": " << dataset.get_data() <<std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
int main()
{
	int x;
	std::cin >> x;
	int rank = 8;
	for (int base = 400; base < 2000; base += 200)
	{
		if (base <= x && x < base + 200)
		{
			break;
		}
		rank--;
	}
	std::cout << rank << std::endl;
}

Measured memory_bytes: 3628
A, B, Q = gets.split.map(&:to_i)
S = A.times.map{gets.to_i}
T = B.times.map{gets.to_i}
X = Q.times.map{gets.to_i}

INF = Float::INFINITY
S.unshift -INF 
S.push INF  
T.unshift -INF 
T.push INF

X.each do |x|
  js = S.bsearch_index{|s| s > x}
  ls = x - S[js - 1]
  rs = S[js] - x
  jt = T.bsearch_index{|t| t > x}
  lt = x - T[jt - 1]
  rt = T[jt] - x
  puts [ls > lt ? ls : lt, 
        rs > rt ? rs : rt,
        rs * 2 + lt, 
        rt * 2 + ls, 
        ls * 2 + rt, 
        lt * 2 + rs].min
end

Measured memory_bytes: 6140
#include <iostream>
using namespace std;
typedef long long ll;
ll s[100001],t[100001];
int main(void){
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        s[i+1]=s[i]+a;
        t[i+1]=max(0LL,a);
    }
    for(int i=0;i<n;i++){
        t[i+1]+=t[i];
    }
    ll ans=-(1LL<<60);
    for(int i=0;i<n-k+1;i++){
        ans=max(ans,max(0LL,s[i+k]-s[i])+t[i]+t[n]-t[i+k]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

void solve()
{
    ll N,X;
    cin >> N >> X;
    vll L(N);
    vll D(N+1);
    for1(i,N) {
        cin >> L[i];
    }
    D[0] = 0;
    for1(i,N) {
        D[i+1] = D[i] + L[i];
    }
    ll ans = 0;
    for1(i,N+1) {
        if (D[i] <= X) {
            ans++;
        }
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;



bool gooddis(long long int n) {

	long long int a = 0;

	while (n >= a * a) {
		if (n == a * a)return true;
		a++;
	}

	return false;
}



vector<pair<long long int, long long int>> getPrimeElements(long long int num) {

	long long int firstnum = num;

	vector<pair<long long int, long long int>> result;
	pair<long long int, long long int> wk;

	if (num % 2 == 0) {
		wk.first = 2;
		wk.second = 0;
		while (num % 2 == 0) {
			wk.second++;
			num /= 2;
		}

		result.push_back(wk);
	}

	long long int waru = 3;

	while (true) {

		if (num % waru == 0) {
			wk.first = waru;
			wk.second = 0;
			while (num % waru == 0) {
				wk.second++;
				num /= waru;
			}

			result.push_back(wk);
		}
		waru += 2;

		if (waru * waru > num) break;

	}

	if (num != 1) {
		wk.first = num;
		wk.second = 1;
		result.push_back(wk);

	}

	return result;
}


int main()
{
    

	int bingo[3][3];

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

	int n;
	cin >> n;

	vector<int> hole(n);
	for (auto& i : hole)cin >> i;

	bool bingohole[3][3] = { false };

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < hole.size(); k++) {
				if (hole[k] == bingo[i][j]) {
					bingohole[i][j] = true;
					break;
				}
			}
		}
	}

	if (bingohole[0][0] && bingohole[0][1] && bingohole[0][2] ||
		bingohole[1][0] && bingohole[1][1] && bingohole[1][2] ||
		bingohole[2][0] && bingohole[2][1] && bingohole[2][2] ||
		bingohole[0][0] && bingohole[1][0] && bingohole[2][0] ||
		bingohole[0][1] && bingohole[1][1] && bingohole[2][1] ||
		bingohole[0][2] && bingohole[1][2] && bingohole[2][2] ||
		bingohole[0][0] && bingohole[1][1] && bingohole[2][2] ||
		bingohole[2][0] && bingohole[1][1] && bingohole[0][2]) 
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}




Measured memory_bytes: 256
from collections import deque
h,w,k=map(int,input().split())
sy,sx,gy,gx=map(int,input().split())
G=[["@"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["@"]+list(input())+["@"]
V=[[10**10]*(w+2) for i in range(h+2)]
V[sy][sx]=0
D=[[[0,0,0,0] for j in range(w+2)] for i in range(h+2)]
D[sy][sx]=[1,1,1,1]
X=deque([])
Y=deque([])
i=1
while G[sy-i][sx]==".":
  Y.append(sy-i)
  X.append(sx)
  V[sy-i][sx]=1
  D[sy-i][sx][0]=1
  D[sy-i][sx][1]=1
  if i==k:
    D[sy-i][sx][0]=0
    break
  i=i+1
i=1
while G[sy+i][sx]==".":
  Y.append(sy+i)
  X.append(sx)
  V[sy+i][sx]=1
  D[sy+i][sx][0]=1
  D[sy+i][sx][1]=1
  if i==k:
    D[sy+i][sx][1]=0
    break
  i=i+1

i=1
while G[sy][sx-i]==".":
  Y.append(sy)
  X.append(sx-i)
  V[sy][sx-i]=1
  D[sy][sx-i][2]=1
  D[sy][sx-i][3]=1
  if i==k:
    D[sy][sx-i][2]=0
    break
  i=i+1
i=1
while G[sy][sx+i]==".":
  Y.append(sy)
  X.append(sx+i)
  V[sy][sx+i]=1
  D[sy][sx+i][2]=1
  D[sy][sx+i][3]=1
  if i==k:
    D[sy][sx+i][3]=0
    break
  i=i+1

def yn(yy,xx):
  D[yy][xx][0]=1
  i=1
  while G[yy-i][xx]==".":
    if V[yy][xx]+1>V[yy-i][xx]:
      break
    D[yy-i][xx][0]=1
    D[yy-i][xx][1]=1
    V[yy-i][xx]=V[yy][xx]+1
    if i==k:
      D[yy-i][xx][0]=0
      Y.append(yy-i)
      X.append(xx)
      break
#    if D[yy-i][xx]!=[1,1,1,1]:
    Y.append(yy-i)
    X.append(xx)
    i=i+1


def yp(yy,xx):
  D[yy][xx][1]=1
  i=1
  while G[yy+i][xx]==".":
    if V[yy][xx]+1>V[yy+i][xx]:
      break
    D[yy+i][xx][0]=1
    D[yy+i][xx][1]=1
    V[yy+i][xx]=min(V[yy+i][xx],V[yy][xx]+1)
    if i==k:
      D[yy+i][xx][1]=0
      Y.append(yy+i)
      X.append(xx)
      break
#    if D[yy+i][xx]!=[1,1,1,1]:
    Y.append(yy+i)
    X.append(xx)
    i=i+1


def xn(yy,xx):
  D[yy][xx][2]=1
  i=1
  while G[yy][xx-i]==".":
    if V[yy][xx]+1>V[yy][xx-i]:
      break
    D[yy][xx-i][2]=1
    D[yy][xx-i][3]=1
    V[yy][xx-i]=min(V[yy][xx-i],V[yy][xx]+1)
    if i==k:
      D[yy][xx-i][2]=0
      Y.append(yy)
      X.append(xx-i)
      break
#    if D[yy][xx-i]!=[1,1,1,1]:
    Y.append(yy)
    X.append(xx-i)
    i=i+1


def xp(yy,xx):
  D[yy][xx][3]=1
  i=1
  while G[yy][xx+i]==".":
    if V[yy][xx]+1>V[yy][xx+i]:
      break
    D[yy][xx+i][2]=1
    D[yy][xx+i][3]=1
    V[yy][xx+i]=min(V[yy][xx+i],V[yy][xx]+1)
    if i==k:
      D[yy][xx+i][3]=0
      Y.append(yy)
      X.append(xx+i)
      break
#    if D[yy][xx+i]!=[1,1,1,1]:
    Y.append(yy)
    X.append(xx+i)
    i=i+1

while len(X)>0:
  x=X[0]
  y=Y[0]
  X.popleft()
  Y.popleft()
  if D[y][x][0]==0:
    yn(y,x)
  if D[y][x][1]==0:
    yp(y,x)
  if D[y][x][2]==0:
    xn(y,x)
  if D[y][x][3]==0:
    xp(y,x)

if V[gy][gx]==10**10:
  print(-1)
else:
  print(V[gy][gx])

Measured memory_bytes: 510356
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N, M;
    cin >> N >> M;
    vector<int> broken(N + 1);
    rep(i, M) {
        int a;
        cin >> a;
        broken[a] = 1;
    }

    vector<int> dp(N + 2);
    const int mod = 1000000007;
    dp[N] = 1;
    for(int i = N - 1; i >= 0; i--) {
        if(broken[i]) {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
        // cout << dp[i] << endl;
    }
    cout << dp[0] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define INF 1000000000000000000LL

int N, M;
ll G[1005][1005];
ll G2[1005][1005];

ll bellmanFord(int s){
  vector<ll> dist, prev;
  rep(i,N){ dist.push_back(INF); prev.push_back(-2); }
  dist[s] = 0;
  bool neg_cycle = false;
  rep(step,N){
    rep(i,N) rep(j,N) if(G[i][j]!=INF && i!=j){
      if(dist[j]>dist[i]+G[i][j]){
	dist[j] = dist[i]+G[i][j];
	prev[j] = i;
	if(step==N-1){
	  dist[j] = -INF;
	  neg_cycle = true;
	}
      }
    }
  }
  if(neg_cycle) return INF;
  return -dist[N-1];
}
vector<ll> bellmanFord2(int s){
  vector<ll> dist, prev;
  rep(i,N){ dist.push_back(INF); prev.push_back(-2); }
  dist[s] = 0;
  bool neg_cycle = false;
  rep(step,N){
    rep(i,N) rep(j,N) if(G2[i][j]!=INF && i!=j){
      if(dist[j]>dist[i]+G2[i][j]){
	dist[j] = dist[i]+G2[i][j];
	prev[j] = i;
	if(step==N-1){
	  dist[j] = -INF;
	  neg_cycle = true;
	}
      }
    }
  }
  return dist;
}

int main(){
  cin >> N >> M;
  rep(i,N){
    rep(j,N){
      G[i][j] = INF;
      G2[i][j] = INF;
    }
  }

  rep(i,M){
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a][b] = -c;
    G2[b][a] = 1;
  }

  vector<ll> cango = bellmanFord2(N-1);
  rep(i,cango.size()-1){
    if(cango[i] == INF){
      rep(j,N){
        G[i][j] = INF;
        G[j][i] = INF;
      }
    }
  }
  
  ll res = bellmanFord(0);
  if(res == INF){
    cout << "inf" << endl;
  }else{
    cout << res << endl;
  }
  
  return 0;
}


Measured memory_bytes: 16000