akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ETree solver = new ETree();
        solver.solve(1, in, out);
        out.close();
    }

    static class ETree {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String s = in.string();
            if (s.charAt(0) == '0' || !new StringBuilder("0" + s).reverse().toString().equals("0" + s)) {
                out.println(-1);
                return;
            }
            int anc = s.length();
            for (int i = s.length() - 1; i > 0; i--) {
                out.print(i);
                out.print(' ');
                out.println(anc);
                if (s.charAt(i - 1) == '1') {
                    anc = i;
                }
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else{
    if(z->key<y->key)y->left=z;
    else y->right=z;
  }
}






void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);

}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

int main() {
	vector<vector<int>> A(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}

	int N;
	cin >> N;

	vector<int> b(N);
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}

	vector<vector<int>> A_ok(3, vector<int>(3, 0));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < N; k++) {
				if (A[i][j] == b[k]) {
					A_ok[i][j] = 1;
					break;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++) {
		if (A_ok[i][0] && A_ok[i][1] && A_ok[i][2]) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	for (int j = 0; j < 3; j++) {
		if (A_ok[0][j] && A_ok[1][j] && A_ok[2][j]) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (A_ok[0][0] && A_ok[1][1] && A_ok[2][2]) {
		cout << "Yes" << endl;
		return 0;
	}

  if (A_ok[0][2] && A_ok[1][1] && A_ok[2][0]) {
    cout << "Yes" << endl;
    return 0;
  }

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int nibun(int x, int y) { return x <= y; }
int answer1(vector<int> a, int b, int c) {
  if (b < 0) {
    return c;
  } else if (a[b] != c) {
    return c;
  } else {
    b--;
    c--;
    return answer1(a, b, c);
  }
}
int answer2(vector<int> a, int b, int c) {
  if (b == (int)a.size()) {
    return c;
  } else if (a[b] != c) {
    return c;
  } else {
    b++;
    c++;
    return answer2(a, b, c);
  }
}
int main() {
  int x, n, ok, ng, mid, t, ans1, ans2, ans;
  vector<int> a;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    a.push_back(t);
  }
  sort(a.begin(), a.end());
  ok = -1;
  ng = (int)a.size();
  while (ng - ok > 1) {
    mid = ok + ng;
    if (nibun(a[mid], x)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  ans1 = answer1(a, ok, x);
  if (ans1 == x) {
    cout << ans1 << endl;
    return 0;
  }
  ans2 = answer2(a, ok, x);
  if ((x - ans1) < (ans2 - x) || (x - ans1) == (ans2 - x)) {
    cout << ans1 << endl;
  } else {
    cout << ans2 << endl;
  }
}


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

int N, A, B, used[100], rings[100]; vector<int> G[100];
 
int rec(int pos)
{
    used[pos] = true; int ret = 1;
     
    for(int i = 0; i < rings[pos]; i++)
    {
        if(!used[G[pos][i]])
        {
            ret = max(ret, rec(G[pos][i]) + 1);
        }
    }
     
    used[pos] = false;
     
    return ret;
}
 
int main()
{
    int N, A, B;
     
    while(true)
    {
        scanf("%d", &N);
         
        if(N == 0) { break; }
 
        for(int i = 0; i < 100; i++)
        {
            used[i] = false;
            rings[i] = 0;
            G[i].clear();
        }
     
        for(int i = 0; i < N; i++)
        {
            scanf("%d", &A); A--;
            scanf("%d", &B); B--;
         
            G[A].push_back(B);
            G[B].push_back(A);
        }
         
        for(int i = 0; i < 100; i++)
        {
            rings[i] = G[i].size();
        }
         
        int nodes = 0;
         
        for(int i = 0; i < 100; i++)
        {
            if(rings[i])
            {
                nodes++;
            }
        }
     
        int ret = 0;
     
        for(int i = 0; i < 100; i++)
        {
            ret = max(ret, rec(i));
                 
            if(ret == nodes) { break; }
        }
         
        printf("%d\n", ret);
    }
     
    return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int k,a,b;
    cin >> k >> a >> b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}

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

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

using namespace std;



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

    ll i = 1;
    ll sum = 0;
    for(i = 1; i <= x; i++){
        sum += i;
        if(x <= sum)    break;
    }

    cout << i << endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
nodes = {}

class Node
    attr_accessor :string
    attr_accessor :no
    attr_accessor :valid
    attr_accessor :child
end

(1..n).each { |i|
    s = gets.chomp
    node = Node.new
    node.string = s
    node.no = i
    node.valid = false
    node.child = [node]
    nodes[i] = node
}


node_array = nodes.values.sort_by { |e| e.string }

(0..(n-2)).each do |i|
    ((i+1)..(n-1)).each do |j|
        if node_array[j].string.start_with?(node_array[i].string)
            node_array[i].child.push(node_array[j])
        else
            break
        end
    end
end

q = gets.to_i
q.times do
    # print node_array.map { |e| [e.no, e.valid] }
    # puts
    k, index =gets.chomp.split(" ").map(&:to_i)
    if k == 1
        nodes[index].valid = true
    elsif k == 2
        nodes[index].valid = false
    else
        node = nodes[index].child.select { |e| e.valid }.first
        if node 
            puts node.no
        else
            puts -1
        end
    end
end



Measured memory_bytes: 36368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    VVI v(2);
    for (i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        v[0].pb(x + y);
        v[1].pb(x - y);
    }
    sort(v[0].begin(), v[0].end());
    sort(v[1].begin(), v[1].end());
    ll ans = 0;
    chmax(ans, v[0][n - 1] - v[0][0]);
    chmax(ans, v[1][n - 1] - v[1][0]);
    cout << ans << endl;
}

Measured memory_bytes: 6692
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

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

  int ans = abs(a - b) + abs(a - c) + abs(b - c) -
            max(abs(a - b), max(abs(a - c), abs(b - c)));
  cout << ans << "\n";
}

Measured memory_bytes: 256
S = str(input())
Q = int(input())

left = []
right = []

reversed_ = False

for _ in range(Q):
    INPUT = input()

    if INPUT == '1':
        reversed_ = not(reversed_)
        left, right = right, left
        continue

    INPUT = INPUT.split()
    F = INPUT[1]
    C = INPUT[2]

    if F == '1':
        left.append(C)
    else:
        right.append(C)

for c in reversed(left):
    print(c, end='')

if reversed_:
    for c in reversed(S):
        print(c, end='')
else:
    print(S, end='')

for c in right:
    print(c, end='')

Measured memory_bytes: 6392
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

a = make_divisors(n)
a.sort()

if len(a) % 2 == 0:
    print(a[len(a)//2 - 1] + a[len(a)//2] -2)
else:
    print(a[len(a)//2]*2-2)

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

cntb = k - a
cntc = cntb - b

if cntb <= 0:
    print(k*1)
elif cntb > 0 and cntc <= 0:
    print((a*1) + (cntb*0))
elif cntb > 0 and cntc > 0:
    print((a*1) + (cntb*0) + (cntc*-1))

Measured memory_bytes: 9192
N, A, B = map(int,input().split())
sum = 0
for i in range(1,N+1):
    i10000 = i // 10**4
    i1000 = (i - i10000*(10**4)) // 10**3
    i100 = (i - i10000*(10**4) - i1000*(10**3)) // 100
    i10 = (i - i10000*(10**4) - i1000*(10**3)- i100*(10**2)) // 10
    i1 = i - i10000*(10**4) - i1000*(10**3)- i100*(10**2) -i10*10
    if A <= i10000 + i1000 + i100 + i10 + i1 <= B:
        sum = sum + i

print(sum)

Measured memory_bytes: 3064
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            for (int i = n; i >= 5; i--)
                if (IsPrime(i) && IsPrime(i-2))
                { Console.WriteLine("{0} {1}", i - 2, i); break; }
        }
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        else if (n == 2) return true;
        else if (n % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i <= sqrtNum; i += 2)
            if (n % i == 0) return false;
        return true;
    }
}

Measured memory_bytes: 9320
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ordered_set tree<int , null_type,less<int , rb_tree_tag,tree_order_statistics_node_update>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 100000000
// order_of_key and *find_by_order
#define N 10000001
int32_t main() {
	fast;
	int a[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] != i + 1) {
			cout << i + 1;
			return 0;
		}
	}









}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<50; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<ll> a(m), b(m), c(m);
    for(int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        c[i] = -c[i];
    }
    vector<ll> dist(n, INF);
    dist[0] = 0;
    for(int i = 0; i < n - 1; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(dist[a[j]] == INF) continue;
            dist[b[j]] = min(dist[b[j]], dist[a[j]] + c[j]);
        }
    }
    vector<int> used(n, 0);
    bool negative = false;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(dist[a[j]] == INF) continue;
            if(dist[a[j]] + c[j] < dist[b[j]])
            {
                dist[b[j]] = dist[a[j]] + c[j];
                used[b[j]] = true;
            }
            if(used[a[j]])
            {
                used[b[j]] = true;
            }
        }
    }
    if(used[n - 1]) cout << "inf" << endl;
    else cout << -dist[n - 1] << endl;
    return 0;
}



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

