akhauriyash/Code-Regression huggingface dataset:
object Main{
 def main(args: Array[String]){
   var in = io.StdIn.readLine().split(' ').map(_.toLong);

   val d:Long = in(0);
   val a:Long = in(1);
   val b:Long = in(2);

   if(a >= b){
       println("delicious");
   }else if(b - a <= d){
       println("safe");
   }else{
       println("dangerous");
   }
 }
}

Measured memory_bytes: 27308
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#define INF 1e16
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;




int main(void){
    int n,q;
    cin>>n>>q;
    vector<Q>event;
    vector<ll>d(q);
    for(int i=0;i<n;i++){
        ll s,t,x;
        cin>>s>>t>>x;
        event.push_back(Q(s-x,P(1,x)));
        event.push_back(Q(t-x,P(-1,x)));
    }
    for(int i=0;i<q;i++)cin>>d[i];
    sort(event.begin(),event.end());
    set<int>s;
    vector<ll>ans(q);
    int now = 0;
    for(int i=0;i<q;i++){
        while(now<event.size() &&  event[now].first<=d[i]){
            if(event[now].second.first==1){
                s.insert(event[now].second.second);
            }
            else s.erase(event[now].second.second);
            now++;
        }
        if(s.empty())ans[i]=-1;
        else ans[i]= (*s.begin());
    }
    for(int i=0;i<q;i++){
        if(i==q-1)cout<<ans[i]<<endl;
        else cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 24040
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <cmath>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;



lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    cin >> n;


    cout <<  800 * n - n / 15 * 200  << endl;


//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 256
from itertools import combinations

ans_list = []

while True:
    n = int(input())
    if n == 0:
        break
    A = list(map(int,input().split()))
    ans = float("inf")
    for (a, b) in combinations(A,2):
        ans = min(ans,abs(a-b))
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5776
import math

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

def division_enumeration(num):
	ans = []
	d = math.floor(float(num)**(1/2))
	for i in range(1,d+1):
		if num % i == 0:
			ans.append(i)
			ans.append(num//i)

	return ans

trgs = sorted(set(division_enumeration(A[0]) + division_enumeration(A[1])), reverse = True)

for trg in trgs:
	cnt = 0
	cond = True
	for i in range(N):
		if A[i] % trg != 0:
			cnt += 1
			if cnt > 1:
				cond = False
				break
	if not cond:
		continue
	
	ans = trg
	break

print(ans)

Measured memory_bytes: 14588
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N, M = ILI()
    return N, M


def solve(N, M):
    if abs(N - M) >= 2:
        return 0
    elif abs(N - M) == 1:
        num_min = min(N, M)
        ans = ((math.factorial(num_min) ** 2) * (num_min + 1)) % MOD
        return ans
    elif abs(N - M) == 0:
        ans = (2 * (math.factorial(N) ** 2)) % MOD
        return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 6296
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Fast in = new Fast();
        int n=in.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        int min=Integer.MAX_VALUE;
        for (int i = 0; i < arr.length; i++) {
            int a=arr[i];
            int s=0;
            while(a%2==0){
                a=a/2;
                s++;
            }
            min=Math.min(min,s);
        }
        System.out.println(min);
    }
}


class Fast {
    BufferedReader br;
    StringTokenizer st;

    public Fast() {
        br = new BufferedReader(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 nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}



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

int main()
{
  string s; cin >> s;
  int counter=1;
  int MAX=0;
  for(int i=1; i<s.length(); ++i){
    if(s[i]==s[i-1]) ++counter;
    else{
      if(s[i-1]=='R')MAX=max(MAX, counter);
      counter=1;
    }
  }
  if(s[s.length()-1]=='R') MAX=max(MAX, counter);
  cout << MAX << endl;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

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

    vector<int> result(n + 1, 0);
    for (int x = 1; x * x <= n; x++)
    {
        for (int y = 1; y * y <= n; y++)
        {
            for (int z = 1; z * z <= n; z++)
            {
                const auto v = x * x + y * y + z * z + x * y + y * z + z * x;
                if (v <= n)
                {
                    result[v]++;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << result[i] << endl;
    }
}


Measured memory_bytes: 3592
i = 1
x = i
n = int(input())

while i <= n:
    x = i
    check = False

    while True:
        if x % 3 == 0 and check == False:
            print(" %s" % i,end="")
            break
        elif x % 10 == 3:
            print(" %s" % i,end="")
            break
        else:
            x /= 10
            x = int(x)
            check = True
            if x <= 0:
                break

    i += 1
print("")


Measured memory_bytes: 5872
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define scanl(x) scanf("%ld", &x)
#define scans(x) scanf("%s", x)

#define INF 1000000000

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

int main() {
	long K, T;
	long a[100001];
	int i;
	long m = 0;
	
	scanl(K); scanl(T);
	for(i=0;i<T;i++) {
		scanl(a[i]);
		m = max(m, a[i]);
	}
	
	printf("%ld\n", max(2 * m - K - 1, 0));
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
	String S = s.next(); 
	char[] Schrs = new char[S.length()];
	String T = s.next();
	char[] Tchrs = new char[T.length()];
	String ans = "Yes";
	
	for(int i=0; i<S.length(); i++) {
		Schrs[i]= S.charAt(i);
		Tchrs[i]= T.charAt(i);
		if(Schrs[i]!=Tchrs[i]) {ans ="No"; break;}
		
	}
		System.out.println(ans);
		
	}

}


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

int main() {
  int x, y, z; cin >> x >> y >> z;
  auto f = [&](int n) {
    return (y + z) * n <= x - z;
  };
  for (int i = x / y; ; i--) {
    if (f(i)) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	cout << std::fixed << std::setprecision(10);
	int N,K;
	cin >> N >> K;
	vector<double> A(N),score(N),ans(N-K+1);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
		score.at(i) = (A.at(i) + 1) / 2;
	}
	for (size_t i = 0; i < K; i++)
	{
		ans.at(0) += score.at(i);
	}

	for (size_t i = 1; i < N-K+1; i++)
	{
		ans.at(i) = ans.at(i - 1) - score.at(i - 1) + score.at(i + K - 1);
	}
	
	sort(ans.begin(), ans.end());
	cout << ans.at(ans.size() - 1);
}

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

int main() {
    int i, N, count=0;
    long long D, T, S;
    vector<long long> X(200000), Y(200000);
    
    cin >> D >> T >> S;
  if (D>T*S)
    cout << "No";
  else
    cout << "Yes";
}
  




Measured memory_bytes: 6228
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      String a[]=sc.nextLine().split("",0);
      System.out.println((a[0].equals(a[1])&&a[2].equals(a[1])||a[1].equals(a[2])&&a[3].equals(a[2]))?"Yes":"No");
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

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

	int n,id;
	scanf("%d",&n);
	vector<int> k(n),p(n),d(n);
	vector<vector<int>> c(n);
	rep(i,n){
		p[i]=-1;
	}
	rep(i,n){
		scanf("%d",&id);
		scanf("%d",&k[id]);
		c[id].resize(k[id]);
		rep(j,k[id]){
			scanf("%d",&c[id][j]);
			p[c[id][j]]=id;
		}
	}
	int p0;
	rep(i,n){
		if(p[i]==-1){
			p0=i;
		}
	}
	queue<int> q;
	rep(i,k[p0]){
		q.push(c[p0][i]);
	}
	d[p0]=0;
	int x;
	while(q.empty()==0){
		x=q.front();
		q.pop();
		d[x]=d[p[x]]+1;
		rep(i,k[x]){
			q.push(c[x][i]);
		}
	}

	rep(i,n){
		printf("node %d: parent = %d, depth = %d, ",i,p[i],d[i]);
		if(p[i]==-1)printf("root, [");
		else if(c[i].size()==0)printf("leaf, [");
		else printf("internal node, [");
		if(c[i].size()!=0){
			rep(j,k[i]-1){
				printf("%d, ",c[i][j]);
			}
			if(k[i]>0) printf("%d",c[i][k[i]-1]);
		}
		printf("]\n");
	}
}

Measured memory_bytes: 7336
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_M = 100000;

int dp[5005][5005];




int main(int argc, char *args[]) {
	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 <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int f = 0;
  for (int i = 0; i < S.size(); i++) {
    if (f == 1 && S[i] == 'F') {
      cout << "Yes" << endl;
      return 0;
    }
    if (S[i] == 'C') f = 1;
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
  int x, t;
  cin >> x >> t;
  cout << max(x-t, 0) << endl;
  return 0;
}


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

prime=[]
num=list(range(3,55555,2))
p=2
while p<int(55555**(1/2)):
    prime.append(p)
    for j, ni in enumerate(num):
        if ni%p==0:
            del num[j]
    p=num.pop(0)
prime.extend(num)

mod5=[]
for p in prime:
    if p%5==1:
        mod5.append(p)
ans=list(map(str , mod5[:n]))
print(' '.join(ans))



Measured memory_bytes: 4084
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		@SuppressWarnings("unchecked") ArrayList<Integer>[] jobs = new ArrayList[m + 1]; // 遅延日数ごとに仕事をグルーピングする
		for ( int i = 0; i <= m; i++ ) {
			ArrayList<Integer> a = new ArrayList<>();
			a.add(0); // ダミー要素
			jobs[i] = a;
		}

		for ( int i = 0; i < n; i++ ) {
			int d = in.nextInt();
			int f = in.nextInt();
			if ( d > m ) continue; // 遅延日数的に候補になりえない仕事は除外
			jobs[d].add(f);
		}

		long total = 0;
		
		PriorityQueue<Integer> pool = new PriorityQueue<Integer>(Collections.reverseOrder()); // job候補のプール

		// m日目をゼロとして考え後退していく days:残り日数
		for ( int today = 0; today <= m; today++ ) {
			for ( Integer i : jobs[today] ) {
				pool.add(i);				
			}
			total += (long) pool.poll();
		}

		System.out.println(total);
		in.close();
	}
}


Measured memory_bytes: 103040
#include<iostream>
#include<vector>
#include<set>
using ll =  long long;

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

using namespace std;

int main(){

    int a, b;
    cin >> a >> b;
    if(a*b%2==0) cout << "Even" << endl;
    else cout << "Odd" << endl;

    return 0;
}

Measured memory_bytes: 256
def check(s):
    n = len(s)
    if s != s[::-1]:
        return False
    t = s[:(n - 1) // 2]
    if t != t[::-1]:
        return False
    u = s[(n + 3) // 2 - 1:]
    if u != u[::-1]:
        return False
    return True


s = input()
print('Yes' if check(s) else 'No')


Measured memory_bytes: 3064
N,Y=map(int,input().split())
flag=False
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            flag=True
            a=i
            b=j
            c=N-i-j
if flag==True:
    print(a,b,c)
else:
    print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, 0, 1, -1 , 1,  1, -1, -1 };
static const char Move[] = { 'E', 'W', 'N', 'S' };

int x, y, s, ans = 0;

int main() {
	while ( ~scanf( "%d %d %d", &x, &y, &s ) && x && y && s ) {
		for ( int i = 1; i < s; i++ ) {
			for ( int j = i; j < s; j++ ) {
				if ( i * ( 100 + x ) / 100 + j * ( 100 + x ) / 100 == s ) {
					ans = max( ans, int( i * ( 100 + y ) / 100 ) + int( j * ( 100 + y ) / 100 ) );
				}
				if ( i * ( 100 + x ) / 100 + j * ( 100 + x ) / 100 > s ) {
					break;
				}
			}
		}
		printf( "%d\n", ans );
		ans = 0;
	}
	return 0;
}

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

const int MAXN = 1e5 + 10;
int gf[MAXN], ge[MAXN], n, a[MAXN];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], gf[i] = __gcd(a[i], gf[i - 1]);
	for (int i = n; i >= 0; i--)
		ge[i] = __gcd(a[i], ge[i + 1]);
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(__gcd(gf[i - 1], ge[i + 1]), ans);
	cout << ans;
}


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

void fct()
{
	int n;
	ll sum = 0;
	cin >> n;
	vector<int> v(n + 1, 0);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= n; j += i)
		{
			v[j]++;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		sum += (i * (ll)v[i]);
	}
	cout << sum << endl;
}
int main() {
	fct();
}

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


int main()
{
    int N;
    string S;
    cin>>N>>S;
    //vector<int> line1(N);
    //for (int i=0;i<N;++i){
    //    cin>>line1.at(i);
    //}
    int count=0;
    for (int i = 1;i<N;++i){
        if (S.at(i) == 'E'){
            count++;
        }
    }
    int tcount = count;
    for (int i=1;i<N;++i){
        if (S.at(i-1)=='W'){
            tcount++;
        }
        if (S.at(i)=='E'){
            tcount--;
        }
        count = min(count,tcount);
    }
    cout<<count<<endl;
}

Measured memory_bytes: 900
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < n; i++) l[i] = sc.nextInt();
        Arrays.sort(l);

        int result = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                for (int k = 0; k < j; k++) {
                    if (l[k] != l[j] && l[i] != l[j] && l[k] + l[j] > l[i]) {
                        result++;
                    }
                }
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 36636
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  string str;
  cin >> str;

  int i = 0;

  if (str == "RRR") {
    cout << 3;
    return 0;
  }
  if (str == "SRR" || str == "RRS") {
    cout << 2;
    return 0;
  }
  if (str == "SSS") {
    cout << 0;
    return 0;
  }
  cout << 1;
  return 0;

  cout << "" << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<double> V(N);
    rep(i,N) cin >> V.at(i);
    sort(begin(V), end(V));
    for (int i = 1; i < N; i++) {
        V[0] = (V[0] + V[i]) / 2;
    }
    cout << V[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n ;
int arr[500005] ;
string str ;
long double r ;
void solve()
{
    cin >> r ;
    cout << fixed << setprecision(10) << 2*r*3.14159265 << "\n" ;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}



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

#define ll long long

namespace mincf{
	const int E=1e6;
	const int V=1e4;
	struct R{
		int to,nex;
		ll cost,flow;
	}r[E];
	int st,en,n,cnt,hea[V];
	
	void A(int u,int v,ll c,ll f){
		r[++cnt]=(R){v,hea[u],c,f}; hea[u]=cnt;
		r[++cnt]=(R){u,hea[v],-c,0};hea[v]=cnt;
	}
	void resta(int n_,int st_,int en_){
		memset(hea,0,sizeof hea);
		cnt=1;
		n=n_; st=st_; en=en_;
	}
	
	int pv[V],pe[V],in[V];
	queue<int>q;
	ll fl,f[V],d[V],ans,sf,inf;
	
	bool spfa(){
		while (!q.empty()) q.pop();
		memset(in,0,sizeof in);
		memset(d,62,sizeof d);
		f[st]=inf=d[0];
		d[st]=0;
		ll x,y,z;
		for (q.push(st);!q.empty();q.pop()){
			x=q.front(); in[x]=0;
			for (int i=hea[x];i>0;i=r[i].nex) if (r[i].flow){
				y=r[i].to;
				z=d[x]+r[i].cost;
				if (z<d[y]){
					d[y]=z;
					f[y]=min(f[x],r[i].flow);
					pv[y]=x;
					pe[y]=i;
					if (!in[y]){
						in[y]=1;
						q.push(y);
					}
				}
			}
		}
		return d[en]!=inf;
	}
	
	ll realmain(){
		sf=ans=0;
		while (spfa()){
			sf+=fl=f[en];
			ans+=fl*d[en];
			for (int x=en;x!=st;x=pv[x]){
				r[pe[x]].flow-=fl;
				r[pe[x]^1].flow+=fl;
			}
		}
		return ans;
	}
}


int n, s, t;

int main(){
    cin>>n;
    s=n*2+1; t=n*2+2;
    mincf::resta(t+6,s,t);
    for (int i=1;i<=n;++i){
        int x, y, c; cin>>x>>y>>c;
        mincf::A(s,i,0,c);
        for (int d=0;d<4;++d){
            ll v= (d&1? x: -x) + (d>>1&1? y: -y);
            mincf::A(i,t+1+d,v,c);
        }
    }
    for (int i=1;i<=n;++i){
        int x, y, c; cin>>x>>y>>c;
        mincf::A(i+n,t,0,c);
        for (int d=0;d<4;++d){
            ll v= (d&1? x: -x) + (d>>1&1? y: -y);
            mincf::A(t+1+d,i+n,-v,c);
        }
    }
    cout<<-mincf::realmain()<<endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
using namespace std;
int main(){
    string s;
    string d1 = "dream", d2="dreamer", e1="erase", e2="eraser";
    int size7= d2.size(), size6=e2.size(), size5=d1.size();
    cin >> s;
    int index =s.size()-1;
    string ans="NO";
    while(true){
        string substring1, substring2, substring3;
        int word_len;
        if((index-size7+1)>=0){
            substring1 = s.substr(index-size7+1, size7);
        }else
            substring1="";
        if((index-size5+1)>=0) {
            substring2 = s.substr(index-size5+1, size5);
        }else
            substring2="";
        if((index-size6+1)>=0)
            substring3 = s.substr(index-size6+1, size6);
        else
            substring3="";
        if(substring1==d2) {
            index -= size7;
        }
        else if(substring2==d1 || substring2==e1){
            index -= size5;
        }
        else if(substring3==e2){
            index -= size6;
        }
        else
            break;

        if(index==-1) {
            ans="YES";
            break;
        }
        else if(index<0)
            break;
    }
    cout << ans << endl;
}



Measured memory_bytes: 512
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

ll ketasu(ll n)
{
    ll ret=0;
    while(n){
        ++ret;
        n/=10;
    }
    return ret;
}
int main()
{
    ll ans=0;
    REP1(i,in())if(ketasu(i)%2)++ans;
    cout<<ans<<endl;
}

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

int main(){
        int n,i,ans=0;
        cin >> n;
        vector<int> b(n-1);
        for(i=0;i<n-1;++i) cin >> b.at(i);
        for(i=0;i<n-2;++i) ans += min(b.at(i),b.at(i+1));
        ans += b.at(0);
        ans += b.at(b.size()-1);
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3528
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)
*/

f(A, B, C, K, X) :- K =< A, X is K, !.
f(A, B, C, K, X) :- K =< A + B, X is A, !.
f(A, B, C, K, X) :- X is A - (K - A - B), !.

main :-
    get_number(A, B, C),
    get_number(K),
    f(A, B, C, K, X),
    writeln(X).



Measured memory_bytes: 8180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Print_Test_Cases
{
    /// <summary>
    /// ????????????????????????????????????????????????????????????
    /// ?????????????????????????????????????????????????????§????????????????????°???????????£?????§????¢??????????????????§??????
    /// ????????¶?????\???????±?????????????????????????????±??????????????????\?????¨?????????????????£?????????????????????
    /// (????????§?????????????????£??????????????????????????¶?????\???????±??????????????????¨?????????????????????????????????????????????)
    /// ????????°?????????????????¨??????????????¶?????\?????¨?????????????????????????????¢??§???????????????
    /// ???????????????????????????(=????????????)????????°????????????????????¨???????????????
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {

            // ????????????
            // Console.ReadLine?????\??£???????????£??????????????§???????????¶?????\?????¨???????????????
            // ???????????¨????????????????????????????????§???PrintTestCases????????¨??????????????????????????????
            // ??\??????????????????????????????????????\???????????????????????????
            List<int> numbers = new List<int>();
            while (true)
            {
                string line = Console.ReadLine();
                int x = int.Parse(line);
                if (x == 0) break;
                numbers.Add(x);
            }

            // ?¨????
            // ??\??????????????????PrintTestCases?????\????????????
            // ?????????????????¨??§???????????????????????????????????????????????§?????????????????\???????????????????????????
            PrintTestCases problem = new PrintTestCases();
            string answer = problem.Print(numbers);


            // ??¨???
            Console.Write(answer);

        }
    }
}

public class PrintTestCases
{
    /// <summary>
    /// ??´??°??????????????????Case i: x ??????????????????????????????
    /// </summary>
    /// <param name="numbers">??´??°????????????</param>
    /// <returns>Case i: x ?????????????????????</returns>
    public string Print(List<int> numbers)
    {
        StringBuilder builder = new StringBuilder();
        int count = 1;
        foreach (int number in numbers)
        {
            builder.Append("Case " + count + ": " + number + "\n");
            count++;
        }
        return builder.ToString();
    }
}

Measured memory_bytes: 10356
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define sc second
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define rep1(i, n) repi(i, 1, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define sp(n) cout << fixed << setprecision(n)
#define ma(n, o) map<n, o>
#define pr(n, o) pair<n, o>
#define so(n) sort(n.begin(), n.end())
#pragma endregion
// abs 絶対値, rtsq ルート, pow(a, n) aのn乗

int main() {
  int r, D, x, N = 10;
  ci(r, D, x);
  ve(int) X(N);
  X.at(0) = r * x - D;
  rep1(i, N) {
    X.at(i) = r * X.at(i - 1) - D;
  }
  rep(i, N) {
    co(X.at(i));
  }
} 


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 300000
int main(void){
	unsigned short a[MAX] = {0};
	int sum[MAX];
	int csum = 0;
	int c,i,j,n;
	c = 0;
	for(i = 2; i < MAX; i++){
		if(a[i] == 0){
			c++;
			csum += i;
			sum[c] = csum;
			for(j = i; j < MAX; j += i){
				a[j] = 1;
			}
		}
	} 
	while(1){
		scanf("%d",&n);
		if(n == 0){break;}
		printf("%d\n",sum[n]);
	}


	return 0;
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int n; cin>>n;
    vector<int>a(n);
    map<int,int>mp;
    ll cnt=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]>=3200)cnt++;
       else mp[a[i]/400]++;
    }
    ll c=0;
    for(auto p:mp){
        c++;
    }
    if(c!=0){
    cout<<c<<" "<<c+cnt<<endl;
    }
    else cout<<1<<" "<<cnt<<endl;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
