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

int main(){
  int x1,y1,x2,y2,x,y;
  cin>>x1>>y1>>x2>>y2;
  x=x2-x1; y=y2-y1;
  cout<<x2-y<<" "<<y2+x<<" ";
  cout<<x1-y<<" "<<y1+x<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int vis[100005];
int f[100],u[100],ans[100];
void findfic(void)
{

}
int main()
{
  //  ios::sync_with_stdio(false);
    /*cout << 4e5;
    ll n;
    cin >> n;
    if(n%2)
        cout << 0 << endl;
    else{

    }*/
    int n,m;
    cin >> n >> m;
    if(n<10)
        m+=100*(10-n);
    
    cout << m<< endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N, a;
	map<int, int> m;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a;
		m[a-1]++;m[a]++;m[a+1]++;
	}
	a = 0;
	for(auto itr = m.begin(); itr!=m.end(); itr++)
		if(a < itr->second)a = itr->second;
	cout << a << "\n";
	return 0;
}

Measured memory_bytes: 4736
fun main(args: Array<String>) {
    abc102c()
}

fun abc102c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toLong() }
        .mapIndexed { index, i -> i - (index + 1) }
        .sorted()

    val mid = aList[aList.size / 2]

    val answer = aList.map { Math.abs(it - mid) }.sum()

    println(answer)
}


Measured memory_bytes: 83040
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a + b >= 10) {
            System.out.println("error");
        } else {
            System.out.println(a + b);
        }
    }
}


Measured memory_bytes: 21844
using System;
using System.Linq;
using System.Collections.Generic;

using Point=System.Tuple<long,long>;

public static class Program {
    public static void Main() {
        int[]nk=Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine((nk[0]+nk[1]-1)/nk[1]);
    }
}


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

int Way[3][200];

int main()
{
  int N;
  cin >> N;
  for(int i=0;i<2;i++)
  {
    for(int j=0;j<N;j++) cin >> Way[i][j];
  }

  int total = Way[0][0];
  for(int i=0;i<N;i++) total += Way[1][i];
  int res = total;

  for(int i=1;i<N;i++)
  {
    total += Way[0][i] - Way[1][i-1];
    if(res < total) res = total;
  }
  cout << res << endl;
}


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

int main() {
  int n; cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int ans = 0;
  int t = p[0];
  for (int i = 0; i < n; i ++) {
    if (t >= p[i]) {
      ans ++;
      t = min(t, p[i]);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1152
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
      
      int a;
      int b;
      
      Scanner sc1 = new Scanner(System.in);
      a = sc1.nextInt();
      b = sc1.nextInt();
      
      if((a*b) % 2 == 0){
       System.out.println("Even");
      }else{
       System.out.println("Odd");
      }    
    }
}


Measured memory_bytes: 23124
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
X = gets.chomp.to_i

count = 0

(0..A).each do |a|
  (0..B).each do |b|
    (0..C).each do |c|
      count += 1 if (X == 500 * a + 100 * b + 50 * c)
    end
  end
end

puts count


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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; }
const int INF = 1000100100;

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

    ll A_minID = INF, Z_maxID = -1;
    REP(i, s.length()) {
        if(s[i] == 'A') {
            chmin(A_minID, i);
        }
        if(s[i] == 'Z') {
            Z_maxID = i;
        }
    }
    ll ans = Z_maxID - A_minID + 1;
    if(ans < 2) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'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'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    string s; cin >> s;
    int acount = 0, bccount = 0;
    ll ans = 0;
    int i = s.size()-1;
    for(; i-1 >= 0; i--){
        if(s[i] == 'C' && s[i-1] == 'B'){
            break;
            bccount++;
            i -= 2;
        }
    }
    for(; i >= 0; i--){
        if(s[i] == 'A'){
            acount++;
            ans += bccount;
        }else if(i-1 >= 0 && s[i] == 'C' && s[i-1] == 'B'){
            bccount++;
            i--;
        }else{
            bccount = 0;
            acount = 0;
        }
    }
    cout << ans <<endl; 
}

Measured memory_bytes: 644
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
const string FILENAME = "input";
const int MAXN = 200228;


int n, m;
int a[MAXN];