typedef long double ld;
typedef long long ll;
const ld pi=acos(-1.0),pi2=pi*2;

struct vec{
	ll x,y;int id;
	vec(){}
	vec(ll x0,ll y0){x=x0;y=y0;}
	vec operator+(vec v){return vec(x+v.x,y+v.y);}
	vec operator-(vec v){return vec(x-v.x,y-v.y);}
	vec operator-(){return vec(-x,-y);}
	ll operator*(vec v){return x*v.y-v.x*y;}
	ld arg(){return atan2(y,x);}
	friend bool operator<(vec a,vec b){
		if(a.arg()!=b.arg())return a.arg()<b.arg();
		return a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y;
	}
}p[105],o(1e9,1e9);

int n;

inline void init(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld%lld",&p[i].x,&p[i].y);
		p[i].id=i;
		if(p[i].y<o.y)o=p[i];
	}
	for(int i=1,j=1;i<=n;++i){
		if(p[i].x!=o.x||p[i].y!=o.y){
			p[j].x=p[i].x-o.x;
			p[j].y=p[i].y-o.y;
			p[j].id=p[i].id;
			++j;
		}
	}
	sort(p+1,p+n);
}

vec st[105];int top;
ld ans[105];
inline void solve(){
	st[top=1]=vec(0,0);st[1].id=o.id;
	for(int i=1;i<n;++i){
		for(;top>1&&(p[i]-st[top-1])*(p[i]-st[top])<0;--top);
		st[++top]=p[i];
	}
	st[0]=st[top];st[top+1]=st[1];
	for(int i=1;i<=top;++i){
		ld arg=(st[i-1]-st[i]).arg()-(st[i+1]-st[i]).arg();
		if(arg<0)arg+=pi2;
		arg=pi-arg;if(arg<0)arg=0;
		ans[st[i].id]=arg/pi2;
	}
	for(int i=1;i<=n;++i)
		printf("%.8lf\n",(double)ans[i]);
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  string s; cin >> s;
  int n = s.size();
  bool same = (s.at(0) == s.at(n-1));

  if (same ^ (n%2 == 0)) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }
}


