akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;

int main() {
  ll N = 0;
  cin >> N;
  map <ll,ll> mp;
  rep(i,N){
    ll a; cin >> a;
    mp[a]++;
  }
  ll M = 0;
  cin >> M;
  rep(i,M){
    ll b; cin >> b;
    if(mp[b] == 0){
      cout << "NO";
      return 0;
    }
    else{
      mp[b]--;
    }
  }
  cout << "YES";
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  int l = 1;
  int r = N;
  int L, R;
  for (int i = 0; i < M; ++i)
  {
    cin >> L;
    if (l < L)
      l = L;
    cin >> R;
    if (R < r)
      r = R;
  }
  cout << ((r < l) ? 0 : r - l + 1);
  return 0;
}


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

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	ll X;
	cin >> X;

	if (X % 11 == 0) {
		cout << (X / 11) * 2;
	}
	else if (X % 11 > 6) {
		cout << (X / 11) * 2 + 2;
	}
	else {
		cout << (X / 11) * 2 + 1;
	}




}	




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

class Dice {
public:
	int		value  = 1;                    // 上面の値　
	int 	s[7] = {0, 1, 2, 3, 4, 5, 6};  // 各面の値

	void init(int x[]) {
		for(int i=0; i<6; i++ ) s[i+1] = x[i];
		value = s[1];	
	}	 
	
	void dump() {
		for(int i=1; i<=6; i++) {
			cout << "S" << i << ":" << s[i] <<", ";
		}
		cout << endl;
	}	
		
	void flip(char c) {
		switch (c) {
			case 'N':
				flip_N();
				break;
			case 'S':
				flip_S();
				break;
			case 'E':
				flip_E();
				break;
			case 'W':
				flip_W();
				break;
			default:
				break;
		}
	}
	void flips(string cmds) {
		for(int i=0; i<cmds.size(); i++) {
			flip(cmds[i]);
		}	
	} 	
	
	int flip_N() {
		// 面3,4変わらず、面1265 をローテ―トする
		int x = s[1];
		s[1] = s[2];
		s[2] = s[6];
		s[6] = s[5];
		s[5] = x;

		value  = s[1];
	}
	
	int flip_S() {
		// 面3,4変わらず、面1265 をローテ―トする
		int x = s[1];
		s[1] = s[5];
		s[5] = s[6];
		s[6] = s[2];
		s[2] = x;

		value  = s[1];
	}
	
	int flip_E() {
		// 面2,5変わらず、面1364 をローテ―トする
		int x = s[1];
		s[1] = s[4];
		s[4] = s[6];
		s[6] = s[3];
		s[3] = x;

		value  = s[1];
	}

	int flip_W() {
		// 面2,5変わらず、面1364 をローテ―トする
		int x = s[1];
		s[1] = s[3];
		s[3] = s[6];
		s[6] = s[4];
		s[4] = x;

		value = s[1];
	}

	int rotate_z() {
		// 面1固定で縦軸(z軸)回転
		int x = s[2];
		s[2] = s[4];
		s[4] = s[5];
		s[5] = s[3];
		s[3] = x;
	}

private:
};




int main() {
	Dice d1;
	int ss[6];

	for(int i=0; i<6; i++) cin >> ss[i];

	int n;
	cin >> n;
	for(int i=0; i < n; i++) {
		d1.init(ss);

		int x,y;
		cin >> x >> y;

		string command = "NNWWNW";   
		bool loop = true;
		for(int j=0;j<command.size() && loop; j++) {
			d1.flip(command[j]);
			for(int k=0; k<4; k++) {
				d1.rotate_z();
  				if ((d1.s[1] == x) && (d1.s[2] == y)) {
  					cout << d1.s[3] << endl;
  					loop = false;
  					break;
  				}
			}	
		}
	}

	return 0;
}


Measured memory_bytes: 3208
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def leven(s1, s2):
    n1 = len(s1)
    n2 = len(s2)
    dp = [[0]*(n1+1) for _ in range(n2+1)]

    for i in range(1, n1+1):
        dp[0][i] = i
    for i in range(1, n2+1):
        dp[i][0] = i

    for j in range(1, n2+1):
        for k in range(1, n1+1):
            m = min(dp[j-1][k], dp[j][k-1])+1
            if s1[k-1] == s2[j-1]:  # 最後の文字削除
                m = min(m, dp[j-1][k-1])
            else:
                m = min(m, dp[j-1][k-1]+1)
            dp[j][k] = m
    print(dp[-1][-1])


s1 = input()[:-1]
s2 = input()[:-1]
leven(s1, s2)



Measured memory_bytes: 42540
#include <stdio.h>

int Euclidean(int a, int b);

