akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll A,B,C,D;

//calc gcd
ll gcd (ll x,ll y){
  if (x<0)x*=-1;
  if (y<0)y*=-1;
  while(y>0){
    x=x%y;
    swap(x,y);
  }
  return x;
}


//calc lcm
ll lcm (ll x,ll y){
  return x*y/gcd(x,y);
}


ll solve(ll x,ll y){
  if (x<=0) return 0;
  return x/y;
}

int main(){
  cin >> A >> B >> C >> D;
  cout << (B-solve(B,C)-solve(B,D)+solve(B,lcm(C,D)))-((A-1)-solve((A-1),C)-solve((A-1),D)+solve((A-1),lcm(C,D)));
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=2e3+5;
int que[M],order[M],tmp[M],now[M],tot,top,n,k,q;
void in()
{
    scanf("%d%d%d",&n,&k,&q);
    for(int i=1;i<=n;++i)scanf("%d",&que[i]),order[i]=que[i];
}
void add(int le,int ri)
{
    tot=0;
    if(le>ri||ri-le+1<k)return;
    for(int i=le;i<=ri;++i)tmp[++tot]=que[i];
    sort(tmp+1,tmp+1+tot);
    for(int i=ri-le+2-k;i>=1;--i)now[++top]=tmp[i];
}
int test(int mn)
{
    int p=1;top=0;
    for(int i=1;i<=n;++i)if(que[i]<mn)add(p,i-1),p=i+1;
    if(top<q)return INT_MAX; 
    sort(now+1,now+1+top);
    return now[q]-mn;
}
void ac()
{
    int ans=INT_MAX;
    sort(order+1,order+1+n);que[++n]=-INT_MAX;
    for(int i=1;i<n;++i)ans=min(test(order[i]),ans);
    printf("%d",ans);
}
int main()
{
    in();ac();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
       int in;
       int h, m, s;
       scanf("%d",&in);
       h =in/3600;
       in %=3600;
       m =in/60;
       in %=60;
       s = in;
       printf("%d:%d:%d\n",h,m,s); 
       } 


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

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 103
#define K 100007
#define MOD 1000000007

int n, k;
int a[N];
ll dp[N][K];

int main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  dp[0][0] = 1;
  rep(i, n) {
    ll v = 0;
    rep(j, a[i]) {
      v += dp[i][j]; v %= MOD;
      dp[i+1][j] = v;
    }
    repl(j, a[i], k) {
      v += dp[i][j]; v %= MOD;
      dp[i+1][j] = v;
      v += MOD - dp[i][j-a[i]];
      v %= MOD;
    }
  }
  cout << dp[n][k] << endl;
  return 0;
}

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

int main(){
    int n;

    cin >> n;

    int a;

    int sum = 1;

    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 2 == 0){
            sum *= 2;
        }
        else{
            sum *= 1;
        }
    }

    int total = 1;
    for(int i = 0; i < n; i++){
        total = total*3;
    }

    cout << total - sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // Educational DP - S Digit Sum
  // dp[i][j][k]:上位からi桁目まで各桁の総和をDで割った際の余りがkとなる数値の個数
  // Dの倍数とは、Dで割った際の余りが0のこと、和なのでmodを好きなタイミングでとれる
  // [(s%D + k) % D]　←　毎回mod Dをとってやる
  // [j || s < ｎ]:未満フラグが立つ条件　→　すでにj==1又はsがn未満のとき
  ll mod = 1e9 + 7; 
  string K;
  int D, N;
  cin >> K >> D;
  N = K.size();
  vector<vector<vector<ll> > > dp(N+1, vector<vector<ll> >(2, vector<ll>(D, 0)));
  dp[0][0][0] = 1;  // 初期値

  REP(i, N){
    int n = (int)(K.at(i) - '0');  // stringから数字を抜き出す
    REP(j, 2){
      REP(k, D){
        for(int s = 0; s <= (j ? 9 : n); s++){
          dp[i+1][j || s < n][(s%D + k) % D] += dp[i][j][k] % mod;
        }
      }
    }
  }

  cout << (dp[N][0][0] + dp[N][1][0] - 1) % mod << endl;  // 0を含んでいるので-1
}



Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
int n,a,p=1e9,q=-1e9;
int main(){
	cin>>n;for(int i=0;i<n;i++){cin>>a;p=min(p,a);q=max(q,a);}
	cout<<q-p<<endl;
	return 0;
}

Measured memory_bytes: 768
INF = 1010101010

def main():
    N,Ma,Mb = map(int,input().split())

    dp = [[INF]*401 for _ in range(401)]
    dp[0][0] = 0

    for i in range(N):
        a,b,c = map(int,input().split())
        nx = [[INF]*401 for _ in range(401)]

        for A in range(401):
            for B in range(401):
                nx[A][B] = min(nx[A][B], dp[A][B])
                if A+a<=400 and B+b<=400:
                    nx[A+a][B+b] = min(nx[A+a][B+b], dp[A][B]+c)

        dp = nx[:]

    ans = INF
    for A in range(1,401):
        for B in range(1,401):
            if Ma*B == Mb*A:
                ans = min(ans, dp[A][B])

    return -1 if ans == INF else ans

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 71000
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-12;
const int N=1000+10,maxn=90000+10,inf=0x3f3f3f3f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    cout<<(m*1900+(n-m)*100)*(1ll<<m)<<endl;
    return 0;
}
/********************

********************/


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

