akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int n, a[100];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);

  cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cout << a[i] << (i != n-1 ? " " : "\n");
	}

	for (int i = 1; i < n; i++) {
		int v = a[i];
		int j = i -1;
		while (j >= 0 and a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;

		for (int k = 0; k < n; k++) {
			cout << a[k] << (k != n-1 ? " " : "\n");
		}
	}
  return 0;
}





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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

template <ll mod>
class modint
{
public:
    constexpr modint(ll value = 0) : _value(value >= 0 ? value % mod : (value % mod) + mod) {}

    constexpr modint operator+() const { return *this; }
    constexpr modint operator-() const { return modint(-_value); }

    constexpr modint &operator+=(const modint &rhs) {
        if ((_value += rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
        if ((_value += mod - rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
        (_value *= rhs._value) %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
        *this *= rhs.inv();
        return *this;
    }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }

    constexpr modint operator++() { *this += 1; return *this; }
    constexpr modint operator--() { *this -= 1; return *this; }
    constexpr modint operator++(int) { modint tmp = *this; ++*this; return tmp; }
    constexpr modint operator--(int) { modint tmp = *this; --*this; return tmp; }

    constexpr bool operator==(const modint &rhs) const { return _value == rhs._value; }
    constexpr bool operator!=(const modint &rhs) const { return _value != rhs._value; }

    constexpr modint inv() const {
        ll a = _value, b = mod, u = 1LL, v = 0LL;
        while (b > 0) {
            ll tmp = a / b;
            a -= tmp * b; swap(a, b);
            u -= tmp * v; swap(u, v);
        }
        return modint(u);
    }

    constexpr modint pow(ll n) const {
        modint e = *this, res = 1;
        while (n) {
            if (n & 1) res *= e;
            e *= e, n >>= 1;
        }
        return res;
    }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m._value;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }

private:
    ll _value;
};
using mint = modint<1000000007>;

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

    int n; cin >> n;
    mint ans = mint(10).pow(n);
    ans -= mint(9).pow(n) * 2;
    ans += mint(8).pow(n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

using namespace std;
using  ull = unsigned long long int;

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


int main() {
	
	ull n,cnt=0;
	cin >> n;

	vector<ull>num(n);

	rep(i, 0, n)cin >> num[i];

	bool flag = false;
	ull here = 0;

	while (cnt < 1000000 && !flag) {

		here = num[here] - 1;
		if (here == 1)flag = true;

		cnt++;
	}
	
	
	if(cnt<1000000 && flag)cout << cnt << endl;
	else cout << "-1" << endl;


	return 0;
}

Measured memory_bytes: 1024
a =input()
a = [str(c) for c in a]
b =input()
b = [str(c) for c in b]

c=len(b)
t=0
for i in range(0,c+3):
	a.append(a[0])
	del a[0]
	if a==b:
		t=1
		
if t==1:
	print('Yes')
else:
	print('No')

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int> t(N + 1), x(N + 1), y(N + 1);
    for (int i = 1; i < N + 1; i++)
        cin >> t[i] >> x[i] >> y[i];
    bool z = true;
    for (int i = 0; i < N; i++)
    {
        int dt = t[i + 1] - t[i];
        int dl = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
        if (dt % 2 != dl % 2 || dl > dt)
            z = false;
    }
    cout << (z ? "Yes" : "No");
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

class dice{
public: 
		int surface[6];
	void setsurface(int a,int b,int c,int d,int e,int f){
		surface[0] = a;
		surface[1] = b;
		surface[2] = c;
		surface[3] = d;
		surface[4] = e;
		surface[5] = f;
	}
	void load(){
		cout << surface[0] << endl;
	}
	void roll(char d){
		int n;
		if(d == 'E'){
			n = surface[5];
			surface[5] = surface[2];
			surface[2] = surface[0];
			surface[0] = surface[3];
			surface[3] = n;
		}
		if(d == 'W'){
			n = surface[3];
			surface[3] = surface[0];
			surface[0] = surface[2];
			surface[2] = surface[5];
			surface[5] = n;
		}
		if(d == 'N'){
			n = surface[4];
			surface[4] = surface[0];
			surface[0] = surface[1];
			surface[1] = surface[5];
			surface[5] = n;
		}
		if(d == 'S'){
			n = surface[5];
			surface[5] = surface[1];
			surface[1] = surface[0];
			surface[0] = surface[4];
			surface[4] = n;
		}
	}
	void loade(){
		cout << surface[2] << endl;
	}
	void spinr(){
		int n;
		n = surface[3];
		surface[3] = surface[1];
		surface[1] = surface[2];
		surface[2] = surface[4];
		surface[4] = n;
	}
	void setup(int n){
		if(surface[0] != n){
			for (int i = 0; i < 3; ++i)
			{
				this->roll('E');
				if(surface[0] == n)break;
			}
			if(surface[0] != n){
				for (int i = 0; i < 3; ++i){
					this->roll('N');
					if(surface[0] == n)break;
				}
			}
		}
	}
	void setfront(int n){
		if(surface[1] != n){
			for (int i = 0; i < 3; ++i){
				this->spinr();
				if(surface[1] == n)break;
			}
		}
	}
};

int main(){
	dice dice1;
	int n[6];
	int m = 0;
	int x[2][24] = {0};
	for (int i = 0; i < 6; ++i)
	{
		cin >> n[i];
	}
	dice1.setsurface(n[0],n[1],n[2],n[3],n[4],n[5]);
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x[0][i] >> x[1][i];
	}
	for(int i = 0; i < m; i++){
		dice1.setup(x[0][i]);
		dice1.setfront(x[1][i]);
		dice1.loade();
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
const int m=200005;

int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
   if(x==ans+1) ans++;
  }
  if(ans==0) {cout<<-1<<endl; return 0;}
  cout<<n-ans<<endl;
}
 

Measured memory_bytes: 384
# your code goes here# your code goes hereimport sys
import sys
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[]
for i in range(N):
    b.append(int(input()))


for i in range(3):
    for j in range(3):
        for x in range(N):
            if A[i][j]==b[x]:
                A[i][j]=0

for i in range(3):
    if A[i][0]==0 and A[i][1]==0 and A[i][2]==0:
        print("Yes")
        sys.exit(0)
for i in range(3):
    if A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
        print("Yes")
        sys.exit(0)
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    print("Yes")
    sys.exit(0)
if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
    print("Yes")
    sys.exit(0)
print("No")
# your code goes here

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

int main(){
  ios::sync_with_stdio(false);
  int a[200500];
  int max=0, sMax=0;
  int n, num;
  cin >> n;

  for(int i=0; i<n; i++){
    cin >> num;
    if(num > max){
      max = num;
    }else if(num > sMax){
      sMax = num;
    }
    a[i] = num;
  }

  for(int i=0; i<n; i++){
    if(a[i] == max)
      cout << sMax << endl;
    else
      cout << max << endl;
  }
  return 0;
}


Measured memory_bytes: 2432
def solve(N, K, x):
  ans = 10**20
  for i in range(N-K+1):
    if x[i]>=0:
      ans = min(ans, x[i+K-1])
    elif x[i+K-1]>0:
      ans = min(ans, -x[i]*2+x[i+K-1])
    else:
      ans = min(ans, -x[i])
  return ans

N,K = map(int, raw_input().split())
x = map(int, raw_input().split())
print min(solve(N,K,x), solve(N,K,[-t for t in x[::-1]]))


Measured memory_bytes: 11344
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
   int n,i;
   int dice0,dice1,dice2;
   string m;
   int ans;

   for(;;){
      cin>>n;
      if(n==0) break;
      
      ans=1;dice0=1,dice1=2,dice2=3;
      for(i=0;i<n;i++){
         cin>>m;
      
         if(m=="North"){
            ans+=dice1;
            dice0=7-dice0;
            swap(dice0,dice1);
         }
         else if(m=="East"){
            ans+=7-dice2;
            dice2=7-dice2;
            swap(dice0,dice2);
         }
         else if(m=="South"){
            ans+=7-dice1;
            dice1=7-dice1;
            swap(dice0,dice1);
         }
         else if(m=="West"){
            ans+=dice2;
            dice0=7-dice0;
            swap(dice0,dice2);
         }  
         else if(m=="Right"){
            ans+=dice0;
            dice1=7-dice1;
            swap(dice1,dice2);
         }
         else if(m=="Left"){
            ans+=dice0;
            dice2=7-dice2;
            swap(dice1,dice2);
         }
      }
      printf("%d\n",ans);
   }
   return 0;
}

Measured memory_bytes: 0
using System;

namespace abc143B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] d = new int[N];
            string[] str = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                d[i] = int.Parse(str[i]);
            }
            int A = 0;
            for (int k = 0; k<N-1; k++)
            {
                for(int m = k+1; m<N; m++)
                {
                    A = A + (d[k] * d[m]);
                }
            }
            Console.WriteLine(A);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, bool> Link;