int main(void){
  int a, b, gcd;

  scanf("%d%d", &a, &b);
  gcd = Euclidean(a, b);
  printf("%d\n", gcd);
  return 0;
}


int Euclidean(int a, int b){
  int r;

  if(a < b){
    r = a;
    a = b;
    b = r;
  }
  while(b != 0){
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> dp(n + 5, vector<int>(n + 5, 0));
    for(int i = n - 1; i >= 0; --i){
        for(int j = n - 1; j >= 0; --j){
            if(s[i] != s[j])    continue;
            chmax(dp[i][j], dp[i + 1][j + 1] + 1);
        }
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(i >= j)  continue;
            chmax(ans, min(dp[i][j], j - i));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 98304
N, M = map(int, input().split())

a = [0] * N
b = [0] * N
c = [0] * M
d = [0] * M
for _ in range(N):
    a[_], b[_] = map(int, input().split())

for _ in range(M):
    c[_], d[_] = map(int, input().split())


for i in range(N):
    min_dist = float('inf')
    ans = 0
    for j in range(M):
        distance = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if min_dist > distance:
            min_dist = distance
            ans = j + 1
    print(ans)

Measured memory_bytes: 3064
S=input()
T=input()
answer='UNRESTORABLE'

if len(T)>len(S):
    print(answer)
elif len(T)==len(S):
    for i in range(len(S)):
        if S[i]!='?' and S[i]!=T[i]:
            print(answer)
            break
    print(T)
else:
    for i in range(len(S)-len(T),0,-1):
        tmpS=S[i:i+len(T)]
        flag=True
        for j in range(len(T)):
            if T[j]==tmpS[j] or tmpS[j]=='?':
                continue
            else:
                flag=False
        if flag:
            ans=S[0:i]+T+S[i+len(T):len(S)]
            answer = ans.replace("?","a")
            break

    print(answer)

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

using namespace std;

#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  string S;
  cin >> S;
  if (S.length() == 1) {
    OUT(S);
    return 0;
  }
  int sum = 0;
  for (const auto& e : S) {
    sum += (int)e - '0';
  }
  if (S[0] != '9') {
    int ans = (S[0] - '0') - 1 + 9 * (S.length()-1);
    OUT(max(sum, ans));
    return 0;
  }
  for (const auto& e : S) {
    if (e != '9') {
      int ans = S.length() * 9 - 1;
      OUT(max(sum, ans));
      return 0;
    }
  }
  OUT(S.length() * 9);

  return 0;
}


Measured memory_bytes: 256
// Author : Chi
// created :
// Sawal : Practice

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <pair<int,int>, null_type, greater<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define pii         pair<ll,ll>
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define ai(a)       for(auto &i:a)cin>>i;
#define ao(a)       for(auto i:a)cout<<i<<' ';
#define TEST1       solve();
#define mod         1000000007
#define aLL(x)      x.begin(),x.end()
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
//LOVE ALGO
//Make sure you have test cases (:->)
void solve(){
    string s;
    cin>>s;
    if(s[s.length()-1]=='s'){
        s+='e';
    }
    s+='s';
    cout<<s;
}
int main(){
    CHI
    TEST1
    return 0;
}


Measured memory_bytes: 3648
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
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);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int cnt = 0;
    while(b <= a) {
        b <<= 1;
        cnt++;
    }
    while(c <= b) {
        c <<= 1;
        cnt++;
    }
    if(k < cnt) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
    int a,b,c,d,x;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    if(a<b)
        x=a;
    else
        x=b;
        
    if(c<d)
        x+=c;
    else
        x+=d;

    printf("%d",x);
}

Measured memory_bytes: 128
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  ll N;
  cin >> N;
  vector<ll> h(N);
  vector<ll> dp(N);
  rep(i, N)
  {
    cin >> h.at(i);
  }
  dp.at(0) = 0;
  dp.at(1) = abs(h.at(1) - h.at(0));
  rep(i, N - 2)
  {
    dp.at(i + 2) = min(dp.at(i + 1) + abs(h.at(i + 1) - h.at(i + 2)), dp.at(i) + abs(h.at(i) - h.at(i + 2)));
  }

  cout << dp.at(N - 1) << endl;
  return 0;
}


Measured memory_bytes: 1792
fun main() {
    println(solve())
}

