akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  int n = s.size();
  vector<vector<int>> dp(n + 1, vector<int> (2, -1));
  vector<vector<int>> ap(n + 1, vector<int> (2, -1));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      if (dp[i][j] == -1) continue;
      // 0 が D
      if (s[i] == 'P' or s[i] == '?') {
        if (dp[i + 1][1] < dp[i][j]) {
          dp[i + 1][1] = dp[i][j];
          ap[i + 1][1] = j;
        }
      }
      if (s[i] == 'D' or s[i] == '?') {
        int add = 1;
        if (j == 1) add++;
        if (dp[i + 1][0] < dp[i][j] + add) {
          dp[i + 1][0] = dp[i][j] + add;
          ap[i + 1][0] = j;
        }
      }
    }
  }

  int cur;
  if (dp[n][0] > dp[n][1]) {
    cur = 0;
  } else {
    cur = 1;
  }

  string ans = "";
  for (int i = n; i > 0; i--) {
    if (cur == 0) ans += "D";
    else ans += "P";
    cur = ap[i][cur];
  }
  reverse(ALL(ans));
  cout << ans << endl;
  return 0;
}


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

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

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

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

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

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

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

    return (result);
}

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

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

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

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

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

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

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

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

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

int main(){
ll n;
cin>>n;
ll a[n],b,c[n-1];
ll sum=0;

for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=0;i<n;i++){
    cin>>b;
    sum+=b;
}
for(int i=0;i<n-1;i++){
    cin>>c[i];
}
for(int i=1;i<n;i++){
    if(a[i]==a[i-1]+1){
        sum+=c[a[i-1]-1];
    }
}
cout<<sum<<endl;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> A(N);
vector<int> B(N);
for(int i=0; i<N; i++)
{
    cin >> A.at(i);
    B.at(i)=A.at(i);
}
int median, downmedian, upmedian;
sort(A.begin(),A.end());
downmedian=A.at((N/2)-1);
upmedian=A.at(N/2);
for(int i=0; i<N; i++)
{
if(B.at(i)>=upmedian) cout << downmedian << endl;
else cout << upmedian << endl;
}
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long n,i,j,k,ans,k1;
    cin>>n;
    if (n==2)
    {
    	cout<<1<<endl;
    	return 0;
	}
    ans=0;
    k=n-1;
    ans=2;
    for (i=2;i*i<=k;i++)
    {
    	if (k%i==0)
    	{
    		if (k/i==i)
    		{
    			ans++;
			}
			else
			{
				ans+=2;
			}
		}
	}
	k=n;
	for (i=2;i*i<=k;i++)
	{
		k1=k;
		if (k1%i==0)
		{
			while (k1%i==0)
			{
				k1=k1/i;
			}
			if (k1==1 || k1%i==1)
			{
				//cout<<i<<endl;
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int Q; cin >> Q;
    vector<vector<int> > ap(26);
    rep(i,n) ap[s[i]-'a'].push_back(i);
    rep(i,Q){
        int a; cin >> a;
        if(a==1){
            int it; char next; cin >> it >> next;
            it--;
            auto whe=lower_bound(all(ap[s[it]-'a']),it);
            ap[s[it]-'a'].erase(whe);
            if(ap[next-'a'].empty()) ap[next-'a'].push_back(it);
            else{
            whe=lower_bound(all(ap[next-'a']),it);
            whe=ap[next-'a'].insert(whe,it);
            }
          	s[it]=next;
        }
        else{
            int l,r; cin>> l >> r;
         	l--; r--;
            int ans=0;
            rep(j,26){
                if(ap[j].empty()) continue;
                auto whe2 = lower_bound(all(ap[j]),l);
                if(ap[j][whe2-ap[j].begin()]<=r && whe2-ap[j].begin()!=ap[j].size()) ans++;
            }
            cout << ans << endl;
        }
    }
return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <set>
#include <deque>
#include <vector>
using namespace std;

typedef long long i64;

i64 k;

i64 dist[100010];

struct edge
{
	int to;
	int cost;
};

vector<edge> edges[100010];


int main()
{
	cin >> k;

	for(int i = 0;i < k;i++)
	{
		{
			//plus 1
			int n = i + 1;
			n = n % k;

			edges[i].push_back({n,1});
		}
		{
			//plus * 10

			int n = i * 10;
			n = n % k;
			edges[i].push_back({n,0});
		}
	}
	typedef pair<i64,int> P;

	deque<P> que;
	que.push_back({1,1});
	fill(dist , dist + 100010,(1LL <<60));
	dist[1] = 1;

	while(!que.empty())
	{
		i64 d = que.front().first;
		int v = que.front().second;

		que.pop_front();

		if(dist[v] < d) continue;

		for(edge& e : edges[v])
		{
			if(dist[e.to] > dist[v] + e.cost)
			{
				dist[e.to] = dist[v] + e.cost;
				if(e.cost == 0)
				{
					que.push_front({dist[e.to],e.to});
				}
				else
				{
					que.push_back({dist[e.to],e.to});
				}
			}
		}
	}

	cout << dist[0] << endl;
	return 0;
}



Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


int main(){
    string s; cin >> s;
    int ans = 700;
    rep(i, 3) if(s[i] == 'o') ans+= 100;
    cout << ans << endl;
}

Measured memory_bytes: 256
Row = int(input())
dictA= {}
a = ""
mid = 0
for i in range (Row):
  a = input()
  dictA.setdefault(a,0) 
  dictA[a] += 1
  mid = max(mid, dictA[a])
sDict = sorted(dictA.items())
for i in range(len(dictA)):
  if sDict[i][1]== mid:
    print(sDict[i][0])

Measured memory_bytes: 46692
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

void solve() {
    int p, q, r;
    cin >> p >> q >> r;
    cout << min({ p + q, q + r, p + r });
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> A(M);
  rep(i, M) cin >> A.at(i);
  
  int sum = 0;
  rep(i, M) sum += A.at(i);
  
  int ans;
  if (N < sum) {
    cout << "-1" << endl;
  }
  
  else {
    ans = N - sum;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main() {
  ll n, m, x, y;
  cin >> n >> m;
  vector<int> red(n, 0), num(n, 1);
  red.at(0) = 1;
  rep(i, m) {
    cin >> x >> y;
    if(red.at(x-1)) red.at(y-1)=1;
    num.at(x-1)--;
    num.at(y-1)++;
    if(num.at(x-1) == 0) red.at(x-1) = 0;
  }
  cout << accumulate(all(red), 0LL);
}

Measured memory_bytes: 1024
a,b,h,m=map(int,input().split())

long_deg=30*h+30*(m/60)
min_deg=6*m

deg=abs(long_deg-min_deg)

import math

ans=a**2+b**2-2*a*b*math.cos(math.radians(deg))
ans=math.sqrt(ans)

print('{:.11f}'.format(ans))

Measured memory_bytes: 9392
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = list()
for i in range(N):
	a = list(map(int,input().split()))
	A.append(a)

count = 0
for i in range(N):
	ans = 0
	for j in range(M):
		ans += A[i][j]*B[j]
	if ans + C > 0:
		count += 1
print(count)

Measured memory_bytes: 3188
def fac(n):
    if (n == 1 or n == 0):
        return 1
    return n * fac(n - 1)

n, m = map(int, (input().split()))
if n <= 1 and m <= 1:
    print (0)
else:
    ans = 0
    if n >= 2:
        ans = fac(n) // (2 * fac(n - 2))
    if m >= 2:
        ans += fac(m) // (2 * fac(m - 2))
    print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7) 
#define ll long long
#define _ << " " <<
#define TRACE(x) cerr << #x << " = " << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"

int a,b,t;

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

	cin >> a >> b >> t;
	cout << t/a * b << endl;
	return 0;
}


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

int main()
{
    string s;
    cin>>s;
    int a,b,c,d;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';

    for(int i=0;i<8;i++){
        if(a+b+c+d==7&&i==0){
            printf("%d+%d+%d+%d=7",a,b,c,d);
            break;
        }
        if(a+b+c-d==7&&i==1){
            printf("%d+%d+%d-%d=7",a,b,c,d);
            break;
        }
        if(a+b-c+d==7&&i==2){
            printf("%d+%d-%d+%d=7",a,b,c,d);
            break;
        }
        if(a-b+c+d==7&&i==3){
            printf("%d-%d+%d+%d=7",a,b,c,d);
            break;
        }
        if(a-b-c+d==7&&i==4){
            printf("%d-%d-%d+%d=7",a,b,c,d);
            break;
        }
        if(a+b-c-d==7&&i==5){
            printf("%d+%d-%d-%d=7",a,b,c,d);
            break;
        }
        if(a-b+c-d==7&&i==6){
            printf("%d-%d+%d-%d=7",a,b,c,d);
            break;
        }
        if(a-b-c-d==7&&i==7){
            printf("%d-%d-%d-%d=7",a,b,c,d);
            break;
        }
    }
        cout<<endl;
}

Measured memory_bytes: 256
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    n,m,k = mi()
    a = mi()
    b = mi()
    
    cum_a = create_cum(a)
    cum_b = create_cum(b)
    
    res, j = 0, m
    for i in range(n+1):
        if cum_a[i] > k:
            break
        while cum_a[i] + cum_b[j] > k:
            j -= 1
        res = max(res, i+j)

    print(res)

def create_cum(x):
    res = [0]
    for i in range(len(x)):
        res.append(res[i]+x[i])
    return res

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 48684
S = list(input())

count_0 = 0
count_1 = 0

for i in range(len(S)):
	if (i % 2 == 1) ^ (S[i] == '1'):
		count_0 += 1
	else:
		count_1 += 1
		
print(min(count_0, count_1))
		

Measured memory_bytes: 49520
n = int(input())
a = list(map(int, input().split()))

b = list(set(a))
c = [0]*len(b)

if len(b)>3:
    print('No')
    exit()

if n%3!=0:
    if len(b)==1 and b[0]==0:
        print('Yes')
        exit()
    else:
        print('No')
        exit()

for i in range(n):
    for j in range(len(b)):
        if a[i]==b[j]:
            c[j]+=1
            break


if len(b)==1:
    if b[0]==0:
        print('Yes')
        exit()
elif len(b)==2:
    if c[0]==n*2//3:
        if b[1]==0:
            print('Yes')
            exit()
    elif c[1]==n*2//3:
        if b[0]==0:
            print('Yes')
            exit()
elif len(b)==3:
    if c[0]==c[1]==c[2]:
        if b[0]^b[1]==b[2] and b[1]^b[2]==b[0] and b[2]^b[0]==b[1]:
            print('Yes')
            exit()

print('No')



Measured memory_bytes: 60784
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	cout << (m1==m2?0:1) << endl;

	return 0;
}


Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
V = gets.split.map(&:to_i)

ans = 0
N.times do |l|
  l.upto(N-1) do |r|
    t = N - (r-l+1) 
    next if t > K
    hand = []
    l.times do |i|
      hand << V[i]
    end
    (r+1).upto(N-1) do |i|
      hand << V[i]
    end
    hand.sort!
    
    tmp = hand.empty? ? 0 : hand.reduce(:+)
    (K-t).times do |i|
      break if i >= t || hand[i] > 0
      tmp -= hand[i]
    end
    ans = tmp if tmp > ans
    #p [l,r,t,hand,tmp]
  end
end
tmp = V.reduce(:+)
V.sort!
(K-N).times do |i|
  break if i >= N || V[i] > 0
  tmp -= V[i]
end
ans = tmp if K >= N && tmp > ans

p ans

Measured memory_bytes: 2044
#include <iostream>
using namespace std;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0;i<(n);++i)

template<int MOD> struct MInt {
  long long val;
  MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt operator/(const MInt& n) const { return MInt(val) /= n; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  MInt& operator/=(const MInt& n) { val = (*this * n.inv()).val; return *this; }
  MInt pow(long long n) const {
    MInt pow = val, ans = 1;
    for (long long p = n; p > 0; p >>= 1) {
      if (p & 1) ans *= pow;
      pow *= pow;
    }
    return ans;
  }
  MInt inv() const { return pow(MOD-2); }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
};
using mint = MInt<1000000007>;

mint fac[1000001];
int main() {
  int in(X); int in(Y);

  int k = (X + Y) / 3;
  if ((X + Y) % 3 != 0 || k > X || k > Y) {
    cout << 0 << endl;
    return 0;
  }
  X -= k; Y -= k;
  fac[0] = 1;
  rep(i, 1e6)
    fac[i+1] = fac[i] * (i+1);
  cout << fac[X + Y] / fac[X] / fac[Y] << endl;

  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
int cnt[MAX];

inline int add(int a, int b) {
    a += b;
    if (a >= MOD) {
        a -= MOD;
    }
    return a;
}

inline int sub(int a, int b) {
    a -= b;
    if (0 > a) {
        a += MOD;
    }
    return a;
}

inline int mult(int a, int b) {
    return (1LL * a * b) % MOD;
}

int f_exp(int x, int exp) {
    if (exp == 0) return 1;
    if (exp & 1) return mult(x, f_exp(x, exp - 1));
    return f_exp(mult(x, x), exp / 2);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    cnt[k] = 1;
    int ans = k;
    ford (i, k - 1, 1) {
        int possible = k / i;
        int total = f_exp(possible, n);
        for (int j = 2 * i; j <= k; j += i) {
            total = sub(total, cnt[j]);
        }
        ans = add(ans, mult(i, total));
        cnt[i] = total;
    }
    cout << ans << endl;
    return 0;
}



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

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int N;
    read(N);
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N, M;
  while(cin>>N>>M && N){
    vector<int> s(N), t(N);
    vector<int> rope(M);
    REP(i, N) scanf("%d %d", &s[i], &t[i]);
    REP(i, M) scanf("%d", &rope[i]);
    sort(rope.begin(), rope.end());
    vector<int> sum_mod[2];
    REP(i, 2) sum_mod[i] = vector<int>(M);
    REP(i, M - 1){
      sum_mod[0][i + 1] = sum_mod[0][i] + ((i % 2 == 0) ? (rope[i + 1] - rope[i]) : 0);
      sum_mod[1][i + 1] = sum_mod[1][i] + ((i % 2 == 1) ? (rope[i + 1] - rope[i]) : 0);
    }
    ll ans = 0;
    REP(i, N){
      bool rev = (s[i] > t[i]);
      if(rev) swap(s[i], t[i]);
      int b_idx = upper_bound(rope.begin(), rope.end(), s[i]) - rope.begin();
      int e_idx = upper_bound(rope.begin(), rope.end(), t[i]) - rope.begin();
      if(b_idx == e_idx){
        ans += (t[i] - s[i]);
        //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
        //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
        continue;
      }
      assert(b_idx < e_idx);
      e_idx--;
      if(!rev){
        int mod = (b_idx + 1) % 2;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (rope[b_idx] - s[i]);
        if(e_idx % 2 == mod){
          ans += (t[i] - rope[e_idx]);
        }
      }else{
        int mod = (e_idx) % 2;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (t[i] - rope[e_idx]);
        if((b_idx + 1) % 2 == mod){
          ans += (rope[b_idx] - s[i]);
        }
      }
      //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
      //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <math.h>

int main(){
  int p[10][10];
  int N, D, i, j, k;
  int count = 0;
  scanf("%d%d", &N, &D);
  for(i=0; i < N; i++){
    for(j=0; j<D; j++){
      scanf("%d", &p[i][j]);
    }
  }
  for(i=0; i<N-1;i++){
    for(j=i+1; j<N;j++){
      double dist = 0;
      for(k=0; k<D; k++)
        dist += pow(p[i][k] - p[j][k], 2);
      dist = sqrt(dist);
      if(ceil(dist) == floor(dist))
        count++;
    }
  }
  printf("%d", count);
}
      


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

#define ll long long

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

  int k;
  cin >> k;
  vector<bool> visited(k);
  int cur = 0, res = -1;
  for (int i = 0; ; ++i) {
    cur = (cur * 10 + 7) % k;
    if (visited[cur]) break;
    visited[cur] = true;
    if (cur == 0) {
      res = i + 1;
      break;
    }
  }
  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

string X;

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

    int tmp = 0;
    vector<int> S;
    for(int i = X.length() - 1; i >= 0; i--) {
        if(X[i] == 'T') tmp++;
        else S.push_back(tmp);
    }
    int rsl = 0;
    tmp = 0;
    rep(i, 0, S.size()) {
        if(S[i] - tmp > 0) {
            rsl++;
            tmp++;
        }
    }
    cout << X.size() - 2 * rsl << endl;
}


Measured memory_bytes: 1044
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,c,d,e,z[1001];
	scanf("%d",&a);
	for(b=0;b<a;b++)
	{
		scanf("%d",&z[b]);
	}
	for(b=a-1;b>=0;b--)
	{	
		printf("%d",z[b]);
		if(b>0)
		{
			printf(" ");
		}
	}
	printf("\n");
}



Measured memory_bytes: 2140
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,k,a[500005],t[1048666],b[5000005],cnt[5000005],L,R;
int he[5000005],nx[1000005],tt[1000005],m;
int get(int k,int l,int r){
    if(l>=L&&r<=R) return t[k];
    int m=(l+r)>>1;
    if(L>m) return get((k<<1)^1,m+1,r);
    if(R<=m) return get(k<<1,l,m);
    return max(get((k<<1)^1,m+1,r),get(k<<1,l,m));
}
int add(int x,int y){
    ++m;
    nx[m]=he[x];
    tt[m]=y;
    he[x]=m;
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i){
        int x;
        scanf("%d",&x);
        a[x]=i;
    }
    for(int i=1;i<=n;++i){
        L=max(a[i]-k+1,1),R=a[i];
        int o=get(1,1,524288);
        if(o)add(a[i],a[o]),++cnt[a[o]];
        L=a[i],R=min(a[i]+k-1,n);
        o=get(1,1,524288);
        if(o)add(a[i],a[o]),++cnt[a[o]];
        int I=524287+a[i];
        while(I)t[I]=i,I>>=1;
    }
    priority_queue<int> q;
    for(int i=1;i<=n;++i)if(!cnt[i])q.push(i);
    for(int i=n;i;--i){
        int k=q.top();
        q.pop();
        b[k]=i;
        for(int j=he[k];j;j=nx[j]){
            --cnt[tt[j]];
            if(!cnt[tt[j]])q.push(tt[j]);
        }
    }
    for(int i=1;i<=n;++i)printf("%d\n",b[i]);
    //system("pause");
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    int t = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == '+') ++t;
        else --t;

    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;

public class Main {
  private static void solve() {
    char[] s = ns();
    int n = s.length;
    char[] t1 = Arrays.copyOf(s, n / 2);
    char[] t2 = new char[n / 2];
    for (int i = (n + 3) / 2 - 1, j = 0; i < n; i++, j++) {
      t2[j] = s[i];
    }
    boolean ok = f(s) && f(t1) && f(t2);

    System.out.println(ok ? "Yes" : "No");
  }

  private static boolean f(char[] s) {
    int n = s.length;
    for (int i = 0; i <= n / 2; i++) {
      if (s[i] != s[n - i - 1]) {
        return false;
      }
    }
    return true;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22612
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
#include <set>
#include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef pair<long long,int> plli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/







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

    int T; cin>>T; cin.ignore();
    if (T<10) {
        cout<<T<<el;
        return 0;
    }

    queue<plli> s;

    for (int t = 1; t<10; ++t) {
        s.push({(ll)t,t});
    }

    int ct = 0;

    while (true) {
        ++ct;
        auto pr = s.front();
        s.pop();
        auto m = pr.first; auto d = pr.second;
        if (ct==T) {
            cout<<m<<el;
            return 0;
        }
        if (d>0) {
            s.push({m*10+(ll)d-1,d-1});
        }
        s.push({m*10+d,d});
        if (d<9) {
            s.push({m*10+(ll)d+1,d+1});
        }
    }

}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;
using P = pair<int, int>;

struct edge {
    int to;
    int cost;
};

vector<int> dist;
vector<vector<edge> > g;

void dijkstra(int s) {
    dist = vector<int>(n, Inf);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > pq;
    pq.push(P(0, s));

    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;

        rep (i, g[v].size()) {
            edge e = g[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pq.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int m;
    cin >> n >> m;
    g = vector<vector<edge> >(n);
    rep (i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge e;
        e.to = b;
        e.cost = 1;
        g[a].push_back(e);
        e.to = a;
        g[b].push_back(e);
    }
    dijkstra(0);
    if (dist[n - 1] == 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    
    return 0;
}



Measured memory_bytes: 15080
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main() {
	string a, b;
	int cnt = 0;
	cin >> a;
	cin >> b;
	for (int i = 0; i < a.length(); i++) {
		if (a[i] == b[i])cnt++;
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int x, y;
	int t;
	
	for(;;){
		scanf("%d%d", &x, &y);
		if(x == 0 && y == 0)break;
		if(x > y) t = x, x = y, y = t;
		printf("%d %d\n", x, y);
	}
	return 0;
}


Measured memory_bytes: 2044
//
// Created on 2020/03/07.
//

//#include <bits/stdc++.h>
#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 <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 <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    string ans;
    bool permission = true;
    int q;
    string s;
    cin>>s>>q;
    int l;
    ans = s;
    while(q){
        int t;
        cin>>t;
        if(t == 1){
            if (permission) permission = false;
            else permission = true;
        }else{
            int f;
            char c;
            cin>>f>>c;
            if(permission){
                if(f==2) {
                    ans.push_back(c);
                    //l++;
                }
                else {
                    auto temp = ans.begin();
                    ans.insert(temp,c);
                    //l++;
                }
            }
            if(!permission){
                if(f==1) {
                    ans.push_back(c);
                    //l++;
                }
                else {
                    auto temp = ans.begin();
                    ans.insert(temp,c);
                    //l++;
                }
            }

        }



        q--;
    }
    if(permission){
        for (int i = 0; i < ans.size(); ++i) {
            cout<<ans[i];
        }
        cout<<endl;
        return 0;
    }else{
        for (int i = ans.size()-1; i >= 0; --i) {
            cout<<ans[i];
        }
        cout<<endl;
    }

}


Measured memory_bytes: 1084
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int n, m, c[32], x[21919];
	while (scanf("%d%d", &n, &m), n)
	{
		for (int i = 0; i < m; ++i)
			scanf("%d", c + i);
		for (int i = 0; i < n; ++i)
			scanf("%d", x + i);

		static ll dp[21919][256];
		const ll INF = 1LL << 55;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= 255; ++j)
				dp[i][j] = INF;

		dp[0][128] = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j <= 255; ++j)
			{
				for (int k = 0; k < m; ++k)
				{
					int y = max(0, min(255, j + c[k]));
					int s = x[i] - y;
					min_swap(dp[i + 1][y], dp[i][j] + s * s);
				}
			}
		}
		printf("%lld\n", *min_element(dp[n], dp[n] + 256));
	}
}

Measured memory_bytes: 0
#define _ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <bits/stdc++.h>
using namespace std;

struct come
{
    int no, comein;
}stu[100000+9];

bool cmp(come a,come b)
{
    return a.comein<b.comein;
}

int main()
{
    int N;
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        stu[i].no=i;
        cin>>stu[i].comein;
    }

    sort(stu+1,stu+N+1,cmp);

    for(int i=1;i<=N;i++)
    {
        if(i==1)cout<<stu[i].no;
        else cout<<' '<<stu[i].no;
    }

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
#include <ctype.h>
using namespace std;

int main() {
    
    string s1,s2,s3;
    string ans = "";
    
    cin >> s1;
    cin >> s2;
    cin >> s3;
    
    ans += toupper( s1[0] );
    ans += toupper( s2[0] );
    ans += toupper( s3[0] );
    
    
    
    cout << ans << endl;
    
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll s = 0;
    rep(i,n) {
        int A;
        cin >> A;
        s+=A;
        a[i]=A;
    }
    for(int i = 1; i < n; ++i) a[i] += a[i-1];
    ll ans = 1000000000000000000LL;
    rep(i,n-1) ans = min(ans, abs(2*a[i]-s));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>

int main()
{
  std::string s, t;

  std::cin >> s;
  std::cin >> t;

 std::sort(&t[0], &t[t.size()], std::greater<char>()); 
 std::sort(&s[0], &s[s.size()]); 

  if ( s < t) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char S[11];
    char T[11];
    int i,a,b;
    scanf("%s",S);
    scanf("%s",T);
    a=0;
    b=0;
    for(i=0;S[i]!='\0';i++){
        if(S[i]!=T[i]){
            a=1;
        }
        if(S[i+1]!=T[i+1]){
            b=1;
        }
        if(S[i+1]==T[i+1]){
            b=0;
        }
    }
    if(a==0&&b==1){
        printf("Yes");
    }else{
        printf("No");
    }

}

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

int n, x;

int a[4][4];
bool used[4][4];

void choose(int x)
{
    for (int i = 1; i <= 3; ++i)
    {
        for (int j = 1; j <= 3; ++j)
        {
            if (!used[i][j] && a[i][j] == x)
            {
                used[i][j] = true;
                return;
            }
        }
    }
}

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

    for (int i = 1; i <= 3; ++i)
    {
        for (int j = 1; j <= 3; ++j) cin >> a[i][j];
    }

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> x;
        choose(x);
    }

    for (int i = 1; i <= 3; ++i)
    {
        if (used[1][i] && used[2][i] && used[3][i])
        {
            cout << "Yes\n";
            return 0;
        }
        if (used[i][1] && used[i][2] && used[i][3])
        {
            cout << "Yes\n";
            return 0;
        }
    }

    if (used[1][1] && used[2][2] && used[3][3]) cout << "Yes\n";
    else if (used[1][3] && used[2][2] && used[3][1]) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define N_MAX 110
#define K_MAX 100010

int main() {
  ll res = 1;
  int N;
  cin >> N;

  vector<ll> a(N);
  rep(i,N){
    cin >> a.at(i);
    if(a.at(i) == 0){
      cout << 0 << endl;
      return 0;
    }
  }

  rep(i,N){
    res *= a.at(i);
    if(res > 1000000000000000000){
      cout << -1 << endl;
      return 0;
    }
  }

  ll check = res;
  rep(i,N){
    check /= a.at(i);
  }  
  if(check != 1){
    cout << -1 << endl;
    return 0;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3988
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

dp[0] = 1
if 1 not in skip:
    dp[1] = 1

for i in range(2, N+1):
    if i in skip:
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])


Measured memory_bytes: 87536
# B - Great Ocean View
# https://atcoder.jp/contests/abc124/tasks/abc124_b

N = int(input())
H = map(int, raw_input().split())
max_h = -1
num_inns = 0

for h in H:
    if h >= max_h:
        num_inns += 1
        max_h = h

print '{}'.format(num_inns)


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    vector<queue<int>> s(3);
    rep(i,3){
        string tmp; cin>>tmp;
        for(auto e:tmp)s[i].push((int)(e-'a'));
    }

    int now = 0;
    while(true){
        if(s[now].empty()){
            cout<<(char)('A'+now)<<endl;
            return 0;
        }
        int tmp = now;
        now = s[now].front();
        s[tmp].pop();
    }

    assert(false);
    return 0;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int 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 F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n,k;cin>>n>>k;
  int a[200010];
  rep(i,n)cin>>a[i],a[i]++;
  int MA=0,sum=0;
  rep(i,k)sum+=a[i];
  MA=sum;
  for(int i=k;i<n;i++){
    sum+=a[i]-a[i-k];
    //cout<<sum<<endl;
    MA=max(MA,sum);
  }
  if(MA%2==0)cout<<MA/2<<endl;
  else cout<<MA/2<<'.'<<5<<endl;
  return 0;
}


Measured memory_bytes: 1792
N = gets.to_i
point_list = N.times.map { gets.split(' ').map(&:to_i) }

dp = Array.new(N)
N.times.each { |i| dp[i] = Array.new(3, 0) }
dp[0][0] = point_list[0][0]
dp[0][1] = point_list[0][1]
dp[0][2] = point_list[0][2]

(1...N).each do |i|
  a_, b_, c_ = dp[i - 1]
  a, b, c  = point_list[i]
  dp[i][0] = [b_, c_].map { |n| n + a }.max
  dp[i][1] = [a_, c_].map { |n| n + b }.max
  dp[i][2] = [a_, b_].map { |n| n + c }.max
end

puts dp[N - 1].max


Measured memory_bytes: 16124
#include<stdio.h>
#include<stdlib.h>
//#define MAX 51
#define MAX 2147483647

//int h[MAX];

/*
void reset(int *p){
    int i;
    for(i = 0;i < MAX;i++)p[i]=0;
}
*/

struct cell {
    int s;//start_time
    int e;//end_time
    int flag;
    int w;//weight
}p[100];

int compare(const void *a,const void *b){
    return ((struct cell *)a) -> s - ((struct cell *)b) -> s;
}

int main(){
    int sum,n,flag,m,a,b,i,j,cnt,now;

    while(scanf("%d",&n),n){
        //reset(h);
        for(i = 0;i < n;i++){
            scanf("%d%d%d",&m,&a,&b);
            p[i].w = m;
            p[i].s = a;
            p[i].e = b;
            p[i].flag = 0;
            //h[a[i]] += m[i];
            //h[b[i]] -= m[i];
        }

        qsort(p,n,sizeof(struct cell),compare);

        for(i = 0,flag = 0,now = 0;i < n;i++){

            for(j = 0;j < i;j++){
                if(p[j].flag == 1&&p[j].e<=p[i].s){
                    p[j].flag = 0;
                    now -= p[j].w;
                }
            }

            now += p[i].w;
            p[i].flag = 1;

            if(150 < now){
                flag = 1;
                break;
            }
        }

        /*
        for(i = 0,flag = 0,sum = 0,cnt = 0;i < MAX;i++){
            for(j = 0;j < n;j++){
                if(a[j] == i){
                    sum += m[j];
                }
                if(b[j] == i){
                    sum -= m[j];
                    cnt++;
                }
                //sum += h[i];
                if(sum > 150){
                    flag=1;
                    break;
                    break;
                }
            }
            if(cnt == n)break;
        }
        */
        if(flag)puts("NG");
        else puts("OK");
    }
    return 0;
}

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

using namespace std;


constexpr int mod = 1000000007;

long long f(int x, int n) {
    long long counter = 1;
    for(int i = 0; i < n; i++) {
        counter *= x;
        counter %= mod;
    }
    return counter;
}

int main() {
    int n;
    cin >> n;
    long long ans = f(10, n) - f(9, n) - f(9, n) + f(8, n);
    ans %= mod;
    if(ans < 0) {
        ans += mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3624