akhauriyash/Code-Regression huggingface dataset:
#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;}

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

    ll n;
    cin >> n;
    ll a[n];
    rep(i, 0, n) cin >> a[i];
    ll cnt = 0;
    rep(i, 0, n) {
        if(a[i] < 0) {
            cnt++;
            a[i] *= -1;
        }
    }

    sort(a, a + n);
    ll rsl = 0;
    rep(i, 0, n) rsl += a[i];
    if(cnt % 2 == 0) cout << rsl << endl;
    else cout << rsl - 2 * a[0] << endl;
}


Measured memory_bytes: 1024
main :: IO ()
main = do
  line <- getLine
  let a:b:_ = map (\x -> read x::Int) $ words line
  case () of
    _
      | a < b  -> putStrLn "a < b"
      | a > b  -> putStrLn "a > b"
      | a == b -> putStrLn "a == b"



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

int key(int x)
{
  int s = 0, m = 0;
  for (int i = 2; i <= x; i++) {
    if (x % i == 0) {
      s += i;
      m = i;
      while (x % i == 0) {
        x /= i;
      }
    }
  }
  return m - (s-m);
}

int main()
{
  int a, b;
  while (cin >> a >> b && a != 0) {
    cout << (key(a) > key(b) ? 'a' : 'b') << endl;
  }
  return 0;
}

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

#define M 100005
int n,m;
char a[M],b[M];

map <int,int> st;

inline int gcd(int x,int y) {return y?gcd(y,x%y):x;}

int main () {
	//freopen("a.in","r",stdin);
	scanf("%d%d",&n,&m);
	scanf("%s%s",a+1,b+1);
	ll L=1ll*n/gcd(n,m)*m;
	for1(1,n,i) st[L/n*(i-1)+1]=a[i];
	for1(1,m,i) {
		int pos=L/m*(i-1)+1;
		if(st.count(pos)&&st[pos]!=b[i]) return puts("-1"),0;
	}
	cout<<L<<endl;
}

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

int main() {
	int a,b,c,k; scanf("%d%d%d%d",&a,&b,&c,&k);
	int ans = min(a,k);
	if (a+b<k) {
		ans-=min(k-a-b,c);
	}
	printf("%d",ans);
}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)  //a~(b - 1)まで
#define print(i) cout << i << endl //気持ち分Pythonてきな
#define all(i) (i).begin(),(i).end() //全選択(sortとか)
#define mp make_pair //mp(OO, OO)とか:::pintとか

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
/*-------------------------------*/

int main(void)
{
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int a, b;
  if (n > k){
    a = k * x;
    b = (n - k) * y;
    print(a + b);
  }
  else{
    print(n * x);
  }

  return 0;
}


Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, i; cin >> n >> i;
    cout << n - i + 1 << endl;
}

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

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

using namespace std;

typedef long long lint;

lint poz(lint a)
{
    if(a < 0)
        return (-a);

    return a;
}

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

    if(a > b)
        swap(a, b);

    lint mn = n;

    if(poz(a - b) % 2 == 0)
        mn = (poz(a - b) >> 1);

    mn = min({mn, max(a - 1, b - 1), max(n - a, n - b)});

    if(poz(a - b) & 1)
    {
        mn = min(mn, a + ((b - a) - 1) / 2);
        mn = min(mn, n - b + 1 + (n - (a + n - b + 1)) / 2);
    }

    cout << mn << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]){
            Scanner sc = new Scanner(System.in);
            int A = Integer.parseInt(sc.next());
            int B = Integer.parseInt(sc.next());
            int C = Integer.parseInt(sc.next());
            int D = Integer.parseInt(sc.next());

            while(A > 0 && C > 0){
                C-=B;
                if(C > 0){
                    A-=D;
                }
            }

            if(C <= 0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }

            sc.close();
    }

}

Measured memory_bytes: 35648
n = gets.to_i
a = gets.split.map(&:to_i)

