akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>

#define rep(i,min,sup) for(int i=min;i<sup;i++)
#define per(i,min,sup) for(int i=(sup-1);i>=min;i--)
#define swap(a,b) {a+=b;b=a-b;a-=b;}
#define ll long long

using namespace std;

main(){
  ll N,A,B;
  scanf("%lld %lld %lld",&N,&A,&B);
  printf("%lld",N/(A+B)*A+min(N%(A+B),A));
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int r, g, b;
  std::cin >> r >> g >> b;
  r *= 100, g *= 10;
  if ((r + g + b) % 4 == 0)
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
k = []
a = []
for i in range(n):
    k_a = list(map(int,input().split()))
    k.append(k_a[0])
    if k_a[0]:
        a.append(k_a[1:])
ans = []
for a_ in a:
    ans.append(set(a_))
k = ans[0]
for a_ in ans:
    k &= a_
print(len(k))

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

int main() {
	string N;
	cin >> N;
	if (N == "SAT") {
		cout << 1 << endl;
	}
	if (N == "FRI") {
		cout << 2 << endl;
	}
	if (N == "THU") {
		cout << 3 << endl;
	}
	if (N == "WED") {
		cout << 4 << endl;
	}
	if (N == "TUE") {
		cout << 5 << endl;
	}
	if (N == "MON") {
		cout << 6 << endl;
	}
	if (N == "SUN") {
		cout << 7 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
'use strict';

function main(arg) {
    let s = parseInt(arg);
    let memo  = new Set();
    let cnt = 1;
    
    memo.add(s);
    
    while(true) {
        cnt++;
        if(s % 2 === 0) {
            s = s / 2;
            if(memo.has(s)) {
                console.log(cnt);
                break;
            }
            memo.add(s);
        } else {
            s = (s * 3) + 1;
            if(memo.has(s)) {
                console.log(cnt);
                break;
            }
            memo.add(s);
        }
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nmd = Input.ar;
        var p = nmd[2] == 0 ? (double)1 / nmd[0] : (double)2 * (nmd[0] - nmd[2]) / ((long)nmd[0] * nmd[0]);
        WriteLine(p * (nmd[1] - 1));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

using namespace std;

int main()
{
    int n, k;
    scanf("%i%i", &n, &k);
    vector<long long> arr(n+200), dp(n+200, INT_MAX);
    for (int x = 1; x <= n; x++)
        scanf("%lli", &arr[x]);
    dp[1] = 0;
    for (int x = 1; x < n; x++)
    {
        for (int y = 1; y <= k; y++)
            dp[x+y] = min(dp[x+y], dp[x] + abs(arr[x]-arr[x+y]));
    }
    printf("%lli\n", dp[n]);
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define LL long long
using namespace std;
const int N=2e5+10;
int n,m,cnt=1,a[N],b[N];
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	m=read();
	for(int i=1;i<=m;i++)b[i]=read();
	if(m>n){printf("NO");return 0;}
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	for(int i=1;i<=m;i++)
	{
		while(a[cnt]<b[i]&&cnt<=n)cnt++;
		if(cnt>n){printf("NO");return 0;}
		if(a[cnt]>b[i]){printf("NO");return 0;}
		cnt++;
	}
	printf("YES");
	return 0;
}

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

int main(void)
{
    char ch;
    cin>>ch;
    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
    {
        cout <<"vowel"<<endl;
    }
    else
    {
        cout <<"consonant"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a * b >= c * d){
        printf("%d\n",a * b);
    }else{
        printf("%d\n",c * d);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >>N;
  vector<long long> A;
  for(int n=0;n<N;n++){
    long long h;
    cin >>h;
    A.push_back(h);
  }
  
  sort(A.begin(),A.end());
  cout << A.at(N-1)-A.at(0) <<endl;
}

Measured memory_bytes: 256
def search(i,j):
  b = [-1,0,1]
  c = 0
  for dx in b:
    for dy in b:
      if dx == 0 and dy == 0:
        continue
      else:
        x = i + dx
        y = j + dy
        if 0 <= x < h and 0 <= y < w:
          if a[x][y] == "#":
            c += 1
  bomb = str(c)
  return bomb
      
h,w = map(int, input().split())
a = [list(input()) for i in range(h)]
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      continue
    else:
      a[i][j] = search(i,j)
  print("".join(a[i]))

Measured memory_bytes: 3188
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  LL debt = 100000L;
  int n;
  while(cin>>n){
    REP(i,n){
      double d = debt*1.05/1000;
      debt = (LL)(ceil(d) * 1000);
    }

    cout << debt  << endl;
  }


  return 0;
}

Measured memory_bytes: 1160
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    if a * b <= 0:
        print("Zero")
    elif a > 0 and b > 0:
        print("Positive")
    else:
        if a * b >= 0:
            if abs(a - b + 1) % 2 == 0:
                print("Positive")
            else:
                print("Negative")
        else:
            if abs(a) % 2 == 0:
                print("Positive")
            else:
                print("Negative")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
const int maxn=5005;
const int inf=0x3f3f3f3f;
typedef long long ll;
int a[maxn];
int n,k;
int b[maxn];
bitset<maxn> dp;
int judge(int x){
    if(a[x]>=k)return 1;
    dp.reset();
    dp[0]=1;
    for(int i=0;i<n;i++){
        if(i==x)continue;
        dp|=(dp<<a[i]);
    }
    for(int i=k-1;i>=k-a[x];i--){
        if(dp[i]){
            return 1;
        }
    }
    return 0;
}
int solve(){
    sort(a,a+n);
    int lo=0,hi=n-1;
    int mas=-1;
    while(lo<=hi){
        int m=(lo+hi)/2;
        if(judge(m))hi=m-1;
        else{
            lo=m+1;
            mas=max(mas,m);
        }
    }
    return mas+1;
}
int main(){
    while(scanf("%d%d",&n,&k)==2){
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        printf("%d\n",solve());
    }
    return 0;
}

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

using namespace std;

int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0;i < N;i++) {
        cin >> h[i];
    }
    int ans = 0;
    for (int i = 0;i < N;i++) {
        if(h[i] >= K){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main(){
    int n;

    cin >> n;
    set<string> str;

    for(int i= 0;i<n;i++){
        string s;
        cin >> s;
        auto itr = str.find(s);
        if(itr == str.end()){
            str.insert(s);
        }
    } 
    
    cout << str.size() << endl;
    return 0;  
}

Measured memory_bytes: 19264
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int H, W;
int MAP[2000][2000];

int TATE[2000][2000];
int YOKO[2000][2000];
int main(void){
    cin >> H >> W;
    char c;
    REP(i, H) REP(j, W){
        cin >> c;
        if (c=='.') MAP[i][j] = 0;
        else MAP[i][j] = 1;
    }
    REP(w,W){
        int start = 0;
        int end = 0;
        while(end < H){
            int count = -1;
            while(end < H and MAP[end][w] != 1){
                count++;
                end++;
            }
            for (int i=start;i<end;i++) TATE[i][w] = count;
            start = ++end;
        }
    }
    REP(h,H){
        int start = 0;
        int end = 0;
        while(end < W){
            int count = -1;
            while(end < W and MAP[h][end] != 1){
                count++;
                end++;
            }
            for (int i=start;i<end;i++) YOKO[h][i] = count;
            start = ++end;
        }
    }

    int res = 0;
    REP(h,H) REP(w,W) res = max(res, TATE[h][w]+YOKO[h][w]+1);
    cout << res << endl;

    return 0;
}



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

using namespace std;

void Main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int ret = c;
    if (b / a < c)
    {
        ret = b / a;
    }

    cout << ret;
}

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

    std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_096_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(10).
    01 maxlen PIC 9(1)  VALUE 2.
    01 cur    PIC 9(2)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).
    01 len    PIC 9(2).

    01 ab1.
        03 ab11 OCCURS 2.
            05 ab PIC 9(3).

    01 ans    PIC X(2).
    01 ZS     PIC Z(3).
    01 DUMMY  PIC X(1).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO ab(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    IF ab(2) < ab(1) THEN
        SUBTRACT 1 FROM ab(1)
    END-IF.

    MOVE ab(1) TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 384
from bisect import *
A,B,Q = map(int,input().split())
inf = float("inf")
S = [-inf]+[int(input()) for a in range(A)]+[inf]
T = [-inf]+[int(input()) for b in range(B)]+[inf]
X = [int(input()) for q in range(Q)]

for x in X:
  si = bisect(S,x)
  ti = bisect(T,x)
  d1 = x-S[si-1]
  d2 = S[si]-x
  d3 = x-T[ti-1]
  d4 = T[ti]-x
  print(min(2*d1+d4,d1+d4*2,2*d2+d3,d2+d3*2,max(d1,d3),max(d2,d4)))

Measured memory_bytes: 20740
#include <bits/stdc++.h>
#define ll long long
#define UP(a,b,i) for(int i=(a);i<=(b);i++)
#define DOWN(a,b,i) for(int i=(a);i>=(b);i--)
#define rep(a,b,i) UP(a,b-1,i)
ll ma=0x80000000;
ll mi=0x7fffffff;
const ll zfc=0xffffffff;
const ll mod=1e9+7;
using namespace std;
inline void input(ll &x)
{
    x=0;
    int f=1;
    char ch=getchar();
    while(!isdigit(ch))
	{
		if(ch=='-')f=-f;
		ch=getchar();
	}
    while(isdigit(ch))
	{
		x=x*10+(ch-'0');
		ch=getchar();
	}
    x*=f;
}
inline void output(ll x)
{
	if(x<0)
    {
        x=-x;
        putchar('-');
    }
    if(x/10>0)output(x/10);
    putchar(x%10+'0');
}
#define I(n) cin>>(n);
#define O(n) cout<<(n);
#define Enter() cout<<endl;
ll x,t;
int main()
{
	I(x);I(t);
	if(0>x-t)cout<<0;else cout<<x-t;
	Enter();
    return 0;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	ll K;

	cin >> K;

	cout << "50\n";

	V<ll> ans(50, 0);

	for (int i = 0; i < 50; ++i) {
		ans[i] = i + (K / 50);
	}

	for (int i = 50 - (K % 50); i < 50; ++i) {
		++ans[i];
	}

	for (int i = 0; i < 50; ++i) {
		cout << ans[i] << " \n"[i + 1 == 50];
	}



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


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

int main()
{
	int n, i,j,temp,way[101];
	cin >> n;
	int f[101][10];
	long long p[101][11],ans,re;
	for (i = 0; i < n; i++)
		for (j = 0; j < 10; j++)
			cin >> f[i][j];
	for (i = 0; i < n; i++)
		for (j = 0; j < 11; j++)
			cin >> p[i][j];
	for (int t = 1023; t ; t--)
	{
		re = 0;
		temp = t;
		memset(way, 0, sizeof(way));
		for (i = 0; i < 10; i++)
		{
			if (temp & 1)
			{
				for (j = 0; j < n; j++)
				{
					if (f[j][i])
						way[j]+=1;
				}
			}
			temp>>=1;
		}
		for (i = 0; i < n; i++)
			re += p[i][way[i]];
		if (t == 1023)
			ans = re;
		else
			if (re > ans)
				ans = re;
	}
	cout << ans << endl;
}

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

int main()
{
	long long int x, y, w, h;
	cin >> w >> h >> x >> y;
	cout << fixed << setprecision(10) << (1.0*w*h)/2 << " ";
	if((2*x)==w && (2*y)==h)
		cout << 1 << endl;
	else
		cout << 0 << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, c int
	fmt.Scan(&n, &m, &c)
	b := make([]int, m)
	for i := range b {
		fmt.Scan(&b[i])
	}
	as := make([][]int, n)
	for i := range as {
		as[i] = make([]int, m)
		for j := range as[i] {
			fmt.Scan(&as[i][j])
		}
	}

	var ans int
	for _, a := range as {
		var sum int
		for i := range a {
			sum += a[i] * b[i]
		}
		if sum+c > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, a;
    
    scanf("%d%d", &n, &a);

    printf("%d", n*n-a);
    
    return 0;
}



Measured memory_bytes: 1696
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
//
const int inf=1e4;
//
int main(){
	int K;
	cin>>K;
	cout<<(K/2)*((K+1)/2)<<endl;
	return 0;
}

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

using namespace std;

////Nayeem Shahriar Joy,Applied Physics &Electronic Engineering,University of Rajshahi.

int gcd(long long int a,long long int b)
{
    long long int c;
    while(a%b!=0)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return b;
}

int main()

{
   long long int a,b,k;
   while(cin>>a>>b)
   {
       k=gcd(a,b);
       cout<<k<<" "<<(a*b)/k<<endl;
   }
   return 0;
}

Measured memory_bytes: 3060
n,k=map(int, input().split())
x = list(map(int, input().split()))

ret= 1000000000
for i in range(n-k+1):
    a = x[i]
    b = x[i+k-1]
    ret =min([ret, abs(a) + abs(a - b), abs(b) + abs(a - b)])

print(ret)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int n, t;
    cin >> n >> t;
    vector<P> d(n);
    // knapsack dp , maximum satisfaction using items 0-i, with time j.
    vector<vector<int>> dp(n + 1, vector<int>(t + 1, 0));

    rep(i, n) cin >> d[i].first >> d[i].second;
    // sort list so item i is the most expensive food
    sort(d.begin(), d.end());

    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < t; ++j)
        {
            chmax(dp[i + 1][j], dp[i][j]);
            int now_time = j + d[i].first;

            if (now_time < t)
                chmax(dp[i + 1][now_time], dp[i][j] + d[i].second);
        }
        // actual best option using items 0-i is knapsack + most expensive food
        int now = dp[i][t - 1] + d[i].second;
        // if this best is better than other options use this item config.
        chmax(ans, now);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll n,sum=0;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) {
        cin>>a[i];
        sum += a[i]-1;
    }
    cout<<sum<<endl;
    
    return 0;
}


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

const int MAX_N = 1000000;
bool prime[MAX_N + 1];

void sieve()
{
  prime[0] = prime[1] = false;
  for(int i = 2; i <= MAX_N; i++)
    prime[i] = true;
  for(int i = 2; i <= MAX_N; i++)
    if(prime[i])
      for(int j = i * 2; j <= MAX_N; j += i)
	prime[j] = false;
}

int main()
{
  sieve();
  int a, d, n, ans;
  while(1){
    cin >> a >> d >> n;
    if(a == 0 && d == 0 && n == 0){
      break;
    }else{
      for(int i = 0, j = 0;; i++){
	if(prime[a + i * d]){
	  if(++j == n){
	    cout << a + i * d << endl;
	    break;
	  }
	}
      }
    }
  }
}

Measured memory_bytes: 2136
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 3e4 + 5;
const int M = 1e6 + 5;
const int Q = 2e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

string s,t;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> s >> t;

    cout << t << s << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll k, a, b;

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> k >> a >> b;
    if ((a / k + 1) * k > b && (a / k) * k < a)
        cout << "NG";
    else
        cout << "OK";
    return 0;
}


Measured memory_bytes: 3584
# 整数の入力
n = gets.to_i

# スペース区切りの整数の入力
weights = gets.chomp.split(" ").map(&:to_i)

diff = 99999

s1 = weights[0]
s2 = weights.inject(:+) - weights[0]

for i in 1..(n-1)
  s1 += weights[i]
  s2 -= weights[i]
  diff_abs = (s1 - s2).abs
  if diff > diff_abs
    diff = diff_abs
  end
end

# 出力
print("#{diff}\n")


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100100][2],w[110],u[110];
int n,bw;
void sed(int i, int j, ll v) {
	if(dp[i][j] == -1) {dp[i][j] = v;return;}
	dp[i][j] = min(dp[i][j],v);
}
ll ds() {
	dp[0][0] = 0;
	int s=1,g=0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<100010;j++) {
			if(dp[j][g] != -1) {
				sed(j,s,dp[j][g]);
				sed(j+u[i],s,dp[j][g]+w[i]);
			}
		}
		s = 1-s;g=1-g;
	}
	for(int i=100010;i>=0;i--) {
		if(dp[i][g] != -1 && dp[i][g] <= bw) {return i;}
	}
	return 0;
}
int main() {
	scanf("%d %d ",&n,&bw);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++) {
		int a,b;
		scanf("%d %d ",&a,&b);
		w[i] = a;u[i]=b;
	}
	printf("%lld\n",ds());
}

