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

int main(){
    int n;  cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    vector<int> lm(n+1, 0), rm(n+1, 0);
    for(int i=0; i<n; i++) lm.at(i+1) = max(a.at(i), lm.at(i));
    for(int i=n-1; 0<=i; i--) rm.at(i) = max(rm.at(i+1), a.at(i));

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

        int ans = max(lm.at(i), rm.at(i+1));
        cout << ans << endl;
    }
        
}

Measured memory_bytes: 3968
#include<stdio.h>
int main(void)
{
  int i=0,j;
  char str,ch[21];

  while(scanf("%c",&str)!=EOF)
    {
      ch[i]=str;
      //printf("%c",ch[i]);
      i++;
    }

  for(j=i-2;j>=0;j--)
    {
      printf("%c",ch[j]);
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9+7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void y(bool cond){
	if (cond)print("Yes");
	else print("No");
}

int dp[100010][3];
int v[100010][3];
void solve() {
	int N; cin >> N;
	REP(i, N) {
		REP(j, 3) {
			cin >> v[i][j];
		}
	}
	REP(i, N) {
		REP(j, 3) {
			chmax(dp[i + 1][(j + 1) % 3], dp[i][j] + v[i][(j + 1) % 3]);
			chmax(dp[i + 1][(j + 2) % 3], dp[i][j] + v[i][(j + 2) % 3]);
		}
	}
	int ans = 0;
	REP(j, 3)chmax(ans, dp[N][j]);
	print(ans);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, h, w;

int main() {
  cin >> h >> w >> n;
  set<pair<int, int>> obs;
  vector<vector<int>> to(w);
  range(i, 0, n) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    if(x < y) continue;
    to[y].push_back(x);
    obs.insert(make_pair(x, y));
  }
  range(i, 0, w) {
    to[i].push_back(h);
    sort(to[i].begin(), to[i].end());
  }
  range(x, 0, h) obs.insert(make_pair(x, w));
  range(y, 0, w) obs.insert(make_pair(h, y));
  int x = 0;
  int y = 0;
  vector<pair<int, int>> cur;
  auto ted = [&]() {
    if(cur.size() < 3) {
      if(cur.size() == 2) {
        return (cur[0] == cur[1] && cur[0] == make_pair(0, 0));
      }
      return false;
    }
    int sz = cur.size();
    return (cur[sz - 1] == cur[sz - 2] && cur[sz - 2] == cur[sz - 3]);
  };
  while(true) {
    if(obs.find(make_pair(x + 1, y)) != obs.end()) {
      cur.emplace_back(x, y);
      if(ted()) break;
      cur.emplace_back(x, y);
      break;
    }
    x++;
    cur.emplace_back(x, y);
    int c = obs.find(make_pair(x, y + 1)) == obs.end();
    y += c;
    cur.emplace_back(x, y);
  }
  int res = cur.size();
  for(int i = 0; i < (int) cur.size(); i += 2) {
    int u = cur[i].first, v = cur[i].second;
    int su = *lower_bound(to[v].begin(), to[v].end(), u);
    res = min(res, i + 1 + (su - u) * 2);
  }
  cout << (res + 1) / 2;
  return 0;
}


Measured memory_bytes: 42352
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b,c,d;

int main(){
  cin >> a >> b >> c >> d;
  if(a<=b) cout << a*c <<endl;
  else cout << b*c+(a-b)*d <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

int main() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &v[i].first, &v[i].second);
    }
    sort(v.begin(),v.end());
    GPQ<tuple<ll, ll, ll>> Q;
    for (int i = 0; i < n; ++i) {
        Q.emplace(v[i].first, 0, i);
    }
    ll val = 0, ans = 0;
    while(!Q.empty()){
        int x, y, z;
        tie(x, y, z) = Q.top(); Q.pop();
        if(y){
            val -= z;
        }else {
            if(v[z].second > val){
                ll w = (v[z].second-val+a-1)/a;
                ans += w;
                Q.emplace(v[z].first+2*d, 1, w*a);
                val += w*a;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9712
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	a,b = map(int,input().split())
	if(a%b==0):
		print(0)
	else:
		print(1)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 63468
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String c = sc.next();
        String[] target = {"a","e","i","o","u"};
        
        for (String s : target) {
        	if (s.equals(c)) {
        		System.out.println("vowel");
        		return;
        	}
        }
        
        System.out.println("consonant");
    }
}

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

int a[25];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	set<int> s;
	for(int i = 0; i < (1 << n); i++) {
		int sum = 0;
		for(int j = 0; j < n; j++) {
			if(i & (1 << j)) {
				sum += a[j];
			}
		}
		s.insert(sum);
	}
	int q, x;
	scanf("%d", &q);
	for(int i = 0; i < q; i++) {
		scanf("%d", &x);
		if(s.find(x) != s.end()) printf("yes\n");
		else printf("no\n");
	}
}



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

const int MAX_N=2e5+10;

int N,a,b,now=3;
vector<vector<int>> G(MAX_N);
vector<queue<int>> qs(2);
vector<int> dep(MAX_N,0),ans(MAX_N,0);

void dfs(int v,int p){
    qs[dep[v]&1].push(v);
    for (int u:G[v]){
        if (u==p) continue;
        dep[u]=dep[v]+1;
        dfs(u,v);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for (int i=0;i<N-1;++i){
        cin >> a >> b; --a,--b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    dfs(0,-1);
    if (qs[0].size()<qs[1].size()) swap(qs[0],qs[1]);
    for (int i=1;i<=N;i+=3){
        ans[qs[0].front()]=i; qs[0].pop();
    }
    if (qs[0].size()<qs[1].size()) swap(qs[0],qs[1]);
    for (int i=2;i<=N;i+=3){
        ans[qs[0].front()]=i; qs[0].pop();
    }
    for (int i=0;i<N;++i) if (!ans[i]){
        ans[i]=now; now+=3;
    }
    for (int i=0;i<N;++i) cout << ans[i] << (i!=N-1?' ':'\n');
}

Measured memory_bytes: 20096
import math 
A, B, H, M = [int(x) for x in input().split(' ')]
theta_h = math.pi * (H / 6 + M / 360)
theta_m = math.pi * (M / 30)
theta = theta_h - theta_m
x = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))
print(x)

Measured memory_bytes: 9436
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007


lli a[510][510]={0};

signed main(){

	lli h,w;
	cin>>h>>w;

	for(lli i=1;i<=h;i++){
		for(lli j=1;j<=w;j++){
			cin>>a[i][j];
		}
	}
	lli dx[4]={-1,0,1,0};
	lli dy[4]={0,-1,0,1};
	vector<tuple<lli,lli,lli,lli>> v;

	/*一筆書きして自分が奇数なら隣に引き渡す*/

	for(lli y=1;y<=h;y++){
		lli x,dx;
		if(y%2==1)x=1,dx=1;
		else x=w,dx=-1;
		
		while(1<=x && x<=w){
			if(a[y][x]%2==1){
				lli nextX = x+dx;
				lli nextY = y;
				if(nextX < 1 || w < nextX){
					nextY++;
					nextX = x;
				}
				if(nextY>h)break;
				a[nextY][nextX]++;
				a[y][x]--;
				v.push_back(make_tuple(y,x,nextY,nextX));
			}
			x+=dx;
		}
	}
	lli size = v.size();
	cout<<size<<endl;
	REP(i,0,size){
		cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<" "<<get<3>(v[i])<<endl;
	}

	if(DEBUG){
		REP(i,1,h+1){
			REP(j,1,w+1){
				cout<<a[i][j]<<" ";
			}
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 8432
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int c = abs(a - b);
    if(c % 2 == 0) cout << min(a+c/2, b+c/2) << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = gets.split.map{|i|i.to_i}
d = "n" * N
M.times{
    s, c = gets.split
    s = s.to_i - 1
    if d[s] == "n"
        d[s] = c
        next
    end
    if d[s] == c
        next
    end
    d = nil
    break
}
if d
    if d[0] == "n"
        if N == 1
            d[0] = "0"
        else
            d[0] = "1"
        end
    end
    d.gsub!(/n/, "0")
    if N > 1 && d[0] == "0"
        puts(-1)
    else
        puts d
    end
else
    puts(-1)
end


Measured memory_bytes: 1788
/*
     予選落ち不可避
 */
#include <stdio.h>

int n;
int player[3][101];
int points[201];

int main() {
    scanf("%d", &n);

    for (int i=0; i<n; i++) {
        int a, b, c;

        scanf("%d %d %d", &a, &b, &c);
        if (player[0][a]) player[0][a] = -1;
        else player[0][a] = i+1;

        if (player[1][b]) player[1][b] = -1;
        else player[1][b] = i+1;

        if (player[2][c]) player[2][c] = -1;
        else player[2][c] = i+1;
    }

    for (int i=0; i<3; i++) {
        for (int j=1; j<=100; j++) {
            if (player[i][j] != 0 && player[i][j] != -1) {
                points[player[i][j]] += j;
            }
        }
    }

    for (int i=1; i<=n; i++) {
        printf("%d\n", points[i]);
    }
}

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

using namespace std;

const int N = 2e5 + 10;
int m, n;

int dist[N], vis[N];
int h[N], e[N], ne[N], idx, id[N];
int deg[N];
int ans[N];
int res;

void add(int a, int b, int c)
{
    e[idx] = b;
    ne[idx] = h[a];
    id[idx] = c;
    h[a] = idx ++;
}


void dfs(int u, int fa, int in)
{
	int t = 0;
	for (int i = h[u]; ~i; i = ne[i])
	{
		int j = e[i];
			if(j == fa) continue;
		++ t;
		if(t == in) t++;
		res = max(t, res);
		ans[id[i]] = t;
		dfs(j, u, t);
	}
}

int main()
{
	res = 0;
    memset(h, -1, sizeof(h));
    scanf("%d", &n);
  	for (int i = 1; i <= n - 1; i ++)
  	{
  		int a, b;
  		scanf("%d%d", &a, &b);
  		add(a, b, i), add(b, a, i);
  		deg[a] ++, deg[b] ++;
	  }
	
	  dfs(1, -1, -1);
	  	  cout << res << endl;
	  for (int i = 1; i <= n - 1; i ++)
	  {
	  	printf("%d\n", ans[i]);
	  }
}


Measured memory_bytes: 8064
/***
        ***Fresher***
    Md Mahfujur Rahman Khan
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

***/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque
/***PAIR***/
#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>
/***MAP***/
#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>
#define mci map<char, ll>
/***VECTOR***/
#define vi vector<ll>
#define vs vector<string>
/***ITERASTORS***/
#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator
#define imci map<char, ll> :: iterator
/*** FAST ***/
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/***FUNCTIONS AND MACROS***/
#define F first
#define S second
#define M_P(x, y) make_pair(x, y)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT(x) count(x)
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT(x) getline(cin , x)
#define NL_   "\n"
#define SP_ " "
#define R_0 return 0
#define R_ return

#define ul unsigned long long int
#define ll long long int
/***
//prime fact
#define most_prime_loop 1001
#define most_prime_number 2000010
#define prime_MAX_arr 2000010/2
ll PRIME[2000010];
void seive()
{
    PRIME[0] = 0;
    for(auto &x: PRIME )
        x = 1;
    for(ll i= 3; i <= most_prime_loop; i+=2)
    {
        for(ll j = i*i; j <= most_prime_number; j+=2*i)
            PRIME[j/2] = 0;
    }
}
***/

#define fr(i, n) for( ll i = 0; i < n; i++)
#define fe(x, n) for( ll i = x; i <= n; i++)
#define fa(x,a)    for(auto &x : a)

#define pi acos(-1)

#define SR(x) sqrt(x)
#define IC   (ll)

const ll  inf = 2000000;
ll i=0, T=0, N=0, tc =0, t= 0;
ll n=0, k=0;
string s;
bool palin(ll a, ll b)
{
    a--;
    b--;
    while(a<=b)
    {
        if(s[a++]!=s[b--]) return 0;
    }
    return 1;
}
int main()
{
       ll a, b, n;
      cin >> a >> b;
      double res =  ceil( max((double)a/0.08, (double)b/0.1));
//      cout << floor(res*0.1);
      if(floor(res*0.08)==(double)a && floor((res*0.1))==(double)b) cout << (ll) res;
      else cout <<-1;

      R_0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  cout << S[0] - '1' + (S.size() - 1) * 9 +
              all_of(begin(S) + 1, end(S), [](int x) { return x == '9'; })
       << endl;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
  ll n = 0, k = 0;
  ll ans = 0;
  bool ok = false;
  cin >> n >> k;
  cout << n - k + 1 << endl;
  return 0;
}

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

int main(){
	LL n;
	cin >> n;
	LL dp[n+1];
	for(int i=0;i<=n;i++){
		dp[i] = 1;
	}
	for(int i=0;i<=2;i++){
		dp[i] = 0;
	}
	for(int i=3;i<=n;i++){
		LL sum = dp[i];
		for(int j=3;j<i;j++){
			sum  = (sum+dp[i-j])%mod;
		}
	   dp[i] = sum;
	}
	cout << dp[n]%mod << endl;
	return 0;
	
}


Measured memory_bytes: 3592
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        ll x;
        cin >> x;
        ll g = __gcd(x , 360LL);
        cout << 360 / g;
    }

    return 0;
}


Measured memory_bytes: 3640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

long long modPow(long long a, long long x, long long p) {
    long long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

long long modInverse(long long a, long long p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}

class FManyManyPaths {
public:
    void solve(std::istream& in, std::ostream& out) {
        // f(r, c) = f(r-1, c) + f(r, c-1)
        //         = f(r-1, c) + f(r-1, c-1) + f(r, c-2)
        //         = f(r-1, c) + ... + f(r-1, 1) + f(r, 0)
        //         = f(r-1, c) + ... + f(r-1, 1) + f(r-1, 0)
        // answer = {f(r2+1, c2) + f(r2, c2) + ... + f(r1+1, c2)} - {f(r2+1, c1-1) + f(r2, c1-1) + ... + f(r1+1, c1-1)}
        // f(r, c) = Combination(r+c, c) = (r+c)!/(r!c!)
        int r1, r2, c1, c2;
        in >> r1 >> c1 >> r2 >> c2;
        ll answer = 0;
        vector<ll> factorials(((r2+1)+c2)+1), inverseFactorials(max(r2+1, c2)+1);
        factorials[0] = 1;
        inverseFactorials[0] = 1;
        REP(i,1,factorials.size()+1) {
            factorials[i] = factorials[i-1] * i;
            factorials[i] %= MOD;
        }
        inverseFactorials[inverseFactorials.size()-1] = modPow(factorials[inverseFactorials.size()-1], MOD-2, MOD);
        RREP(i,1,inverseFactorials.size()-1) {
            inverseFactorials[i] = inverseFactorials[i+1] * (i+1);
            inverseFactorials[i] %= MOD;
        }
        REP(r,r1+1, r2+2) {
            ll add = factorials[r+c2];
            add *= inverseFactorials[r];
            add %= MOD;
            add *= inverseFactorials[c2];
            add %= MOD;
            answer += add;
            answer %= MOD;
        }
        REP(r,r1+1, r2+2) {
            ll sub = factorials[r+c1-1];
            sub *= inverseFactorials[r];
            sub %= MOD;
            sub *= inverseFactorials[c1-1];
            sub %= MOD;
            answer = answer + MOD - sub;
            answer %= MOD;
        }
        out << answer << "\n";
    }
};


signed main() {
    FManyManyPaths solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; 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; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;

vector<ll> a;
vector<ll> p;

ll rec(ll n, ll x) {
    if (n==0) {
        return 1;
    } else if (x == 1) {
        return 0;
    } else if (x <= a[n-1] + 1) {
        return rec(n-1, x-1);
    } else if (x == 2 + a[n-1]) {
        return p[n-1] + 1;
    } else if (x < 2 + 2*a[n-1]) {
        return p[n-1] + 1 + rec(n-1, x - 2 - a[n-1]);
    } else {
        return p[n];
    }
}

int main() { 
    ll N; cin >> N;
    ll X; cin >> X;

    a.push_back(1);
    p.push_back(1);
    REP(i, N) {
        a.push_back(2*a[i]+3);
        p.push_back(2*p[i]+1);
    }

    cout << rec(N, X) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a,int b) {
  a+=b;
  return a>=mod?a-mod:a;
}
int sub(int a,int b) {
  a-=b;
  return a<0?a+mod:a;
}
int mul(int a,int b) {
  return (int)((long long)a*b%mod);
}
int power(int a,int b) {
  int res=1;
  while (b>0) {
    if (b&1) {
      res=mul(res,a);
    }
    a=mul(a,a);
    b>>=1;
  }
  return res;
}
const int M=2e6+10;

int fac[M],invf[M];
void init(){
    fac[0]=1;
    for(int i=1;i<M;i++)
        fac[i]=mul(fac[i-1],i);
    invf[M-1]=power(fac[M-1],mod-2);
    for(int i=M-2;i>=0;i--){
        invf[i]=mul(invf[i+1],i+1);
    }
    return;
}
int ncr(int N,int R){
    if(R>N)return 0;
    if(R==0||N==R)return 1;
    return mul(fac[N],mul(invf[N-R],invf[R]));
}
int m;
int ss(int n,int a){
    /**
    The number of ways to distribute
    sum total A to n target each have even value
    */
    int ans=0;
    /// 2 6 2
    for(int i=a%2;i<=min({n,a,m});i+=2){
        plusle(ans,mul(ncr(n,i),ncr((a-i)/2+n-1,n-1)));
    }
    return ans;
}
int n;
int ans;

int main(){
    scanf("%d%d",&n,&m);
    init();
    ans=ss(n,3*m);
   /// cerr<<ans<<endl;
    minun(ans,mul(n,sub(ss(n,m),ss(n-1,m))));
    printf("%d\n",ans);
    ///supposed that there is

}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define MX 3003

int dp[MX][MX];
string s, t;
int N, M, res;

int go(int i, int j){
    if (i >= N || j >= M) return 0;
    if (dp[i][j] != -1) return dp[i][j];
    int ans = 0;
    if (s[i] == t[j]) ans = 1 + go(i+1, j+1);
    ans = max({ans, go(i+1, j), go(i, j+1)});
    return dp[i][j] = ans;
}

void path(int i, int j, int len){
    if (i >= N || j >= M || len == 0) return;
    if (s[i] == t[j]){
        cout << s[i];
        path(i+1, j+1, len-1);
        return;
    }
   if (go(i+1, j) == len){
        path(i+1, j, len);
        return;
   }
   if (go(i, j+1) == len){
        path(i, j+1, len);
        return;
   }
}
int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> s >> t;
    N = s.size(), M = t.size();
    res = go(0, 0);

//    for (int i = 0; i < N; i++){
//        for (int j = 0; j < M; j++){
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }
    path(0, 0, res);
    cout << endl;
    return 0;
}


Measured memory_bytes: 35968
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b = na()
if (a + b) % 2 == 0:
    print((a + b) // 2)
else:
    print("IMPOSSIBLE")


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

using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;

int main() {
	int n;
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	ll gcd=__gcd(a[0],a[1]);
	for(int i=2;i<n;i++){
	    gcd=__gcd(gcd,a[i]);
	}
	cout<<gcd;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
//大きい順にソート
int c[200002];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]>s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int n,i;
  scanf("%d",&n);
  int a[n+1];
  long long sum=0;
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  merge(0,n-1,a);
  sum=a[0];
  for(i=2;i<n;i++)
    sum+=(long long)a[i/2];
  printf("%lld\n",sum);
  return 0;
}

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

using ll=long long; 

void solve(){
	ll n;
	cin>>n;
	ll ans=1;
	for(ll i=1; i*i<=n; i++){
		ans=i*i;
	}	
	cout<<ans<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int n,m;
	std::cin >> m >> n;
	int** a = new int*[m];
	for (int i=0; i<m; i++) {
		a[i] = new int[n];
	}
	int* b = new int[n];
	
	for (int i=0; i<m; i++) {
		for (int j=0; j<n; j++) {
			std::cin >> a[i][j];
		}
	}
	for (int j=0; j<n; j++) {
		std::cin >> b[j];
	}
	
	for (int i=0; i<m; i++) {
		int val = 0;
		for (int j=0; j<n; j++) {
			val += a[i][j] * b[j];
		}
		std::cout << val << std::endl;
	}
	
	return 0;
}




Measured memory_bytes: 3128
N = int(input())
inputs = sorted([int(i) for i in input().split()])

min_value = inputs[0]
max_value = inputs[-1]
process = []
for i in range(1, N-1):
    value = inputs[i]
    if value >= 0:
        process.append([min_value, value])
        min_value -= value
    elif value < 0:
        process.append([max_value, value])
        max_value -= value
process.append([max_value, min_value])

print(max_value - min_value)
for item in process:
    print(item[0], item[1])


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

bool check(string& t, string& s)
{
  int n = s.size();
  for (int i = 2; i < n; ++i) {
    if (t[i - 1] == 'W') {
      if (s[i - 1] == 'o') {
        t[i] = (t[i - 2] == 'W') ? 'S' : 'W';
      }
      else if (s[i - 1] == 'x') {
        t[i] = (t[i - 2] == 'W') ? 'W' : 'S';
      }
    }
    else if (t[i - 1] == 'S') {
      if (s[i - 1] == 'o') {
        t[i] = (t[i - 2] == 'W') ? 'W' : 'S';
      }
      else if (s[i - 1] == 'x') {
        t[i] = (t[i - 2] == 'W') ? 'S' : 'W';
      }
    }
  }

  bool ok = true;
  if (t[n - 1] == 'S') {
    if (s[n - 1] == 'o') {
      ok = ok and t[n - 2] == t[0];
    }
    else {
      ok = ok and t[n - 2] != t[0];
    }
  }
  else if (t[n - 1] == 'W') {
    if (s[n - 1] == 'o') {
      ok = ok and t[n - 2] != t[0];
    }
    else {
      ok = ok and t[n - 2] == t[0];
    }
  }

  if (t[0] == 'S') {
    if (s[0] == 'o') {
      return ok and t[n - 1] == t[1];
    }
    else {
      return ok and t[n - 1] != t[1];
    }
  }
  else if (t[0] == 'W') {
    if (s[0] == 'o') {
      return ok and t[n - 1] != t[1];
    }
    else {
      return ok and t[n - 1] == t[1];
    }
  }
  return false;
}

int main()
{
  int N; scanf("%d", &N);
  string s; cin >> s;

  vector<char> ws = { 'W', 'S' };
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      string t(N, 'Z');
      t[0] = ws[i];
      t[1] = ws[j];
      if (check(t, s)) {
        printf("%s\n", t.c_str());
        return 0;
      }
    }
  }
  printf("-1\n");
  return 0;
}


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

