akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }

  ll money = 1000;
  ll now = 0;
  rep(i,n-1) {
    if (a[i] > a[i+1]) { // should sell
      money += now * a[i];
      now = 0;
    }
    if (a[i] < a[i+1]) { // should buy
      ll diff = money / a[i]; // round down
      money -= diff * a[i];
      now += diff;
    }
  }
  // At last
  if (now > 0) {
    money += now * a[n-1];
    now = 0;
  }

  cout << money << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  string A;	
    if (S == "ABC"){
    	A = "ARC";
    }
    else if (S == "ARC"){
    	A = "ABC";
    }
   cout << A << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int a[1000000]={0};
int main(){
    int n;
    cin >>n;
    map<ll , ll,greater<ll> >mp;
    for(int i=0;i<n;i++){
        ll k=0;
        cin >>k;
        ll num = mp[k];
        mp[k]=num+1;
    }
    //cout<<mp.size()<<"jj"<<endl;
    ll sum=1;
    int flag=0,hhh=0;
    if(mp.begin()->second>=4){
        cout<<mp.begin()->first*mp.begin()->first<<endl;
        return 0;
    }
    else
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(flag==2)
            break;
        if(it->second>=2){
            sum*=it->first;
            hhh=1;
            flag++;
        }
    }
    if(hhh)cout<<sum<<endl;
    else cout<<0<<endl;
    return 0;
}


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

const int INF = 1e9;
using lint = long long;
const lint LINF = 1e18;
#define bit(n) ((lint)1 << n);

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

template <lint mod>
class mod_integer {
    lint val;

    public:
    mod_integer(): val(0) {}
    mod_integer(lint init_val):
        val(init_val >= 0? init_val % mod: (init_val % mod + mod) % mod) {}
    
    bool operator ! () {
        return val == 0;
    }
    mod_integer operator - () {
        return mod_integer(-val);
    }
    mod_integer operator ++ (int) {
        mod_integer that = *this;
        this -> val = (this -> val + 1) % mod;
        return that;
    }
    mod_integer operator -- (int) {
        mod_integer that = *this;
        this -> val = (this -> val - 1 + mod) % mod;
        return that;
    }
    
    bool operator == (mod_integer that) {
        return val == that.val;
    }
    bool operator != (mod_integer that) {
        return val != that.val;
    }

    mod_integer& operator += (const mod_integer& that) {
        val = (val + that.val) % mod;
        return *this;
    }
    mod_integer& operator -= (const mod_integer& that) {
        val = (val - that.val + mod) % mod;
        return *this;
    }
    mod_integer& operator *= (const mod_integer& that) {
        val = (val * that.val) % mod;
        return *this;
    }
    mod_integer& operator /= (const mod_integer& that) {
        lint res = 1, n = that.val, p = mod - 2;
        while (p > 0) {
            if (p % 2 == 1) res = res * n % mod;
            n = n * n % mod;
            p /= 2;
        }
        val = val * res % MOD;
        return *this;
    }

    mod_integer operator + (const mod_integer& that) {
        return mod_integer(*this) += that;
    }
    mod_integer operator - (const mod_integer& that) {
        return mod_integer(*this) -= that;
    }
    mod_integer operator * (const mod_integer& that) {
        return mod_integer(*this) *= that;
    }
    mod_integer operator / (const mod_integer& that) {
        return mod_integer(*this) /= that;
    }

    friend istream& operator >> (istream& is, mod_integer& n) {
        lint init_val;
        cin >> init_val;
        n = mod_integer(init_val);
        return is;
    }
    friend ostream& operator << (ostream& os, const mod_integer& n) {
        return os << n.val;
    }
}; using mint = mod_integer<MOD>;

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

    lint m, n, k;
    cin >> m >> n >> k;
    
    mint comb = 1;
    for (lint i = 0; i < k - 2; i++) {
        comb *= (m * n - 2 - i);
        comb /= i + 1;
    }

    mint num_m = 0;
    for (lint i = 1; i < m; i++) {
        num_m += i * (m - i);
    }
    mint num_n = 0;
    for (lint i = 1; i < n; i++) {
        num_n += i * (n - i);
    }

    cout << comb * (num_n * m * m + num_m * n * n) << endl;

    return 0;
}

Measured memory_bytes: 384
import sys
from functools import reduce 
n, m = map(int, sys.stdin.readline().split())
a  = list(map(int, sys.stdin.readline().split()))
b = [abs(i-m) for i in a]

def gcd(x,y):
    while y > 0:
        x, y = y ,x % y
    return x
  
print(reduce(gcd, b))

Measured memory_bytes: 14668
import std.algorithm;
import std.array;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool isGood (int cur)
{
	return cur % 2 == 0 || cur % 3 == 0 || cur % 5 == 0;
}