Measured memory_bytes: 1792
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = [0]*N
count = 0
for j in range(1,len(S)):
    if S[j] == 'C' and S[j - 1] == 'A':
        count += 1
    else:
        pass
    S1[j] = count
#print(S1)

for k in range(Q):
    print(S1[A[k][1]-1]-S1[A[k][0]-1])

Measured memory_bytes: 30684
var H, W, i, j: longint;
    a: array[1..1000] of ansistring;
    dp: array[0..1000, 0..1000] of longint;
begin
    readln(H, W);
    for i:=1 to H do
            readln(a[i]);
    for i:=1 to H do
    begin
        for j:=1 to W do
        begin
            if a[i][j]='#' then
                dp[i,j]:=0
            else
                dp[i,j]:=(dp[i,j-1]+dp[i-1,j]) mod 1000000007;
            dp[1,1]:=1;
        end;
    end;
    writeln(dp[H, W]);
end.

Measured memory_bytes: 5120
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		sc.close();
		int cntmax = -1;
		int cnt, ii;
		int imax = 0;
		for(int i = 1; i <= n; i++) {
			cnt =0;
			ii =i;
			while(true) {
				if(ii%2==1)break;
				ii=ii/2;
				cnt++;
			}
//			System.out.println(""+i+":"+cnt);
			if(cnt > cntmax) {
				cntmax = cnt;
				imax = i;
			}
		}
		System.out.println(imax);
	}
}


