akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define maxn 200005 
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
long long n,w1[maxn],dis1[maxn],dis2[maxn],c,w2[maxn],w[maxn],sm1[maxn],sm2[maxn];
long long pos1,pos2,mx1=-inf,mx2=-inf,ans;
int main()
{
	scanf("%lld%lld",&n,&c);
	for(long long i=1;i<=n;++i)
	{
		scanf("%lld%lld",&dis1[i],&w[i]);
		dis2[i]=c-dis1[i];
		w1[i]=w1[i-1]+w[i];
	}
	for (long long i=n;i;i--) w2[i]=w2[i+1]+w[i];
	for(long long i=1;i<=n;++i)
	if(w1[i]-dis1[i]>mx1) mx1=w1[i]-dis1[i],pos1=i;
	for(long long i=n;i;i--)
	if(w2[i]-dis2[i]>mx2) mx2=w2[i]-dis2[i],pos2=i;
	for(long long i=0;i<=n+1;++i) sm1[i]=sm2[i]=-inf;
	for(long long i=1;i<=n;++i) sm1[i]=max(sm1[i-1],w1[i]-dis1[i]);
	for(long long i=n;i;--i)    sm2[i]=max(sm2[i+1],w2[i]-dis2[i]);
	ans=max(ans,max(mx1,mx2));
	ans=max(ans,max(mx1,mx2));
	for(long long i=1;i<=n;++i) ans=max(ans,w1[i]-2*dis1[i]+sm2[i+1]);
	for(long long i=n;i;i--) ans=max(ans,w2[i]-2*dis2[i]+sm1[i-1]); 
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			while ((x = in.readLine()) != null) {
				if (x.equals("0 0")) break;
				
				String[] values = x.split(" ");
	
				int a = Integer.parseInt(values[0]);
				int b = Integer.parseInt(values[1]);
				
				for (int i = 0; i < a; i++) {
					for (int j = 0; j < b; j++) {
						if ((i == 0) || (j == 0) || (i == (a - 1)) || (j == (b - 1))) {
							System.out.print('#');
						} else {
							System.out.print('.');
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

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

using namespace std;

const int N = (int)2e5 + 7;

int a[N];
int n;
map < int, int > mp;

main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		mp[a[i]]++;
	}
	int ans = 0;
	sort(a + 1, a + n + 1);
	for (int i = n; i >= 1; i--) {
		if (mp[a[i]] == 0) continue;
		int cur = 1;
		while (cur <= a[i]) cur <<= 1;
		if (mp[cur - a[i]] > (cur == a[i] + a[i])) {
			ans++;
			mp[a[i]]--;
			mp[cur - a[i]]--;
		}
	}
	cout << ans;
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
    typedef long long ll;
    #define pb push_back
    #define f first
    #define s second
    #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define endl '\n'

using namespace std;
const int MAX=1e5+2;
const int inf = 1e9+77;
const int MOD = 1e9+7;
ll x[MAX];

char ALPH[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};


char ALPH_C[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char vowels[6]={'a','e','i','o','u','y'};

ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         if(y%2==1)
         s*=x;
         return s;
}


ll dp[MAX];
int n;
ll solve(int i){
    if(i==n-1) return 0;
    ll &res=dp[i];
    if(res!=-1) return res;
     if(i<n-2){
        res=min(solve(i+1)+abs(x[i]-x[i+1]),solve(i+2)+abs(x[i]-x[i+2]));
     }
     else res=solve(i+1)+abs(x[i]-x[i+1]);

     return res;

}


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

//    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>x[i];
    }
    for(int i=0;i<MAX;i++){
        //for(int j=0;j<100;j++)
        dp[i]=-1;
    }
    cout<<solve(0);



    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, (right - left) + 1));
    }
}

Measured memory_bytes: 63484
#include <stdio.h>

int main (void)
{
   int n , d , x=0 , i , j;

       scanf("%d",&n);
   int a[n+1];
       scanf("%d%d",&d,&x);
    for(i=0; i<n; i++)
       scanf("%d",&a[i]);

    for(i=0; i<n; i++){
      for(j=1; j<=d; j=j+a[i])
         x = x + 1;
    }

    printf("%d\n",x);
    return 0 ;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    reverse(a.begin(),a.end());
    rep(i,n){
        cout<<a[i];
        if(i<n-1) cout<<" ";
    }
    cout<<endl;
    return 0;
} 


Measured memory_bytes: 3000
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        switch (s){
            case "SUN":
                System.out.println(7);
                return;
            case "MON":
                System.out.println(6);
                return;
            case "TUE":
                System.out.println(5);
                return;
            case "WED":
                System.out.println(4);
                return;
            case "THU":
                System.out.println(3);
                return;
            case "FRI":
                System.out.println(2);
                return;
            default:
                System.out.println(1);
        }
    }
}