Measured memory_bytes: 512
from fractions import gcd

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

def devisor(x):
    n1 = A//x
    n2 = B//x
    cnt = n2 - n1
    if A%x == 0:
        cnt += 1
    return cnt

num_all = B-A+1
num_c = devisor(C)
num_d = devisor(D)

lcm_cd = C*D // gcd(C,D)

num_cd = devisor(lcm_cd)
 
print(num_all - num_c - num_d + num_cd)

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

int main(){
  bool flag = false;
  int n, count = 0;
  int dice1[100], dice2[100];
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> dice1[i] >> dice2[i];
  
  for(int i = 0; i < n; i++){
    if(dice1[i] == dice2[i])
      count++;
    else
      count = 0;
    
    if(count == 3){
      flag = true;
      break;
    }
  }
  
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
    
}


Measured memory_bytes: 3632
n = int(input())

flag = False
for i in range(26):
    for j in range(15):
        if 4*i + 7*j == n:
            flag = True
            break
        elif 4*i + 7*j > n:
            break
    if flag:
        break

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
N, A = list(map(int, input().split()))
x = list(map(int, input().split()))
for i in range(N):
	x[i] -= A

L = [[0 for i in range(10002)] for j in range(N)]
for i in range(N):
	L[i][5001 + x[i]] = 1

