akhauriyash/Code-Regression huggingface dataset:
ABCD = input()
a = int(ABCD[0])
b = int(ABCD[1])
c = int(ABCD[2])
d = int(ABCD[3])


for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = a
            if i==0:
                ans += b
                X="+"
            else:
                ans -= b
                X="-"
            if j==0:
                ans += c
                Y="+"
            else:
                ans -= c
                Y="-"
            if k==0:
                ans += d
                Z="+"
            else:
                ans -= d
                Z="-"
            if ans==7:
                print(str(a)+X+str(b)+Y+str(c)+Z+str(d)+"=7")
                exit()


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# ALDS1_3_A

def calc(a, b, op):
    
    if op == "+":
        return b + a
    elif op == "-":
        return b - a
    elif op == "*":
        return b * a

operator_list = ("+", "-", "*")
list = input().split()
stack = []
for i in list:
    if i in operator_list:
        a = stack.pop()
        b = stack.pop()
        stack.append(calc(a, b, i))
    else:
        stack.append(int(i))

print(stack.pop())


Measured memory_bytes: 5600
unittest
{
	assert( [ "5 4 2" ].parse.expand.solve == "5 3" );
	assert( [ "3 3 3" ].parse.expand.solve == "1 3" );
	assert( [ "314159265 358979323 84" ].parse.expand.solve == "448759046 224379523" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abk = input.front.split.to!( long[] );
	return tuple( abk[ 0 ], abk[ 1 ], abk[ 2 ] );
}

auto solve( long a, long b, long k )
{
	foreach( i; 0 .. k )
	{
		if( i % 2 == 0 )
		{
			// 高橋君のターン
			a -= ( a % 2 == 1 );
			b += a / 2;
			a /= 2;
		}
		else
		{
			// 青木君のターン
			b -= ( b % 2 == 1 );
			a += b / 2;
			b /= 2;
		}
	}
	return format( "%s %s", a, b );
}


Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
string s;
void solve()
{
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
	{
		cout << "Bad";
	}
	else
	{
		cout << "Good";
	}
}
int main()
{
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
def main() -> None:
    N = int(input())
    V = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    ans = 0
    for i in range(N):
        if V[i] > C[i]:
            ans += V[i] - C[i]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


bool p[1000001] = { false };

int main()
{
	int n;
	cin >> n;
	Vi A(n);
	rep(i, n)  cin >> A[i];

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

	int ans = 0;
	rep(i, n) {
		if (i != n - 1) {
			if (A[i] == A[i + 1]) {
				p[A[i]] = true;
				continue;
			}
		}
		if (!p[A[i]]) ans++;
		for (int j = A[i]; j <= 1000000; j += A[i]) p[j] = true;
	}
	cout << ans << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

using P = Point<long long>;
template<class T>
T polygonArea2(vector<Point<T>>& v) {
	T a = v.back().cross(v[0]);
	rep(i,0,sz(v)-1) a += v[i].cross(v[i+1]);
	return a;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vector<P> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i].x >> a[i].y;
	}
	for(int i = 0; i < n; i++){
		P r = a[(i+2) % n] - a[(i+1) % n];
		P s = a[i] - a[(i+1) % n];
		if(r.cross(s) < 0){
			cout << 0 << '\n';
			exit(0);
		}
	}
	cout << 1 << '\n';
}



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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  ll L, R; cin >> L >> R;
  if (L/2019!=R/2019) { cout << 0 << endl; return 0; }
  ll result = INF;
  for (ll i=L; i<R; i++) {
    for (ll j=i+1; j<=R; j++) {
      result = min(result,i*j%2019);
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double,double> P;
const double INF=-(1<<29);
int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    for(int i=0; i<n; i++) scanf("%lf%lf",&a[i].F,&a[i].S);
    double l=0,r=111111;
    for(int t=0; t<30; t++) {
      double m=(l+r)/2;
      vector<P> v;
      for(int i=0; i<n; i++) {
        if(a[i].S<=m) continue;
        double x=sqrt(a[i].S*a[i].S-m*m);
        v.push_back(P(a[i].F-x,-1));
        v.push_back(P(a[i].F+x,1));
      }
      sort(v.begin(),v.end());
      int d[v.size()+1];
      memset(d,0,sizeof(d));
      double x=INF,y=0;
      for(int i=0; i<v.size()+1; i++) {
        if(i) d[i]=d[i-1]-v[i-1].S;
        if(x==INF&&d[i]>0) x=v[i-1].F;
        if(d[i]==0) {
          if(x!=INF) y=max(y,v[i-1].F-x);
          x=INF;
        }
      }
      if(y>=m*2) l=m;
      else r=m;
    }
    printf("%.9f\n",l*2);
  }
  return 0;
}


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



using namespace std;

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

  long long p,q,r,s;
  p=a*c;
  p = max(p,a*d);

  q = b*c;
  q = max(q,b*d);

  cout<<max(p,q)<<endl;


}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N = int(input())

    answer = 0
    for i in range(1, N+1):
        quotient = N // i
        answer += (((1+quotient)*quotient) // 2) * i
    print(answer)

if __name__ == "__main__":
    main()



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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector <int> b(n);
    for (int i = 1; i < n; i++) {
        b[i] = (a[i] ^ a[i-1]); 
    }
    vector <int> c(n);
    int kek = 0;
    for (int i = 1; i < n; i += 2) {
        kek ^= b[i];
    }
    for (int i = 0; i < n; i++) {
        cout << (kek ^ a[i]) << ' ';
    }
    return 0;
}


