akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<pair<int,int>,int>mm;
const int mod=1000000007;
int power[400005];
map<pair<int,int> ,int>tt;

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(0);   

  #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
  #endif  

      power[0]=1;
      for(int i=1;i<=400000;i++)
      		power[i]=(power[i-1]*2)%mod;
      int n;
      cin>>n;
      int x,y;
      int res1=0,res2=0,res3=0;
      for(int i=0;i<n;i++)
      {
      	cin>>x>>y;
      	if(x==0)
      			res1++;
      	if(y==0)
      			res2++;
      	if(x==0&&y==0)
      			res3++;
        if(x!=0||y!=0)
        {
          int g=__gcd(x,y);
          x/=g;
          y/=g;
        }
      	if(y<0)
      	{
      		y*=-1;
      		x*=-1;      		
      	}
      	mm[{x,y}]++;
      	tt[{x,y}]++;
      }
      int ans=1;
      for(auto i:tt)
      {
      	if(i.first.first==0||i.first.second==0)
      			continue;
      	int z=1;
      	if(i.first.first>=0)
      		z=-1;
      	if(mm[{z*i.first.second,abs(i.first.first)}]==0)
      	{
      		ans*=power[i.second];
      		ans%=mod;
      	}
      	else
      	{
      		if(i.first.first>0)
      				continue;
      		int tot=0;
      		x=0;
      		y=0;
      		x+=i.second;
      		y+=mm[{i.first.second,abs(i.first.first)}];
      		if(i.first.first<0)
      		{
            tot=power[x+y];
      			tot+=mod-((power[x]+mod-1)*(power[y]+mod-1))%mod;
      			tot%=mod;
      			ans*=tot;
      			ans%=mod;
      		}
      	}
      }
  int temp=ans+mod-1;
  res1-=res3;
  res2-=res3;
  int tot=0;
  tot+=power[res1]-1+mod;
  tot+=power[res2]-1+mod;
  tot+=res3+1;
  tot%=mod;
  ans*=tot;
  ans%=mod;
  ans+=mod-1;
  ans%=mod;
  ans+=mod-(temp*(res3))%mod;
  ans%=mod;
  cout<<ans;

}


Measured memory_bytes: 44216
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
-- templete

f cs = g 0 0 cs
  where
    g r s [] = if r<=11 && s>0 then g (r+10) (s-1) [] else if r>21 then 0 else r
    g r s (x:xs)
      | x==1 = g (r+1) (s+1) xs
      | x<=9 = g (r+x) s xs
      | otherwise = g (r+10) s xs

main = do
    c <- getInts
    when (c/=[0]) $ do
        print $ f c
        main
    



Measured memory_bytes: 4040
#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(0);

    int d, t, s;
    cin >> d >> t >> s;

    if(d <= t * s) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 3652
s=input()
list=[]
lhst=[]
for i in range(len(s)):
  list.append(0)
  lhst.append(0)
for j in range(len(s)):
  if j%2==0:
    list[j]=1
  else:
    lhst[j]=1
d=0
e=0
for l in range(len(s)):
  f=int(s[l])
  if list[l]==f:
    d+=1
  else:
    e+=1
print(min(d,e))

Measured memory_bytes: 4848
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a%3 == 0 ||
		b%3 == 0 ||
		(a+b)%3 == 0 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 1772
p,q= input().split()
a,b =(int(p), int(q))
L_list = input().split()
L_list_int = []
count = 0
for i in range(a):
    L_list_int.append(int(L_list[i])) 

for i in range(a + 1):
    if sum(L_list_int[:i]) <= b:
        count += 1
    else:
        break
print(count)

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

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int A, B, C;
	//long long N, M;
	//double d, e;
	//string s, t;
	//vector<int> v;
	//vector<pair<int, int>> pl;

	//while() {}
	//for(int i=0; i<N; i++) {}
	
	cin >> A >> B >> C;
	cout << max(0, C - (A - B));
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
n, m, c = map(int, input().split(' '))

B  = list(map(int, input().split(' ')))

cnt = 0
for i in range(n):
    A = list(map(int, input().split(' ')))
    cnt += sum([a*b for a,b in zip(A,B)]) + c > 0

print(cnt)

Measured memory_bytes: 3060
i = list(map(int, input().split()))

if i[0] > i[1]:
    i[0], i[1] = i[1], i[0]
    
    
    if i[1] > i[2]:
        i[1], i[2] = i[2], i[1]
        
        if i[0] > i[1]:
            i[0], i[1] = i[1], i[0]
        
            
        
    
elif i[1] > i[2]:
    i[1], i[2] = i[2], i[1]
     
    if i[0] > i[1]:
        i[0], i[1] = i[1], i[0]
        
    
print (i[0], i[1], i[2] )


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
vector<int> cnt(100);
int Mketa;