def partition(a, p, r)
  x = a[r]
  i = p-1
  (p..r-1).each do |j|
    if a[j] <= x
      i += 1
      t = a[i]
      a[i] = a[j]
      a[j] = t
    end
  end
  t = a[i+1]
  a[i+1] = a[r]
  a[r] = t
  return i + 1
end

q = partition(a, 0, n-1)

ans = []
a.each_with_index do |x, i|
  if i == q
    ans << "[#{x}]"
  else
    ans << x.to_s
  end
end
puts ans.join(" ")


Measured memory_bytes: 14832
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    int c=input.nextInt();
    if(a>=1 && b>=1 && c>=1 && a<=10000 && b<=10000 && c<=10000)
    {
      int temp=a;
      a=a+b;
      b=b+c;
      c=c+temp;
      if(a<b && a<c)
      {
        System.out.println(a);
      }else
      if(b<c && b<a)
      {
        System.out.println(b);
      }else
      if(c<a && c<b)
      {
        System.out.println(c);
      }else
      if(a==b && b==c)
      {
        System.out.println(a);
      }
    }
  }
}

Measured memory_bytes: 21844
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
using namespace std;
typedef long long ll;
const int maxn = 500000 + 5;
int n, N, Q;
int a[maxn], tree[maxn];
struct Query{
    int l, r, id;
    bool operator < (const Query &x) const {
        return r < x.r;
    }
}q[maxn];
int lst[maxn], ans[maxn];
void update(int x, int k) {
    for(int i = x; i <= n; i += lowbit(i))
        tree[i] += k;
}
int query(int x) {
    int ret = 0;
    for(int i = x; i; i -= lowbit(i))
        ret += tree[i];
    return ret;
}
int main() {	
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> Q;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= Q; ++i) cin >> q[i].l >> q[i].r, q[i].id = i;
    sort(q + 1, q + Q + 1);
    int pos = 1;
    for(int i = 1; i <= Q; ++i) {
        for(pos; pos <= q[i].r; ++pos) {
            if(lst[a[pos]]) update(lst[a[pos]], -1);
            lst[a[pos]] = pos;
            update(pos, 1);
        }
        ans[q[i].id] = query(q[i].r) - query(q[i].l - 1);
    }
    for(int i = 1; i <= Q; ++i)
        cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 17356
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a[3] = {}, val[3] = {1, 0, -1};
    for (int i = 0; i < 3; i++) cin >> a[i];
    int k; cin >> k;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        int mi = min(k, a[i]);
        ans += mi * val[i], k -= mi;
    }
    cout << ans;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main() {
    ll a,b;
    cin>>a>>b;
    bitset<32> A(a),B(b);
    cout<<(A&B)<<endl;
    cout<<(A|B)<<endl;
    cout<<(A^B)<<endl;
    
}