Measured memory_bytes: 5560
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	int N =	sc.nextInt();
	int ans	= 0;
	for(int i = 0; i<N; i++) {
            ans	+= i+1;
	}
	System.out.println(ans);
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>
#include <map>

using namespace std;

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

	map<int, pair<int, int>> info;

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			int a;
			cin >> a;

			info[a] = make_pair(i, j);
		}
	}

	vector<vector<bool>> bingo(3, vector<bool>(3, false));

	int N;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;

		if (info.find(a) != info.end())
		{
			bingo[info[a].first][info[a].second] = true;
		}
	}

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

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

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

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

	cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

int house[5][4][11] = {0};

int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
	int b,f,r,v;
	scanf("%d %d %d %d",&b,&f,&r,&v);
	house[b][f][r] += v;
}




for(int building=1;building<5;building++){
	for(int floor=1;floor<4;floor++){
		for(int room = 1;room<11;room++){
			printf(" %d",house[building][floor][room]);
		}
		printf("\n");
	}

	
	if(building == 4){
		break;
	}

	printf("####################");
	printf("\n");
}



	return 0;
}


Measured memory_bytes: 2100
def cal(a,b):
    if 4*a*b-A*(a+b)>0:
        return (A*a*b)/(4*a*b-A*(a+b))
    else:
        return -1
A = int(input())
for i in range(1,3501):
    for j in range(i,3501):
        t = cal(i,j)
        if t == -1:
            continue
        if t == int(t):
            print(i,j,int(t))
            exit()

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
#define repe(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mst(a, b)   memset((a), (b), sizeof(a))
#define gc() gutchar()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pr;
typedef long long ll;
const double eps = 1e-5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const ll mod = 1e9+7;
const int N = 2e5+5;

struct node
{
	ll x, h;
	bool operator< (const node &a) const { return x < a.x; }
} p[N];

ll q[N], res;

