akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define add(a,b) (a+=b)%=998244353

int main() {
    ll N, S, ans = 0; cin >> N >> S;
    vl dp(3001, 0);
    rep(i,N) {
        ll a; scanf("%ld",&a);
        vl ndp(3001, 0);
        ndp[0] = ndp[a] = 1;
        rep(j,3001) {
            add(ndp[j], dp[j]);
            if (j+a > S) continue;
            add(ndp[j+a], dp[j]);
        }
        add(ans, ndp[S]);
        dp = ndp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
  char n;
  int alp[26] = {};
  while(cin >> n) {
    if(n <= 'z' && 'a' <= n) alp[n-'a']++;
    else if(n <= 'Z' && 'A' <= n) alp[n-'A']++;
  }

  for(int i = 0; i < 26; i++) {
    cout << char('a'+i) << " : " << alp[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int x, y, b, p;
        
    cin >> N;
    while (N--) {
        cin >> x >> y >> b >> p;

        if (b >= 5 && p >= 2) 
            cout << (b * x + p * y) * 0.8 << endl;
        else {
            int sum1 = (max(b, 5) * x + max(p, 2) * y) * 0.8;
            int sum2 = b * x + y * p;
            cout << min(sum1, sum2) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1240
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;
#define INF 100000005
#define MAX 1000005

int a[105];
int main(){
	int n, ans = 0, f = 1;
	cin >> n;
	for(int i = 0;i < n;i++)cin >> a[i];
	for(;f;){
		for(int i = 0;i < n;i++){
			if(a[i]%2 == 1){
				f = 0;
				break;
			}
			a[i] = a[i] / 2;
		}
		if(f)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(87);
  a[0] = 2;
  a[1] = 1;
  for(int i = 2;i <= 86;i++)a[i] = a[i - 1] + a[i - 2];
  cout << a[n] << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

#define MAX_W 10001
int N, W;
int v[100], w[100];
int dp[MAX_W];

void solve(){
    Rep(i, 0, MAX_W) dp[i] = 0;
    Rep(i, 0, N){
        Rep(j, 1, MAX_W){
            dp[j] = Max2(dp[j], dp[j - 1]);
            if(j >= w[i]) dp[j] = Max2(dp[j - w[i]] + v[i], dp[j]);
        }
    }
}

int main(){
    cin >> N >> W;
    Rep(i, 0, N) cin >> v[i] >> w[i];
    solve();
    Print(dp[W]);
    return 0;
}


Measured memory_bytes: 3148
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		int H = GetInt();
		int W = GetInt();

		StringBuilder sb = new StringBuilder();
		for(int i = 0; i <= W+1; i++)
			sb.Append("#");
		sb.Append("\n");
		for(int i = 0; i < H; i++)
		{
			sb.Append("#");
			sb.Append(GetString());
			sb.Append("#\n");
		}
		for(int i = 0; i <= W+1; i++)
			sb.Append("#");

		Console.WriteLine(sb);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11136
#!/usr/bin/env python3
import sys
from collections import deque
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(H, W, Ch, Cw, Dh, Dw, walkable):
    N = HEIGHT * WIDTH
    visited = [0] * N

    start = (Ch + 1) * WIDTH + (Cw + 1)
    goal = (Dh + 1) * WIDTH + (Dw + 1)
    toVisit = []
    toVisit.append(start)

    currentDistance = 0
    while True:
        nextJumpOrigin = []
        while toVisit:
            p = toVisit.pop()
            if p == goal:
                return currentDistance
            if visited[p]:
                continue

            visited[p] = 1
            nextJumpOrigin.append(p)
            for d in [-1, +1, -WIDTH, +WIDTH]:
                if walkable[p + d] and not visited[p + d]:
                    toVisit.append(p + d)

        # no continuous cell
        nextJump = set()
        for origin in nextJumpOrigin:
            for dx in [-2, -1, 0, +1, +2]:
                for dy in [-WIDTH * 2, -WIDTH, 0, WIDTH, WIDTH * 2]:
                    p = origin + dx + dy
                    if not walkable[p]:
                        continue
                    if visited[p]:
                        continue
                    if p in nextJump:
                        continue
                    nextJump.add(p)
        for p in nextJump:
            toVisit.append(p)

        currentDistance += 1
        if not toVisit:
            return -1


def readMap(H, W):
    global SENTINEL, HEIGHT, WIDTH
    SENTINEL = 2
    HEIGHT = H + SENTINEL * 2
    WIDTH = W + SENTINEL * 2
    data = [0] * (HEIGHT * WIDTH)
    ok = ord(".")
    for i in range(H):
        S = input().strip()
        y = (i + SENTINEL) * WIDTH
        for j in range(W):
            data[y + (j + SENTINEL)] = 1 if S[j] == ok else 0
    return data


def main():
    # parse input
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    D = readMap(H, W)
    print(solve(H, W, Ch, Cw, Dh, Dw, D))


# tests
T1 = """
4 4
1 1
4 4
..#.
..#.
.#..
.#..
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
1
"""

T2 = """
4 4
1 4
4 1
.##.
####
####
.##.
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
-1
"""

T3 = """
4 4
2 2
3 3
....
....
....
....
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
0
"""

T4 = """
4 5
1 2
2 5
#.###
####.
#..##
#..##
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
2
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 92176
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>

using namespace std;
typedef long long ll;

const int MAXN = 100100;
int T[MAXN], A[MAXN];
int N;

bool check[MAXN];
int upper[MAXN];

bool check2[MAXN];
int upper2[MAXN];
const int MOD = 1e9+7;

ll solve() {
	upper[0] = T[0];
	check[0] = true;
	for (int i = 1; i < N; i++) {
		upper[i] = upper[i-1];
		if (T[i] > T[i-1]) {
			check[i] = true;
			upper[i] = T[i];
		}
	}
	upper2[N-1] = A[N-1];
	check2[N-1] = A[N-1];
	for (int i = N-2; i >= 0; --i) {
		upper2[i] = upper2[i+1];
		if (A[i] > A[i+1]) {
			check2[i] = true;
			upper2[i] = A[i];
		}
	}
	for (int i = 0; i < N; i++) {
		if (check[i] && check2[i] && upper[i] != upper2[i]) return 0;
		if (check[i] && upper[i] > upper2[i]) return 0;
		if (check2[i] && upper2[i] > upper[i]) return 0;
	}
	ll ans = 1;
	for (int i = 0; i < N; i++) {
		if (!(check[i] || check2[i])) (ans *= min(upper[i], upper2[i])) %= MOD;
	}
	return ans;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> T[i];
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N<112)
    cout << 111 << endl;
  else if(N<223)
    cout << 222 << endl;
  else if(N<334)
    cout << 333 << endl;
  else if(N<445)
    cout << 444 << endl;
  else if(N<556)
    cout << 555 << endl;
  else if(N<667)
    cout << 666 << endl;
  else if(N<778)
    cout << 777 << endl;
  else if(N<889)
    cout << 888 << endl;
  else
    cout << 999 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		sc.close();

		if(a<1200){
			System.out.print("ABC");
		}else{
			System.out.print("ARC");
		}
	}
}

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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main() {
  int n, m, l;
  cin >> n >> m >> l;

  vector<vector<int>> vec_a(n, vector<int>(m));
  vector<vector<int>> vec_b(m, vector<int>(l));

  rep(i, n) {
    rep(j, m) { cin >> vec_a[i][j]; }
  }
  rep(i, m) {
    rep(j, l) { cin >> vec_b[i][j]; }
  }

  vector<vector<int64_t>> vec_c(n, vector<int64_t>(l));

  rep(i, n) {
    rep(j, l) {
      rep(k, m) { vec_c[i][j] += vec_a[i][k] * vec_b[k][j]; }
    }
  }

  rep(i, n) {
    rep(j, l) {
      if (j) {
        printf(" ");
      }
      printf("%ld", vec_c[i][j]);
    }
    printf("\n");
  }
}



Measured memory_bytes: 3324
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
dp = [10**12]*(1+10**5)
dp[0] = 0
for i in range(N):
    w,v = WV[i]
    for j in range(len(dp)-1, 0, -1):
        if j-v<=0:
            tmp = w
        else:
            tmp = dp[j-v] + w
        dp[j] = min(dp[j], tmp)
ans = 0
for v,w in enumerate(dp):
    if w<=W:
        ans = max(ans, v)
    else:
        break
print(ans)

Measured memory_bytes: 42476
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int h;
int a[11][5];
int d[11][5];

int main(){
	while(1){
		cin>>h;
		if(h==0)break;
		REP(i,11)
			REP(j,5)
			a[i][j]=-1;
		for(int i=h-1;i>=0;i--){
			for(int j=0;j<5;j++){
				cin>>a[i][j];
			}
		}
		int ans=0;
		int flag=1;
		for(int qq=0;qq<200;qq++){
			
			for(int i=0;i<h;i++){
				if(a[i][0]!=-1&&a[i][0]==a[i][1]&&a[i][1]==a[i][2]&&a[i][2]==a[i][3]&&a[i][3]==a[i][4]){
					ans+=a[i][0]*5;
					for(int j=0;j<5;j++)
						a[i][j]=-1;
				}else if(a[i][0]!=-1&&a[i][0]==a[i][1]&&a[i][1]==a[i][2]&&a[i][2]==a[i][3]){
					ans+=a[i][0]*4;
					for(int j=0;j<4;j++)
						a[i][j]=-1;
				}else if(a[i][1]!=-1&&a[i][1]==a[i][2]&&a[i][2]==a[i][3]&&a[i][3]==a[i][4]){
					ans+=a[i][1]*4;
					for(int j=1;j<5;j++)
						a[i][j]=-1;
				}else if(a[i][0]!=-1&&a[i][0]==a[i][1]&&a[i][1]==a[i][2]){
					ans+=a[i][0]*3;
					for(int j=0;j<3;j++)
						a[i][j]=-1;
				}else if(a[i][1]!=-1&&a[i][1]==a[i][2]&&a[i][2]==a[i][3]){
					ans+=a[i][1]*3;
					for(int j=1;j<4;j++)
						a[i][j]=-1;
				}else if(a[i][2]!=-1&&a[i][2]==a[i][3]&&a[i][3]==a[i][4]){
					ans+=a[i][2]*3;
					for(int j=2;j<5;j++)
						a[i][j]=-1;
				}
			}
			
			for(int i=0;i<h;i++){
				for(int j=0;j<h-1;j++){
					for(int k=0;k<5;k++){
						if(a[j][k]==-1){
							swap(a[j][k],a[j+1][k]);
						}
					}
				}
			}
			
			/*if(qq==0){
				cout<<endl;
				for(int i=h-1;i>=0;i--){
					for(int j=0;j<5;j++){
						cout<<a[i][j]<<" ";
					}
					cout<<endl;
				}
			}*/
			
			
		}
		cout<<ans<<endl;
	}
	return 0;
}
			


Measured memory_bytes: 3008
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int n;
    scanf("%d", &n);
    int map[n][3];
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            scanf("%d", &map[i][j]);
        }
    }

    int now[2];
    now[0]=now[1]=0;

    int ans = 1;

    for(int i=0; i<n; i++){
        int cost = abs(now[0]-map[i][1])+abs(now[0]-map[i][2]);

        if(cost > map[i][0]){
            ans = 0;
            break;
        }

        if((map[i][0]-cost)%2!=0){
            ans = 0;
            break;
        }

        now[0] = map[i][1];
        now[1] = map[i][2];
    }

    if(ans){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::vector<int> ac(n+1,0);
	rep(i,n) ac[i+1] = ac[i] + a[i];
	debug(ac);
	int sum = ac[n];
	int min = sum;
	rep(i,n) { min = std::min(min, std::abs(sum- 2*ac[i+1])); }
	print(min);

	return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        String beforechar = "";
        int count = 0;

        for(int i = 0; i < S.length(); i++){
            if(i==0){
                beforechar = S.substring(i,i+1);
            }else{
                if(S.substring(i,i+1).equals(beforechar)){
                   count ++;
                   if(beforechar.equals("0")){
                        beforechar = "1";
                   }else{
                       beforechar = "0";
                   }
                }else{
                    beforechar = S.substring(i,i+1);
                }
            }
        }

        System.out.println(count);

    }
}

Measured memory_bytes: 39632
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	String S, T;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		S = tokens[0];
		T = tokens[1];
	}

	void calc() {
	}

	void showResult() {
		System.out.println(T + S);
	}
}


Measured memory_bytes: 20948
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;
const double pi = acos(-1.0);
int main()
{
	int n,m;
	int x,s=0;
	cin>>n>>m;
	while(m--)
	{
		cin>>x;
		s+=x;
	}
	s=n-s;
	if(s<0)s=-1;
	cout<<s;
	return 0;
}

Measured memory_bytes: 3624
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main() {
	int a, b, k;
	cin >> a >> b >> k;

	if ((b - a) / 2 >= k) {
		REP(i, k) {
			cout << a + i << endl;
		}
		REP(i, k) {
			cout << b -k+ i+1 << endl;
		}
	}
	else {
		REP(i, b - a + 1) {
			cout << a + i << endl;
		}
	}
	
	
	

	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=(int)2e5+5;
char str[MAXN];
int mark[MAXN],dp[(1<<26)+10];
int main()
{
	int n;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=(1<<26);i++)dp[i]=(int)1e9;
	for(int i=1;i<=n;i++){
		mark[i]=(mark[i-1]^(1<<(str[i]-'a')));
		for(int j=0;j<26;j++){
			dp[mark[i]]=min(dp[mark[i]^(1<<j)]+1,dp[mark[i]]);
		}
	}
	dp[0]=1;
	printf("%d\n",dp[mark[n]]);
	return 0;
}

Measured memory_bytes: 263424
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
ans=[]
i=0
rest=a[i]
for j in range(h):
    ans_j=[]
    for k in range(w):
        if(rest==0):
            i+=1
            rest=a[i]

        if(j%2==0):
            ans_j.append(i+1)
            rest-=1
        else:
            ans_j.insert(0, i+1)
            rest-=1
    ans.append(ans_j)

for i in range(len(ans)):
    for j in range(len(ans[i])):
        print(ans[i][j],end=" ")
    print()

Measured memory_bytes: 3920
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int, input().split())
UF = UnionFind(N)
      
for _ in range(M):
  a,b = map(int, input().split())
  UF.union(a-1,b-1)

answer = 0
for x in UF.roots():
  answer = max(answer, UF.size(x))

print(answer)

Measured memory_bytes: 18608
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, k = MAP()
ans = 0
for i in range(k, n + 2):
    ans += n * (n + 1) // 2 - (n - i) * (n - i + 1) // 2 - (i - 1) * i // 2 + 1
    ans %= mod
print(ans)

Measured memory_bytes: 74752
def main():
  import sys
  b=sys.stdin.buffer
  h,w=map(int,b.readline().split())
  x=w+1
  s=[5-c//8for c in b.read()]
  dp=[10000]*h*x
  dp[0]=a=b=p=q=s[0]
  for i in range(w):
    t=s[i]
    b+=a^t
    dp[i]=b
    a=t
  for i in range(x,h*x,x):
    t=s[i]
    q+=p^t
    dp[i]=b=q
    a=p=t
    for j in range(i+1,i+w):
      sj=s[j]
      b+=a^sj
      k=j-x
      t=dp[k]+(s[k]^sj)
      if b>t:b=t
      dp[j]=b
      a=sj
  print(b+1>>1)
main()

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    for (int i = 0; i <= n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll val = b[i];
        ll hoge = min(val, a[i]);
        ans += hoge;
        val -= hoge;

        ll foo = min(val, a[i + 1]);
        ans += foo;
        a[i + 1] -= foo;
        val -= foo;
    }

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

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl;
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

int main()
{
    int n;
    cin >> n;
    V a(n);
    int cnt = 0, mi = 100001;
    bool zero = false;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] < 0)
        {
            cnt++;
        }
        if (a[i] == 0)
        {
            zero = true;
        }
        mi = min(mi, abs(a[i]));
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += abs(a[i]);
    }
    if (!zero && cnt % 2 != 0)
    {
        ans -= mi*2;
    }
    OUT(ans);
}

Measured memory_bytes: 640
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (b - a == c - b) {
    print("YES");
  } else {
    print("NO");
  }
}


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

int main() {
	ll n;
	cin>>n;
	for(int i=1;i<10;i++)for(int j=i;j<10;j++){
		if(i*j==n){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


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

int main() {
  int n, x, t;
  int count=0;
  
  cin >> n >> x >> t;
  
  count = n/x * t;
  n%=x;
  
  if(n>0)
    count+=t;
  
  cout << count << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;

long long arr[82];

long long max(long long a, long long b) {
    if(a > b) return a;
    return b;
}

int main() {
    int n;
    cin >> n;
    long long sum = 1000, buy = 0;
    for(int i = 1;i <= n;i ++) scanf("%lld", &arr[i]);
    arr[0] = 10000; arr[n+1] = 0;
    for(int i = 1;i <= n;i ++) {
        if(arr[i] <= arr[i-1] && arr[i] < arr[i+1]) {
            buy += sum / arr[i];
            sum -= (sum/arr[i]) * arr[i];
        }
        else if(arr[i] >= arr[i-1] && arr[i] > arr[i+1]) {
            sum += buy * arr[i];
            buy = 0;
        }
    }
//    for(int i = 1;i <= n;i )
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3736
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) int {
	S := sc.s()
	T := sc.s()

	ans := 0
	for i := 0; i < len(S); i++ {
		if S[i] != T[i] {
			ans++
		}
	}

	fmt.Println(ans)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 2712
<?php

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    sort($a);
    
    $x = $a[0];
    $ansi = 0;
    for($i=1;$i<$n;$i++){
        if($a[$i] > $x*2){
           $ansi = $i;
        }
        $x += $a[$i];
    }
    echo $n - $ansi;
 
?>

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

const int N = 5000000;
bool prime[N];
int main() {
    for (int i=0; i<N; ++i) prime[i] = 1;
    prime[0] = prime[1] = 0;
    for (int i=2; i<N; ++i) {
        if (prime[i])
            for (int j=i*2; j<N; j+=i)
                prime[j] = 0;
    }
    vector<int> v;
    for (int i=0; i<N; ++i) if (prime[i]) v.push_back(i);
    
    int n, p;
    while(cin>>n>>p, n!=-1) {
        int a = upper_bound(v.begin(), v.end(), n) - v.begin();
        vector<int> ans;
        for (int i=a; i<a+100; ++i) {
            for (int j=a; j<=i; ++j) {
                ans.push_back(v[i]+v[j]);
            }
        }
        sort(ans.begin(), ans.end());
        //for (int i=0; i<100; ++i) cout << ans[i] << " ";cout <<endl;
        cout << ans[p-1] << endl;
    }
}

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

int main(){
	string s1, s2, s3; cin >> s1 >> s2 >> s3;
	cout << s1[0] << s2[1] << s3[2] << endl;
	return 0;
}

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

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r){
  if(l>=r)return;
  int root=pre[pos];
  pos++;
  int m=distance(in.begin(),find(in.begin(),in.end(),root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}

void slove(){
  pos=0;
  rec(0,pre.size());
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<post[i];
  }
  cout<<endl;
}

int main(){
  int k;

  cin>>n;
  
  for(int i=0;i<n;i++){
    cin>>k;
    pre.push_back(k);
  }

  for(int i=0;i<n;i++){
    cin>>k;
    in.push_back(k);
  }

  slove();

  return 0;
}
 

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

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

main() {
    int W,a,b; cin >> W >> a >> b;
    if(a==b||a<b && b<a+W || a>b && a<b+W) cout << 0 << endl;
    else if(a<b){cout << abs(b-a-W) << endl;}
    else cout << abs(a-b-W) << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
c=0
for i in range(n):
    if A[i]>=3200:
        c+=1
        A[i]=8
    else:
        A[i]//=400
m=len(set(A))
if c:
    if m==1:
        print(1,c)
    else:
        print(m-1,m-1+c)
else:
    print(m,m)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> a;
    vector<long long> b;
    for(int i = 1; i <= n; i++){
        long long t;
        cin >> t;
        a.push_back(t);
        b.push_back(t - i);
    }
    sort(b.begin(), b.end());
    long long snuke;
    if(n % 2 == 0){
        snuke = (b[n/2-1]+b[n/2])/2;
    } else {
        snuke = b[n/2];
    }
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        ans += abs(a[i-1] - (snuke+i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int,P> P3;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, w, h, px, py, ans=0;
    cin >> w >> h >> n;
    cin >> px >> py;
    REP(i,n-1){
        int x, y;
        cin >> x >> y;
        if(x>px == y>py){
            ans += max(abs(x-px),abs(y-py));
        }
        else{
            ans += abs(x-px)+abs(y-py);
        }
        px = x;
        py = y;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t N;
    cin >> N;
    long long sum = 1LL;
    for (int i=1; i <= N; i++) {
        sum = sum *i;
        sum = sum % int(pow(10, 9.0) + 7);
    }

    cout << sum << endl;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long x, long long y){
  set<long long> st1({1, 3, 5, 7, 8, 10, 12});
  set<long long> st2({4, 6, 9, 11});
  set<long long> st3({2});

  if(st1.count(x) > 0 && st1.count(y) > 0) cout << YES << endl;
  else if(st2.count(x) > 0 && st2.count(y) > 0) cout << YES << endl;
  else if(st3.count(x) > 0 && st3.count(y) > 0) cout << YES << endl;
  else cout << NO << endl;
}

// 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)
int main(){
    long long x;
  scanf("%lld",&x);
  long long y;
  scanf("%lld",&y);
    solve(x, y);
    return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    int ans = 0;

    if (y < x && x != 0 || x < 0 && y > 0) {
        ans++;
        x = -x;
    }
    ans += abs(abs(y) - abs(x));
    x += abs(abs(y) - abs(x));
    if (x == -y && x != 0) ans++;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
 
using namespace std;
 
int s[10]={0};
 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0,b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}



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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll A, B, C, K;

int main() {
    cin >> A >> B >> C >> K;
    if(K % 2) {
        cout << B - A << "\n";
    } else {
        cout << A - B << "\n";
    }
    return 0;
}

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

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

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

int A[3][3], N, b[101];

int main() {
    REP (i, 3) {
        REP (j, 3) {
            cin >> A[i][j];
        }
    }
    cin >> N;
    REP (i, N) {
        cin >> b[i];
    }
    REP (i, N) {
        REP (j, 3) {
            REP (k, 3) {
                if (A[j][k] == b[i]) {
                    A[j][k] = 0;
                }
            }
        }
    }
    REP (i, 3) {
        if (A[i][0] + A[i][1] + A[i][2] == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    REP (i, 3) {
        if (A[0][i] + A[1][i] + A[2][i] == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (A[0][0] + A[1][1] + A[2][2] == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    if (A[0][2] + A[1][1] + A[2][0] == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

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

    //クリアできる?
    // vector<int> allAb(m, 0);
    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < m; j++){
    //         allAb[j] += a[i][j];
    //     }
    // }
    // for(auto ab : allAb){
    //     if(ab < x){
    //         cout << -1 << endl;
    //         return 0;
    //     }
    // }

    //総当り
    int ref = accumulate(c.begin(), c.end(), 0) + 1;
    int ans = ref;
    for(int i = 0; i < (1 << n); i++){
        bitset<12> s(i);
        vector<int> abilities(m, 0);
        int tmp = 0;
        for(int j = 0; j < n; j++){
            if(s.test(j)){
                tmp += c[j];
                for(int k = 0; k < m; k++){
                    abilities[k] += a[j][k];
                }
            }
        }
        bool ok = true;
        for(auto ab : abilities){
            if(ab < x){
                ok = false;
            }
        }
        if(ok){
            ans = min(ans, tmp);
        }
    }

    if(ans == ref){
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int wareru = 0;
  int ans =0;
  for(int k=1;k<=n;++k){
    for(int i=1;i<=k;++i){
      if(k%i==0) ++wareru;
    }
    if(wareru==8 && k%2) ++ans;
    wareru = 0;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=29;
const ll INF=1LL<<63;
int x,y,z;

ll expr0(string S,int &i);
ll expr1(string S,int &i);
ll expr2(string S,int &i);
ll factor(string S,int &i);
ll number(string S,int &i);

ll expr0(string S,int &i){
    ll res=0;
    
    res=expr1(S,i);
    
    while(i<S.size()){
        if(S[i]=='+'&&x==0){
            i++;
            res+=expr1(S,i);
        }else if(S[i]=='-'&&y==0){
            i++;
            res-=expr1(S,i);
        }else if(S[i]=='*'&&z==0){
            i++;
            res*=expr1(S,i);
        }else break;
    }
    
    return res;
}

ll expr1(string S,int &i){
    ll res=0;
    
    res=expr2(S,i);
    
    while(i<S.size()){
        if(S[i]=='+'&&x==1){
            i++;
            res+=expr2(S,i);
        }else if(S[i]=='-'&&y==1){
            i++;
            res-=expr2(S,i);
        }else if(S[i]=='*'&&z==1){
            i++;
            res*=expr2(S,i);
        }else break;
    }
    
    return res;
}

ll expr2(string S,int &i){
    ll res=0;
    
    res=factor(S,i);
    
    while(i<S.size()){
        if(S[i]=='+'&&x==2){
            i++;
            res+=factor(S,i);
        }else if(S[i]=='-'&&y==2){
            i++;
            res-=factor(S,i);
        }else if(S[i]=='*'&&z==2){
            i++;
            res*=factor(S,i);
        }else break;
    }
    
    return res;
}

ll factor(string S,int &i){
    ll res=0;
    if(S[i]=='('){
        i++;
        res=expr0(S,i);
        i++;
    }else{
        res=number(S,i);
    }
    
    return res;
}

ll number(string S,int &i){
    ll res=0;
    while('0'<=S[i]&&S[i]<='9'){
        res*=10;
        res+=S[i]-'0';
        i++;
    }
    return res;
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    ll ans=-LLONG_MAX;
    
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                x=i;
                y=j;
                z=k;
                
                int w=0;
                ans=max(ans,expr0(S,w));
            }
        }
    }
    
    cout<<ans<<endl;
}




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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL H,W;
  cin >> H >> W;
  vector<string> S(H);
  REP(i,H){
    cin >> S[i];
  }

  vector<vector<vector<LL>>> V(H, vector<vector<LL>>(W, vector<LL>(4, 0)));

  {
    LL idx = 0;
    REP(i, H)
    {
    LL cnt = 0;
      REP(j,W){
        LL x = i;
        LL y = j;
        if(S[x][y]=='#'){
          cnt = 0;
        }else{
          cnt++;
          V[x][y][idx] = cnt;
        }
      }
    }
  }
  {
    LL idx = 1;
    REP(i, H)
    {
    LL cnt = 0;
      REP(j,W){
        LL x = i;
        LL y = W-j-1;
        if(S[x][y]=='#'){
          cnt = 0;
        }else{
          cnt++;
          V[x][y][idx] = cnt;
        }
      }
    }
  }

  {
    LL idx = 2;
    REP(j,W){
    LL cnt = 0;
      REP(i, H)
      {
        LL x = i;
        LL y = j;
        if(S[x][y]=='#'){
          cnt = 0;
        }else{
          cnt++;
          V[x][y][idx] = cnt;
        }
      }
    }
  }
  {
    LL idx = 3;
    REP(j,W){
    LL cnt = 0;
      REP(i, H)
      {
        LL x = H-i-1;
        LL y = j;
        if(S[x][y]=='#'){
          cnt = 0;
        }else{
          cnt++;
          V[x][y][idx] = cnt;
        }
      }
    }
  }

  LL max = 0;

  REP(i, H)
  {
    REP(j,W){
      LL cnt = -3;
      REP(k, 4)
      {
        cnt += V[i][j][k];
      }
      if(cnt>max){
        max = cnt;
      }
    }
  }

  cout << max << endl;
}


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

using namespace std;
const int nax=2e5+5;
vector<int> grafo[nax];
queue<int> q;
int n,m;
bitset<nax> v;
int bfs(int k){
  int cont=0;
  q.push(k);
  while(!q.empty()){
    int co=q.front();
    q.pop();
    if(v[co])continue;
    cont++;
    v[co]=1;
    for(int x:grafo[co])q.push(x);
  }
  return cont;
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    grafo[a].push_back(b);
    grafo[b].push_back(a);
  }
  int mas=1;
  for(int i=1;i<=n;i++)
    if(!v[i])
      mas=max(mas,bfs(i));
  cout<<mas<<endl;

}


Measured memory_bytes: 15056
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

typedef vector<double> vec;
typedef vector<vec> mat;

#define EPS (1e-9)
bool EQ(double a,double b){
  return abs(a-b)<EPS;
}

struct Rec{
  int w,h;
  int age;
  bool operator==(const Rec r)const{
    return r.w==w&&r.h==h&&r.age==age;
  }
};

int N,W,D;
int P[101];
int S[101];
vector<Rec> recs;
int NumToRec[110];
bool used[110];

int main(){
  while(cin>>N>>W>>D&&(N|W|D)){
    recs.clear();
    Rec init;
    init.w=W;
    init.h=D;
    init.age=0;
    recs.push_back(init);
    NumToRec[1]=0;
    for(int i=0;i<N;i++)cin>>P[i]>>S[i];
    for(int i=0;i<N;i++){
      // 今回対象となるrec
      Rec r=recs[NumToRec[P[i]]];
      // 選んだやつをリストから削除
      for(int j=0;j<recs.size();j++){
	if(recs[j]==r){
	  recs.erase(recs.begin()+j);
	  break;
	}
      }
      // 縦分割
      S[i]%=(r.w+r.h);
      if((S[i]>=0&&S[i]<=r.w)||(S[i]>=r.w+r.h&&S[i]<=2*r.w+r.h)){
	int nw=S[i];
	if(S[i]>=r.w+r.h)nw=S[i]-r.w-r.h;
	Rec r1,r2;
	r1.age=r2.age=i+1;
	r1.w=nw;r1.h=r.h;
	r2.w=r.w-nw;r2.h=r.h;
	//if(r1.w<0||r2.w<0)cout<<i<<endl;
	recs.push_back(r1);
	recs.push_back(r2);
      }
      else{
	int nh=S[i];
	if(S[i]>=2*r.w+r.h)nh=S[i]-2*r.w-r.h;
	else nh=S[i]-r.w;
	Rec r1,r2;
	r1.age=r2.age=i+1;
	r1.w=r.w;r1.h=nh;
	r2.w=r.w;r2.h=r.h-nh;
	//if(r1.h<0||r2.h<0)cout<<i<<endl;
	recs.push_back(r1);
	recs.push_back(r2);
      }
      memset(NumToRec,-1,sizeof(NumToRec));
      memset(used,0,sizeof(used));
      // 番号を新たに振りなおす
      for(int k=1;k<=recs.size();k++){
	// 一番古いものを探索
	vector<int> oldest;
	int num=1000000;
	for(int j=0;j<recs.size();j++){
	  if(used[j])continue;
	  if(recs[j].age<num){
	    oldest.clear();
	    num=recs[j].age;
	    oldest.push_back(j);
	  }
	  else if(recs[j].age==num)
	    oldest.push_back(j);
	}
	int cand=oldest[0];
	for(int j=1;j<oldest.size();j++){
	  int candS=recs[cand].w*recs[cand].h;
	  int curS=recs[oldest[j]].w*recs[oldest[j]].h;
	  if(curS<candS)cand=oldest[j];
	}
	used[cand]=true;
	NumToRec[k]=cand;
      }
    }
    vector<int> res;
    for(int i=0;i<recs.size();i++)
      res.push_back(recs[i].w*recs[i].h);
    sort(res.begin(),res.end());
    for(int i=0;i<res.size();i++){
      cout<<res[i];
      if(i!=res.size()-1)cout<<" ";
      else cout<<endl;
    }
  }
  

  return 0;
}

Measured memory_bytes: 908