int main ()
{
    int N,M;
    scanf ("%d %d",&N,&M);
    if (N<=100)
    {
        if (M<N)
    {
        printf ("No\n");
    }
    else
    {
        printf ("Yes\n");
    }
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<deque>
#include<string>
using namespace std;
using ll = long long int;

int n;
ll k;
ll ret = 0;

int main(void) {
	cin >> n >> k;
	ret = k;
	for (int i = 0; i < n - 1; i++) {
		ret *= ll(k - 1);
	}
	cout << ret << endl;
	return 0;
}

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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

i64 n,k,m;
int main()
{ 
    fastInOut
    cin>>n>>k;
    vector<i64>v;
    for(int i=0;i<n;i++){
         cin>>m;
         v.push_back(m);
    }
    v.push_back(k);
 
    sort(v.begin(),v.end());
    vector<i64>temp;
    for(int i=1;i<=n;i++){
           i64 tt=v[i]-v[i-1];
           temp.push_back(tt);
    } 

    i64 r=temp[0];
    for(int i=1;i<temp.size();i++){
        r=__gcd(r,temp[i]);
    } 
    cout<<r; 
   
  return 0;
}















Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
long long n,a,z;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a,z+=a;
	if(z%2)cout<<"NO"<<endl;else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int table[55000];

int main(){
	for(int i=2;i<1000;i++){
		if(table[i]==0){
			for(int j=i*2;j<=55000;j+=i){
				table[j]=1;
			}
		}
	}
	int a;
	while(~scanf("%d",&a)){
		int i;
		for(i=a-1;table[i]==1;i--);
		printf("%d ",i);
		for(i=a+1;table[i]==1;i++);
		printf("%d\n",i);
	}
}

Measured memory_bytes: 0
import java.util.Scanner;


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

        int H = 0;
        int W = 0;

        while (true) {
            H = sc.nextInt();
            W = sc.nextInt();

            if (H == 0 && W == 0) break;

            for (int i=0; i<H; ++i) {
                for (int j=0; j<W; ++j) {
                    System.out.print('#');
                }
                System.out.print('\n');
            }

            System.out.print('\n');
        }
    }
}