typedef vector<vector<Link> > Graph;

int main () {
    int V, E, r;
    cin >> V >> E >> r;
    Graph g(V, vector<Link>(V));

    // Set identity to 0
    for(int i=0; i<V; i++)
        g[i][i] = make_pair(0, true);

    // Set known edges
    for(int i=0; i<E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s][t] = make_pair(d, true);
    }

    // Run Floyd-Warshall algorithm
    for(int k=0; k<V; k++)
        for(int i=0; i<V; i++)
            for(int j=0; j<V; j++)
                if (
                        (g[i][k].second && g[k][j].second) &&
                        (!g[i][j].second || g[i][j].first > g[i][k].first + g[k][j].first))
                    g[i][j] = make_pair(g[i][k].first + g[k][j].first, true);

    // Check if any cycle
    for(int i=0; i<V; i++)
        if (g[r][i].second && g[i][i].first < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }

    // Print output
    for(int i=0; i<V; i++)
        if (g[r][i].second)
            cout << g[r][i].first << endl;
        else
            cout << "INF" << endl;
}



Measured memory_bytes: 10664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    double ans = 0;
    rep(i,n){
        double x;
        string u;
        cin >> x >> u;
        if (u == "BTC") ans += x * 380000;
        else ans+= x;
    }
    cout << ans << endl;
    return 0;
}

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

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll h, w;
  cin >> h >> w;

  if((h % 3) * (w % 3) == 0){
    cout << 0 << endl;
    return 0;
  }

  ll a, b, c, mx, mn, dif = 1e10;

  FOR(i, 1, h){
    a = i * w;
    b = (w / 2) * (h - i);
    c = (w - w / 2) * (h - i);
    mx = max(max(a, b), c);
    mn = min(min(a, b), c);
    dif = min(dif, mx - mn);
  }

  FOR(i, 1, w){
    a = i * h;
    b = (h / 2) * (w - i);
    c = (h - h / 2) * (w - i);
    mx = max(max(a, b), c);
    mn = min(min(a, b), c);
    dif = min(dif, mx - mn);
  }

  cout << min(min(h, w), dif) << endl;
}