int main()
{
	int n, d, a;
	cin >> n >> d >> a;
	d <<= 1;
	repe(i, 1, n){
		scanf("%lld %lld", &p[i].x, &p[i].h);
	}
	sort(p + 1, p + n + 1);
	repe(i, 1, n){
		q[i] += q[i-1];
		p[i].h -= q[i] * a;
		if (p[i].h <= 0) continue;
		ll t = (p[i].h + a - 1) / a;
		res += t; q[i] += t;
		ll l = i, r = n;
		ll temp = p[i].x + d;
		while (l < r)
		{
			ll mid = l + r + 1 >> 1;
			if (p[mid].x <= temp)	l = mid;
			else	r = mid - 1;
		}
		q[l + 1] -= t;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 4992
//code written by a living bruh moment
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;

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

    public static void main(String[] args) {
        String s = in.next();
        String t = in.next();
        HashMap<Character, Character> hm = new HashMap<Character,Character>();
        HashMap<Character, Character> hm2 = new HashMap<Character,Character>();
        boolean check = true;
        for(int i = 0; i<s.length(); i++){
            if(!hm.containsKey(s.charAt(i))){
                hm.put(s.charAt(i),t.charAt(i));
            }
            else{
                if(hm.get(s.charAt(i)) != t.charAt(i)){
                    check = false;
                    out.println("No");
                    break;
                }
            }
            if(!hm2.containsKey(t.charAt(i))){
                hm2.put(t.charAt(i),s.charAt(i));
            }
            else{
                if(hm2.get(t.charAt(i)) != s.charAt(i)){
                    check = false;
                    out.println("No");
                    break;
                }
            }
        }
        if(check) out.println("Yes");
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong()
        {
            return Long.parseLong(next());
        }
        public double nextDouble()
        {
            return Double.parseDouble(next());
        }
        public String nextLine()
        {
            try
            {
                return reader.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }
        public boolean hasNext()
        {
            String next=null;
            try
            {
                next=reader.readLine();
            }
            catch(Exception e)
            {
            }
            if(next==null)
            {
                return false;
            }
            tokenizer=new StringTokenizer(next);
            return true;
        }
    }
}

Measured memory_bytes: 38868
#include<stdio.h>
int main()
{
 int n,m,l,i,j,k;
 long int sum;
 int nl[100][100]={0};

 scanf("%d%d%d",&n,&m,&l);
int nm[100][100];
int ml[100][100];


for(i=0;i<n;i++){               
      for(j=0;j<m;j++){
                        scanf("%d",&nm[i][j]);
                        }
                  }
for(i=0;i<m;i++){               
      for(j=0;j<l;j++){
                        scanf("%d",&ml[i][j]);
                        }
                 }

for(i=0;i<n;i++){      
                         
      for(j=0;j<l;j++){
                        sum=0;  
                        for(k=0;k<m;k++){
                                           sum+=nm[i][k]*ml[k][j];
                                         }
                        printf("%ld",sum);
                        if(j+1==l)printf("\n");
                      
                         else printf(" ");

                        }
                  }
 return 0;
}







Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    rep(i,s.size()) cout << (char)('A'+(s[i]+n-'A')%26);

    cout << endl;

    return 0;
    
}

Measured memory_bytes: 256
if __name__ == '__main__':
    n= int(input())
    s = [int(i) for i in input().split(" ")]
    dict = {}
    for i in s:
        if i in dict:
            dict[i] = dict[i]+1
        else:
            dict[i] = 1
    sum = 0
    for i in dict.values():
        if i > 1:
            sum = sum + (i-1)*i//2

    for i in s:
        num = sum
        if i in dict :
            num = num -dict[i] +1
        print(num)

Measured memory_bytes: 26140
#include <stdio.h>

int main(){
    int x, y;
    scanf("%d %d", &x, &y);
    
    if(y % 2 == 1){
       printf("No");
    }else if(y >= 2*x && y <= 4*x) {
       printf("Yes");
    }else{
       printf("No");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 1728
import sys
 
v = ""
for line in sys.stdin:
    v = [int(i) for i in line.split("/")]
 
if v[0] < 2019:
  print("Heisei")
elif v[0] == 2019 and v[1] <= 4 and v[2] <= 30:
  print("Heisei")
else:
  print("TBD")
 

Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
    int k, l;
    int ans = 1;

    scanf("%d", &k);

    if (k % 7 == 0)
        l = 9 * k / 7;
    else 
        l = 9 * k;
    
    if (l % 2 == 0 || l % 5 == 0)
        ans = -1;
    else 
    {
        int remain = 10 % l;

        while (remain != 1) {
            remain = remain * 10 % l;
            ans++;
        }
    }

    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

int target = 0;

int e(){return -1;}
int op(int a,int b){return max(a,b);}
bool f(int n){return n < target;}

int main(){
  
  int n,Q;
  cin >> n >> Q;
  vector<int> v(n);
  rep(i,n)cin >> v[i];
  segtree<int,op,e> seg(v);
  while(Q--){
    int t,l,r;cin >> t >> l >> r;
    if(t == 1){
      seg.set(--l,r);
    }else if(t == 2){
      cout << seg.prod(--l,r) << "\n";
    }else{
      target = r;
      cout << seg.max_right<f>(--l)+1 << "\n";

    }
  }

  


  return 0;
}

Measured memory_bytes: 6164
n = input()
s = list(map(int, input().split()))
c = 0
while True:
        exist = False
        #print(s)
        for i in range(len(s)):
                #print(i)
                if s[i]%2 != 0:
                        exist = True

        if exist:
                print(c)
                break
        for i in range(len(s)):
                s[i] = s[i]/2
        c += 1

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

int main() {
  ll a,b,c; cin >> a >> b >> c;
  ll d = c-a-b;
  if (d > 0 && d*d > 4*a*b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
    long long H;
    cin >> H;

    long long ans = 0, cnt = 1;
    while (H > 0) {
        ans += cnt;
        H /= 2;
        cnt *= 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
n, t = map(int, input().split())

a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

dp = [[0 for j in range(t+1)] for i in range(n+1)]
prev = [[(0, 0) for j in range(t+1)] for i in range(n+1)]

for i in range(n):
    for j in range(t):
        if j + a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
                prev[i+1][j+a[i]] = (i, j)
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]
            prev[i+1][j] = (i, j)

happy = dp[n][t-1]
i = n
j = t-1


used = set([])
while i > 0 or j > 0:
    pi, pj = prev[i][j]
    if dp[pi][pj] != dp[i][j]:
        used.add(pi)
    i = pi
    j = pj

unused = []
for i in range(n):
    if i not in used:
        unused.append(b[i])

if len(unused) == 0:
    ans = happy
else:
    ans = happy + max(unused)

print(ans)





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

int main () {
  int k, s;
  cin >> k >> s;
  int counter=0;
  for (int x=0; x<=k; x++) {
    for (int y=0; y<=k; y++) {
      int niko = x+y;
      if (s-niko <= k && s-niko >= 0) {
        counter++;
      }
    }
  }
  cout << counter <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define pb push_back
typedef long long ll;
typedef pair<ll,ll>P;
#define fi first
#define sc second
#define mp make_pair
int n,c;
vector<int>za[(1<<18)];
vector<ll>sum[(1<<18)];
vector<ll>num[(1<<18)];
int a[100005],cc[100005];
void add(int i,int v){
	i += (1<<17)-1;
	za[i].pb(v);
}
void make(){
	for(int i=(1<<18)-1;i>=(1<<17)-1;i--){
		sort(za[i].begin(),za[i].end());
		za[i].erase(unique(za[i].begin(),za[i].end()),za[i].end());
		sum[i].resize(za[i].size()+1,0);
		num[i].resize(za[i].size()+1,0);
	}
	for(int i=(1<<17)-2;i>=0;i--){
		za[i].resize(za[i*2+1].size()+za[i*2+2].size());
		merge(za[i*2+1].begin(),za[i*2+1].end(),za[i*2+2].begin(),za[i*2+2].end(),za[i].begin());
		za[i].erase(unique(za[i].begin(),za[i].end()),za[i].end());
		sum[i].resize(za[i].size()+1,0);
		num[i].resize(za[i].size()+1,0);
	}
}
int f(int x){ return x&-x;}
void addsum(int pos,int k,int a){
	for(int i=k;i<sum[pos].size();i+=f(i)) sum[pos][i]+=a;
}
void addnum(int pos,int k,int a){
	for(int i=k;i<num[pos].size();i+=f(i)) num[pos][i]+=a;
}
ll sumsum(int pos,int k){
	ll res = 0;
	for(int i=k;i>0;i-=f(i)) res+=sum[pos][i];
	return res;
}
ll sumnum(int pos,int k){
	ll res = 0;
	for(int i=k;i>0;i-=f(i)) res+=num[pos][i];
	return res;
}
ll query(int a,int b,int k,int l,int r,int aa){
	if(r<a||b<l) return 0;
	if(a<=l&&r<=b){
		int x = lower_bound(za[k].begin(),za[k].end(),aa)-za[k].begin();
		ll v = sumsum(k,x)*1LL*c + sumnum(k,x)*1LL*aa; //cout<<sumsum(k,x)<<" " << sumnum(k,x)<<endl;
		v += (sumsum(k,sum[k].size()-1)-sumsum(k,x)) + (sumnum(k,sum[k].size()-1)-sumnum(k,x))*1LL*c*aa;
		/*if(v){
				cout<<(sumnum(k,sum[k].size()-1)-sumnum(k,x))<<endl;
				cout<<(sumsum(k,sum[k].size()-1)-sumsum(k,x))<<endl;
				cout<<a<<b<<endl;
				cout<<"===="<<endl;
		}*/
		return v;
	}
	return query(a,b,k*2+1,l,(l+r)/2,aa)+query(a,b,k*2+2,(l+r)/2+1,r,aa);
}
void make2(int a,int b){
	a += (1<<17)-1;
	int c = lower_bound(za[a].begin(),za[a].end(),b)-za[a].begin()+1;
	addsum(a,c,b); addnum(a,c,1);
	while(a){
		a = (a-1)/2;
		c = lower_bound(za[a].begin(),za[a].end(),b)-za[a].begin()+1;
		addsum(a,c,b); addnum(a,c,1);
	}
}
int main(){
	cin>>n>>c;
	rep(i,n)cin>>a[i]>>cc[i];
	rep(i,n){
		add(a[i],cc[i]);
	}
	make(); ll ret = 0; //return 0;
	for(int i=0;i<n;i++){
		ret += query(a[i]+1,(1<<17)-1,0,0,(1<<17)-1,cc[i]);
		//cout<<ret<<endl;
		make2(a[i],cc[i]);
	}
	cout<<ret<<endl;
}



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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll a;
  string s;
  cin >> a >> s;
  if (a >= 3200) {
    COUT(s);
  }
  else {
    COUT("red");
  }

}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
  static public void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    if(S.length()!=3)System.exit(0);
    if(S.equals("RRR")){
      System.out.println("3");
      System.exit(0);
    }
    if(S.equals("RRS") || S.equals("SRR")){
      System.out.println("2");
      System.exit(0);
    } if (S.equals("SSS")){
        System.out.println("0");
      System.exit(0);
    } else {
      System.out.println("1");
    }
 }
}

Measured memory_bytes: 35564
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;

void solve()
{
	int x,n;
	cin>>x>>n;
	int arr[101];
	int a;
	loop(i,0,n)
	{
		cin>>a;
		arr[a] = 1;
	}
	int left = x;
	int right = x;
	while(true)
	{
		if(arr[left]!=1)
		{
			cout<<left<<endl;
			break;
		}
		if(arr[right]!=1)
		{
			cout<<right<<endl;
			break;
		}
		left--;
		right++;
	}
}

int32_t main()
{
	FastIO; PRECISION;
	int t = 1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
} 

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  int a,b,c;
  cin >> a >>b >>c;
  int left = 4 * a * b;
  int right = c*c - 2*a*c -2*b*c + 2*a*b + a*a + b*b;
  //if(sqrt(a) + sqrt(b) < sqrt(c)) puts("Yes");
  if( c - a - b <= 0) {
    puts("No"); return 0;
  }
  if(left < right) puts("Yes");
  else puts("No");
}


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

using namespace std;

typedef struct QRY {
  int a;
  int b;
  int c;
  int d;
} qry_t;

int main(void) {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<qry_t> qry(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> qry.at(i).a >> qry.at(i).b >> qry.at(i).c >> qry.at(i).d;
  }

  vector<vector<int>> A(1, vector<int>(N)), Am(0, vector<int>(N));
  A.at(0).at(0) = 1;

  /* 数列をDFSで列挙 */
  for (int i = 1; i < N; i++) {
    Am = A;
    A.clear();

    for (auto it = Am.begin(); it != Am.end(); ++it) {
      for (int j = it->at(i-1); j <= M; ++j) {
        vector<int> a = *it;
        a[i] = j;
        A.push_back(a);
      }
    }
  }
  
  int ans = 0;
  for (auto it = A.begin(); it != A.end(); ++it) {
    int tmp = 0;
    for (int i = 0; i < Q; ++i) {
      if (it->at(qry.at(i).b - 1) - it->at(qry.at(i).a - 1) == qry.at(i).c) {
        tmp += qry.at(i).d;
      }
    }
    ans = max(tmp, ans);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8364
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#define DBG(...) {string dst__=#__VA_ARGS__;dreplace(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dreplace(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
constexpr LL LINF=334ll<<53; constexpr int INF=15<<26; constexpr LL MOD=1E9+7;

VLL fac(1003),inv(1003);
long long modpow(long long a, long long n,long long mod=MOD){
    long long i=1,ret=1,p=a;
    while(i<=n){
        if(i&n) ret=(ret*p)%mod;
        i=(i<<1);
        p=(p*p)%mod;
    }
    return ret;
}
/*long long modpow(long long a, long long n){
    if(n==0) return 1;
    long long re=modpow((a*a)%MOD,n/2)%MOD;
    if(n%2==1) re= (re*a)%MOD;
    return re;
}*/

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    fac[0]=1; inv[0]=1;
    for(int i=1; i<1003; ++i){
        fac[i]=fac[i-1]*i%MOD;
    }
    inv[1002]=modpow(fac[1002],MOD-2);
    for(int i=1001; i>=1; --i){
        inv[i]=inv[i+1]*(i+1)%MOD;
    }
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >>d;
    vector<VLL> dp(n+1,VLL(n+1));
    dp[a-1][0]=1;
    for(int i=a; i<=b; ++i){
        dp[i][0]=1;
        for(int j=1; j<=n; ++j){
            if(j<n) dp[i][j]=dp[i-1][j];
            for(LL k=c; k<=min(d,j/i); ++k){
                LL den=((modpow(fac[i],k)*fac[k])%MOD*fac[n-j])%MOD;
                dp[i][j]=(dp[i][j]+(dp[i-1][j-i*k]*fac[n-j+i*k])%MOD*modpow(den,MOD-2))%MOD;
            }
        }
    }
    LL ans=0;
    for(int i=a; i<=b; ++i){
        ans=(ans+dp[i][n])%MOD;
    }
    cout <<ans <<"\n";

    return 0;
}



Measured memory_bytes: 8192
a, b, c = gets.split.map(&:to_i)

1000.times do |i|
  unless a.even? && b.even? && c.even?
    puts i
    exit
  end
  
  a2 = (b + c) / 2
  b2 = (c + a) / 2
  c2 = (a + b) / 2
  a = a2
  b = b2
  c = c2
end

puts(-1)


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, h, w, b, a[100000];

  cin >> h >> w >> n;
  ll cnt = 0;
  for(int i = 1; i <= n; i++) {
    cin >> b;
    for(int j = 0; j < b; j++) {
      a[cnt] = i;
      cnt++;
    }
  }
  cnt = 0;
  for(int i = 0; i < h; i++) {
    if (i % 2 == 1) {
      reverse(a + cnt, a + cnt + w);
    }
    for(int j = cnt; j < cnt + w; j++) {
        cout << a[j] << " ";
    }
    cnt += w;
    cout << endl;
  }

	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{int a,b,c,d,s1=0,s2=0;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
if(a<b) s1=a;
else s1=b;
if(c<d) s2=c;
else s2=d;
printf("%d",s1+s2);
return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, C, K; cin >> N >> C >> K;
  vector<ll> T(N); REP(i, N) cin >> T[i];
  sort(all(T));
  ll k = 0;
  ll cnt = 0;
  ll tmp = 0;
  bool flag = false;
  for(int i = 0; i < N; ++i) {
    if(T[k] + K >= T[i]) {
      tmp++;
      if(tmp == C) {
        tmp = 0;
        cnt++;
        k = i + 1;
        if(i + 1 == N) flag = true;
      }
    } else {
      tmp = 1;
      cnt++;
      k = i;
    }
  }
  if(flag == false) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 5e3 + 20;

struct vec {
    ld x, y;

    vec rotate(ld a) {
        return vec{x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)};
    }

    vec operator-(vec other) {
        return vec{x - other.x, y - other.y};
    }

    vec operator*(ld a){
        return vec{x * a, y * a};
    }

    ld len(){
        return sqrt(x * x + y * y);
    }
};

void solve() {
    ld pi = acos(-1.0);

    ll a, b, h, m;
    cin >> a >> b >> h >> m;

    ld angle1 = 2 * pi * (60 * h + m) / (12 * 60);
    ld angle2 = 2 * pi * m / 60;


    vec e = vec{0, 1}.rotate(angle1) * a;
    vec f = vec{0, 1}.rotate(angle2) * b;

    cout << (e - f).len();
}

#else

void solve() {

}

#endif

void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case #" << (i++) << ": ";
        solve();
        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
    //    gen();
#endif

}


Measured memory_bytes: 4180
#include<stdio.h>
#define MAX 100005
#define NIL -1
 
typedef struct{
  int parent, left, right;
}Node;
 
Node Tree[MAX];
int Depth[MAX];
int degree[MAX];
int h;
 
void preOrder(int);
void inOrder(int);
void postOrder(int);
 
int main(void){
  int i, n, root;
  int vertex;
  int child[2];
 
 
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ) {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &vertex, &child[0], &child[1]);
 
    //子どもがいない場合はdegreeは0である。
    if(child[0] == NIL && child[1] == NIL)
      degree[vertex] = 0;
 
    //子どもがどちらかにいればdegreeは1である。
    else if(child[0] == NIL && child[1] != NIL){
      degree[vertex] = 1;
      Tree[child[1]].parent = vertex;
      Tree[vertex].right = child[1];
    }
     
    else if(child[0] != NIL && child[1] == NIL){
      degree[vertex] = 1;
      Tree[child[0]].parent = vertex;
      Tree[vertex].left = child[0];
    }
 
 
    //子どもが両方存在するという事はdegreeは2という事
    else{
      degree[vertex] = 2;
      Tree[child[0]].parent = vertex;
      Tree[child[1]].parent = vertex;
       
      Tree[vertex].left = child[0];
      Tree[vertex].right = child[1];
    }
  }

  for (i = 0; i < n; i++)
  {
    if (Tree[i].parent == NIL){
      root = i;
    }
  }

  printf("Preorder\n");
  preOrder(root);
  printf("\n");
 
  printf("Inorder\n");
  inOrder(root);
  printf("\n");
 
  printf("Postorder\n");
  postOrder(root);
  printf("\n");
 
  return 0;
}
 