val solve: () -> Any = {
    val (N, K) = readIntList()
    val list = (0L..N).toList()
    var first = list.takeLast(K-1).sum()
    var last = list.take(K-1).sum()
    var ans = 0L
    for (n in K .. N + 1) {
        first += list[N-n+1]
        last += list[n-1]
        ans += first - (last - 1)
        ans %= 1_000_000_000L + 7
    }
    ans
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 46080
n = int(input())
a = [list(map(int,input().split())) for _ in range(n-1)]

for i in range(n-1): #出発する駅のインデックス
    total_time = a[i][1] + a[i][0]
    current_time = total_time
    for j in range(i+1,n-1): #通過駅
        if current_time <= a[j][1]:
            total_time = a[j][1] 
            total_time += a[j][0]
            current_time = a[j][1] + a[j][0]
        else:
            for i in range(a[j][2]):
                if (current_time+i)%a[j][2] == 0:
                    current_time += i
                    current_time += a[j][0]
                    total_time += i + a[j][0]
                    break
    print(total_time)

print(0) #最後の駅にいるとき

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

using namespace std;

struct node
{
	int ls,rs;
	node()
	{
		ls=rs=-1;
	}
}T[41];

int n,Pre[40],In[40];

vector<int> Post;

int make(int Ins,int Int,int Pres)
{
	//
	if(Ins>Int) return -1;
	int r;
	for(r=Ins;In[r]!=Pre[Pres];r++);
	T[Pre[Pres]].ls=make(Ins,r-1,Pres+1);
	T[Pre[Pres]].rs=make(r+1,Int,Pres+1+r-Ins);
	//printf("%d %d %d %d\n",Ins,Int,Pres,r);
	return Pre[Pres];
}

void Postorder(int t)
{
	if(t==-1) return;
	Postorder(T[t].ls);
	Postorder(T[t].rs);
	Post.push_back(t);
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&Pre[i]);
	for(int i=0;i<n;i++)
		scanf("%d",&In[i]);
	int r=make(0,n-1,0);
	Postorder(r);
	for(int i=0;i<Post.size();i++)
		printf("%d%c",Post[i],i+1==n?'\n':' ');
	return 0;
}

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

int main(void){
  string A, B, C;
  cin >> A >> B >> C;
  char a, b, c;
  a = A.at(0) - 0x20;
  b = B.at(0) - 0x20;
  c = C.at(0) - 0x20;
  cout << a << b << c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
ll n, x;
pair<ll, pll> op[MN];
ll tot;

ll get(int i, ll k){
    if(i > n) return 0;
    if(k <= op[i].f){
        //cout << "get " << i << " " << k << " " << op[i].s.f*k << "\n";
        return op[i].s.f*k;
    } else{
        //cout << "get " << i << " " << k << " " << op[i].s.f*op[i].f+op[i].s.s*(k-op[i].f) << "\n";
        return op[i].s.f*op[i].f+op[i].s.s*(k-op[i].f);
    }
}

bool calc(ll k){
    //cout << "doing " << k << "\n";
    ll amt = k/x;
    ll res = k%x;
    ll sm = 0;
    ll orz = get(amt+1, x);
    FOR(i, 1, amt){
        ll res = get(i, x);
        sm += res;
    }
    ll mx = 0;
    FOR(i, 1, amt){
        ll cur = sm-get(i, x)+orz + get(i, res);
        mx = max(mx, cur);
    }
    FOR(i, amt+1, n){
        ll cur = sm+get(i, res);
        mx = max(mx, cur);
    }
    //cout << "best ans is " << mx << " with " << amt << " " << res << "\n";
    return mx >= tot;
}

bool comp(pair<ll, pll> a, pair<ll, pll> b){
    ll res1 = a.s.f*a.f+a.s.s*(x-a.f);
    ll res2 = b.s.f*b.f+b.s.s*(x-b.f);
    if(res1 != res2) return res1 > res2;
    return a.f < b.f;
}

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

    cin >> n >> x;
    FOR(i, 1, n){
        cin >> op[i].f >> op[i].s.f >> op[i].s.s;
        tot += op[i].f*op[i].s.f;
    }
    //cout << "tot is " << tot << "\n";

    sort(op+1, op+1+n, comp);
    /*FOR(i, 1, n){
        cout << op[i].f << " " << op[i].s.f << " " << op[i].s.s << "\n";
    }*/

    ll l=-1, r=n*x;
    while(l+1 < r){
        ll mid = (l+r)/2; //calc after all
        //cout << "checking " << mid << "\n";
        if(calc(mid)){
            r = mid;
        } else{
            l = mid;
        }
    }

    cout << r << "\n";
    return 0;
}


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

