akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 1e6 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 84
// mbeginer 162
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];
//vector<ll>adj[e];

/*ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}*/

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/


int main()
{
    vector<ll>kt(100000, 0);
    kt[1] ++;
    for(int i=2; i*i<=100000; i++)
    {
        if(kt[i] == 0)
        {
            //cout << i <<" ";
            for(int j=i*i; j<=100000; j+=i)
            {
                kt[j] ++;
            }
        }
    }
    vector<ll>dp(100000, 0);
    for(int i=2; i<=100000; i++)
    {
        dp[i] = dp[i-1];
        if(kt[i] == 0 && kt[(i+1)/2] == 0)
        {
            dp[i] ++;
        }
    }
    int q;
    cin >> q;
    while(q -- )
    {
        int x, y;
        cin >> x >> y;
        cout << dp[y] - dp[x-1] <<"\n";
    }
}
/*

*/


Measured memory_bytes: 2176
n = int(input())
A = list(map(int, input().split(' ')))
q = int(input())
M = list(map(int, input().split(' ')))
sumA = sum(A)
minA = min(A)
def solve(i, A, target):
    global sumA
    global n
    if target == 0:
        return True
    if i >= n:
        return False
    return solve(i+1, A, target) or solve(i+1, A, target-A[i])

for i in range(q):
    if M[i] > sumA or M[i] < minA:
        print('no')
    else:
        flag = solve(0,A,M[i])
        if flag:
            print('yes')
        else:
            print('no')


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string n;
  cin >> n;
  if(n[0]=='7'||n[1]=='7'||n[2]=='7')cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    vector<pair<int,int>> a(n);
    rep(i,n) {
        a[i].second = i+1;
        cin >> a[i].first;
    }
    sort(a.begin(), a.end());
    rep(i,n) {
        cout << a[i].second;
        cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
m, k = map(int, input().split())
if k >= 2**m:
  print(-1)
  exit()
if m == 0:
  print(0, 0)
elif m == 1:
  if k == 0:
    print(0, 1, 1, 0)
  else:
    print(-1)
else:
  b = [i for i in range(2**m) if i != k]
  c = b[::-1]
  A = b + [k] + c + [k]
  print(*A)

Measured memory_bytes: 17296
#include <stdio.h>
int koko(int n,int k){
	if(n==1){
		return k;
	}
	else if(n%2==0){
		n=n/2;
		k++;
		return koko(n,k);
	}
	else{
		n=3*n+1;
		k++;
		return koko(n,k);
	}
}
int main(void) {
	while(1){
		int n,k=0;
		scanf("%d",&n);
		if(n==0) break;
		printf("%d\n",koko(n,k));
	}
	return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdexcept>
#include <cstdlib>

using namespace std;

struct Vec2
{
    int x, y;
};

struct RobotState
{
    Vec2 pos;
    int dir; // 0, 1, 2, 3
};

Vec2 dd [] = { {0, -1}, {1, 0}, {0, 1}, {-1, 0} };

void DirectToEmptyCell(const vector<vector<char>> &maze, RobotState &robot)
{
    while (maze[robot.pos.y + dd[robot.dir].y][robot.pos.x + dd[robot.dir].x] == '#')
    {
        robot.dir = (robot.dir + 1) % 4;
    }
}

void GoForward(RobotState &robot)
{
    auto d = dd[robot.dir];
    robot.pos.x += d.x;
    robot.pos.y += d.y;
}

int DirCharToInt(char c)
{
    switch (c)
    {
    case 'N':
        return 0;
    case 'E':
        return 1;
    case 'S':
        return 2;
    case 'W':
        return 3;
    default:
        throw logic_error("unko");
    }
}

char DirIntToChar(int dir)
{
    static const char m[] = { 'N', 'E', 'S', 'W' };
    return m[dir];
}

int main()
{
    int H, W;
    long long L;
    while (cin >> H >> W >> L, H || W || L)
    {
        vector<vector<char>> maze(H + 2, vector<char>(W + 2, '#'));
        long long visited[102][102][4];
        for (size_t i = 0; i < 102; i++)
            for (size_t j = 0; j < 102; j++)
                for (size_t k = 0; k < 4; k++)
                {
                    visited[i][j][k] = -1;
                }
        RobotState robot;
        // input maze
        for (int i = 1; i < H + 1; ++i) 
        {
            for (int j = 1; j < W + 1; ++j)
            {
                char c;
                cin >> c;
                if (c == '.' || c == '#')
                {
                    maze[i][j] = c;
                }
                else
                {
                    maze[i][j] = '.';
                    robot.pos.x = j;
                    robot.pos.y = i;
                    robot.dir = DirCharToInt(c);
                }
            }
        }
        // do this
        for (long long i = 0; i < L; ++i)
        {
            // detect loop
            auto& n = visited[robot.pos.y][robot.pos.x][robot.dir];
            if (n != -1)
            {
                i = L - (L - i) % (i - n);
                if (i == L)
                {
                    break;
                }
            }
            else
            {
                n = i;
            }
            
            DirectToEmptyCell(maze, robot);
            GoForward(robot);
        }
        cout << robot.pos.y << ' ' << robot.pos.x << ' ' << DirIntToChar(robot.dir) << endl;
    }

    return 0;
}

Measured memory_bytes: 3348
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

type Item struct {
  Comparison int
  Index int
}
type PriorityQueue []*Item
func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
  return pq[i].Comparison < pq[j].Comparison
}
func (pq PriorityQueue) Swap(i, j int) {
  pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Pop() interface{} {
  old := *pq
  n := len(old)
  item := old[n - 1]
  *pq = old[0:n - 1]
  return item
}
func (pq *PriorityQueue) Push(x interface{}) {
  item := x.(*Item)
  *pq = append(*pq, item)
}
func InitPQ(Q *[]int) PriorityQueue {
  var PQ PriorityQueue
  for i, q := range (*Q) {
    heap.Push(&PQ, &Item{q, i})
  }
  return PQ
}

func main() {
  N := NextInt()
  T := make([][]int, N)
  for i := range T {
    T[i] = make([]int, 0)
  }
  D := make([]int, N)
  for i := 0; i < N - 1; i++ {
    ab := NextIntVec()
    a := ab[0] - 1
    b := ab[1] - 1
    T[a] = append(T[a], b)
    T[b] = append(T[b], a)
    D[a] += 1
    D[b] += 1
  }
  C := NextIntVec()
  sort.Ints(C)
  W := make([]int, N)
  PQ := InitPQ(&D)
  cnt := 0
  for i := 0; i < N; i++ {
    for {
      node := heap.Pop(&PQ).(*Item)
      //if node.Comparison != D[node.Index] { continue }
      if W[node.Index] > 0 { continue }
      W[node.Index] = C[i]
      for _, adj := range T[node.Index] {
        if W[adj] > 0 { continue }
        D[adj] -= 1
        heap.Push(&PQ, &Item{D[adj], adj})
      }
      cnt += node.Comparison * W[node.Index]
      break
    }
  }
  Write(cnt)
  ans := strconv.Itoa(W[0])
  for i := 1; i < N; i++ {
    ans += " " + strconv.Itoa(W[i])
  }
  Write(ans)
  Output()
}

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

int main(){
    string s,ssub;
    cin >> s;
    int i=0,count=0;
    for(i=0;i<8;i++){
        ssub=s;
        ssub=ssub.erase(i,s.size()-7);
        //cout << ssub << endl;
        if(ssub=="keyence")count++;
    }
    if(count!=0)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a + b >= 10) {
			System.out.println("error");
		} else {
			System.out.println(a+b);
		}
		sc.close();
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 1e5 + 5;
long long n, x, cnt;
long long a[maxn];
int main(){
	cin >> n >> x;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
		if(a[i] + a[i - 1] <= x){
			continue;
		}
		cnt += abs(a[i] + a[i - 1] - x);
		a[i] = x - a[i - 1];
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define uint unsigned int
#define ull unsigned long long
#define solid const auto &
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define gm int mid((l+r)/2)
#define space putchar(' ')
#define enter putchar('\n')
#define rd() ({ri t;in(t);t;})
#define Size(x) ((int)x.size())
#define mem(x,y) memset(x,y,sizeof(x))
template<class T>il void in(T &x)
{
	x=0; char c=getchar(); bool f=0;
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=x*10+(c^'0'),c=getchar();
	f?x=-x:0;
}
template<class T>il void out(T x,const char c='\n')
{
	static short st[30]; short m=0;
	if(x<0) {if(x==-2147483648) {printf("-2147483648"); return;} putchar('-'),x=-x;}
	do st[++m]=x%10,x/=10; while(x);
	while(m) putchar(st[m--]|'0');
	putchar(c);
}
template<class T,class ...Args>il void in(T &x,Args &...args) {in(x); in(args...);}
template<class T,class ...Args>il void out(const T &x,const Args &...args) {out(x,' '); out(args...);}
template<class T>il void prt(T a[],int n) {for(ri i=0; i<n; ++i) out(a[i],' '); enter;}
template<class T>il void clr(T a[],int n) {memset(a,0,sizeof(T)*n);}
template<class T>il void clr(T *a,T *b) {memset(a,0,sizeof(T)*(b-a));}
template<class T>il bool ckmax(T &a,const T &b) {return a<b?a=b,1:0;}
template<class T>il bool ckmin(T &a,const T &b) {return a>b?a=b,1:0;}
namespace MOD_CALC
{
const int md=998244353,inv2=(md+1)/2;
il int add(const int a,const int b) {return a+b>=md?a+b-md:a+b;}
il int sub(const int a,const int b) {return a-b<0?a-b+md:a-b;}
il int mul(const int a,const int b) {return (LL)a*b%md;}
il void inc(int &a,const int b) {(a+=b)>=md?a-=md:0;}
il void dec(int &a,const int b) {(a-=b)<0?a+=md:0;}
il int qpow(int a,int b) {int r=1; for(; b; b>>=1,a=mul(a,a)) if(b&1) r=mul(r,a); return r;}
il int mdinv(const int a) {return qpow(a,md-2);}
template<class ...Args>il int add(const int a,const int b,const Args &...args) {return add(add(a,b),args...);}
template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
} using namespace MOD_CALC;
namespace i207M
{
#pragma endregion
#define N 200005
const int inf=1e9;
int n;
struct Node
{
	int a,b;
} p[N];
bool cmp(const Node &x,const Node &y)
{
	return x.a<y.a;
}
multiset<int>s;
il LL calc()
{
	return *s.rbegin()-*s.begin();
}
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
	// freopen("ot.out","w",stdout);
#endif
	in(n);
	int rmax=0,rmin=inf,bmax=0,bmin=inf;
	for(ri i=1; i<=n; ++i)
	{
		in(p[i].a,p[i].b);
		if(p[i].a>p[i].b) swap(p[i].a,p[i].b);
		ckmax(rmax,p[i].b);
		ckmin(rmin,p[i].b);
		ckmax(bmax,p[i].a);
		ckmin(bmin,p[i].a);
	}
	LL ans1=(LL)(rmax-rmin)*(bmax-bmin);
	sort(p+1,p+1+n,cmp);
	for(ri i=1; i<=n; ++i) s.insert(p[i].a);
	LL ans2=calc();
	for(ri i=1; i<=n; ++i)
	{
		s.erase(s.find(p[i].a));
		s.insert(p[i].b);
		ckmin(ans2,calc());
	}
	ans2*=rmax-bmin;
	out(min(ans1,ans2));
	return 0;
}
#pragma region
}
signed main()
{
	i207M::main();
	return 0;
}
#pragma endregion


Measured memory_bytes: 13184
#include<cstdio>
using namespace std;

int n, p;
int d[50], wan, now;

bool isEnd() {
  int counter = 0;
  for (int i = 0; i < n; i++) if(d[i] > 0) counter++;
  return counter == 1;
}

int main() {
  while (1) {
    scanf("%d%d", &n, &p);
    if (n == 0) break;
    for (int i = 0; i < n; i++) d[i] = 0;
    wan = p, now = n - 1;
    while (!isEnd()) {
      wan += d[now];
      d[now++] = 0;
      if (now == n) now = 0;
      for (int i = 0; i < n; i++) d[i] += wan / n;
      wan %= n;
      for (; wan > 0; wan--) {
        d[now++]++;
        if (now == n) now = 0;
      }
    }
    for (int i = 0; i < n; i++) if (d[i] > 0) {
      printf("%d\n", i);
      break;
    }
  }
}



Measured memory_bytes: 2676
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll x;
    cin>>x;
    ll i=1;
    ll m=100*1.01;
    while(m<x){
        i++;
        m=m*1.01;
    }
    cout<<i<<endl;
}

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;
public class Main {
    void solve(BufferedReader in) throws Exception {
        int n = toInt(in.readLine());
        int[] a = toInts(in.readLine());
        int d2 = 0;
        int d4 = 0;
        int d1 = 0;
        for(int x: a) {
            if(x%4 == 0) d4++;
            else if(x%2 == 0) d2++;
            else d1++;
        }
        if(d2 != 0) d1++;
        if(d4 >= d1 - 1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }


    }
    int toInt(String s) {return Integer.parseInt(s);}
    int[] toInts(String s) {
        String[] a = s.split(" ");
        int[] o = new int[a.length];
        for(int i = 0; i<a.length; i++) o[i] = toInt(a[i]);
        return o;
    }
    void e(Object o) {
        System.err.println(o);
    }
    public static void main(String[] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        (new Main()).solve(in);
    }
}


Measured memory_bytes: 38488
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(c <= a+b) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    cout << endl;
    return 0;
}

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

