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

int main(void)
{
  int n;
  scanf("%d", &n);
  int a[n];
  int i = 0;
  while (i < n)
  {
    scanf("%d", &a[i]);
    i++;
  }
  
  int flg = 1;
  int tmp;
  while (flg == 1)
  {
    flg = 0;
    i = 0;
    while (i + 1 < n)
    {
      if (a[i] < a[i + 1])
      {
        tmp = a[i];
        a[i] = a[i + 1];
        a[i + 1] = tmp;
        flg = 1;
      }
      i++;
    }
  }
  
  i = 0;
  int ali = 0, bob = 0;
  while (i < n)
  {
    if (i % 2 == 0)
    {
      ali += a[i];
    }
    else if (i % 2 == 1)
    {
      bob += a[i];
    }
    i++;
  }
  printf("%d", ali - bob);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	ll n;
	cin >> n;
	ll ans = n-1;
	for (ll x = 1; x*x <= n; x++) {
		if (n % x) continue;
		ll y = n / x;
		ll t = x - 1 + y - 1;
		if (t < ans) ans = t;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,x,y;
  cin >> x >> y;
  if( x*2 <= y && y <= x*4 && y%2 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			int m = sc.nextInt();
			int l[] = new int[m];
			int r[] = new int[m];
			for (int i = 0; i < m; i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}

			Arrays.sort(l);
			Arrays.sort(r);

			if (l[m - 1] <= r[0]) {
				if (n >= r[0] - l[m - 1] + 1) {
					System.out.println(r[0] - l[m - 1] + 1);
				} else {
					System.out.println(n);
				}
			} else {
				System.out.println(0);
			}

		}
	}
}


Measured memory_bytes: 84484
n, k = map(int, input().split())
result = 0
if k % 2 == 0:
	counter = (n - k // 2) // k
	result += (counter + 1) ** 3
	counter = n // k
	result += counter ** 3
else:
	counter = n // k
	result = counter ** 3

print(result)

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> vec(H);
  for (int i=0;i<H;i++)
    cin >> vec.at(i);
  
  for (int i=0; i<W+2; i++)
    cout << "#";
  
  cout << endl;
  
  for (int i=0; i<H; i++)
    cout << "#" << vec.at(i) << "#" << endl;
  
  for (int i=0; i<W+2; i++)
    cout << "#";
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   }
}


Measured memory_bytes: 35576
/// Find the maximum product of subsequences  of size k
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
using namespace std;
signed main()
{
    ll i,j,k,n,s=0;
    cin>>n;
    cin>>k;
    ll K=k;
    vector<ll>neg,pos,zero;
    vector<pair<ll,ll> >vec;
    ll arr[n];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        if(arr[i]>0)
        {
            pos.pb(arr[i]);
            s=1;
        }
        else if(arr[i]<0)
        {
            neg.pb(abs(arr[i]));
            s=-1;
        }
        else
        {
            zero.pb(arr[i]);
            s=1;
        }
        vec.pb(make_pair(abs(arr[i]),s));
    }
    ll idp=pos.size()-1;
    ll idn=neg.size()-1;
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end());
    sort(vec.begin(),vec.end());
    ll ans=1;
    if(k%2)
    {
        if(pos.size()>0)
        {
            ans=((ans*pos[idp])%mod+mod)%mod;
            idp--;
            k--;
        }
    }
    /// as k is even so k will be zero if enough positive or negative pair is present here
    while(k&& (idp>0||idn>0))
    {
        ll a=-inf;
        ll b=-inf;
        if(idp>=1)
            a=pos[idp]*pos[idp-1];
        if(idn>=1)
            b=neg[idn]*neg[idn-1];
        if(a>b)
        {
            ans+=mod;
            a+=mod;
            ans%=mod;
            a%=mod;
            ans=(a*ans)%mod;
            idp=idp-2;
            k=k-2;
        }
        else
        {
            ans+=mod;
            b+=mod;
            ans%=mod;
            b%=mod;
            ans=(b*ans)%mod;
            idn=idn-2;
            k=k-2;
        }
    }
    if(k)
    {
        if(zero.size())
            ans=0;
        else
        {
            ans=1;
            for(i=0; i<K; i++)
                ans=((ans%mod*((vec[i].first*vec[i].second)%mod))%mod+mod)%mod;
        }
    }
    cout<<ans;
    return 0;

}


Measured memory_bytes: 10896
#include <stdio.h>
 