int main(){
    ll n,a,b;cin>>n>>a>>b;
    ll ans=0;
    ll x_b,x_a;cin>>x_b;
    for(int i=1;i<n;i++){
        cin>>x_a;
        ans+=min(b,(x_a-x_b)*a);
        x_b=x_a;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0) {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=h-1;i>=0;i--) cin >> s.at(i);
  
  vector<vector<int>> map(h,vector<int>(w,0));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s.at(i).at(j) == '#'){
        if(i+1<h) map.at(i+1).at(j)++;
        if(i+1<h && j+1<w) map.at(i+1).at(j+1)++;
        if(j+1<w) map.at(i).at(j+1)++;
        if(i-1>=0 && j+1<w) map.at(i-1).at(j+1)++;
        if(i-1>=0) map.at(i-1).at(j)++;
        if(i-1>=0 && j-1>=0) map.at(i-1).at(j-1)++;
        if(j-1>=0) map.at(i).at(j-1)++;
        if(i+1<h && j-1>=0) map.at(i+1).at(j-1)++;
      }
    }
  }
  for(int i=h-1;i>=0;i--){
    for(int j=0;j<w;j++){
      if(s.at(i).at(j) == '#') cout << '#';
      else cout << map.at(i).at(j);
    }
    cout << endl;
  }
}
  
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define ALICE cout << "Alice" << endl
#define BOB cout << "Bob" << endl
#define DRAW cout << "Draw" << endl


class A {
	int a, b;
public:
	void solve()
	{
		if (a != b)
		{
			if (a != 1)
			{
				if (b != 1)
				{
					if (a > b) ALICE;
					else BOB;
				}
				else BOB;
			}
			else ALICE;
		}
		else DRAW;
	}