Measured memory_bytes: 39896
import itertools
N = int(input())
j = [i + 1 for i in range(N)]
P = []
temp = input()
P = tuple([int(i) for i in temp.split()])
temp = input()
Q = tuple([int(i) for i in temp.split()])

J = [i for i in itertools.permutations(j)]
a = J.index(P)
b = J.index(Q)
print(abs(a - b))


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

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

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

int main(){

    ll n; cin >> n;
    ll in, mn = INF;
    rep(i, 5){
        cin >> in;
        mn = min(mn, in);
    }

    if(mn != 1) cout << n/mn+5 << endl;
    else cout << n/mn+4 << endl;

    return 0;
}

Measured memory_bytes: 3628
/*
 ID: swagchicken1
 PROG:
 LANG: C++11
 */

#include <iostream>
#include <tuple>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cctype>
#include <climits>
#include <chrono>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;

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

//#define endl '\n';

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1000000007;

long double PI = 4*atan(1);
long double eps = 1e-12;


ll dp[2010][2010] = {};
int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    //ofstream cout("output.txt");
    //ifstream cin("input.txt");
    ll n; cin >> n;
    pair<ll, int> a[2010] = {};
    FOR(i,0,n) {
        cin >> a[i].f;
        a[i].s = i;
    }
    sort(a,a+n, greater<pair<ll, int>>());
    dp[0][0] = 0;
    FOR(i,1,n+1) {
        FOR(j,0, i+1) {
            int x = j;
            int y = i - j;
            if(x > 0) {
                dp[x][y] = max(dp[x][y], dp[x-1][y] + a[i-1].f*(abs(a[i-1].s - x + 1)));
            }
            if(y > 0) {
                dp[x][y] = max(dp[x][y], dp[x][y-1] + a[i-1].f*(abs(n - y - a[i-1].s)));
            }
        }
    }
    ll ans = 0;
    FOR(i,1,n+1) {
        ans = max(ans, dp[n - i][i]);
    }
    cout << ans << endl;
    //auto stop = chrono::high_resolution_clock::now();
    //auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    //cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}