Measured memory_bytes: 21716
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var oh = new Array(4);
  for( var i=0; i<4; i++ ) {
    oh[i] = new Array(3);
    for( var j=0; j<3; j++ ) {
      oh[i][j] = new Array(10);
      for( var k=0; k<10; k++ ) {
        oh[i][j][k] = 0;
      }
    }
  }
  var data = input.split( '\n' );
  for( var i=1; i<data.length; i++ ) {
    var p = data[i].split( ' ' ).map( Number );
    var b = p[0]-1;
    var f = p[1]-1;
    var r = p[2]-1;
    var v = p[3];
    for( var s=0; s<4; s++ ) {
      for( var j=0; j<3; j++ ) {
        for( var k=0; k<10; k++ ) {
          if( s == b && j == f && k == r ) {
            oh[s][j][k] += v;
          }
        }
      }
    }
  }
  var output = [];
  for( var i=0; i<4; i++ ) {
    for( var j=0; j<3; j++ ) {
      for( var k=0; k<10; k++ ) {
        output.push( ' '+oh[i][j][k] );
      }
      if( i != 3 || j != 2 ) { output.push( '\n' ); }
    }
    if( i != 3 ) { output.push( '####################\n' ); }
  }
  console.log( output.join( '' ) );
});

Measured memory_bytes: 9092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [i32; n], }
//
// # matrix
// input! { row: usize, column: usize, mat: [[i32; column]; row] }
//
// # string
// input! { s: chars }
// 
// # maze
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
// 3 4
// ####
// #..#
// .#.#

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: usize, b: usize, c: usize,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}