	A() { cin >> a >> b; }
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int n,flag=0;
vector<ll> a(100009), pat[100009],used(100009);
ll solve(ll x){
	used[x]=1;
	int fl = 0;
	for(int i=0;i<pat[x].size();i++){
		if(used[ pat[x][i] ] == 0)fl++;
	}
	if(fl == 0){
		return a[x];
	}
	vector<ll> subs;
	ll tot = 0;
	for(int i=0;i<pat[x].size();i++){
		if(used[pat[x][i]]==0){
			ll nu = solve( pat[x][i] ) ;
			if(nu==-1)return -1;
			subs.pb(nu);
			tot+=nu;
		}
	}
	sort( subs.begin(),subs.end());
	if( a[x]*2 < tot ){
		flag = -1;
		return -1;
	}
	else if(tot < a[x]){
		flag = -1;
		return -1;
	}
	else if( subs[subs.size()-1] > a[x]){
		flag = -1;
		return -1;
	}
	else{
		return 2*a[x]-tot;
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n-1;i++){
		ll fr,to;
		cin>>fr>>to;
		pat[fr].pb(to);
		pat[to].pb(fr);
	}
	if(n==2){
		if(a[1]==a[2]){
			cout<<"YES"<<endl;
			return 0;
		}
		else{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	ll good;
	for(int i=1;i<=n;i++){
		if(pat[i].size()>1){
			good = i;
			i = n+1;
		}
	}
	ll an = solve(good);
	if( an == 0 && flag == 0){
		cout<<"YES"<<endl;
		return 0;
	}
	else{
		cout<<"NO"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 16640
n,m=map(int,input().split())
l=[1]+[0]*(n+1)
a=[1]*n
for i in range(m):
 x,y=map(int,input().split())
 if l[x-1]:l[y-1]=1
 a[x-1]-=1;a[y-1]+=1
 if not a[x-1]:l[x-1]=0
print(l.count(1))

Measured memory_bytes: 10360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int h,w;
int f[10][10];

int ct;
int x[24],y[24];

unordered_map<int,int> dp;
int dfs(int s)
{
    if(dp.count(s)) return dp[s];

    int mask = s>>5;
    int now = s&31;

    vector<int> nx;
    int X=x[now], Y=y[now];

    X = x[now]+1;
    while(X<w)
    {
        if(f[Y][X]>0)
        {
            if(!(mask>>f[Y][X]&1))
            {
                nx.pb(f[Y][X]);
                break;
            }
        }
        ++X;
    }
    X = x[now]-1;
    while(X>=0)
    {
        if(f[Y][X]>0)
        {
            if(!(mask>>f[Y][X]&1))
            {
                nx.pb(f[Y][X]);
                break;
            }
        }
        --X;
    }

    X = x[now];
    Y = y[now]+1;
    while(Y<h)
    {
        if(f[Y][X]>0)
        {
            if(!(mask>>f[Y][X]&1))
            {
                nx.pb(f[Y][X]);
                break;
            }
        }
        ++Y;
    }
    Y = y[now]-1;
    while(Y>=0)
    {
        if(f[Y][X]>0)
        {
            if(!(mask>>f[Y][X]&1))
            {
                nx.pb(f[Y][X]);
                break;
            }
        }
        --Y;
    }

    // finish
    if(mask == (1<<ct)-1-1)
    {
        if(x[now]==x[0] || y[now]==y[0]) return 1;
        else return 0;
    }

    int ret=0;
    for(const auto &p:nx)
    {
        if(p==0) continue;

        int nmask = mask|(1<<p);
        int nxt = (nmask<<5) | p;
        ret += dfs(nxt);
    }

    dp[s]=ret;
    return ret;
}

int main()
{
    while(scanf(" %d %d", &w, &h),h)
    {
        ct=1;
        rep(i,h)rep(j,w)
        {
            scanf(" %d", &f[i][j]);
            if(f[i][j]==1)
            {
                f[i][j] = ct;
                x[ct] = j;
                y[ct] = i;
                ++ct;
            }
            else if(f[i][j]==2)
            {
                f[i][j] = 0;
                x[0] = j;
                y[0] = i;
            }
            else f[i][j]=-1;
        }

        dp.clear();
        printf("%d\n", dfs(0));
    }
    return 0;
}

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

public class Main {
    static ArrayList<Integer> heights = new ArrayList<>();
    static ArrayList<Integer> bests = new ArrayList<>();
    static int stones = 0;
    static int maxJump = 0;

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

        stones = sc.nextInt() ;
        maxJump = sc.nextInt();
        for (int c=0;c<stones;c++) {
           heights.add(sc.nextInt());
        }

        bests.add(0);
        bests.add(Math.abs(heights.get(0)-heights.get(1)));

        if (stones > 2){
            for (int c=2;c<stones;c++) {
                int bestJump = 0;
                for (int i=1;i <= maxJump;i++){
                    if (c-i >= 0) {
                        int thisJump = bests.get(c-i) + Math.abs(heights.get(c-i) - heights.get(c));
                        if (i == 1){
                            bestJump = thisJump;
                        }
                        if (thisJump <= bestJump) {
                            bestJump = thisJump;
                        }
                    }

                }

                bests.add(bestJump);

            }
        }


        System.out.println(bests.get(bests.size() - 1));

    }


}


Measured memory_bytes: 63420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    int N;string s;
    cin >> N >> s;
    ve<ve<char>> A(4,(ve<char>(N+1)));
    
    A[0][0] = 'W',A[0][1] = 'S';
    A[1][0] = 'W',A[1][1] = 'W';
    A[2][0] = 'S',A[2][1] = 'S';
    A[3][0] = 'S',A[3][1] = 'W';
    
    ve<char> las;
    
    if(s[0] == 'o') las = {'W','S','S','W'};
    else las = {'S','W','W','S'};

    
    rep(k,4){
        reps(i,1,N){
            if(s[i] == 'o'){
                if(A[k][i] == 'S') A[k][i+1] = A[k][i-1];
                else A[k][i+1] = (A[k][i-1]=='S' ? 'W':'S');
            }else{
                if(A[k][i] == 'S') A[k][i+1] = (A[k][i-1]=='S' ? 'W':'S');
                else A[k][i+1] = A[k][i+1] = A[k][i-1];
            }
        }
        if(A[k][N-1] == las[k] && A[k][N] == A[k][0]){
            rep(i,N) cout << A[k][i];
            cout << endl;
            return 0;
        }
    }
    
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int n,ans;
signed main(){
	
	string s;
    cin>>s;
    if(s=="SUN")ans=7;
    if(s=="MON")ans=6;
    if(s=="TUE")ans=5;
    if(s=="WED")ans=4;
    if(s=="THU")ans=3;
    if(s=="FRI")ans=2;
    if(s=="SAT")ans=1;
    cout<<ans<<endl;
}

Measured memory_bytes: 768
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll x;
  cin >> x;
  ll res = 100;
  int ans = 0;
  while (true) {
    res = res + res / 100;
    ans++;
    if (x <= res) break;
  }
  cout << ans << endl;
  return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

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

    bool isok = true;
    rep(i,n){
        if(a[i] % 2 == 0){
            if(a[i]%3 != 0 && a[i]%5 != 0){
                isok = false;
            }
        }
    }
    if(isok) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            y[i] = sc.nextInt();
        }
        double p1 = 0;
        double p2 = 0;
        double p3 = 0;
        double max = 0;
        for(int i = 0; i < n; i++){
            double diff = x[i] - y[i];
            if(diff < 0){
                diff *= -1;
            }
            p1 += diff;
            p2 += diff * diff;
            p3 += diff * diff * diff;
            if(max < diff){
                max = diff;
            }
        }
        System.out.println(p1);
        System.out.println(Math.sqrt(p2));
        System.out.println(Math.cbrt(p3));
        System.out.println(max);
    }
}


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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

int n,a;
int x[51];
ll dp[51][51][2501];
ll sum;

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

        for (int i = 1; i <= n; i ++) {
                scanf ("%d", &x[i]);
        }

        dp[0][0][0] = 1;

