akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e5+10;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2);
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
bool check(int x){

}
int binary(int x,int y){
    int s=x,e=y,mid;
    while(s<e){
        mid=ceil((s+e)/2.0);
        if(check(mid))
            s=mid;
        else
            e=mid-1;
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[i]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}

int fun(int arr[],int s,int e){
    if(e-s==1){
        return 0;
    }
    int sz1=(s+e)/2;
    int sz2=e-(sz1+s);
    int ans=fun(arr,s,sz1)+fun(arr,sz1,e);
    int x=s;
    for(int i=sz1;i<e;i++){
        if(arr[i]>arr[x]){
            ans+=sz1-(x);
        }
        else{
            i--;
            x++;
        }
    }
    return ans;
}

in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        int n,d,c;
        cin>>d>>n;
        c=d;
        vector<int> v;
        int l=-1,f;
        for(int i=0;i<n;i++){
            int a;
            cin>>a;
            if(i==0)l=f=a;
            else{
                v.pb(a-l);
                l=a;
            }
        }
        v.pb(c-l+f);
        int mx=0;
        for(int i=0;i<v.size();i++){
            mx=max(mx,v[i]);
        }
        cout<<c-mx<<endl;
    }
    RETURN;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ins insert
#define Pq priority_queue
#define u_set unordered_set
#define MOD 1000000007
#define MAXN 100001
#define set_val(arr,v) memset(arr, v, sizeof(arr))
#define FOR(i,from,to) for(int i=from; i<to; i++)
#define FOL(i,from,to) for(int i=from; i>=to; i--)
#define B() begin()
#define E() end()
#define F first
#define S second

ll dp[10001];

int main() {
	ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
	ll h,n;
	cin >> h >> n;
	vector<pair<ll,ll>> ab;
	FOR(i,0,n) {
		ll a,b;
		cin >> a >> b;
		ab.pb(mp(a,b));
	}
	dp[0] = 0;
	FOR(i,1,h+1) {
		dp[i] = INT_MAX;
		FOR(j,0,n) {
			if(i - ab[j].F < 0) dp[i] = min(dp[i], ab[j].S);
			else dp[i] = min(dp[i], dp[i - ab[j].F] +  ab[j].S); 
		}
	}
	cout << dp[h] << endl;
	return 0; 
}

Measured memory_bytes: 384
def is_not_less_than(ls, ind, key):
    if ls[ind] >= key:
        return True
    else:
        return False
def return_min_ind_whose_value_not_less_than(ls,key):
    r = len(ls)
    l = -1
    while True:
        next_ind = (r+l) // 2
        if is_not_less_than(ls, next_ind, key):
            r = next_ind
        else:
            l = next_ind
        if r - l == 1:
            return r
n_shrine,n_temple,Q = map(int,input().split())
shrine_ls = [0] * (n_shrine+1)
temple_ls = [0] * (n_temple+1)
Q_ls = [0] * Q
for i in range(n_shrine):
    shrine_ls[i] = int(input())
shrine_ls[-1] = float('inf')
for i in range(n_temple):
    temple_ls[i] = int(input())
temple_ls[-1] = float('inf')
for i in range(Q):
    Q_ls[i] = int(input())

for q in Q_ls:
    i_Rshrine = return_min_ind_whose_value_not_less_than(shrine_ls,q)
    Rshrine = shrine_ls[i_Rshrine]
    i_Lshrine = i_Rshrine-1
    Lshrine = shrine_ls[i_Lshrine]

    i_Rtemple = return_min_ind_whose_value_not_less_than(temple_ls,q)
    Rtemple = temple_ls[i_Rtemple]
    i_Ltemple = i_Rtemple-1
    Ltemple = temple_ls[i_Ltemple]
    # Temple,Shrine共に右
    RR = max(Rtemple,Rshrine) - q
    # Temple,Shrine共に左
    if i_Lshrine >= 0 and i_Ltemple >= 0:
        LL = abs(min(Ltemple,Lshrine)-q)
    else:
        LL = float('inf')
    #右templeと左shrine
    if i_Lshrine >= 0:
        RtLs = 2*min(Rtemple-q,q-Lshrine) + max(Rtemple-q,q-Lshrine)
    else:
        RtLs = float('inf')
    # 左templeと右shrine
    if i_Ltemple >= 0:
        LtRs = 2*min(Rshrine-q,q-Ltemple) + max(Rshrine-q,q-Ltemple)
    else:
        LtRs = float('inf')

    print(min(LL,RR,RtLs,LtRs))



