akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

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

string random_str() {
  random_device dev;
  mt19937 rand(dev());
  string r = "";
  rep (i, 8) {
    r += ('a' + rand()%25);
  }
  return r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);

  set<string> used;
  cout << "?az" << endl;

  loop {
    string s; cin >> s;
    if (used.count(s) > 0 or s[0] != 'z') {
      cout << "!OUT" << endl;
      return 0;
    }
    used.insert(s);
    cout << "?" << s[s.size()-1] << random_str() << 'z' << endl;
  }

  return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
#define ff(i,s,n) for(int i=s;i<n;i++)
#define fr(i,s,n) for(int i=n-1;i>=s;i--)
#define llu long long int


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int d,s,t;
	cin>>d>>t>>s;
	int p=(int)ceil((double)d/(double)s);
	if(p<=t){
		cout<<"Yes";
	} else{
		cout<<"No";
	}
}

//1
//7 2
//3 5 4 5 1 1 1


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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);

    string S; cin >> S;

    ll ans = 0;
    for (int i = 0; i<S.size()/2; i++) {
        ll l = i;
        ll r = S.size()-i-1;
        // cout << "l:"<< l<<","<< "S[l]: "<<S[l] << ", r:"<< r<<","<< "S[r]: "<<S[r] << endl;
        if (S[l] != S[r]) ++ans;
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
	int result = 0;
	int n;

	cin >> n;

	vector<int> cuisine(n);
	vector<int> satisfaction(n);
	vector<int> addition(n - 1);

	for (int i = 0; i < n; i++) {
		cin >> cuisine[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> satisfaction[i];
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> addition[i];
	}

	for (int i = 0; i < n; i++) {
		result += satisfaction[cuisine[i] - 1];
		if (i != 0 && cuisine[i] - 1 == cuisine[i - 1]) {
			result += addition[cuisine[i - 1] - 1];
		}
	}

	cout << result;
}

Measured memory_bytes: 256
use std::cmp::max;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut ans = 0;
    if (n as f64).sqrt().fract() == 0.0 {
        ans = ((n as f64).sqrt()) as usize;
    } else {
        let tmp: Vec<usize> = (1..n+1)
            .take_while(|x| x * x <= n)
            .filter(|&x| n % x == 0)
            .collect();
        ans = {
            *tmp.iter()
                .map(|&x| max(x, n / x))
                .collect::<Vec<usize>>()
                .iter()
                .min()
                .unwrap()
        }
    }
    println!("{}", ans.to_string().len());
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>

long double prob(int n, int k)
{
    if (n >= k)
        return 1;
    else 
        return prob(n * 2, k) / 2;
}

int main()
{
    int n, k;
    std::cin >> n >> k;
    long double ans {};
    for (int i {1}; i <= n; ++i)
        ans += prob(i, k);
    std::cout << std::setprecision(9) << ans / n;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
if N>1 and M>1:
  print(N*M-(N*2 + (M-2)*2))
elif N==1 and M>1:
  print(N*M-2)
elif M==1 and N>1:
  print(N*M-2)
else:
  print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    int d[100];
    cin >> n;
    rep(i,n){
        cin >> d[i];
    }

    int ans = 0;
    rep(i, n){
        for(int j=i; j<n; j++){
            if(i != j)
                ans += d[i]*d[j];
        }
    }
    cout << ans;

    return 0;
}

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

using namespace std;



int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int cnt=0;
		for(int i=5; i<=n; i*=5){
			cnt+=n/i;
		}
		cout<<cnt<<endl;
	}
}

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

int main(void){

  int i, j, n;

  scanf("%d", &n);

  for(i=1;i<=n;i++){
    j = i;
    if(i%3 == 0){
      printf(" %d", i);
    }else{
      while(j > 0){
        if(j%10 == 3){
          printf(" %d", i);
          break;
        }
        j /= 10;
      }
    }
  }
  printf("\n");
  return 0;

}



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

int keta(int n1){
  int a=0;
  while(n1!=0){
    n1=n1/10;
    a++;
  }
  return a;
}
  