Measured memory_bytes: 3172
#include <stdio.h>
int main() {
  int a[6];
  int k;
  for (int i = 0; i < 5; i++) {
    scanf("%d",&a[i]);
  }
  scanf("%d",&k);
  if (k<a[4]-a[0]) {
    printf("%s\n",":(" );
    return 0;
  }
  printf("%s\n","Yay!");
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
const int N=100005,mo=1000000007;
int deg[N],a[N],vis[N],b[N],cnt[N],f[N];
bool u[N];
int calc(int x,int y){return (x<y)+(x<=y);}
int main(){
	int n,ans=1;
	scanf("%d\n",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		deg[a[i]]++;
	}
	for (int i=1;i<=n;i++)
	if (!vis[i]){
		int j=i;
		for (;!vis[j];j=a[j]) vis[j]=i;
		if (vis[j]==i)
			for (;!u[j];j=a[j]) u[j]=1;
	}
	for (int i=1;i<=n;i++)
	if (!deg[i]){
		int j=i,k=0;
		for (;!u[j];j=a[j]) k++;
		b[j]=k;
	}
	else if (deg[i]>u[i]+1) ans=0;
	for (int i=1;i<=n && ans;i++)
	if (u[i]){
		int x=0,y=0,k=0;
		for (int j=i;u[j];j=a[j]){
			k++;u[j]=0;
			if (b[j]){
				if (!x) x=b[j],y=k;
					else ans=ans*calc(b[j],k)%mo;
				k=0;
			}
		}
		if (!x) cnt[k]++;
			else ans=ans*calc(x,y+k)%mo;
	}
	for (int i=1;i<=n && ans;i++){
		int x=(i&1)+(i>1);f[0]=1;
		for (int j=1;j<=cnt[i];j++){
			f[j]=f[j-1]*x%mo;
			if (j>1) f[j]=(f[j]+1ll*(j-1)*i%mo*f[j-2])%mo;
		}
		ans=1ll*ans*f[cnt[i]]%mo;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1792
use proconio::input;

fn main() {
    input! {
        h_1: u16,
        m_1: u16,
        h_2: u16,
        m_2: u16,
        k: u16,
    };
    println!("{}", (h_2*60+m_2) - (h_1*60+m_1) - k);
}


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


int main(void) {
  int n, cnt;
  int p[20];

  scanf("%d", &n);
  for (int i=0;i<n;i++) {
    scanf("%d", p+i);
  }

  cnt = 0;
  for (int i=0;i<n-2;i++) {
    if (p[i] < p[i+1] && p[i+1] <= p[i+2]) {
      cnt++;
    } else if (p[i+2] < p[i+1] && p[i+1] <=p[i]) {
      cnt++;
    }
  }

  printf("%d\n", cnt);
  return 0;
}

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

int main()
{
    int n;
    cin>>n;
  	if(n%1000==0) cout<<0;
    else if(n>=1000) cout<<(((n/1000)+1)*(1000)-(n));
    else{
        cout<<((1000-n));
    }
    return 0; 
}


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

int main()
{
  string S;
  cin >> S;

  if (S == "abc")
  {
    cout << "Yes" << endl;
    return 0;
  }
  if (S == "acb")
  {
    cout << "Yes" << endl;
    return 0;
  }
  if (S == "bac")
  {
    cout << "Yes" << endl;
    return 0;
  }
  if (S == "bca")
  {
    cout << "Yes" << endl;
    return 0;
  }
  if (S == "cab")
  {
    cout << "Yes" << endl;
    return 0;
  }
  if (S == "cba")
  {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
bool test(const vector<int>& A, int k)
{
    int last = 0;
    if (k == 1) {
        for (int a : A) {
            if (a <= last) return false;
            last = a;
        }
        return true;
    }
    map<int, int> m;
    for (int a : A) {
        if (a <= last) {
            m[a] += 1;
            m.erase(++m.find(a), m.end());
            int b = a;
            while (b > 0 && m[b] >= k) {
                m[b] = 0;
                m[b-1]++;
                b--;
            }
            if (b == 0) return false;
        }
        last = a;
    }
    return true;
}
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto& a : A) cin >> a;
    int lo = 0, hi = N;
    while (hi - lo > 1) {
        int mid = (lo + hi) / 2;
        (test(A, mid) ? hi : lo) = mid;
    }
    cout << hi << endl;
    return 0;
}


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

vector<int> a;
int main(){
    int N, x;
    cin >> N >> x;
    for (int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(),a.end());
    int sum = 0;
    int ans = 0;
    for (int i=0; i < a.size(); i++){
        sum += a[i]; 
        if (x < sum){
            break;
        }
        if (i == a.size()-1){
            if (x != sum){
                break;
            }
        }
        ans++;
    }

    printf("%d",ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){

   ll n, k;
   cin>>n>>k;

  COMinit();

   REP(i, k){
     ll ans;
     ans = COM(n-k+1, i+1)%MOD;
     ans *= COM(k-1, i)%MOD;
     ans = ans%MOD;
     cout<<ans<<endl;
   }

  return 0;
  
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())

point_list = [K for i in range(N)]

for i in range(Q):
  num = int(input()) - 1
  point_list[num] += 1

for i in point_list:
  i -= Q
  if i > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 6740
#include <stdio.h>
int main(void)
{
   int a,b,d,r;
   double f;
   scanf("%d %d",&a,&b);
   d=a/b;
   r=a%b;
   f=(double)a/(double)b;
   printf("%d %d %.8lf",d,r,f);
   return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    double d = Double.parseDouble(str[1]);
    int[] x = new int[n];
    int[] y = new int[n];
    int count = 0;
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      x[i] = Integer.parseInt(str[0]);
      y[i] = Integer.parseInt(str[1]);
      double diff = Math.sqrt(Math.pow(x[i],2)+Math.pow(y[i],2));
      if(diff<=d) {
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 58248
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main(){
	fast_io;
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a; i<=b;i++){
		if(i%k==0){cout<<"OK";return 0;}
	}
	cout<<"NG";

	
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX_SEQ 1000

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

  for(int i=0;i<n;i++) {
    char seq1[MAX_SEQ+1];
    char seq2[MAX_SEQ+1];
    vector<char> seq_sub;
    cin >> seq1;
    cin >> seq2;
    int seq1_len = 0;
    int seq2_len = 0;
    while(seq1[seq1_len] != '\0')
      seq1_len++;
    while(seq2[seq2_len] != '\0')
      seq2_len++;

    /*
    cout << "length" << endl;
    cout << seq1_len << endl;
    cout << seq2_len << endl;
    */

    int lcs[seq1_len+1][seq2_len+1];
    for(int i=0;i<=seq1_len;i++)
      lcs[i][0] = 0;
    for(int i=0;i<=seq2_len;i++)
      lcs[0][i] = 0;

    for(int i=1;i<=seq1_len;i++) {
      for(int j=1;j<=seq2_len;j++) {
        int s1_it = i-1;
        int s2_it = j-1;
        if(seq1[s1_it] == seq2[s2_it]) {
          lcs[i][j] = lcs[i-1][j-1] + 1;
        }
        else {
          lcs[i][j] = max(lcs[i][j-1],lcs[i-1][j]);
        }
      }
    }
    /*
    cout << "lcs[i][j]" << endl;
    for(int i=0;i<=seq1_len;i++) {
      for(int j=0;j<=seq2_len;j++) {
        cout << lcs[i][j] << " ";
      }
      cout << endl;
    }
    */

    cout << lcs[seq1_len][seq2_len] << endl;
  }
}

Measured memory_bytes: 5080
#include<bits/stdc++.h>
using namespace std;
long long n,k,r,s,p,i,ans,a;
string t;
int main()
{
	cin>>n>>k>>r>>s>>p;
	cin>>t;
	for(i=0;i<n-k;i++)
	{
		if(t[i]==t[i+k])
		 t[i+k]='0';	
	}
	for(i=0;i<n;i++)
	{
		if(t[i]=='r')ans+=p;
		if(t[i]=='p')ans+=s;
		if(t[i]=='s')ans+=r;	
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;
 
//const long long INF = 1LL << 55;
 
#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MAX_P 200020
   
int main(){
   ioboost;
   int n;cin >> n;
   vector<ll> a(n);rep(i,n)cin >> a[i];

   ll ans = 0;
   ll min_p = 1;
   rep(i,n){
      if(!i){
         ans += a[i] - 1;
         min_p++;
         continue;
      }
      if(a[i] == min_p)min_p++;
      else{
         if(a[i] % min_p == 0){
            a[i] -= min_p + 1;ans++;
            ans += a[i] / min_p;
            // ans += a[i] / (min_p + 1);
         }else{
            ans += a[i] / min_p;
         }
      }
   }
   cout << ans << endl;
}

Measured memory_bytes: 1024
N,K=map(int,input().split())
sunuke=[0]*N
count=0
for _ in range(K):
  d=int(input())
  has=list(map(int,input().split()))
  for i in range(N):
    for j in range(d):
      if i+1==has[j]:
        sunuke[i]=1
for i in range(N):
  if sunuke[i]==0:
    count+=1
print(count)



Measured memory_bytes: 9052
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <chrono>
#include <random>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<i64, i64>;

int main() {
    string s;
    cin >> s;
    
    string a, b;
    for (char c: s) {
        if (c != 'x') {
            a.push_back(c);
        }
    }
    b = string(a);
    reverse(b.begin(), b.end());
    if (a != b) {
        cout << -1 << endl;
        return 0;
    }
    
    vi interval;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != 'x') {
            interval.push_back(cnt);
            cnt = 0;
        } else {
            cnt++;
        }
    }
    
    interval.push_back(cnt);
    int ans = 0;
    for (int i = 0; i < interval.size(); i++) {
        ans += abs(interval[i] - interval[interval.size() - 1 - i]);
    }
    cout << ans / 2 << endl;
}


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

using namespace std;

using ll = long long;

const int INF = 1001001001;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M, L;
  cin >> N >> M >> L;
  vector<vector<int>> dist(N, vector<int>(N, INF));
  for (int i = 0; i < M; ++i) {
    int A, B, C;
    cin >> A >> B >> C;
    --A;
    --B;
    dist[A][B] = dist[B][A] = C;
  }
  for (int i = 0; i < N; ++i) dist[i][i] = 0;
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  vector<vector<int>> dist2(N, vector<int>(N, INF));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (dist[i][j] <= L) dist2[i][j] = 1;
    }
  }
  for (int i = 0; i < N; ++i) dist2[i][i] = 0;
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
      }
    }
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int s, t;
    cin >> s >> t;
    --s, --t;
    int ans = dist2[s][t] - 1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
}