void preOrder(int n) {
  if(n == NIL)return;
  printf(" %d", n);
  preOrder(Tree[n].left);
  preOrder(Tree[n].right);
}
 
void inOrder(int n) {
  if(n == NIL)return;
  inOrder(Tree[n].left);
  printf(" %d", n);
  inOrder(Tree[n].right);
}
 
void postOrder(int n) {
  if(n == NIL)return;
  postOrder(Tree[n].left);
  postOrder(Tree[n].right);
  printf(" %d", n);
}
 



Measured memory_bytes: 2048
import java.util.*;
 
class Main {
    
	static int res=0,d,w,E[][]=new int[10][10];
	
    public static void main(String[] args) {
         
       Scanner cin=new Scanner(System.in);
       
       while(true) {
    	   d=cin.nextInt();w=cin.nextInt();
    	   if(d==0)break;
    	   res=0;
    	   for(int i=0;i<d;i++) {
    		   for(int j=0;j<w;j++)E[i][j]=cin.nextInt();
    	   }
    	   solve(3,3);
    	   System.out.println(res);
       }  
    }
    
    static void solve(int y,int x){
    	
    	
    	for(int a=0;a<=d-y;a++) {
    		for(int b=0;b<=w-x;b++) {
    			int Emin=10,Imax=0;
    			for(int i=a;i<a+y;i++) {
    	    		for(int j=b;j<b+x;j++) {
    	    			
    	    			//System.out.print(y+" "+x+" "+i+" "+j+" "+E[i][j]+" ");
    	    			if(i==a || i==a+y-1 || j==b || j==b+x-1) {
    	    				//System.out.print("E");
    	    				Emin=Math.min(E[i][j], Emin);
    	    			}
    	    			else {
    	    				//System.out.print("I");
    	    				Imax=Math.max(E[i][j], Imax);
    	    			}
    	    			
    	    			//System.out.println();
    	    		}
    	    	}
    			if(Imax<Emin) {
    				int cap=0;
    				for(int i=a+1;i<a+y-1;i++) {
    					for(int j=b+1;j<b+x-1;j++)cap+=Emin-E[i][j];
    				}
    				res=Math.max(cap, res);
    			}
    	    	//else System.out.println(y+" "+x+" "+a+" "+b+" "+Emin+" "+Imax+" "+"NO SPACE");
    			//System.out.println();
    			
    		}
    	}
    	
    	
    	
    	if(y<d)solve(y+1,x);
    	if(x<w)solve(y,x+1);
    }
}