        for (int i = 1; i <= n; i ++) {
                for (int j = 0; j <= i; j ++) {
                        for (int k = 0; k <= 2500; k ++) {
                                dp[i][j][k] += dp[i - 1][j][k];

                                if (j > 0 && x[i] <= k)
                                        dp[i][j][k] += dp[i - 1][j - 1][k - x[i]];
                        }
                }
        }
        for (int i = 1; i <= n; i ++) {
                sum += dp[n][i][a * i];
        }
        printf("%lld", sum);
}


Measured memory_bytes: 49152
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 50000
#define INF 100000000
using namespace std;
typedef long long ll;
int t[MAX+1],c[21];
struct bags{
	int value;
	int weight;
};
vector<bags> B;
int dp[102][10002];
int main()
{	
	int n,m; 
	struct bags tian;
	cin>>n>>m;
	B.push_back(tian);
	for(int i=1;i<=n;i++)
	{
		struct bags tmp;
		cin>>tmp.value>>tmp.weight;
		B.push_back(tmp);
	}
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		dp[0][i]=0;
	}
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(j<B[i].weight)
				dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-B[i].weight]+B[i].value);
			}
		}
	cout<<dp[n][m]<<endl;
}


Measured memory_bytes: 6976
#include<iostream>

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

int main(){
    
    int n,a,b;
    cin >> n >> a >> b;

    int tmp =0;
    int res = 0;
    int ans =0;
    for(int i=1;i<=n;i++){
        res = 0;
        tmp = i;
        for(int j=1;j<=5;j++){
            res += tmp%10;
            tmp /= 10;
        }
        if( a<=res && res <=b) ans += i; 
    };


    cout << ans << endl;

    return 0;
};



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
h = [int(x) for x in input().split()]
dp = [-1 for _ in range(n)]


def rec_dp(i: int) -> int:
    global h, dp
    if i == 0:
        return 0
    if dp[i] != -1:
        return dp[i]
    res = rec_dp(i - 1) + abs(h[i] - h[i - 1])
    if i - 2 >= 0:
        res = min(rec_dp(i - 2) + abs(h[i] - h[i - 2]), res)
    dp[i] = res
    return res


print(rec_dp(n - 1))


Measured memory_bytes: 118552
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    xyh = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    xyh.sort(key=lambda x: x[2], reverse=True)
    for x in range(101):
        for y in range(101):
            b = True
            h = 0
            for i in range(n):
                xx, yy, hh = xyh[i]
                if i == 0:
                    h = hh + abs(xx - x) + abs(yy - y)
                else:
                    if hh != max(h - abs(xx - x) - abs(yy - y), 0):
                        b = False
                        break
            if b:
                print(x, y, h)
                exit()


if __name__ == '__main__':
    slove()


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<ll> H(N); REP(i, N) cin >> H[i];
  ll res = 0; ll ans = 0;
  REP(i, N - 1) {
    if(H[i] >= H[i + 1]) res++;
    else {
      if(ans < res) ans = res;
      res = 0;
    }
  }
  if(ans < res) ans = res;
  cout << ans << endl;
}


Measured memory_bytes: 3980
#include<stdio.h>
int main(){
  int n,a,b,c,cnt=0;
  scanf("%d %d %d",&a,&b,&c);
  for(n=1;n<=c;n++){
    if(c%n==0&&a<=n&&n<=b){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 2752
#include <iostream>

using namespace std;

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

	int cnt = 0;
	for (int i = 1; i <= N; i+=2){
		int x = i;
		int d_cnt = 0;
		for (int j = 1; j <= i; j++){
			if (i % j == 0){
				d_cnt++;
			}
		}
		if (d_cnt == 8){
			cnt++;
		}
	}

	cout << cnt << endl;
}

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

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

    long long int n;
    std::array<long long int, 71> arr;
    int age;

    while (std::cin >> n, n) {
        arr[10] = arr[20] = arr[30] = arr[40]
                = arr[50] = arr[60] = arr[70]
                = 0;
        for (; n--;) {
            std::cin >> age;
            age = (age > 69 ? 60 : age);
            ++arr[age + 10 - age % 10];
        }
   
        std::cout << arr[10] << "\n"
                  << arr[20] << "\n"
                  << arr[30] << "\n"
                  << arr[40] << "\n"
                  << arr[50] << "\n"
                  << arr[60] << "\n"
                  << arr[70] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1200
S, T = open(0).read().split()
m1, m2 = {}, {}
for s, t in zip(S, T):
    if s in m1:
        m1[s].add(t)
    else:
        m1[s] = set(t)
    if t in m2:
        m2[t].add(s)
    else:
        m2[t] = set(s)
for v1, v2 in zip(m1.values(), m2.values()):
    if len(v1) != 1 or len(v2) != 1:
        print('No')
        exit()
print('Yes')

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

int main()
{
	int a,b,k,k2;
	scanf("%d%d%d",&a,&b,&k);
	k2=b-k;
	for(int i=a;i<=b;i++){
		if(k){
			printf("%d\n",i);
			k--;
		}
		else if(i>k2){
			printf("%d\n",i);
		}
	}
	return 0;
 } 

Measured memory_bytes: 256
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s) for s in sum_row]))

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