Measured memory_bytes: 1280
def process():
  count = int(input())
  nums_str = input().split()
  nums_int = []
  for strn in nums_str:
    nums_int.append(int(strn))

  if 0 in nums_int:
    result = 0
    return result
  else:
    result = 1
    for intn in nums_int:
      result *= intn
      if result > 1000000000000000000:
        result = -1
        return result
    return result
    
print(process())

Measured memory_bytes: 21652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265359
#define MOD 998244353
const int MAX = 510000;

int main() {
  int N;cin>>N;
  map<char,ll> score;
  rep(i,N){
   string s;
   cin>>s;
   char q=s[0]; 
   if(q=='M'||q=='A'||q=='R'||q=='C'||q=='H'){
   score[q]++;}
  }
  ll m[5];
  m[0]=score['M'];
  m[1]=score['A'];
  m[2]=score['R'];
  m[3]=score['C'];
  m[4]=score['H'];
  ll ans=0;
  ans+=m[0]*m[1]*m[2];
  ans+=m[0]*m[1]*m[3];
  ans+=m[0]*m[1]*m[4];
  ans+=m[0]*m[2]*m[3];
  ans+=m[0]*m[2]*m[4];
  ans+=m[0]*m[3]*m[4];
  ans+=m[1]*m[2]*m[3];
  ans+=m[1]*m[2]*m[4];
  ans+=m[1]*m[3]*m[4];
  ans+=m[2]*m[3]*m[4];
  cout<<ans;
}

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