fn fib(n: usize) -> usize {
    if n == 0 { return 1; }
    match n {
        1|2 => n,
        _ => fib(n-1) + fib(n-2)
    }
}

fn main() {
    input! { h: usize, w: usize, k: usize }

    // dp[h][k]: the number that result in k-th line if amida have been traversed by h-th row
    let mut dp = [[0; 8+1]; 100+1];

    for i in 1..h+1 {
        for j in 1..w+1 {
            if i == 1 {
                if j == 1 || j == 2 { dp[i][j] = fib(w-j); }
            } else {
                // to straight
                if w >= j {
                    dp[i][j] += dp[i-1][j] * fib(j-1) * fib(w-j) % 1_000_000_007;
                }
                // to left
                if w-j >= 1 {
                    dp[i][j] += dp[i-1][j+1] * fib(j-1) * fib(w-j-1) % 1_000_000_007;
                }
                // to right
                if j >= 2 {
                    dp[i][j] += dp[i-1][j-1] * fib(j-2) * fib(w-j) % 1_000_000_007;
                }
            }
        }
    }
    println!("{}", dp[h][k] % 1_000_000_007);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#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 long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n, t, a;
    cin >> n >> t >> a;
    int x;
    int ans = 0;
    double m = 1e9;
    for (int i = 0; i < n; i++){
        cin >> x;
        double d = t - x * 0.006;
        if (abs(d-a) < m){
            m = abs(d-a);
            ans = i+1;
        }
    }
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 7;
const ll mod = 998244353;

map<int, int> mp;
int main() 
{
    ll ans = 0, n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        int x;
        cin >> x;
        if(mp.count(i - x) > 0)ans += mp[i - x];
        if(mp.count(x + i))
            mp[x + i] += 1;
        else{
            mp[x + i] = 1;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 12860
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int a, b, c;
	cin >> a >> b >> c;

	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}

	return 0;

}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n, k;
    cin>>n>>k;
    if(k==1){
        cout<<0<<endl;
        return  0;
    }else{
        cout<<n-k<<endl;
        return  0;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define D(a) cout<<#a<<": ";for(auto i:a)cout<<i<<' ';cout<<endl;
using namespace std;
vector<vector<int>> graph, dist;
vector<int> level;
void recur(int i, int lv)
{
    level[i] = lv;
    for (int n : graph[i]) if (level[n] == -1) recur(n, lv+1);
}
long long f(int i, int j)
{
    level = vector<int>(graph.size(), -1);
    level[i] = 0;
    if (j != -1) level[j] = 0;
    recur(i, 0);
    if (j != -1) recur(j, 0);
    vector<int> multipler(*max_element(level.begin(), level.end()) + 1);
    for (int a = 0; a < graph.size(); a++) {
        int cnt = 0;
        for (int n : graph[a]) if (level[n] == level[a] + 1) cnt++;
        multipler[level[a]] = max(multipler[level[a]], cnt);
    }
    long long ans = j == -1 ? 1 : 2;
    for (int m : multipler) ans *= max(1, m);
    return ans;
}
int main()
{
    int N; cin >> N;
    graph.resize(N);
    dist.resize(N, vector<int>(N, N));
    for (int i = 0; i < N; i++) dist[i][i] = 0;
    for (int i = 0; i < N - 1; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        dist[a][b] = dist[b][a] = 1;
    }
    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    int a, b;
    for (int i = 0, M = 0; i < N; i++)
        if (M < dist[0][i])
            M = dist[0][i], a = i;
    for (int i = 0, M = 0; i < N; i++)
        if (M < dist[a][i])
            M = dist[a][i], b = i;
    int d = dist[a][b];
    vector<int> A;
    A.push_back(a);
    for (int i = 1, t = a; i <= d; i++) {
        for (int u : graph[t]) {
            if (dist[a][u] == i && dist[u][b] == d - i) {
                A.push_back(u);
                t = u;
                break;
            }
        }
    }
    if (d % 2 == 1) {
        long long a = f(A[d / 2], A[d / 2 + 1]);
        cout << d / 2 + 1 << ' ' << a << endl;
    } else {
        long long a = f(A[d / 2], -1);
        for (int u : graph[A[d / 2]]) {
            a = min(a, f(A[d / 2], u));
        }
        cout << d / 2 + 1 << ' ' << a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
int a[5];
void solve(){
	int n,m;
	cin>>n>>m;
	memset(a,-1,sizeof a);
	int sum=0;
	while(m--){
		int s,c;
		cin>>s>>c;
		if(a[s]==-1 || a[s]==c){
			sum+=c;
			a[s]=c;
		} else{
			cout<<-1<<endl;
			return;
		}
	}
	if(n>1 && a[1]==0){
		cout<<-1<<endl;
		return;
	}
	for(int i=1;i<=n;i++){
		if(i==1 && a[i]==-1 && n>1){
			cout<<1;
			continue;
		}
		if(a[i]==-1)
			cout<<0;
		else
			cout<<a[i];
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  while(1) {
    int ans = 0;
    ;
    string num;
    cin >> num;
    if(num == "0")
      break;
    for(int i = 0; i < num.size(); i++)
      ans += num[i] - '0';
    cout << ans << endl;
  }

  return 0;
}



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

using namespace std;

const int INF = 1e9 + 7;

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  vector<int> h(N);
  for(int &x: h){
    scanf("%d", &x);
  }
  vector<int> dp(N, INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    for ( int j = 1; j <= K; j++) {
      if (i + j < N) {
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i + j]));
      }
    }
  }
  printf("%d\n", dp[N-1]);
  return 0;
}


Measured memory_bytes: 4020
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,p; cin >> n;
    int a[9]={0};
    for (int i=0; i<n; i++){
        cin >> p;
        if (p<3200) a[p/400]=1;
        else a[8]++;
    }
    int ans1=0,ans2=0;
    for (int i=0; i<8; i++) ans1+=a[i];
    ans2=ans1+a[8];
    cout << max(ans1,1) << " " << ans2 << endl;
}