Measured memory_bytes: 26292
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  priority_queue<P> q;
  vll as(n);
  rep(i, n){
    cin >> as[i];
    q.emplace(as[i], -i);
  }

  vll ans(n, 0);

  ll curM = INF;
  ll curi = n;
  map<ll, ll, greater<ll>> mp;
  while(!q.empty()){
    ll nxM = q.top().first;
    ll nxi = -q.top().second;
    q.pop();
    if(nxi > curi) continue;
    if(curi < n) {
      mp[nxM]++;
      ans[curi] += curM - nxM;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ){
      if((*itr).first <= nxM) break;
      ans[curi] += ((*itr).first - nxM)*(*itr).second;
      mp[nxM] += (*itr).second;
      mp.erase(itr++);
    }
    for (ll i = curi - 1; i > nxi; i--){
      mp[as[i]]++;
    }
    curM = nxM;
    curi = nxi;
  }
  for(auto [k, v] : mp) ans[0] += k*v;
  ans[0] += as[0];

  rep(i, n) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 12744
if __name__ == '__main__':
    
    while True:
        try:
            A = list(map(int,input()))
            
            def rec(A):
                n = len(A)
                if n == 1:
                    return A[0]
                
                tmp = []
                for i in range(n-1):
                    a = (A[i] + A[i+1]) % 10
                    tmp.append(a)
                
                return rec(tmp)

            print(rec(A))        

        except EOFError:
            break



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
 int n;
  string s;
  cin>>s;
  n=s.size();
  int ans=0,test=0; 
  rep(i,n){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')test++;
    else {
      ans=max(ans,test);
      test=0;
    }
  }
  cout<<max(ans,test)<<endl;
}


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