int main()
{
    int n = 0, i, min = 0, max = 0;
    long long int sum = 0;
    int input_num[10001], output_num[3];
 
    scanf("%d", &n);
     
    for (i = 0; i < n; i++)
    {
        scanf("%d", &input_num[i]);
        if (i == 0)
        {
            max = input_num[i];
            min = input_num[i];
        }
        if (input_num[i] > max)
        {
            max = input_num[i];
        }
        if (input_num[i] < min)
        {
            min = input_num[i];
        }
 
        sum += input_num[i];
    }
 
    output_num[0] = min;
    output_num[1] = max;
 
    printf("%d %d %lld\n", output_num[0], output_num[1], sum);
 
    return 0;
}

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

using namespace std;

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    cout << d[n / 2] - d[n / 2 - 1];
    return 0;
}


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

chr_start = 95
base = 26
digits = []

for i in range(13):
    res = n % base
    if res == 0:
        res = 26
    n = (n-res) // base
    digits.append(res+1)
    if n ==0:
        break
        
ans = "".join(reversed([chr(chr_start+d) for d in digits if d > 0]))
print(ans)

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

int min(int a,int b){
    if (a<b) return a;
    else return b;
}
        
int main() {
    int n; cin >> n;
    int odd1[100010]={0};
    int odd2[100010]={0};
    int even1[100010]={0};
    int even2[100010]={0};
    for (int i=0; i<n; i++){
        int a;
        cin >> a;
        if (i%2 != 0) {
            odd1[a]++;
            odd2[a]++;
        }
        else {
            even1[a]++;
            even2[a]++;
        }
    }
    sort(odd1,odd1+100010);reverse(odd1,odd1+100010);
    sort(even1,even1+100010);reverse(even1,even1+100010);
    int a1,a2;
    for (int i=0; i<100010;i++){
        if (odd2[i] == odd1[0]) {
            a1 = i;
            break;
        }
    }
    for (int i=0; i<100010;i++){
        if (even2[i] == even1[0]) {
            a2 = i;
            break;
        }
    }
    if (a1 != a2)
        cout << n - odd1[0]-even1[0];
    else
        cout << min(n - odd1[0] - even1[1],n - even1[0] - odd1[1])<< endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
    int a[5],i,q,x=10,s=0;
    for(i=0;i<5;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]%10!=0&&a[i]%10<x)
                {x=a[i]%10;q=i;}
        }
    for(i=0;i<5;i++)
    {
        while(i!=q&&a[i]%10!=0)
            a[i]++;
        s+=a[i];
    }
        printf("%d",s);
    return 0;
}

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

int main(){
    int n;
    double t,a;
    cin >> n >> t >> a;
    vector<double> h(n);

    for(int i=0; i<n; i++){
        cin >> h.at(i);
        h.at(i)*=0.006;
    }

    int ans;
    double x,y=1000;
    for(int i=0; i<n; i++){
        x=abs(a-(t-h.at(i)));
        if(y>x){
            ans=i+1;
            y=x;
        }
    }
    cout << ans << endl;
}

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

// 入力
long long N;

// cur: 現在の値、use: 7, 5, 3 のうちどれを使ったか, counter: 答え
void func(long long cur, int use, long long &counter) {
    if(cur > N)
        return; // ベースケース
    if(use == 0b111)
        ++counter; // 答えを増やす

    // 7 を付け加える
    func(cur * 10 + 7, use | 0b001, counter);

    // 5 を付け加える
    func(cur * 10 + 5, use | 0b010, counter);

    // 3 を付け加える
    func(cur * 10 + 3, use | 0b100, counter);
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> N;
    long long res = 0;
    func(0, 0, res);
    cout << res << endl;
}


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

public class Main{