int main(){
  int N,ans=0;
  scanf("%d",&N);
  int n=keta(N);
  if(n%2==1){
    if (n==1){
      printf("%d",N);
    }
    else{
      for(int i=1;i<n;i++){
        if(i%2==1){
          ans+=9*(pow(10,i-1));
        }
      }
      ans+=N-pow(10,n-1)+1;
      printf("%d",ans);
    }
  }
  else{
    for(int i=0;i<n;i++){
      if (i%2==1){
        ans+=9*(pow(10,i-1));
      }
    }
    printf("%d",ans);
  }
  return 0;
}

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

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

Measured memory_bytes: 3628
n = int(input())
graph = [[] for _ in range(n)]

edge_sum = 0
for _ in range(n - 1):
    u, v = map(int, input().split())
    if u > v:
        u, v = v, u
    edge_sum += u * (n - v + 1)

dot_sum = n * (n + 1) * (n + 2) // 6
print(dot_sum - edge_sum)


Measured memory_bytes: 23428
from itertools import permutations, combinations_with_replacement

def calc(op, x, y):
    if op == "+":
        return x + y
    else:
        return x - y

def solve():
    A, B, C, D = map(int, list(input()))
    OP = combinations_with_replacement(["+", "-"], 3)
    for op in OP:
        O = permutations(op)
        s = set(O)
        for o in s:
            op1, op2, op3 = o
            tmp = calc(op3, calc(op2, calc(op1, A, B), C), D)
            if tmp == 7:
                print(f"{A}{op1}{B}{op2}{C}{op3}{D}=7")
                exit()

if __name__ == "__main__":
    solve()