int main(){
    int x,y;
    cin>>x>>y;
    if(y%2!=0)
    cout<<"No";
    else{
        int l=x*2;
        int h=x*4;
        if(y>=l && y<=h)
        cout<<"Yes";
        else
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3676
S=input()
if S=="SSS":
    print(0)
elif S=="SSR":
    print(1)
elif S=="SRS":
    print(1)
elif S=="RSS":
    print(1)
elif S=="SRR":
    print(2)
elif S=="RSR":
    print(1)
elif S=="RRS":
    print(2)
else:
    print(3)

Measured memory_bytes: 9068
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;


void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}


void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}


void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2100
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

signed main(void)
{
	string o, e;
	cin >> o >> e;

	REP(i, o.size()+e.size()) {
		if(i%2) cout << e[i/2];
		else cout << o[i/2];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int A[9];
int perm[9];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  rep(i, 9) cin >> A[i];
  rep(i, 9) perm[i] = i+1;
  int s = 0;
  do {
    bool ok = true;
    rep(i, 9) {
      if (A[i] != -1 && A[i] != perm[i]) ok = false;
    }
    if (!ok) continue;
    if (perm[0] + 10*perm[1]+perm[2] + 100*perm[3] + 10*perm[4] + perm[5] == 100*perm[6] + 10*perm[7] + perm[8]) s++;
  }
  while (next_permutation(perm, perm+9));
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 3176
'use strict'

const main = arg => {
 const input = arg.trim().split("\n").map(num => parseInt(num, 10));
 const result = input.filter(num => num !== 0).map((num,i) => "Case "+(i+1)+": "+num);

 console.log(result.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 20524
import std.stdio;
import std.algorithm;
import std.conv;

void main(string[] args)
{
	int[] values;
	values.length = 10;

	foreach(int i;0..10)
	{
		readf("%d\n",&values[i]);
	}
	static bool greater(int x,int y)
	{
		return x > y;
	}
	sort!(greater)(values);
	foreach(int i;0..3)
	{
		writeln(values[i]);
	}
}

Measured memory_bytes: 1076
class SegmentTree:
	def __init__(self, orig, func, unit):
		_len = len(orig)
		self.func = func
		self.size = 1 << (_len - 1).bit_length()
		self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
		self.unit = unit

		for i in range(self.size - 1, 0, -1):
			self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])

	def update(self, i, v):
		i += self.size
		self.tree[i] = v
		while i:
			i //= 2
			self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

	def find(self, l, r):
		l += self.size
		r += self.size
		ret = self.unit
		while l < r:
			if l & 1:
				ret = self.func(ret, self.tree[l])
				l += 1
			if r & 1:
				r -= 1
				ret = self.func(ret, self.tree[r])
			l //= 2
			r //= 2
		return ret


def main():
	N, Q, *L = map(int, open(0).read().split())
	tree = SegmentTree([(1 << 31) - 1] * N, min, (1 << 31) - 1)
	ans = []
	for c, x, y in zip(*[iter(L)] * 3):
		if c:
			ans.append(tree.find(x, y + 1))
		else:
			tree.update(x, y)
	print(*ans, sep="\n")


if __name__=="__main__":
	main()



Measured memory_bytes: 29220
L=input()
MOD=10**9+7
l=len(L)
dp1=[0]*(l+1)
dp2=[0]*(l+1)
dp2[0]=1
for i in range(l):
    dp1[i]%=MOD
    dp2[i]%=MOD
    if int(L[i])==1:
        dp1[i+1]=3*dp1[i]+dp2[i]
        dp2[i+1]=dp2[i]*2
    else:
        dp1[i+1]=3*dp1[i]
        dp2[i+1]=dp2[i]
ans=dp1[l]+dp2[l]
print(ans%MOD)

Measured memory_bytes: 11084
import java.util.*;

class Main {
	static int n;
	static double[][][] dp;

	public static double dfs(int a, int b, int c) {
		if(a == 0 && b == 0 && c == 0) return 0;

		if(dp[a][b][c] == -1) {
			dp[a][b][c] = 1.0;
			if(a > 0)
				dp[a][b][c] += (1.0*a/n) * dfs(a-1, b+1, c);
			if(b > 0)
				dp[a][b][c] += (1.0*b/n) * dfs(a, b-1, c+1);
			if(c > 0)
				dp[a][b][c] += (1.0*c/n) * dfs(a, b, c-1);
			dp[a][b][c] /= 1-(1.0*(n-(a+b+c))/n);
		}

		return dp[a][b][c];
	}

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

    	n = sc.nextInt();
    	int a = 0;
    	int b = 0;
    	int c = 0;
    	for(int i = 0; i < n; i++) {
    		int tmp = sc.nextInt();
    		if(tmp == 3) a++;
    		if(tmp == 2) b++;
    		if(tmp == 1) c++;
    	}

    	dp = new double[n+1][n+1][n+1];
    	for(double[][] i : dp) for(double[] j : i) Arrays.fill(j, -1);

    	System.out.println(dfs(a, b, c));
    }
}

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	//string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n;

	vector<mint> a(n), s(n + 1, 0);
	rep(i, n) {
		cin >> a[i].x;
		if (i == 0) s[i] = a[i];
		else s[i] = s[i - 1] + a[i];
	}

	mint ans = 0;
	rep(i, n) {
		ans += a[i] * (s[n - 1] - s[i]);
	}

	cout << ans.x << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_c();

	return 0;
}


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

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

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