int main()
{
    long long int k,n;
    cin>>k>>n;
    long long int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    long long int ans=k-arr[n-1]+arr[0];
    for(int i=0;i<n-1;i++)
    {
        ans=max(ans,arr[i+1]-arr[i]);
    }
    cout<<k-ans<<endl;
}

Measured memory_bytes: 1792
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d %d %d\n" @@ fun n d a ->
  let xhs = Array.init (n + 1) @@ function
    | 0 -> (max_int, 0)
    | _ -> Scanf.scanf "%d %d\n" @@ fun x h -> x, h in
  Array.sort (fun (x, _) (x', _) -> compare x x') xhs;
  let cost = ref 0 in
  let acc = Array.make (n + 1) 0 in
  let bomb = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    let (x, h) = xhs.(i) in
    if acc.(i) + bomb.(i) * a < h then begin
      let j = upper_bound i (n + 1) @@ fun j -> fst xhs.(j) <= x + 2 * d in
      let x = (h - (acc.(i) + bomb.(i) * a) + a - 1) / a in
      cost := !cost + x;
      bomb.(i) <- bomb.(i) + x;
      bomb.(j + 1) <- bomb.(j + 1) - x;
    end;
    acc.(i + 1) <- acc.(i) + bomb.(i) * a;
  done;
  Printf.printf "%d\n" !cost


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

int n;
string s,t;

main()
{
    cin>>n>>s>>t;
    string ans={};
    rep(i,n)
    {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// yukicoder@csharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.CompilerServices;
//using System.Web.UI;
using Debug = System.Diagnostics.Debug;
// using System.Drawing.Primitives;
//using System.Drawing;
using System.Windows;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            new Solver().Solve();
        }
    }

    //class Cout {
    //    public static Cout operator >>(
    //        Cout a, int b)
    //    {
    //        Console.WriteLine(b);
    //        return a;
    //    }
    //    //public void Cout(long a) { Console.WriteLine(a); }
    //    //public void Cout(double a) { Console.WriteLine(a); }
    //}

    class GeneralPurposeClass
    {
        //public const double inf = double.PositiveInfinity;
        public const long inf = 1L << 50;
        public static readonly TextWriter error = Console.Error;

        public void Rep(long n_, Action<int> action)
        {
            for (int i = 0; i < n_; i++)
            {
                action(i);
            }
        }

        public void Rep2(int a, long n_, Action<int> action)
        {
            for (int i = a; i < n_; i++)
            {
                action(i);
            }
        }

        public string ReadLine()
        {
            return Console.ReadLine();
        }

        public string ReadNext()
        {
            var s = "";
            while (true)
            {
                var c = Console.Read();
                if (c != ' ' && c != '\n' && c != '\r')
                {
                    s += (char)c;
                    break;
                }
            }
            while (true)
            {
                var c = Console.Read();
                if (c == ' ' || c == '\n' || c == '\r') break;
                s += (char)c;
            }
            return s;
        }

        public long ReadLong()
        {
            return Stol(ReadNext());
        }

        public long Stol(string s)
        {
            return long.Parse(s);
        }

        public static void Write<T>(T a)
            where T : IComparable
        { Console.Write(a); }

        public static void WriteL<T>(T a)
            where T : IComparable
        { Console.WriteLine(a); }

        public static void Dump<T>(string s, T a)
            where T : IComparable
        {
#if DEBUG
            error.Write(s + ": " + a.ToString());
#endif
        }

        public static void Dumpl<T>(string s, T a)
            where T : IComparable
        {
#if DEBUG
            Dump(s, a); error.WriteLine();
#endif
        }
    }

    class Solver : GeneralPurposeClass
    {
        public void Solve()
        {
            var a = ReadLong();
            var b = ReadLong();

            var res = a * b;
            if (a > 9 || b > 9) res = -1;
            WriteL(res);
        }
    }
}


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