int main() {
    string s; cin >> s;
    for(int bit=0; bit<(1<<3); bit++){
        string str = "";
        str += s[0];
        int cnt = s[0] - '0';

        if(bit & (1<<0)){
            cnt += s[1] - '0';
            str += "+";
        }else{
            cnt -= s[1] - '0';
            str += "-";
        }
        str += s[1];

        if(bit & (1<<1)){
            cnt += s[2] - '0';
            str += "+";
        }else{
            cnt -= s[2] - '0';
            str += "-";
        }
        str += s[2];

        if(bit & (1<<2)){
            cnt += s[3] - '0';
            str += "+";
        }else{
            cnt -= s[3] - '0';
            str += "-";
        }
        str += s[3];
        if(cnt == 7){
            str += "=7";
            cout << str << endl;
            break;
        }
    }
}

Measured memory_bytes: 3624
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll A, B, C; cin >> A >> B >> C;
    if(C - B - A <= 0) {
        cout << "No" << endl;
    }
    else {
        ll X = 4 * A * B;
        ll Y = (C - B - A) * (C - B - A);
        fprintf(stderr, "X = %lld, Y = %lld\n", X, Y);
        cout << (X < Y ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String... args){
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();

    int cnt = 0;
    while(N>0){
      N /= K;
      cnt++;
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }


int n,m;
vector<int> dp;
vector<vector<int>> g;


int dfs(int cur){
	if(dp[cur] >= 0) return dp[cur];
	dp[cur] = 0;
	rep(i,g[cur].size()){
		chmax(dp[cur], dfs(g[cur][i]) + 1);
	}
	return dp[cur];
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	dp.resize(n,-1);
	g.resize(n);
	rep(i,m){
		int x,y;cin >> x >> y;
		x--;y--;
		g[x].pb(y);
	}
	int ans = 0;
	rep(i,n){
		chmax(ans, dfs(i));
	}
	cout << ans << endl;
}


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

int main()
{
	vector<int> v(3);
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	if (v[0] == 5 && v[1] == 5 && v[2] == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 764
Amount_problem, Goal_point = map(int, input().split())
NumPro_ConpBonus = [[int(_) for _ in input().split()] for i in range(Amount_problem)]

min_num_ans = 1100
for i_binary in range(2**Amount_problem):
    num_ans = 0
    now_point = 0

    # Set highest scoring question to minimum position.
    for i_position in range(Amount_problem):
        if (i_binary >> i_position) & 1 == 0:
            continue

        now_point += NumPro_ConpBonus[(Amount_problem-1) - i_position][1] \
            + 100*(Amount_problem-i_position)*NumPro_ConpBonus[(Amount_problem-1) - i_position][0]

        num_ans += NumPro_ConpBonus[(Amount_problem-1) - i_position][0]

    if now_point < Goal_point:
        for i_position in range(Amount_problem):
            if (i_binary >> i_position) & 1 == 1:
                continue

            for add_num_ans in range(1, NumPro_ConpBonus[(Amount_problem-1) - i_position][0]):
                if (now_point + 100*(Amount_problem-i_position)*add_num_ans) >= Goal_point:
                    num_ans += add_num_ans
                    min_num_ans = min(min_num_ans, num_ans)
    else:
        min_num_ans = min(min_num_ans, num_ans)

print(min_num_ans)

Measured memory_bytes: 44272
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (b); i >= (a); i--)
#define xx first
#define yy second
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N = 200010;
const int maxn = 1e9+7;
char s[N];
int main()
{
    ll tmp=0,ans=0;
    scanf("%s",s);
    int len = strlen(s);
    rep(i,0,len-1)
        if(s[i]=='B')tmp++;
        else ans+=tmp;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
    printf("1x1=1\n");
    printf("1x2=2\n");
    printf("1x3=3\n");
    printf("1x4=4\n");
    printf("1x5=5\n");
    printf("1x6=6\n");
    printf("1x7=7\n");
    printf("1x8=8\n");
    printf("1x9=9\n");

    printf("2x1=2\n");
    printf("2x2=4\n");
    printf("2x3=6\n");
    printf("2x4=8\n");
    printf("2x5=10\n");
    printf("2x6=12\n");
    printf("2x7=14\n");
    printf("2x8=16\n");
    printf("2x9=18\n");

    printf("3x1=3\n");
    printf("3x2=6\n");
    printf("3x3=9\n");
    printf("3x4=12\n");
    printf("3x5=15\n");
    printf("3x6=18\n");
    printf("3x7=21\n");
    printf("3x8=24\n");
    printf("3x9=27\n");

    printf("4x1=4\n");
    printf("4x2=8\n");
    printf("4x3=12\n");
    printf("4x4=16\n");
    printf("4x5=20\n");
    printf("4x6=24\n");
    printf("4x7=28\n");
    printf("4x8=32\n");
    printf("4x9=36\n");

    printf("5x1=5\n");
    printf("5x2=10\n");
    printf("5x3=15\n");
    printf("5x4=20\n");
    printf("5x5=25\n");
    printf("5x6=30\n");
    printf("5x7=35\n");
    printf("5x8=40\n");
    printf("5x9=45\n");

    printf("6x1=6\n");
    printf("6x2=12\n");
    printf("6x3=18\n");
    printf("6x4=24\n");
    printf("6x5=30\n");
    printf("6x6=36\n");
    printf("6x7=42\n");
    printf("6x8=48\n");
    printf("6x9=54\n");

    printf("7x1=7\n");
    printf("7x2=14\n");
    printf("7x3=21\n");
    printf("7x4=28\n");
    printf("7x5=35\n");
    printf("7x6=42\n");
    printf("7x7=49\n");
    printf("7x8=56\n");
    printf("7x9=63\n");

    printf("8x1=8\n");
    printf("8x2=16\n");
    printf("8x3=24\n");
    printf("8x4=32\n");
    printf("8x5=40\n");
    printf("8x6=48\n");
    printf("8x7=56\n");
    printf("8x8=64\n");
    printf("8x9=72\n");

    printf("9x1=9\n");
    printf("9x2=18\n");
    printf("9x3=27\n");
    printf("9x4=36\n");
    printf("9x5=45\n");
    printf("9x6=54\n");
    printf("9x7=63\n");
    printf("9x8=72\n");
    printf("9x9=81\n");
    
    return 0;
}

Measured memory_bytes: 524