int [] solve (int n)
{
	int [] res;
	int cur = 1;
	while (res.length < n - 3)
	{
		if (isGood (cur))
		{
			res ~= cur;
		}
		cur += 1;
	}
	auto s = sum (res);
	foreach (u; cur + 1..cur + 100) if (isGood (u))
	{
		foreach (v; u + 1..u + 100) if (isGood (v))
                {
			foreach (w; v + 1..v + 100) if (isGood (w))
			{
				if ((u + v + w + s) % 30 == 0 &&
				    gcd (gcd (u, v), w) == 1)
				{
					res ~= u;
					res ~= v;
					res ~= w;
					return res;
				}
			}
		}
	}
	assert (false);
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		writefln ("%(%s %)", solve (n));
	}
}


Measured memory_bytes: 2556
#include<iostream>
#include <cstdio>

using namespace std;

int main() {

	int i, j;

	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= 9; j++) {
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}

	return 0;
}

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

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

  int a, b, c;
  cin >> a >> b >> c;
  cout << (a * b)/2 << endl;
  return 0;
}


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

int n,ans=0;
int a[5005],pre[5][5005];

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		
		if (ch=='R')  a[i]=0;
		else if (ch=='G')  a[i]=1;
		else a[i]=2;
	}
	for (int i=n;i>=1;i--)
	{
		pre[a[i]][i]=pre[a[i]][i+1]+1;
		pre[(a[i]+1)%3][i]=pre[(a[i]+1)%3][i+1];
		pre[(a[i]+2)%3][i]=pre[(a[i]+2)%3][i+1];
	}
	for (int i=1;i<=n-2;i++)
	{
		for (int j=i+1;j<=n-1;j++)
		{
			if (a[i]==a[j])  continue;
			
			int pos;
			for (int k=0;k<=2;k++)
			{
				if (k!=a[i]&&k!=a[j])
				{
					pos=k;
					break;
				}
			}
			ans+=pre[pos][j+1];
		}
	}
	for (int i=1;i<=n-2;i++)
	{
		for (int j=i+1;j<=n-1;j++)
		{
			int pos=2*j-i;
			if (pos>n||pos<=0)  break;
			
			if (a[i]!=a[j]&&a[i]!=a[pos]&&a[j]!=a[pos])  ans--;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,m,x,y,kk,white,black,head[N],col[N];
struct Edge{int nxt,to;}e[N];
inline void link(int x,int y){e[++kk].nxt=head[x];e[kk].to=y;head[x]=kk;}
void dfs(int u,int co){
	if (col[u]){
		if (col[u]!=co){
			printf("%lld\n",1ll*n*(n-1)/2-1ll*m);
			exit(0);
		}
		return;
	}
	col[u]=co;
	if (co==1) white++;else black++;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		dfs(v,3-col[u]);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		link(x,y);link(y,x);
	}
	dfs(1,1);
	printf("%lld\n",1ll*white*black-1ll*m);
	return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n;
  std::cin >> n;
  vector<pi> students;
  rep(i, n) {
    int a;
    std::cin >> a;
    students.eb(a, i);
  }
  sort(rng(students));
  rep(i, n) {
    if (i == 0)
			std::cout << students[i].se + 1;
		else
			std::cout << " " << students[i].se + 1;
  }
	std::cout << "\n";
}


Measured memory_bytes: 1780
#![allow(non_snake_case)]

use std::io;
use std::io::prelude::*;
use std::collections::VecDeque;

fn main() {
    let sin = io::stdin();
    let mut l_iter = sin.lock().lines();

    let line = l_iter.next().unwrap().unwrap();
    let mut ws = line.split_whitespace();
    let _n = ws.next().unwrap().parse::<usize>().unwrap();
    let q = ws.next().unwrap().parse::<u32>().unwrap();

    let mut queue = VecDeque::new();
    for line in l_iter {
        let l = line.unwrap();
        let mut ws = l.split_whitespace();
        let name: String = ws.next().unwrap().to_string();
        let time: u32 = ws.next().unwrap().parse::<u32>().unwrap();
        queue.push_back((name, time));
    }

    // println!("{:?}", queue);

    let mut t = 0;
    while queue.len() > 0 {
        if let Some((name, time)) = queue.pop_front() {
            if time <= q {
                println!("{} {}", name, t+time);
                t += time;
            } else {
                queue.push_back((name, time - q));
                t += q;
            }
        }
    }
}



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

int main() {
	string s;
	cin >> s;
	int sum = 700;
	for (auto itr = s.begin(); itr != s.end(); ++itr) {
		if (*itr == 'o') sum += 100;
	}
	cout << sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>

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

using namespace std;

int main() {

	string str;
	cin >> str;

	rep(i, 0, str.size()) {
		if (str[i] == ',')str[i] = ' ';
	}

	cout << str << endl;






	return 0;
}

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

typedef pair<int, int> pii;

int N, M;
vector<vector<int> > R;
vector<int> P;

int main() {
    scanf("%d %d", &N, &M);
    R.resize(M);
    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        R[t % M].push_back(t);
    }
    P = vector<int>(M, 0);
    for(int i = 0; i < M; i++) {
        sort(R[i].begin(), R[i].end());
        for(int j = 0; j < R[i].size(); j++) {
            if(j != R[i].size() - 1 && R[i][j] == R[i][j + 1]) {
                P[i]++;
                j++;
            }
        }
    }
    int ans = (int)R[0].size() / 2 + (M % 2 == 0? (int)R[M / 2].size() / 2 : 0);
    for(int i = 1; i < (M + 1) / 2; i++) {
        int cnt1 = R[i].size();
        int cnt2 = R[M - i].size();
        while(cnt1 != cnt2) {
            if(cnt1 < cnt2) {
                if(P[M - i] == 0) break;
                else cnt2 -= 2, P[M - i]--;
            }
            else {
                if(P[i] == 0) break;
                else cnt1 -= 2, P[i]--;
            }
        }
        ans += ((int)R[i].size() + (int)R[M - i].size() - (max(cnt1, cnt2) - min(cnt1, cnt2))) / 2;
    }

    cout << ans;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> as(n);
	vector<ll> asum(n + 1, 0);
	vector<ll> bs(m);
	vector<ll> bsum(m + 1, 0);
	rep(i, n) {
		cin >> as[i];
		asum[i + 1] = asum[i] + as[i];
	}
	rep(i, m) {
		cin >> bs[i];
		bsum[i + 1] = bsum[i] + bs[i];
	}
	ll upper = 0;
	for (int i = 0; i <= n; i++) {
		ll c = asum[i];
		ll rest = k - c;
		if (rest >= 0) {
			ll count = i;
			if (rest > 0) {
				auto u = std::upper_bound(bsum.begin(), bsum.end(), rest);
				std::advance(u, -1);
				ll add = u - bsum.begin();
				count += add;
			}
			upper = max(upper, count);
		}
	}
	cout << upper << endl;
	return 0;
}


Measured memory_bytes: 9584
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int cnt = Integer.parseInt(br.readLine());
		String str[] = br.readLine().split(" ");
		for(int i=0;i<cnt;i++){
			if(i==cnt-1){
				System.out.println(str[cnt-i-1]);
			}else{
				System.out.print(str[cnt-i-1]+" ");
			}
		}
	}
}