Measured memory_bytes: 20996
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        h: usize,
        w: usize,
        k: i32,
        ccc: [Chars; h]
    };
    let black_sum = ccc.iter().fold(0, |cc_sum, cc| {
        cc_sum + cc.iter().fold(0, |c_sum, &c| c_sum + (c == '#') as i32)
    });
    // if black_sum == k {
    //     println!("1");
    //     return;
    // }
    let mut ok = 0;
    for row_size in 0..h {
        for row_indexes in (0..h).combinations(row_size) {
            for col_size in 0..w {
                for col_indexes in (0..w).combinations(col_size) {
                    let mut count = 0;
                    for row in 0..h {
                        for col in 0..w {
                            if !row_indexes.contains(&row)
                                && !col_indexes.contains(&col)
                                && (ccc[row][col] == '#')
                            {
                                count += 1;
                            }
                        }
                    }
                    if count == k {
                        ok += 1;
                    }
                }
            }
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 2228
s=input()
t=input()
ans=1000000
for i in range(len(s)):
    c=0
    if (i+len(t)-1<len(s)):
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                c+=1
        ans=min(ans,c)
print(ans)

Measured memory_bytes: 9112
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
using ll=long long;

int x_gcd(int a,int b){
	if(a<b)x_gcd(b,a);
	int res;
	while(res=a%b){
		a=b;
		b=res;
	}
	return b;
}

int main(){
	int n,X,x[100010],div=1000000000;

	cin>>n>>X;
	for(int i=0;i<n;i++)cin>>x[i];

	int b=abs(x[0]-x[1]);
	for(int i=0;i<n-2;i++){
		b=x_gcd(b,abs(x[i+1]-x[i+2]));
//		cout<<b<<endl;
	}
	for(int i=0;i<n;i++)div=min(div,abs(x[i]-X));
	if(n==1)cout<<abs(x[0]-X);
	else cout<<x_gcd(b,div);
}



Measured memory_bytes: 640
import collections
import math

n = int(input())
str_list = []
for i in range(n):
    str_list.append(''.join(sorted(input())))

ans = 0
for i in collections.Counter(str_list).values():
    if i >=2 :
        ans += math.factorial(i)//math.factorial(i-2)//math.factorial(2)
print(ans)

Measured memory_bytes: 68568
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#include<queue>
#define mod 998244353
#define pb push_back
#define ll long long
using namespace std;
int main(){
	ll n,l;
	vector<ll> a;
	cin>>n>>l;
	a.pb(0);
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	int good = 0;
	for(int i=1;i<=n-1;i++){
		if(a[i]+a[i+1] >= l){
			good = i;
		}
	}
	if(good == 0) { cout<<"Impossible"<<endl; return 0;}
	else{
		cout<<"Possible"<<endl;
		for(int i=1;i<good;i++){
			cout<<i<<endl;
		}
		for(int i=n-1;i>good;i--){
			cout<<i<<endl;
		}
		cout<<good<<endl;
	}
	return 0;
}

Measured memory_bytes: 1780
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main(){
    int n;
    cin>>n;
    int h[100];
    for(int i=0;i<n;i++)cin>>h[i];
    int ans=0;
    for(int i=1;i<=100;i++){
        bool count=false;
        for(int j=0;j<n;j++){
            if(h[j]>=i)count=true;
            else if(count==true){
                    ans++;
                    count=false;
            }
            if(j==n-1&&count==true){
                ans++;
                count=false;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

bool CanGo(int y, int x, int R, int C) {
	return y >= 0 && y < R && x >= 0 && x < C;
}

int TraceMaze(queue<vector<int>>& Queue, vector<vector<bool>>& Map) {
	vector<int> nowstate = Queue.front();
	Queue.pop();
	int R = Map.size();
	int C = Map[0].size();
	int ny = nowstate[0];
	int nx = nowstate[1];
	int step = nowstate[2];

	if (Map[ny][nx]) {
		Map[ny][nx] = false;
		if (CanGo(ny - 1, nx, R, C))Queue.push({ ny - 1, nx,step + 1 });
		if (CanGo(ny + 1, nx, R, C))Queue.push({ ny + 1, nx,step + 1 });
		if (CanGo(ny, nx - 1, R, C))Queue.push({ ny , nx - 1,step + 1 });
		if (CanGo(ny, nx + 1, R, C))Queue.push({ ny , nx + 1,step + 1 });
	}
	return step-1;
}

int main() {
	int H, W;
	cin >> H >> W;

	queue<vector<int>> Queue;
	vector<vector<bool>> Map(H, vector<bool>(W, true));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			if (c == '#') Queue.push({ i,j,0 });
		}
	}
	int steps = -1;
	while (!Queue.empty()) steps = TraceMaze(Queue, Map);
	if (steps > 0) cout << steps << endl;
	else cout << 0 << endl;
}


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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint com(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;

modint dp[102][10];
modint fibs[10];

modint fib(int n) {
    if (n < 2) return n;
    if (fibs[n]) return fibs[n];
    return fibs[n] = fib(n-1) + fib(n-2);
}

int main(void){
    int Y,X,K;
    cin>>Y>>X>>K;
    dp[0][1] = 1;
    rep(y,Y+1){
        rep1(x,X){
            dp[y+1][x-1] += dp[y][x] * fib(x-1) * fib(X+1-x);
            dp[y+1][x]   += dp[y][x] * fib(x)   * fib(X+1-x);
            dp[y+1][x+1] += dp[y][x] * fib(x)   * fib(X-x);
        }
    }
    cout << dp[Y][K] << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
S_1 = sum(A)%(10**9+7)
S_2 = sum([a**2%(10**9+7) for a in A])
result = ((S_1**2)%(10**9+7)-S_2)%(10**9+7)
if result%2==0:
  print(result//2)
else:
  print((result+10**9+7)//2)

Measured memory_bytes: 31544
h,w = map(int,input().split())
cst = []

for i in range(10):
    cst.append(list(map(int,input().split())))

a = []
for i in range(h):
    a.append(list(map(int,input().split())))

li = [10**4 for i in range(10)] 
li[1] = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if li[k] > li[j] + cst[k][j]:
                li[k] = li[j] + cst[k][j]

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += li[a[i][j]]

print(ans)







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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> pos(m);
    rep(i,m) cin >> pos[i].first >> pos[i].second;

    rep(i,1000){
        int keta = 1;
        int x = i/10;
        vector<int>d(1,i%10);
        //桁数
        while(x>0){
            keta++;
            d.push_back(x%10);
            x/=10;
        }
        reverse(d.begin(),d.end());
        if(keta != n) continue;
        bool ok = true;
        rep(i,m){
            if(d[pos[i].first-1] != pos[i].second) ok = false;
        }
        if(ok) {cout << i << endl;return 0;}
    }
    cout << -1 << endl;
}

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

int main() {
  long long n, k;
  map<long long, long long> v;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    if (v.find(a) == v.end()) {
      v[a] = b;
    }
    else {
      v[a] += b;
    }
  }

  long long sum = 0;
  for (map<long long, long long>::iterator it = v.begin(); it != v.end(); it++) {
    pair<long long, long long> item = *it;
    sum += item.second;
    if (sum >= k) {
      cout << item.first << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll A,B;
    cin >> A >> B;
    if(A*B <= 0){
        cout << "Zero" << "\n";
    }else if(A > 0 || (B-A)%2 == 1){
        cout << "Positive" << "\n";
    }else{
        cout << "Negative" << "\n";
    }
}

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

signed main(){

  int n; cin >> n;
  string s; cin >> s;

  int ans = 1;
  for(int i = 0; i < n; i++){
    if(i+1 < n && s[i] != s[i+1]) ans++;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
    string S;
    cin >> S;
    if (S[S.size() - 1] == '3') {
        cout << "bon" << endl;
    } else if (S[S.size() - 1] == '0' || S[S.size() - 1] == '1' || S[S.size() - 1] == '6' || S[S.size() - 1] == '8') {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl; 
    }
    return 0;
}

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

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    // Input the data
    vector<int> order(N);
    for (int i = 0; i < N; i++)
    {
        cin >> order.at(i);
    }

    vector<int> points(N);
    for (int i = 0; i < N; i++)
    {
        cin >> points.at(i);
    }

    vector<int> bonus(N - 1);
    for (int i = 0; i < N - 1; i++)
    {
        cin >> bonus.at(i);
    }

    // Calc for points
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += points.at(order.at(i) - 1);
    }

    // Calc for bonus
    for (int i = 0; i < N - 1; i++)
    {
        if (order.at(i) == order.at(i + 1) - 1)
        {
            sum += bonus.at(order.at(i) - 1);
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
s = int(input())

a_list = []
a_list.append(s)
count = 1
while True:
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3*s + 1
    count += 1    
    
    if s in a_list:
        break
    else:
        a_list.append(s)

print(count)

Measured memory_bytes: 2940
import math

if __name__ == '__main__':
    Q = int(input())
    for _ in range(Q):
        a, b = map(int, input().split())
        big = max(a, b)
        small = min(a, b)
        c = math.floor(math.sqrt(a * b))
        if c * c == a * b:
            c -= 1

        if big == small:
            print(2 * big - 2)
        elif big == small + 1:
            print(2 * small - 2)
        elif c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)


Measured memory_bytes: 3064
# coding: utf-8
N = int(input())
ans = 0
d = {}
for i in range(N):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s not in d.keys():
        d[s] = 1
    else:
        d[s] += 1
# print(d)
for key in d.keys():
    ans += d[key] * (d[key] - 1) // 2
print(ans)

Measured memory_bytes: 17804
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;


int main(){
    string A, B, C;
    cin >> A >> B >> C;
    if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;

}


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

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  int ans = ((h2 * 60 + m2) - (h1 * 60 + m1)) - k;
  
  cout << ans << endl;
}


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

int main(){
  int N,D;
  cin >> N >> D;
  int count = 0;
  for(int i = 0; i < N; i++){
    int x,y;
    cin >> x >> y;
    if(pow(x,2)+pow(y,2) <= pow(D,2)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3624
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main argv =
    let [|_;k|] = reads int
    let s = read string
    String.mapi (fun i c -> if i = k - 1 then Char.ToLower(c) else c) s
    |> printfn "%s"
    0

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N), B(N);
	REP(i, N) cin >> A[i];

	sort(A.begin(), A.end());
	ll res = 0;
	if(N%2==0){
		REP(i, N/2){
			B[2*i] = A[N/2-1-i];
			B[2*i+1] = A[N-1-i];
		}
		REP(i, N-1) res += abs(B[i]-B[i+1]);
	}else{
		ll cand1 = 0, cand2 = 0;

		REP(i, N/2){
			B[2*i+1] = A[i]; 
		}
		REP(i, N/2+1){
			B[2*i] = A[N/2+i];
		}
		swap(B[2], B[N-1]);
		REP(i, N-1) cand1 += abs(B[i]-B[i+1]);

		REP(i, N/2){
			B[2*i+1] = A[N/2+1+i]; 
		}
		REP(i, N/2+1){
			B[2*i] = A[i];
		}
		swap(B[0], B[N-3]);
		REP(i, N-1) cand2 += abs(B[i]-B[i+1]);

		res = max(cand1, cand2);
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Text;

class Program
{
	static void Main()
	{
		var input = Console.ReadLine().Split();
		var i = input.Select(s => int.Parse(s)).ToArray();

		var sortedI = i.OrderBy(_ => _);
		var sb = new StringBuilder();
		sortedI.ToList().ForEach(e =>
		{
			sb.Append(e);
			if(e != sortedI.Last())
				sb.Append(" ");
		});

		Console.WriteLine(sb.ToString());
	}
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, m;

int a[31];

void read() {
  cin >> n >> m;

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

}

void solve() {
  int sol = 0;
  for(int i = 1; i <= m; ++i)
    if (a[i] == n)
      ++sol;
  cout << sol;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(ll i=(a);i<=(b);++i)
#define rf(i,a,b) for(ll i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
const int mod=1e9+7;
ll st=1,n,k,ans,cnt1;
ll qp(ll x,ll c){
	ll s=1;
	while(c){
		if(c&1)s=(s*x)%mod;
		x=(x*x)%mod,c>>=1;
	}
	return s;
}
int main(){
	read(n),read(k);
    st=qp(10,100);
    fr(i,k,n+1){
    	ll mn=i*(i-1)/2,mx=(2*n-i+1)*i/2;
		ans=(ans+mx-mn+1)%mod;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  if(A+B<C+D){
    cout<<"Right"<<endl;
  }else if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }else{
    cout<<"Left"<<endl;
  }
  
  return 0;
}

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

int main()
{
  ll n,m;
  cin >> n >> m;
  vector<ll> flag(n,0);
  vector<ll> WA(n,0);

  ll cnt_ac = 0;
  ll cnt_wa = 0;

  rep(m)
  {
    ll p;
    string s;

    cin >> p;
    cin >> s;

    if ( s=="WA" && flag[p-1] == 0 ) WA[p-1]++;
    else if ( s=="AC" ) flag[p-1] = 1; 
  }

  for(auto q:flag) cnt_ac += q;
  for (ll i = 0; i < n; i++)
  {
    if(flag[i]==1) cnt_wa += WA[i];
  }
  

  cout << cnt_ac << " " << cnt_wa << endl;

  return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)
#define Ans(s) cout << s << endl;

const int inf = (int)1e9 + 7;
const long long 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; }

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

ll h[MAX];
ll dp[MAX];

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

	for (int i = 0; i < n; i++) cin >> h[i];
	for (int i = 0; i < MAX; i++) dp[i] = INF;

	dp[0] = 0;

	for (int i = 1; i <= n; i++)
	{
		if (i != 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
function Main(input) {
	input = input.split("\n").map(Number);
  input.shift();
  var flag = true;
  for(var i=0;i<input.length;i++){
    if(input[i]%2==1) flag = false;
  }
  if(!flag){
  console.log("first")
  }else{
  console.log("second")
  }
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 19864
#include<bits/stdc++.h>
#include<sstream>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

char c[1024];

void print(int a,int b){
  for(int i=a;i<=b;i++)
    cout<<c[i];
  cout<<endl;
}
void replace(int a,int b, char* str){
  for(int i=0;i<=b-a;i++)
    c[a+i]=str[i];
}
void reverse(int a,int b){
  for(int i=a;i<=(a+b)/2;i++)
    swap(c[i],c[b-(i-a)]);
}

int main(){ _;
  int q;
  cin>>c>>q;
  REP(i,q){
    char query[16];cin>>query;
    int a,b;cin>>a>>b;
    switch(query[2]){
    case 'p':
      char str[1024];cin>>str;
      replace(a,b,str);
      break;
    case 'v': reverse(a,b);break;
    case 'i': print(a,b);break;
    }
  }
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    vl v(3);rep(i,3)cin >> v[i];
    sort(all(v));
    ll ans=0;
    ans+=v[2]-v[1];
    ans+=(v[1]-v[0]+1)/2;
    if((v[1]-v[0])%2==1)ans++;
    cout <<ans <<endl;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())
flag = False
S_uniq = list(set(S))
S_duplicate = [x for x in set(S) if S.count(x) > 1]
T_uniq = list(set(T))
T_duplicate = [x for x in set(T) if T.count(x) > 1]
if len(S_uniq) != len(T_uniq):
    flag = True
else:
    for j in S_duplicate: 
        S_indexes = [i for i, x in enumerate(S) if x == j]
        T_single = T[min(S_indexes)]
        T_indexes = [i for i, x in enumerate(T) if x == T_single]
        if S_indexes != T_indexes:

            flag = True
            break
if flag:
    print('No')
else:
    print('Yes')

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

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


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector< int > A((1 << N) * 2);
  for(int i = 0; i < (1 << N); i++) cin >> A[i];
  for(int i = 0; i < (1 << N); i++) A[i + (1 << N)] = A[i];
  auto dp = make_v< int >(N + 1, (1 << N) * 2);
  fill_v(dp, -1);
  for(int i = 0; i < A.size(); i++) {
    dp[0][i] = A[i];
  }
  auto choose = [&](int x, int y) {
    if(x == -1) return y;
    if(y == -1) return x;
    if(x > y) swap(x, y);
    if(S[y - x - 1] == '1') return y;
    return x;
  };
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < A.size(); j++) {
      if(dp[i][j] == -1) continue;
      if(j + (1 << i) < A.size()) {
        int u = dp[i][j];
        int v = dp[i][j + (1 << i)];
        dp[i + 1][j] = choose(u, v);
      }
    }
  }
  for(int i = 0; i < (1 << N); i++) {
    cout << dp[N][i] << "\n";
  }
}



Measured memory_bytes: 46444
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int N = s.length();
		for(int i = 0 ; i < N ; i++) {
			if(i % 2 == 0) {
				System.out.print(s.charAt(i));
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 28636
#include<stdio.h>
int main(void){int i,n;int number;long long int sum = 0;int min =0;int max = 0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&number);if(i==0){min =number;max = number;}if(number<min) min = number;if(number>max) max = number;sum += number;}printf("%d %d %lld\n",min,max,sum);return 0;}

Measured memory_bytes: 2728
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())

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

int main() {
    int n,m;
    map<int,int> mpa,mpb;
    cin>>n;
    VI d(n);
    for(int i=0;i<n;i++){
        cin>>d[i];
        mpa[d[i]]++;
    }
    cin>>m;
    VI t(m);
    for(int i=0;i<m;i++){
        cin>>t[i];
        mpb[t[i]]++;
    }
    
    for(int i=0;i<m;i++){
        int x = t[i];
        if(mpb[x]>mpa[x]){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 20608
#include <iostream>

int a, b, c[110], d = 1, i = 1;

int main()
{
	std::cin >> a >> b;
	while(i <= b)
	{
		if(a == 0 && d % 100 != 0)
		{
		
			c[i] = d;
			i++;
		}
		if(a == 1 && d % 100 == 0)
		{
			if(d / 100 == 100)
			{
				c[i] = d + 100;
				i++;
			}else
			{
				c[i] = d;
				i++;
			}

		}
		if(a == 2 && d % 100 == 0)
		{
			if(d / 100 % 100 == 0)
			{
				if(d / 100 / 100 == 100)
				{
					c[i] = d + 10000;
					i++;
				}else
				{
					c[i] = d;
					i++;
				}	
			}

		}
		d++;
		
	}
	std::cout << c[b] << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;

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

void solve17(int a, int b) {
    vector<int> v;
    int j;
    REP(i,b) {
        scanf("%d", &j);
        v.push_back(j);
    }
    sort(v.begin(), v.end());
    
    bool haszero = (v[0] == 0);
    if (haszero) {v.erase(v.begin()); b--;}
    
    vector<pair<int, int> > vv; // 1st: size, 2nd: concatable to next
    int cnt = 1;
    REP(i,b-1) {
        if (v[i+1] - v[i] == 1) {
            cnt++;
        }else if (v[i+1] - v[i] == 2) {
            vv.push_back(make_pair(cnt, 1));
            cnt = 1;
        }else {
            vv.push_back(make_pair(cnt, 0));
            cnt = 1;
        }
    }
    vv.push_back(make_pair(cnt, 0));
    int sz = vv.size();
    if (!haszero) {
        sort(vv.begin(), vv.end());
        cout << vv[sz-1].first << endl;
    }else {
        
    }
    
    int ans = 0;
    if (haszero) {
        REP(i,sz) {
            if (vv[i].second) ans = max(ans, vv[i].first + vv[i+1].first + 1);
            else ans = max(ans, vv[i].first + 1);
        }
        cout << ans << endl;
    }
}

int main() {
    int a, b;
    while(cin >> a >> b, a+b) {
        solve17(a, b);
    }
    return 0;
}

Measured memory_bytes: 1784
#include <iostream>

using namespace std;

int main()
{
    int N;
    int A[15];
    int x[15][15];
    int y[15][15];
    int i, j, k;
    int p, q;
    int count;
    int max;
    int flag;

    cin >> N;
    for(i = 0; i < N; i++) {
        cin >> A[i];
        for(j = 0; j < A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }

    //    N:0, 1, 2, 3, ...
    // 1<<N:1, 2, 4, 8, ...
    max = 0;
    for(i = 0; i < (1<<N); i++) {
        //cout << "i: " << i << endl;
        flag = 1;
        count = 0;
        for(j = 0; j < N; j++) {
            //cout << "j: " << j << endl;
            p = i & (1<<j);
            if(p != 0) {
                /* 正直もの */
                count++;
                for(k = 0; k < A[j]; k++) {
                    // xビット取り出して
                    q = i & (1 << x[j][k]);
                    if(q != 0) {
                        q = 1;
                    }
                    // yになっているか?
                    // なっていない場合 矛盾
                    if(q != y[j][k]) {
                        flag = 0;
                    }
                }
            } else {
                /* 不親切は無視 */;
            }
        }
        if(flag == 1 && count > max) {
            max = count;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static long mod = 1_000_000_007;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		boolean[] step = new boolean[in.nextInt()];
		int bs = in.nextInt();
		int[] bsnum = new int[bs];
		for (int i = 0; i < bs; i++) {
			bsnum[i] = in.nextInt();
		}
		in.close();
		for (int i = 0; i < step.length; i++) {
			step[i] = true;
		}
		for (int b : bsnum) {
			step[b - 1] = false;
			if (b != 1 && !step[b - 2]) {
				System.out.println(0);
				return;
			}
		}
		long[] dp = new long[step.length + 1];
		dp[0] = 1L;
		for (int i = 0; i < dp.length - 1; i++) {
			if (!step[i]) {
				dp[i + 1] = 0;
				continue;
			}
			if (i == 0) {
				dp[i + 1] = 1L;
            	continue;
			}
			dp[i + 1] = dp[i] + dp[i - 1];
			dp[i + 1] %= mod;
		}
		System.out.println(dp[step.length]);
	}
}

Measured memory_bytes: 47872
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 16
#define INF 0x3f3f3f3f
using namespace std;

int a[MAX_N];
int x[MAX_N][MAX_N];
int y[MAX_N][MAX_N];

int counter2(int x){
    if(x == 0) return 0;
    else return (counter2( x>> 1) + (x & 1));
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    for(int i =1;i<=n;i++){
        cin>>a[i];
        for(int j = 1; j <= a[i]; j++){
            cin>>x[i][j]>>y[i][j];
        }
    }
    int maxh = 0;
    for(int bit = 1; bit< (1<<n); bit++){
        bool flag = true;
        for(int i = 1; i<=n;i++){
            if(!(bit&(1<<(i-1)))) continue;
            for(int j =1; j <= a[i]; j++){
                if(((bit>>(x[i][j]-1))&1)^y[i][j]) flag = false;
            }
        }
        if(flag) maxh = max(maxh,counter2(bit));
    }
    cout<< maxh <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

		boolean a[] = new boolean[10001];
		Arrays.fill(a, true);
		a[0]=a[1]=false;
		for(int i=2; i*i<=10000; i++)
		{
			if(!a[i])
				continue;
			for(int j=i*2; j<=10000; j+=i)
				a[j]=false;		
		}

		while(sc.hasNext())
		{
			int ans =0;
			int n = sc.nextInt();
			for(int i=1; i<=n; i++)
			{
				if(a[i]&&a[n-i+1])
				{
					ans++;
				}
			}
			System.out.println(ans);
		}

	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    int x,a,b;
    while(~scanf("%d%d%d",&x,&a,&b))
    {
        if(abs(x-a)>abs(x-b))
        {
            printf("B\n");
        }
        else
            printf("A\n");
    }
}

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

using namespace std;

int main(void) {
	long long int count = 0;
	int n;
	
	cin >> n;

	vector<int> a(n + 1), b(n + 1);

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

	for (int i = n; i >= 1; i--) {
		if ((a[i] + count) % b[i] != 0) {
			count += b[i] - ((a[i] + count) % b[i]);
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1024
/*
ID: Sho10
LANG: C++
TASK:race
*/
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll a,b;
int32_t main(){
CODE_START;
cin>>a>>b;
a=a+b-1;
cout<<a/b<<endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
    int i,j;
    string a,b;
    cin>>a>>b;
    int n=a.length();
    int m=b.length();
    int l[n+1][m+1];
    for(i=0;i<n+1;i++)
    {
        for(j=0;j<m+1;j++)
        {
            if(i==0 || j==0)
                l[i][j]=0;
            else if(a[i-1]==b[j-1])
                l[i][j]=1+l[i-1][j-1];
            else
                l[i][j]=max(l[i-1][j],l[i][j-1]);
        }
    }
    i=n;j=m;
    vector<char> ans;
    while(l[i][j])
    {
        if(a[i-1]==b[j-1])
        {
            ans.push_back(a[i-1]);
            i--;
            j--;
        }
        else if(l[i-1][j]>l[i][j-1])
            i--;
        else
            j--;
    }
    reverse(ans.begin(),ans.end());
    for(i=0;i<ans.size();i++)
    {
        cout<<ans[i];
    }
    return 0;
}


Measured memory_bytes: 35456
#! /usr/bin/python
# -*- coding: utf-8 -*-

(N, A, B, C, X) = map(int, raw_input().split())
while N != 0:
    Y = map(int, raw_input().split())
    F = -1
    p = 0
    for i in range(10001):
        if X == Y[p]:
            p += 1
            if p >= N:
                F = i
                break
        X = (A*X+B)%C

    print F
    (N, A, B, C, X) = map(int, raw_input().split())

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

int main() {
  int M,D;
  cin >> M >> D;
  int c = 0;
  for(int i =1;i<=M;i++){
    for(int j = 1;j<=D;j++){
      int d10 = j/10;
      int d1 = j%10;
      
      if(d10 >= 2 && d1 >= 2 && i == d1*d10) c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 384
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define sz(a)  int((a).size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define CLR(a) memset((a), 0, sizeof(a))
#define INF (1 << 31) - 1
const int dh[8] = {-1, 1, 0, 0,1,1,-1,-1};
const int dw[8] = {0, 0, 1, -1,1,-1,1,-1};
typedef long long ll;
typedef pair<int, int> p;
typedef vector <int> VI;
typedef vector <string> VS;

vector <int> his;

int main(){

	ll s,c;
	cin >> s;
	cin >> c;

	if(c <= 2 * s ){
		cout << c / 2 << endl;
	}else{
		cout << s + ((c - 2 * s) / 4) << endl;		
	}

	return 0;	
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while (true) {
			int n = s.nextInt();
			int r = s.nextInt();
			if (n == 0 && r == 0) {
				break;
			}
			int[] values = new int[n];
			for (int i = 0; i < values.length; i++) {
				values[i] = n - i;
			}
			for (int i = 0; i < r; i++) {
				int p = s.nextInt();
				int c = s.nextInt();
				for (int k = p; k > 1; k--) {
					int a = values[k - 2];
					for (int l = 0; l < c; l++) {
						values[k + l - 2] = values[k + l - 1];
					}
					values[k + c - 2 ] = a;
				}

			}
			System.out.println(values[0]);
		}
	}
}

Measured memory_bytes: 28300
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <math.h>

#define INT_MAX       2147483647

using namespace std;

void solve()
{
	int n, k;
	cin >> n >> k;
	if (n*k % 2 == 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

int main()
{

	solve();
	return 0;
}


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

using namespace std;


struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;

typedef vector<int> V;
typedef vector<V> VV;
typedef VV Graph;

const LL MOD=1e9+7;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0,j=1;j<n;i++,j++)
        if(s[i]==s[j]){
            cout<<i+1<<" "<<j+1<<endl;
            return 0;
        }
    for(int i=0,j=2;j<n;i++,j++)
        if(s[i]==s[j]){
            cout<<i+1<<" "<<j+1<<endl;
            return 0;
        }
    
    cout<<"-1 -1"<<endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int64_t money=1000;
  int64_t stock=0;
  for(int i=0;i<N-1;i++){
    if(A[i+1]>A[i]){
      stock+=money/A[i];
      money%=A[i];
      money+=A[i+1]*stock;
      stock=0;
    }
  }
  cout<<money<<endl;
  return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
 
int main()
{
 int num[10]; 
 int i = 0;
 int n;
 while(scanf("%d",&n)!=EOF)
 {
  if((n == 0)&&(i > 0))
  {
    printf("%d\n",num[i-1]);
    i -= 2;
  }else num[i] = n;
  i++;
 }
 return 0;
}

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

int main() {
	int n;
	cin>>n;
	double ans = 0.0000000;
	for(int i=0;i<n;++i) {
		double x;
		string y;
		cin>>x>>y;
		if(y == "BTC") {
			ans += 380000.00000*x;
		} else {
			ans += x;
		}
	}
	printf("%.5f",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
int main() {
  string s,t;
  cin >> s >> t;
  ll k=s.size();
  bool b=false;
  rep(i,k){
    bool a=true;
    rep(j,k){
      if(s[j]!=t[(i+j)%k]){
        a=false;
      }
    }
    if(a)
      b=true;
  }
  if(b){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import sys

def to_str(symbol, num):
    return '{0} {1}'.format(symbol, num)

if __name__ == '__main__':
    symbols = ['S','H','C','D']
    cards = [to_str(x,y) for x in symbols for y in range(1,14)]
    n = int(input())
    if n == 52: sys.exit()
    for i in range(n):
        cards.remove(input())
    print('\n'.join(cards))

Measured memory_bytes: 6724
def triangle(args)
  args.sort.each_cons(3) do |a, b, c|
    a**2 + b**2 == c**2 ? puts("YES") : puts("NO")
  end
end

gets.chomp.to_i.times do
  triangle(gets.chomp.split(' ').map! { |elm| elm.to_i })
end

Measured memory_bytes: 6116
n,h = map(int, input().split())
list_ken = []
for i in range(n):
    list_ken.append(list(map(int, input().split())))
max_kiri = 0
for i in range(n):
    if max_kiri < list_ken[i][0]:
        max_kiri = list_ken[i][0]
sum_nage = 0
count_nage = 0
list_nage = []
for i in range(n):
    if list_ken[i][1] >= max_kiri:
        sum_nage += list_ken[i][1]
        list_nage.append(list_ken[i][1])
        count_nage += 1

list_nage.sort(reverse = True)

if (h - sum_nage) < 0:
    i = 0
    while h > 0:
        h -= list_nage[i]
        i += 1
    print(i)

elif (h - sum_nage) % max_kiri == 0:
    print((h-sum_nage) // max_kiri + count_nage)
else:
    print((h-sum_nage)//max_kiri + 1 + count_nage)


Measured memory_bytes: 28548
#include <iostream>
#include <map>
#include <set>
int main()
{
    int n;
    double k;
    std::cin >> n >> k;
    std::set<int> nums;
    std::map<int,double> num_counts;
    for(int i=0;i<n;i++)
    {
        int a,b;
        std::cin >> a >> b;
        nums.insert(a);
        num_counts[a]+=b;
    }
    double  counts=0;
    for(auto num : nums)
    {
        counts += num_counts[num];
        if(k<=counts)
        {
            std::cout << num;
            break;
        }
    } 
}

Measured memory_bytes: 7168
#include <stdio.h>

int main(void){
  int n;
  scanf("%d", &n);
  int s[n];
  for(int i=0; i<n; i++) scanf("%d", &s[i]);
  
  int q;
  scanf("%d", &q);
  int t[q];
  for(int i=0; i<q; i++) scanf("%d", &t[i]);
  
  int cou=0;
  for(int i=0; i<q; i++){
    for(int j=0; j<n; j++){
      if(t[i]==s[j]){
        cou++;
        break;
      }
    }
  }
  
  printf("%d\n", cou);
  return 0;
}




Measured memory_bytes: 2104
a,b,c,d=map(int,input().split());m=998244353;n=6011;x=range(c+d);D=[[0]*6011for _ in[0]*6011];D[a][b]=1
for i in x:
 for j in x:D[i+1][j+1]+=(D[i+1][j]*(i+1)+D[i][j+1]*(j+1)-D[i][j]*i*j)%m
print(D[c][d])

Measured memory_bytes: 351192