for i in range(N - 1):
	for j in range(10002):
		if L[i][j] != 0:
			L[i + 1][j] += L[i][j]
			L[i + 1][j + x[i + 1]] += L[i][j]

print(L[N - 1][5001])

Measured memory_bytes: 7668
class UNION_FIND(object):
    def __init__(self,n):
        self.parent=[-1 for i in range(n)]
        
    def root(self,x):
        if self.parent[x]<0:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])
            return self.parent[x]
 
    def size(self,x):
        return -self.parent[self.root(x)]
    def union(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]  #Aのサイズを更新する
        self.parent[y]=x   #Bの親をAに変更する
        return True

n=int(input())
u=UNION_FIND(2*n)
for i in range(n-1):
    a,b,c=map(int,input().split())
    if c%2==0:
        u.union(a-1,b-1)
        u.union(a-1+n,b-1+n)
    else:
        u.union(a-1+n,b-1)
        u.union(a-1,b-1+n)
#print(u.parent)
for i in range(n):
    if u.root(i)<n:
        print(1)
    else:
        print(0)

Measured memory_bytes: 8924
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD = 998244353;
const int MOD2 = 1000000007; 
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll fastpow(ll n,ll x)
{   
	if(x==0)
	return 1 ;
	if(x%2==0)
	return (fastpow(n*n%MOD2,x/2)%MOD2) ;
	return (x*fastpow(n*n%MOD2,(x-1)/2)%MOD2)%MOD2 ; 
}

int main(int argc, char** argv)
{   sws ;

   // tcase
    {
    	ll n,k ;
    	cin>>n ;
    	ll a[n],b[n],c[n] ;
    	forn(i,n)
    	{
		cin>>a[i]>>b[i]>>c[i] ;
	    }
    	ll dp1[n],dp2[n],dp3[n];
    	forn(i,n)
    	dp1[i]=dp2[i]=dp3[i]=0 ;
    	dp1[0]=a[0] ;
    	dp2[0]=b[0] ;
    	dp3[0]=c[0] ;
    	for(int i=1; i<n;i++)
    	{
    		dp1[i]=max(dp1[i],dp2[i-1]+a[i]) ;
    		dp1[i]=max(dp1[i],dp3[i-1]+a[i]) ;
    		dp2[i]=max(dp2[i],dp1[i-1]+b[i]) ;
    		dp2[i]=max(dp2[i],dp3[i-1]+b[i]) ;
    		dp3[i]=max(dp3[i],dp2[i-1]+c[i]) ;
    		dp3[i]=max(dp3[i],dp1[i-1]+c[i]) ;
		}
		cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1])) ;
   
}

return 0 ;
}

Measured memory_bytes: 8284
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	ll n, a, b;
	cin >> n >> a >> b;

	ll num = n / (a + b), m = n % (a + b);
	ll ans = a * num + min(m, a);
	cout << ans << endl;
}

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