Measured memory_bytes: 17036
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(int i = a; i < n; ++i)
#define pb push_back
#define mp make_pair
#define f first
//#define sex second

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <set>
#include <ostream>
#include <queue>
#include <functional>
#include <sstream>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#pragma comment(linker, "/STACK:228228000")
const ll mod = 9982443530;

ll n, c, res = mod;
ll ds[31][31];
ll cols[3][31];
ll wr[555][555];

int main()
{
	/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	cin >> n >> c;

	forn(i, 1, c + 1)
	{
		forn(j, 1, c + 1)
		{
			cin >> ds[i][j];
		}
	}

	forn(i, 1, n + 1)
	{
		forn(j, 1, n + 1)
		{
			cin >> wr[i][j];
			forn(t, 1, c + 1)
			{
				if (wr[i][j] == t)
					continue;
				cols[(i + j) % 3][t] += ds[wr[i][j]][t];
			}
		}
	}

	forn(i, 1, c + 1)
	{
		forn(j, 1, c + 1)
		{
			if (j == i)
				continue;

			forn(t, 1, c + 1)
			{
				if (t == i || t == j)
					continue;
				res = min(res, cols[0][i] + cols[1][j] + cols[2][t]);
			}
		}
	}

	cout << res;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
string s;
cin>>n>>s;
for(int i=0;i<s.size();i++){
    if((char)(s.at(i)+n)>'Z'){
        cout<<char(s.at(i)+n-'Z'+'A'-1);
    }else{
    cout<<(char)(s.at(i)+n);
    }
}

}










Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1000
#define MAX_S 305
map<string,int> mp;
string A,B;
int si,ti;
int n;
bool used[MAX_N];
vector<int> x[MAX_N],y[MAX_N];
vector<int> G[MAX_S][MAX_S];
int t[MAX_S][MAX_S];