Measured memory_bytes: 38368
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c,d;
    cin >> a >> b;
    if(a + b >= 10)cout << "error" << endl;
    else cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N,M;
    int l,r;
    int l_max,r_min;
    
    cin >> N >> M;
    
    cin >> l_max >> r_min;
    
    for(int i=1;i<M;i++){
        cin >> l >> r;
        if( l  > l_max)
            l_max = l;
        if( r < r_min)
            r_min = r;
    }
    
    if( r_min >= l_max){
        cout << r_min - l_max + 1 << endl;
    }else{
        cout << 0 << endl;
    }
    
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1,0),ans(N+1,0);
    vector<int> B;
    for(int i=1;i<=N;i++) cin >> A[i];
    bool ok = true;
    for(int i=N;i>=1;i--){
        int cnt = 0;
        for(int j=i;j<=N;j+=i){
            cnt += ans[j];
        }
        if(cnt%2!=A[i]){
            ans[i] = 1;
            B.push_back(i);
        }
    }
    cout << B.size() << endl;
    for(auto x:B) cout << x << endl;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define reps(i, s, n) for (int i = (s); i < (n); ++i)
#define repse(i, s, n) for (int i = (s); i <= (n); ++i)
#define repsr(i, n, s) for (int i = (n); i >= (s); --i)
#define all(xs) (xs).begin(), (xs).end()
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;