int n,a[300012],b[300012],h[300012],cnt=0,now,ans,num[300012];
int fa[300012],vis[300012];

int find(int x){
	if (fa[x]==x)
	  return x;
	return fa[x]=find(fa[x]);
}

int main(){
//	freopen("duliu.in","r",stdin);
//	freopen("duliu.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	  scanf("%d",&a[i]),now^=a[i],h[++cnt]=a[i],a[n+1]^=a[i];
	for (int i=1;i<=n;i++)
	  scanf("%d",&b[i]),h[++cnt]=b[i],b[n+1]^=b[i];
	h[++cnt]=now;
	h[++cnt]=a[n+1];
	h[++cnt]=b[n+1];
	sort(h+1,h+1+cnt);
	cnt=unique(h+1,h+1+cnt)-h-1;
	for (int i=1;i<=n+1;i++)
	  a[i]=lower_bound(h+1,h+1+cnt,a[i])-h;
	for (int i=1;i<=n+1;i++)
	  b[i]=lower_bound(h+1,h+1+cnt,b[i])-h;
	now=lower_bound(h+1,h+1+cnt,now)-h;
	for (int i=1;i<=cnt;i++)
	  fa[i]=i;
	for (int i=1;i<=n+1;i++)
	  if (a[i]!=b[i])
	  {
	    ans++;
		fa[find(a[i])]=find(b[i]);
	  }
	if (ans==0)
	{
	  printf("%d\n",ans);
	  return 0;
	}
	for (int i=1;i<=n+1;i++)
	  if (a[i]!=b[i])
	    vis[find(a[i])]=1;
	for (int i=1;i<=cnt;i++)
	  ans+=vis[i];
	if (a[n+1]!=b[n+1])
	  ans--;
	if (vis[find(a[n+1])])
	  ans--;
	
	for (int i=1;i<=n;i++)
	  num[a[i]]++;
	num[now]++;
	for (int i=1;i<=n;i++)
	{
	  num[b[i]]--;
	  if (num[b[i]]<0)
	  {
	    ans=-1;
		break;
	  }
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long ;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

vvi all;

void def(ll count, ll i, ll n, ll m, vi x){
    if(count == n) {
        all.push_back(x);
        return;
    }
    for(ll j=i; j<=m; j++){
        x.at(count) = j;
        def(count+1,j,n,m,x);
    }
}

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n,m,q;
    cin >> n >> m >> q;
    vi a(q),b(q),c(q),d(q);
    rep(i,q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    vi x(n);
    def(0,1,n,m,x);
    ll res = 0;
    for(vi v:all){
        ll point = 0;
        rep(i,q){
            if(v.at(b.at(i)-1)-v.at(a.at(i)-1)==c.at(i)) {
                point += d.at(i);
            }
        }
        res = max(res, point);
    }
    cout << res << endl;
}

Measured memory_bytes: 13896
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    use std::collections::BinaryHeap;
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let mut next: Vec<Vec<usize>> = vec![Vec::new(); 3 * (n + 1)];
    for _ in 0..m {
        let a: usize = scan(tokens);
        let b: usize = scan(tokens);
        next[3 * a + 0].push(3 * b + 1);
        next[3 * a + 1].push(3 * b + 2);
        next[3 * a + 2].push(3 * b + 0);
    }
    let s: usize = scan(tokens);
    let t: usize = scan(tokens);
    let mut heap = BinaryHeap::new();
    let mut visited = vec![false; 3 * (n + 1)];
    heap.push((0, 3 * s + 0));
    while let Some((d, x)) = heap.pop() {
        if visited[x] {
            continue;
        }
        visited[x] = true;
        if x == 3 * t + 0 {
            println!("{}", -d / 3);
            return;
        }
        for &y in &next[x] {
            heap.push((d - 1, y));
        }
    }
    println!("-1");
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long a, b, c, d; scan(a, b, c, d);
      long res = std::max((long)0, std::minmax({b - c, d - a, b - a, d - c}).first);
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 764
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  long long h, w;
  cin >> h >> w;
  long long ans = (1LL << 60);

  // patern A (三枚おろし)
  if (h >= 3) {
    if (h % 3 == 0) {
      ans = 0;
    } else {
      ans = min(ans, w);
    }
  }
  if (w >= 3) {
    if (w % 3 == 0) {
      ans = 0;
    } else {
      ans = min(ans, h);
    }
  }

  // patern B (横に切ってから, 縦)
  for (long long i = 0; i < h - 1; i++) {
    long long area1 = (i + 1) * w;
    long long area2 = (h - i - 1) * (w / 2);
    long long area3 = (h - i - 1) * ((w + 1) / 2);
    ans = min(ans, max({area1, area2, area3}) - min({area1, area2, area3}));
  }
  // patern C (縦に切ってから, 横)
  for (long long i = 0; i < w - 1; i++) {
    long long area1 = (i + 1) * h;
    long long area2 = (w - i - 1) * (h / 2);
    long long area3 = (w - i - 1) * ((h + 1) / 2);
    ans = min(ans, max({area1, area2, area3}) - min({area1, area2, area3}));
  }

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

Measured memory_bytes: 256
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(l[K-1])

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
map<pair<int,int>,int> m1;
vector<int> v1[MAXN];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        if(x==1||y==1||x==n||y==n){
            m1[make_pair(x,y)] = true;
            m1[make_pair(y,x)] = true;
            v1[x].push_back(y);
            v1[y].push_back(x);
        }
    }
    for(int x:v1[1]){
        if(m1[make_pair(x,n)]){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 43248
/*
csc -debug A.cs && mono --debug A.exe <<< "1 3"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var A = cin.NextInt();
        var P = cin.NextInt();

        System.Console.WriteLine((3*A + P) / 2);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 11092
#include<algorithm>
#include<cmath>
#include<deque>
#include<iomanip>
#include<iostream>
#include<list>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<string>
#include<vector>

#include<map>
#include<set>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;


//map,setのやり方覚える
int main(){
  ll n;
  cin >> n;
  vector<string>  s(n);
  rep(i,n){
    cin >> s[i];
    sort(s[i].begin(),s[i].end());
  }
  ll ans = 0;
  // set<string> st,pre;
  map<string,int> mp;
  rep(i,n){
    mp[s[i]]++;
  }
  for(auto itr : mp){
    ans += (ll)itr.second*(itr.second-1)/2;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 18176
package main

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

func main() {
	var price = 700
	var cnt   = 0
	var sc    = bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		for _, s := range sc.Text() {
			if (string(s) == "o") {
				cnt++
			}
		}
	}
	
	fmt.Println(price + (100 * cnt))

}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
int a,b,temp;
while(1){
    scanf("%d %d",&a,&b);
    if(a==0 && b==0){break;}
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    printf("%d %d\n",a,b);

}
return 0;
}



Measured memory_bytes: 2040
#include <cstdio>
#include <cassert>
#include <vector>
#include <algorithm>

std::vector <std::pair <double, double> > list;

double l, m, r;

inline std::pair <double, double> operator + (std::pair <double, double> a, std::pair <double, double> b)
{
	return std::make_pair(a.first + b.first, a.second + b.second);
}

inline std::pair <double, double> operator - (std::pair <double, double> a, std::pair <double, double> b)
{
	return std::make_pair(a.first - b.second, a.second - b.first);
}

inline std::pair <double, double> inter(std::pair <double, double> a, std::pair <double, double> b)
{
	return std::make_pair(std::max(a.first, b.first), std::min(a.second, b.second));
}

inline bool check(double x)
{
	std::pair <double, double> delta = std::make_pair(r * x, l * x);
	std::vector <std::pair <double, double> > tmp;
	bool flag = false;
	for (int i = 0; i < (int)list.size(); i ++)
	{
		std::pair <double, double> now = inter(list[i] + delta, std::make_pair(-m, m));
		if (now.first <= now.second)
		{
			flag = true;
			tmp.push_back(now);
		}
		now = inter(list[i] - delta, std::make_pair(-m, m));
		if (now.first <= now.second)
		{
			flag = true;
			tmp.push_back(now);
		}
	}
	list.clear();
	if (!flag)
		return false;
	std::sort(tmp.begin(), tmp.end());
	for (int i = 0; i < (int)tmp.size(); i ++)
	{
		double nowr = tmp[i].second;
		int r = i;
		while (r + 1 < (int)tmp.size() && tmp[r + 1].second <= nowr)
		{
			r ++;
			nowr = std::max(nowr, tmp[r].second);
		}
		list.push_back(std::make_pair(tmp[i].first, nowr));
		i = r;
	}
	return true;
}

int main()
{
	int n;
	scanf("%d%lf%lf%lf", &n, &l, &m, &r);
	assert(n <= 1000);
	l /= 2;
	list.push_back(std::make_pair(0, 0));
	bool ans = true;
	for (int i = 1; i <= n; i ++)
	{
		double x;
		scanf("%lf", &x);
		if (ans)
			ans = check(x);
	}
	if (ans)
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M);
    REP(i, M) cin >> a[i];

    vector<ll> fibo(N + 1);
    fibo[0] = 1, fibo[1] = 1;
    for (int i = 2; i <= N; ++i) fibo[i] = (fibo[i - 2] + fibo[i - 1]) % MOD;
    vector<ll> b(N + 1);
    ll ans;
    if (M != 0) 
    {
        b[0] = a[0] - 1;
        b[M] = N - a[M - 1] - 1;
        for (int i = 1; i < M; ++i) 
        {
            b[i] = a[i] - a[i - 1] - 2;
        }
    }

    if (M == 0)
    {
        ans = fibo[N] % MOD;
    }
    else 
    {
        ans = 1;
        REP(i, M + 1)
        {
            if (b[i] == -1) 
            {
                ans = 0;
                break;
            }
            ans = (ans * fibo[b[i]]) % MOD;
        }
    }

    cout << ans << endl;
}


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

using namespace std;

int main(){
  int n,m;cin >> n >> m;
  vector<int> vec(n + 10,0);
  for(int i = 0; i < m; ++i){
    int l, r; cin >> l >> r;
    vec[l] += 1;
    vec[r + 1] -= 1;
  }
  int ans = 0;
  int cnt = 0;
  for(auto&&e : vec){
    cnt += e;
    if(cnt >= m)ans ++;
    if(ans&cnt < m)break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    if(c[0][2]-c[0][1]==c[1][2]-c[1][1] && c[1][2]-c[1][1]==c[2][2]-c[2][1] && c[0][1]-c[0][0]==c[1][1]-c[1][0] && c[1][1]-c[1][0]==c[2][1]-c[2][0] && c[0][2]-c[1][2]==c[0][1]-c[1][1] && c[0][1]-c[1][1]==c[0][0]-c[1][0] && c[1][2]-c[2][2]==c[1][1]-c[2][1] && c[1][1]-c[2][1]==c[1][0]-c[2][0])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    
    
}


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

#define all(x) (x).begin(), (x).end()
#define init()                 \
  ios::sync_with_stdio(false); \
  cin.tie(0)

#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b)
{
  return a == 0 ? b
                : b == 0 ? a
                         : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b)
{
  return a * b / gcd(a, b);
}

template <long long MAX>
class CombinationCalculator
{
  long long mod_;
  long long fac[MAX];
  long long finv[MAX];
  long long inv[MAX];

public:
  CombinationCalculator(long long mi = MOD) : fac(), finv(), inv()
  {
    mod_ = mi;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
      fac[i] = fac[i - 1] * i % mod_;
      inv[i] = mod_ - inv[mod_ % i] * (mod_ / i) % mod_;
      finv[i] = finv[i - 1] * inv[i] % mod_;
    }
  }

  long long c(long long n, long long k) const
  {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod_) % mod_;
  }
};

template <long long MAX = 210000>
using CC = CombinationCalculator<MAX>;

template <typename T>
T modpow(T a, T n, T mod = MOD)
{
  T res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
T modinv(T a, T m = MOD)
{
  T b = m, u = 1, v = 0;
  while (b)
  {
    T t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

bool inrange(int i)
{
  return 1 <= i && i <= 12;
}

int main()
{
  init();

  string s;
  cin >> s;

  int a, b;
  sscanf(s.c_str(), "%2d%2d", &a, &b);

  if (inrange(a))
  {
    if (inrange(b))
    {
      cout << "AMBIGUOUS" << endl;
    }
    else
    {
      cout << "MMYY" << endl;
    }
  }
  else
  {
    if (inrange(b))
    {
      cout << "YYMM" << endl;
    }
    else
    {
      cout << "NA" << 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)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int L, R;
	cin >> L >> R;

    ll ans = LINF;
    for (ll i = L; i <= min(R, L+2019); i++) {
        for (ll j = i+1; j <= min(R, L+2019); j++) {
            ans = min(ans, ((i%2019)*(j%2019)%2019));
        }        
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
const int N=1e5+5;
int n,a[N],b[N],i,p[N];
P aa[N],bb[N];
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i),aa[i]={a[i],i};sort(aa+1,aa+n+1);
	for(i=1;i<=n;++i)scanf("%d",b+i),bb[i]={b[i],i};sort(bb+1,bb+n+1);
	for(i=1;i<=n;++i)if(aa[i].first>bb[i].first){puts("No");return 0;}
	for(i=2;i<=n;++i)if(aa[i].first<=bb[i-1].first){puts("Yes");return 0;}
	for(i=1;i<=n;++i)p[aa[i].second]=bb[i].second;
	int len=0;
	for(i=1;++len,p[i]!=1;i=p[i]);
	puts(len==n?"No":"Yes");
}

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



void solve(){
  char x;
  cin >> x;
  if(x == 'A') cout << 'T' << endl;
  if(x == 'T') cout << 'A' << endl;
  if(x == 'C') cout << 'G' << endl;
  if(x == 'G') cout << 'C' << endl;

}

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


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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {  // TODO
  int N, K, R, S, P;
  cin >> N >> K;
  vector<int> A(3);
  rep(i, 3) cin >> A[i];
  vector<char> J(N);
  rep(i, N) cin >> J[i];
  vector<int> ctoi(256);
  ctoi['r'] = 2;
  ctoi['c'] = 0;
  ctoi['p'] = 1;
  int ans = 0;

  rep(i, K) {
    vector<int> x;
    for (int j = i; j < N; j += K) {
      x.push_back(ctoi[J[j]]);
    }
    vector<int> dp(2);
    int pre = -1;
    for (int nx : x) {
      vector<int> p(2);
      swap(dp, p);
      dp[0] = max(p[0], p[1]);
      if (pre == nx) {
        dp[1] = p[0] + A[nx];
      } else {
        dp[1] = max(p[0], p[1]) + A[nx];
      }
      pre = nx;
    }
    ans += max(dp[0], dp[1]);
  }
  cout << ans << endl;

  return 0;
}

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

#define   ll             long long int
#define   pb             push_back
#define   mp             make_pair
#define   fast           ios_base::sync_with_stdio(false);cin.tie(NULL);
#define   ff             first
#define   ss             second
#define   nil           -10e+9
#define   initial         0
#define   waiting         1
#define   visit           2
#define   inf            10e+9
#define   mx             200005
#define   mxx            1000005
#define   mod            1000000007
#define   pr             pair<ll,ll>
#define   pp_queue       priority_queue<pr,vector<pr>, greater<pr> >
#define   dp_queue       priority_queue<int,vector<int>, greater<int> >
#define   sp_queue       priority_queue<int>
#define   fr(i,p,q)      for(int i=p;i<q;++i)
#define   frr(i,p,q)     for(int i=p;i<=q;++i)
#define   mem(a,b)       memset(a,b,sizeof(a))
#define   len(a)         (int)a.size()
#define   input          freopen("input.txt", "r", stdin);
#define   output         freopen("output.txt", "w", stdout);
#define   debug(arr,j,n) fr(i,j,n) cout<<arr[i]<<" ";

ll power(ll a,ll b){ll aa=1;while(b){if(b&1){aa=aa*a;aa%=mod;}a=a*a;a%=mod;b/=2;}return aa;}

using namespace std;

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

  ll g=__gcd(a,b);

  vector<ll> c;


  for(ll i=1;i<sqrt(g)+1;i++){
    if(g%i==0){
      if(g/i==i) {
        c.pb(i);
      }
      else
      {
        c.pb(i);
        c.pb(g/i);
      }
    }
  }

vector<int> f(c.size(),1);

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

for(int i=0;i<c.size();i++){
  for(int j=i+1;j<c.size();j++){
    if(__gcd(c[i],c[j])>1 and f[j]==1){
      f[j]=0;
    }
  }
}

int ans=0;
for(int i=0;i<f.size();i++){
  if(f[i]) ans++;
}
cout<<ans;

  return 0;
}


Measured memory_bytes: 384
import math

N = int(input())


# data の桁数を取得する
data_size = int (math.log10(N) + 1)
# data_size
sum = N%10
# sum
m = N%10
# m
for i in range(2,data_size+1):
    # print(sum,m)
    sum += int((N%(10**i)-m)/(10**(i-1)))
    m = N%(10**i)
# print(sum)

if N%sum == 0:
    print("Yes")
if N%sum != 0:
    print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int a, b;
    cin>>a>>b;
    if(a+b>9) cout<<"error"<<endl;
    else cout<<a+b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define m 1000000007
int main()
{
	ll n,i,j,W;
	cin>>n>>W;
	ll v[n],w[n];
	for(i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
	}
	ll dp[n+1][W+1];
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=W;j++)
		{
			if(i==0||j==0)
			{
			dp[i][j]=0;
			continue;}
			if(w[i-1]<=j)
			{
				dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
				//cout<<"jjj\n";
			}
			else
			dp[i][j]=dp[i-1][j];
			//cout<<dp[i][j]<<"nnn"<<endl;
		}
	}
	cout<<dp[n][W]<<"\n";
}


Measured memory_bytes: 82456
s=input()
maxx=0
tmp=0
for i in range(len(s)):
    if s[i]== 'A' or s[i]=='T' or s[i]=='G' or s[i]=='C':
        tmp+=1
        maxx=max(maxx,tmp)
    else:
        tmp=0
print(maxx)

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

#define ll long long int

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll ans = 0;
	string s;
	cin >> s;
	ll n = s.size();
	for(ll i = 0; i < n; i++){
		ans = (int(s[i] - '0')%9) + (ans%9);
	}
	if(ans % 9 == 0)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
	return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll oo = 1e18;
const ll mod = 998244353,maxn = 303;
const double PI = acos(-1);



int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    string s;
    cin >> s;
    a = stoi(s);
    b = a%100;
    a /= 100;

    if (a > 0 and a <= 12 and b <= 12 and b > 0){
        cout << "AMBIGUOUS" << endl;
    }
    else if (a <= 12 and a > 0){
        cout << "MMYY" << endl;
    }
    else if (b <= 12 and b > 0){
        cout << "YYMM" << endl;
    }
    else {
        cout << "NA" << endl;
    }
    return 0;
}

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

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		while((line = br.readLine()) != null){
			char[] charArray = line.toCharArray();
			for(int i = 0;i < charArray.length;i++){
				System.out.print(charArray[charArray.length - (i + 1)]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 24048
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <complex>
#include <sstream>

using namespace std;

typedef long long lli;

int data;

bool formula(string str){
  if(str.size() == 1){
    if(str[0] == 'T') return true;
    if(str[0] == 'F') return false;
    int p = str[0] - 'a';
    return (1 << p) & data;
  }
  if(str[0] == '-') return formula(str.substr(1)) ? false : true;
  int l = 1;
  for(int i=1;i<(int)str.size()-1;i++){
    if(str[i] == '(') l++;
    if(str[i] == ')') l--;
    if(l == 1){
      if(str[i] == '*'){
        bool a = formula(str.substr(1, i-1));
        bool b = formula(str.substr(i+1, (int)str.size() - (i+2)));
        if(a && b) return true;
        else return false;
      }
      if(str[i] == '+'){
        bool a = formula(str.substr(1, i-1));
        bool b = formula(str.substr(i+1, (int)str.size() - (i+2)));
        if(a || b) return true;
        else return false;
      }
      if(str[i] == '-' && str[i+1] == '>'){
        bool a = formula(str.substr(1, i-1));
        bool b = formula(str.substr(i+2, (int)str.size() - (i+3)));
        if(a) return b;
        else return true;
      }
    }
  }
}

bool solve(string a, string b){
  for(int i=0;i<(1<<11);i++){
    data = i;
    if(formula(a) != formula(b)) return false;
  }
  return true;
}

main(){
  string str;
  while(cin >> str){
    if(str == "#") break;
    string a, b;
    for(int i=0;i<str.size();i++){
      if(str[i] == '='){
        a = str.substr(0, i);
        b = str.substr(i+1);
        break;
      }
    }
    cout << (solve(a, b) ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 1484
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

int dayInMonth(int y, int m) {
	if(y % 3 == 0) {
		return 20;
	}
	if(m%2 == 0) {
		return 19;
	}
	return 20;
}


void main(){
	auto n = readInt();
	for(int i; i < n; ++i) {
		auto ymd = readInts();
		auto y = ymd[0];
		auto m = ymd[1];
		auto d = ymd[2];
		int ans;
		ans += dayInMonth(y, m) + 1 - d;
		d = 1;
		m += 1;
		if(m > 10) {
			y += 1;
			m = 1;
		}
		while(y < 1000) {
			ans += dayInMonth(y, m);
			m += 1;
			if(m > 10) {
				y += 1;
				m = 1;
			}
		}
		writeln(ans);
	}
}

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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define FOR(i,a,b) for(long long i=(a);i<=(b);i++)

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  REP(i, M) {
    cin >> B[i];
  }
  int ans = 0;
  REP(i, N) {
    vector<int> A(M);
    REP(j, M) {
      cin >> A[j];
    }
    int s = 0;
    REP(j, M) {
      s += A[j] * B[j];
    }
    s += C;
    if(s > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)

int main()
{
	int n; cin>>n;
	bitset<2000*2000/2+1> bs(1);
	int sum = 0;
	REP(i,n) { int c; cin>>c; bs |= bs<<c; sum += c; }
	for( int i = sum / 2; i >= 0; --i )
		if( bs[i] ) { cout << sum - i << endl; break; }

	return 0;
}

Measured memory_bytes: 1024
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

N=int(input())
A=list(map(int,input().split()))
money=1000


for i in range(N-1):
    if A[i]<A[i+1]:
        money+=money//A[i]*(A[i+1]-A[i])
print(money)


Measured memory_bytes: 72804
#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()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int Q(int n)
{
    if(n<=6) return n+1;
    return n-5;
}

int calcCD(string s)
{
    int r = 0;
    for(int i=1; i<=11; ++i) (r+=(s[i]-'0')*Q(i))%=11;

    if(r<=1) return 0;
    return 11 - r;
}

int main()
{
    string s;
    cin >>s;
    reverse(all(s));

    int idx = s.find('?');

    vector<int> ans;
    rep(i,10)
    {
        s[idx] = '0'+i;
        if(calcCD(s) == s[0]-'0') ans.pb(i);
    }

    if(ans.size()==1) cout << ans[0] << endl;
    else cout << "MULTIPLE" << endl;
    return 0;
}

Measured memory_bytes: 3196
import sys

def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    not_good = set()
    for i in range(M):
        if H[A[i] - 1] < H[B[i] - 1]:
            not_good.add(A[i])
        elif H[B[i] - 1] < H[A[i] - 1]:
            not_good.add(B[i])
        else:
            not_good.add(A[i])
            not_good.add(B[i])
    good = set(range(1, N + 1)) - not_good
    print(len(good))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)


if __name__ == "__main__":
    main()


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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		int target;
		cin >> target;
		int left = 0;
		int right = n - 1;
		int count = 0;
		while(right >= left)
		{
			count++;
			int m = (left + right) / 2; 
			if(target == Vec[m])
			{
				break;
			}
			target < Vec[m] ? right = m - 1 : left = m + 1;
		}
		cout << count << endl;
	}
}

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

Measured memory_bytes: 0
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Set<Integer> num = new HashSet<>();
    for(int i=0;i<N;i++){
      int di = sc.nextInt();
      num.add(di);
    }
    System.out.println(num.size());
  }
}


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

int main() {
  int n,x,d=0;
  cin>>n>>x;
  vector<int> m(n);
  rep(i,n){
    cin>>m[i];
    x -= m[i];
    d++;
  }
  sort(m.begin(),m.end());
  d += x / m[0];
  cout<<d<<endl;
}

Measured memory_bytes: 256
# include <cstring>
# include <cstdio>
# include <iostream>
# include <queue>
# define N 100050 //N为顶点个数 
# define M 200050 //N为顶点个数 
# define WQD 0x7f7f7f7f//无穷大 
int n;//图的顶点个数
int m;//图的边数 
struct Edge{int next,to, w;}  e[M<<1];//不用0号单元 
int head[N+1]; 
int dis[N+1];//存放源点到其他点的路径
bool vis[N+1];
bool book[N+1];
bool spfa(int s);//差分约束判断 
using namespace std;
int main()
{
	ios::sync_with_stdio ( false ) ;
	int u,v,w;
	memset(head,-1,sizeof(head));
	cin>>n>>m;
	for(int i=1; i<=m; i++)  //本题约束关系为=，要添加两条边 
	{
		cin>>u>>v>>w;//输入第i条边 ,i为编号 
		e[i]=(Edge){head[u],v,w};head[u]=i;
		e[m+i]=(Edge){head[v],u,-w};head[v]=m+i;
	}
	memset(book,0,sizeof(book));
	memset(dis,0x7f,sizeof(dis));
	for(int i=1; i<=n; i++)
		if(!vis[i]) 
		{
			vis[i]=1;
			if(spfa(i)==false)  {cout<<"No";return 0;}
		}
	cout<<"Yes";
	return 0;
}
bool spfa(int s)
{
 	queue<int>q;
 	//memset(book,0,sizeof(book));
	//memset(dis,0x7f,sizeof(dis));
	dis[s]=0;
	q.push(s);book[s]=1;
	while(q.size()>0)//如果没松弛就松弛，如果松弛过就判断是否符合约束条件，如果自相矛盾就是不可能的数据 
	{
		int k=q.front();q.pop();//对头元素出队 
		book[k]=0;
		for(int i=head[k]; i!=-1; i=e[i].next)
		{
			int v=e[i].to;
			if(dis[v]==WQD )//如果v点没松弛过，就松弛更新dis[v]的值 
				//题目的约束条件是= 
				{				
					dis[v]=dis[k]+e[i].w;//更新 
					if(book[v]==0)	{q.push(v);	book[v]=1;}//入队标记
					vis[v]=1;//标记该点已经松弛过 
				}
			else if(dis[v]!=dis[k]+e[i].w)	return false;//这里也可以用不等于，根据题意理解差分系统约束条件 
		}		
    }
	return true;//别掉了这句 
}

Measured memory_bytes: 6400