int N, a[100000];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    // 全体の色の種類は max(a) or max(a) + 1
    // max(a)の場合はmax(a)を達成する人の色は複数人で共有される
    // よって、a[i] = max(a)となるiが二つ以上ある
    // 自分を除いてもたかだか1色しか減らないから、ほかはa[i] = max(a) - 1
    // a[0: x] が max(a)-1, a[x: x+y=N]がmax(a)のとき、
    // x + 1 以上 x + y/2 以下の色数ができる
    // max(a) + 1 の場合は、すべてmax(a)
    // 全員違う色で、max(a) = N - 1

    sort(a, a + N);
    int max_a = a[N-1];
    int x = 0;
    for(int i = 0; i < N; i++){
        if(a[i] == max_a - 1){
            x++;
        }
    }
    int y = (N - x);
    bool ok = (a[N-2] == max_a && a[0] >= max_a - 1 && max_a >= x + 1 && max_a <= x + y/2)
        || (a[0] == max_a && max_a == N - 1);
    cout << (ok? "Yes": "No") << endl;
    


}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
using namespace std;
typedef long long int ll;
const int MOD = 1000000007;

bool hantei(int n, int m, string* a, string* b){
    bool ret = false;
    bool tmp;
    // cout << n << m << endl;
    //始点のループ
    for(int i=0; i <= n - m; i++){
        for(int j=0; j <= n - m; j++){
            //比較のループ
            tmp = true;
            for(int k = 0 ; k < m; k++){
                for(int l = 0; l < m; l++){
                    // cout << a[i+k][j+l] << b[k][l] << endl;
                    if(a[i+k][j+l] != b[k][l]){
                        tmp = false;
                    }
                }
            }
        if(tmp) ret = true;
        }
    }   
    return ret;
}