int main() {
  int A, B, K; cin >> A >> B >> K;
  int cnt = 0;
  for (int i = min(A, B); i >= 1; --i) {
    if (A % i == 0 && B % i == 0) cnt++;
    if (cnt == K) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int m = int.MaxValue;
            int total = 0;
            for (int i = 0; i < N; i++)
            {
                int v = int.Parse(Console.ReadLine());
                total += v;

                if (0 != v % 10)
                {
                    m = Math.Min(m, v);
                }
            }
            if (m == int.MaxValue)
            {
                Console.WriteLine(0);
                return;
            }

            if (0 == (total % 10))
            {
                total -= m;
            }

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13140
N = int(input())
low = 0
high = N - 1
t = (low + high) // 2
flag = 0
print(0)
resl = input()
print(N-1)
resr = input()
if resl == "Vacant" or resr == "Vacant":
    flag = 1

while(flag == 0):
    print(t)
    inp = input()
    if inp == "Vacant":
        break
    if (high-t) % 2 == 0 and inp != resr:
        low = t
        resl = inp
    elif (high-t) % 2 == 1 and inp == resr:
        low = t
        resl = inp
    elif (t-low) % 2 == 0 and inp != resl:
        high = t
        resr = inp
    else:
        high = t
        resr = inp
    t = (low + high) // 2



Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    int n; cin >> n;
    ll v[n][3];
    ll dp[n+1][3];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> v[i][j];
            dp[i][j] = 0;
        }
    }
    dp[1][0] = v[0][0];
    dp[1][1] = v[0][1];
    dp[1][2] = v[0][2];
    for(int i = 1; i < n; i++){
        dp[i+1][0] = max(dp[i][1] + v[i][0], dp[i][2] + v[i][0]);
        dp[i+1][1] = max(dp[i][0] + v[i][1], dp[i][2] + v[i][1]);
        dp[i+1][2] = max(dp[i][0] + v[i][2], dp[i][1] + v[i][2]);
    }
    cout << max({dp[n][0],dp[n][1],dp[n][2]});
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>