bool check(int x) {
	if (x == 0) {
		return 0;
	}
	for (int i = 2 * n - 1; i >= 2 * n - x; i--) {
		int len = 2 * n - 1 - i;
		if (a[2 * n - 2 * x + len] + a[i] < m) {
			return false;
		}
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	cin >> n >> m;
	for (int i = 0; i < 2 * n; i++) {
		cin >> a[i];
	}
	sort(a, a + 2 * n);
	int l = 0;
	int r = n;
	while (l != r) {
		int mid = (l + r + 1) >> 1;
		if (check(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int x = l;
	int ans = 0;
	for (int i = 0; i < 2 * n - 2 * x; i++) {
		chkmax(ans, a[i] + a[2 * n - 2 * x - 1 - i]);
	}
	for (int i = 2 * n - 1; i >= 2 * n - x; i--) {
		int len = 2 * n - 1 - i;
		chkmax(ans, a[2 * n - 2 * x + len] + a[i] - m);
	}
	cout << ans << '\n';
	return 0; 	
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int n;
    int a[128];
    int mini;
    int tmp;
    int i, j;

    scanf("%d", &n);
    for (i = 0; i < n; ++i){
        scanf("%d", a + i);
    }

    mini = (int)1e9;
    for (i = -100; i <= 100; ++i){
        tmp = 0;
        for (j = 0; j < n; ++j){
            tmp += (a[j] - i) * (a[j] - i);
        }
        if (tmp < mini){
            mini = tmp;
        }
    }

    printf("%d\n", mini);

    return (0);
}


Measured memory_bytes: 128
N, M=map(int,input().split())
a=[input() for _ in range(N)]
b=[input() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        count=0
        for k in range(M):
            for l in range(M):
                if a[i+k][j+l]!=b[k][l]:
                    break
                else:
                    count+=1
        if count==M*M:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int a,b;
  cin >> a >> b;
  if(b>a){
    rep(i,b) cout << a ;
  }
  else {
    rep(i,a) cout << b;
  }
  cout  << 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++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int n;
  cin >> n;
  vector<char> v(n);
  rep(i, n) { cin >> v[i]; }

  auto result = find(all(v), 'Y');

  if (result == v.end()) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=[0]*N

for i in range(N-1):
  B[i]=A[i+1]-A[i]
B[-1]=(A[0]+K)-A[-1]

#print(B)
print(sum(B)-max(B))

Measured memory_bytes: 26436
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    int cnt = 0, cnt_2 = 0, cnt_4 = 0;
    for(int i = 0; i < N; i++){
        if(a[i] % 4 == 0){
            cnt_4++;
        }else if(a[i] % 2 == 0){
            cnt_2++;
        }else{
            cnt++;
        }
    }

    if(cnt_2 == 0 && cnt <= cnt_4+1){
        cout << "Yes" << endl;
    }else if(cnt <= cnt_4){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
  int k, s;
  cin >> k;
  cin >> s;

  int result = 0;
  for (int x = 0; x <= k; x++) {
    if (s < x) {
      break;
    }

    for (int y = 0; y <= k; y++) {
      if (s < x + y) {
	continue;
      }

      if (s - (x + y) <= k)
	result++;
    }
  }

  cout << result << endl;
}



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

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}


// TODO: write
int main() {
  string s,t;cin>>s>>t;
  int ans = 0;
  rep(i,s.size())ans += s[i] == t[i];
  print(ans);
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	int N, M;
	cin >> N >> M;

	vector <ll> a(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}

	vector < pair <ll, ll > > vp(M);


	for (int i = 0; i < M; ++i)
	{
		ll b, c;
		cin >> b >> c;

		vp.push_back(make_pair(c, b));
	}

	sort(a.begin(), a.end());
	sort(vp.rbegin(), vp.rend());

	vector <ll> replace;

	for (const auto& p : vp)
	{
		for (int i=0;i<p.second;++i)
		{
			if (SZ(replace) >= N)
			{
				break;
			}

			replace.push_back(p.first);
		}
	}



	ll ret = 0;
	for (int i=0;i<N;++i)
	{
		if (SZ(replace)>i)
		{
			ret += max(replace[i], a[i]);
		}
		else
		{
			ret += a[i];
		}
	}


	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 5988
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

// B - Exponential
int main(){
    int X;
    cin >> X;
    
    vector<int> ans_vec = {1};
    for(int b=2;b<1000;++b){
        for(int p=2;p<1000;++p){
            if(pow(b, p)>X) break;
            ans_vec.push_back(pow(b, p));
        }
    }

    int ans = *max_element(ans_vec.begin(), ans_vec.end());
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
import itertools

N = int(input())

MARCH = [0]*5
ans = 0
for i in range(N):
  S = input()
  t = S[0]
  if t == "M":
    MARCH[0] += 1
  elif t == "A":
    MARCH[1] += 1
  elif t == "R":
    MARCH[2] += 1
  elif t == "C":
    MARCH[3] += 1
  elif t == "H":
    MARCH[4] += 1

comb = itertools.combinations(MARCH,3)

for j in comb:
  ans += j[0]*j[1]*j[2]
print(ans)
 

Measured memory_bytes: 44632
while 1:
    W, H = list(map(int,input().split()))
    if W == 0:break
 
    C = [list(map(int, input().split())) for i in range(H) ]
     
    def work(x,y):
        ax = [-1, 0, 1, -1, 1, -1, 0, 1]
        ay = [-1, -1, -1, 0, 0, 1, 1, 1]
 
        if C[y][x] != 1:return False
        stack = [(x,y)]
 
        while len(stack) > 0:
            s = stack.pop(-1)
            C[s[1]][s[0]] = -1 #mark
 
            for _x in [s[0] + _x for _x in ax]:
                for _y in [s[1] + _y for _y in ay]:
                    if 0 <= _x < W and 0 <= _y < H and C[_y][_x] == 1:
                        stack.append((_x, _y))
        return True
#    def work(x,y):
#        ax = [-1, 0, 1, -1, 1, -1, 0, 1]
#        ay = [-1, -1, -1, 0, 0, 1, 1, 1]
#
#        if C[y][x] != 1:return False
#        C[y][x] = -1 #mark
#
#        for _ax in ax:
#            for _ay in ay:
#                if 0 <= _ax + x < W and 0 <= _ay + y < H:
#                    work(_ax + x, _ay + y)
#        return True
 
    cnt = 0
    for x in range(W):
        for y in range(H):
            cnt += work(x,y)
    print(cnt)


Measured memory_bytes: 10428
#!/usr/bin/env python
# coding: utf-8

# In[15]:


N = int(input())


# In[16]:


ans = 0
if N%2 != 0:
    print(ans)
else:
    i = 1
    while 1:
        tmp = (5**i)*2
        if tmp <= N:
            ans += N//tmp
            i += 1
        else:
            break
    print(ans)


# In[ ]:






Measured memory_bytes: 9092
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong(), a = sc.nextLong(),
                b = sc.nextLong(), c = sc.nextLong(),
                d = sc.nextLong(), e = sc.nextLong();
        long min = Math.min(a, Math.min(b, Math.min(c, Math.min(d, e))));
        long num = (long)Math.ceil((double)n / min) - 1;
        System.out.println(num + 5);
    }
}


Measured memory_bytes: 35800
#include <iostream>

using namespace std;

int main()
{
  string n;
  cin >> n;
  for (int i = 0; i < n.size(); i++) {
    if (n[i] == '1')
      cout << '9';
    else if (n[i] == '9')
      cout << '1';
  }
  cout << endl;

  return 0;
}


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

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

    long long n, t;
    cin >> n >> t;
    vector<long long> T(n);
    for(int i = 0; i < n; i++){
        cin >> T[i];
    }

    long long ans = t;
    for(int i = 0; i < n - 1; i++){
        if(T[i] + t <= T[i + 1]){
            ans += t;
        }else{
            ans += T[i + 1] - T[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <functional>
using namespace std;

signed main(void)
{
	unsigned long long n, a, b;
	cin >> n >> a >> b;
	 unsigned long long h[100004];
	for (int i = 0; i < n; i++) {
		scanf("%lld", &h[i]);
	}
	unsigned long long lb =0; unsigned long long ub = 1000000000;
	while (ub - lb>1) {
		unsigned long long mid = (ub + lb) / 2;
		unsigned long long count = 0;
		for (int i = 0; i < n; i++) {
			if(h[i]>mid*b){
				count += (h[i] - mid*b) / (a - b);
				if ((h[i] - mid*b) % (a - b) != 0)count += 1;
			}
			if (count > mid)break;
		}
		if (count <= mid) { ub = mid; }
		else lb = mid;
	}
	cout << ub;
	return 0;
}

Measured memory_bytes: 1024
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= putStrLn . solve 

-- |
-- >>> solve [3, 1]
-- "Yes"
-- >>> solve [1, 2]
-- "No"
-- >>> solve [2, 2]
-- "No"
solve :: [Int] -> String 
solve xs
    | even (product xs) = "No"
    | otherwise = "Yes"

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 380
#include <iostream>

using namespace std;
long long n,a,b,c,d,dif;
int main()
{
    cin>>n>>a>>b>>c>>d;
    dif=b-a;
    for(long long i=0;i<=n-1;i++)
    {
        if(1LL*(n-1-i)*c-1LL*i*d<=dif&&1LL*(n-1-i)*d-1LL*i*c>=dif)
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

void main(){

    string[8] map;
    for(int i=0;i<8;i++) map[i] = readln().chomp();
    writeln(90);
    for(int j=0;j<8;j++){
	for(int k=0;k<8;k++){
	    write(map[7-k][j]);
	}
	writeln();
    }

    writeln(180);
    for(int j=0;j<8;j++){
	for(int k=0;k<8;k++){
	    write(map[7-j][7-k]);
	}
	writeln();
    }


    writeln(270);
    for(int j=0;j<8;j++){
	for(int k=0;k<8;k++){
	    write(map[k][7-j]);
	}
	writeln();
    }
}

Measured memory_bytes: 2436
#include <stdio.h>
int n, a[100];
int main() {
	while(true) {
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		int ret = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < i; j++) {
				if(a[i] < a[j]) {
					ret++;
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2604
#!/usr/bin/env python3

A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            Yen = 500 * a + 100 * b + 50 * c
            if (X == Yen):
                ans += 1

print(ans)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            String a = sc.next();
            for (int i=a.length(); i>0; i--){
                System.out.printf("%s",a.charAt(i-1));
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 25916
#include <bits/stdc++.h>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double lxd;
#define INF 1000000007
#define mem(dp,a) memset(dp,a,sizeof dp)
#define flash ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define f(i,n) for (ll i=0;i<n;i++)
#define fo(i,x,n) for (ll i=x;i<=n;i++)
#define pb(x) push_back(x)
#define tr(c,it) for(((c).begin())it=(c).begin();it!=(c).end();it++)
#define test ll t; cin>>t;
#define fls fflush(stdout) ;
int main()
{
  ll n;cin>>n;
  ll height[n],dp[n];
  for(ll i=0;i<n;i++)cin>>height[i];
  dp[0]=0;
  dp[1]=abs(height[1]-height[0]);
  for(ll i=2;i<n;i++)
  {
      dp[i]=min(dp[i-1]+abs(height[i-1]-height[i]),
      dp[i-2]+abs(height[i-2]-height[i]));
  }
  // for(ll i=0;i<n;i++)cout<<dp[i]<<" ";
  cout<<dp[n-1]<<endl;
   return 0; 
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 998244353;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int gcdExtended(int a, int b, int *x, int *y);

// Function to find modulo inverse of a
int modInverse(int a, int m) {
  int x, y;
  int g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    cout << "Inverse doesn't exist";
  else {
    // m is added to handle negative x
    int res = (x % m + m) % m;
    return res;
  }
}

// C function for extended Euclidean Algorithm
int gcdExtended(int a, int b, int *x, int *y) {
  // Base Case
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }

  int x1, y1; // To store results of recursive call
  int gcd = gcdExtended(b % a, a, &x1, &y1);

  // Update x and y using results of recursive
  // call
  *x = y1 - (b / a) * x1;
  *y = x1;

  return gcd;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;

  ll n = s.length();
  ll arr[n + 5];
  ll pre[n + 5];
  memset(pre, 0, sizeof(pre));
  ll val = 0;
  for (ll i = 1; i <= n; i++) {
    arr[i] = s[i - 1] - '0';
    val = val * 10 + arr[i];
    val %= 2019;
    pre[i] = (pre[i - 1] * 10 + arr[i]) % 2019;
  }

  for (ll i = 1; i <= n; i++) {
    pre[i] = (pre[i] * modInverse(power(10, i, 2019), 2019)) % 2019;
  }

  ll freq[3000];
  memset(freq, 0, sizeof(freq));
  freq[0] = 1;

  ll res = 0;
  for (ll i = 1; i <= n; i++) {

    res += freq[pre[i]];
    freq[pre[i]]++;
  }

  cout << res << en;

  return 0;
}


Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
unsigned long N;
unsigned long M;
unsigned long A[10000];
int ans;
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A[i];
    ans += A[i];
  }
  ans = N - ans;
  if (ans < 0) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
const long long mod = 1e9+7;
unsigned long long kaijou[200010];
unsigned long long g_kaijou[200010];
// g_kaijou[n] ha (n!)^-1

long long powmod(long long a, long long b, long long p){
// returns a**b (mod p)
    if (b == 0) {
        return 1;
    }
    else if(b % 2){
        return (a*powmod(a,b-1,p)) % p;
    }
    else{
        long long d = powmod(a, b/2,p);
        return (d*d) % p;
    }
}

long long nCr(int n, int r){
// nCr = (kaijou[n] * g_kaijou[r] * g_kaijou[n-r])
    if (n==r) return 1;
    else return kaijou[n]*g_kaijou[r]%mod*g_kaijou[n-r]%mod;
}

int main(){
    int H,W,A,B;
    cin >> H >> W >> A >> B;

    kaijou[0] = 1;
    kaijou[1] = 1;
    for(int i=2; i<=H+W+2; ++i){
        kaijou[i] = (kaijou[i-1]*i)%mod;}
    g_kaijou[0] = 1;
    for(int i=1; i<=H+W+2; ++i){
        g_kaijou[i] = powmod(kaijou[i],mod-2,mod);}

    long long ans = 0;
    for(int i=B+1; i<=W; ++i){
        ans += (nCr(H-A-1+i-1,H-A-1)*nCr(W-i+A-1,A-1))%mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

import sys

#def xcheck(n):
#	
#    m = int(n**.5)
#    return 1 if abs(m*m - n) < 1e-6 else 0
#	if(1):
#		#兵法数なら
#		return 1
#	return 0

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
l=hoge[0]
r=hoge[1]

if((r-l)>2019):
	print(0)
	sys.exit()

l=l%2019
r=((r-1)%2019)+1

#r=((r-1)%2019)+1
#if(l>r):
#	r+=2019

###
#print(l)
#print(r)

minans=2018
for i in range(l,r):
	for j in range(i+1,r+1):
		tmp = (i*j)%2019
		if tmp < minans:
			minans = tmp


#		print("{} {} minans {}".format(i,j,minans))
print(minans)





#print(min(n*a,b))

#print(n)
#print(a)
#print(b)




Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;



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

	cin >> N >> M;
	vector<int>num(N);
	for (int i = 0; i < N; i++) {
		cin >> num[i];
	}
	M = num[N - 1];
	K = 0;
	for (int i = N - 1; i >= 0; i--) {
		M = max((int)M, num[i]);
		K = max(K, M - num[i]);
		num[i] = M - num[i];
	}
	M = 0;
	for (int i = 0; i < N; i++) {
		if (num[i] == K)M++;
	}
	cout << M << endl;
	return 0;
}

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

int main()
{
ll n ;
cin >> n ;
ll w[n][2];
bool pa;
rep(i,n){
  ll x , y ;
  cin >> x >> y ;
  if(i==0)pa=(x+y+30000000000)%2;
  if((x+y+30000000000)%2!=pa){
    cout << -1 << endl;
    return 0;
  }
  if(!pa)x--;
  w[i][0]=x;
  w[i][1]=y;
}

if(pa)cout << 35 << endl;
else cout << 36 << endl;
rep(i,35){
  cout << (1LL<<(35-i-1)) << " ";
}
if(!pa)cout << 1 << " ";
cout << endl;
string ans[n]={};
rep(i,n){
  ll u=w[i][0]+w[i][1],v=w[i][0]-w[i][1];
  ll xx=0,yy=0;
  rep(j,35){
    if(u-xx>=0&&v-yy>=0){xx+=(1LL<<(35-j-1));yy+=(1LL<<(35-j-1));ans[i]+="R";}
    else if(u-xx<0&&v-yy<0){xx-=(1LL<<(35-j-1));yy-=(1LL<<(35-j-1));ans[i]+="L";}
    else if(u-xx>=0&&v-yy<0){xx+=(1LL<<(35-j-1));yy-=(1LL<<(35-j-1));ans[i]+="U";}
    else {xx-=(1LL<<(35-j-1));yy+=(1LL<<(35-j-1));ans[i]+="D";}
  }
  //if(xx==u&&yy==v)cout << "ok" << endl;
}
rep(i,n){
  if(pa)cout << ans[i] << endl;
  else cout << ans[i]+"R" << endl;
  
}
return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BShiftOnly solver = new BShiftOnly();
        solver.solve(1, in, out);
        out.close();
    }

    static class BShiftOnly {
        int count = 0;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            divide(a);
            out.println(count);
        }

        private void divide(int[] arr) {
            if (Arrays.stream(arr).allMatch(i -> i % 2 == 0)) {
                count++;
                divide(Arrays.stream(arr).map(i -> i / 2).toArray());
            }
        }

    }
}


Measured memory_bytes: 28876
import math
a,b,h,m=map(int,input().split())
h=(h+m/60)*30
m=m*6
if m==0:m=360
j=max(m,h)-min(m,h)
if j>180:j=360-j
if j==180:print(a+b)
elif j==0:print(max(a,b)-min(a,b))
elif j==90:print(math.sqrt(a**2+b**2))
else:print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi/(180/j))))


Measured memory_bytes: 9460
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();
		int B = in.nextInt();
		if (A < 10 && B < 10) {
			System.out.println(A * B);
		} else {
			System.out.println(-1);
		}
		in.close();
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
 
using ll = long long;
using namespace std;


void solveCase() {
   int n;
   vector <int> v(3), v1(3);
   for(auto &e: v) cin >> e;

   int ans = 0;
   map <vector <int>, bool> m;

   while(true) {
      if(m.find(v) != m.end()) {
         cout << -1 << endl;
         return;
      }
      bool odd = false;
      for(auto e: v) if(e % 2 != 0) odd = true;
      if(odd) break;
      ans++;
      m[v] = true;
      v1[0] = (v[1] + v[2]) / 2;
      v1[1] = (v[0] + v[2]) / 2;
      v1[2] = (v[0] + v[1]) / 2;
      v = v1;
   }
   cout << ans << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solveCase();
   }
 
   return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
int main(){
    int a[5];
    while(~scanf("%d",&a[0])){
        for(int i=1;i<5;i++){
            scanf("%d",&a[i]);
        }
        std::sort(a,a+5);
        std::reverse(a,a+5);
        for(int i=0;i<4;i++){
            printf("%d ",a[i]);
        }
        printf("%d\n",a[4]);
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	fast;
	
	ll int n;
	cin>>n;
	
	if(n%2==1)
	cout<<0;
	
	else{
		ll int cnt=0;
		for(ll int i=5;i<=n/2;i*=5){
			cnt+=(n/(2*i));
		}	
		
		cout<<cnt;
	}
	
	return 0;
}

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

int n,d;

int main(){

	cin >> n >> d;
	int last = 1;
	int ans = 0;
	while ( last <= n ){
		ans++;
		last += 2 * d + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
  
	multiset<int> s;
	int q;
	cin >> q;
	while(q--){
		int op, el;
		cin >> op >> el;
		if(op == 1)cout << s.count(el) << '\n';
		else if(op == 2)s.erase(el);
		else if(op == 3){
			int r;cin >> r;
			auto lef = s.lower_bound(el);
			auto right = s.upper_bound(r);
			while(lef != right)cout << *lef << '\n', lef++;
			
		}
		else s.insert(el), cout << s.size() << '\n';
	}
    return 0;
}



Measured memory_bytes: 12396
#include<bits/stdc++.h>
#define ll  long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define f(i,n)   for(long long i=0;i<n;i++)
#define INF 1e9+5
#define LINF 1e18L+5;
#define pb push_back
#define mk make_pair
using namespace std;
/************************BELIAL**********DEVIL*********BELIAL***********DEVIL*************************/
void max_self(long long &a,long long b)
{
  a= max(a,b);
  return;

}
int main()
{

 long long n;

 long long W;
 cin>>n>>W;

 vector<long long> dp(W+1,0);// dp[i]= max value having weight less than or equal i


 for(long long item=0;item<n;item++)
 {
    long long w,v;
    	cin>>w>>v;

    	for(long long wt_already=W-w;wt_already>=0;wt_already--)// this loop is used to see if better ans is possible using current item
    	{
           max_self(dp[w+wt_already],dp[wt_already]+v);

    	}

 }

long long ans=-1;

    for(long long i=0;i<=W;i++)
    {
       max_self(ans, dp[i]);

    }



   cout<<ans;





}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    int i,j;
    int a[101][101];
    int r,c;
    
    scanf("%d %d",&r,&c);
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&a[i][j]);   // a[i][j] = 100;
        }
    }
    for (i=0; i<=r; i++)a[i][c]= 0; //横一列の合計を入れるところ[1][c],[2][c]・・・・[r][c]        
    for (j=0; j<=c; j++)a[r][j]= 0; //縦一列の合計を入れるところ[r][1],[r][2]・・・・[r][c]
    
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            a[i][c] +=a[i][j];
            a[r][j] +=a[i][j];
            a[r][c] +=a[i][j];
        }
    }
     for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
           if (j<c)printf("%d ",a[i][j]);
           else printf("%d\n",a[i][j]);
        } 
     }
    return 0;
}



Measured memory_bytes: 2072
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;

/* debug macros */
#ifdef WAFDAYO
#define DBG_PRINT(s, t, u) { std::cerr << s << " \e[2m=\e[m \e[1m" << t << "\e[m" << u; }
#else
#define DBG_PRINT(s, t, u) {}
#endif
#define dbg(x) DBG_PRINT(#x, x, std::endl)
#define dbgc(x) DBG_PRINT(#x, x, ", ")
#define idbg(x, i) DBG_PRINT(#x "[" << i << "]", x[i], std::endl)
#define idbgc(x, i) DBG_PRINT(#x "[" << i << "]", x[i], ", ")

/* IO utilities */
struct read_item { read_item() {}; template<class T> operator T() { T t; std::cin >> t; return t; } };

/* types and constants */
typedef long long i64;
//const i64 inf = (i64)1.05e18;
const int inf = (int)1.05e9;

int get_steps(vector<int>& from, vector<int>& odd) {

	static vector<int> sorted;
	static vector<bool> used;

	sorted.clear();
	for(auto& a : from) {
		sorted.push_back(a);
	}
	sort(sorted.begin(), sorted.end());
	used.resize(sorted.size());
	fill(used.begin(), used.end(), false);

	const int n = from.size();
	int steps = 0;

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

		bool ok = false;

		for(int j = 0; j < n; j++) {
			if(used[j]) {
				continue;
			}
			if(sorted[i] == from[j] && (i & 1) == odd[j]) {
				used[j] = true;
				ok = true;
				break;
			}
			steps += 1;
		}

		if(!ok) {
			return -1;
		}
	}

	return steps;
}

int main() {

	const int n = read_item();
	vector<int> xs(n), ys(n);
	for(int i = 0; i < n; i++) {
		const int x = read_item();
		xs[i] = x;
	}
	for(int i = 0; i < n; i++) {
		const int y = read_item();
		ys[i] = y;
	}

	vector<int> odd(n);
	for(int i = 0; i < n; i++) {
		odd[i] = (i % 2 == 0) ? 0 : 1;
	}

	sort(odd.begin(), odd.end());
	int ans = inf;

	while(true) {

		static vector<int> from;

		from.clear();
		for(int i = 0; i < n; i++) {
			bool same = (odd[i] == (i & 1));
			from.push_back(same ? xs[i] : ys[i]);
		}

		int s = get_steps(from, odd);
		if(s >= 0) {
			ans = min(ans, s);
		}

		if(!next_permutation(odd.begin(), odd.end())) {
			break;
		}
	}

	if(ans == inf) {
		ans = -1;
	}
	printf("%d\n", ans);

	return 0;
}

/* wafdayo~~~ */


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

static const int MAX = 1000001;

int  price[30];
bool dp[MAX];

bool prime( int n );

int main()
{

	int n, x;
	bool flg;

	while( 1 ) {

		flg = false;

		if( cin >> n >> x, n == 0 && x == 0 ) break;

		for( int i = 0; i < MAX; i++ ) dp[i] = false;

		for( int i = 0; i < n; i++ ) cin >> price[i];

		dp[0] = true;

		/*
		for( int i = 0; i < n; i++ ) {
			for( int j = 0; j < x - price[i]; j++ ) {
			
				if( dp[j] ) dp[j + price[i]] = true;

			}
		}
		*/

		for( int i = 0; i < x; i++ ) {
			if( dp[i] ) {
				for( int j = 0; j < n; j++ ) {
					
					if( i + price[j] <= x ) {
						dp[i + price[j]] = true;
					}
					else continue;

				}
			}
		}

		for( int i = x; i > 0; i-- ) {

			if( dp[i] && prime( i ) ) {
				cout << i << endl;
				flg = true;
				break;
			}

		}

		if( !flg ) cout << "NA" << endl;

	}

	return 0;

}

bool prime( int x )
{

	for( int i = 2; i * i <= x; i++ ) {
		if( x % i == 0 ) return false;
	}

	return true;

}

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

#define lli long long int
#define LLI(n) \
  lli n;       \
  cin >> n;
#define LLIV(a, n)            \
  vector<lli> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define STR(n) \
  string n;    \
  cin >> n;
#define Sort(n) sort(n.begin(), n.end());
#define Reve(n) reverse(n.begin(), n.end());
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define C45(n) (n + 1) / 2
#define OUT(n) cout << n << endl;
#define SRC(n, c)                    \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    if (s.at(i) == c)                \
    {                                \
      n++;                           \
    }                                \
  };