bool solve(){
  for(int i=0;i<MAX_N;i++)used[i]=false;
  for(int i=0;i<MAX_S;i++)
    for(int j=0;j<MAX_S;j++)
      t[i][j]=(i==j?0:1e7);
  
  queue<int> qa,qb;
  qa.push(si);
  qb.push(ti);
  while(!qa.empty()){
    int a=qa.front();qa.pop();
    int b=qb.front();qb.pop();
    if(t[a][b]==-1)continue;
    t[a][b]=-1;
    for(int i=0;i<(int)G[a][b].size();i++){
      int id=G[a][b][i];
      if(used[id])continue;
      used[id]=true;
      for(int j=0;j<(int)x[id].size();j++){
        qa.push( x[id][j] );
        qb.push( y[id][j] );
      }
    }
    for(int i=0;i<MAX_S;i++){
      if(t[b][i]==-1){
        qa.push(a);
        qb.push(i);
      }
      if(t[i][a]==-1){
        qa.push(i);
        qb.push(b);
      }
    }
  }

  for(int k=0;k<MAX_S;k++)
    for(int i=0;i<MAX_S;i++)
      for(int j=0;j<MAX_S;j++)
        t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
  for(int i=0;i<MAX_S;i++)
    if(t[i][i]<0)return false;
  return true;
}

int input(string &s){
  cin>>s;
  if(mp.count(s)==0){
    int res=mp.size();
    mp[s]=res;
    return res;
  }else{
    return mp[s];
  }
}

int main(){
  si=input(A);
  ti=input(B);
  cin>>n;
  for(int i=0;i<n;i++){
    int q;
    cin>>q;
    for(int j=0;j<q;j++){
      string str;
      int L=input(str);
      int R=input(str);
      x[i].push_back(L);
      y[i].push_back(R);
      G[L][R].push_back(i);
    }
  }
  cout<< (solve()?"Yes":"No") <<endl;
  return 0;
}

Measured memory_bytes: 224948
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

#define MOD 1000000007
using namespace std;
typedef long long ll;
ll sum[200001];
vector<ll> v[2019];
int main() {
  ll ans = 0LL;
  int n;
  string s;
  cin >> s;
  n = s.length();
  reverse(s.begin(), s.end());
  int x = 1;
  v[0].push_back(0);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + x * (s[i] - '0');
    sum[i + 1] %= 2019;
    v[sum[i + 1]].push_back(1 + i);
    x *= 10;
    x %= 2019;
  }
  for (ll i = 0; i < 2019; i++) {
    if (!v[i].empty()) {
      for (ll j = 0; j < v[i].size(); j++) {
        ans += (ll)(v[i].size() - j - 1);
        /*for (ll k = j + 1; k < v[i].size(); k++) {
          if (v[i][k] - v[i][j] >= 4) {
            ans += (ll)(v[i].size() - k);
          }
        }*/
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n, m;
  cin >> n;
  vector<string> s(n);
  map<string, int> counter1;
  map<string, int> counter2;

  for(int i=0;i<n;i++) {
    cin >> s[i];
    counter1[s[i]]++;
  }
  cin >> m;
  vector<string> t(m);
  for(int i=0;i<m;i++) {
    cin >> t[i];
    counter2[t[i]]++;
  }

  int max = 0;

  for(auto it = counter1.begin();it!=counter1.end();it++) {
    it->second -= counter2[it->first];
    if(it->second > max) {
      max = it->second;
    }
  }

  cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end()
#define int long long
#define double long double
int gcd(int x, int y){
    if (y == 0)
        return x;
    x = x % y;
    gcd(y, x);
}
main()
{
	int n;
	cin>>n;
	int a=0;
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			if(i*j==n){
				cout<<"Yes"<<endl;
				a=1;
				break;
			}
		}
		if(a==1) break;
	}
	if(a==0)cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x; cin>>x;
    string g; cin>>g;
    int len=(int)g.size();
    for(int i=0;i<len;i++){
        int w = g[i]-'A';
        w=(w+x)%26;
        g[i]=w+'A';
    }cout<<g;







return 0;}


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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  vector<int> a(3);
  cin >> a;

  whole(sort, a);
  cout << (a[0] == a[2] ? "Yes" : "No") << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll ans[100010];

int main(){
  int a,b,q;
  cin >> a >> b >> q;
  vector<ll> s(a),t(b),x(q);
  rep(i,a)cin >> s[i];
  rep(i,b)cin >> t[i];
  rep(i,q)cin >> x[i];

  rep(i,q){
    ll temp=longinf;
    auto it=lower_bound(s.begin(),s.end(),x[i]);
    auto it2=lower_bound(t.begin(),t.end(),x[i]);
    ll distl=longinf,distr=longinf;
    ll distl2=longinf,distr2=longinf;
    if(it==s.end()){
      distl=x[i]-s[a-1];
    }
    else if(it==s.begin()){
      distr=s[0]-x[i];
    }
    else{
      distr=(*it)-x[i];
      it--;
      distl=x[i]-(*it);
    }
    if(it2==t.end()){
      distl2=x[i]-t[b-1];
    }
    else if(it2==t.begin()){
      distr2=t[0]-x[i];
    }
    else{
      distr2=(*it2)-x[i];
      it2--;
      distl2=x[i]-(*it2);
    }
    temp=max(distl,distl2);
    temp=min(temp,max(distr,distr2));
    temp=min(temp,distl+distr2+min(distl,distr2));
    temp=min(temp,distl2+distr+min(distl2,distr));
    ans[i]=temp;
  }
  rep(i,q)cout << ans[i] << endl;
return 0;}

Measured memory_bytes: 4480
n, y = map(int, input().split())

res = 0
for a in range(n+1):
    for b in range(n+1-(a)):
        if 0 <= y - 10000*(a) - 5000*(b) <= 1000*(n-(a+b)):
            c = (y - 10000*(a) - 5000*(b) ) // 1000
            if a+b+c == n:
                r,e,s = a,b,c
                res += 1

if res > 0:
    print(r,e,s)
else:
    print(-1,-1,-1)



Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;


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

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int

const int hell=1000000007;



int solve( ){


  int a,b,c;
  cin>>a>>b>>c;
  cout<<a+b+c-max({a,b,c});

}
signed main()
{  int t=1;

 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);                                                                    

  clock_t time_req;

    // Without using pow function
                                                                                                                   
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
      cout<<endl;

     }

         time_req = clock() - time_req;
    //cout <<endl<< "Processor time taken is "
     // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 256