int main() {
    int n;
    cin >> n;
    int a, b, c, d;
    a = n/1000;
    b = (n%1000)/100;
    c = (n%100)/10;
    d = n%10;

    if(a+b+c+d == 7) {
        cout << a << "+" << b << "+" << c << "+" << d << "=7";
    }
    else if(a+b+c-d == 7) {
        cout << a << "+" << b << "+" << c << "-" << d << "=7";
    }
    else if(a+b-c+d == 7) {
        cout << a << "+" << b << "-" << c << "+" << d << "=7";
    }
    else if(a+b-c-d == 7) {
        cout << a << "+" << b << "-" << c << "-" << d << "=7";
    }
    else if(a-b+c+d == 7) {
        cout << a << "-" << b << "+" << c << "+" << d << "=7";
    }
    else if(a-b+c-d == 7) {
        cout << a << "-" << b << "+" << c << "-" << d << "=7";
    }
    else if(a-b-c+d == 7) {
        cout << a << "-" << b << "-" << c << "+" << d << "=7";
    }
    else if(a-b-c-d == 7) {
        cout << a << "-" << b << "-" << c << "-" << d << "=7";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

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

  vector<long> dp(W+1, 0);
  rep(i,n){
    vector<long> nxt(dp);

    rep(j,W){
      if(j + w[i] <= W) nxt[j+w[i]] = max(nxt[j+w[i]], dp[j] + v[i]);
    }

    swap(nxt, dp);
  }

  cout << *max_element(all(dp)) << endl;

  return 0;
}


Measured memory_bytes: 1816
t=int(input())

#mapH[j][i]=(i,j)

for repeet in range(t):
        actinidia_tate=[]
        actinidia_yoko=[]
        gx,gy=[int(i) for i in input().split(" ")]

        mapH=[[0 for i in range(gx+1)] for j in range(gy+1)]
        mapH[0][0]=1
        p=int(input())
        for i in range(p):
                x1,y1,x2,y2=[int(j) for j in input().split(" ")]
                if x1==x2:
                        actinidia_tate.append([x1,max(y1,y2)])
                else:
                        actinidia_yoko.append([max(x1,x2),y1])
	
        for i in range(1,gx+1):
                try:
                        actinidia_yoko.remove([i,0])
                except:
                        mapH[0][i]+=mapH[0][i-1]
        for j in range(1,gy+1):
                try:
                        actinidia_tate.remove([0,j])
                except:
                        mapH[j][0]+=mapH[j-1][0]
	
        for i in range(1,gx+1):
                for j in range(1,gy+1):
                        try:
                                actinidia_yoko.remove([i,j])
                        except:
                                mapH[j][i]+=mapH[j][i-1]
                        try:
                                actinidia_tate.remove([i,j])
                        except:
                                mapH[j][i]+=mapH[j-1][i]


        if mapH[-1][-1]==0:
                print("Miserable Hokusai!")

        else:
                print(mapH[-1][-1])

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

int p(int k) {
    int ret = 1;
    while(k--) ret *= 10;
    return ret;
}

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

    long long res = 0;
    for(int A=1; A<=N; ++A) {
        if(A % 10 == 0) continue;
        string tmp = to_string(A);
        int h = (int)(tmp[0] - '0');
        int t = (int)(tmp[tmp.size() - 1] - '0');

        if(t == h) ++res;
        if(t * 10 + h <= N) ++res;

        if(t * p(2) + h > N) continue;
        int l = 0, r = 10;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(t * p(2) + m * 10 + h <= N) l = m;
            else r = m;
        }
        res += r;

        if(t * p(3) + h > N) continue;
        l = 0, r = 100;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(t * p(3) + m * 10 + h <= N) l = m;
            else r = m;
        }
        res += r;

        if(t * p(4) + h > N) continue;
        l = 0, r = 1000;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(t * p(4) + m * 10 + h <= N) l = m;
            else r = m;
        }
        res += r;

        if(t * p(5) + h > N) continue;
        l = 0, r = 10000;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(t * p(5) + m * 10 + h <= N) l = m;
            else r = m;
        }
        res += r;
    }
    cout << res << '\n';
}

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