//こぴー
/*#define ZISYO(s, S)                  \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    S.at(i) = s.at(i);               \
  }                                  \
  Sort(S) Reve(S) for (lli i = 0; i < s.size(); i++) { s.at(i) = S.at(i); };
*/

//素数
bool IsPrime(lli num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
      return false;
  }
  return true;
}
//各桁の和
lli Sum(lli n)
{
  lli sum = 0;
  if (n < 0)
    return 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(void)
{
  ios::sync_with_stdio(false);
  LLI(n)
  
  if(n >= 64) {
    OUT(64)
  }
  else if(n >= 32) {
    OUT(32)
  }
  else if(n >= 16) {
    OUT(16)
  }
  else if(n >= 8) {
    OUT(8)
  }
  else if(n >= 4) {
    OUT(4)
  }
  else if(n >= 2) {
    OUT(2)
  }
  else {
    OUT(1)
  }
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long[] a = new long[N];
        a[0] = Long.parseLong(sc.next());
        long max = a[0];
        long min = a[0];
        for(int i=1; i<N; i++) {
            a[i] = Long.parseLong(sc.next());
            if(max < a[i]) max = a[i];
            if(min > a[i]) min = a[i];
        }
        System.out.println(max-min);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
    int n, m;
    string u, t;
    bool is_opened = false;
    set<string> ids;

    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> u;
        ids.insert(u);
    }
    cin >> m;
    for (int i=0; i<m; i++) {
        cin >> t;
        if (ids.find(t) == ids.end()) {
            cout << "Unknown " << t << endl;
        }
        else {
            is_opened = !is_opened;
            if (is_opened) {
                cout << "Opened by " << t << endl;
            }
            else {
            cout << "Closed by " << t << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;

const ll N = 3e6+7;
const ll mod = 998244353;
ll n, m, ans = 0, f[N], rev[N];

ll binpow(ll a, ll b){
	if(!b) return 1;
	if(b == 1) return a%mod;
	ll temp = binpow(a, b/2);
	if(b%2 == 0) return (temp*temp)%mod;
	else return (temp*((temp*a)%mod))%mod;
}

void init(ll n){
	f[0] = 1;
	f(i,0,n){
		if(i) f[i] = (f[i-1]*i)%mod;
		rev[i] = binpow(f[i], mod-2);
	}
}

ll Ckn(ll k, ll n){
	return (f[n]*((rev[n-k] * rev[k])%mod))%mod;
}

ll calc(ll a, ll b, ll c){
	ll result = 0, now = min(a, min(b, c));
	f(i,0,now){
		if((b-i)%2 != 0) continue;
		result += (Ckn(i, a)*Ckn(a-1, (b-i)/2 + a-1))%mod;
		result %= mod;
	}
	return result;
}

signed main(){
//	freopen("PERFECT1.inp","r",stdin);
//	freopen("PERFECT1.out","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	init(3*max(n, m)*1LL);
	ans = (calc(n, 3*m, m) - n*((calc(n, m, m) - calc(n-1, m, m) + mod)%mod) + mod)%mod;
	ans = (ans+mod)%mod;
	cout << ans;
}



Measured memory_bytes: 47104
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,M;
vector<pair<int,int> >A;
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)
	{
		int x,y;cin>>x>>y;
		A.push_back(make_pair(x,-1));
		A.push_back(make_pair(y,1));
	}
	sort(A.begin(),A.end());
	long now=0;
	long ans=0;
	for(pair<int,int>p:A)
	{
		long t=p.first;
		ans=max(ans,now%2?M*(now-1)+t:M*now-t);
		now-=p.second;
		ans=max(ans,now%2?M*(now-1)+t:M*now-t);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 7016
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}



int main() {
  ll N,ans=0;
  cin >> N;
  rep2(i,1,N+1) {
    ll t = N/i;
    ans += i*(t*(t+1)/2);
  }
  cout << ans << endl;
}

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

typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for (int j = 0; j < n; ++j) {
        cin >> p[j];
    }
    sort(p.begin(),p.end());
    int ans=0;
    for (int i = 0; i < k; ++i) {
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  vector<double> g(a);
  double ans;
  for(int i = 0;i < a;i++){
    cin >> g.at(i);
    ans += 1/g.at(i);}
  ans = 1/ans;
  cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int main(void) {

    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if ( ((x - r) >= 0 && (x + r) <= W)
            && ((y - r) >= 0) && ((y + r) <= H)) {
        puts("Yes");
    }
    else {
        puts("No");
    }

    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;

const int dy[] = {0,0,1,-1};
const int dx[] = {1,-1,0,0};
int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n,0), b(n,0);
	rep(i,m){
		int x, y;
		cin >> x >> y;
		x--; y--;
		if(x == 0){
			a[y] = 1;
		}
		if(y == n - 1){
			b[x] = 1;
		}
	}
	rep(i,n){
		if(a[i] && b[i]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
char s[1000009],lens;
//aihfiuoawfiuhihfGUIwiufhiofiojfiofiowdjfiojwhwgiugwuiehiofhdifh
///adfhjdhfjadhfhifhef
//adfjhdfhadh
void fuck()
{
	fuck();	
}
int main()
{
    scanf("%s",s+1);
    lens=strlen(s+1)-8;
    for(int i=1;i<=lens;i++)
    {
    	putchar(s[i]);
    }
    return 0;
}
/*
2
4 2
2 4
*/

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

queue<char> que[3];

int rec(int i){
    if(que[i].empty()) return i;
    char q = que[i].front();
    que[i].pop();
    return rec(q - 'a');
}

int main(){
    for(int i = 0; i < 3; i++){
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            que[i].push(s[j]);
        }
    }
    cout << (char)(rec(0) + 'A') << endl;
    return 0;
}

Measured memory_bytes: 3652
from collections import deque
from collections import defaultdict

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

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

G = Graph()

N, Q = getlist()
for i in range(N - 1):
	a, b = getlist()
	G.add_edge(a, b)
	G.add_edge(b, a)

plus = [0] * (N + 1)
for i in range(Q):
	p, x = getlist()
	plus[p] += x

q = deque([]) 
ans = [0] * N
visit = [-1] * (N + 1)
visit[1] = 1
q.append(1)
while q:
	m = q.pop()
	visit[m] = 1
	ans[m - 1] += plus[m]
	x = ans[m - 1]
	for i in G.graph[m]:
		if visit[i] == -1:
			q.append(i)
			ans[i - 1] += x

print(" ".join(list(map(str, ans))))

Measured memory_bytes: 125996
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    if(A!=1&&B!=1)
    {
        printf("1\n");
    }
    else if(A!=2&&B!=2)
    {
        printf("2\n");
    }
  else
  {
      printf("3\n");
    }
  return 0;

}


Measured memory_bytes: 1596
N, M = [int(x) for x in input().split()]
Like = [0 for _ in range(M+1)]
for i in range(N):
  KA = [int(x) for x in input().split()]
  for j in range(1, KA[0]+1):
    Like[KA[j]] += 1
ans = 0
for i in range(M+1):
  if(Like[i]==N):
    ans += 1
print(ans)

Measured memory_bytes: 9136