akhauriyash/Code-Regression huggingface dataset:
//in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    //int t;
    //cin>>t;
    //while(t--)
    //{
        ll n,a;
        cin>>n;
        string s[27];
        string ns="";
        s[0]="z";
        s[1]="a";
        s[2]="b";
        s[3]="c";
        s[4]="d";
        s[5]="e";
        s[6]="f";
        s[7]="g";
        s[8]="h";
        s[9]="i";
        s[10]="j";
        s[11]="k";
        s[12]="l";
        s[13]="m";
        s[14]="n";
        s[15]="o";
        s[16]="p";
        s[17]="q";
        s[18]="r";
        s[19]="s";
        s[20]="t";
        s[21]="u";
        s[22]="v";
        s[23]="w";
        s[24]="x";
        s[25]="y";
        s[26]="z";
        if(n<=26)
            cout<<s[n]<<endl;
        else
        {
           while(1){
            if(n%26==0)
            {
                if(n>=27 && n<=702)
                {
                    a=n%26;
                    n=n/26-1;
                    //cout<<a<<" "<<n<<" "<<s[a]<<" "<<s[n]<<endl;
                    ns+=s[a];
                    ns+=s[n];
                     //cout<<ns<<endl;
                    break;
                }
                else
                {
                    ns+="z";
                    n=n/26-1;
                }
            }
            else
            {
                    if(n>=27 && n<=701)
                    {
                        a=n%26;
                        n=n/26;
                        ns+=s[a];
                        ns+=s[n];
                        break;

                    }
                    a=n%26;
                    n=n/26;
                    ns+=s[a];


            }
        }
        reverse(ns.begin(),ns.end());
            cout<<ns<<endl;
        }
    }
//}




Measured memory_bytes: 3552
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int ra = 0, rb = 0;
  rep(i, n) {
    bool f = true;
    if (s[i] == 'a') {
      if (ra < a + b) {
        ra++;
      }
      else {
        f = false;
      }
    }
    else if (s[i] == 'b') {
      rb++;
      if (ra < a + b && rb <= b) {
        ra++;
      }
      else {
        f = false;
      }
    }
    else f = false;
    cout << (f ? "Yes" : "No") << endl;
  }


  
  return 0;
}

Measured memory_bytes: 896
/*
If you want to shine like a sun, first burn like a sun.
*/

#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;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
	string s;
	cin>>s;

	forn(i,0,s.sze)
	{
		cout<<'x';
	}
        
        












    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
war=[list(map(int,input().split())) for i in range(m)]
war=sorted(war)
right=0
left=0
ans=0
for i in range(m):
  if right<=war[i][0]:
    ans+=1
    right=war[i][1]
    left=war[i][0]
  else:
    left=war[i][0]
    right=min(war[i][1],right)
print(ans)