long long K, X, Y;
vector<pair<long long, long long> > ANS;
bool Swap = false, Xm = false, Ym = false;

void output(vector<pair<long long, long long> > V) {
	cout << V.size() << endl;
	for (int i = 0; i < V.size(); i++) {
		long long ANSX = V[i].first, ANSY = V[i].second;
		if (Swap) swap(ANSX, ANSY);
		if (Xm) ANSX = -ANSX;
		if (Ym) ANSY = -ANSY;
		cout << ANSX << " " << ANSY << endl;
	}
}

int main() {
	cin >> K >> X >> Y;
	if (K % 2 == 0 && (X + Y) % 2 != 0) {
		cout << -1 << endl;
		return 0;
	}
	if (X < 0) Xm = true, X = -X;
	if (Y < 0) Ym = true, Y = -Y;
	if (X < Y) Swap = true, swap(X, Y);
	if (X + Y < K) {
		if ((X + Y) % 2 == 1) {
			ANS.push_back({ X, X - K });
			ANS.push_back({ (K + 3 * X - Y) / 2, (X - K + Y) / 2 });
			ANS.push_back({ X,Y });
			output(ANS);
		}
		else {
			ANS.push_back({ (X + Y) / 2, (X + Y - 2 * K) / 2 });
			ANS.push_back({ X,Y });
			output(ANS);
		}
		return 0;
	}
	long long P = (K - (X + Y) % K) % K;
	long long N;
	if (P % 2 == 0) N = (X + Y + K - 1) / K;
	else            N = (X + Y + K - 1) / K + 1;
	long long A = (N * K - X - Y) / 2;
	long long B = X;
	long long C = (N * K - X + Y) / 2;
	long long NOWX = 0, NOWY = 0;
	for (int i = 1; i <= N; i++) {
		if (i * K <= A) {
			ANS.push_back({ 0, -i * K });
		}
		else if (i * K <= A + B) {
			ANS.push_back({ i * K - A, -A });
		}
		else {
			ANS.push_back({ X, i * K - A * 2 - B });
		}
	}
	output(ANS);
}

Measured memory_bytes: 8684
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main(){
  int n,m;
  cin >> n >> m;
  vector<int> pe(150000);
  vector<int> re(n+1);
  int score=0;
  int sum = 0;
  rep(i,0,m){
      int num;
      string s;
      cin >> num >> s;
      if(s=="WA"){
          pe.at(num)++;
      }
      if(s=="AC" && re.at(num)==0){
          score ++;
          re.at(num) ++;
          sum += pe.at(num);
      }
  }
  printf("%d %d",score,sum);
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
ll N, W;
ll dp[110][100010];
ll w[110], v[110];
ll f(int i, int weight){
    if(weight > W) return -1e12;
    if(i == N) return 0;
    ll &ans = dp[i][weight];
    if(ans == -1){
        ans = max(ans, f(i + 1, weight + w[i]) + v[i]);
        ans = max(ans, f(i + 1, weight));
    }
    return ans;
}
int main(){
    fast;
    cin >> N >> W;
    for(int i = 0; i < N; i++)
        cin >> w[i] >> v[i];
    memset(dp, -1, sizeof dp);
    cout << f(0, 0) << "\n";
    return 0;
}


Measured memory_bytes: 89492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
  int n;
  cin >> n;
  vector<vector<int>> abc(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) cin >> abc[i][j];
  }
  
  vector<vector<ll>> dp(n+1, vector<ll>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;  // 二日続けて同じ活動をしてはいけない
        chmax(dp[i+1][k], dp[i][j] + abc[i][k]);
      }
    }
  }
  
  ll ans = 0;
  for (int j = 0; j < 3; j++) chmax(ans, dp[n][j]);
  cout << ans << endl;
}

Measured memory_bytes: 14064
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int X = int.Parse(Console.ReadLine());
        if (400 <= X && X <= 599) { Console.WriteLine("8"); }
        else if(600 <= X && X <= 799) { Console.WriteLine("7"); }
        else if(800 <= X && X <= 999) { Console.WriteLine("6"); }
        else if(1000 <= X && X <= 1199) { Console.WriteLine("5"); }
        else if (1200 <= X && X <= 1399) { Console.WriteLine("4"); }
        else if (1400 <= X && X <= 1599) { Console.WriteLine("3"); }
        else if(1600 <= X && X <= 1799) { Console.WriteLine("2"); }
        else if (1800 <= X && X <= 1999) { Console.WriteLine("1"); }
    }
}


Measured memory_bytes: 27500
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;
vector<int> ball;
bool search(int l, int r, int n)
{
  if (n == 10) {
    return true;
  }

  if (l < ball[n]) {
    if (search(ball[n], r, n + 1)) {return true;}
  } 
  if (r < ball[n]) {
    if (search(l, ball[n], n + 1)) {return true;}
  }
  return false;
}