int main(){
    int n, m;
    bool ans;
    cin >> n >> m;
    string a[n], b[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i < m; i++){
        cin >> b[i];
    }
    ans = hantei(n, m, a, b);
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Open(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout);
#define inl inline
#define reg register
#define i64 long long 
#define int long long 
using namespace std;
inl int read(){int x=0,f=0;char ch=0;while(!isdigit(ch))f|=(ch=='-'),ch=getchar();while(isdigit(ch))(x*=10)+=(ch^48),ch=getchar();return f?-x:x;}
inl void Ot(reg int x){if(x<0)x=-x,putchar('-');if(x>=10)Ot(x/10);putchar(x%10+'0');}
inl void Print(reg int x,char til='\n'){Ot(x);putchar(til);}
inl int Max(reg int x,reg int y){return x>y?x:y;}
inl int Min(reg int x,reg int y){return x<y?x:y;}
inl int Abs(reg int x){return x<0?-x:x;}
const int Mod=1e9+7;
const int MAXN=1500000;
int n,sum1=1,sum3;
int a[MAXN];
int p[MAXN];
inl int qpow(reg int x,reg int y=Mod-2){
	reg int ret=1;
	for(;y;y>>=1,x=x*x%Mod)if(y&1)ret=ret*x%Mod;
	return ret;
}
inl int gcd(reg int x,reg int y){
	return y==0?x:gcd(y,x%y);
}
inl void f(reg int x){
	if(x<2)return;
	for(reg int i=2,tmp=0;i*i<=x;i++,p[i-1]=Max(p[i-1],tmp),tmp=0)
		while(x%i==0)x/=i,tmp++;
	if(x>1)p[x]=Max(p[x],1);
}
signed main(){
	#ifndef ONLINE_JUDGE
		// freopen("../../data.in","r",stdin);
	#endif
	n=read();
	for(reg int i=1;i<=n;i++){
		a[i]=read();
		f(a[i]);
		sum3=(sum3+qpow(a[i]))%Mod;
	}
	for(reg int i=2;i<=1000000;i++)
		if(!p[i])continue;
	else /*cout<<i<<" "<<p[i]<<endl,*/sum1=sum1*qpow(i,p[i])%Mod;
	// cout<<sum1<<endl;
	Print(sum1*sum3%Mod);
	return 0;
}

Measured memory_bytes: 10240
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	FastScanner sc;
	int[] arr;

	void run() {
		Scanner cin = new Scanner(System.in);
		int N = Integer.parseInt(cin.nextLine().trim());
		String line = cin.nextLine();
		String[] lineArr = line.split(" ");
		int size = lineArr.length;
		arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = Integer.parseInt(lineArr[i]);
		}
		Arrays.sort(arr);
		int ans = 0;
		int idx = size - 2;
		for (int i = 0; i < N; i++) {
			ans += arr[idx];
			idx = idx - 2;
		}
		
		System.out.println(ans);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 9936
#include <iostream>

using namespace std;
int N;
const int MAX_N = 100;
int a[MAX_N];
int b[9], c[9];

void solve() {
	int Mans = 0;
	int mans = 0;

	for (int i = 0; i < N; i++) {
		if (a[i] >= 1 && a[i] <= 399) {
			++b[0];
		}
		else if (a[i] >= 400 && a[i] <= 799) {
			++b[1];
		}
		else if (a[i] >= 800 && a[i] <= 1199) {
			++b[2];
		}
		else if (a[i] >= 1200 && a[i] <= 1599) {
			++b[3];
		}
		else if (a[i] >= 1600 && a[i] <= 1999) {
			++b[4];
		}
		else if (a[i] >= 2000 && a[i] <= 2399) {
			++b[5];
		}
		else if (a[i] >= 2400 && a[i] <= 2799) {
			++b[6];
		}
		else if (a[i] >= 2800 && a[i] <= 3199) {
			++b[7];
		}
		else if(a[i] >= 3200 && a[i] <= 4800){
			++b[8];
		}
		
	}

	for (int i = 0; i < 9; i++) {
		c[i] = b[i];
	}
	
	for (int i = 0; i < 8; i++) {
		if (c[i] != 0 && c[8] > 0) {
			++c[i];
			--c[8];
		}
	}
	for (int i = 0; i < 8; i++) {
		if (c[i] != 0) {
			++mans;
			
		}

	}
	if (mans == 0) {
		mans = 1;
	}

	for (int i = 0; i < 8; i++) {
		if (b[i] != 0) {
			++Mans;
		}
	}
	Mans += b[8];
	cout << mans << " " << Mans << endl;
}

int main() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 256
n=int(input())
A = list(map( int, input().split( )))
B = list(map( int, input().split( )))
#左から順に倒す
C = [0] * (n+1)
#左隣からの応援
ans = 0
for i in range(n):
    C[i+1] = min(max(B[i]+C[i]-A[i], 0),B[i])
    ans += min(A[i], B[i] + C[i])

ans += min(A[n], C[n])
print(ans)
   


Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------
void Main(){
  int n,m;
  cin>>n>>m;
  if(n>=m){cout<<0; return;}
  vi x(m);
  vi y(m-1);
  cin>>x;
  sort(rng(x));
  rep(i,m-1) y[i] = x[i+1] - x[i];
  sort(rng(y));
  cout<<accumulate(y.begin(),y.begin()+y.size()-(n-1),0ll);

} int main(int argc,char** argv)
{fastio; myio; Main();}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    vector<int> e(4);
    for(int i=0; i<4; ++i)
        cin >> e[i];

    sort(e.begin(), e.end());
    if(e[0] == e[1] && e[2] == e[3])
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    return 0;
}

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