int main() {
    int w, h;
    char f[20][20];
    while (cin >> w >> h && w && h) {
        int c = 1;
        queue<pair<int, int>> q;
        rep(y,h) {
            rep(x,w) {
                cin >> f[y][x];
                if (f[y][x] == '@') {
                    q.push({x, y});
                    f[y][x] = 'x';
                }
            }
        }
        while (q.size()) {
            pair<int, int> p = q.front(); q.pop();
            for (int i = 0; i < 4; ++i) {
                int nx = p.first+dx[i];
                int ny = p.second+dy[i];
                if (0 <= nx && nx < w && 0 <= ny && ny < h && f[ny][nx] == '.') {
                    ++c;
                    q.push({nx, ny});
                    f[ny][nx] = 'x';
                }
            }
        }
        cout << c << endl;
    }
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int main()
{
	int n, dp[N][3], A[N][3];
	cin >> n;
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; ++i)
	{
		cin >> A[i][0] >> A[i][1] >> A[i][2];
	}
	for (int day = 1; day <= n; ++day)
	{
		for (int event = 0; event < 3; ++event)
		{
			for (int last = 0; last < 3; ++last)
			{
				if(last == event)
					continue;
				dp[day][event] = max(dp[day][event], dp[day - 1][last] + A[day][event]);
			}
		}
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]}); 
}


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