def gcd(x, y):
	if y == 0:
		return x
	r = x % y
	while r != 0:
		x = y
		y = r
		r = x % y
	return y

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

l = [0] * (n + 2)
r = [0] * (n + 2)

for i in range(1, n + 1):
	l[i] = gcd(l[i - 1], a[i - 1])

for i in range(n, 0, -1):
	r[i] = gcd(r[i + 1], a[i - 1])

ans = 1
for i in range(1, n + 1):
	ans = max(ans, gcd(l[i - 1], r[i + 1]))

print(ans)

Measured memory_bytes: 14428
#include<stdio.h>
#include<stdlib.h>
int fun(int ,int );
int fun(int n,int m)
{
    return (n-1)*(m-1);
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    printf("%d\n",fun(n,m));
    return 0;
}

Measured memory_bytes: 128
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N,ans=0;
    int V[21],C[21];
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    for(int k=0;k<N;k++){
        cin>>C[k];
    }
    for(int l=0;l<N;l++){
        if(V[l]>C[l]){
            ans=ans+V[l]-C[l];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int n,u,k,i,j,v[1000],x[1000][1000];
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v[i]);
      x[u-1][v[i]-1] = 1;
     }
  }
 
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j == 0){
    if(x[i][j] != 1) printf("0");
    else printf("1");
      }
      else{
    if(x[i][j] != 1) printf(" 0");
    else printf(" 1");
      }
    }
    printf("\n");
  }
 
  return 0;
}

Measured memory_bytes: 976
import java.util.Scanner;

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

		if(str.charAt(0)=='7' || str.charAt(1)=='7' || str.charAt(2)=='7') {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		scan.close();
	}
}


Measured memory_bytes: 35716
#include <bits/stdc++.h>
#define pb push_back
#define INF 1<<30
#define all(x) x.begin(),x.end()
#define ms(a,v) memset(a,v,sizeof a)
#define II ({int a; scanf("%d", &a); a;})
#define LL  ({ll  a; scanf("%lld", &a); a;})
#define EPS 1e-10
#define pi acos(0.0)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<int> vi ;
typedef vector<ll>vl;

#define FOR(i,n) for( __typeof(n)i = 0 ; i < n ; i++)
#define FORL(i,a, b) for( __typeof(n)i = a ; i <= b ; i++)
#define FORR(i,a, b) for( __typeof(n)i = a ; i >= b ; i--)
#define For(i,n) for( __typeof(n)i = 1 ; i <= n ; i++)
#define forstl(i,n) for(__typeof(n.begin())i = n.begin();i!=n.end();i++)
#define forab(i,a,b) for( __typeof(b) i = a ; i <= (b) ; i++ )
#define forba(i,b,a) for( __typeof(b) i = b ; i >= (a) ; i-- )

int x[4] = {0 , 0 , -1, 1};
int y[4] = {1, -1, 0  , 0};