int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h+2);
    for(int i = 1; i <= h; i++) cin >> s[i];
    
    for(int i = 0; i < h+2; i++){
        for(int j = 0; j < w+2; j++){
            if(i == 0 || i == h+1){
                cout << '#';
            }else{
                if(j == 0 || j == w+1)
                    cout << '#';
                else
                    cout << s[i][j-1];
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(ary);
        int max = n/2;
        int min = n/2 - 1;
        System.out.println(ary[max] - ary[min]);

    }
}

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

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

    //ios::sync_with_stdio(0);
    //cin.tie(0);
    int n;
    cin>>n;
    int vec[n];

    for(int i=0;i<n;i++){
    	cin>>vec[i];
    }
    sort(vec,vec+n);
    double sum=vec[0];
    for(int i=1;i<n;i++){
    	sum=(sum+vec[i])/2;
    }
    cout<<sum<<endl;


	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

binary = [bin(a) for a in A]
bin_K = bin(K)
ma_len = max([len(e) for e in binary] + [len(bin_K)]) - 2
B = [e[2:].zfill(ma_len) for e in binary]
bin_K = bin_K[2:].zfill(ma_len)
ans = 0
X = []

flag = False
for i in range(ma_len):
    num_1 = 0
    num_0 = 0
    for j in range(N):
        if B[j][i] == "0":
            num_0 += 1
        else:
            num_1 += 1
    if num_1 >= num_0:
        added = "0"
        if bin_K[i] == "1":
            flag = True
    else:
        if flag:
            added = "1"
        else:
            if bin_K[i] == "1":
                added = "1"
            else:
                added = "0"
    if added == "1":
        ans += 2**(ma_len - i - 1) * num_0
    else:
        ans += 2**(ma_len - i - 1) * num_1
    # X.append(added)

print(ans)
# print("".join(X))


Measured memory_bytes: 31560
#include <stdio.h>
#include <string.h>

#define max 100

int main()
{
    int N, i, cnt=0;
    char S[max];
    
    scanf("%d %s", &N, S);
    
    if(N%2!=0){
        printf("No");
        return 0;
    }
    
    for (i=0; i<N/2; i++) {
        if (S[i]!=S[i+N/2]) {
            cnt++;
        }
    }
    
    if(cnt==0)
        printf("Yes");
    else
        printf("No");
    
    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(), a.end());
  int alice=0, bob=0;
  int count=1;
  for(int i=N-1;i>=0;i--){
    if(count%2==1){
      alice += a.at(i);
    }
    else{
      bob += a.at(i);
    }
    count++;
  }
  cout<<alice-bob<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n;
		cin >> n;
		int count =0;
		for(int i=1; i<=9; i++){
			if(n%i==0){
				if(i== n/i || ((n/i)<=9 && 1<=(n/i))){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
		
		cout << "No" << endl;
		return 0;
	}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	long long  n; cin >> n;
	string s; cin >> s;
	s = "*" + s;
	string col = "RGB";

	vector<vector<long long >> pref(n + 1, vector<long long >(3, 0));
	for (long long  i = 1; i <= n; i++) {
		for (long long  j = 0; j <= 2; j++) pref[i][j] = pref[i - 1][j] + (s[i] == col[j]);
	}

	long long  ans = 0;

	for (long long  i = 1; i <= n - 2; i++) {
		for (long long  j = i + 1; j <= n - 1; j++) {
			if (s[i] == s[j]) continue;
			//k-j=j-i =>k=2*j-i
			long long  k = 2 * j - i;
			long long  c = -1;
			if ((s[i] == 'R' or s[i] == 'G') and (s[j] == 'G' or s[j] == 'R')) c = 2;
			else if ((s[i] == 'R' or s[i] == 'B') and (s[j] == 'B' or s[j] == 'R')) c = 1;
			else c = 0;
			assert(c >= 0 and c <= 2);

			ans += (pref[n][c] - pref[j][c]);
			if (k <= n) ans -= (pref[k][c] - pref[k - 1][c]);
		}
	}

	cout << ans;
	return 0;
}

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

const int mod=1e9+7,N=2050;
int a,b,c[N][N],ans;

inline int ad(int x,int y){x+=y;if(x>=mod) x-=mod;return x;}
inline int mul(int x,int y){return 1ll*x*y%mod;}

int main(){
	int i,j;
	c[0][0]=1;
	for(i=1;i<N;++i){
		c[i][0]=c[i][i]=1;
		for(j=1;j<i;++j) c[i][j]=ad(c[i-1][j-1],c[i-1][j]);
	}
	scanf("%d%d",&a,&b);
	ans=a+1;
    for(i=max(1,b-a);i<b;++i)
    	for(j=max(1,2*(b-i)-a);j<=b-i;++j)
    	    ans=ad(ans,mul(mul(c[b-1][i-1],c[b-i-1][j-1]),c[a-2*(b-i)+j+2][2]));   	
    printf("%d\n",ans);
}


Measured memory_bytes: 15616
using namespace std;

#include <iostream>

int main()
{
    int a, b,c;
    cin >> a;
    cin >> b;
    if (a == 1) {
        if (b == 2) {
            c = 3;
        }
        else {
            c = 2;
        }
    }
    else if(a==2){
        if (b == 1) {
            c = 3;
        }
        else {
            c = 1;
        }
    }
    else {
        if (b == 1) {
            c = 2;
        }
        else {
            c = 1;
        }
    }
    cout << c<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
typedef long long ll;
using namespace __gnu_pbds;

typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double lld;

lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
ll hell=1000000007;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    string s;
    cin>>s;
    ll n,i;
    n=s.size();
    ll c=0;
    for(i=0;i<n;i++)
        if(s[i]=='B')
            c++;
    ll p=n-c;
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='B')
        {
            ans+=p-i;
            p++;
        }
    }
    cout<<ans;
    return 0;
}








Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		char op = sc.next().charAt(0);
		int B = sc.nextInt();
		sc.close();
		
		if(op == '+')
			System.out.println((A+B));
		else
			System.out.println((A-B));
	}
}