struct z{
  int x;
  int y;
};

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

int h,w;
char s[27][27];

int main(){
  int i,j,k,r;
  int v[25][25];
  int d[25][25];
  int max = 0;
  char nx,ny;
  char bx,by;
  struct z queue[20000];
  int head = 0;
  int tail = 0;

  scanf("%d %d", &h, &w);

  for(i = 0;i < h;i++){
    scanf("%s", s[i]);
  }

  for(i = 0;i < h;i++){
    for(j = 0;j < w;j++){
      head = 0;
      tail = 0;
      for(k = 0;k < h;k++){
        for(r = 0;r < w;r++){
          v[k][r] = 0;
          d[k][r] = -99999;
        }
      }

      bx = i; by = j;

      if(s[bx][by] == '#') continue;

      queue[tail].x = bx;
      queue[tail].y = by;
      tail++;
      d[bx][by] = 0;
      v[bx][by] = 1;

      while(head != tail){
        bx = queue[head].x;
        by = queue[head].y;
        head++;
      for(k = 0;k < 4;k++){
        nx = bx + dx[k]; ny = by + dy[k];

        if(nx < h && ny < w && nx >= 0 && ny >= 0 && v[nx][ny] == 0 && s[nx][ny] != '#'){
          queue[tail].x = nx;
          queue[tail].y = ny;
          tail++;
          d[nx][ny] = d[bx][by] + 1;
          v[nx][ny] = 1;
        }
      }
    }

    for(k = 0;k < h;k++){
      for(r = 0;r < w;r++){
        if(d[k][r] > max) max = d[k][r];
      }
    }
    }
  }

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

  return 0;
}


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

#define endl '\n'

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

	int n, t;
	cin >> n >> t;

	vector<int> v(t + 1);

	int b, e;
	while(n--)
		cin >> b >> e, ++v[b], --v[e];

	int best = 0;
	for(int i = 0, cur = 0; i <= t; ++i)
		cur += v[i], best = max(best, cur);

	cout << best << endl;

    return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2;
	int ans;
	cin>>s1>>s2;
	for (int i=0;i<3;i++)
	{
		if (s1[i]==s2[i])
			ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int v[212345];

int main(){
    int n;
    long long resposta, total = 0;
    
    scanf("%d", &n);
    int v[n];
    
    for (int i = 0; i < n; i++){
        scanf("%d", &v[i]);
        total += v[i];
    }
    
    long long rogerio = total, mathias = 0, diferenca;
    for (int i = 0; i <= n-2; ++i){
        mathias += v[i];
        rogerio -= v[i];
        diferenca = mathias - rogerio;
        
        if (diferenca < 0)
            diferenca *= -1;
        if (i == 0 || (i != 0 && resposta > diferenca))
            resposta = diferenca;
    }
    printf("%lld\n", resposta);
    return 0;
}


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

int main()
{
  int n, m, l;
  cin >> n >> m >> l;
  vector< vector<long> > a;
  a.resize( n );
  for( int i = 0; i < n; i++ ) {
    a[ i ].resize( m );
  }

  vector< vector<long> > b;
  b.resize( m );
  for( int i = 0; i < m; i++ ) {
    b[ i ].resize( l );
  }

  for( int i = 0; i < n; i++ ) {
    for( int j = 0; j < m; j++ ) {
      cin >> a[ i ][ j ];
    }
  }

  for( int i = 0; i < m; i++ ) {
    for( int j = 0; j < l; j++ ) {
      cin >> b[ i ][ j ];
    }
  }

  for( int i = 0; i < n; i++ ) {
    for( int j = 0; j < l; j++ ) {
      long sum = 0;
      for( int k = 0; k < m; k++ ) {
        sum += a[ i ][ k ] * b[ k ][ j ];
      }
      cout << sum;
      if( j == l - 1 ) {
        cout << endl;
      }
      else {
        cout << " ";
      }
    }
  }


  return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cmath>
using namespace std;
using llong = long long;

llong n;
llong a[100005];

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

    double x = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
        x += log10((double)a[i]);
    }

    if (x > 18.5) {
        cout << -1 << endl;
    }
    else {
        llong ans = 1;
        for (int i = 0; i < n; i++) {
            ans *= a[i];
        }

        if (ans > (llong)(1e18)) cout << -1 << endl;
        else cout << ans << endl;
    }

}