void solve()
{
	string s;
	cin >> s;

	if (s[0] == 'R')
	{
		if (s[1] == 'R')
		{
			if (s[2] == 'R')
				cout << 3 << endl;
			else
				cout << 2 << endl;
		}
		else
		{
			cout << 1 << endl;
		}
	}
	else
	{
		if (s[1] == 'R')
		{
			if (s[2] == 'R')
				cout << 2 << endl;
			else
				cout << 1 << endl;
		}
		else
		{
			if (s[2] == 'R')
				cout << 1 << endl;
			else
				cout << 0 << endl;
		}
	}
}

int main()
{


	int T = 1;
	//cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)

	//freopen("input.txt", "r", stdin);

	// Printing the Output to output.txt file
	//freopen("output.txt", "w", stdout);

	while (T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3624
// abc140_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n;
  cin >> n;
  cout << n*n*n << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
memo = [0]*10010

for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            z = i**2+j**2+k**2+i*j+j*k+k*i
            if z <= n:
                memo[z] += 1


for i in range(1, n+1):
    print(memo[i])

Measured memory_bytes: 68992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int cnt = s.length() - 2;
        int abs = Integer.MAX_VALUE;
        for (int i = 0; i < cnt; i++) {
            int v = Integer.parseInt(s.substring(i, i + 3));
            int tmp = Math.abs(753 - v);
            if (abs > tmp) abs = tmp;
        }
        System.out.println(abs);
    }
}


Measured memory_bytes: 23124
MOD = 10 ** 9 + 7


def add(x, y):
    ret = x + y
    if ret >= MOD:
        ret -= MOD
    return ret


S = input().strip()

dp = [[0] * 4 for _ in range(len(S) + 1)]
dp[0][0] = 1

for i in range(len(S)):
    unit = 3 if S[i] == '?' else 1
    for j in range(4):
        dp[i + 1][j] = dp[i][j] * unit % MOD

    if S[i] == 'A' or S[i] == '?':
        dp[i + 1][1] = add(dp[i + 1][1], dp[i][0])
    if S[i] == 'B' or S[i] == '?':
        dp[i + 1][2] = add(dp[i + 1][2], dp[i][1])
    if S[i] == 'C' or S[i] == '?':
        dp[i + 1][3] = add(dp[i + 1][3], dp[i][2])

print(dp[-1][3])

Measured memory_bytes: 27564
#include <stdio.h>