Measured memory_bytes: 21844
program key2020_C
    implicit none
    integer::N,K,S
    integer::i
    read*,N,K,S
    if(K/=0)then
        write(*,"(i0)",advance="no")S
    else
        write(*,"(i0)",advance="no")merge(S+1,S-1,S/=10**9)
    endif
    do i=2,K
        write(*,"(A,i0)",advance="no")" ",S
    end do
    do i=K+1,N
        if(K==0.and.i==N)exit
         write(*,"(A,i0)",advance="no")" ",merge(S+1,S-1,S/=10**9)
    end do
    write(*,*)
end program key2020_C

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

typedef vector<int>  vi;
typedef set<char> setchar;
typedef set<int> sett;
typedef deque <int> dq;
typedef long long ll;
#define vec(a)  a.begin(),a.end()
#define pb     push_back
#define pf     push_front
#define mem(a,b) memset(a,b,sizeof(a));
#define inI(a)  scanf("%d",&a);
#define inL(a)  scanf("%lld",&a);
#define SWAP(a,b) a= a^b, b=a^b, a=a^b
#define uff ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
//int fx[]={+0,-1,-1,-1,+0,+1,+1,+1};
//int fy[]={-1,-1,+0,+1,+1,+1,+0,-1};
int fx[]= {0,-1,0,+1};
int fy[]= {-1,0,+1,0};



int main()
{
     uff
    //freopen("input.txt","r",stdin);
    string s,t;
    int id=0;
    cin>>s>>t;
  for(int i=0;i<3;i++)
  {
    if(s[i]==t[i])
      id++;
  }
  cout<<id<<endl;



    return 0;

}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	multiset<int, greater<int>> small;
	multiset<int> large;
	ll sum = 0, m = -inf, ans = 0;
	rep(_, n) {
		int type;
		cin >> type;
		if (type == 1) {
			int a, b;
			cin >> a >> b;
			sum += b;
			if (small.size() == large.size()) {
				if (large.size() == 0 || a <= *large.begin()) small.insert(a);
				else {
					large.insert(a);
					small.insert(*large.begin());
					large.begin() = large.erase(large.begin());
				}
			}
			else {
				if (*small.begin() <= a) large.insert(a);
				else {
					small.insert(a);
					large.insert(*small.begin());
					small.begin() = small.erase(small.begin());
				}
			}
			int d = *small.begin();
			if (m > d) ans += m - d;
			m = d;
			ans += abs(m - a);
		}
		else if (type == 2) cout << m << ' ' << ans + sum << '\n';
	}
}

Measured memory_bytes: 9600