void initCnt (int n) {
  for (int i = 1; i < 100; i++)
  {
    if (i % 10 == 0) continue;
    if (i / 10 == i % 10) {
      cnt[i] = cnt[i % 10];
      cerr << "cnt[" << i << "]=" << cnt[i] << endl;
      continue;
    }
    
    if (i < 10) cnt[i]++;

    int keta = 2;
    while (keta < Mketa) {
      if (keta == 2) {
        cnt[i]++;
        keta++;
        continue;
      }
      int temp = keta - 2;
      int ck = 1;
      while (temp--) {
        ck *= 10;
      }
      cnt[i] += ck;
      keta++;
    }
    int now = i % 10;
    int Mnow = now + 1;
    int ketatemp = keta - 1;
    while (ketatemp--)
    {
      now *= 10;
      Mnow *= 10;
    }
    if (i < 10) now += i;
    else now += i / 10;
    while (now <= min(n, Mnow))
    {
      cnt[i]++;
      if (Mketa == 2) break;
      now += 10;
    }
    cerr << "cnt[" << i << "]=" << cnt[i] << endl;
  }
  
}

int main() {
  int N;
  cin >> N;
  Mketa = 1;
  int temp = N;
  while (temp / 10 > 0) {
    Mketa++;
    temp /= 10;
  }
  cerr << "Mketa=" << Mketa << endl;
  int ans = 0;

  initCnt(N);
  for (int i = 1; i <= N; i++) {
    if (i % 10 == 0) continue;

    int keta = 1;
    int j = i;
    while (j / 10 > 0) {
      keta++;
      j /= 10;
    }
    if (keta > 2) {
      int two = j * 10 + (i % 10);
      ans += cnt[two];
    } else {
      ans += cnt[i];
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
from queue import Queue as Qe

H,W = map(int,input().split())

D = [[-1 for j in range(W)] for i in range(H)]
S = [input() for i in range(H)]

D[0][0] = 1
q = Qe()
q.put((0,0))
White = 1 if S[0][0] == "." else 0
Black = 1 if S[0][0] == "#" else 0
ans = 0

def_h = 0
def_w = 0
while not q.empty():
    h,w = q.get()
    #print(h,w,White,Black)
    if h-1>=0 and S[h][w]!=S[h-1][w] and D[h-1][w] == -1: #up
        if S[h-1][w]=="#":
            ans += White
            Black += 1
        else:
            ans += Black
            White += 1
        D[h-1][w] = 1
        q.put((h-1,w))
    if h+1<H and S[h][w]!=S[h+1][w] and D[h+1][w] == -1: #down
        if S[h+1][w]=="#":
            ans += White
            Black += 1
        else:
            ans += Black
            White += 1
        D[h+1][w] = 1
        q.put((h+1,w))
    if w-1>=0 and S[h][w]!=S[h][w-1] and D[h][w-1] == -1: #left
        if S[h][w-1]=="#":
            ans += White
            Black += 1
        else:
            ans += Black
            White += 1
        D[h][w-1] = 1
        q.put((h,w-1))
    if w+1<W and S[h][w]!=S[h][w+1] and D[h][w+1] == -1: #right
        if S[h][w+1]=="#":
            ans += White
            Black += 1
        else:
            ans += Black
            White += 1
        D[h][w+1] = 1
        q.put((h,w+1))
    if q.empty():
        okei = False
        for i in range(def_h,H):
            wara = def_w if i==def_h else 0
            for j in range(wara,W):
                if D[i][j] == -1:
                    D[i][j] = 1
                    q.put((i,j))
                    White = 1 if S[i][j] == "." else 0
                    Black = 1 if S[i][j] == "#" else 0
                    def_h,def_w = i,j
                    okei = True
                    break
            if okei: break
                
print(ans)

Measured memory_bytes: 5616
N = int(input())
H = list(map(int,input().split()))
cnt = 0
m = 0
for i in range(len(H)-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        m = max(m,cnt)
        cnt = 0
m = max(m,cnt)
print(m)


Measured memory_bytes: 63984
package main

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}

	for i := 0; i < n; i++ {
		if i <= k-1 {
			continue
		}
		if a[i-k] < a[i] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 5992
fun main( args : Array<String> ) { 
  val n  = readLine()!!.toInt()
  val ms = readLine()!!.split(" ").map { it.toInt() }.sorted().reversed()
  val m  = mutableMapOf<Int, MutableList<Int>>()

  ms.mapIndexed { i,x -> 
    val ff = i/2
    if( m[ff] == null) m[ff] = mutableListOf()
    m[ff]?.let { it.add(x) }
  }

  m.map { kv -> 
    val (k, v) = kv
    when { 
      v.size != 1 -> v.min()!!.toInt()
      else        -> 0
    }
  }.reduce { y,x ->
    y+x
  }.let { println(it) }
}


Measured memory_bytes: 36072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
ll exp(ll n, ll k)
{
	if (!k) return 1;
	ll ans = exp(n, k/2);
	ans*=ans;
	ans%=mod;
	if (k%2) 
	{
		ans *= n;
		ans %= mod;
	}
	return ans;
}
ll factorial[500010];
ll nchoosek(ll n, ll k)
{
	ll num = factorial[n];
	ll denom = factorial[k] * factorial[n-k];
	denom %= mod;
	num*=exp(denom, mod-2);
	return num%mod;
}
ll ans, n, a, b, k;
int main()
{
	scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
	factorial[0] = 1;
	for (ll i = 1; i <= 500000; i++) factorial[i] = (factorial[i-1]*i)%mod;
	for (ll i = 0; i <= n; i++)
	{
		ll am = a*i;
		ll need = k-am;
		if (need < 0) continue;
		if (b)
		{
		if (need%b == 0 && need/b <= n)
		{
			ll am = nchoosek(n, i) * nchoosek(n, need/b);
			am %= mod;
			ans += am;
			ans %= mod;
		}
		}
	}
	ans %= mod;
	printf("%lld\n", ans);
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>

int main (){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    int N;std::cin >> N;
    long long sumA=0,ans=0;
    std::vector<long long> A(N,0);for (int i=0;i<N;++i){std::cin >> A[i];sumA+=A[i]; }
    long long modN=1000000007;

    for (int i=0;i<N-1;++i){
        sumA -= A[i];
        ans += A[i] * (sumA % modN);
        ans %= modN;
    }
    std::cout << ans;
    return 0 ;
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007

using namespace std;

ll a, b, c, d, n;

int main() {
    cin >> a >> b >> c >> d;
    cin >> n;
    a *= 4, b *= 2;
    if (n % 2 == 0)
        cout << min(n * a, min(n * b, min(n * c, n / 2 * d))) << endl;
    else
        cout << min(n * a, min(n * b, min(n * c, n / 2 * d + min(a, min(b, c))))) << endl;

	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[list(map(int, input().split())) for i in range(N)]
A.insert(0,[0,0,0])
a=1
for i in range(N):
    d=abs(A[i+1][1]-A[i][1])+abs(A[i+1][2]-A[i][2])
    if d>A[i+1][0]-A[i][0] or d%2!=(A[i+1][0]-A[i][0])%2:
        a=0
        break
if a:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27300
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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


use std::cmp;
use std::collections::VecDeque;

fn main(){
    input! {
        h: usize, w: usize,
        b: [chars; h],
    }

    let mut a = vec![vec!['#';w+2]; h+2];
    let mut q = VecDeque::new();
    for i in 0 .. h {
        for j in 0 .. w {
            let x = b[i][j];
            a[i+1][j+1] = x;
            if x == '#' {
                q.push_front((i+1, j+1, 0));
            }
        }
    }

    let mut ans = 0;
    while let Some((i, j, m)) = q.pop_back() {
        ans = cmp::max(ans, m);
        if a[i-1][j] == '.' { a[i-1][j] = '#'; q.push_front((i-1, j, m+1)); }
        if a[i+1][j] == '.' { a[i+1][j] = '#'; q.push_front((i+1, j, m+1)); }
        if a[i][j-1] == '.' { a[i][j-1] = '#'; q.push_front((i, j-1, m+1)); }
        if a[i][j+1] == '.' { a[i][j+1] = '#'; q.push_front((i, j+1, m+1)); }
    }
   
   println!("{}", ans);
}





Measured memory_bytes: 37428
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/errno.h>

#define READ_BUF_SIZE 1024

static int
read_num (int *out, int max)
{
  char *p;
  char buf[READ_BUF_SIZE];
  int i = 0;
  char format[128];

  sprintf (format, "%%%d[^\n]%%*[^\n]", READ_BUF_SIZE);
  if (scanf (format, buf) == EOF)
    {
      printf ("EOF\n");
      fseek (stdin, 0L, SEEK_SET);
      return -1;
    }
  getchar ();

  for (p = strtok (buf, " "); p; p = strtok (NULL, " "))
    {
      char *endptr = NULL;
      long num = strtol (p, &endptr, 10);
      if (*endptr != '\0' || errno == ERANGE)
	continue;
      else
	out[i++] = num;
      if (i >= max)
	break;
    }
  return i;
}

int
main (int argc, char *argv[])
{
  int input[100];
  read_num (input, 1); 
  int i, j, cnt = 0;

  //printf ("%d\n", input[0]);
  for (i = 1; i <= input[0]; i++)
    {
      int surplus = 0;
      if (i % 2 == 0)
	continue;
      for (j = 1; j <= input[0]; j++)
      {
	if (i % j == 0)
	  surplus++;
      }
      if (surplus == 8)
	cnt++;
    }
  printf ("%d\n", cnt);
  return 0;
}


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

int main() {
    string data;

    while (cin >> data) {
        if (data == "0") break;
        int score[2] = {0};
        for (int i = 1, l = data.size(); i < l; i++) {
            score[data[i] == 'B']++;
        }
        score[score[0]<score[1]]++;
        cout << score[0] << " " << score[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    N=ii()
    P = tuple(tuple(mis()) for _ in range(N))
    ans = 0
    def length(prv, nex):
        if prv is None:
            return 0
        else:
            return ((P[nex][0]-P[prv][0])**2 + (P[nex][1]-P[prv][1])**2) ** 0.5

    def rec(bf, val, prev):
        nonlocal ans
        if bf == 2**N-1:
            ans += val
        else:
            for i in range(N):
                b = 1 << i
                if not bf & b:
                    rec(bf | b, val + length(prev, i), i)

    rec(0, 0, None)

    for i in range(1, N+1):
        ans /= i
    
    print(ans)

main()


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 

vector<int>dx={0,1,0,-1},dy={1,0,-1,0};
const int N=60,inf=1e18;
int a[N],B[N],S[N];
int G[N][N];

int32_t main()
{
	IOS
	int n,m;cin>>n>>m;
	rpqi pq;
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;pq.push(x);
	}
	vii cb(m);
	for(int i=0;i<m;i++)cin>>cb[i].second>>cb[i].first;
	rsrt(cb);
	for(int i=0;i<m;i++)
	{
		int b=0;
		while(b < cb[i].second && pq.top() < cb[i].first)
		{
			pq.pop();pq.push(cb[i].first);b++;
		}
	}
	int ans=0;
	while(pq.size())
	{
		ans+=pq.top();pq.pop();
	}
	cout<<ans<<endl;
	

}


Measured memory_bytes: 2804
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

s64 T1, T2;
s64 A1, A2;
s64 B1, B2;

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

    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

    s64 diff = A1 * T1 + A2 * T2 - B1 * T1 - B2 * T2;
    if (diff == 0)
    {
        cout << "infinity\n";
        return 0;
    }

    u64 ans = 0;
    s64 diffAB1 = A1 * T1 - B1 * T1;
    s64 diffAB2 = A2 * T2 - B2 * T2;

    s64 temp1 = diffAB1 / diff;
    s64 temp2 = (diffAB2 - diffAB1) / diff;

    if ( temp1 < 0 || (temp1 == 0 && temp2 > 0) )
    {
        if (temp1 * diff == diffAB1) ans = 2 * (abs(temp1) - 1) + 2;
        else ans = 2 * abs(temp1) + 1;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
//problem_c.go

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	//"strings"
)

const (
	mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

// -----------------------------------------

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntSlice(n int) []int {
	ns := []int{}
	for i := 0; i < n; i++ {
		ns = append(ns, getInt())
	}
	return ns
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStringSlice(n int) []string {
	ss := []string{}
	for i := 0; i < n; i++ {
		ss = append(ss, getString())
	}
	return ss
}

func sortIntSlice(ns []int) []int {
	sort.Sort(sort.IntSlice(ns))
	return ns
}

func rsortIntSlice(ns []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(ns)))
	return ns
}

// -----------------------------------------

func solve() {
	n := getInt()
	a := getIntSlice(n)

	flag := true

	a = sortIntSlice(a)

	for i := 0; i < n-1; i++ {
		if a[i] == a[i+1] {
			flag = false
		}
	}

	if flag {
		fmt.Fprintln(wr, "YES")
	} else {
		fmt.Fprintln(wr, "NO")
	}
}

// -----------------------------------------

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}


Measured memory_bytes: 10624
s = input()
new_s = []
for i in range(len(s)):
    if s[i] != "x":
        new_s.append(s[i])

for i in range(len(new_s)):
    if new_s[i] != new_s[-1-i]:
        print(-1)
        exit()

i = 0
j = len(s) - 1
cnt = 0
while True:
    if  i > j:
        break
    if s[i] == s[j]:
        i += 1
        j -= 1
    else:
        if s[i] == "x":
            cnt += 1
            i += 1
        else:
            cnt += 1
            j -= 1
print(cnt)

Measured memory_bytes: 3956
#include<stdio.h>
int main(){
	int a,b,n;
	scanf("%d%d",&a,&b);
	if(a<b){n=b*2-1;}
	if(a==b){n=b*2;}
	if(b<a){n=a*2-1;}
	printf("\n%d",n);
	return 0;
}

Measured memory_bytes: 128
import collections
from operator import mul
from functools import reduce

def C(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n = input()
n = int(n)
x = []
for i in range(n):
  l = input()
  x.append(''.join(sorted(l)))

c = collections.Counter(x)
values, counts = zip(*c.most_common())
sum = 0
for i in range(len(counts)):
  if counts[i] > 1:
    sum += C(counts[i], 2)

print(sum)

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

int main()
{
  int n;
  cin>>n;
  vector<int> h(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  vector<int> memo(n,-1);
  memo[0]=0;
  memo[1]=abs(h[1]-h[0]);
  
  for(int i=2;i<n;i++)
  {
    memo[i]=min(memo[i-1]+abs(h[i]-h[i-1]),memo[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<memo[n-1]<<endl;
  
}

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


int main(){

    int A, B;
    cin >> A >> B;
    if (A - 2 * B > 0) {
        cout << A - 2 * B << endl;
    } else {
        cout << 0 << endl;
    }
}

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

int main(){
  int x,y;
  cin >> x >> y;
  set<int> g;
  g.insert(4);
  g.insert(6);
  g.insert(9);
  g.insert(11);
  if(x == 2 || y == 2) cout << "No" << endl;
  else if(g.count(x) == g.count(y)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

//Common
using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;template<typename T> using Func=function<T>;template<typename T> using Str=basic_string<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQ std::priority_queue

//Math
template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
template<typename T> inline T sq(T x){return x*x;}
cxp int lgc(int x){return 64-__builtin_clzll(x-1);}
cxp int lgf(int x){return 63-__builtin_clzll(x);}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1), eps=1e-10;

//IO
template<typename T>ostream& operator<<(ostream& s, const Arr<T>& a) {for(auto i:a) cout<<i<<' '; return s;}
int getint(){int x;cin>>x;return x;}
char getchr(){char x;cin>>x;return x;}
#ifndef DEBUG
	//#pragma GCC optimize ("Ofast") //somtimes it become more slower
	auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif

//Misc
int sz(const auto& x){return x.size();}
auto split(auto s, auto p){
	Arr<decltype(s)> ret;
	auto it1=s.begin();
	for(auto it2=it1; (it2 = find(it1,s.end(),p)) != s.end(); it1=it2+1)
		ret.pushb({it1, it2});
	ret.pushb({it1,s.end()});
	return ret;
}
template<typename T> T rev(const T& a){return {a.rbegin(),a.rend()};}
Arr<int> range(int n){ Arr<int> ret(n); rep(i,n)ret[i]=i; return ret; }
struct defer{ defer(auto f):f(f){} ~defer(){f();} function<void()> f; };
#define defer(x) auto _##__COUNTER__ = defer([&](){x;});
#define lam(expr, ...) [&](__VA_ARGS__){return expr;}
#define reduce accumulate

#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

signed main(){
	int n; cin>>n;
	int a[n];
	rep(i,n)
		cin>>a[i];
	sort(a,a+n);
	a[n-1]/=2;
	cout<<accumulate(a,a+n,0)<<endl;
	return 0;
}



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

int main()
{
    int n;cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    vector<int> d(n);
    int i,j;
    for(i=0;i<n;i++)cin>>a.at(i)>>b.at(i);
    for(i=0;i<n;i++)cin>>c.at(i)>>d.at(i);
    vector<pair<int,int>> pb(n);
    vector<int> pairbr(n,-1);
    vector<int> pairrb(n,-1);
    for(i=0;i<n;i++)pb.at(i)=make_pair(c.at(i),d.at(i));
    sort(pb.begin(),pb.end());
    int ymax;
    int ch;
    for(i=0;i<n;i++)
    {
        ymax=-1;
        ch=-1;
        for(j=0;j<n;j++)
        {
            if(b.at(j)>ymax&&pb.at(i).first>a.at(j)&&pb.at(i).second>b.at(j)&&pairrb.at(j)==-1)
            {
                ymax=b.at(j);
                ch=j;
            }
        }
        if(ch!=-1)
        {
            pairbr.at(i)=ch;
            pairrb.at(ch)=i;
        }
    }
    int ans=0;
    for(i=0;i<n;i++)if(pairbr.at(i)!=-1)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
// AtCoder Beginner Contest 081
// B - Shift only
#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);}

  int count = 0;
  bool shift_flg = true;
  while (shift_flg == true) {
    for (int i = 0; i < n; i++) {
      if (a.at(i) % 2 != 0) {
        shift_flg = false;
        break;
      }

      a.at(i) /= 2;
    }

    if (shift_flg == true) {count++;}
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
(n,k),p,c=[[*map(int,t.split())]for t in open(0)]
a=-9e9
for i in range(n):
 s=f=j=0;x,*l=i,
 while~f:x=p[x]-1;s+=c[x];l+=s,;f-=x==i
 for t in l[:k]:j-=1;a=max(a,t+(j+k)//len(l)*s*(s>0))
print(a)

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

int main(){
    int A,B,Q;
    cin>>A>>B>>Q;
    vector<int64_t> S(A),T(B);
    for(auto &s:S) cin>>s;
    for(auto &t:T) cin>>t;
    for(int i=0;i<Q;i++){
        int64_t x;
        cin>>x;
        int64_t ls,lt,rs,rt;
        if(x<S[0]) ls=-1e12;
        else ls=*--upper_bound(S.begin(), S.end(),x);
        if(x<T[0]) lt=-1e12;
        else lt=*--upper_bound(T.begin(), T.end(),x);
        if(x>S.back()) rs=1e12;
        else rs=*upper_bound(S.begin(), S.end(),x);
        if(x>T.back()) rt=1e12;
        else rt=*upper_bound(T.begin(), T.end(),x);
        int64_t ans = 1e12;
        ans=min(ans,max(rs,rt)-x);
        ans=min(ans,x-min(ls,lt));
        ans=min(ans,rs-lt+min(rs-x,x-lt));
        ans=min(ans,rt-ls+min(rt-x,x-ls));
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 2944
from collections import deque

n,m=map(int,input().split())
l=[[] for i in range(n)]
ans=[-1]*n
flag=[False]*n
q=deque([0])
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    l[a].append(b)
    l[b].append(a)
flag[0]=True
while len(q)>0:
    now=q[0]
    q.popleft()
    for i in l[now]:
        if flag[i]:
            continue
        ans[i]=now
        flag[i]=True
        q.append(i)
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

Measured memory_bytes: 35508
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
from itertools import combinations as comb

def subsets(L):
    for i in range(len(L) + 1):
        for c in comb(L, i):
            yield c


def ri():
    return int(input())

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


def solve():
    h, w, k = rl()
    grid = []
    for i in range(h):
        grid.append(input())


    def test(rows, cols):
        blacks = 0
        for i in range(h):
            if i in rows:
                continue
            for j in range(w):
                if j in cols:
                    continue
                if grid[i][j] == "#":
                    blacks += 1
        return blacks

    ans = 0
    for rowset in subsets(range(h)):
        for colset in subsets(range(w)):
            if test(rowset, colset) == k:
                ans += 1

    print (ans)





mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 74908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

const int INF = 1e9;

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

    int N;
    cin >> N;
    vector<int> V(N+1), W(N+1);
    for (int i = 1; i <= N; i++) cin >> V[i] >> W[i];
    vector<vector<pair<int, int>>> vals(min(1 << 10, N + 1));
    vals[0].push_back({0, 0});
    for (int i = 1; i < min(1 << 10, N + 1); i++) {
        vals[i] = vals[i / 2];
        for (auto& p : vals[i / 2]) {
            vals[i].push_back({p.first + W[i], p.second + V[i]});
        }
        sort(ALL(vals[i]));
        REP(j, vals[i].size()-1) {
            if (vals[i][j].second > vals[i][j+1].second) {
                vals[i][j+1].second = vals[i][j].second;
            }
        }
    }
    int Q;
    cin >> Q;
    REP(q, Q) {
        int v, L;
        cin >> v >> L;
        int ans = 0;
        if (v < (1 << 10)) {
            auto it = lower_bound(ALL(vals[v]), make_pair(L, INF));
            ans = (--it)->second;
        } else {
            vector<pair<int, int>> vals2;
            vals2.push_back({0, 0});
            while (v >= (1 << 10)) {
                vector<pair<int, int>> tmp;
                for (auto& p : vals2) {
                    tmp.push_back({p.first + W[v], p.second + V[v]});
                }
                vals2.insert(vals2.end(), ALL(tmp));
                v /= 2;
            }
            for (auto& p : vals2) {
                if (p.first > L) continue;
                auto it = lower_bound(ALL(vals[v]), make_pair(L - p.first, INF));
                ans = max(ans, (--it)->second + p.second);
            }
        }
        cout << ans << '\n';
    }
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    vector<Vi> is_open(N, Vi(10));
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < 10; j++) {
            cin >> is_open[i][j];
        }
    }
    vector<Vl> P(N, Vl(11));
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    ll ans = -L_INF;
    for (ll mask = 1; mask < (1LL << 10); mask++) {
        ll score = 0;
        for (ll i = 0; i < N; i++) {
            ll cnt = 0;
            for (ll j = 0; j < 10; j++) {
                if ((mask >> j) & 1 && is_open[i][j]) {
                    ++cnt;
                }
            }
            score += P[i][cnt];
        }
        ans = max(ans, score);
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

typedef struct dice {
  int a[6];
  void change(char ch) {
    if(ch == 'E') {
      int temp = a[0];
      a[0] = a[3];
      a[3] = a[5];
      a[5] = a[2];
      a[2] = temp;
    }
    if(ch == 'N') {
      int temp = a[0];
      a[0] = a[1];
      a[1] = a[5];
      a[5] = a[4];
      a[4] = temp;
    }
    if(ch == 'S') {
      int temp = a[0];
      a[0] = a[4];
      a[4] = a[5];
      a[5] = a[1];
      a[1] = temp;
    }
    if(ch == 'W') {
      int temp = a[0];
      a[0] = a[2];
      a[2] = a[5];
      a[5] = a[3];
      a[3] = temp;
    }
  }
  int query(int x) { return a[x]; }
} dice;

int main(void) {
  dice a;
  for(int i = 0; i < 6; i++) {
    cin >> a.a[i];
  }
  int q;
  cin >> q;
  for(int i = 0; i < q; i++) {
    int front, top;
    cin >> top >> front;
    char d[8] = {'N', 'N', 'N', 'N', 'E', 'N', 'N', 'N'};
    for(int j = 0; j < 8; j++) {
      if(a.query(1) == front) {
        break;
      }
      a.change(d[j]);
    }
    while(a.query(0) != top)
      a.change('E');
    cout << a.query(2) << endl;
  }

  return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=350;
int main(){
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<s.size();i++){
        if(i%2){
            if(s[i]=='1') a++;
            else b++;
        }
        else{
            if(s[i]=='1') b++;
            else a++;
        }
    }
    cout<<min(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 512
from collections import defaultdict
n = int(input())

d = defaultdict(int)
for _ in range(n):
    key = input()
    d[key] += 1

dict = sorted(d.items(), key=lambda x:x[1], reverse=True)
max_v = max(d.values())

dict_li = []
for a in dict:
    if a[1]==max_v:
        dict_li.append(a[0])

dict_li.sort()
for s in dict_li:
    print(s)


Measured memory_bytes: 46080
n, m = [int(x) for x in input().split()]
transitions = [list(map(int,input().split())) for _ in range(m)]
one_roots = set()
second_roots = set()
for transition in transitions:
    if transition[0] == 1:
        one_roots.add(transition[1])
    if transition[1] == n:
        second_roots.add(transition[0])

print('POSSIBLE' if len(one_roots.intersection(second_roots)) > 0 else 'IMPOSSIBLE')


Measured memory_bytes: 58888
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

int dist[5][5];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    int p,q,r;
    cin>>p>>q>>r;
    
    REP(i,1,3)REP(j,1,3)dist[i][j] = OO;
    REP(i,1,3)dist[i][i] = 0;
    
    dist[1][2] = p;
    dist[2][3] = q;
    dist[3][1] = r;
    
    REP(k,1,3){
        REP(i,1,3){
            REP(j,1,3){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    int ans = OO;
    vector<int>vec;
    REP(i,1,3)vec.pb(i);
    
    do{
        cerr << "test" << endl;
        int tmp = dist[vec[0]][vec[1]] + dist[vec[1]][vec[2]];
        ans = min(ans, tmp);
    }while(next_permutation(vec.begin(), vec.end()));
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int max(int a,int b){
  if(a < b){
    return b;
  }else{
    return a;
  }
}

int main(void){
  int N;
  int b[2][101]={0};
  int sum[2][101]={0};
  int i,j;
  scanf("%d",&N);
  for(j = 0;j < 2;j++){
    for(i = 0;i < N;i++){
      scanf("%d",&b[j][i]);
    }
  }
  sum[0][0] = b[0][0];
  sum[1][0] = b[1][0]+b[0][0];
  for(j = 0;j < 2;j++){
    for(i = 1;i < N;i++){
      if(j == 0){
        sum[j][i] = sum[j][i-1]+b[j][i];
      }else{
        sum[j][i] = max(sum[j][i-1],sum[j-1][i])+b[j][i];
      }
    }
  }
  printf("%d\n",sum[1][N-1]);
  return 0;
}

Measured memory_bytes: 128
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools

setrecursionlimit(10**7)

def input():
  return stdin.readline().strip()

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, A, B, C, D = reads()
S = input()

def reachable(i, j):
  return not any(S[k] == S[k+1] == "#" for k in range(i, j))

def swappable(i, j):
  return any(S[k-1] == S[k] == S[k+1] == "." for k in range(i, j+1))

A, B, C, D = A-1, B-1, C-1, D-1

possible = reachable(A, C) and reachable(B, D)

if D < C:
  # A < B < D < C
  swapl = swappable(B, D)
  possible = possible and swapl

print("Yes" if possible else "No")

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

#define CO const
#define IN inline
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

CO int mod=1e9+7;
IN int add(int a,int b){
	return (a+=b)>=mod?a-mod:a;
}
IN int mul(int a,int b){
	return (int64)a*b%mod;
}
IN int fpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1) ans=mul(ans,a);
	return ans;
}

int p2[106];
int g[15][15];
int c[1<<15],d[1<<15];
int f[2][1<<15];

int main(){
	int n=read<int>(),m=read<int>();
	p2[0]=1;
	for(int i=1;i<=m;++i) p2[i]=mul(p2[i-1],2);
	for(int i=1;i<=m;++i){
		int x=read<int>()-1,y=read<int>()-1;
		g[x][y]=1; // x<y
	}
	for(int s=0;s<1<<n;++s)
		for(int i=0;i<n;++i)for(int j=i+1;j<n;++j)
			if(g[i][j]){
				if(s>>i&1 and s>>j&1) c[s]+=g[i][j];
				if(s>>i&1 or s>>j&1) d[s]+=g[i][j];
			}
	for(int o=0;o<2;++o)for(int s=0;s<1<<n;++s){
		if(~s>>o&1) continue;
		f[o][s]=p2[c[s]];
		for(int t=(s-1)&s;t;t=(t-1)&s){
			if(~t>>o&1) continue;
			f[o][s]=add(f[o][s],mod-mul(f[o][t],p2[c[s-t]]));
		}
	}
	int ans=p2[m];
	for(int s=0;s<1<<n;++s){
		if(~s&1 or s>>1&1) continue;
		for(int t=(1<<n)-1-s;t;t=(t-1)&((1<<n)-1-s)){
			if(~t>>1&1 or c[s]+c[t]<c[s|t]) continue;
			ans=add(ans,mod-mul(f[0][s],mul(f[1][t],p2[m-d[s|t]])));
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

int main()
{
int A;
int B;
int C;
char S[ 100 ];

	cin >> S;

	A = atoi( S );
	B = atoi( S + 5 );
	C = atoi( S + 8 );

	if( B > 4 )
		cout << "TBD" << endl;
	else if( B < 4 )
		cout << "Heisei" << endl;
	else if( C > 30 )
		cout << "TBD" << endl;
	else
		cout << "Heisei" << endl;

	return 0;
}


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

int main(){
  int N; 
  string prefix,suffix;
  cin >> N >> prefix >> suffix;

  int len_common= N;
  while(len_common > 0){
    bool is_satisfied= true;
    int offset= N- len_common;
    for(int i=0; i<len_common; i++){
      if(prefix.at(offset+ i) != suffix.at(i)){
        is_satisfied= false;
        break;
      }
    }
    if(is_satisfied){ break; }

    len_common--;
  }

  int ans= 2*N- len_common;

  cout << ans << endl;
}

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


int main()
{
	int a,b,c,x,y,s1=0,s2=0,s3=0;
	cin>>a>>b>>c>>x>>y;
	s1+=a*x+b*y;
	if(x>=y)
	{
		s2+=c*2*y;
		s2+=a*(x-y);
	}
	else 
	{
		s2+=c*2*x;
		s2+=b*(y-x);
	}
	s3+=c*max(x,y)*2;
	cout<<min(s1,min(s2,s3));
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    n %= 10;

    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)cout << "hon" << endl;
    else if(n == 0 || n == 1 || n == 6 || n == 8)cout << "pon" << endl;
    else cout << "bon" << endl;


    return 0;
}

Measured memory_bytes: 3596
import scala.annotation.tailrec
import scala.collection.mutable


import scala.io.StdIn._
object Main extends App {
  val letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  solve(readLine.trim)
  @tailrec def solve(arg: String): Unit = {
    if (arg != ".") {
      println(arg.foldLeft(List(Nil): List[List[Char]]){
        case (list, '?') ⇒ list.flatMap(l ⇒ letters.map(c ⇒ c::l))
        case (list, c) ⇒ list.map(l ⇒ c::l)
      }.map(_.reverse).flatMap {l ⇒
        l match {
          case Chiper(chiper, Nil) ⇒ Some(chiper.mkString(""))
          case _ ⇒ None
        }
      } match {
        case Nil ⇒ "."
        case l ⇒ l.min
      })
      solve(readLine.trim)
    }

  }
  object Chiper {
    def unapply(arg: List[Char]): Option[(List[Char], List[Char])] = {
      arg match {
        case l LetterSeq rest ⇒
          rest match {
            case Nil ⇒ Some(l, Nil)
            case c Chiper r ⇒ Some(l ++ c, r)
            case _ ⇒ Some(l, rest)
          }
        case _ ⇒ None
      }
    }
  }
  object Letter {
    def unapply(arg: List[Char]): Option[(Char, List[Char])] = {
      arg match {
        case '+'::(l Letter t) ⇒ Some((((l + 1 - 'A') % 26 + 'A').toChar, t))
        case '-'::(l Letter t) ⇒ Some((((l + 25 - 'A') % 26 + 'A').toChar, t))
        case c::r if c.isLetter ⇒ Some((c, r))
        case _ ⇒ None
      }
    }
  }
  object LetterSeq {
    def unapply(arg: List[Char]): Option[(List[Char], List[Char])] = {
      arg match {
        case '['::(seq Chiper ']'::rest) ⇒ Some((seq.reverse, rest))
        case c Letter (seq LetterSeq rest) ⇒ Some((c :: seq, rest))
        case c Letter rest ⇒ Some((List(c), rest))
        case _ ⇒ None
      }
    }
  }
}


Measured memory_bytes: 586540
#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);
    }
    int count=0;
    int min=10000;
    int sum1=0;
    int sum2=0;
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<count; j++)
        {
            sum1+=A.at(j);
        }
        for(int k=count; k<N; k++)
        {
            sum2+=A.at(k);
        }
        if(min>abs(sum1-sum2))
        {
            min=abs(sum1-sum2);
        }
        count++;
        sum1=0;
        sum2=0;
    }
    cout << min << endl;
}


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

int main() {
  int N, Y;
  cin >> N >> Y;
  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N; y++) {
      int z = N - x - y;
      if (10000 * x + 5000 * y + 1000 * z == Y && 0 <= z && z <= N) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int m = scanner.nextInt();
        int d = scanner.nextInt();
        int ans = 0;
        for(int i = 22; i <= d; i++) {
            int f = i / 10;
            int s = i % 10;
            if (f <2 || s < 2) continue;
            if (s * f <= m) ans++;
        }
        out.println(ans);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

const lint mod = 1e+9 + 7;
lint n;
vector<lint> c;

// a^n mod pを計算　O(log n)
long long pow_mod(long long a, long long n, long long p) {
    if (n == 0) return 1;
    if (n & 1) return pow_mod(a, n - 1, p) * a % p;
    long long temp = pow_mod(a, n / 2, p);
    return temp * temp % p;
}

int main() {
    cin >> n;
    c.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());
    lint ans = 0;
    for (int i = 0; i < n; i++) {
        lint add = c[i] * (n - i + 1) % mod;
        ans = (ans + add) % mod;
    }
    cout << ans * pow_mod(4, n - 1, mod) % mod << endl;
}

Measured memory_bytes: 1792