int main(void){
  int N,M,i,j,k,l,flag;
  char a[51][51],b[51][51];

  scanf("%d %d",&N,&M);

  for(i=0;i<N;i++){
    scanf("%s",a[i]);
  }
  for(i=0;i<M;i++){
    scanf("%s",b[i]);
  }

  for(i=0;i<N-M+1;i++){
    for(j=0;j<N-M+1;j++){
      flag=1;
      for(k=0;k<M;k++){
        for(l=0;l<M;l++){
          if(a[i+k][j+l]!=b[k][l]){
            flag=0;
          }
        }
      }
      if(flag==1){
        printf("Yes\n");
        return 0;
      }
    }
  }

  if(flag==0){
    printf("No\n");
  }

  return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  if(S == "Sunny")
    cout << "Cloudy" << endl;
  else if(S == "Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#na-
import itertools
H, W, K = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(H)]
def check(k):
    if k <= K:
        return(True)
    else:
        return(False)
        
noans = 0
def make_lst(i):
    global noans, lst, havelst
    temp = S[0][i]
    for h in range(H-1):
        if y[h]:
            lst.append(temp)
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
    lst.append(temp)
    if check(max(lst)):
        havelst = 1
    else:
        noans = 1
               
def nocut(i):
    global cutnum, lst, havelst
    prelst = []
    temp = S[0][i]
    j = 0
    for h in range(H-1):
        if y[h]:
            lst[j] += temp
            prelst.append(temp)
            j += 1
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
    prelst.append(temp)
    lst[-1] += temp
    if check(max(lst)):
        return(True)
    else:
        cutnum += 1
        lst = prelst        
                 
ans = float("inf")
cutlst = []    
for y in itertools.product((0, 1), repeat=H-1):
    havelst = 0
    lst = []
    cutnum = sum(y)
    for x in range(W):
        if noans:
            break
        if havelst:
            nocut(x)
        else:
            make_lst(x)
    if noans==1:
        noans = 0
        continue
    ans = min(cutnum, ans)
print(ans)

Measured memory_bytes: 3188
#coding :utf-8                                                                                                                                              
N, K = map(int, raw_input().split())
D = map(int, raw_input().split())

while True:
    flag = True
    for x in D:
        if str(x) in str(N):
            flag = False
            break
    if flag:
        break
    N += 1

print N

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int a, b, c;
    cin >> a >> b >> c;

    if(a == b + c || b == a + c || c == a + b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

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

bool IsPrime(long long num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;  // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }
    // 素数
    return true;
}

int main() {
    //
    long long num;
    long long sNum;
    long long Min = 9999999;
    string a, b;

    cin >> num;

    if (IsPrime(num) == true) {
        cout << to_string(num).size();
        return 0;
    }

    for (long long i = 1; i <= sqrt(num); i++) {
        if (num % i == 0) {
            a = to_string(i);
            b = to_string(num / i);
            Min = min(Min,(long long)max(a.size(), b.size()));
        }
    }

    cout << Min;
    //
}

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

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

    int n, m;
    cin >> n >> m;
    vector<bool> a(n + 1, true);
    REP(i, m) {
        int tmp;
        cin >> tmp;
        a[tmp] = false;
    }

    vector<ll> dp(n + 1, 0);
    dp[0] = 1;

    REP(now, n) {
        for (int next = now + 1; next <= min(now + 2, n); next++) {
            if (a[next]) {
                dp[next] += dp[now];
                dp[next] %= int(1e9 + 7);
            }
        }
    }

    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;

#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;
int a,b,c,d;
int sum,ans;
str s1,s2,s;

int32_t main() {
    fast();
    cin >> a >> b;

    vec q(b);
    f(i,0,b){
    	cin >> q[i];
    	sum+=q[i];
    }
    if(sum>=a){
    	cout<<"Yes\n";
    }
    else{
    	cout<<"No\n";
    }

    return 0;
}
 

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 1e5+10;

const int base = 1e5+10;

int n;
int A[MAXN];
int small[MAXN];
ll fw[3*MAXN];

ll query(int i) {
	ll ret = 0;
	while(i>0) {
		ret += fw[i];
		i -= (i&-i);
	}
	return ret;
}

void update(int i, ll v) {
	while(i<=base+n) {
		fw[i] += v;
		i += (i&-i);
	}
}

// x보다 같거나 작은 median의 개수
ll calc(int x) {
	for(int i=1;i<=n;i++) {
		if(A[i]<=x) {
			small[i] = small[i-1] + 1;
		}
		else{
			small[i] = small[i-1] - 1;
		}
	}

	for(int i=0;i<=base+n;i++) {
		fw[i] = 0;
	}

	ll sum=0;
	update(base+0, 1ll);
	for(int R=1;R<=n;R++) {
		sum += query(base+small[R]-1);

		// printf("small[%d]:%d, ret:%lld\n", R, small[R], query(base+small[R]-1));
		update(base+small[R], 1ll);
	}

	// printf("x=%d, sum=%lld\n", x, sum);
	// puts("");
	return sum;
}

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

	vector<int> cand;
	for(int i=1;i<=n;i++){
		scanf("%d", &A[i]);
		cand.push_back(A[i]);
	}

	sort(cand.begin(), cand.end());
	cand.erase(unique(cand.begin(), cand.end()), cand.end());

	int L = 0, R = cand.size()-1;
	while(L<R) {
		int M =(R+L)/2;
		ll ret = calc(cand[M]);

		if(ret>=(ll)n*(n+1)/2/2+1) R = M;
		else L = M+1;
	}

	printf("%d", cand[L]);

	// vector<int> mds;
	// for(int i=0;i<n;i++){		
	// 	for(int j=i;j<n;j++){
	// 		vector<int> tmp;

	// 		for(int k=i;k<=j;k++)
	// 			tmp.push_back(A[i]);
	// 		sort(tmp.begin(), tmp.end());
	// 		mds.push_back(tmp[(j-i+1)/2]);
	// 	}
	// }
	// sort(mds.begin(), mds.end());
	// printf("%d", mds[mds.size()/2]);
	return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[][] board = new char[n + 1][];
		for(int i = 0; i < n + 1; i++) {
			board[i] = sc.next().toCharArray();
		}
		int sum = 0; //print
		for(int i = 1; i <= n; i++) {//?????????????????£????????????
			out: for(int j = 0; j < board[i].length; j++) {//1??????????????¢?´¢
				if(board[i][j] == board[0][0]) {
					for(int k = j + 1; k < board[i].length; k++) {//2??????????????¢?´¢
						if(board[i][k] == board[0][1]) {
							int interval = k - j;//1???????????¨2??????????????????
							int cnt = 2;//?????????????????¢?´¢???????????????
							for(int m = k + interval; m < board[i].length; m = m + interval) {//3???????????\????????¢?´¢
								if(board[i][m] == board[0][cnt]) {
									cnt = cnt + 1;
									if(cnt == board[0].length) {
										sum = sum + 1;
										break out;
									}
								} else {
									break;
								}
							}
						}
					}
				}
			}
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 27608
N, A, B = map(int, input().split())

D = B - A

ans = float('inf')
if D % 2 == 0:
    ans = D//2
else:
    # 左端まで行く
    move = A - 1
    L = 1
    R = B - move
    D = R - L
    if D % 2 == 0:
        ans = min(ans, D//2 + move)
    else:
        ans = min(ans, D//2+1 + move)
    # 右端まで行く
    move = N - B
    L = A + move
    R = N
    D = R - L
    if D % 2 == 0:
        ans = min(ans, D//2 + move)
    else:
        ans = min(ans, D//2+1 + move)

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

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

  int debt = 100000;
  for (int i=0; i<n; i++) {
    debt += debt*0.05;

    int amari = debt % 1000;
    if (amari > 0) {
      debt -= amari;
      debt += 1000;
    }
  }
  cout << debt << endl;

  return 0;
}



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

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

  int i=0,j=-1,k=-1,x=0;
  string s=a;
  
  while(i!=a.size() && j!=b.size() && k!=c.size()){
    if(s[x]=='a'){
      i++;
      s=a;
      x=i;
    }else if(s[x]=='b'){
      j++;
      s=b;
      x=j;
    }else{
      k++;
      s=c;
      x=k;
    }
  }
  
  if(i==a.size())cout<<'A'<<endl;
  else if(j==b.size())cout<<'B'<<endl;
  else cout<<'C'<<endl;
}

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

int main() {

  int a, b;
  cin >> a >> b;
  int t;
  if(a <= b) {
    if(b == 1) {
      t = a * 1;
    }
    else if(b == 3) {
      t = a * 111;
    }
    else if(b == 4) {
      t = a * 1111;
    }
    else if(b == 5) {
      t = a * 11111;
    }
    else if(b == 6) {
      t = a * 111111;
    }
    else if(b == 7) {
      t = a * 1111111;
    }
    else if(b == 8) {
      t = a * 11111111;
    }
    else if(b == 9) {
      t = a * 111111111;
    }
  }
  else if(b <= a) {
    if(a == 1) {
      t = b * 1;
    }
    else if(a == 2) {
      t = b * 11;
    }
    else if(a == 3) {
      t = b * 111;
    }
    else if(a == 4) {
      t = b * 1111;
    }
    else if(a == 5) {
      t = b * 11111;
    }
    else if(a == 6) {
      t = b * 111111;
    }
    else if(a == 7) {
      t = b * 1111111;
    }
    else if(a == 8) {
      t = b * 11111111;
    }
    else if(a == 9) {
      t = b * 111111111;
    }
  }
  cout << t << endl;
}
    

Measured memory_bytes: 256
from bisect import bisect_right
import sys
input = sys.stdin.readline


X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

A1 = [A[0]-a for a in A]
B1 = [B[0]-b for b in B]
C1 = [C[0]-c for c in C]

'''
for ia, a in enumerate(A1):
    ib = bisect_right(B1, a)
    ic = bisect_right(C1, a)
    if (ia)*(ib)*(ic) > K:
        break

if ia == X-1:
    A2 = A1
else:
    A2 = A1[:ia+2]
if ib == Y-1:
    B2 = B1
else:
    B2 = B1[:ib+2]
if ic == Z-1:
    C2 = C1
else:
    C2 = C1[:ic+2]
'''
Q = []
for ia, a in enumerate(A1):
    for ib, b in enumerate(B1):
        for ic, c in enumerate(C1):
            if (ia+1) * (ib+1) * (ic+1) > K:
                break 
            Q.append(a+b+c)
Q.sort()
S = A[0] + B[0] + C[0]
for i in range(K):
    print(S-Q[i])

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

int nextanother(int& i, int N, int One) {
	int Another;
	cin >> Another;
	i++;
	while (i < N && Another == One) {
		cin >> Another;
		i++;
	}
	return Another;
}

int main() {
	int N;
	cin >> N;
	int ans = 1;
	int A1, A2, A3;
	cin >> A1;
	int i = 1;
	A2 = nextanother(i, N, A1);
	while (i < N) {
		A3 = nextanother(i, N, A2);
		if (((A3 < A2) & (A2 > A1)) || ((A3 > A2)& (A2 < A1))) {
			ans++;
			if (i < N) {
				A1 = A3;
				A2 = nextanother(i, N, A1);
			}
		}
		else {
			A1 = A2;
			A2 = A3;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	cin>>n;
	ll ans=0;
	ll ar[n];
	for(i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	ll mn=ar[0];
	for(i=1;i<n;i++)
	{
		if(ar[i]<mn)
		ans+=mn-ar[i];
		else mn=ar[i];
	}
	cout<<ans;
}

Measured memory_bytes: 5084