Measured memory_bytes: 22996
if_debag = False

input_texts = """5 25000
20 1000
40 1000
50 1000
30 1000
1 1000"""

input_texts = input_texts.split('\n')
it = iter(input_texts)
#next(it)

def my_input():
    if if_debag:
        return next(it)
    else:
        return input()

d, g = map(int, my_input().split())
ps = list()
cs = list()
for i in range(d):
    p, c = map(int, my_input().split())
    ps.append(p)
    cs.append(c)

minv = 2000
for i in range(1 << d):
    toita_mondai = 0
    sougou_tensu = 0
    for j in range(d):
        if (i >> j) & 1:
            toita_mondai += ps[j]
            sougou_tensu += (j + 1) * 100 * ps[j] + cs[j]
    if sougou_tensu >= g:
        minv = min(minv, toita_mondai)
    else:
        nokori = g - sougou_tensu
        flag = False
        for j in range(d - 1, -1, -1):
            if (i >> j) & 1:
                continue
            for _ in range(ps[j]):
                nokori -= 100 * (j + 1)
                toita_mondai += 1
                if nokori <= 0:
                    minv = min(minv, toita_mondai)
                    flag = True
                    break
            if (flag): break        
print(minv)

Measured memory_bytes: 41968
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp{
  char name[100];
  int t;
}
P;
P Q[LEN];
int head, tail, n;
void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
P dequeue(void){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
int min(int a,int b){
  return a < b ? a : b; 
}
int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  char str[64];
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 5013;

int N, INF;
int ans;
int dp[MAXN];

int add(int a, int b)
{
    a += b; if (a >= INF) a -= INF; return a;
}
int mul(int a, int b)
{
    return (ll) a * b % INF;
}
int sub(int a, int b)
{
    a -= b; if (a < 0) a += INF; return a;
}
int pwr(int a, int b)
{
    int res = 1;
    while(b)
    {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> INF;
    // FOR(i, 0, 4)
    // {
    //     FOR(j, 0, 4)
    //     {
    //         FOR(k, 0, 4)
    //         {
    //             if (i + 2 * j + k < 3 && i + j + k <= 2)
    //             {
    //                 cerr << i << " " << j << " " << k << endl;
    //                 ans++;
    //             }
    //         }
    //     }
    // }
    // cout << ans << '\n';
    // return 0;
    dp[0] = 1;
    FOR(i, 0, N)
    {
        int c = min(i + 1, N - i);
        //you can add any multiple of c.
        FOR(j, 0, c)
        {
            for (int k = j + c; k < N; k += c)
            {
                dp[k] = add(dp[k], dp[k - c]);
            }
        }
    }
    FOR(i, 0, N)
    {
        ans = add(ans, dp[i]);
    }
    // ans = sub(ans, N + 1);
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

typedef long long int ll;
#define MAXSIZE 10000000;

const int MAX = 510000;
const int MOD = 1000000007;
const long long INF = 1LL << 60;

ll dp[10001][1001] = {0};

int main()
{
    int n, x;
    while (true)
    {
        cin >> n >> x;
        if (n == 0 && x == 0)
        {
            break;
        }

        set<int> st;
        for (int i = 1; i <= n; i++)
        {
            st.insert(i);
        }
        set<set<int>> ansSet;

        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (i == j)
                    continue;
                int res = x - i - j;
                if (res == i || res == j)
                    continue;
                set<int> temp{i, j, res};
                if (st.count(res) == 1)
                {
                    ansSet.insert(temp);
                }
            }
        }

        cout << ansSet.size() << endl;
    }
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

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


*/



Measured memory_bytes: 3364
fun main(arg: Array<String>) {
    val K = nextInt()
    var ans = 0L
    repeat(K, K, K) { a, b, c ->
        ans += gcd(a.plus1(), gcd(b.plus1(), c.plus1()))
    }
    return println(ans)
}
fun Int.plus1() = (this + 1).toLong()
tailrec fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b
inline fun repeat(times1: Int, times2: Int, times3: Int, action: (Int, Int, Int) -> Unit) {
    for (index1 in 0 until times1)
        for (index2 in 0 until times2)
            for (index3 in 0 until times3) {
                action(index1, index2, index3)
            }
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 34708
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<long long> S1(N + 1, 0);
  for (int i = 0; i < N; i++){
    S1[i + 1] = S1[i] + max(a[i], 0);
  }
  vector<long long> S2(N + 1, 0);
  for (int i = 0; i < N; i++){
    S2[i + 1] = S2[i] + a[i];
  }
  long long ans = 0;
  for (int i = 0; i <= N - K; i++){
    ans = max(ans, (S1[i] - S1[0]) + max(S2[i + K] - S2[i], (long long) 0) + (S1[N] - S1[i + K]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 5100
#include<iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char const *argv[])
{
    int R;

    cin>>R;
    if(R>=2800){
        cout<<"AGC"<<endl;
    }else if(R>=1200){
        cout<<"ARC"<<endl;
    }else {
        cout<<"ABC"<<endl;
    }
    return 0;
}

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

int main() {
    int n; scanf("%d", &n);
    if (n <= 500) {
        cout << n << endl;
        for (int i = 1; i <= n; i++, cout << endl) 
            for (int j = 1; j <= n; j++) cout << i << ' ';
    } else {
        cout << 500 << endl;
        for (int i = 1; i <= 500; i++, cout << endl) 
            for (int j = 1; j <= 500; j++) {
                int t = j - i + 1; if (t <= 0) t += 500;
                if ((i & 1) && t + 500 <= n) t += 500;
                cout << t << ' ';
            }
    }
} 

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

int main(){
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vector<int> lis(n, 0);
    for(int i = 0; i < n-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            lis[i+1]++;
        }
    }
    for(int i = 1; i < n; i++){
        lis[i] = lis[i] + lis[i-1];
    }
    for(int i = 0; i < q; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        cout << lis[b] - lis[a] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001
#define fi first
#define se second
using P = pair<ll,ll>;

int main(void) {
	ll n,d,a; cin >> n >> d >> a;
	vector<P> p(n);
	rep(i,n) cin >> p[i].fi >> p[i].se;
	SORT(p);
	ll l = d*2;
	ll ans = 0;
	ll tot = 0;
	queue<P> q;
	rep(i,n){
		ll x = p[i].fi;
		ll h = p[i].se;
		while( q.size() && q.front().fi < x ){
			tot -= q.front().se;
			q.pop();
		}
		h = max(ll(0),h-tot);
		ll num = (h+a-1)/a;
		ll damage = a*num;
		ans += num;
		tot += damage;
		q.emplace(x+l,damage);
	}
	cout << ans << endl;
}




Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define maxn 10005
#define MOD 998244353
#define INF 10000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll dp[maxn];

void solve(){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0 ; i <n; i++) cin >>a[i];
    ll ans = INF;
    for(ll i = 1; i <=100; i++){
        ll s = 0;
        for(ll j = 0 ; j < n; j++){
            s += (a[j] - i)*(a[j] - i);
        }
    ans = min(ans, s);
    }
    cout << ans;
}

int main()
{
    fast();
    int t= 1; //cin >> t;
    while(t--){
        solve();
    }
}

/*
5
1 2
2 3
3 4
3 5
*/


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
string ss,fro,bac;bool re=0;
int main()
{
	cin>>ss;
	fro=bac="";
	int q=read();
	while(q--)
	{
		int kk=read();
		if(kk==1)re=!re;
		else
		{
			kk=(read()+re)%2;char cc=getchar();
			while(cc==' '||cc=='\n')cc=getchar();
			if(kk)fro=cc+fro;
			else bac=bac+cc;
		}
	}
	ss=fro+ss+bac;
	if(re)reverse(ss.begin(),ss.end());
	cout<<ss;
}

Measured memory_bytes: 1512
def divide_by_2(num):
	cnt = 0		

	while True:
		if num % 2 != 0:
			break
		num /= 2
		cnt += 1
	
	return cnt


def main():
	N = int(input())

	lst = [-1] * (N + 1)

	for num in range(1, N + 1):
		cnt = divide_by_2(num)
		lst[num] = cnt

	print(lst.index(max(lst)))


  
if __name__ == "__main__":
  	main()

Measured memory_bytes: 9152
#include <iostream>
#include <vector>
#include <set>
#include <functional>
#include <algorithm>

int main() {
    long long n, l, w, t, w0, ret = 0;
    std::cin >> n >> l;
    std::vector<std::multiset<long long, std::greater<>>> v(4);
    std::cin >> w0 >> t;
    v[0].insert(t);
    for (auto i = 1; i < n; i++) {
        std::cin >> w >> t;
        v[w - w0].insert(t);
    }
    std::vector<long long> p0(v[0].size() + 1), p1(v[1].size() + 1), p2(v[2].size() + 1), p3(v[3].size() + 1);
    for (auto i = 1; i < p0.size(); i++) {
        p0[i] = p0[i - 1] + *v[0].begin();
        v[0].erase(v[0].begin());
    }
    for (auto i = 1; i < p1.size(); i++) {
        p1[i] = p1[i - 1] + *v[1].begin();
        v[1].erase(v[1].begin());
    }
    for (auto i = 1; i < p2.size(); i++) {
        p2[i] = p2[i - 1] + *v[2].begin();
        v[2].erase(v[2].begin());
    }
    for (auto i = 1; i < p3.size(); i++) {
        p3[i] = p3[i - 1] + *v[3].begin();
        v[3].erase(v[3].begin());
    }

    for (auto i0 = 0; i0 < p0.size(); i0++) {
        for (auto i1 = 0; i1 < p1.size(); i1++) {
            for (auto i2 = 0; i2 < p2.size(); i2++) {
                for (auto i3 = 0; i3 < p3.size(); i3++) {
                    if (i0 * w0 + i1 * (w0 + 1) + i2 * (w0 + 2) + i3 * (w0 + 3) <= l) ret = std::max(ret, p0[i0] + p1[i1] + p2[i2] + p3[i3]);
                }
            }
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
b = []
for _ in range(m):
    b.append(int(input()))
c = []
for i in range(n):
    c.append(sum([a[i][j] * b[j] for j in range(m)]))
for i in c:
    print(i)



Measured memory_bytes: 6020
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<float.h>
using namespace std;


int main() {
    string  a, b,c,d;
    cin >> a>>b>>c;
    cout << a[0] << b[1] << c[2] << endl;
  
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int main(){
    int X,Y,Z;
    cin >> X;
    cin >> Y;
    cin >> Z;
    swap(X,Y);
    swap(X,Z);
    cout << X <<" "<< Y <<" "<< Z;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
     
int main(){
     
     
    int n, i, t;
     
    vector<int> v;

    double k;
     
     
    cin >> n;
     
     
    for( i = 0 ; i < n ; i = i + 1 ){
     
         cin >> t;
     
         v.push_back(t);
     
         }


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


    k = (double)( v.at(0) + v.at(1) ) / 2;
     
     
    for( i = 1 ; i < n - 1 ; i = i + 1 ){
     
         k = (double)( k + v.at(i + 1) ) / 2;
     
         }
     
     
    cout << fixed << setprecision(7);
     
    cout << k << endl;
     
     
    return 0;
     
     
    }

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

long a[45], b[45];
int main() {
    long A, B; cin >> A >> B;
    if(A>0) --A;
    int mx=0;
    long ans=0;
    for(long i=2; i/2<=max(A, B); i *= 2){
        long t=A/i, u=B/i;
        a[mx]=i/2*t, b[mx]=i/2*u;
        if(A%i>=i/2) a[mx] += A%i-i/2+1;
        if(B%i>=i/2) b[mx] += B%i-i/2+1;
        if((b[mx]-a[mx])%2>0) ans += i/2;
        ++mx;
    }
    cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
const int N=3e5+100;
ll mod=1e9+7;
ll a[N];
ll gcd(ll a,ll b )
{
     return  b==0?a:(gcd(b,a%b));

}
int main()
{
    ll a,b;
    cin>>a>>b;
    if(a>b)swap(a,b);
    ll sum=a*b;
    cout<<sum/gcd(a,b);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define  ll  long long int
#define  sz  200010

using namespace std;

ll num[sz];
priority_queue<ll>q;
set<ll>st;
set<ll> :: iterator it;

int main()
{

    ll n,i,j,s=0,d,k,x,a,b,p;

    cin>>n>>k;

    for(i=1;i<=n;i++)
    {
        cin>>d;
        st.insert(d);
        num[d]++;
    }

    p=st.size();

    if(p<=k)
    {
        cout<<0<<endl;
        return 0;
    }

    for(it=st.begin();it!=st.end();it++)
    {
        d=*it;
        x=num[d];
        q.push(-x);

    }

    ll c=0;
    d=p-k;

    while(!q.empty())
    {
        x=q.top();
        q.pop();
        x=x*-1;
        c++;

        s+=x;

        if(c==d)break;
    }


    cout<<s<<endl;


    return 0;
}


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

int main()
{
    int a, b;
    std::cin >> a >> b;

    int num_a = 0;
    int num_b = 0;
    for (int i = 0; i < b; i++)
    {
        num_a *= 10;
        num_a += a;
    }
    for (int i = 0; i < a; i++)
    {
        num_b *= 10;
        num_b += b;
    }

    if (a < b)
        std::cout << num_a << std::endl;
    else
        std::cout << num_b << std::endl;

    return 0;
}

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

int main() {
	
	int A,B;
	cin >>A >>B;
	
	if((A+B)%2==0){
		
		cout <<(A+B)/2 <<endl;
		
	}
	else{
		
		cout <<"IMPOSSIBLE"<<endl;
		
	}
	
}

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

int main() {
  string S;
  int counter = 0;
  cin >> S;
  for (int i = 0; i < S.size(); i++){
      if (isupper(S[i])){
        counter = counter + 1;
      }
  }
  if (counter != 2){
    cout << "WA" << endl;
  }else if (S[0] != 'A'){
    cout << "WA" <<endl;
  }else{
    for (int j = 2; j < S.size()-1; j++){
      if (S[j] == 'C'){
        cout << "AC" << endl;
        break;
      } else if (j == S.size() - 2){
        cout << "WA" << endl;
      }
    }
  }
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define maxn 55
using namespace std;
int n,m,q,st=maxn,ed=0,sum;
int a[maxn],b[maxn],c[maxn],d[maxn],p[15];
void dfs(int step) //step当前处理到的步数
{
    int i,j;
    if(step==ed+1) //已找到a sequence A
    {
        int t=0;
        for(j=1; j<=q; j++) //尝试测试数据
            if(p[b[j]]-p[a[j]]==c[j])
                t+=d[j];
        sum=max(sum,t);//找最大值
        return;
    }
    for(i=p[step-1]; i<=m; i++) //注意，元素值非递减
    {
        p[step]=i;//设置数组元素值iiiii 
        dfs(step+1);
    }
}
int main()
{
    int i;
    scanf("%d%d%d",&n,&m,&q);
    for(i=1; i<=q; i++)
        scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]),st=min(st,a[i]),ed=max(ed,b[i]);
    ed=ed-st+1,st=1,p[0]=1;//st,ed找数组脚标的边界，目标，脚标起始位置从1开始。
    dfs(1);
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//街aからbの最短経路問題
//最短経路が何通りあるか調べる
//配るdp
int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N,A,B;
    cin >> N >> A >> B;

    string res;

    if(abs(A-B) % 2 == 0)
    {
      res = "Alice";
    }
    else res = "Borys";

    cout << res << endl;

    return 0;    

}



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

int A[101];

int main(void) {
 
    int N,M;
    cin >> N >> M;

    int sum = 0;
    for(int i=0;i<N;++i)
    {
        cin >> A[i];
        sum += A[i];
    }
    
    int ans = 0;
    for(int i=0;i<N;++i)
    {
        if (double(A[i]) >= double(sum/(4.0*M))) ans++;
    }

    if (ans >= M)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
 
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int main()
{
  char s[200001];
  scanf("%s", s);
  int start, end;
  for (int i = 0; ; i++)
    if (s[i] == 'A') {
      start = i;
      break;
    }
  for (int i = strlen(s); ; i--)
    if (s[i] == 'Z') {
      end = i;
      break;
    }
  printf("%d", end - start + 1);
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

main(){
	int n, i, j;
	scanf("%d",&n);
	
	for(i=3;i<=n;i++){
		if(i%3==0||i%10==3||(i/10)%10==3||(i/100)%10==3||(i/1000)%10==3)printf(" %d",i);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

const char dayName[ 7 ][ 7 ] = { "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur" };

int zeller( int, int );

int main( void ) {
	int mon, day;

	for ( ; scanf( "%d %d", &mon, &day ), mon; printf( "%sday\n", dayName[ zeller( mon, day ) ] ) ) ;

	return 0;
}

int zeller( int m, int d ) {
	int y = 2004;

	if ( m < 3 ) {
		y--;
		m += 12;
	}
	
	return ( y + y / 4 - y / 100 + y / 400 + ( m * 13 + 8 ) / 5 + d ) % 7;
}

Measured memory_bytes: 596
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a+b>=c){
    printf("%d\n",b+c);
    return 0;
  }
  printf("%d\n",a+b+b+1);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	bool benar;
	benar=false;
	while(cin>>a>>b)
	{

				if (benar)
		{
			cout<<"\n";
		}
		if ((a==0) and (b==0))
		{
			goto lari;
		}

	for (int i=1;i<=a;i++)
	{
		for (int j=1;j<=b;j++)
		{
			cout<<"#";
		}
	cout<<"\n";
	}
	benar=true;
	}
	lari:
	return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int n, cnt, ans = 1e9;
bool a[maxn + 10][maxn + 10];
char s[maxn + 10];
int main() {
	scanf("%d", &n);
	bool fd = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= n; ++j) {
			a[i][j] = s[j] == '#'; fd |= a[i][j];
		}
	}
	if (!fd) printf("-1");
	else {
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (!a[j][i]) {
					++cnt; break;
				}
		for (int i = 1; i <= n; ++i) {
			int now = cnt + 1;
			for (int j = 1; j <= n; ++j)
				now += !a[i][j];
			for (int j = 1; j <= n; ++j)
				if (a[j][i]) {
					--now; break;
				}
			ans = min(ans, now);
		}
		printf("%d", ans);
	}
}


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

typedef long long ll;

ll t,d,l;
ll x[100005];
ll i;
ll ans;

bool solve(){
	cin >> t >> d >> l;
	if(t == 0){
		return false;
	}
	for(i=0;i<t;i++){
		cin >> x[i];
	}
	ll value = 0;
	ans = 0;
	for(i=0;i<t-1;i++){
		if(x[i] >= l)value = d;
		if(value >= 1){
			ans++;
			value--;
		}
	}
	cout << ans << endl;
	return true;
}

int main(){
	while(solve()){}
	return 0;
}



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

using namespace std;

int main() {
	string S;
	cin>>S;
	long long w,ans;
	w=ans=0;
	for(int i=0;i<S.size();i++){
		if(S[i]=='W') w++;
	}
	w--;
	for(int i=S.size()-1;i>0;i--){
		if(S[i]=='W') ans+=(i-w), w--;
	}
	cout<<ans;
	return 0;
}

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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N,K;
	string S;
	cin >> N >> S >> K;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] != S[K - 1])S[i] = '*';
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxN=2e5+10;
int N;
string S;
int num[maxN],cnt[maxN];
int main()
{
	cin>>S;
	N=S.size();
	S='$'+S;
	int pw=1;
	for(int i=N;i>=1;i--)
	{
		int tmp=S[i]-'0'; 
		num[i]=(num[i+1]+pw*tmp)%2019;
		pw=pw*10%2019;
//		cout<<num[i]<<endl;
	}
	cnt[0]=1;
	int ans=0;
	for(int i=N;i>=1;i--)
	{
		ans+=cnt[num[i]];
		cnt[num[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4548
<?php

$is_honban = 1;

if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $s = $sc->next();



} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);

  $s = '011';



}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;
//echo $s;
$ans = $s[0] + $s[1] + $s[2];



//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

?>


Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int T, n, k[200010], l[200010], r[200010];
vector<int> vec1[200010], vec2[200010];
priority_queue<int> que;

signed main() {
	cin >> T;
	for (int t = 0; t < T; t++) {
		cin >> n;
		ll ans = 0;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			cin >> k[i] >> l[i] >> r[i];
			if (l[i] <= r[i])vec2[k[i] + 1].push_back(r[i] - l[i]), ans += l[i];
			else vec1[k[i]].push_back(l[i] - r[i]), cnt++, ans += r[i];
		}
		for (int i = n; i > cnt; i--)for (int j = 0; j < (int)vec1[i].size(); j++)que.push(vec1[i][j]);
		for (int i = cnt; i >= 1; i--) {
			for (int j = 0; j < (int)vec1[i].size(); j++)que.push(vec1[i][j]);
			if (que.empty())continue;
			ans += que.top(); que.pop();
		}
		while (!que.empty())que.pop();
		for (int i = 1; i <= cnt; i++)for (int j = 0; j < (int)vec2[i].size(); j++)que.push(vec2[i][j]);
		for (int i = cnt + 1; i <= n; i++) {
			for (int j = 0; j < (int)vec2[i].size(); j++)que.push(vec2[i][j]);
			if (que.empty())continue;
			ans += que.top(); que.pop();
		}
		while (!que.empty())que.pop();
		for (int i = 1; i <= n + 1; i++)vec1[i].clear(), vec2[i].clear();
		cout << ans << endl;
	}
}

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

int main() {
	int n, taro=0, hanako=0;
	cin >> n;
	string card1, card2;
	for (int i = 0;i < n;i++) {
		cin >> card1 >> card2;
		if (card1 > card2)
			taro += 3;
		else if(card1 < card2)
			hanako += 3;
		else {
			taro++;
			hanako++;
		}
	}
	cout << taro << " " << hanako << endl;
}

Measured memory_bytes: 3176
n,k=map(int,input().split())
s=list(input())
count0=[]
count1=[]
if s[0]=="0":
    count1.append(0)

i=0
temp=0
while i<=n-1:
    j=0
    while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
    if s[i]=="0":
        count0.append(j+1)
    else:
        count1.append(j+1)
    i+=(j+1)


if s[-1]=="0":
    count1.append(0)


sun=sum(count0[:k])+sum(count1[:k+1])
temp=sun
for i in range(len(count0)-k):
    sun=sun+count0[k+i]+count1[k+1+i]-count0[i]-count1[i]
    temp=max(temp,sun)
print(temp)

Measured memory_bytes: 82952
#include<stdio.h>
int main()
{
    int i,n,m,k,a;
    double b;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0,m=0,k=0;i<n;i++)
        {
            scanf("%d",&a);
            if(a%4==0)
                m++;
            else if(a%2==0)
                k++;
        }
        if(k)
        n-=k-1;
        if(m>=n/2)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

int main() {
    cin >> s >> t;
    bool flg = false;
    int slen = s.length();
    for(int i = 0; i < slen; ++i) {
        string sfst, ssnd, sre;
        sfst = s.substr(0, i);
        ssnd = s.substr(i, slen-i);
        sre = ssnd + sfst;
        if(sre == t) {
            flg = true;
            break;
        }
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

vector<long long> input(long long N){
  vector<long long> res(N);
  for (int i = 0; i < N; i++)scanf("%lld", &res[i]);
  sort(res.begin(), res.end());
  return res;
}

int main(){
    int N;
    scanf("%d", &N);
    vector<long long> A(N);
    A = input(N);
    A.push_back(0);//最後の要素を処理する
    
    int cnt = 1;//何個あるかカウント
    long long view = A[0];//今見ている数(Ai)
    long long ans = 0;
    for(int i = 1; i <= N; i++){
        if(A[i] == view)cnt++;
        else{
            if(cnt < view)ans += cnt;//個数 < Ai ：全部消す
            else ans += (cnt - view);//Ai <= 個数 ：余剰分(個数 - Ai)を消す
            cnt = 1;
            view = A[i];
        }
    }
    
    printf("%lld\n", ans);
}

Measured memory_bytes: 1804
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    a = sorted(A)
    asum = [0]*N
    asum[0]=a[0]
    for x in range(1, N):
        asum[x] = asum[x-1]+a[x]
    
    stop = -1
    for i in range(N-1):
        if asum[i] * 2 < a[i+1]:
            stop = i
    print(N-stop-1)


    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21236
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num[] = new int[3];
		for(int i = 0; i < num.length; i++) {
			num[i] = sc.nextInt();
		}
		int count5 = 0;
		int count7 = 0;
		for(int i = 0; i < num.length; i++) {
			if(num[i] == 5) {
				count5++;
			}else if(num[i] == 7) {
				count7++;
			}else {
				break;
			}
		}
		if(count5 == 2 && count7 == 1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21716
import java.util.Scanner;
 
public class Main {
 
	public static final long MOD = 1_000_000_007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		
		System.out.println(m*m*m);
		
	}
 
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


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

  ll ans = 0;
  rep(i, n) {
    ll x = i+1;
    if (x%3 != 0 && x%5 != 0) ans += x;
  }

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


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld; 
typedef vector<int> vi;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)

int main()
{
	ll a, b, n;
	cin>>a>>b>>n;
	cout<<(a*min(n, b-1)/b)<<endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int n;
  scanf("%d",&n);
  std::vector<int > s(n), l(n), p(n);
  for (int i=0; i<n; i++){
    scanf("%d",&s[i]);
    scanf("%d",&l[i]);
    scanf("%d",&p[i]);
  }
  int m;
  scanf("%d",&m);
  std::vector<int > w(m);
  for (int i=0; i<m; i++){
    scanf("%d",&w[i]);
  }
  std::vector<std::vector<int > > dp(n, std::vector<int > (394, 0));

  // i=0 case
  for (int j=0; j<=393; j++){
    if (j<s[0]){
      dp[0][j] = 0;
    } else {
      for (int k=s[0]; k<=l[0]; k++){
        dp[0][j] = std::max(dp[0][std::max(j-k,0)]+p[0], dp[0][j]);
      }
    }
  }
  
  // i>0 case
  for (int i=1; i<n; i++){
    for (int j=0; j<=393; j++){
      if (j<s[i]){
        dp[i][j] = dp[i-1][j];
      } else {
        for (int k=s[i]; k<=l[i]; k++){
          dp[i][j] = std::max(dp[i][std::max(j-k,0)]+p[i], dp[i][j]);
        }
        dp[i][j] = std::max(dp[i-1][j], dp[i][j]);
      }
    }
  }
  
  // answer
  bool ng = false;
  for (int i=0; i<m; i++){
    if (dp[n-1][w[i]]==0){
      ng = true;
    }
  }
  
  if (ng) {
    printf("-1\n");
  } else {
    for (int i=0; i<m; i++){
      printf("%d\n",dp[n-1][w[i]]);
    }
  }
  return 0;
}



Measured memory_bytes: 3388
#include<iostream>
#include<cmath>
using namespace std;
int N_MAX = 100000;
int main()
{
  int n,a,b,c=0,s,i,res;
  int t[N_MAX];
  cin >> n;
  cin >> b;
  s=abs(b);
  for(i=1;i<n;i++){
    cin >> a;
    s+=abs(a-b);
    t[i-1]=abs(a-b)+abs(b-c)-abs(a-c);
    c=b;
    b=a;
  }
  a=0;
  s+=abs(a-b);
  t[n-1]=abs(a-b)+abs(b-c)-abs(a-c);
  for(i=0;i<n;i++)
    cout << s-t[i] << endl;
  return 0;
}

Measured memory_bytes: 1664
count=0
S=str(input())
T=str(input())
if 1<=len(S)<=2*(10**5) and 1<=len(T)<=2*(10**5):
    if len(S)==len(T) and (str.islower(S) and str.islower(T)):
         for i in range(len(S)):
                if S[i]==T[i]:
                    count=count+0
                else:
                    count=count+1
    else:
        print("wrong")
print(count)



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

typedef long long ll;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<bool>> maps(H, vector<bool>(W));
    for(int i = 0; i < H; i++)
    {
        string mapLine;
        cin >> mapLine;
        for(int j = 0; j < W; j++){
            maps[i][j] = (mapLine[j] == '.');
        }
    }
    vector<vector<int>> lrLightLength(H, vector<int>(W, -1));
    vector<vector<int>> udLightLength(H, vector<int>(W, -1));
    for(int i = 0; i < H; i++)
    {
        int left;
        int right;
        int j = 0;
        while(j < W)
        {
            while(j < W && maps[i][j] == false){
                j++;
            }
            if(j < W){
                left = j;
                while(j < W && maps[i][j] == true){
                    j++;
                }
                right = j;
                int length = right - left;
                for(int k = left; k < right; k++)
                {
                    lrLightLength[i][k] = length;
                }
            }
        }
    }

    for(int i = 0; i < W; i++)
    {
        int up;
        int down;
        int j = 0;
        while(j < H)
        {
            while(j < H && maps[j][i] == false){
                j++;
            }
            if(j < H){
                up = j;
                while(j < H && maps[j][i] == true){
                    j++;
                }
                down = j;
                int length = down - up;
                for(int k = up; k < down; k++)
                {
                    udLightLength[k][i] = length;
                }
            }
        }
    }

    int answer = 0;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            answer = max(answer, lrLightLength.at(i).at(j) + udLightLength.at(i).at(j) - 1);
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 32256
#include <iostream>
#include <vector>
#include <climits>
#include <functional>
#include <queue>
using namespace std;

template<typename Monoid>
class SegmentTree{
private:
    using F = function<Monoid(Monoid,Monoid)>;
    int sz;
    vector<Monoid> seg;
    const F op;//演算
    const Monoid e;//単位元
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    //代入
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    //前計算(?)
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] += x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

struct range{
    int l,r,val;
    bool operator<(const range& right)const{
        return val>right.val;
    }
};

typedef pair<int,int> Pa;

int main(){
    int N;
    const int inf = 1e9;
    auto func = [](Pa a,Pa b){
        if(a.first<b.first) return a;
        else return b;
    };
    cin >> N;
    vector<int> P(N);
    vector<SegmentTree<Pa>> seg;
    seg.push_back(SegmentTree<Pa>(N/2,func,Pa(inf,-1)));
    seg.push_back(SegmentTree<Pa>(N/2,func,Pa(inf,-1)));
    for(int i=0;i<N;i++){
        cin >> P[i];
        seg[i%2].set(i/2,Pa(P[i],i));
    }
    seg[0].build(),seg[1].build();
    vector<int> ans(N);
    priority_queue<range> Q;
    Q.push({0,N,seg[0].query(0,N/2).first});
    for(int i=0;i<N;i+=2){
        range now = Q.top(); Q.pop();
        int s = now.l%2,t = (s+1)%2;
        Pa left = seg[s].query(now.l/2,now.r/2);
        ans[i] = left.first;
        Pa right = seg[t].query((left.second+1)/2,(now.r+1)/2);
        ans[i+1] = right.first;
//        cerr << now.l << " " << now.r << " " << left.second << " " << right.second << endl;
        if(now.l!=left.second){
            Q.push({now.l,left.second,seg[now.l%2].query(now.l/2,left.second/2).first});
        }
        if(right.second+1!=now.r){
            Q.push({right.second+1,now.r,seg[(right.second+1)%2].query((right.second+1)/2,now.r/2).first});
        }
        if(left.second+2!=right.second){
            Q.push({left.second+1,right.second,seg[(left.second+1)%2].query((left.second+1)/2,right.second/2).first});
        }
    }
    for(auto x:ans) std::cout << x << " ";
    std::cout << endl;
}

Measured memory_bytes: 9852
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
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;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    int A,B,K; cin>>A>>B>>K;
    cout << min(B/A, K) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    string s;
    cin >> s;
    string ans;
    for(int i=0;i<s.length();i++){
        if(i%2==0){
            ans += s[i];
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 512