int main(){
    string s; cin >> s;
    int len = s.size();
    int l = 0; 
    int r = len - 1;
    int ans = 0;
    while(l < r){
        if(s[l] != s[r]) ans++;
        l++;
        r--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char s[101],p[101];
  int i,j,sn=0,pn=0,t;

  scanf("%s %s",s,p);

//文字数カウント
  while(s[sn] != '\0') sn++;
  while(p[pn] != '\0') pn++;

  for(i=0;i<sn;i++){
    t=1;
    for(j=0;j<pn;j++)
      if(s[(i+j)%sn] != p[j]) t=0;
    if(t) break;
  }

  if( t )
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}
  
      

Measured memory_bytes: 524
# -*- coding:utf-8 -*-
import sys
input = sys.stdin.readline
n = int(input())
c = str(input()).replace("\n","")
cl = list(c)
# print(cl)
rnum = cl.count("R")

if rnum == 0:
  print(0)
  sys.exit()

rnum_f = cl[:rnum].count("R")
print(min(rnum,rnum-rnum_f))

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

int A, B, C;
long long k;

int main(){

	scanf("%d%d%d%lld", &A, &B, &C, &k);
	if(k&1) printf("%d\n", B-A);
	else printf("%d\n", A-B);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  2017/07/09  Problem: AGC 017 B / Link: http://agc017.contest.atcoder.jp/tasks/agc017_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N,A,B,C,D;


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

  cin >> N>>A>>B>>C>>D;
  bool f = 0;

  FOR(i, 0, N - 1) {
	 ll u = A + (N - 1 - i)*D - C*i;
	  ll d = A + (N - 1 - i)*C - D*i;
	  if (u >= B&&d <= B)f = 1;
  }
  FOR(i, 0, N - 1) {
	  ll u = A  -(N - 1 - i)*C + D*i;
	  ll d = A  -(N - 1 - i)*D + C*i;
	  if (u >= B&&d <= B)f = 1;
  }
  

  if(f)
	  cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

constexpr int mod = 998244353;

int d[112345];
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> d[i], d[i]++;
  ll num[112345];
  num[0] = 0;
  ll ans = 1;
  if(d[0] != 1) ans = 0;
  sort(d, d + n);
  num[1]++;
  for(int i = 1; i < n; i++) {
    ans *= num[d[i]-1];
    ans %= mod;
    num[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

void half(long long h, long long w, long long *r1, long long *r2)
{
    if ((h*w)%2)
    {
        long long m = max(h,w);
        long long a = min(h,w);
        long long b = m/2 * a;
        *r1 = b;
        *r2 = h*w - b;
    }else
    {
        long long r = h*w/2;
        *r1 = r;
        *r2 = r;
    }
    
    
}

int main()
{
    long long H, W;
    cin >> H;
    cin >> W;
    long long ans = pow(10.0, 5.0);
    long long a,b,c;
    long long he, wi;
    for (int i = 1; i < H; i++)
    {
        he = H - i;
        a = he*W;
        half(H-he, W, &b, &c);
        ans = min(ans, max({a,b,c}) - min({a,b,c}));
    }
    for (int i = 1; i < W; i++)
    {
        wi = W - i;
        a = wi*H;
        half(H, W-wi, &b, &c);
        ans = min(ans, max({a,b,c}) - min({a,b,c}));
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define inf 1000000007;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int a, b, c, k;

signed main() {
	cin >> a >> b >> c >> k;
	if (k % 2 == 0)cout << a - b << endl;
	else cout << b - a << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
	if b==0:
		return a
	return gcd(b,a%b)
def lcm(a,b):
	return a*b//gcd(a,b)
a,b,c,d=map(int,input().split())
ans=b-a+1
ans1=b//c+b//d-b//lcm(c,d)
ans2=(a-1)//c+(a-1)//d-(a-1)//lcm(c,d)
print(ans-ans1+ans2)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main() {
	int x, a, b,bb1, bb2;

	scanf("%d %d %d", &x, &a, &b);

	if (a < b) {
		bb1 = x - a;
		bb2 = b - x;
		if (bb1 > bb2) {
			printf("B\n");
		}
		else {
			printf("A\n");
		}

	}
	else {
		bb1 = b - x;
		bb2 = x - a;
		if (bb1 > bb2) {
			printf("B\n");
		}
		else {
			printf("A\n");
		}

	}


	



	
	

	//getchar();
	//getchar();
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a>0){
        cout<<(b-a)*e<<endl;
    }
    else{
        cout<<b*e+d-a*c<<endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (unsigned long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (unsigned long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    int n;
    cin >> n;
    vector<int> b(n);
    REP(i, n) cin >> b[i];

    vector<bool> vanished(n, false);
    vector<int> ans;
    while(!b.empty()) {
        bool okay = false;
        for (int j = b.size(); j--;) {
            if (b[j] == j + 1) {
                b.erase(b.begin() + j);
                ans.emplace_back(j + 1);
                okay = true;
                break;
            }
        }
        if (!okay) break;
    }

    if (!b.empty()) {
        cout << -1 << endl;
    } else {
        for (int i = ans.size(); i--;) {
            cout << ans[i] << endl;
        }
    }
    
}

Measured memory_bytes: 256