Measured memory_bytes: 4780
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long int LL;
const int maxn=101000;
int main()
{
    int K,A,B;
    scanf("%d%d%d",&K,&A,&B);
    for(int i=A;i<=B;i++)
    {
        if(i%K==0)
        {
            printf("OK\n");
            return 0;
        }
    }
    printf("NG\n");
    return 0;
}

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

int main() {

  long long int n;
  cin >> n;

  vector< long long int > v;

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

    long long int in;
    cin >> in;
    v.push_back( in );

  }

  bool f[10000] = {};

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

    long long int cnt = 0;

    for ( long long int j = 0; j < 4; j++ ) {

      long long int k = i + j;
      if ( k >= n ) break;
      cnt = cnt * 10 + v[k];
      f[cnt] = true;

    }

  }

  for ( long long int i = 0;; i++ ) {

    if ( f[i] == false ) {
      cout << i << endl;
      return 0;
    }

  }

  return 0;

}

Measured memory_bytes: 1236
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
from collections import Counter
C = Counter(a)
total = sum(a)
for _ in range(q):
    b, c = map(int, input().split())
    C[c] += C[b]
    total += c*C[b]
    total -= b*C[b]
    C[b] = 0
    print(total)



Measured memory_bytes: 89504
#include <stdio.h>

int main(void)
{
	int r,d,x;
	
	scanf("%d %d %d",&r,&d,&x);
	
	int ans[11]={};
	
	ans[0] = x;
	
	int i;
	
	for(i = 1;i < 11; i++){
		ans[i] = r*ans[i-1] - d;
	}
	
	for(i = 1;i < 11; i++){
		printf("%d\n",ans[i]);
	}
	
	return 0;
	
}

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ull x=100,n,ans=0;
    cin>>n;
    while(x<n){
        ull y=x/100;
        x+=y;
        ans++;
    }
    cout<<ans el;
}

main()
{
     fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


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

using namespace std;

int N, v[110], count = 0;

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

    for(int i = 0; i < N; i++) {
        int min = i;
        for(int j = i; j < N; j++) {
            if(v[j] < v[min]) min = j;
        }
        if(min != i) {
            swap(v[i], v[min]);
            ::count += 1;
        }
    }
    for(int i = 0; i < N; i++) {
        if(i == N - 1) {
            cout << v[i] << endl;
        } else {
            cout << v[i] << " ";
        }
    }
    cout << ::count << endl;
    return 0;
}

Measured memory_bytes: 0
from sys import stdin
from string import ascii_lowercase


def myfind(s, c):
    result = []
    for i, x in enumerate(s):
        if x == c:
            result.append(i)
    return result


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = []
    for x in ascii_lowercase:
        idxs = myfind(s, x)
        if not idxs:
            continue
        result.append(x)
        if len(result) >= K:
            break
        temp = sorted(list(set([s[x:] for x in idxs])))
        for y in temp:
            for z in range(len(y)):
                foo = y[: z + 1]
                if not foo in result:
                    result.append(foo)
                    if len(result) >= K:
                        break
            if len(result) >= K:
                break
        if len(result) >= K:
            break

    print(result[-1])


if __name__ == '__main__':
    main()


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

#define lli long long int
#define mpr make_pair
#define pr pair<lli,lli>
#define pb push_back
#define vl vector<lli>
#define mp map<lli,lli>
#define all(x) x.begin(),x.end()
#define FOR(i,n) for(lli i=0;i<(lli)n;i++)
#define FOR1(i,j,n) for(lli i=j;i<(lli)n;i++)
#define mod 1000000007

lli power(lli x,lli n,lli m)
{
	lli res=1;
	while(n>0)
	{
		if(n&1) res=(res*x)%m;
		x=(x*x)%m;
		n=n>>1;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli n;
    cin>>n;
    string s;
    while(n>0)
	{
		lli k=(n-1+26)%26;
		n/=26;
		//if(k>0)
		s=(char)(k+'a')+s;
		if(k==25)
		n--;
		/*else
		s='z'+s;*/
		//n--;
	}
	cout<<s<<endl;
	
	
	
return 0;
}


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

int main()
{
	int n;
	long W;
	cin >> n >> W;
	long w[110];
	int v[110];
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	long dp[100010];
	for (int i = 0; i <= sum; i++)
	{
		dp[i] = 1 << 30;
	}
	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = sum; j >= 0; j--)
		{
			if (v[i] <= j)
			{
				dp[j] = min(dp[j - v[i]] + w[i], dp[j]);
			}
		}
	}
	for (int i = sum; i >= 0; i--)
	{
		if (dp[i] <= W)
		{
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 1024