int main()
{
	vector<int> prime;
	for(int i=2;i<=300000;i++){
		if(i%7==1 || i%7==6){
			bool ok=true;
			for(int k=0;k<prime.size();k++){
				if(i%prime[k]==0){ok=false;break;}
			}
			if(ok) prime.push_back(i);
		}
	}

	int n;
	while(cin>>n){
		if(n==1) return 0;
		cout<<n<<":";

		for(int i=0;i<prime.size();i++){
			if(prime[i]>n) break;
			if(n%prime[i]==0) cout<<" "<<prime[i];
		}
		cout<<endl;
	}

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
int A[10001];

int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while(A[i] != key) i++;
    return i!=n; 
}

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

    int n,q;
    cin >> n;
    REP(i, n){
        int x;
        cin >> x;
        A[i] = x;
    }
    cin >> q;
    int ans = 0;
    REP(i, q){
        int x;
        cin >> x;
        ans += search(A, n, x);
    }

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

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,ANS=0;
	vector<ll>V;
	cin>>N;
	rep(i,N){
		ll t;
		cin>>t;
		V.push_back(t);
	}
	rep(i,N-1){
		if(V[i]==V[i+1]){
			V[i+1]=20000-i;
			ANS++;
		}
	}
	cout<<ANS<<endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0)
            break;
        cout << min(x, y) << " " << max(x, y) << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	string str;
	string left="qwertasdfgzxcvb";
	while(cin>>str,str!="#"){
		int i;
		bool pre=true,l;
		int res=0;
		for(i=0;i<str.size();i++){
			l=false;
			int j;
			for(j=0;j<left.size();j++){
				if(str[i]==left[j])l=true;
			}
			if(pre!=l&&i!=0)res++;
			pre=l;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int u[n - 1], v[n - 1], w[n - 1];
    vector<pair<int, int>> g[n];
    rep(i, 0, n - 1) {
        cin >> u[i] >> v[i] >> w[i];
        u[i]--;
        v[i]--;
        g[u[i]].push_back(make_pair(v[i], w[i]));
        g[v[i]].push_back(make_pair(u[i], w[i]));
    }

    int color[n];
    rep(i, 0, n) color[i] = -1;

    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    color[0] = 0;
    int cnt = 0;
    while (!q.empty()) {
        int now = q.front().first;
        q.pop();
        for (int i = 0; i < (int)g[now].size(); i++) {
            if (cnt == n) break;
            int next_pos = g[now][i].first;
            int next_cost = g[now][i].second;
            if (color[next_pos] != -1) continue;
            q.push(make_pair(next_pos, next_cost));
            if (color[now] == 0) {
                if (next_cost % 2 == 0) color[next_pos] = 0;
                else color[next_pos] = 1;
                cnt++;
            } else {
                if (next_cost % 2 == 0) color[next_pos] = 1;
                else color[next_pos] = 0;
                cnt++;
            }
            if (cnt == n) break;
        }
        if (cnt == n) break;
    }

    rep(i, 0, n) cout << color[i] << endl;
    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
  int N = inputValue();
  int A[20];
  int B[20];
  int C[20];
  inputArray(A, N);
  inputArray(B, N);
  inputArray(C, N-1);
  int ans = 0;
  REP(i, N){
    int index = A[i] - 1;
    ans += B[index];
    if(i > 0){
      int preindex = A[i-1] - 1;
      if(index == preindex + 1){
        ans += C[preindex];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int s;
    cin >> s;
    int y=s/100;
    int m=s-y*100;

    if(0<y && y<=12 && 0<m && m<=12){
        cout << "AMBIGUOUS" << endl;
    }else if(0<y && y<=12 && (m>12 || m==0)){
        cout << "MMYY" << endl;
    }else if((y==0 || y>12) && 0<m && m<=12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;

    }
}

Measured memory_bytes: 3560
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]

ab.sort(key = lambda x:x[1],reverse = True)
ans = 0
damage = 0
flag = True
maxA = max(ab)
maxA = maxA[0]
for a,b in ab:
    if maxA > b:
        break
    damage += b
    ans += 1
    if damage >= H:
        flag = False
        break

if flag:
    if (H-damage)%maxA == 0:
        ans += (H-damage)//maxA
    else:
        ans += (H-damage)//maxA + 1
    print(ans)
    
else:
    print(ans)

Measured memory_bytes: 28968
def main():
    a,b,x = map(int,input().split())
    S = x/a
    import math
    if S >= (a*b)/2:
        tan = 2*(a*b-S)/(a**2)
        print(math.degrees(math.atan(tan)))
    else:
        tan = 2*S/(b**2)
        print(90-math.degrees(math.atan(tan)))
    
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void){
    
    int drugnumber;
    int drugcounter;
    /* x????¨????,y?????´????????? */
    double drugeffect[120][120] = {0};
    int i,j,k,l;
    double max = 0;
    double answer[100] = {0};
    
    while(cin >> drugnumber >> drugcounter,drugnumber+drugnumber)
    {
        double combination[120][120] = {0};
        /*??£??\*/
        FOR(j, 1, drugnumber+1)
        FOR(i, 1, drugnumber+1)
        cin >> drugeffect[j][i];
        
        //cout << drugeffect[2][1];
        
        for(k = 1;k <= drugnumber; k++)
            combination[1][k] = 1.0;
        //cout << combination[1][2] << endl;
        
        /* j?????¬?????°,i????????°*/
        
        for(i = 1; i< drugcounter;i++)
            for(j = 1; j<= drugnumber;j++)
            {
                for(k = 1; k<=drugnumber;k++)
                {
                    if((combination[i][j] * drugeffect[j][k]) >= combination[i+1][k])
                        combination[i+1][k] = combination[i][j]*drugeffect[j][k];
                     //cout << combination[i+1][j] << " ";
                    /*
                     if((combination[j][i] * drugeffect[j][i]) >= combination[j][i])
                     combination[j][i+1] = combination[j][i] * drugeffect[j][i];
                     */
                }
            }
        
    
    for(i = 1 ; i<= drugnumber;i++)
        if(max <  combination[drugcounter][i])
            max = combination[drugcounter][i];
    
        answer[l] = max;
        max = 0;
        l++;
        
    }
    REP(i,l)
    printf("%.2f\n",answer[i]);
    return 0;
    
}

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

long long N, M, a[100009][3], maxn = -(1LL << 60);

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 888