Measured memory_bytes: 62212
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {
	int k, n;
	cin >> k >> n;
	int l = n - (k - 1);
	int r = n + (k - 1);
	for (int i = l; i <= r; ++i) {
		cout << i << " ";
	}
	cout << endl;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>
#define pL3 pair<pL, ll>

const int MX=1000010;
const ll inf=1e18;
const ll mod=1e9+7;


ll dp[2020];

ll cal(int S)
{
    if(S==0) return 1;
    if(~dp[S]) return dp[S];

    ll ret=0;
    for(int i=3; i<=S; i++)
    {
        ret+=cal(S-i);
        ret%=mod;
    }
    return dp[S]=ret;
}

int main()
{
    FasterIO;

//    int tc, cs=1; cin>>tc;
//    while(tc--)
    {

        ll n;
        cin>>n;

        mem(dp, -1);

        ll ans=cal(n);

        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int cnt = 0;
  while (1) {
    if (a >= b) {
      b *= 2;
      cnt++;
    } else {
      break;
    }
  }

  while (1) {
    if (b >= c) {
      c *= 2;
      cnt++;
    } else {
      break;
    }
  }

  if (cnt <= k) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int INF = 1e9;
int main()
{
	int N;
	string S;
	cin >> N >> S;
	int white = 0, black = 0;
	for(char& c : S)
	{
		if(c == '.') white++;
		else black++;
	}
	int rightWhite = white;
	int leftBlack = 0;
	int ans = min(white, black);
	for(int inx = 0; inx < N; inx++)
	{
		if(S[inx] == '.')
		{
			rightWhite--;
		}
		else
		{
			leftBlack++;
		}
		ans = min(ans, leftBlack + rightWhite);
	}
	cout << ans << endl;
	return 0;
}


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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

#define INF 1000000000;
#define REP(i,n) for(i=0;i<n;i++)

int gcd(int a,int b);
/*比較函数の実装
int -32768 to 32767 (2**15-1)
long -2147483648 to 2147483648 (2**31-1)
*/
int intcmp(const void *a,const void *b){
  return *(int *)a - *(int *)b;
}
//qsort(a,sizeof(a)/sizeof(int),sizeof(int),intcmp);
int longcmp(const void *a,const void *b){
  return *(long *)a - *(long *)b;
}
//qsort(a,sizeof(a)/sizeof(long),sizeof(long),longcmp);
int doublecmp(const void *a, const void *b){
  return *(double *)a - *(double *)b;
}
//qsort(a,sizeof(a)/sizeof(double),sizeof(double),doublecmp);
int main(void)
{
  int p,q,r;
  scanf("%d%d%d",&p,&q,&r);

  int min;
  int max;
  min = MIN(p,MIN(q,r));
  max = MAX(p,MAX(q,r));
  printf("%d",p+q+r-max);

  return 0;
}

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

int main() {
    long long L, R;
    cin >> L >> R;

    R = min(R, L + 2019);

    long long ans = 2018;
    for (long long i = L; i <= R; i++) {
        for (long long j = i + 1; j <= R; j++) {
            ans = min(ans, (i * j) % 2019);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int D = in.nextInt();
            out.println((int) Math.ceil(N / (1.0 + 2 * D)));
        }

    }
}



Measured memory_bytes: 21844
main(){
	int n,m[11][11];
	for(;scanf("%d",&n),n;){
		int i,j;
		for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&m[i][j]);
		for(i=0;i<=n;i++){
			int sum_r=0,sum_c=0;
			for(j=0;j<n;j++)sum_r+=m[i][j],sum_c+=m[j][i];
			m[i][n]=sum_r,m[n][i]=sum_c;
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++)printf("%5d",m[i][j]);
			puts("");
		}
	}
	exit(0);
}

Measured memory_bytes: 0
n, m, _ = gets.split.map(&:to_i)
r = gets.split.map { |z| z.to_i - 1 }
max = 1e10
d = Array.new(n) { Array.new(n, max) }
m.times do
  a, b, c = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  d[a][b] = c
  d[b][a] = c
end
n.times do |k|
  dk = d[k]
  n.times do |i|
    next if i == k
    di = d[i]
    dik = di[k]
    n.times do |j|
      tmp = dik + dk[j]
      di[j] = tmp if tmp < di[j]
    end
  end
end

ans = r.permutation.map do |perm|
  perm.each_cons(2).inject(0) { |sum, (x, y)| sum + d[x][y] }
end.min

p ans


Measured memory_bytes: 2936
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fileio freopen("in","r",stdin);freopen("out","w",stdout);


int main(){
	LL Q, H, S, D, N;
	cin >> Q >> H >> S >> D;
	cin >> N;
	Q *= 8, H *= 4, S *= 2;
	LL X = 0;
	X += (N/2) * min(min(Q, H), min(S, D)); 
	N = N % 2;
	Q /= 2, H /= 2, S /= 2;
	if (N) X += min(min(Q, H), S);
	cout << X;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 6'009;

int a[N];
int b[N];
int f[N];
int nf[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (a[i] > a[j]) {
        swap(a[i], a[j]);
        swap(b[i], b[j]);
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    f[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < N; ++j) {
      nf[j] = f[j];
    }
    for (int j = 0; j < m; ++j) {
      nf[j + a[i]] = max(nf[j + a[i]], f[j] + b[i]);
    }
    for (int j = 0; j < N; ++j) {
      f[j] = nf[j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans = max(ans, f[i]);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, A, B;
  cin>>N>>A>>B;
  int anum=0, bnum=0, cnum=0;
  int tmp;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    if(tmp<=A) anum++;
    else if(tmp<=B) bnum++;
    else cnum++;
  }
  cout<<min(anum, min(bnum, cnum))<<endl;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
pair<char,int> num[100000+10];
pair<char,int> cop[100000+10];

int par(pair<char,int> *A,int las){
  int x = A[las].second;
  int i = -1;
  for(int j=0;j<las;j++){
    if(A[j].second <= x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[las]);
  return i+1;
}
void q_sort(pair<char,int> *A, int len){
  if(len < 1) return ;
  int k = par(A,len);
  q_sort(A,k-1);
  q_sort(A+k+1,len-k-1);
}

void merge(pair<char,int> *A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  pair<char,int> *L, *R;
  L = (pair<char,int>*)malloc(sizeof(pair<char,int>)*(n1+1));
  R = (pair<char,int>*)malloc(sizeof(pair<char,int>)*(n2+1));
  for(int i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(int i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1].second = 2*INF; // 編集
  R[n2].second = 2*INF; // 編集
  int i =0,j = 0;
  for(int k=left;k<right;k++){
    if(L[i].second<=R[j].second){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
  free(L);
  free(R);
}
void mergesort(pair<char,int> *A, int left, int right){
  if(left + 1 < right){
    int mid = (left + right) /2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}
//-----------------------------------------

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

  int n;
  cin >> n;

  REP(i,n) cin >> num[i].first >> num[i].second;

  REP(i,n) cop[i] = num[i];

  mergesort(cop,0,n);
  q_sort(num,n-1);

  bool f = true;
  REP(i,n) if(cop[i] != num[i]) f = false;

  if(f) cout << "Stable"<<endl;
  else cout << "Not stable"<<endl;

  REP(i,n) cout << num[i].first << " " << num[i].second << endl;





  return 0;
}



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

int main(void){
    for(;;){
    bool a[600][600]={{0}};
    bool flag[1000]={0};
    bool fla[1000]={0};
	int n;
	int m;
	int cnt=0;
	cin>>n>>m;
	if(n==0&&m==0)break;

    for(int i=0;i<m;i++){
        int p,q;
        cin>>p>>q;
        if(q==1)swap(p,q);
        if(p==1)flag[q]=1,fla[q]=1;
        a[p][q]=1;
        a[q][p]=1;
    }


    for(int i=2;i<=n;i++){
        for(int j=2;j<=n;j++){
            if(fla[j]==1||fla[i]==1)if(a[i][j]==1)flag[j]=1,flag[i]=1;//,cout<<"-"<<i<<j<<endl;
            //if(fla[j]==1&&a[j][i]==1)fla[i]=1;//,cout<<"+"<<i<<j<<endl;

        }
    }
    for(int i=2;i<=n;i++){
        if(flag[i]==1)cnt++;//,cout<<i<<"-"<<endl;
    }
    cout<<cnt<<endl;

    }
	return 0;
}

Measured memory_bytes: 1520
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,l,r;
  int S = 0;
  cin >> N;
    for(int i=0; i<N; i++) {
      cin >> l >> r;
        S += r-l+1;
    }
  cout << S <<endl;
  }

Measured memory_bytes: 3612
n,m=gets.split.map(&:to_i)
xs = gets.split.map(&:to_i).sort
distances = Array.new(m-1)

(0..xs.length-2).each_with_index do |_, i|
  distances[i] = xs[i+1]-xs[i]
end

distances = distances.sort
ans = distances[0..-n].inject(:+)

p ans || 0

Measured memory_bytes: 11248
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  System.out.print(n > 899 ? "1":"9");
  System.out.print(n%100 > 89 ? "1":"9");
  System.out.println(n%10 > 8 ? "1":"9");
}}

Measured memory_bytes: 21844
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())

    ans = 0
    a, b, ba = 0, 0, 0
    for _ in range(N):
        S = input()
        ans += S.count("AB")

        if S[0] == "B" and S[-1] == "A":
            ba += 1
        elif S[-1] == "A":
            a += 1
        elif S[0] == "B":
            b += 1

    # A B A B
    if a > 0 and ba:
        a -= 1
        ans += ba

        if b > 0:
            ans += 1
            b -= 1
    elif a == 0 and ba:
        ans += ba - 1
        if b > 0:
            ans += 1
            b -= 1

    # A B
    ans += min(a, b)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

const ll L = 1e5+5;

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

    char c;
    cin >> c;

    cout << (char)(c+1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
const ll MOD = 1e9 + 7;

ll N, M;
vector<ll> a;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  a.resize(M);
  for (ll i = 0; i < M; i++) {
    cin >> a[i];
  }

  for (ll i = 0; i < M - 1; i++) {
    if (a[i + 1] - a[i] == 1) {
      cout << 0 << endl;
      return 0;
    }
  }

  vector<ll> ans(N + 1, 0);
  ans[0] = 1;
  ll cur = 0;
  ll start = 2;
  if (M != 0) {
    if (a[cur] == 1) {
      cur++;
      ans[1] = 0;
    } else {
      ans[1] = 1;
    }
  } else {
    ans[1] = 1;
  }

  for (ll i = start; i <= N; i++) {
    if (cur < M && i == a[cur]) {
      ans[i] = 0;
      cur++;
    } else {
      if (ans[i - 1] == 0 && ans[i - 2] == 0) {
        ans[i] = 1;
      } else {
        ans[i] = (ans[i - 1] + ans[i - 2]);
        ans[i] %= MOD;
      }
    }
  }

  // for (auto &e : ans) {
  //   cout << e << endl;
  // }

  cout << ans[N] << endl;
  return 0;
}

Measured memory_bytes: 1408
from collections import Counter
N = int(input())
*S, = map(int, input().split())
C = Counter(S)

memo = [[-1]*(N+1) for i in range(N+1)]
def comb(n, k):
    if memo[n][k] != -1:
        return memo[n][k]
    if k == 0 or n == k:
        return 1
    memo[n][k] = r = comb(n-1, k) + comb(n-1, k-1)
    return r

*CS, = C.items()
CS.sort(reverse=1)
S = [0]
for k, v in CS:
    S.append(S[-1]+v)
T = [0]
for i in range(N+1):
    T.append(T[-1]+comb(N, i))
ok = 1
if len(S) < len(T):
    ok = 0
else:
    ok = all(a <= b for a, b in zip(S, T)) and S[-2] >= 2**(N-1)
print("Yes" if ok else "No")

Measured memory_bytes: 57120
#include "iostream"
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    uint X;
    cin >> X;

    uint Y;
    vector<uint> primes = {2};
    if (X == 2) {
        cout << X;
        return 0;
    } else if ( X == 3) {
        cout << 3;
        return 0;
    }
    for (uint i=3; i <= X/2 + 1; i += 2) {
        bool prime_flg = true;
        for (uint j=0; j < primes.size(); j++) {
            if (i % primes.at(j) == 0) {
                prime_flg = false;
            }
        }
        if (prime_flg == true) {
            if (X == i) {
                cout << i;
                return 0;
            }
            primes.push_back(i);
        }
    }
    // cout << primes.size() << endl;
    if (X % 2 == 0) {
        Y = X + 1;
    } else {
        Y = X;
    }

    while (true){
        bool prime_flg = true;
        for (uint i=0; i < primes.size(); i++){
            if (Y % primes.at(i) == 0) {
                prime_flg = false;
            } 
        }
        if (prime_flg == true) {
            cout << Y << endl;
            return 0;
        }
        Y += 2;

    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	array<long long, 26> count;
	count.fill(0);
	for(auto c : s) ++count[c - 'a'];
	long long ans = s.size() * (s.size() + 1) / 2;
	for(auto x : count) ans -= x * (x + 1) / 2;
	++ans;
	cout << ans << endl;
	return 0;
}


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

const int MAX_N = 10e5;
const int MAX_M = 10e5;

bool is_bipartite(int v, int N, vector<int> G[MAX_N + 1], int color[MAX_N + 1], int cur = 0) {
    color[v] = cur;
    for (int i = 0; i < G[v].size(); i++) {
        int nv = G[v][i];
        if (color[nv] != -1) {
            if (color[nv] == cur) return false;
            continue;
        }
        
        if (!is_bipartite(nv, N, G, color, 1 - cur)) return false;
    }
    return true;
}

int main() {
    // input
    int N, M, A[MAX_M], B[MAX_M];
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> A[i] >> B[i];

    // make graph
    vector<int> G[MAX_N + 1];
    for (int i = 0; i < M; i++) {
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }

    // initialize color
    int color[MAX_N + 1];
    for (int i = 1; i <= N; i++) color[i] = -1;

    if (is_bipartite(1, N, G, color)) {
        int num_white = 0, num_black = 0;
        for (int i = 1; i <= N; i++) {
            if (color[i] == 0) num_white++;
            else num_black++;
        }
        long long ans = 1LL * num_white * num_black - M;
        cout << ans << endl;
    } else {
        long long ans = 1LL * N * (N - 1) / 2 - M;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 36992
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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 long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n, a, b;
ll v[51];
ll cmb[51][51];
 
int main(int argc, char **argv) {
	cin >> n >> a >> b;
	REP(i, n) cin >> v[i];
	sort(v, v + n);
	reverse(v, v + n);
	ll sum = 0;
	REP(i, a) sum += v[i];
	cout << fixed << setprecision(8) << ((double)sum / a) << endl;
	--a; --b;
	int l = a, r = a;
	while (l > 0 && v[l - 1] == v[a]) --l;
	while (r < n - 1 && v[r + 1] == v[a]) ++r;
	REP(i, n + 1) cmb[i][0] = cmb[i][i] = 1;
	FOR(i, 2, n + 1) FOR(j, 1, i) cmb[i][j] = cmb[i - 1][j - 1] + cmb[i - 1][j];
	ll res = 0;
	if (l == 0) FOR(i, a - l + 1, b - l + 2) res += cmb[r - l + 1][i];
	else res = cmb[r - l + 1][a - l + 1];
	cout << res << endl;
	return 0;
}

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

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    for (ll A = 1; A <= N; A++) {
        ll B = 1;
        while (A * B < N) {
            B++;
            ans += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
typedef pair<int,int> P;

int main(){
    int N,C;cin>>N>>C;
    tuple<int,int,int> t[100010];
    vector<P> p;
    for(int i=0;i<N;i++){
        int x,y,z;
        cin>>x>>y>>z;
        t[i]=make_tuple(z,x,y);
    }
    sort(t,t+N);
    int i=1,c=get<0>(t[0]),from=get<1>(t[0]),to=get<2>(t[0]);
    while(i<N){
        if(c==get<0>(t[i])){
            if(to==get<1>(t[i]))
                to=get<2>(t[i]);
            else{
                p.push_back({from,to});
                from=get<1>(t[i]);
                to=get<2>(t[i]);
            }
        }
        else{
            p.push_back({from,to});
            c=get<0>(t[i]);
            from=get<1>(t[i]);
            to=get<2>(t[i]);
        }
        i++;
    }
    p.push_back({from,to});
    sort(p.begin(),p.end());

    int ans=1;
    priority_queue<int,vector<int>,greater<int>> pq;
    pq.push(p[0].second);
    for(int i=1;i<p.size();i++){
        int S=p[i].first;
        int T=pq.top();
        if(T<S){
            pq.pop();
            pq.push(p[i].second);
        }
        else{
            ans++;
            pq.push(p[i].second);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
ll solve(vector<ll >&p,vector<ll >&q)
{
	ll ans=0;

	while(q!=p)
	{
		ans++;
			
		next_permutation(p.begin(),p.end());
	
		
	}
	
	return ans;
}
int main()
{
  
  cin>>n;

vector<ll>P(n),Q(n);
for(ll i=0;i<n;i++)cin>>P[i];
for(ll i=0;i<n;i++)cin>>Q[i];

if(P>Q)swap(P,Q);


cout<<solve(P,Q);


  
  
}


Measured memory_bytes: 256
primes = [True] * (150000)
primes[0] = primes[1] = False
for i in range(2, int(len(primes)**0.5)+1):
	if primes[i]:
		for j in range(i*2, len(primes), i):
			primes[j] = False

def m(n, p):
	ns = []
	for i in range(n+1, n+p+3000):
		if primes[i]: ns.append(i)
	r = []
	for i in range(len(ns)):
		for j in range(i, len(ns)):
			r.append(ns[i]+ns[j])
	return sorted(r)[p-1]

while True:
	n, p = map(int, input().split())
	if (n, p) == (-1, -1):
		break
	print(m(n, p))

Measured memory_bytes: 13556
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        if(Math.Abs(inpt[0]-inpt[1])>=2) {
            Console.WriteLine(0);
            return;
        }
        long ans = 1;
        long mod = 1000000000 + 7;
        for (int i = 0; i < inpt[0]; i++) {
            ans = ans * (inpt[0] - i);
            ans = ans % mod;
        }
        for (int i = 0; i < inpt[1]; i++) {
            ans = ans * (inpt[1] - i);
            ans = ans % mod;
        }
        if(inpt[0]==inpt[1]) {
            ans = ans * 2;
            ans = ans % mod;
        }
        Console.WriteLine(ans);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"




100000 100000


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

//aとbが同じ文字となりうるか判定
bool same(char a, char b){
    return (a == '?' || b == '?' || a == b);
}

//aのx文字目以降とbが一致するか
bool consist(string a, string b, int x){
    if(x >= a.size()) return true;
    rep(i, min(b.size(), a.size()-x)){
        if(!same(b[i], a[x+i])) return false;
    }
    return true;
}

int main(){
    string s[3];
    int n[3];
    rep(i, 3) {cin >> s[i]; n[i] = s[i].size();}
    bool a[3][3][4001];
    rep(i, 3) rep(j, 3) rep(k, 4001){
        a[i][j][k] = consist(s[i], s[j], k);
    }
    int ans = inf;
    //先頭の文字がi,j,kの順番である場合を調べる
    rep(i, 3) rep(j, 3) rep(k, 3){
        if(i == j || j == k || k == i) continue;
        //j,kを始める位置をすべて調べる
        rep(p, n[i]+1) rep(q, max(n[j], n[i]-p)+1){
            if(!a[i][j][p] || !a[j][k][q] || !a[i][k][p+q]) continue;
            int tmp = n[i];
            tmp = max(tmp, p+n[j]);
            tmp = max(tmp, p+q+n[k]);
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class ABC139A {
    public static void Main() {
        int ans = 0;
        string S, T;
        S = Console.ReadLine();
        T = Console.ReadLine();

        for (int i = 0; i < 3; i++) {
            if (S[i] == T[i]) ans++;
        }
        Console.WriteLine(ans);
    }
}


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

int main()
{
  int A,B;
  bool C=false;
  int count=0;
  cin >> A >> B;
  for(int i=1; i<1090; i++)
  {
    if(((i*8)/100==A)&&(i/10==B))
    {
      count=i;
      C=true;
      break;
    }
  }
  if(C)
  {
    cout << count << endl;
  }
  else
  {
    cout << "-1" <<endl;
  }
  
}

Measured memory_bytes: 384
#include <stdio.h> 
int main()
{
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf("%d",&k);
    printf("%d",a[k-1]);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define MAXN 200005
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;
struct node{
    ll a,b,c,d;
};
node x[55];
ll n,m,q;
ll dfs(vector<ll>as,ll now){
    ll nm=as.size();
    if(nm==n){
        ll ans=0;
        for(int i=0;i<q;i++){
            ll a=x[i].a-1,b=x[i].b-1;
            if(as[b]-as[a]==x[i].c){
                ans+=x[i].d;
            }
        }
        return ans;
    }
    else{
        ll tp=0;
        as.push_back(now);
        for(int i=now;i<=m;i++){
            ll tmp;
            as[nm]=i;
            tmp=dfs(as,i);
            tp=max(tmp,tp);
        }
        return tp;
    }


}
int main(){
    ios::sync_with_stdio(false);
    #define int ll

    cin>>n>>m>>q;
    for(int i=0;i<q;i++){
        cin>>x[i].a>>x[i].b>>x[i].c>>x[i].d;
    }
    vector<int>temp;
    temp.push_back(1);
    int ans=dfs(temp,1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static Scanner sc = new Scanner();

    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var A = sc.ReadIntArray(N);

        long x = 0; // i番目の山の降雨量
        var k = 1;
        for (int i = N - 1; i >= 0; i--)
        {
            x += A[i] * k;
            k *= -1;
        }

        var ans = new long[N];
        ans[0] = x;
        for (int i = 1; i < N; i++)
        {
            ans[i] = (A[i - 1] - (ans[i - 1] / 2)) * 2;
        }

        Console.WriteLine(string.Join(" ", ans));
    }

    static long Gcd(long a, long b)
    {
        var v = new[] { a, b };
        while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
        return v[0];
    }

    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }

    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}

class HashMap<K, V> : Dictionary<K, V> where V : new()
{
    private V DefaltValue = new V();
    public HashMap() { }
    public HashMap(V defaultValue)
    {
        this.DefaltValue = new V();
    }
    new public V this[K i]
    {
        get
        {
            V v;
            return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
        }
        set { base[i] = value; }
    }
}

Measured memory_bytes: 30684
#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 MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  vector<P> A(3*N);
  REP(i, N){
    cin >> A[i].first;
    A[i].second=-1;
  }
  FOR(i,N,2*N){
    cin >> A[i].first;
    A[i].second=-2;
  }
  FOR(i,2*N,3*N){
    cin >> A[i].first;
    A[i].second=-3;
  }
  sort(ALL(A));
  vector<int> vec(3*N);
  REP(i,3*N){
    vec.at(i)=-1*A.at(i).second;
  }

  ll cnt1=0;
  ll cnt12=0;
  ll cnt123=0;
  vector<ll> vec1(3*N,0);
  vector<ll> vec12(3*N,0);
  vector<ll> vec123(3*N,0);
  REP(i,3*N){
    if(vec.at(i)==1){
      cnt1++;
      vec1.at(i)=cnt1;
      if(i!=0){
        vec12.at(i)=vec12.at(i-1);
        vec123.at(i)=vec123.at(i-1);
      }
    }else if(vec.at(i)==2){
      if(i!=0){
        cnt12+=vec1.at(i-1);
        vec12.at(i)=cnt12;
        vec1.at(i)=vec1.at(i-1);
        vec123.at(i)=vec123.at(i-1);
      }
    }else{
      if(i!=0){
        cnt123+=vec12.at(i-1);
        vec123.at(i)=cnt123;
        vec1.at(i)=vec1.at(i-1);
        vec12.at(i)=vec12.at(i-1);
      }
    }
  }
  cout << vec123.at(3*N-1) << endl;
}

Measured memory_bytes: 10880
import sys

n = int(input())
bricks = [int(a) for a in input().split()]

try:
  bricks.index(1)
except:
  print(-1)
  sys.exit()

result = 0
numbers = []
watch = 1
for i in range(n):
  if bricks[i] == watch:
    watch = watch + 1
  else:
    result = result + 1

print(result)


Measured memory_bytes: 24744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int num = stdin.nextInt();
		int prevT = 0;
		int prevX = 0;
		int prevY = 0;
		for (int i = 0; i < num; i++) {
			int t = stdin.nextInt();
			int x = stdin.nextInt();
			int y = stdin.nextInt();

			int time = t - prevT;
			int move = Math.abs(x - prevX) + Math.abs(y - prevY);
			if ((time < move) || ((time - move) % 2 > 0)) {
				System.out.println("No");
				return;
			}

			prevT = t;
			prevX = x;
			prevY = y;
		}

		System.out.println("Yes");
	}

}


Measured memory_bytes: 88048
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int n;
string city[15];
string tmp[15];
int dp[1<<15][15];
int cost[15][15];
bool ng[15];
const int inf=512;

int main(){
	
	while(cin>>n,n){

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

		fill(&ng[0],&ng[n],false);
		//?????¨?????????????????????????????????
		for(int i=0;i<n;i++){
			if(ng[i]) continue;
			for(int j=0;j<n;j++){
				if(i==j) continue;

				if(tmp[i].find(tmp[j])!=string::npos) ng[j]=true;
			}
		}

		int m=0;
		for(int i=0;i<n;i++){
			if(!ng[i]) city[m++]=tmp[i];
		}

		n=m;
		const int N=1<<n;
		
		fill(&dp[0][0],&dp[N][n],inf);
		fill(&cost[0][0],&cost[n][n],inf);

		for(int i=0;i<n;i++){
			dp[1<<i][i]=city[i].size();
		}

		//city[i]????????????city[j]?????????????????????
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j) cost[i][j]=0;
				//city[i]???????????????len????????¨city[j]????????????len??????????????????
				int li=city[i].size(),lj=city[j].size();
				for(int len=min(li,lj);len>=0;len--){
					if(city[i].substr(li-len,len)==city[j].substr(0,len)){
						cost[i][j]=lj-len;
						break;
					}
				}
			}
		}

		for(int bit=1;bit<N;bit++){
			int from=n;
			while(from--){
				if(!(bit&(1<<from))) continue;
				int to=n;
				while(to--){
					if(bit&(1<<to)) continue;
					dp[bit|(1<<to)][to]=min(dp[bit|(1<<to)][to],dp[bit][from]+cost[from][to]);
				}
			}
		}
		
		cout<<*min_element(dp[N-1],dp[N])<<endl;

	}

}

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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

// g0<=g1,s0<=s1,b0<=b1
int maxDonguri(int n, int g0, int s0, int b0, int g1, int s1, int b1) {
    int ret = 0;
    if (g0 > g1) { g0 = g1 = 1; }
    if (s0 > s1) { s0 = s1 = 1; }
    if (b0 > b1) { b0 = b1 = 1; }
    vint v = {g1 - g0, s1 - s0, b1 - b0}, w = {g0, s0, b0};
    vint dp(n + 1);
    rep(i, 3) {
        for (int j = w[i]; j <= n; j++) { chmax(dp[j], dp[j - w[i]] + v[i]); }
    }
    return dp[n];
}

int N;
int gA, sA, bA;
int gB, sB, bB;
signed main() {
    cin >> N;
    cin >> gA >> sA >> bA;
    cin >> gB >> sB >> bB;
    N += maxDonguri(N, gA, sA, bA, gB, sB, bB);
    N += maxDonguri(N, gB, sB, bB, gA, sA, bA);
    cout << N << endl;
}

Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    if(S == "Y"){
      cout << "Four" << endl;
      break;
    }
    else{
      if(i == N - 1){
        cout << "Three" << endl;
      }
    }
  }
}

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

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	int n_cnt(0);
	ll ans(0);
	for(int i(0);i<N;++i){
		cin >> A[i];
		if(A[i] < 0){
			n_cnt++;
			A[i] = -A[i];
		}
		ans += A[i];
	}
	sort(A.begin(),A.end());
	if(n_cnt%2 == 1) ans = ans - 2 * A[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024