int main()
{
  int N;
  scanf("%d ", &N);
  
  for (int i = 0; i < N; i++) {
    ball.clear();
    ball.resize(10);
    for (int i = 0; i < 10; i++) {
      scanf("%d ", &ball[i]);
    }
    if (search(ball[0], 0, 1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
typedef long long ll;
ll ar[100005];
ll cnt_bit[45];
int main() {
  int n;
  ll k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    ll tmp = ar[i];
    while (tmp) {
      if (tmp & 1) cnt_bit[cnt]++;
      tmp = (tmp>>1);
      cnt++;
    }
  } 
  ll ans = 0;
  for (int i = 40; i >= 0; i--) {
    ll cur = (1ll << i);
    if (cur > k) {
      ans += cur*cnt_bit[i];
    } else {
      ll no = cur*cnt_bit[i];
      ll yes = cur*(n-cnt_bit[i]);
      if (no >= yes) ans += no;
      else {
        ans += yes;
        k -= cur;
      }
    }
  }
  cout << ans << el;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FOR(i,j,n) for(int i=j;i<n;i++)
#define LL long long
#define pii pair<int,int>
#define fir first
#define sec second
#define MEM(i,j) memset(i,j,sizeof(i))
#define ALL(i) i.begin(),i.end()
#define VI vector<int>
#define VP vector<pii>
#define pb(a) push_back(a)
#define maxn 100005
using namespace std;
pii arr[maxn] , brr[maxn];
int pa[maxn];
inline int dis(pii seg[],int idx)
{
	return seg[idx+1].fir - seg[idx].fir;
}
struct edge{
	int u,v,cost;
} E[maxn*2];
inline bool operator < (edge a,edge b)
{
	return a.cost < b.cost;
} 
int Find(int x)
{
	return ( x == pa[x]) ? x : pa[x] = Find(pa[x]);
}
inline void Union(int x,int y)
{
	pa[Find(x)] = Find(y);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;
	FOR(i,0,n)
	{
	    cin >> arr[i].fir >> brr[i].fir;
		arr[i].sec = brr[i].sec = i;
	    pa[i] = i;
	}
	sort(arr,arr+n);
	sort(brr,brr+n);
	int cur = 0;
	FOR(i,0,n-1)
	{
		E[cur++] = edge{arr[i].sec,arr[i+1].sec,dis(arr,i)};
		E[cur++] = edge{brr[i].sec,brr[i+1].sec,dis(brr,i)};
	}
	sort(E,E+cur);
	long long ans = 0;
	int cnt = 0;
	FOR(i,0,cur)
	{
		int u = E[i].u;
		int v = E[i].v;
		int cost = E[i].cost;
		if(Find(u) != Find(v))
		    Union(u,v) , ans += cost , cnt++;
		if(cnt == n-1)    break;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4608
//#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
//#include<unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define of(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof a)
#define uint unsigned int

const  int N = 4e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

int a[N];
int t, n, m;

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

int main()
{
	/*ios::sync_with_stdio(false);*/
	cin >> n;
	fo(i, 1, n)
		sc(a[i]);
	double ans = 0;
	fo(i, 1, n)
		ans += (1.0) / a[i];
	printf("%.14f\n", 1.0 / ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int k,i;
long long n;
string s;
int main()
{
	cin >> n;
	while ( n != 0 )
	{
		n-=1;
		k = n%26;
		n/=26;
		s+=char(k+97);
	}
	reverse(s.begin(),s.end());
	if ( n != 1 ) cout << s;
	else cout << "a";
}

Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
	int n, k;
	cin >> n >> k;
	if (n%k == 0) {
		cout << "0" << endl;
	}
	else {
		cout << "1" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# n + 1 長の array を返す
def cumulative_sum(array)
  tmp = [0]
  previous = 0
  array.each { |num| tmp << previous += num }
  tmp
end

def ans(cumulative_sums, previous_plus, ans, added)
  cumulative_sums.each do |sum|
    if previous_plus && sum + added >= 0
      ans += (sum + added).abs + 1
      added -= (sum + added).abs + 1
    elsif !previous_plus && sum + added <= 0
      ans += (sum + added).abs + 1
      added += (sum + added).abs + 1
    end
    previous_plus = !previous_plus
  end
  ans
end

n = gets.to_i
nums = gets.split.map(&:to_i)
cumulative_sums = cumulative_sum(nums)
cumulative_sums.delete_at(0)
first = cumulative_sums.delete_at(0)
answers = []
if first > 0
  added = -(first + 1)
  answers << ans(cumulative_sums, true, 0, 0)
  answers << ans(cumulative_sums, false, added.abs, added)
elsif first < 0
  added = -first + 1
  answers << ans(cumulative_sums, true, added.abs, added)
  answers << ans(cumulative_sums, false, 0, 0)
else
  answers << ans(cumulative_sums, true, 1, 1)
  answers << ans(cumulative_sums, false, 1, -1)
end

puts answers.min


Measured memory_bytes: 21812
K,N=gets.split.map &:to_i;M=998244353;I=[1,1];*F=I;*R=I
2.upto(N+K){|i|I<<z=(M-M/i)*I[M%i]%M;F<<i*F[-1]%M;R<<z*R[-1]%M}
A=[]
(1..(K+1)/2).each{|q|
    i=q*2+1
    x=0
    (0...[q+1,N+1].min).each{|t|
        next if K-i+t<0
        r=F[q]*R[t]*R[q-t]*F[N+K-i]*R[K-i+t]*R[N-t]*2**t%M
        x=(x+r)%M
    }
    A<< x
}
O=(1...K).map{|i|A[(i-1)/2]}
p *[*O,A[-1],*O.reverse]

Measured memory_bytes: 2556
# islands war
n,m=map(int,input().split())
lists=[]
for i in range(m):
    a,b=map(int,input().split())
    lists.append((a,b))
lists=sorted(lists,key=lambda x:(x[0],x[1]))

Uselist=[0 for i in range(n)]
for j in lists:
    if not Uselist[j[0]]:
        Uselist[j[0]]=j
    else:
        continue

uselist=[]
for j in Uselist:
    if j!=0:
        uselist.append(j)
counter=0
inf=0
maxi=10**15
length=len(uselist)
for j in range(length):
    inf=max(inf,uselist[j][0])
    maxi=min(maxi,uselist[j][1])
    if inf<maxi:
        pass
    elif inf>=maxi:
        counter+=1
        inf=maxi
        maxi=uselist[j][1]
print(counter+1)

Measured memory_bytes: 25372
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll tx; tx=1; while(tx--)
typedef long long int ll;
int main() {
    FIO;
    test{
        ll n;
        cin>>n;
        set<string>s;
        string t;
        for(ll i=0;i<n;i++){
            cin>>t;
           s.insert(t); 
        }
        cout<<s.size()<<endl;
    }
	return 0;
}


Measured memory_bytes: 19232
fun main(args: Array<String>){
    val input: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    val n = input[0]
    val mList = Array(input[1], {i -> 0})
    var count = 0

    for(i in 0 until input[1]){
        mList[i] = 0
    }

    for(i in 0 until n){
        val nInput: List<Int> = readLine()!!.split(" ").map { it.toInt() }
        for(j in 1 until nInput[0]+1){
            mList[nInput[j]-1]++
        }
    }

    for(i in mList){
        if(i == n) count++
    }

    println(count)
}

Measured memory_bytes: 38004
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

bool cmp(pair<ll,ll>&a,pair<ll,ll>&b)
{
    if(a.fi==b.fi)
        return a.se>b.se;
    return a.fi>b.fi;
}

priority_queue<ll>pq;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	vector< pair<ll,ll> >vv;
	for(ll i=0;i<n;i++)
	{
	    ll a,b;
	    cin>>a>>b;
	    vv.eb(mp(m-a,b) );
	}
	sort(vv.begin(),vv.end(),cmp);
	ll po=0;
	ll ans=0;
	for(ll day=m-1;day>=0;day--)
	{
	   // cout<<day<<" "<<vv[po].fi<<"\n";
	    while(day==vv[po].fi && po<n)
	    {
	        pq.push(vv[po].se);
	        po++;
	    }
	    if(!pq.empty())
	    {
	        ans+=pq.top();
	        pq.pop();
	    }
	    
	}
	cout<<ans;
    return 0;
}


//252908XL

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

int main(void){
    int n,ans=1e9;
    cin >> n;
    string s;
    cin >> s;
    int a[n+1],b[n+1];
    a[0]=0;b[0]=0;
    rep(i,n){
        if(s[i]=='W') a[i+1] = a[i]+1;
        else a[i+1] = a[i];
    }
    //rep(i,n+1) cout << a[i];
    reverse(s.begin(),s.end());
    rep(i,n){
        if(s[i]=='R') b[i+1] = b[i]+1;
        else b[i+1] = b[i];
    }
    //rep(i,n+1) cout << b[i];
    rep(j,n+1){
        ans = min(max(a[j],b[n-j]),ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5288
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()
cnt = 0
c = 1

for i in range(N):
  if a[i] != c:
    cnt += 1
  else:
    c += 1
    
print(cnt if cnt < N else -1)

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

int arr[1005], ans, n, k;

int main(){
  	cin >> n >> k;
  	for(int i=0;i<k;++i){
    	int t, m; cin >> t;
      for(int j=0;j<t;++j){
      		cin >> m;
        	arr[m-1] = 1;
      }
    }
  	for(int i=0;i<n;++i){
    	if(arr[i] == 0) ++ans;
    }
  	cout << ans;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int collatz( int num )
{
	if( num == 1 ) return 0;
	if( num%2 == 0 ) return 1+collatz(num/2);
	else return 1+collatz(num*3+1);
}

int main(void)
{
	int n;
	while( cin >> n ){
		if( n == 0 ) break;
		cout << collatz(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
s = input()
n = len(s)
ans = 0

for i in range(2**(n-1)):
  index =format(i,'b').zfill(n-1)
  index = [int(ind) for ind in index]
  
  
  t = s
  for k in range(n-1):
    if index[k]==1:
      t = t[:k+1+sum(index[:k])]+ '+' + s[k+1:]

  ans += eval(t)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 1

lli data[3][3];
lli ans=0;

int main(){
	lli data[3][3];
	for(lli i=0;i<3;i++){
		for(lli j=0;j<3;j++){
			cin>>data[i][j];
		}
	}
	lli a[3] = {0};
	lli b[3] = {0};

	REP(i,110){
		a[0] = i;
		b[0] = data[0][0]-a[0];
		b[1] = data[0][1]-a[0];
		b[2] = data[0][2]-a[0];
		a[1] = data[1][0]-b[0];
		a[2] = data[2][0]-b[0];

		/*計算して正しいか？*/
		lli flag=0;
		REP(j,3){
			REP(k,3){
				if(a[j]+b[k]!=data[j][k]){
					flag=1;
				}
			}
		}
		if(flag==0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const LL inf = 1 << 30;
const int mod = 998244353;
map<PII,int>mp;
map<PII,int>mp1;
map<PII,int>mp2;
map<PII,int>::iterator it;
const int maxn = 505;
struct point{
    int x,y,flag;
}s,q;
int n;
int ans = 0;
int main(){
	int a,b,x;
	bool ans = true;
	cin >> a >> b >> x;
	if(a+b >= x&&a <= x) printf("YES\n");
	else printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  multimap<string,int> mp;
  int q;
  cin >> q;
  REP(i,q){
    int t;
    string key;
    cin >> t >> key;
    if(t==0){
      int x;
      cin >> x;
      mp.insert({key,x});
    }else if(t==1){
      auto itr = mp.lower_bound(key);
      auto itr2 = mp.upper_bound(key);
      for(auto i = itr;i!=itr2;++i){
        cout << i->second << endl;
      }
    }else if(t==2){
      mp.erase(key);
    }else{
      auto itr = mp.lower_bound(key);
      string r;
      cin >> r;
      auto itr2 = mp.upper_bound(r);
      for(auto i = itr;i!=itr2;++i){
        cout << i->first << " " << i->second << endl;
      }
    }
  }
}



Measured memory_bytes: 24752
import java.io.*;
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int month = sc.nextInt();
    int day = sc.nextInt();
    if(day >= month) {
      System.out.println(month);
    } else {
      System.out.println(month-1);
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n, h; cin >> n >> h;
	int a_max = 0, max_n = 0, a[n], b[n], ans = 0;
	Rep(i, n){
		cin >> a[i] >> b[i];
		if(a[i] > a_max){
			max_n = i;
			a_max = a[i];
		}else if(a[i] == a_max){
			if(b[max_n] > b[i]){
				max_n = i;
			}
		}
	}
	vector<int> v;
	Rep(i, n){
		if(b[i] > a_max && i != max_n){
			v.pb(b[i]);
		}
	}
	sort(v.begin(), v.end(), greater<int>());
	Rep(i, v.size()){
		h -= v[i]; ans += 1;
		if(h <= 0){
			cout << ans << endl;
			return 0;
		}
	}
	if(h > b[max_n]) ans += (h - b[max_n] - 1) / a[max_n] + 2;
	else ans += 1;

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

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define N 3005

using namespace std;

long long cost[N][N];
long long a[N];

long long solve(int l, int r){
    if(cost[l][r] != -1)
        return cost[l][r];
    if(l == r)
        return cost[l][r] = a[l];
    return cost[l][r] = max(a[l] - solve(l + 1, r), a[r] - solve(l, r - 1));
}

int main(){
    int n;
    cin>>n;
    for(int i = 1 ; i <= n ; i++)
        cin>>a[i];
    memset(cost, -1, sizeof cost);

    cout<<solve(1, n);
    return 0;
}


Measured memory_bytes: 71040
def main():
    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]
    K = int(input())
    print(A[K-1])


if __name__ == '__main__':
    main()


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

int main()
{

  int h,n,x,sum=0;
  cin>>h>>n;

  while(n--)
  {
    cin>>x;
    sum=sum+x;
  }

  int res;
  res=h-sum;
  

  if(res<=0)
    cout<<"Yes";
  else
    cout<<"No";
}


Measured memory_bytes: 256
eval"H,W,K="+`tr \\  ,`;a=2;b=1,1,2,3,5,8,13,21;H.times{a=0,*(1..W).map{|i|a[i]*b[i-1]*b[W-i]+a[i-1]*b[i-2]*b[W-i]+a[i+1]*b[i-1]*b[W-i-1]},0};p a[K].%10**9+7

Measured memory_bytes: 2136
n   = gets.to_i
ary = gets.split.map(&:to_i)
ave = 0
min = 1000
ans = 0

ave = ary.inject(:+).to_f / n
n.times do |i|
  if min > (ave - ary[i]).abs
    min = (ave - ary[i]).abs
    ans = i
  end
end

puts ans

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

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

  bool flg = true;
  if (S.size()+1 == T.size()){
    for(int i=0;i<S.size();i++)
      if (S[i] != T[i]){
        flg = false;
        break;
      }
  }
  else
    flg = false;
  
  if (flg)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}

Measured memory_bytes: 3612
#include "iostream"
using namespace std;


int main(){
	int n;
	cin >> n;
	int i = 1;
	// CHECK_NUM:
	do{
	int x = i;
		
			if (x % 3 == 0){
				cout << " " << i;
				//		goto END_CHECK_NUM;
				//break;
			}
	//	INCLUDE3:
			else{

				do{
					if (x % 10 == 3){
						cout << " " << i;
						//		goto END_CHECK_NUM;
						break;
					}

					x /= 10;
					//		if (x) goto INCLUDE3;
				} while (x);
			}
		
//END_CHECK_NUM:
	//  if ( ++i <= n ) goto CHECK_NUM;
	}while (++i <= n);
	
  cout << endl;
  return 0;
}



Measured memory_bytes: 3088
package main

import (
	"fmt"
)

func main() {
	a := [4][3][10]int{}

	var n, b, f, r, v int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&b, &f, &r, &v)
		a[b-1][f-1][r-1] += v
	}

	for i := 0; i < 4; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 10; k++ {
				fmt.Printf(" %d", a[i][j][k])
			}
			fmt.Println()
		}
		if i < 3 {
			fmt.Println("####################")
		}
	}
}



Measured memory_bytes: 1124
n = int(input())
l = list(map(int,input().split()))

a = 0
b = 0
for c in l:
    if c%2 == 0:
        a += 1
        if (c%3 == 0) or (c%5 == 0):
            b += 1
        else:
            pass 
    else:
        pass
        
if a == b:
    print("APPROVED")
else:
    print("DENIED")

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

using namespace std;

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

    map <string, int> Cnt;

    int Max = 0;
    for (int i = 0; i < n; i++) {
        string s;   cin >> s;
        Cnt[s]++;

        Max = max(Max, Cnt[s]);
    }

    vector <string> str;
    for (auto x : Cnt)
        if (x.second == Max)
            str.push_back(x.first);

    sort(str.begin(), str.end());

    for (auto x : str)
        cout << x << '\n';

    return 0;
}

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

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    string s;
    cin >> s;
    // 0
    int ans1 = 0;
    int temp = 0;
    if (s[0] == '1')
        ans1++;
    temp = 0;
    rep2(i, 1, s.size())
    {
        if (s[i] - '0' == temp)
            ans1++;
        temp = (temp + 1) & 1;
    }
    // 1
    int ans2 = 0;
    temp = 0;
    if (s[0] == '0')
        ans2++;
    temp = 1;
    rep2(i, 1, s.size())
    {
        if (s[i] - '0' == temp)
            ans2++;
        temp = (temp + 1) & 1;
    }

    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

ll gcd(ll m, ll n) {
    return n != 0 ? gcd(n, m % n) : m;
}

ll lcm(ll m, ll n) {
    // If both m and n are large numbers, the result is overflow without parentheses.
    return m * (n / gcd(m, n));
}

vector<ll> divisors(ll n) {
    vector<ll> v;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            v.push_back(i);
            if (i * i != n) {
                v.push_back(n / i);
            }
        }
    }
    return v;
}

void solve() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    REP(i, n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    bool go = false;
    int ans = 0;
    REP(i, n) {
        if (go) ans += t[i];
        else if (x == s[i]) go = true;
    }
    cout << ans << EOL;
}


Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<int> v;
vector<vector<int>> G;
vector<int> odd;
int dfs(int crt, int pre) {
    v[crt] = 1;
    for (int &nextV : G[crt]) {
        if (nextV == pre) continue;
        if (v[nextV]) {
            if (crt < nextV) {
                cout << crt << " " << nextV << endl;
                odd[crt] ^= 1;
            }
        } else {
            if (dfs(nextV, crt)) {
                cout << nextV << " " << crt << endl;
            } else {
                cout << crt << " " << nextV << endl;
                odd[crt] ^= 1; 
            }
        }
    }
    return odd[crt];
}

int main(void) {
    int N, M; cin >> N >> M;
    G.resize(N+1);
    v.resize(N+1);
    odd.resize(N+1);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if (M % 2) cout << -1 << endl;
    else dfs(1, 0);
}

Measured memory_bytes: 15488
words = list(input())
num = len(words)
children = [0 for s in range(num)]
p = 0
for i in range(num - 1):
  p += 1
  if i == num - 2:
    if words[i] == "R":
      if p % 2 == 1:
        children[i] += int(p/2) + 1
        children[i+1] += int(p/2) + 1
        p = 0
      else:
        children[i] += int(p/2)
        children[i+1] += int(p/2) + 1
        p = 0
    else:
      p += 1
      if p % 2 == 1:
        children[i-p+2] += int(p/2) + 1
        children[i-p + 1] += int(p/2)
        p = 0
      else:
        children[i+2-p] += int(p/2)
        children[i-p+1] += int(p/2)
        p = 0
  elif words[i] == words[i + 1]:
    pass
  else:
    if words[i] == "R":
      if p % 2 == 1:
        children[i] += int(p/2) + 1
        children[i+1] += int(p/2)
        p = 0
      else:
        children[i] += int(p/2)
        children[i+1] += int(p/2)
        p = 0
    else:
      if p % 2 == 1:
        children[i-p+1] += int(p/2) + 1
        children[i-p] += int(p/2)
        p = 0
      else:
        children[i+1-p] += int(p/2)
        children[i-p] += int(p/2)
        p = 0
             
answer = str(children[0])
for i in range(num - 1):
  answer += " " + str(children[i+1])
print(answer)

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

using namespace std;

int main() {
	int N;
	cin >> N;
	string S[N];

	int cnt[4] = {0}; // 0:AC, 1:WA, 2:TLE, 3:RE
	for(int i=0; i<N; i++) {
		cin >> S[i];
		if(S[i].at(0) == 'A') {
			cnt[0]++;
		} else if(S[i].at(0) == 'W') {
			cnt[1]++;
		} else if(S[i].at(0) == 'T') {
			cnt[2]++;
		} else if(S[i].at(0) == 'R') {
			cnt[3]++;
		}
	}

	cout << "AC x " << cnt[0] << "\n";
	cout << "WA x " << cnt[1] << "\n";
	cout << "TLE x " << cnt[2] << "\n";
	cout << "RE x " << cnt[3] << "\n";
	return 0;
}

Measured memory_bytes: 6716
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

template <typename T> struct BIT {
    int n;
    vector<T> bit;
    BIT(int n_) : n(n_ + 1), bit(n, 0) {
    }

    void add(int i, T x) {
        if (i == 0) {
            cout << "BIT add ERROR" << endl;
            exit(1);
        }
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[idx] += x;
        }
    }

    T sum(int i) {
        T s(0);

        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[idx];
        }
        return s;
    }
};

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

    int N, Q;
    cin >> N >> Q;

    vec<int> mp(N + 1);
    vec<int> ball(N + 1);

    rep(i, N) {
        int c;
        cin >> c;
        int now = i + 1;
        if (mp[c] == 0) {
            mp[c] = now;
        } else {
            ball[mp[c]] = now;
            mp[c]       = now;
        }
    }

    vec<vec<pair<int, int>>> query(N + 1);
    vec<int> l(Q), r(Q);
    rep(i, Q) {
        cin >> l[i] >> r[i];
        query[l[i]].push_back({r[i], i});
    }

    BIT<ll> bit(N);
    vec<int> ans(Q);
    for (int i = N; i > 0; --i) {
        if (ball[i] != 0) bit.add(ball[i], 1);
        for (auto [R, index] : query[i]) {
            ans[index] = bit.sum(R);
        }
    }

    rep(i, Q) {
        cout << r[i] - l[i] + 1 - ans[i] << "\n";
    }
}


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

int check(int h,int w,int x,int y,int k,vector<vector<int>> list){
  for(int i=0;i<h;i++){
    if(x&(1<<i)){
      for(int j=0;j<w;j++){
        list.at(i).at(j) = 2;
      }
    }
  }
  
  for(int j=0;j<w;j++){
    if(y&(1<<j)){
      for(int i=0;i<h;i++){
        list.at(i).at(j) = 2;
      }
    }
  }
  
  int cnt=0;
  //cout << list[0].size() << endl;
  //cout << list.size() << endl;

  for(int i=0;i<list.size();i++){
    for(int j=0;j<list[0].size();j++){
      if(list.at(i).at(j) == 1){
        cnt++;
      }
    }
  }
  
  if(cnt == k){
    return(1);
  }

  return(0);
}

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<int>> list(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char c;
      cin >> c;
      if(c == '.'){
        list.at(i).at(j) = 0;
      }else if(c == '#'){
        list.at(i).at(j) = 1;
      }
    }
  }
  
  int ans=0;
  for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
      //cout << i << " " << j << endl;
      //cout << (i&(1<<1)) << endl;
      ans += check(h,w,i,j,k,list);
    }
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{

  char x,y,a='A';
  while(scanf(" %c,%c", &x, &y)!=EOF){

  if(a==x){
    a=y;
  }else if(a==y){
    a=x;
  }
  }
  printf("%c\n", a);

  return 0;
}

Measured memory_bytes: 540
x = 1
y = 1
i = 0
while x!=0 or y!=0:
	i+=1
	x,y = [int(i) for i in input().split()]
	if x!=0 or y!=0:
		if x <= y:
			print("{0} {1}".format(x,y))
		else:
			print("{0} {1}".format(y,x))

Measured memory_bytes: 7588
#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main()
{
 map <int,int> mp;  int x;  
 for(int i=1;i<=100;i++)
 {
     for(int j=1;j<=100;j++)
     {
         for(int k=1;k<=100;k++)
         {
            x=(pow((i+j),2)+pow((j+k),2)+pow((k+i),2));
            x/=2;
            mp[x]++;
         }
     }
 }
 int n; cin>>n;
 for(int i=1;i<=n;i++)
 {
     cout<<mp[i]<<endl;
 }
 
}

Measured memory_bytes: 5956
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

//#define __int64 long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

long long int convert(string s, int cnt){
	long long int res = 0;
	long long int num = s[0] - '0';
	bitset<10> bit(cnt);
	
	for(int i=1; i<s.length(); i++){
		if(bit[i-1]){
			res += num;
			num = s[i] - '0';
		}else{
			num *= 10;
			num += s[i] - '0';
		}
	}
	
	res += num;
	
	return res;
}


int main(){
	string s;
	long long int ans = 0;
	cin >> s;
	
	for(int i=0; i<pow(2, s.length()-1); i++){
		ans += convert(s, i);
	}
	
	cout << ans << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// ?????????dot(a,b) = |a||b|cos??
D dot(P a, P b) {
    return (conj(a)*b).X;
}
// ?????????cross(a,b) = |a||b|sin??
D cross(P a, P b) {
    return (conj(a)*b).Y;
}
// ?????????????????? a->b->c
int ccw(P a, P b, P c) {
    b -= a;	c -= a;
    //3???????????´???????????????
    if (cross(b,c) > EPS) return +1;	// counter clockwise
    if (cross(b,c) < -EPS) return -1;	// clockwise
    //3???????????´???????????????
    if (dot(b,c) < -EPS) return +2;		// c--a--b on line
    if (norm(b) < norm(c)) return -2;	// a--b--c on line or a==b
    return 0;							// a--c--b on line or a==c or b==c
}
// ????????¨??????
bool isecSS(P a1, P a2, P b1, P b2) {
    return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
    ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

P crosspointLL(P a1, P a2, P b1, P b2) {
    D d1 = cross(b2-b1, b1-a1);
    D d2 = cross(b2-b1, a2-a1);
    return a1 + d1/d2 * (a2-a1);
}

class CrossPoint{
public:
    double x, y;
    int o, l;
    bool is_underground;
    CrossPoint(double x, double y, int o, int l): x(x), y(y), o(o), l(l){
        is_underground = o^l;
    };
};

bool cmp(CrossPoint p1, CrossPoint p2){
    if(EQ(p1.x, p2.x))
        return p1.y < p2.y;
    else
        return p1.x < p2.x;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int T; cin>>T;
    while(T--){
        int xa, ya, xb, yb;
        cin >> xa >> ya >> xb >> yb;
        
        int N; cin >> N;
        
        vector<CrossPoint> crosspoints;
        for(int i=0; i<N; i++){
            int xs, ys, xt, yt, o, l;
            cin >> xs >> ys >> xt >> yt >> o >> l;
            
            if(isecSS(P(xa, ya), P(xb, yb), P(xs, ys), P(xt, yt))){
                P p = crosspointLL(P(xa, ya), P(xb, yb), P(xs, ys), P(xt, yt));
                crosspoints.push_back(CrossPoint(p.X, p.Y, o, l));
            }
        }
        
        if(crosspoints.size()){
            sort(crosspoints.begin(), crosspoints.end(), cmp);
            
            int count = 0;
            for(int i=1; i<crosspoints.size(); i++)
                count += crosspoints[i-1].is_underground != crosspoints[i].is_underground;
            cout << count << endl;
        }else{
            cout << 0 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1228
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,K = MI()
V = LI()

ans = 0
for i in range(K+1):  # 操作回数
    for j in range(N+1):  # 左から取る個数
        for k in range(N+1):  # 右から取る個数
            if j + k > min(N,i):
                break
            l = i-j-k  # 戻す個数
            if l > j+k:
                continue
            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans,sum(A[m] for m in range(j+k-l)))
print(ans)


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  int ans = min(b, d) - max(a, c);
  if (ans < 0) { ans = 0; }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

const int NMAX = 100;

int v[NMAX+2], pmin = 1, pmax = 0;
vector<pair<int,int>> sol;

int main()
{
    int N;
    cin >> N;
    for( int i = 1;  i <= N;  ++i ) {
        cin >> v[i];
        if( v[i] < v[pmin] )
            pmin = i;
        if( v[i] > v[pmax] )
            pmax = i;
    }
    if( v[pmin] == v[pmax] ) {
        cout << "0\n";
        return 0;
    }
    /// fa totul de acelasi semn
    if( v[pmax] >= -v[pmin] && v[pmax] > 0 ) {
        for( int i = 1;   i <= N;  ++i ) {
            if( v[i] <= 0 ) {
                sol.push_back({pmax, i});
            }
        }
        /// fac totul crescator
        sol.push_back({pmax, 1});
        for( int i = 2;  i <= N;  ++i ) {
            sol.push_back({i-1, i});
        }
    }
    else if( v[pmin] < -v[pmax] && v[pmin] < 0 ) {
        for( int i = 1;  i <= N;  ++i ) {
            if( v[i] >= 0 ) {
                sol.push_back({pmin, i});
            }
        }
        /// descrescator, de la capat
        sol.push_back({pmin, N});
        for( int i = N - 1;  i >= 1;  --i ) {
            sol.push_back({i+1, i});
        }
    }
    cout << sol.size() << '\n';
    for( auto pp : sol ) {
        cout << pp.first << ' ' << pp.second << '\n';
    }
    return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#define k 1024
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",&a);
#define m(a,b) a<b?a:b
int x,w,n,m,c[k],d[k],p[k];
int main(){s(n)s(m)r(n)s(d[i])r(m)s(c[i])r(n+1)p[i]=1<<29;p[0]=0;r(m*n)w=n-i%n,x=p[w-1]+c[i/n]*d[w-1],p[w]=p[w]<x?p[w]:x;printf("%d\n",p[n]);}

Measured memory_bytes: 1036