Measured memory_bytes: 256
n = int(input())
 
def dfs(s):

    if int(s) > n:
        return 0
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
  
print(dfs('0'))

Measured memory_bytes: 3060
N, M = map(int, input().split())
li = [[int(i) for i in input().split()] for _ in range(N)]
mn = 0
dr = 0

li.sort()
for l in li:
    if M - dr > l[1]:
        dr += l[1]
        mn += l[0] * l[1]
    else:
        mn += l[0] * (M - dr)
        break

print(mn)


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

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

  if (count(S.begin(), S.end(), 'a') == 1 &&
      count(S.begin(), S.end(), 'b') == 1 &&
      count(S.begin(), S.end(), 'c') == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3568
#define onlycc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;

string s, t;
int ret = 987654321;

int main()
{
    onlycc;
    cin >> s >> t;
    for(int i = 0; i <= s.size()-t.size(); i++)
    {
        int cnt = 0;
        for(int j = i; j < t.size()+i; j++)
        {
            if(s[j] != t[j-i]) cnt++;
        }

        ret = min(ret, cnt);
    }

    cout << ret;

    return 0;
}


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

int n, q;
int a[50];
int m[200];

int search(int i, int tar){
  if( tar == 0) return 1;
  if( i >= n) return 0;
  int res = search(i + 1, tar) || search(i + 1, tar - a[i]);
  return res;
}

void solve(){

  for(int i = 0; i < q; i++){
    if(search(0, m[i])) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return ;
}


int main(){
  cin >> n;
  for(int i = 0; i<n; i++) cin >> a[i];
  cin >> q;
  for(int i = 0; i<q; i++) cin >> m[i];
  solve();
  return 0;
}

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

int main() {
	int n,i,j,k,a, b;
	cin >> n;
	vector<int> w(n);
	vector<int> dif(n);
	for (i = 0; i < n; i++) {
		cin >> w[i];
	}

	for (i = 0; i < n; i++) {
		a = 0;
		b = 0;
		for (j = 0; j <= i; j++) {
			a += w[j];
		}
		for (k = j; k < n; k++) {
			b += w[k];
		}
		dif[i] = abs(a - b);
	}
	sort(dif.begin(),dif.end());
	cout << dif[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int D;
vi c(26+1);
// D+1 * 26+1 vec
vector<vi> s;
// 1 ~ 26 のコンテストnumber
vi output;
// 1 ~ 26 のコンテストについて最後に開催した日
vector<vi> last_day;

void input(){
    cin >> D;
    rep(i,26) cin >> c[i+1];
    s.resize(D+1, vi(26+1));
    rep(i,D) rep(j,26) cin >> s[i+1][j+1];
    output.resize(D+1);
    last_day.resize(D+1, vi(26+1));
}

int last(int d, int i){
    // d日目より前にタイプiのコンテストを開催した日
    return last_day[d][i];
}

ll calScore(){
    ll ret = 0;
    vi b_ret(D+1);
    for(int i=1;i<=D;++i){
        b_ret[i] = b_ret[i-1] + s[i][output[i]];
        ret += s[i][output[i]];
        for(int j=1;j<=26;++j){
            b_ret[i] -= c[j] * (i - last(i, j));
            ret -= c[j] * (i - last(i, j));
        }
    }

    // B_ret
    //cerr << "B_ret\n";
    for(int i=1;i<=D;++i){
        cout << b_ret[i] << "\n";
    }
    return ret;
}

int main(){
    input();
    rep(i,D) cin >> output[i+1];
    for(int i=1;i<=26;++i){
        last_day[0][i] = 0;
    }
    for(int i=1;i<=D;++i){
        for(int j=1;j<=26;++j){
            if(output[i] == j) last_day[i][j] = i;
            else last_day[i][j] = last_day[i-1][j];
        }
    }

    calScore();
}

Measured memory_bytes: 3712
S=input()
N=len(S)
mod=pow(10,9)+7
#dp[N][4]
dp=[[0]*4 for i in range(N+1)]
dp[0][0]=1
for i in range(N):
    if S[i]=="A" or S[i]=='?':
        dp[i+1][0]+=dp[i][0]
        dp[i+1][1]+=dp[i][1]
        dp[i+1][2]+=dp[i][2]
        dp[i+1][3]+=dp[i][3]
        dp[i+1][1]+=dp[i][0]
    if S[i]=="B" or S[i]=='?':
        dp[i+1][0]+=dp[i][0]
        dp[i+1][1]+=dp[i][1]
        dp[i+1][2]+=dp[i][2]
        dp[i+1][3]+=dp[i][3]
        dp[i+1][2]+=dp[i][1]
    if S[i]=="C" or S[i]=='?':
        dp[i+1][0]+=dp[i][0]
        dp[i+1][1]+=dp[i][1]
        dp[i+1][2]+=dp[i][2]
        dp[i+1][3]+=dp[i][3]
        dp[i+1][3]+=dp[i][2]
    for j in range(4):
        dp[i+1][j]=(dp[i+1][j])%mod
print(dp[N][3])

Measured memory_bytes: 27616
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

H, W, N = getlist()
D = defaultdict(int)
D[0] += (H - 2) * (W - 2)
L = []
for i in range(N):
	a, b = getlist()
	for j in range(3):
		for k in range(3):
			if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:
				L.append((a - j, b - k))

L = sorted(L)
n = len(L)
if n != 0:
	v = L[0]
c = 0
for i in range(n):
	if v == L[i]:
		c += 1
	else:
		D[c] += 1
		c = 1
	v = L[i]

if n != 0:
	D[c] += 1
for i in range(1, 10):
	D[0] -= D[i]

for i in range(10):
	print(D[i])

Measured memory_bytes: 135976
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (100010)
int n,a[N];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int mid1,mid2;
	if (n%2) printf("0");
	else{
		mid1=n/2,mid2=n/2+1;
		printf("%d",a[mid2]-a[mid1]);
	}
}


Measured memory_bytes: 768
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD int(1e9+7)
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}

int main()
{
	fast
	int n;
	cin>>n;
	vector <vector <int> > arr(n,vector <int>(3,0)),dp(n,vector <int>(3,0));
	REP(i,n)
		REP(j,3)
			cin>>arr[i][j];
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	FOR(i,1,n)
	{
		dp[i][0] = arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 5;
vi adj[N];
int n, rob, pol;
int police[N], robbery[N];

void bfs(int start, int *dis) {
    queue<int> q;
    dis[start] = 0;
    q.push(start);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int nxt : adj[u]) {
            if (dis[nxt] == -1) {
                dis[nxt] = dis[u] + 1;
                q.push(nxt);
            }
        }
    }
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int a, b;
    cin >> n >> rob >> pol;
    for (int i = 1; i < n; i++) {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    memset(police, -1, sizeof police);
    memset(robbery, -1, sizeof robbery);
    bfs(rob, robbery);
    bfs(pol, police);

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (robbery[i] < police[i]) {
            ans = max(ans, police[i] - 1);
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6656