Measured memory_bytes: 29496
#include <stdio.h>
#include <stdlib.h>
void CountingSort(int *,int *,int);
int C[10001]={0},i;
int main(void){
  int n,*A,*B;
  scanf("%d",&n);
  A=(int *)malloc(sizeof(int)*n);
  B=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  
  CountingSort(A,B,n);
  for(i=0;i<n;i++){
    printf("%d",B[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  return 0;
}
void CountingSort(int *A,int *B,int k){
  /*C[i]にiの出現数を記録する */
  i=0;
  while(i<k){
    C[A[i++]]++;
  }

  /*C[i]にi以下の数の出現数を記録する*/
  i=0;
  while(i<10001){
    C[i]=C[i]+C[i-1];
    i++;
  }

  for(i=k-1;i>=0;i--){
    B[C[A[i]]-1]=A[i];
    C[A[i]]--;
  }
}


Measured memory_bytes: 17364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_171
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            int[] ps = ReadInts();
            Array.Sort(ps);
            int res = 0;
            for(int i = 0; i < k; i++)
            {
                res += ps[i];
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27880
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int x, y; cin >> x >> y;
    if (x % y == 0) {cout << -1 << endl; return 0;}
    for (ll a = x; ; a += x) {
        if (a % y != 0) {
            cout << a << endl;
            return 0;
        }
    }
}

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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

int main() {
    // get values from input
    int N;
    READ(N);

    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        READ(A[i]);
    }

    // main procedure
    vector<ll> max_not_take_last(N+1);
    vector<ll> max_take_last(N+1);
    vector<ll> max_all(N+1);

    vector<ll> max_one_more(N+1);

    max_one_more[1] = A[0];
    for (int i = 2; i < N+1; ++i) {
        if (i % 2 == 0) {
            max_not_take_last[i] = max_one_more[i - 1];
            max_take_last[i] = max_not_take_last[i - 1] + A[i - 1];


        } else {
            max_not_take_last[i] = max_all[i - 1];
            max_take_last[i] = max_all[i - 2] + A[i - 1];

            max_one_more[i] = max_one_more[i - 2] + A[i - 1];
        }
        max_all[i] = max(max_not_take_last[i], max_take_last[i]);
    }

    // output
    WRITE(max_all[N]);

    return 0;
}


Measured memory_bytes: 10312
def resolve():
  N, K = map(int, input().split(" "))
  A = [int(x) for x in input().split(" ")]
  maxA = max(A)
  base = 10**9+7
  # counter_of_A = [0]*(maxA+1)
  integra_of_counter = [0]*(maxA+1)

  # A の転倒数を数える。
  inversion_num_of_first_A = 0
  for a in reversed(A):
    if a > 1:
      inversion_num_of_first_A += integra_of_counter[a-1]
    
    for x in range(a, maxA+1):
      integra_of_counter[x] += 1


  # B の 2 番目の転倒数を数える
  inversion_num_of_second_A = 0
  for a in reversed(A):
    if a > 1:
      inversion_num_of_second_A += integra_of_counter[a-1]
    
    for x in range(a, maxA+1):
      integra_of_counter[x] += 1
  # print(integra_of_counter)
  # print(inversion_num_of_second_A)

  # print("K =", K, "a =", inversion_num_of_first_A, "d =", inversion_num_of_second_A - inversion_num_of_first_A)
  if K%2 == 0:
    result = K//2 * (2*inversion_num_of_first_A%base + (K-1)*(inversion_num_of_second_A - inversion_num_of_first_A)%base)
  else:
    result = (inversion_num_of_first_A%base + ((K-1)*(inversion_num_of_second_A - inversion_num_of_first_A)//2)%base)*K
  result %= base

  print(result)
if __name__ == "__main__":
  resolve()

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int> > data(M);
    vector<int> k(M), s(N);
    for (int i = 0; i < M; i++) {
        cin >> k.at(i);
        for (int j = 0; j < k.at(i); j++) {
            cin >> s.at(j);
            data.at(i).push_back(s.at(j));
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; i++) {
        cin >> p.at(i);
    }

    int ans = 0, count;
    bool can;
    for (int bit = 0; bit < (1 << N); bit++) {
        can = true;
        for (int i = 0; i < M; i++) {
            count = 0;
            for (int j = 0; j < k.at(i); j++) {
                if (bit & (1 << (data.at(i).at(j) - 1))) {
                    count++;
                }
            }
            if (count % 2 != p.at(i)) {
                can = false;
            }
        }
        if (can) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    vector<ll> c(n);
    for(int i=0;i<n;++i) {
        cin >> p[i];
        --p[i];
    }
    for(int i=0;i<n;++i) cin >> c[i];

    ll ans = -LINF;
    for(int i=0;i<n;++i) {
        ll now = i, tmp = 0LL, kk = k;
        vector<Pll> hist(n, {-1LL, -1LL}); // {いつ訪れたか, その時のスコア}

        hist[i] = {kk, 0LL};
        bool loop_check = false;
        while(kk > 0LL) {
            now = p[now];
            tmp += c[now];
            ans = max(ans, tmp);
            --kk;

            if(!loop_check && hist[now].first != -1LL) {
                ll sc = tmp - hist[now].second;
                ll n_sc = hist[now].first - kk;
                if(kk/n_sc >= 1LL) {
                    tmp += (kk / n_sc - 1LL) * sc;
                    ans = max(ans, tmp);
                    kk -= (kk / n_sc - 1LL) * n_sc;
                }
                loop_check = true;
            }

            if(!loop_check) hist[now] = {kk, tmp};
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3788
N , K = (int(i) for i in input().split())

h = [0] * N
for i in range(N):
    h[i] = int(input())

h.sort()

min = 1000000000

for i in range(N - K + 1):
    if min > h[i + K - 1] - h[i]:
        min = h[i + K - 1] - h[i]

print(min)


Measured memory_bytes: 46040
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
int d[100000];
int num[100000];
int main(){
  int n,m; cin >> n >> m;
  fill_n(num,100000,1);
  d[0] = 1;
  rep(i,m){
    int a,b; cin >> a >> b;a--,b--; 
    num[a]--; num[b]++;
    if(d[a] == 1)
      d[b] = 1;
    if(num[a] == 0)
      d[a] = 0;
  }
  int ans = 0;
  rep(i,n){
    if(d[i])
      ans++;
  }
  cout <<ans << endl;
}

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int w, a, b; cin >> w >> a >> b;

  if(a<=b) {
    if(a+w>=b) {
      cout << 0 << endl;
    } else {
      cout << b-(a+w) << endl;
    }
  } else {
    if(b+w>=a) {
      cout << 0 << endl;
    } else {
      cout << a-(b+w) << endl;
    }
  }

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int N;

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

  unordered_map<int, int> map;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (map.find(a) != map.cend()) {
      map[a]++;
    } else {
      map[a] = 1;
    }
  }

  int res = 0;
  for (auto pair : map) {
    if (pair.first < pair.second)
      res += pair.second - pair.first;
    else if (pair.first > pair.second)
      res += pair.second;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 7136
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int x[1048577],y[1048577],mp[1024][1024],memo[1024][1024],m=1048576,p;
bool isp[1048577],done[1024][1024];

bool check(int p, int q){
	return (!(0<=p&&p<1024&&0<=q&&q<1024));
}

int solve(int i, int j){
	if(check(i,j)){
		return -INF;
	}
	if(done[i][j]){
		return memo[i][j];
	}
	done[i][j] = true;
	if(mp[i][j]>m){
		return memo[i][j] = -INF;
	}else if(mp[i][j]==p){
		return memo[i][j] = (isp[p]?1:0);
	}
	return memo[i][j] = max(max(solve(i-1,j-1),solve(i-1,j+1)),solve(i-1,j))+((isp[mp[i][j]])?1:0);
}

int main(void){
	int i=0,j=0,k,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0},ans;
	while(m){
		x[m] = i;
		y[m] = j;
		mp[i][j] = m;
		if(check(i+dx[p],j+dy[p]) || mp[i+dx[p]][j+dy[p]]){
			++p; if(p==4){ p -= 4; }
		}
		i += dx[p]; j += dy[p];
		--m;
	}
	fill(isp,isp+1048577,true); isp[0] = false; isp[1] = false;
	for(i=2; i<1048577; ++i){
		if(!isp[i]){
			continue;
		}
		for(j=i*2; j<1048577; j+=i){
			isp[j] = false;
		}
	}
	cin >> m >> p;
	while(m && p){
		fill(done[0],done[1024],false);
		ans = -INF;
		for(k=1; k<1048577; ++k){
			if(!isp[k]){
				continue;
			}
			ans = max(ans,solve(x[k],y[k]));
		}
		if(ans<=0){
			cout << "0 0" << endl;
			cin >> m >> p;
			continue;
		}
		for(k=1048576; k>0; --k){
			if(!isp[k]){
				continue;
			}
			if(solve(x[k],y[k])==ans){
				cout << ans << " " << k << endl;
				break;
			}
		}
		cin >> m >> p;
	}
	return 0;
}



Measured memory_bytes: 21532
n = int(input())
alst = [int(input()) for _ in range(n)]
alst.sort()
if n % 2 == 0:
    mid = n // 2
    ans = sum(alst[mid + 1:]) * 2 + alst[mid] - sum(alst[:mid - 1]) * 2 - alst[mid - 1]
else:
    mid = n // 2
    ans1 = sum(alst[mid + 1:]) * 2 - sum(alst[:mid - 1]) * 2 - alst[mid - 1] - alst[mid]
    ans2 = sum(alst[mid + 2:]) * 2 - sum(alst[:mid]) * 2 + alst[mid + 1] + alst[mid]
    ans = max(ans1, ans2)
    
print(ans)

Measured memory_bytes: 13360
import scala.io.StdIn.{readLine,readInt}

object Main {

  def add(s:String,t:String):String = {
    val (x,y) = if(s.length>t.length) (s,t) else (t,s)
    val r = new StringBuilder
    var carryOver = 0
    var (i,j) = (x.length-1,y.length-1)

    for(k <- j to 0 by -1) {
      val z = x(i).asDigit+y(k).asDigit+carryOver
      r.insert(0,z%10)
      carryOver = z/10
      i -= 1
    }

    for( k <- i to 0 by -1){
      val z = x(k).asDigit + carryOver
      r.insert(0,z%10)
      carryOver = z/10
    }

    if(carryOver>0) r.insert(0,"1")
    r.result
  }

  def main(args:Array[String]) = {
    val n = readInt
    for(i<-1 to n) {
      val s = readLine
      val t = readLine
      if(s.length > 80 || t.length > 80) println("overflow")
      else {
        val result = add(s,t)
        if(result.length > 80) println("overflow") else println(result)
      }
    }
  }
}

Measured memory_bytes: 43572
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d;
  e=min(b,d)-max(a,c);
  if(e<0) cout<<"0";
  else cout<<e;
  cout<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long int a,b;
int x[100005];
int main()
{
    scanf("%d %lld %lld",&n,&a,&b);
    for(int i=1;i<=n;i++)
        scanf("%d",&x[i]);
    long long int meghans=0;
    for(int i=2;i<=n;i++)
    {
        long long int y=x[i]-x[i-1];
        long long int cost=a*y;
        meghans+=min(cost,b);
    }
    printf("%lld",meghans);















    return 0;
}


Measured memory_bytes: 640
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M; string S;
	cin >> N >> M >> S;
	vector<int> safe;
	for (int i = 0; i <= N; ++i) {
		if (S[i] == '0') {
			safe.push_back(i);
		}
	}
	bool ok = true;
	for (int i = 1; i < safe.size(); ++i) {
		if (safe[i] - safe[i - 1] > M) {
			ok = false;
			break;
		}
	}
	if (!ok) {
		cout << -1 << endl;
	}
	else {
		int ptr = int(safe.size()) - 1;
		vector<int> seq;
		while (ptr > 0) {
			int cur = ptr;
			while (ptr > 0 && safe[cur] - safe[ptr - 1] <= M) --ptr;
			seq.push_back(safe[cur] - safe[ptr]);
		}
		for (int i = int(seq.size()) - 1; i >= 0; --i) {
			cout << seq[i];
			if (i > 0) cout << ' ';
		}
		cout << endl;
	}
}

Measured memory_bytes: 1480
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

long long maxm=-2017,minm=2000000000;

int main()
{
    int n,i;
    long long s;
    cin>>n;
    for (i=1;i<=n;i++)
    {
    	cin>>s;
    	if (s>maxm)
    	{
    		maxm=s;
		}
		if (s<minm)
		{
			minm=s;
		}
    }
	cout<<maxm-minm<<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;

int main(void){
  string s; cin >> s;
  rep(i,s.size()){
    if(i%2==0) cout << s[i];
  }
  cout << endl;
  
  return 0;
}


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

int n,m,dp[5][10010];
string a;

int main()
{
	int i;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>a;
		cout<<a<<endl<<a<<endl;;
	}
}

Measured memory_bytes: 256
function main(input) {
  input = input.trim();
  const [k, x] = input.split(" ").map(n => Number(n));
  const min = Math.max(x-k+1, -1000000);
  const max = Math.min(x+k-1, 1000000);
  const result = [];
  for (let i = min; i <= max; i++) {
    result.push(i);
  }
  console.log(result.join(" "));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
/**
 *   author: sahushivam
 *   created: 12 January 2020 (Sunday)  17:49:32
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

int k=0;

void solve(){
	int n, m;
	cin>>n>>m;
	vector<vector<pair<int,int>>> graph(n*m);
	vector<string> ss;
	for(int i=0;i<n;i++)
	{
		string s; cin>>s;
		ss.PB(s);
	}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(ss[i][j]=='.'){
				if(i+1 < n and ss[i+1][j]=='.')
				{
					graph[i*m+j].PB({1,(i+1)*m+j});
				}
				if(j+1 <m and ss[i][j+1]=='.')
				{
					graph[i*m+j].PB({1,i*m+(j+1)});
				}
				if(i-1>=0 and ss[i-1][j]=='.')
				{
					graph[i*m+j].PB({1,(i-1)*m+j});
				}
				if(j-1>= 0 and ss[i][j-1]=='.')
				{
					graph[i*m+j].PB({1,i*m+(j-1)});
				}
			}
		}
	}

	int ans=0;

	for(int i=0;i<n*m;i++)
	{
		k=0;
		if(ss[i/m][i%m]!='.') continue;
		vector<int>dist(n*m,INT_MAX);
		priority_queue<pair<int,int>,vector<pair<int,int> >, greater<pair<int,int> > > q;
	    int source=i;
	    q.push({0,source}); dist[source]=0;
	    while(!q.empty())
	    {
	    	int v=q.top().second;
	    	q.pop();
	    	for(auto u:graph[v])
	    	{
	    		int wei=u.first;
	    		int node=u.second;
	    		if(dist[node]>dist[v]+wei)
	    		{
	    			dist[node]=dist[v]+wei;
	    			q.push({dist[node],node});
	    		}
	    	}
	    }
		for(int i=0;i<n*m;i++)
		{
			if(dist[i]!=INT_MAX)
				ans=max(ans,dist[i]);
		}
	}
	cout<<ans;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int findGcd(int a, int b) {
	while(b > 0) {
		int t = a % b;
		a = b;	
		b = t;
	}
	return a;
}

int main() {
	int n, k, a;
	while (scanf("%d%d", &n, &k) == 2) {
		int max = 0, gcd = 0;
		for(int i = 0; i < n; i++) {
			scanf("%d", &a);
			max = max > a ? max : a;	
			gcd = findGcd(gcd, a);
		}
		if (k <= max && 0 == k%gcd) {
			printf("POSSIBLE\n");			
		} else {
			printf("IMPOSSIBLE\n");			
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>



int  mod(a) {
	if (a > 0)
		if (a%2 == 0)return 0;
		else return 1;

	else if (((-1)*a) % 2 == 0) return 0;
	else return 1;


}
int main() {
	long long n ;
	int a[1000000], i,j;
	scanf("%lld", &n);
	for (i=0; n != 0;i++) {
		a[i] = mod(n);
		n = (n - a[i]) / (-2);
		
	}
	if (i == 0) {
		printf("%d", 0);
		return 0;
	}
	for(j=i-1;j>=0;j--)
	printf("%d", a[j]);
	
	
	return 0;

}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int Mn = 1e9, s, n, a;
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &a);
		s += a;
		if (a % 10)Mn = min(Mn, a);
	}
	if (s % 10 == 0) {
		if (Mn > 8e8)printf("0\n");
		else printf("%d\n", s - Mn);
	}
	else printf("%d\n", s);
}

Measured memory_bytes: 128
#include <cstdio>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <iostream>
#include <functional>
#include <cmath>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  char a[99];
  char b[99];
  int num,rooti;
  double rootd;
  scanf("%s %s\n",b,a);
  strcat(b,a);
  num = atoi(b);
  rootd = sqrt((double)num);
  rooti = (int)rootd;
  rooti = (double)rooti;

  if(rooti == rootd){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main(){
  int n,w,tw,tv;
  vector<vector<ll>> dp(101,vector<ll>(100001,0));
  cin >> n >> w;
  for(int i=1;i<=n;i++){
    cin >> tw >> tv;
    for(int j=0;j<=w;j++){
      dp[i][j]=dp[i-1][j];
      if(j-tw>=0){
        dp[i][j]=max(dp[i][j],dp[i-1][j-tw]+tv);
      }
    }
  }
  cout << dp[n][w]<<endl;
}


Measured memory_bytes: 80256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

int dp[3005][6005];
void solve(){
    int n,t;
    cin>>n>>t;
    vector<pair<int,int>>p(n);
    rep(i,n){
        cin>>p[i].first>>p[i].second;
        p[i].second=-p[i].second;
    }
    sort(p.begin(),p.end());
    rep(i,n){
        for(int j=0;j<=6000;++j){
            if(j-p[i].first>=t||j-p[i].first<0)dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j],dp[i][j-p[i].first]-p[i].second);
        }
    }
    int maxv=0;
    rep(i,6001)chmax(maxv,dp[n][i]);
    cout<<maxv<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 70656
d=list(map(int,input().split()))

N=d[0]
K=d[1]

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for i in range(1,K+1):
  if i > N-K+1:
    print(0)
  else:
    num = cmb(N-K+1, i)*cmb(K-1, i-1)
    print(int(num)%(1000000000+7))
    
  



Measured memory_bytes: 3444
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

vector<int> uf, usz;
int nc;

void init(int n){
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

  for(int i = 0; i < uf.size(); i++){
    uf[i] = i;
  }
}

int find(int a){
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}

void union_(int a, int b){
  a = find(a);
  b = find(b);

  if(a != b){
    if(usz[a] >= usz[b]){
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}

int check(int a, int b){
  return (find(a) == find(b)) ? 1 : 0;
}

int get_size(int a){
  return usz[find(a)];
}

ll d[700100];

int main(){
	ll n,m,q;
	cin>>n>>m>>q;
	ll flag7 = 0;
	if(m%7!=0){
		flag7 = 1;
		m *= 7;
	}
	init(m+1);
	clr(d,0);
	vector<ll> v;
	rep(i,0,q){
		ll a;
		cin>>a;
		if(flag7==1){
			rep(j,0,7){
				d[a+(m/7)*j] = 1;
			}
		}
		else{
			d[a] = 1;
		}
	}
	rep(i,0,m){
		if(d[i]==1){
			union_(i,m);
			continue;
		}
		vector<ll> v1;
		if(i-7>=0)v1.pb(i-7);
		if(i%7!=0)v1.pb(i-1);
		if(i%7!=6)v1.pb(i+1);
		if(i+7<m)v1.pb(i+7);
		rep(j,0,v1.sz){
			if(d[v1[j]]==1)continue;
			union_(i,v1[j]);
		}
	}
	ll ans1 = nc-1;
	set<ll> se1;
	set<pair<ll,ll> > se2; 
	rep(i,0,7){
		if(d[i]==0&&d[m-7+i]==0){
			ll a1 = find(i);
			ll b1 = find(m-7+i);
			if(a1==b1)se1.insert(a1);
			else{
				se2.insert(mp(max(a1,b1),min(a1,b1)));
			}
		}
	}
	vector<ll> v1(all(se1));
	vector<pair<ll,ll> > v2(all(se2));
	ll ans2 = v1.sz;
	ll ans3 = v2.sz;
	ll ans4 = 0;
	rep(i,0,v2.sz){
		int flag = 1;
		rep(j,0,v1.sz){
			if(v1[j]==v2[i].fi||v1[j]==v2[i].se){
				flag = 0;
			}
		}
		if(flag == 0){
			ans3--;
			ans4++;
		}
	}
	ll a = 7*n/m;
	ans1 -= (ans2+ans4+ans3*2);
	cout << ans1*a+ans2+ans3*(a+1)+ans4 << endl;
	return 0;
}




Measured memory_bytes: 11168
//0007:   Debt Hell
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		 int week = Integer.parseInt(in.readLine());

		 int debt = 100000;
		 
		 for(int i=0;i<week;i++){
			 debt =(int)Math.ceil(debt*1.05/1000)*1000;
		 }

			System.out.println(debt);

	}
}

Measured memory_bytes: 16852
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
 
#define rep for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int s[1000][1000];

int main(){
  int h,w,a,b;cin >> h >> w >> a >> b;
  for(int i = 0;i<h;i++){
    for(int j = 0;j<w;j++){
      if(i<b and j<a or i>=b and j >= a){
        cout << "0";
      }else{
        cout << "1";
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 1LL << 60;
constexpr int inf = 1 << 30;

int t[1 << 8];

int main() {
    string S; cin >> S;
    ++t[S[0]];
    ++t[S[1]];
    ++t[S[2]];
    ++t[S[3]];
    int cnt = 0;
    bool ans = true;
    for (int i = 0; i < (1 << 8); ++i) {
        cnt += t[i] > 0;
        if (t[i] > 0 && t[i] != 2) {
            ans = false;
        }
    }
    if (cnt != 2) ans = false;
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 760
n = int(input())
a = []
a.append([int(i) for i in input().split()])
a.append([int(i) for i in input().split()])
ans = 0
for i in range(n):
    tmp = a[0][0]
    x = 0
    y = 0
    for j in range(n):
        if i == j:
            y += 1
        else:
            x += 1
        tmp += a[y][x]
    ans = max(tmp,ans)
print(ans)


Measured memory_bytes: 63676
#include<iostream>
using namespace std;
int main(){
	int x;
	cin>>x;
	int array[100]={};
	for(int i=0;i<x;i++){
		cin>>array[i];
	}
	for(int i=x-1;i>=0;i--){
		if(i !=x-1) cout<<" ";
		cout<<array[i];
	}
	cout<<endl;
        return 0;
}


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

using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back

int main(){
	fast;
	lli n,m,x;
	cin>>n>>m;
	lli sum=0;
	for (int i=0;i<m;i++){
		cin>>x;
		sum+=x;
	}
	if (sum<=n) cout<<n-sum<<endl;
	else cout<<"-1"<<endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define N 205
using namespace std;
typedef pair<int,int> P;
typedef pair<long double,P> P1;

struct point{
  long double x,y,z;
};

int n;
point p[N],v[N];
long double r[N],vr[N];
const long double EPS=(1e-9);

long double getd(long double T,int a,int b){
  
  long double X=(p[a].x+T*v[a].x)-(p[b].x+T*v[b].x);
  long double Y=(p[a].y+T*v[a].y)-(p[b].y+T*v[b].y);
  long double Z=(p[a].z+T*v[a].z)-(p[b].z+T*v[b].z);
  
  return sqrt(X*X+Y*Y+Z*Z);
}

long double getTime2(long double T,int a,int b){
  
  long double L=0,R=T;
  
  while(L+EPS<R){
    
    long double M=(L+R)/2.0;
    long double X=r[a]-M*vr[a]+r[b]-M*vr[b];
    
    if(getd(M,a,b)>X) L=M;
    else R=M;
    
  }
  
  return L;
}

long double getTime(int a,int b){
  
  long double L=0,R=min(r[a]/vr[a],r[b]/vr[b]);
  
  while(L+EPS<R){
    
    long double M=(L+R)/2.0;
    long double pX=r[a]-M*vr[a]+r[b]-M*vr[b];
    long double X=r[a]-(M+EPS)*vr[a]+r[b]-(M+EPS)*vr[b];
    
    if(getd(M,a,b)-pX>getd(M+EPS,a,b)-X) L=M;
    else R=M;
    
  }
  
  long double X=r[a]-L*vr[a]+r[b]-L*vr[b];
  
  if(getd(L,a,b)<X) return getTime2(L,a,b);
  return (1e9);
}

int main(){
  
  while(1){
    
    cin>>n;
    if(!n) break;
    
    for(int i=0;i<n;i++){
      cin>>p[i].x>>p[i].y>>p[i].z;
      cin>>v[i].x>>v[i].y>>v[i].z;
      cin>>r[i]>>vr[i];
    }
    
    bool used[N];
 
    memset(used,0,sizeof(used));

    priority_queue<P1,vector<P1>,greater<P1> > q;
    
    for(int i=0;i<n;i++)
      q.push(P1(r[i]/vr[i],P(i,i)));
    
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	q.push(P1(getTime(i,j),P(i,j)));
    
    long double ans[N];
    
    while(!q.empty()){
      
      P1 t=q.top(); q.pop();
      
      long double T=t.first;
      int a=t.second.first;
      int b=t.second.second;
      
      if(used[a]||used[b]) continue;
      
      used[a]=used[b]=true;
      
      ans[a]=ans[b]=T;
      
    }
    
    for(int i=0;i<n;i++) printf("%.10Lf\n",ans[i]);
    
  }
  
  return 0;
}

Measured memory_bytes: 4552
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int M;
	cin >> M;
	vector<int> p(M), q(M);
	for (int i = 0; i < M; ++i) {
		cin >> p[i] >> q[i];
		--p[i], --q[i];
	}
	vector<int> par(N), depth(N);
	function<void(int, int)> make_order = [&](int pos, int pre) {
		par[pos] = pre;
		for (int i : G[pos]) {
			if (i == pre) continue;
			depth[i] = depth[pos] + 1;
			make_order(i, pos);
		}
	};
	make_order(0, -1);
	vector<long long> A(1 << M);
	for (int i = 0; i < M; ++i) {
		long long x = 0;
		while (p[i] != q[i]) {
			if (depth[p[i]] < depth[q[i]]) {
				swap(p[i], q[i]);
			}
			x |= 1LL << (p[i] - 1);
			p[i] = par[p[i]];
		}
		for (int j = 1 << i; j < 2 << i; ++j) {
			A[j] = A[j - (1 << i)] | x;
		}
	}
	long long ans = 0;
	for (int i = 0; i < 1 << M; ++i) {
		int parity = 0;
		for (int j = 0; j < M; ++j) {
			if ((i >> j) & 1) parity ^= 1;
		}
		long long mul = 1LL << (N - 1 - __builtin_popcountll(A[i]));
		if (__builtin_popcount(i) & 1) ans -= mul;
		else ans += mul;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int cnt=0;
    for(int i=a;i<=b;i++)
    {
        if(i%c==0)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
vector<int> vec(n+1);
  for(int i=1;i<n+1;i++){
  cin >> vec.at(i);}
  int cnt=0;
  for(int i=1;i<n+1;i++){
    if(vec.at(vec.at(i))==i)cnt++;}
  cout << cnt/2 <<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n;
    int d;
    cin >> n >> d;
    vector<int> x(n);
    vector<int> y(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    double root = 0;
    int count = 0;
    for(int i = 0; i < n; i++){
        root = sqrt(pow(x[i], 2) + pow(y[i], 2)); 
        if(root <= d){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4904
/*input
20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/
#include <bits/stdc++.h>
using namespace std;
#define TEMPLATE

#ifdef TEMPLATE
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

#endif

struct FENWICK
{
	// queries [1:N]
	vector<ll>A;
	int N;
	FENWICK(int n): N(n)
	{
		A.resize(n + 1, 0);
	}
	void add(int i, ll x)
	{
		for (; i <= N; i += (i) & (-i))
			A[i] = (x + A[i]) % MOD;
	}
	ll getQ(int i)
	{
		ll get = 1;
		for (; i > 0; i -= (i) & (-i))
			get = (A[i] + get) % MOD;
		return get;
	}
};

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N, M;
	cin >> N >> M;
	vi pir(N);
	vi ant(M);
	for (int i = 0; i < N; ++i)
		cin >> pir[i];

	for (int i = 0; i < M; ++i)
		cin >> ant[i];

	FENWICK sums(M);

	for (int i = 0; i < N; ++i)
		for (int j = M - 1; j >= 0; --j)
			if (pir[i] == ant[j])
				sums.add(j + 1, sums.getQ(j));

	printf("%lld\n", sums.getQ(M));
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
pii dolls[220];
int dp[220];//dp[i]:=i番目の人形を最後にしたときの最大の人形
int main(){
	int n,m;
	while(cin>>n,n){
		memset(dp, 0, sizeof(dp));
		memset(dolls, 0, sizeof(dolls));
		for(int i =0;i <n;i++){
			int h,r;
			cin>>h>>r;
			dolls[i].first=h;
			dolls[i].second=r;
		}
		cin>>m;
		for(int i =0;i <m;i++){
			int x,y;
			cin>>x>>y;
			dolls[n+i].first=x;
			dolls[n+i].second=y;
		}
		for(int i =0;i <n+m;i++){
			dp[i]=1;
		}
		sort(dolls,dolls+n+m);
		for(int i =0;i <n+m;i++){//最後の人形
			for(int j =0;j <n+m;j++){
				if(i==j)continue;
				if(dolls[i].first>dolls[j].first&&dolls[i].second>dolls[j].second){
					dp[i]=max(dp[i],dp[j]+1);
				}
			}
		}
		int ans = 0;
		for(int i =0;i <n+m;i++){
			ans=max(ans,dp[i]);
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

int main(void){
    //素数生成
    vector<int> sosu;
    sosu.push_back(2);
    for(int i=3;i<100001;i+=2){
        if(!any_of(sosu.begin(),sosu.end(),[i](int x){return i%x == 0;})){
            sosu.push_back(i);
        }
    }
    
    //2017に似た数生成
    vector<int> like;
    for(int i=3;i<100001;i+=2){
        if(binary_search(sosu.begin(),sosu.end(),(i+1)/2) && binary_search(sosu.begin(),sosu.end(),i))like.push_back(i);
    }
    
    //累積和生成
    array<int ,100001>rui = {};
    
    for(int i=3;i<100001;i++){
        rui[i] = rui[i-1];
        if(binary_search(like.begin(),like.end(),i))rui[i]++;
    }

    int roop,a,b;
    cin >> roop;
    for(int i = 0;i<roop;i++){
        cin >> a >> b;
        cout << rui[b]-rui[a-1] << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;

ll solve(ll K, const vector<ll>& as)
{
    ll mask = 1LL << 50, X = 0;

    while (mask)
    {
        ll ones = 0, zeros = 0;

        // Conta o número de zeros e uns de todos os a's no bit indicado pela máscara
        // Observe que 10^12 < 2^50
        for (ll a : as)
            if (a & mask)
                ++ones;
            else
                ++zeros;

        // Caso exista mais zeros do que uns e a adição do bit não supera K, atualize X
        if (ones < zeros and (X | mask) <= K)
            X |= mask;

        mask >>= 1;
    }

    ll ans = 0;

    // Cálculo de X
    for (const auto& a : as)
        ans += X ^ a;

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;

    vector<ll> as(N);

    for (int i = 0; i < N; ++i)
        cin >> as[i];

    int ones = 0;

    for (int i = 0; i < N; ++i)
        if (as[i] & 1)
            ones++;

    auto ans = solve(K, as);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
from collections import deque

n, m = list(map(int, input().split(' ')))

abm = [None] * m
for i in range(m):
    abm[i] = list(map(int, input().split(' ')))

def check(i):
    cl = [False] * n
    edges = abm[:i] + abm[i + 1:]
    d = deque([1])

    def bfs():
        while True:
            if not d:
                return
            
            v = d.popleft()
            if cl[v - 1]:
                continue
            else:
                cl[v - 1] = True

                nxts = [edge[0] for edge in edges if edge[1] == v]
                for nxt in nxts:
                    d.append(nxt)

                nxts = [edge[1] for edge in edges if edge[0] == v]
                for nxt in nxts:
                    d.append(nxt)

    bfs()

    if cl.count(False):
        return True
    else:
        return False

count = 0
for i in range(m):
    if check(i):
        count += 1
print(count)



Measured memory_bytes: 42480
#include <bits/stdc++.h>
using namespace std;
vector<bool> is_prime;
void era(int n){
    for (int p=2; p<=n; p++) {
        if (!is_prime[p]) continue;
        for (int k=2*p; k<=n; k += p) is_prime[k] = false;
    }
}
int main(){
	int x; cin >> x;
    is_prime.assign(10*x+1,1);
    era(10*x);
    for(int i=x; ; ++i){
        if(is_prime[i]){
            cout << i <<endl;
            break;
        }
    }
}

Measured memory_bytes: 384
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
for i in range(M):
	a[i], b[i] = map(int, input().split())
	a[i] -= 1
	b[i] -= 1

cnt = [0 for i in range(N)]
for i in range(M):
	cnt[a[i]] += 1
	cnt[b[i]] += 1
for i in cnt:
	if i % 2 == 1:
		print("NO")
		break
else:
	print("YES")

Measured memory_bytes: 85024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int P = scanner.nextInt();
		int Q = scanner.nextInt();
		int R = scanner.nextInt();
		int ans = Math.min(P + Q, Math.min(P + R, Q + R));
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 21332
#include <stdio.h>
using namespace std;

int main() {
  int n, m, a[100]={};
  scanf("%d %d", &n, &m);
  for (int i=0; i<n; i++) {
    int k;
    scanf("%d", &k);
    for (int j=0; j<k; j++) {
      int d;
      scanf("%d", &d);
      a[d]++;
    }
  }
  int ans=0;
  for (int i=1; i<=m; i++) {
    if ( a[i]==n ) ans++;
  }
  printf("%d\n", ans);
  
  return 0; 
}

Measured memory_bytes: 128
import std.stdio;
import std.string;
 
void main() {
    string ans = "WA";
    string s = readln.strip;

    if (s[0] == 'A') {
        ulong c = 0;
        foreach(i, e; s[0..$ - 1]) {
            if (e == 'C' && i > 1) {
                c = i;
                break;
            }
        }
        if (c > 1) {
            ans = "AC";
            foreach(i, e; s) {
                if (i == 0 || i == c)
                    continue;
                if (e < 97 || e > 122) {
                    ans = "WA";
                    break;
                }
            }
        }
    }
    writeln(ans);
}

Measured memory_bytes: 256
import java.util.*;
 
class Main{
	public static void main(String[] a){
		String X;
		Scanner in = new Scanner(System.in);
		X = in.next();
		Stack<Character> s = new Stack<Character>();
		for(int i=0; i<X.length(); i++){
			if(s.empty()){
				s.push(X.charAt(i));
				continue;
			}
			if((s.peek()=='S') && (X.charAt(i)=='T')) s.pop();
			else s.push(X.charAt(i));
		}
		StringBuilder sb = new StringBuilder("");
		while(!s.empty()){
			sb.append(s.pop());
		}
		System.out.println(sb.length());
	}
}

Measured memory_bytes: 28296