Measured memory_bytes: 256
import Data.Bool (bool)

main :: IO ()
main = do
    n  <- read <$> getLine
    xs <- fmap read . words <$> getLine
    answer $ solve n xs

type Answer = Int
answer :: Answer -> IO ()
answer = print

solve :: Int -> [Int] -> Int
solve n = bin 2 (2 * n - 2)
  where
    bin l g
      | l == g    = const g
      | r == 1    = bool l g . gte g
      | otherwise = bool . bin l (m - 1) <*> bin m g <*> gte m
      where
        r = g - l
        m = l + r `div` 2
    gte x = go . foldr ((:) . (x <=)) []
    go (x : y : xs)
      | x == y    = left   2 x y $ zip [3 ..] xs
      | otherwise = left   0 x y $ zip [3 ..] xs
    left   l w z xs@((i, x) : xs')
      | i >= n    = middle l w z xs
      | z /= x    = left   l w x xs'
      | otherwise = left   i x x xs'
    middle l w z xs@((i, x) : xs')
      | i >  n    = right  m w z xs
      | z /= x    = right  m w x xs'
      | otherwise = x
      where
        m = 2 * n - l
    right m w z [(i, x)]
      | z /= x    = w
      | otherwise = x
    right m w z ((i, x) : xs)
      | i >  m    = w
      | z /= x    = right m w x xs
      | otherwise = x

valid :: Int -> [Int] -> Bool
valid k = go
  where
    median (x, y, z)
      | max x (min y z) == x && min x (max y z) == x = x
      | max y (min z x) == y && min y (max z x) == y = y
      | max z (min x y) == z && min z (max x y) == z = z
    inner (x : y : z : xs) = median (x, y, z) : inner (y : z : xs)
    inner               _  = []
    go [x] = x == k
    go  xs = go $ inner xs


Measured memory_bytes: 84348
#include <iostream>
using namespace std;
 
int main(){
  int a; cin >> a;
  int b; cin >> b;
  int k;
  
  if( (a + b) % 2 == 0){
    k = (a + b) / 2;
    cout << k << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

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


Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	String S = sc.next();
      	
      	int cnt = 0;
      	for(int i=0; i< 1000;  i++){
        	if(pinMatch(i,S)){
            	cnt++;
            }
        }
      	System.out.println(cnt);
        return;
	}
 	public static boolean pinMatch(int pin_int, String str){
      	String pin = String.valueOf(pin_int);
      	if (pin_int<100){
        	pin = "0" + String.valueOf(pin_int);
        }
      	if (pin_int<10){
        	pin = "00" + String.valueOf(pin_int);
        }

      	int str_len = str.length();
      	int pointer = 0;
      	for(int i = 0; i < str_len; i++){
          if(pin.charAt(pointer)==str.charAt(i)){
            pointer++;
          }
          if(pointer==3){
            return true;
          }
        }
		return false;
	}
}


Measured memory_bytes: 24228
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n; scanf("%d", &n);
	
	printf("%d\n", n * n * n);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n,m,ans;
int f[3010][3010][2];
int mod=1e9+7;
int plu(int &a,int b)
{
	a+=b;
	if (a>=mod) a-=mod;
}
int main()
{
	scanf("%d%d",&m,&n);
	for (int i=0;i<=m;i++)
		f[0][i][0]=1; 
	for (int i=1;i<=n;i++)
		for (int j=0;j<=m;j++)
		{
			int k=m-j;
			if (j)
			{
				plu(f[i][j][1],f[i-1][j][1]);
				plu(f[i][j][1],f[i-1][j-1][1]);
				if (j==1)
				{
					plu(f[i][j][1],f[i-1][j][0]);
					plu(f[i][j][1],f[i-1][j-1][0]);
				}
				else
				{
					plu(f[i][j][0],f[i-1][j][0]);
					plu(f[i][j][0],f[i-1][j-1][0]);
				}
			}
			if (k)
			{
				plu(f[i][j][1],f[i-1][j][1]);
				plu(f[i][j][1],f[i-1][j+1][1]);
				if (j==0)
				{
					plu(f[i][j][1],f[i-1][j][0]);
					plu(f[i][j][1],f[i-1][j+1][0]);
				}
				else
				{
					plu(f[i][j][0],f[i-1][j][0]);
					plu(f[i][j][0],f[i-1][j+1][0]);
				}	
			}
		}
	for (int i=0;i<=m;i++)
		plu(ans,f[n][i][1]);
	printf("%d",ans);
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if ((a - x) * (a - x) > (b - x) * (b - x)) {
    cout << 'B' << endl;
  }
  else {
    cout << 'A' << endl;
  }
}

Measured memory_bytes: 256
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i]=map(int,input().split())

l=L[0]
r=R[0]

for i in range(1,M):
    if L[i]>l:
        l=L[i]
    if R[i]<r:
        r=R[i]
    if r-l < 0:
        print(0)
        exit()
print(r+1-l)

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


void solve(long long N, long long M, vector<long long> A, vector<long long> B){
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	bool runnable=true;
	for (int i = 0; i<N-1; i++) {
		if (A[i] == A[i+1]) runnable = false;
	}
	for (int i = 0; i<M-1; i++) {
		if (B[i] == B[i+1]) runnable = false;
	}

	long long res = 1;
	for (int i = N*M; i>0; i--) {
		long long aCount = upper_bound(A.begin(),A.end(),i) - lower_bound(A.begin(),A.end(),i);
		long long bCount = upper_bound(B.begin(),B.end(),i) - lower_bound(B.begin(),B.end(),i);
		if (aCount != 0 && bCount != 0) {
		} else if (aCount != 0) {
			res *= B.end() - upper_bound(B.begin(),B.end(),i);
			res %= 1000000007;
		} else if (bCount != 0) {
			res *= A.end() - upper_bound(A.begin(),A.end(),i);
			res %= 1000000007;
		} else {
			//cout << ( N - (upper_bound(A.begin(),A.end(),i) - A.begin()))*(M - (upper_bound(B.begin(),B.end(),i) - B.begin()))-(N*M-i) << "\n";
			res *= ( N - (upper_bound(A.begin(),A.end(),i) - A.begin()))*(M - (upper_bound(B.begin(),B.end(),i) - B.begin()))-(N*M-i);
			res %= 1000000007;
		}
	}
	if (runnable) {
		cout << res << "\n";
	} else {
		cout << "0\n";
	}
}

int main(){
	long long M;
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	scanf("%lld",&M);
	vector<long long> B(M-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&B[i]);
	}
	solve(N, M, A, B);
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N; cin >> N;
    string S[60];
    string X;
    ll cnt[60];
    cnt[0] = 0;
    for (int i = 0; i < N; i++) {
        ll c;
        cin >> S[i] >> c;
        cnt[i+1] = cnt[i] + c;
    }
    cin >> X;
    for (int i = 0; i < N; i++) {
        if(S[i] == X){
            cout << cnt[N] - cnt[i+1] << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 999;// 1e25;
static const ll MAX_N = 100001;

ll a[100001] = {};
int  main() {
	ll n, k; cin >> n >> k;
	rep(i, 0, n)cin >> a[i];

	ll ans = 0;
	rep_re(i, -1, 40) {
		if (i != -1 && !(k & (1LL << i))) continue;//skip value over k

		ll tmp = 0;
		rep_re(j, 0, 40) {
			ll mask = 1LL << j;
			ll num = 0;
			rep(i, 0, n)if (a[i] & mask) num++; //the number of 1

			if (j > i) {
				if (k & mask) tmp += mask * (n - num);//the number of 0
				else tmp += mask * num;//the number of 1
			}
			else if (j == i) {
				tmp += mask * num;
			}
			else {
				tmp += mask * max(num, n - num);
			}
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int c=0,n,d,x[11][11];cin>>n>>d;
	for(int i=0;i<n;i++)for(int j=0;j<d;j++)cin>>x[i][j];
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)
	{
		int y=0;
		for(int k=0;k<d;k++)y+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
		if((int)sqrt(y)==sqrt(y))c++;
	}
	cout<<c<<endl;
	return 0;
}

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

int main()
{

    int n, m, l, r;
    int lmax, rmin;

    cin >> n >> m;
    lmax = 1;
    rmin = n;

    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        if(lmax < l){
            lmax = l;
        }
        if(rmin > r){
            rmin = r;
        }
    }
    if(rmin-lmax+1 > 0){
        cout << rmin-lmax+1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0,d,p,q,r,s;
    cin>>a;
    b=a/500;
    d=a-(500*b);
    p=d/5;


         cout<<(b*1000)+(p*5)<<endl;
}


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

int main() {
  int N;
  cin>>N;
  char P;
  int M;
  vector<vector<int> > C(4,vector<int>(13));

  while(cin>>P&&cin>>M){
    if(P=='S'){C.at(0).at(M-1)=M;}
    else if(P=='H'){C.at(1).at(M-1)=M;}
    else if(P=='C'){C.at(2).at(M-1)=M;}
    else if(P=='D'){C.at(3).at(M-1)=M;}
  }
 
  for(int i=0;i<4;i++){
   for(int j=0;j<13;j++){
      if(i==0&&C.at(i).at(j)==0){cout<<'S'<<" "<<j+1<<endl;}
      else if(i==1&&C.at(i).at(j)==0){cout<<'H'<<" "<<j+1<<endl;}
      else if(i==2&&C.at(2).at(j)==0){cout<<'C'<<" "<<j+1<<endl;}
      else if(i==3&&C.at(3).at(j)==0){cout<<'D'<<" "<<j+1<<endl;}
     }   
 }

  return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define ll long long
const int maxn = 100000 + 100;
using namespace std;
ll n,k,t;


int main()
{
  cin>>n>>k;
  if(k==0){ cout<<n;return 0;}
  if(k>n) { cout<<min(k-n,n); return 0 ;  }
  t = n%k;
  cout<< min(t,k-t) ;
    /*
 std::ios::sync_with_stdio(false);
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);*/


return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n,i;

  for(;;){
    scanf("%d",&n);
    if(n==0)break;

    int point[100]={0};

    for(i=0;i<n;i++)
      scanf("%d",&point[i]);

    int max=0,min=1000,maxnum,minnum;

    for(i=0;i<n;i++){
      if(max<=point[i]){
        maxnum=i;
        max=point[i];
      }
      if(min>=point[i]){
        minnum=i;
        min=point[i];
      }
    }

    point[minnum]=0;
    point[maxnum]=0;
    
    int sum=0;
    for(i=0;i<n;i++)
      sum+=point[i];

    printf("%d\n",sum/(n-2));
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> P;

const int INF = 100000000;

int G[10][10];
bool used[10][10];
int n, m;
int ans;
vector<int> ans2;
vector<int> path;

bool check(){
  long long a = 0;
  for(int i=0;i<ans2.size();i++){
    a = a*10 + ans2[i];
  }
  long long b = 0;
  for(int i=0;i<path.size();i++){
    b = b*10 + path[i];
  }
  return a <= b;
}

void dfs(int p, int c){
  path.push_back(p+1);
  if(c == ans){
    if(!check()){
      ans2 = path;
    }
  }else if(c > ans){
    ans2 = path;
    ans = c;
  }
  for(int i=0;i<n;i++){
    if(G[p][i] == INF) continue;
    if(used[p][i]) continue;
    used[p][i] = used[i][p] = true;
    dfs(i, c+G[p][i]);
    used[p][i] = used[i][p] = false;
  }
  path.pop_back();
}

main(){
  while(cin >> n >> m && (n|m)){
    fill(G[0], G[10], INF);
    ans2.clear();
    ans = -1;
    for(int i=0;i<m;i++){
      int a, b, c;
      cin >> a >> b >> c;
      a--;
      b--;
      G[a][b] = G[b][a] = c;
    }
    for(int i=0;i<n;i++){
      path.clear();
      fill(used[0], used[10], false);
      dfs(i, 0);
    }
    cout << ans << endl;
    if(ans2.size() > 0){
      cout << ans2[0];
      for(int i=1;i<ans2.size();i++){
        cout << ' ' << ans2[i];
      }
    }
    cout << endl;
  }
}

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



int main() {
	int i, j, k, l;
	int	n, m, h, g, r;
	int f = 0;
	int d;



	scanf("%d %d", &m, &d);

	if (d < 11) {
		f = 0;
		goto end;
	}
	
	for (i = 1;i < m+1;i++) {
		for (j = 2;j<10;j++) {
			for (k = 2;k<10;k++) {
				if (j * 10 + k > d) {
					break;
				}

				if ((j*k) == i) {
					f = f + 1;
				}
			}
		}
	}


	end:
	printf("%d", f);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int,pi> pp;
#define p(x,y,z) pp(x,pi(y,z))
const int maxn = 55;
const int maxv = 5050;

struct edge {
	int v, cost, t;
};

int dp[maxn][maxv];
int n,m,silver;
bool visited[maxn];
int co = 0;

pi shop[maxn];

vector <edge> adjlist[maxn];

int32_t main() {
	FAST
	cin >> n >> m >> silver;
	silver = min(silver, maxv-45);
	for (int i =0;i<m;i++) {
		int a,b,cost,t; cin >> a >> b >> cost >> t;
		adjlist[a].push_back({b,cost,t});
		adjlist[b].push_back({a,cost,t});
	}
	
	for (int i =1;i<=n;i++) {
		cin >> shop[i].f >> shop[i].s;
		shop[i].f =  min(shop[i].f, maxv-45);
	}
	
	memset(dp,-1,sizeof dp);
	priority_queue <pp,vector<pp>,greater<pp>> pq;
	pq.push(p(0,1,silver));
	dp[1][silver] = 0;
	
	while (!pq.empty()) {
		pp cur = pq.top(); pq.pop();
		int curt = cur.f, x = cur.s.f, s = cur.s.s;
		if (dp[x][s] != curt) continue;
		if (!visited[x]) {
			visited[x] = 1;
			co++;
		}
		if (co == n) break;
		//cout << x << " " << s << " " << curt << "\n";
		
		for (int i = 0; s + shop[x].f * i < maxv; i++) {
			int newsilver = s + shop[x].f * i;
			int newt = curt + shop[x].s * i;
			
			for (auto vv: adjlist[x]) {
				int ss = newsilver - vv.cost;
				if (ss < 0) continue;
				int tt = newt + vv.t;
				int v = vv.v;

				if (dp[v][ss] == -1 or tt < dp[v][ss]) {
					dp[v][ss] = tt;
					pq.push(p(tt,v,ss));
				}
			}	
		}	
	}
	
	//cout << "ENDED\n";
	
	for (int i =2;i<=n;i++) {
		int ans = LLONG_MAX/2;
		for (int j =0; j < maxv; j++) {
			if (dp[i][j] == -1) continue;
			ans = min(ans,dp[i][j]);
		}
		cout << ans << "\n";
	}
	
}




Measured memory_bytes: 103872
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  ll sum = 0;
  ll res1 = 0, res2 = 0;
  cin>>n;
  vector<int> a(n);
  for(int i=1;i<=n;i++){
    cin>>a[i-1];
    a[i-1]-=i;
  }
  sort(a.begin(),a.end());
  int b1=a[n/2];
  int b2=a[n/2-1]; 
  for(int i=1;i<=n;i++){
    res1+=abs(a[i-1]-b1);
    res2+=abs(a[i-1]-b2);
  }
  cout<<(res1>res2?res2:res1)<<endl;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
l,r = 0,0
ans = 0
s = 0
while l < n:
  if r < n and s+a[r] == s^a[r]:
    s += a[r]
    r += 1
    #print(s)
  else:
    ans += r-l
    s -= a[l]
    #print(s)
    l += 1
    
print(ans)

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

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

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

  for (ll a=1; a<=3500; a++) {
    for (ll b=1; b<=3500; b++) {
      ll x = n * a * b;
      ll y = 4*a*b - n*a - n*b;
      if (y>0 && x%y==0) {
        printf("%lld %lld %lld\n", a, b, x/y);
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
ll ar[1000000];
int main()
{
    ll n;

  cin>>n;
  for(ll i=0;i<n;i++)
    cin>>ar[i];
    ll ans=0;
    ll  ma=ar[0];
   for(ll i=0;i<n;i++)
      {
          ma=max(ma,ar[i]);
          if((ar[i])-ma<0)
          {
              ans+=abs(ma-ar[i]);
          }
      }
      cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5148
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
int ans = 0;

void bfs(char **tile, int w, int h){
  ans++;
  tile[w][h] = '#';

  if(tile[w][h-1] == '.')
  bfs(tile, w, h-1);

  if(tile[w][h+1] == '.')
  bfs(tile, w, h+1);

  if(tile[w-1][h] == '.')
  bfs(tile, w-1, h);

  if(tile[w+1][h] == '.')
  bfs(tile, w+1, h);

  return;
}


int main(){
  int W,H,index_w,index_h;

  while(true){
    cin >> W >> H;
    if(W == 0 && H == 0) break;

    char **tile;
    tile = new char* [H+2];
    REP(i,H+2) tile[i] = new char[W+2];

    REP(i,H+2){
      REP(j,W+2){
        if(i == 0 || i == H+1 || j == 0 || j == W+1) tile[i][j] = '#'; //sentry?
        else scanf(" %c",&tile[i][j]);

        if(tile[i][j] == '@') {
          index_h = j;
          index_w = i;
        }

      }
    }
    ans = 0;
    bfs(tile,index_w,index_h);
    
    REP(i,H) delete[] tile[i];
    delete[] tile;
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1268
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();

        if(S.contains("a") && S.contains("b") && S.contains("c")){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}
 

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define int long long int
int gcd(int a,int b){
	return b==0 ? a : gcd(b,a%b);
}


int32_t main(){
    
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int t=1;
	// cin>>t;
	while(t--){
		int n;
		cin>>n;
		int d[n][2];
		for(int i=0;i<n;i++) cin>>d[i][0]>>d[i][1];
			int flag = 0;
		for(int i=2;i<n;i++){
			if(d[i][1]==d[i][0]&&d[i-1][1]==d[i-1][0]&&d[i-2][1]==d[i-2][0]){
				flag = 1;
				break;
			}
		}
		cout<<(flag?"Yes":"No");
	}	
}
    



Measured memory_bytes: 3632
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	var money float64
	for i := 0; i < N; i++ {
		var temp float64
		fmt.Scan(&temp)
		var BTC string
		fmt.Scan(&BTC)
		if BTC == "BTC" {
			temp *= 380000
		}
		money += temp
	}
	fmt.Println(money)
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	LL n;cin>>n;
	for(LL r=sqrt(n);r>=1;r--){
		if(n%r==0){
			cout<<r+n/r-2<<endl;
			return 0;
		}
	}
	return 0;
}


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

#define N 4

int goal[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0};

int adjacent[16][4] = {
	{1, 4, -1, -1},
	{0, 2, 5, -1},
	{1, 3, 6, -1},
	{2, 7, -1, -1},
	{0, 5, 8, -1},
	{1, 4, 6, 9},
	{2, 5, 7, 10},
	{3, 6, 11, -1},
	{4, 9, 12, -1},
	{5, 8, 10, 13},
	{6, 9, 11, 14},
	{7, 10, 15, -1},
	{8, 13, -1, -1},
	{9, 12, 14, -1},
	{10, 13, 15, -1},
	{11, 14, -1, -1},
};

int dist[16][16] = {
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6},
	{1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5},
	{2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4},
	{3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3},
	{1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5},
	{2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4},
	{3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3},
	{4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2},
	{2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4},
	{3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3},
	{4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2},
	{5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1},
	{3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3},
	{4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2},
	{5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1}
};

int board[16];

void print_board(){
	for(int i=0; i < N ; i++){
		for(int j=0 ; j < N ; j++) cout << board[i*N+j] << ", ";
	}
	cout << endl;
}

int calc_heuristic(){
	int dis_sum = 0;
	int x = 0;
	for(int i=0 ; i < 16 ; i++ ){
		x = board[i];
		if(x != 0) dis_sum += dist[x][i];
	}
	return dis_sum;
}

bool flag = true;

void ida_search(int limit, int step, int space, int prev_m){
	if(flag){
		step++;

		int adj, h;
		for(int i=0 ; i < 4 ; i++){
			adj = adjacent[space][i];
			if(adj == -1) break;
			if(board[adj] == prev_m) continue;

			board[space] = board[adj];
			board[adj] = 0;
			h = calc_heuristic();
			if(h == 0){
				cout << step << endl;
				flag = false;
			}
			else if(h + step < limit) ida_search(limit, step, adj, board[space]);
			board[adj] = board[space];
			board[space] = 0;
		}
	}
}


int main(void){

	int init_space = 0;

	int in_raw[4];
	for(int i=0 ; i < N ; i++){
		cin >> in_raw[0] >> in_raw[1] >> in_raw[2] >> in_raw[3];

		for(int j=0 ; j < N ; j++){ 
			board[i*N+j] = in_raw[j];
			if(in_raw[j] == 0) init_space = i*N + j;
		}

	}

	int limit = calc_heuristic();
	if(limit == 0){
		cout << 0 << endl;
		flag = false;
	}

	while(flag){
		ida_search(limit, 0, init_space, -1);
		limit += 2;
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll a,b;

int main(){
	cin >> a >> b;
	ll ans = 0;
	rep(k,50){
		ll ca = (a-1)/(1LL << (k+1))*(1LL << k) + max((ll)0,(a-1)%(1LL << (k+1)) - ((1LL << k) - 1));
		if(a == 0)ca = 0;
		ll cb = b/(1LL << (k+1))*(1LL << k) + max((ll)0,b%(1LL << (k+1)) - ((1LL << k) - 1));
		// cout << k << " " << cb << " " << ca << endl;
		if((cb - ca) % 2)ans += (1LL << k);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  int dig;
  int sum = 0;
  
  scanf("%d", &n);
  
  while(n != 0){
    dig = n % 10;
    sum += dig;
    n /= 10;
  }

  if( sum == 1) printf("10\n");
  else          printf("%d\n",sum);

  return 0;
}
  

Measured memory_bytes: 128
import java.util.*;

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

    int W = sc.nextInt();
    int H = sc.nextInt();
    int N = sc.nextInt();

    int x = 0, y = 0, a = 0;
    int x1 = 0, y1 = 0, x2 = W, y2 = H;
    
    for (int i = 0; i < N; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      a = sc.nextInt();

      if (a == 1) {
        x1 = Math.max(x1, x);
      } else if (a == 2) {
        x2 = Math.min(x2, x);
      } else if (a == 3) {
        y1 = Math.max(y1, y);
      } else {
        y2 = Math.min(y2, y);
      }
      // System.out.println("x1:" + x1 + " y1:" + y1 + " x2:" + x2 + " y2:" + y2);
    }

    System.out.println(Math.max((x2 - x1), 0) * Math.max((y2 - y1), 0));
    
  }
}

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

int dp[20000];

int rec(int x,int K){
	if(dp[x]!=-1)return dp[x];
	if(x==0)return 0;
	set<int>se;
	for(int i=1;i<=x/K;i++){
		se.insert(rec(x-i,K));
	}
	int c=0;
	while(se.count(c))c++;
	return dp[x]=c;
}

int grundy(int x,int K){
	if(K==1)return x;
	while(1){
		if(x%K==0)return x/K;
		int a=x/K+1;
		int d=x-x/K*K;
		x-=((d+a-1)/a)*a;
	}
}

int main(){
	int n;cin>>n;
	int x=0;
	rep(i,n){
		int a,K;scanf("%d%d",&a,&K);
		x^=grundy(a,K);
	}
	if(x)puts("Takahashi");
	else puts("Aoki");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    vector<vector<ll> > f(n, vector<ll>(10)), p(n, vector<ll>(11));
    rep1(i, n) rep1(j, 10) cin >> f[i][j];
    rep1(i, n) rep1(j, 11) cin >> p[i][j];
    ll ans;
    for (ll bit=1; bit<(1<<10); bit++){
        vector<ll> c(n);
        for (ll i = 0; i < 10; ++i) {
            if (bit & (1 << i)) {
                for (ll j = 0; j < n; ++j) c[j] += f[j][i];
            }
        }
        ll sum = 0;
        for (ll i = 0; i < n; ++i) sum += p[i][c[i]];
        if (bit==1) ans = sum;
        else ans = max(ans, sum);
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3556
from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)

k = int(input())

def bfs(k):
    ls = []
    q = deque()
    for i in range(1,10):
        q.append(str(i))
    while q:
        tmp = q.popleft()
        ls.append(tmp)
        if len(ls)==k:
            break
        n = int(tmp[-1])
        if n==0:
            tmp_new = tmp + "0"
            q.append(tmp_new)
            tmp_new = tmp + "1"
            q.append(tmp_new)
        elif 0<n<9:
            tmp_new = tmp + str(n-1)
            q.append(tmp_new)
            tmp_new = tmp + str(n)
            q.append(tmp_new)
            tmp_new = tmp + str(n+1)
            q.append(tmp_new)
        elif n==9:
            tmp_new = tmp + "8"
            q.append(tmp_new)
            tmp_new = tmp + "9"
            q.append(tmp_new)
        else:
            print("Error")
    return ls

ls = bfs(k)
# print(ls)
print(ls[k-1])

Measured memory_bytes: 72924
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
    int n,m;
    cin >> n;
    map<string, int> mp;
    for(int i = 0; i < n; i++) {
        string s; cin >> s;
        mp[s]++;
    }
    cin >> m;
    for(int i = 0; i < m; i++) {
        string t; cin >> t;
        mp[t]--;
    }
    int ans = 0;
    for(auto& x: mp) {
        ans = max(ans, x.second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double x = sc.nextDouble();

    double tant = 2 * (b- (x/(a*a)))/a;

    double y = a*tant;

    // System.out.println(x);
    // System.out.println(a*tant);
    // System.out.println(a*tant);

    double ans = Math.toDegrees(Math.atan(tant));

    if (x < a*a*b/2){
      System.out.println(Math.toDegrees(Math.atan(a*(b*b)/(2*x))));
    }else{
      System.out.println(Math.toDegrees(Math.atan(tant)));
    //System.out.println(Math.PI/4);
    }
  }
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll inf = 100000000;
typedef pair<ll, ll> P;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
int a[4][4];
int main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	int b[15];
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < n; k++) {
				if (a[i][j] == b[k]) {
					a[i][j] = inf;
				}
			}
		}
	}

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

			for (int j = 0; j < 3; j++) {
				if (a[0][j] == inf) {
					if (a[1][j] == inf && a[2][j] == inf) {
						cout << "Yes" << endl;
						return 0;
					}
				}
			}
		
			if (a[0][0] == inf && a[1][1] == inf && a[2][2] == inf) {
				cout << "Yes" << endl;
				return 0;
	  }

			if (a[0][2] == inf && a[1][1] == inf && a[2][0] == inf) {
				cout << "Yes" << endl;
				return 0;
			}

			cout << "No" << endl;
			return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
int main(){
    int n,a;
    bool ans=true;
    cin>>n;
    REP(i,n){
        cin>>a;
        if(a%2==0&&a%3!=0&&a%5!=0) ans=false;
    }
    if(ans) cout<<"APPROVED";
    else cout<<"DENIED";
    cout<<endl;
}

Measured memory_bytes: 256