using namespace std;

int dp[1010][1010];



int solve() {

	string s,t;

	cin >> s >> t;


	int max_s = s.length();
	int max_t = t.length();

	memset(dp,0, sizeof(int) * 1010 * 1010);



	for (int i = 1; i <= max_s; i++) {
		for (int j = 1; j <= max_t; j++) {
			if (s.at(i - 1) == t.at(j -1)) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i][j - 1],dp[i -1][j]);			
			}
		}
	}
	return dp[max_s][max_t];
}

int main() {
	int q;

	cin >> q;

	for (int i = 0; i  < q; i++) {
		cout << solve() << endl;
	}

}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int p[200000];
	rep(i,n) scanf("%d",&p[i]);

	int mn=n+1;
	int ans=0;
	rep(i,n){
		if(p[i]<=mn) ans++;
		mn=min(mn,p[i]);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(){
    int h, w;
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                if(x == 0 || y == 0 || x == w-1 || y == h-1) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<math.h>
wn,wx[100],wy[100],wr[100];
tx,ty,sx,sy;
D(){
	int i,tx0,ty0,sx0,sy0,it,is;
	for(i=0;i<wn;i++){
		tx0=tx-wx[i];
		ty0=ty-wy[i];
		sx0=sx-wx[i];
		sy0=sy-wy[i];
		it=hypot(tx0,ty0)<wr[i];
		is=hypot(sx0,sy0)<wr[i];
		if(it^is)
			return 0;
		if(!it&&!is)
			if(fabs((sy0-ty0)*sx0-(sx0-tx0)*sy0)/hypot(sx0-tx0,sy0-ty0)<=wr[i])
				if(-tx0*(sx0-tx0)-ty0*(sy0-ty0)>0&&-sx0*(tx0-sx0)-sy0*(ty0-sy0)>0)
					return 0;
	}
	return 1;
}
main(i,m){
	for(;scanf("%d",&wn),wn;){
		for(i=0;i<wn;i++)
			scanf("%d%d%d",wx+i,wy+i,wr+i);
		scanf("%d",&m);
		for(;m--;){
			scanf("%d%d%d%d",&tx,&ty,&sx,&sy);
			puts(D()?"Danger":"Safe");
		}
	}
	exit(0);
}

Measured memory_bytes: 0
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))

h = []
for ai in a:
    heapq.heappush(h, -ai)

for i in range(m):
    ai = heapq.heappop(h)
    heapq.heappush(h, -(-ai//2))

print(-sum(h))

Measured memory_bytes: 14180
#import<cstdio>
int t,n,c[510],s[510],f[510],i,a,j;main(){for(scanf("%d",&n);~scanf("%d%d%d",c+j++,s+j,f+j););for(f[j-1]=1;i<n;a=!printf("%d\n",a))for(j=i++;t=s[j];)a=(a<t?t:(~-a/f[j]+1)*f[j])+c[j++];}


Measured memory_bytes: 128