	public static void main(String[] args) {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = null;
		for (;;) {
			// for()の中身は使わないなら；；だけでいい
			try {
				input = br.readLine();
			} catch (IOException e) {
			}
			String[] inputs = input.split(" ");
			int H = Integer.parseInt(inputs[0]);
			int W = Integer.parseInt(inputs[1]);
			if (H == 0 && W == 0) {
				break;
			}
			for (int i = 1; i <= H; i++) {
				for (int j = 1; j <= W; j++) {
					// if (j < W) これいらない
					if (j == 1 || i == 1 || i == H || j == W) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
					// printlnは改行して表示。printは横並びに書いていく
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}


Measured memory_bytes: 31408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  vector< vector <char>> x(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>x[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<x[i][j];
    }
    cout<<endl;
    for(int j=0;j<w;j++){
      cout<<x[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    P = sorted(P)
    print(sum(P[:K]))

if __name__ == "__main__":
    run()

Measured memory_bytes: 9224
from sys import stdin

def gcd(a, b):
  return a if b == 0 else gcd(b, a % b)
  
def lcm(a, b):
  return a * b // gcd(a,b)
  
N = int(input())
T = [int(t) for t in stdin]

answer = 1
for t in T:
  answer = lcm(answer, t)
  
print(answer)

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

int main(){
  int n;
  cin >> n;
  int F[100];
  F[0] = 1;
  F[1] = 1;
  for(int i=2; i<n+1; i++){
    F[i] = F[i-2] + F[i-1];
  }
  cout << F[n] << endl;
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n, m, a, b int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &m)

	island1 := make([]bool, n+1)
	islandn := make([]bool, n+1)
	for i := 0; i < m; i++ {
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &a, &b)
		if a == 1 || a == n {
			island1[b] = true
		} else if b == 1 || b == n {
			islandn[a] = true
		}
	}
	for i := 1; i <= n; i++ {
		if island1[i] && islandn[i] {
			fmt.Println("POSSIBLE")
			return
		}
	}
	fmt.Println("IMPOSSIBLE")
}


Measured memory_bytes: 6396
#include <stdio.h>
#include <string.h>
int q[2000000];
void swap(int i, int j) {
  int t;
  t=q[i];
  q[i]=q[j];
  q[j]=t;
}
int main(void) {
  int k,s=0,i,pr,l,r;
  char com[2];
  while (1) {
    scanf("%s%d", com,&k);
    if(!strncmp(com,"en",2)) break;
    if(com[0]=='i'){
      q[i=s]=k;
      while (i>0 && q[i]>q[pr=(i-1)/2]) {
        swap(i,pr);
        i=pr;
      }
      ++s;
    } else {
      printf("%d\n", q[0]);
      q[i=0]=q[--s];
      --q[s];
      while ((l=i*2+1)<s) {
        if ((r=l+1)<s && q[r] > q[l]) l=r;
        if (q[i] < q[l]) swap(i,l);
        i=l;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4696
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  if(x== 7 || x==5 || x==3){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

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

int main() {
    ll n;
    cin >> n;
    string name;
    while (n >= 26) {
        ll a = n % 26;
        if (a != 0) {
            name.push_back('a' + a - 1);
            n = n / 26;
        }
        else {
            name.push_back('z');
            n = n / 26 - 1;
        }
    }
    if (n != 0) name.push_back('a' + n - 1);
    reverse(name.begin(), name.end());
    cout << name << endl;
}

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

int main(){
    long int n,data = 0,before = 0;
    cin >> n;
    long int a[100002] = {};

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        data += abs(before - a[i]);
        before = a[i];
    }

    data += abs(a[n]);

    long int ans;

    for(int i = 1; i <= n; ++i){

        ans = data - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]);
        ans += abs(a[i - 1] - a[i + 1]);

        cout << ans << endl;

    }
}

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

using namespace std;

int main(){

    char s[100];
    int tam,iguais=1,extra=0;

    cin >> s;
    tam=strlen(s);
    sort(s,s+tam);
    for(int i=0;i<tam;i++){
        if(s[i] == s[i+1]){
            iguais++;
        }
        else{
            if(iguais%2 != 0){
                extra++;
            }
            iguais=1;
        }
    }
    if(extra==0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}

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


int main (){
    int N;
    cin >> N;
    int x1=N/100;
    int x2=(N-x1*100)/10;
    int x3=N-100*x1-10*x2;
    if(x1==7 || x2==7 || x3==7){
        cout << "Yes"<< endl;
    }
    else{
    cout << "No" << endl;
    }
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {

	public static void main(String[] args) {
	
		int a=0,b=0,c,i;
		Scanner sc=new Scanner(System.in);
		for(;;){
		try{
		a=sc.nextInt();
		b=sc.nextInt();
		}
		catch (Exception e) {
			System.exit(0);
		}
			
		
		
		c=a+b;
		for(i=1;;i++){
			int d=c/10;
			if(d==0)break;
			c=d;
					
		}
		System.out.println(i);
	

}
}
}

Measured memory_bytes: 12000
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

template <class T>
T fast_pow(T n, int exp) {
  T ret = 1, powOf2 = n;
  while (exp > 0) {
    if (exp & 1) ret *= powOf2;
    powOf2 *= powOf2;
    exp /= 2;
  }
  return ret;
}

class modint {
 public:
  ll n;
  int mod = MOD;

  modint(const ll x = 0) noexcept : n(x) {}
  modint inverse() { return fast_pow(*this, mod - 2); }
  modint& operator+=(const modint a) {
    n += a.n;
    n %= mod;
    return *this;
  }
  modint operator+(const modint a) { return modint(*this) += a; }
  modint& operator-=(const modint a) {
    n += (mod - a.n);
    n %= mod;
    return *this;
  }
  modint operator-(const modint a) { return modint(*this) -= a; }
  modint& operator*=(const modint a) {
    n *= a.n;
    n %= mod;
    return *this;
  }
  modint operator*(const modint a) { return modint(*this) *= a; }
  modint& operator/=(modint a) { return (*this) *= a.inverse(); }
  modint operator/(const modint a) { return modint(*this) /= a; }
};
ostream& operator<<(ostream& o, const modint& m) {
  o << m.n;
  return o;
}

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

  int n;
  cin >> n;

  vector<int> cnt = {0, 0, 0};
  modint ans = 1;
  for (int i = 0; i < n; ++i) {
    int m, p = 0, t = 0;
    cin >> m;
    for (int j = 0; j < 3; ++j) {
      if (cnt[j] == m) {
        ++p;
        t = j;
      }
    }
    ans *= p;
    ++cnt[t];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x,i,j,k,lcm,g;
    cin>>n;
    cin>>x;
    lcm=x;
    n--;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        g=__gcd(lcm,x);
        lcm=(lcm/g)*x;
    }
    cout<<lcm<<endl;
}


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

// #pragma comment(linker, "/STACK:1024000000,1024000000")
// #define pi acos(-1)
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.141592653589793//23846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)

#define local
#ifdef local
#endif

#define MAX 10233
#define LCH(i) ((i) << 1)
#define RCH(i) ((i) << 1 | 1)
const int N = 1e3 + 5;

int main()
{
    ios::sync_with_stdio(false);cin.tie(NULL);
    int H, A;
    cin >> H >>A;
    cout << (H + A-1)/A << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;

ll kaijo(ll x){
  if(x==1) return x=1; 
  return x%inf*kaijo(x-1)%inf;
}



int main() {
  ll n,m;
  cin>>n>>m;
  ///
  ll ans=0;
  if(n==m){
    ans+=kaijo(n)%inf*kaijo(m)%inf;
    ans=ans*2%inf;
  }
  if(abs(n-m)==1){
   ans+=kaijo(n)%inf*kaijo(m)%inf; 
  }

  
  
  cout<<ans%inf<<endl;  
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int main() {
	int N, X;
	cin >> N >> X;
	vector<int>x(N);
	rep(i, N) {
		cin >> x[i];
		x[i] = abs(X - x[i]);
	}
	int ans = x[0];
	for(int i = 1; i < N; i++) {
		ans = gcd(ans, x[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
diagram = gets.chomp.chars

search = ->{
  max = min = height = 0
  diagram.each_with_index do |x, i|
    case x
    when "\\"
      height -= 1
      min = height if height < min
    when "/"
      height += 1
      max = height if height > max
    end
  end
  [max - min, max]
}

n, level = search.()
table = Array.new(n) {[]}

diagram.each_with_index do |x, i|
  case x
  when "\\"
    table[level] << i
    level += 1
  when "/"
    level -= 1
    a = table[level].last
    table[level] << i if a
  end
  table
end
table.map! do |one_level|
  one_level.each_slice(2).with_object([]) {|x, ar| ar << x if x.size == 2}
end

calc_area = ->(pair, level) {
  area = pair[1] - pair[0]
  return area if level == n
  table1 = table[level]
  table[level].each do |downer_pair|
    if pair[0] < downer_pair[0] and downer_pair[1] < pair[1]
      table1 -= [downer_pair]
      area += calc_area.(downer_pair, level + 1)
    end
  end
  table[level] = table1
  area
}

pools = []
solve = ->{
  min = [[Float::INFINITY, 0], 0]
  table.each_with_index do |one_level, i|
    next if one_level.empty?
    pair = one_level[0]
    min = [pair, i] if pair[0] < min[0][0]
  end
  table[min[1]] -= [min[0]]
  pools << calc_area.(min[0], min[1] + 1) if min[0][0] != Float::INFINITY
  solve.() unless table.flatten.empty?
}

solve.() unless table.empty?

if pools.empty?
  puts 0, 0
else
  puts pools.inject(&:+)
  puts pools.size.to_s + " " + pools.join(" ")
end


Measured memory_bytes: 123060
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

vector<int> erat(int n) {
    vector<int> primes(n);
    for (int i = 2; i < n; ++i) primes[i] = i;
    for (int i = 2; i*i < n; ++i)
        if (primes[i])
            for (int j = i*i; j < n; j+=i) primes[j] = 0;
    // 素数のみをvectorに格納する場合は以下の行を追加 (0 である要素を全削除)
    // primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
    return primes;
}

const int S = 200010;
signed main() {
    vector<int> primes = erat(S), pseu(S);
    for(int i=1; i<S/2; i++) {
        if(primes[i] && primes[(i+1)/2]) pseu[i] = true;
        pseu[i] += pseu[i-1];
    }


    int Q; cin >> Q;
    rep(i,0,Q) {
        int l, r; cin >> l >> r;
        cout << pseu[r] - pseu[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

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

int main() {
	int N, M, L;
	int A[100][100] = {}, B[100][100] = {};
	cin >> N >> M >> L;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < L; j++) {
			cin >> B[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < L; j++) {
			if (j != 0) cout << " ";
			long long count = 0;
			for (int k = 0; k < M; k++) {
				count += A[i][k] * B[k][j];
			}
			cout << count;
		}
		cout << endl;
	}
}


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

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

    int n;
    cin >> n;
    string S;
    cin >> S;

    for(int oi = 0; oi < 2; oi++){
        for(int oj = 0; oj < 2; oj++){
            string ans = "";
            if(oi == 0) ans += "S";
            else ans += "W";

            if(oj == 0) ans += "S";
            else ans += "W";

            for(int i = 1; i < n - 1; i++){
                if(ans[i] == 'S'){
                    if(S[i] == 'o'){
                        ans += ans[i - 1];
                    }else{
                        ans += (ans[i - 1] == 'S' ? 'W' : 'S');
                    }
                }else{
                    if(S[i] == 'o'){
                        ans += (ans[i - 1] == 'S' ? 'W' : 'S');
                    }else{
                        ans += ans[i - 1];
                    }
                }
            }
            
            bool f = false;
            if(ans[n - 1] == 'S'){
                if(S[n - 1] == 'o'){
                    if(ans[n - 2] == ans[0]){
                        f = true;
                    }
                }else{
                    if(ans[n - 2] != ans[0]){
                        f = true;
                    }
                }
            }else{
                if(S[n - 1] == 'o'){
                    if(ans[n - 2] != ans[0]){
                        f = true;
                    }
                }else{
                    if(ans[n - 2] == ans[0]){
                        f = true;
                    }
                }
            }
            if(!f) continue;
            if(ans[0] == 'S'){
                if(S[0] == 'o'){
                    if(ans[n - 1] == ans[1]){
                        cout << ans << endl;
                        return 0;
                    }
                }else{
                    if(ans[n - 1] != ans[1]){
                        cout << ans << endl;
                        return 0;
                    }
                }
            }else{
                if(S[0] == 'o'){
                    if(ans[n - 1] != ans[1]){
                        cout << ans << endl;
                        return 0;
                    }
                }else{
                    if(ans[n - 1] == ans[1]){
                        cout << ans << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 712
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
# define mod 1000000007

ll arr[100001];
int main()
{
   ll i,j,k,n,m,t,cnt=0,flag=0,prod=1;
   memset(arr,0,sizeof(arr));
   cin >> n;
   if(n==1)
      cout << 0;
   ll a[n];
   for(i=0;i<n;i++)
    cin >> a[i];
   if(n==2)
   {
       cout << abs(a[0]-a[1]);
       return 0;
   }
    arr[0]=0;
    arr[1]=abs(a[0]-a[1]);
    for(i=2;i<n;i++)
        arr[i]=min(arr[i-2]+abs(a[i-2]-a[i]),arr[i-1]+abs(a[i-1]-a[i]));
    cout << arr[n-1];
}


Measured memory_bytes: 5148
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  ll asum = 0, bsum = 0;
  rep(i, n) {
    cin >> a[i];
    asum += a[i];
  }
  rep(i, m) {
    cin >> b[i];
    bsum += b[i];
  }

  int ai = n;
  ll t = asum;
  while (ai >= 1 && t > k) t -= a[--ai];
  int ans = ai;

  ai = 0;
  int bi = m;
  t = bsum;
  while (true) {
    while (bi >= 1 && t > k) t -= b[--bi];
    if (bi == 0) break;
    ans = max(ans, ai + bi);
    if (ai == n) break;
    t += a[ai++];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	string s;
	cin>>s;
	vector<char> vec(26,0);
	for(ll i=0;i<4;i++){
		int c=s[i]-'A';
		vec[c]++;
	}
	ll count=0;
	for(ll i=0;i<26;i++){
		if(vec[i]==2){
			count++;
		}
	}
	if(count==2){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<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 = sc.nextInt();
        int[][] arr = new int[n][2];
        for(int i=0;i<n;i++){
            arr[i] = new int[]{sc.nextInt(),sc.nextInt()};
        }
        Arrays.sort(arr,(a,b) -> a[1]-b[1]);
        int[] min = arr[0];
        int[] max = arr[0];
        long ans = 0;
        for(int i=1;i<n;i++){
            ans = Math.max(Math.max(cmp(min,arr[i]),cmp(max,arr[i])),ans);
            if(arr[i][0]>max[0]){
                if(arr[i][1]-max[1]<arr[i][0]-max[0]) max = arr[i];
            }
            if(arr[i][0]<min[0]){
                if(arr[i][1]-min[1]<min[0]-arr[i][0]) min = arr[i];
            }
        }
        System.out.println(ans);


    }
    static long cmp(int[] a, int[] b){
        return (long)Math.abs(a[0]-b[0])+(long)Math.abs(a[1]-b[1]);
    }
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<int, int> P;

int main(){
    int n, k, s;
    cin >> n >> k >> s;
    int part1, part2;

    if(s == 1000000000) {
        REP(i, k) {
            cout << s << " ";
        }
        REP(i, n-k) {
            cout << 1 << " ";
        }
    } else {
        REP(i, k) {
            cout << s << " ";
        }
        REP(i, n-k) {
            cout << 1000000000 << " ";
        }
    }

    cout << endl;


    return 0;
}

Measured memory_bytes: 1280
import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class Main {
	static int mod = 1000000007;
	static InputReader in = new InputReader(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {

		int n=in.nextInt();
		int T=in.nextInt();
		int ans=mod;
		for(int i=1;i<=n;i++)
		{
			int c=in.nextInt();
			int t=in.nextInt();
			if(t<=T)
				ans=min(ans, c);
		}
		if(ans==mod)
			out.println("TLE");
		else
			out.println(ans);
		out.close();

	}

	static class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}

	private static void tr(Object... o) {
		if (!(System.getProperty("ONLINE_JUDGE") != null))
			System.out.println(Arrays.deepToString(o));
	}
}




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

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



int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());

    while(true)
    {
        string res;
        int m,f,r;
        cin >> m >> f >> r;
        if(m + f + r == -3)break;

        if(m == -1 || f == -1  || m + f < 30)res = "F";
        else if(m + f >= 80)res = "A";
        else if(m + f >= 65)res = "B";
        else if(m + f >= 50)res = "C";
        else
        {
            if(r >= 50)res = "C";
            else res = "D";
        }
        cout << res << endl;
    }

    //cout << endl;

    return 0;    
}




Measured memory_bytes: 3156
#!/usr/bin/env python3
h,w,k = map(int,input().split())
b =[]
for i in range(h):
    s = input()
    b.append(s)
# 縦の切り方を固定すれば、左から見て貪欲に考えることができる。
# どれかの切り方でK+1　以上1 のマスがあれば、そこで切る
if h == 1:
    print(math.ceil(s//k))
    exit()
# リストで現在のそれぞれのブロックの1の数を持つ

# 列の切断が入ったときに全て0に初期化
# bit 全探索は 2 ** h-1 存在する 
ans = h*w #INF
for i in range(2**(h-1)):
    cnt_white = [0] 
    # ループの中で宣言する
    ans_i = 0
    #前処理として、どこに切れ込みがあるかを見て、リストの構成
    for bit in range(h-1):
        if i >> bit & 1:
            cnt_white.append(0)
            ans_i += 1
    #print("i = ",i,cnt_white)
    c = 0
    last_div = 0
    while c < w:# 左から貪欲
        r_idx = 0
        
        for r in range(h):
            if b[r][c] == "1":#対応するブロックのcnt+=1
                cnt_white[r_idx] += 1
                #print("col = ",c,cnt_white,r_idx,ans_i)
            if i >> r & 1:#次にブロックが変わるのでidxを増やす
                r_idx += 1
        # 1行だけでmax(cnt_white) >= k+1になるときはその切り方では不可能
        if max(cnt_white) >= k+1:
            # 戻らないといけない
            ans_i += 1
            if c == last_div:
                ans_i = h*w  #INF
                break
            last_div = c
            c -= 1
            cnt_white = [0]*len(cnt_white)#初期化
            #print("initialize",last_div)
        c += 1
    ans = min(ans,ans_i)
print(ans)

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

int main(){
  string S;
  cin >> S;
  
  int n = S.size(), ans = 0;
  for(int i = 0;i < n;i++){
    int cnt = 0;
    for(int j = i;j < n;j++){
      char b = S.at(j);
      if(b == 'A' || b == 'C' || b == 'G' || b == 'T') cnt++;
      else break;
    }
    ans = max(ans, cnt);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
typedef long double ld;
#define maxn 200001

int N,Q;
vi adj[maxn];
int st[maxn],en[maxn];

int fw[maxn];
int cur = 1;

void upd(int p,int v){ //update position p by +=v
	for (int i=p; i<=N; i+= (i&(-i))){
		fw[i] += v;
	}
}


void update_range(int a,int b, int c){ //update position a to b by +=c
	upd(a,c); //upd function from the PURQ fenwick
upd(b+1,-c);
}

int qry(int p){ //query p
	int ans = 0;
	for (int i = p; i>0; i -= (i&(-i))){
		ans += fw[i];
	}
	return ans;
}



void dfs(int x,int p){
	st[x] = cur++;
	aFOR(i,adj[x]) if (i != p) dfs(i,x);
	en[x] = cur - 1;
}
int32_t main()
{
	cin>>N>>Q;
	
	FOR(i,1,N-1){
		int a,b; cin>>a>>b;
		adj[a].pb(b); adj[b].pb(a);
	}
	dfs(1,-1);
	
	FOR(i,1,Q){
		int p,x; cin>>p>>x;
		
		update_range(st[p],en[p],x);
	}
	
	FOR(i,1,N) cout<<qry(st[i])<<' ';
}


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

int main(){
  int N;
  cin>>N;
  int64_t A=2, B=1;
  for(int i=0;i<N-1;i++){
    int64_t C=B;
    B+=A;
    A=C;
  }
  cout<<B;
}

Measured memory_bytes: 3620
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int A,B,C;cin>>A>>B>>C;
    int K;cin>>K;
    int k = K;
    K -= A;
    if(K<0){
        cout << k << endl;
        exit(0);
    }
    K -= B;
    if(K<0){
        cout << A << endl;
        exit(0);
    }
    cout << A-K << endl;
    return 0;
}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//ori
#define MOD 1000000007
 
int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  int ans = max(A*B,C*D);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  string t;
  rep(3){
    string s;
    cin >> s;
    t += s[0];
  }
  cout << t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
#define     sz(x)           (int)(x).size()
#define     grid            vector<vector<ll> >
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
  //use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

int const maxm = (int)(2e5)  + 5;

ll const lim = (ll)(1e17);

int main()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  IOS;

  ll n, W;

  cin >> n >> W;

  vector<ll> v(n + 1), w(n + 21);

  for (int i = 1; i <= n; i++)
  {
    cin >> w[i] >> v[i];
  }

  grid dp(n + 1, vector<ll>(maxm, lim));

  for (int i = 1; i <= n; i++)
  {
    for (int j = 1; j <= 100005; j++)
    {
      dp[i][j] = min(dp[i - 1][j], dp[i][j]);
      if (v[i] <= j)
      {
        dp[i][v[i]] = min(dp[i][v[i]], w[i]);
        dp[i][j] = min(dp[i - 1][j], w[i] + dp[i - 1][j - v[i]]);

      }
    }
  }

  ll ans = 0;

  for (int i = 1; i <= n; i++)
  {
    for (int j = 1; j < 100005; j++)
    {
      if (dp[i][j] <= W)
      {
        ans = max(ans, (ll)j);
      }
    }
  }

  cout << ans << endl;



}

Measured memory_bytes: 162576
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int m,i,j,k,l,s[100010],n[100010],d[300010]={1};
  s[0]=n[0]=1;
  scanf("%d",&m);
  for(i=1;i<100010;i++)d[i]=1e9;
  for(j=0;s[j]<100000;j++)s[j+1]=s[j]*6;
  for(k=0;n[k]<100000;k++)n[k+1]=n[k]*9;
  //printf("%d %d\n",s[j-1],n[k-1]);
  for(i=0;i<=m;i++){
    d[i+1]=MIN(d[i+1],d[i]+1);
    for(l=0;l<j;l++)d[i+s[l]]=MIN(d[i+s[l]],d[i]+1);
    for(l=0;l<k;l++)d[i+n[l]]=MIN(d[i+n[l]],d[i]+1);
  }
  printf("%d\n",d[m]-1);
  return 0;
}
    
  


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,a[100008],t,nxt,pos[100008];
char op[100008];
LL ans,tmp,suf[100008];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>t;
	for(int i=1;i<n;++i){
		cin>>op[i]>>a[i];
	}
	nxt=n;
	for(int i=n-1;i;--i){
		suf[i]=suf[i+1]+a[i];
		if(op[i]=='-'){
			pos[i]=nxt;
			nxt=i;
		}
	}
	for(int i=1;i<n;++i){
		if(op[i]=='-'){
			ans=max(ans,tmp-(suf[i]-suf[pos[i]])+suf[pos[i]]);
			tmp-=a[i];
		}
		else{
			tmp+=a[i];
			if(i==n-1)	ans=max(ans,tmp);
		}
	}
	cout<<ans+t;
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#define endl "\n"
using namespace std;

void solve(int a)
{

}
const int mxn=1e3;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k,sum=0; cin >> n >> k;int a[n];
    for (int i=0;i<n;++i) cin >> a[i];
    sort(a,a+n); for (int i=0;i<k;++i) sum+=a[i];
    cout << sum;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> vi;
	int XOR = 0;
	int tmp;
	rep (i, N) {
		cin >> tmp;
		vi.push_back(tmp);
		XOR ^= tmp;
	}

	rep (i, N) {
		cout << (vi[i] ^ XOR) << " ";
	}

	return 0;
}

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

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

    ll L, R; cin >> L >> R;

    if (R - L >= 2019) {
        L %= 2019;
        R = 2019;
    } else if (2019 <= L) {
        L %= 2019;
        R %= 2019;
    }

    ll sum = 1000000000000000;
    for (int i = L; i < R; i++) {
        for (int j = i + 1; j <= R; j++) {
            if ((i * j) % 2019 < sum) sum = (i * j) % 2019;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
s=input()
for i in range(0,len(s)-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        exit()

for i in range(0,len(s)-2):
    if s[i]==s[i+2]:
        print(i+1,i+3)
        exit()

print(-1,-1)


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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    vector<int> x(n);
    for(int i = 0;i < n;i ++){
        cin >> x.at(i);
    }
    vector<int> y(n);
    for(int i = 0;i < n;i ++){
        y.at(i) = x.at(i);
    }

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

    for(int i = 0;i < n;i ++){
        if(x.at(i)<= y.at(n/2 -1)){
            cout << y.at(n/2) << endl;;
        }else{
            cout << y.at(n/2-1) << endl;;
        }
    }
}

Measured memory_bytes: 3840
import qualified Data.Map as Map
import Data.Maybe

type Map = Map.Map Char Int

solve :: String -> Int -> Map -> [Int]
solve [] _ _ = []
solve (s:ss) i m = result : solve ss nexti nextm
  where saved = fromMaybe (-1) $ Map.lookup s m
        result = if saved < 0 then i else saved
        nexti = if saved < 0 then i + 1 else i
        nextm = Map.insert s result m

main :: IO ()
main = do
  s <- getLine
  t <- getLine
  let rs = solve s 0 Map.empty
  let rt = solve t 0 Map.empty
  putStrLn $ if rs == rt then "Yes" else "No"

Measured memory_bytes: 38396
n,m = map( int, input().split() )
ab = []
for _ in range(n):
    ab.append( list( map( int, input().split() ) ) )

ab.sort()
sum_money = 0
for i in range(n):
    if m > ab[i][1]:
        sum_money += ab[i][0]*ab[i][1]
        m -= ab[i][1]
    else:
        sum_money += ab[i][0]*m
        break

print(sum_money)

Measured memory_bytes: 60792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
string s;
int main(){
	int N; cin >> N;
	cin >> s;
	map<char,int> mpaf,mpbe;
	for(int i = 0; i < N; i++){
		mpaf[s[i]]++;
	}
	int be = 0, af = 0;
	int ans = 0;
	for(int i = 0; i < N; i++){
		mpbe[s[i]]++;
		mpaf[s[i]]--;
		int num = 0;
		for(char t = 'a'; t <= 'z'; t++){
			if(mpbe[t] > 0 && mpaf[t] > 0) num++;
		}
		ans = max(ans,num);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256