akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
	int k, s;
	cin >> k >> s;
	long long ans = 0;
	for(int x = 0; x <= k; x++) {
		for(int y = 0; y <= k; y++) {
			int z = s - x - y;
			if(z >= 0 && z <= k) {
				ans += 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using namespace std;

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

long long pows[11], res = 0, cnt = 0;
int len = 0;
void rec(long long curpast, long long pastsumm, long long ost, long long ostlen) {
    res += pastsumm + ost;
    long long n = 0;
    for (int i = 1; i < ostlen; i++) {
        rec(ost % pows[i], pastsumm + ost % pows[i], ost / pows[i], ostlen - i);
        ///cout << ost % pows[i] << ' ' << pastsumm + ost % pows[i] << ' ' << ost / pows[i] << endl;
    }
}

void solve() {
    long long s;
    cin >> s;
    res = 0;
    long long p = 1;
    while(s / p) {
        pows[len] = p;
        len++;
        p *= 10;
    }
    pows[len] = p;
    rec(0, 0, s, len);
    cout << res;
}

int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        if (0) {
            freopen("weapons.in", "r", stdin);
            freopen("weapons.out", "w", stdout);
        }
    #endif

    solve();

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int, int>
#define lli long long int
#define tup tuple<int, int, int>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b ,c, d=0;
    cin >> a >> b;
    while(a--)
    {
        cin >> c;
        d += 2*min(c, abs(b-c));
    }
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

vector < ll > A,B; 

int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	int n,x,mn = mod;
	ll ans = 0;
	scanf("%d %d",&n,&x);
	REP(i,n){
		int u;scanf("%d",&u);A.pb(u);
		ans += u;
		mn = min(mn,u);
	}
	REP(i,n){
		if(A[i]==mn) mn = 0;
		if(!mn) B.pb(A[i]);
		else A.pb(A[i]);
	}
	REPP(i,n,A.size()) B.pb(A[i]);
	// REP(i,n) printf("%lld ",B[i]);printf("\n");
	A = B;
	REPP(i,1,n){
		set < pii > S;
		ll pans = (1ll)*x*i;
		// printf("%lld\n",pans);
		REP(j,n){
			S.insert(mp(A[j],j));
			while(!S.empty()){
				pii a = *S.begin();
				// printf("%d %d %d %d\n",a.X,a.Y,j,i);
				if(j-a.Y>i) S.erase(a);
				else{ pans+=a.X;break;}
			}
		}
		ans = min(ans,pans);
	}
	printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 384
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,y) for(int i=(x);i<=(y);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    cin>>n;
    vi v(n);
    rep(i,n){
        cin>>v[i];
    }
    sort(all(v));
    int ans=0;
    rep(i,n-1){
        ans+=v[i+1]-v[i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    string str;
    cin >> str;

    int s=-1, g=-1;
    for (int i = 0; i < str.length()-1; i++) {
        if (str[i] == str[i+1]) {
            s = i + 1;
            g = i + 2;
        }
    }

    for (int i = 0; i < str.length() - 2; i++) {
        if (str[i] == str[i+2]) {
            s = i + 1;
            g = i + 3;
        }
    }

    cout << s << " " << g << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;

    double th = (M_PI/6)*(11*m/60-h);
    cout <<  std::setprecision(25) << sqrt(a*a + b*b -2*a*b*cos(th)) << endl;
    
    return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s,t;
cin >> s >> t;
int cnt = 0;
for (int i = 0; i < (int) s.length(); ++i){
	if (s[i] != t[i]) ++cnt;
}
cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 3816
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner  sc = new Scanner(System.in);
        while(true){
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(x == 0&&y ==0)break;
            else if(x>y)System.out.println(y+" "+x);
            else System.out.println(x+" "+y);
        }
        sc.close();
    }
}


Measured memory_bytes: 34792
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node *prev, *next;
};

Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	// ???????????´??????????´??????????
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key) {
	Node *cur = nil->next;	// ??????????¬????????´?????????????
	while ( cur != nil && cur->key != key ) {
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t) {
	if ( t == nil ) return;	// t??????????????´?????????????????????
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	// ????´¢????????????????????????
	deleteNode(listSearch(key));
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while ( 1 ) {
		if ( cur == nil ) break;
		if ( isf++ > 0 ) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for ( i = 0; i < n; i++ ) {
		scanf("%s%d", com, &key);	// ?????????????????\?????¢??°????????¨
		if ( com[0] == 'i' ) { insert(key); np++; size++; }
		else if (com[0] == 'd' ) {
			if (strlen(com) > 6 ) {
				if (com[6] == 'F' ) deleteFirst();
				else if (com[6] == 'L') deleteLast();
			} else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}

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

int main() {
    int H, W;
    while(1) {
        
        cin >> H >> W;
        
        if(H == 0 && W == 0) {
            break;
        }
        
        for(int i = 0; i < H; i++) {
            if(i == 0 || i == H - 1) {
                for(int j = 0; j < W; j++) {
                    cout << '#';
                }
            }
            else {
                cout << '#';
                for (int k = 0; k < W - 2; k++) {
                    cout << '.';
                }
                cout << '#';
            }
            cout << endl;
        }
        
        cout << endl;
    }
    
    
    return 0;
}


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

int main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll ans;

    if(x/d>=k)
        ans=x-d*k;
    else
    {
        ll e=x/d;
        k-=e;
        x-=e*d;
        if(k%2==1)
            x=abs(x-d);
        ans=x;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
import collections

n = int(input())
p = list(map(int, input().split()))
count2 = []
for i in range(1, n-1):
    count = []
    count.append(p[i-1])
    count.append(p[i])
    count.append(p[i+1])
    count.sort()
    if(count[1] == p[i]):
        count2.append(count[1])
ans = collections.Counter(count2)
print(len(ans))

Measured memory_bytes: 3316
s = input()
l = len(s)
flag = False
for i in range(l//2):
    if s[i] != s[-(i+1)]:
        flag = True
for i in range(int((l-1)/2)):
    if s[i] != s[int((l-1)/2)-i+1] and s[int((l+3)/2)+i-1] != s[-(i+1)]:
        flag = True
print('No' if flag else 'Yes')

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  vector<int> rate(9);
  rep(i,n){
    int s =  min(a.at(i)/400, 8);
    rate.at(s)++;
  }

  int fix=0;
  int free=rate.at(8);
  rep(i,8){
    if(rate.at(i))fix++;
  }

  cout << max(fix,1) << " " << fix+free;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if (abs(a-c) <= d) cout << "Yes" << endl;
    else if (abs(a-b) <= d && abs(b-c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,ans,m;
    int x[100];
    cin>>n;
    cin>>m;
    ans=1;
    for (int i=1;i<n;i++){
        cin>>x[i];
        if(x[i]>=m){
            m=x[i];
            ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}

ll n,m;
string a,b;

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>n>>m>>a>>b;
	ll k=n/gcd(n,m)*m;
	n=k/n;
	m=k/m;
	ll kk=n/gcd(n,m)*m;
	for(ll i=0;i<k;i+=kk){
			if(a[i/n]!=b[i/m]){
				Tone(-1);
				return 0;
			}
	}
	
	Tone(k);
	
	return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const ll mod = 1000000007;

int main(){
	ll s; cin >> s;
	ll x = (ll)sqrt((long double)s);
	for(ll a=max(1LL,x-3LL);a<=x+3LL;a++){
		if(a*a <= s && s <= a*(a+1)){
			cout << 0 << " " << 0 << " " << a << " " << 1 << " " 
			<< a*(a+1)-s << " " << a+1 << endl;
			return 0;
		}
		if(a*(a+1) <= s && s <= (a+1)*(a+1)){
			cout << 0 << " " << 0 << " " << a+1 << " " << 1 << " " 
			<< (a+1)*(a+1)-s << " " << a+1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	int k;
	cin >> k;
	int ans = 0;
	int count = 0;
	while (count <= 1000000) {
		ans = (ans * 10 + 7) % k;
		count++;
		if (ans == 0) {
			cout << count << endl;
			return 0;
		}

	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 3608
n, m, x, y = map(int, input().split())
xi = sorted(list(map(int, input().split())), reverse=True)
yi = sorted(list(map(int, input().split())), reverse=True)

xi.append(x)
yi.append(y)

if max(xi) >= min(yi):
    print("War")
    exit(0)

print("No War")

Measured memory_bytes: 3064
s = input()
k = int(input())


e=len(s)
l=[]
for i in range(e):
	for j in range(i+1, e+1):
		a = s[i:j]
		if len(a)>k: break
		#print(i,j,a)
		l.append(a)


l=list(set(l))
l.sort()
#print(l)

print(l[k-1])


Measured memory_bytes: 5052
character(26) l
integer,dimension(26)::a
character(100) S
l="abcdefghijklmnopqrstuvwxyz"
a=0
read*,S
do i=1,Len_trim(S)
do j=1,26
if(S(i:i)==l(j:j)) a(j)=mod(a(j)+1,2)
end do
end do
print"(A)",merge("Yes"," No",maxval(a)==0)
end

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  long long n,a,b,sum=0,ans=0;
  long long syo = 0,amari = 0;
  
  cin >> n;
  cin >> a;
  cin >> b;
  
  if(a == 0)
  {
    cout << 0 << endl;
  }
  else if (b == 0)
  {
    cout << n << endl;
  }
  else
  {
    sum = a+b;
    if(n/sum >= 1)
    {
      syo = (long long)(n/sum);
      amari = n % sum;

    }
    else
    {
      amari = n;
    }
  	if(amari > a)
  	{
      amari = a;
    }
  	ans = syo*a+amari;

  	cout << ans << endl;
  }
}


Measured memory_bytes: 256
import math
import collections

N = input()
nums = list(map(int, input().split()))
counter = collections.Counter(nums)
patterns = {}
for k, v in counter.items():
    patterns[k] = math.comb(v, 2)

baseline = sum(v for v in patterns.values())

for n in nums:
    # todo : memo
    print(baseline - patterns[n] + math.comb(counter[n] - 1, 2))

Measured memory_bytes: 34420
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
set<string> st;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		st.insert(s);
	}
	cout << (int)st.size() << endl;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    bool ok = true;
    for(int i = 1; i <= n; ++i)
    {
        int Ai;
        cin >> Ai;
        if(Ai % 2 == 0)
            if(Ai % 3 == 0 || Ai % 5 == 0)
            {
                continue;
            }
            else
            {
                ok = false;
                break;
            }
    }

    if(ok)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;

    return 0;
}


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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;

int main() {
    string S;
    cin>>S;
    regex re("A?KIHA?BA?RA?");
    smatch match;
    cout<<(regex_match(S,match,re)?"YES":"NO")<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int n,k; cin>>n>>k;
  int now = 1;
  for(int i = 0; i < n; i++) {
    int next_a = now * 2;
    int next_b = now + k;
    now = min(next_a, next_b);
  }

  cout << now << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

int main() {
  int N, ans;
  cin >> N;

  ans = N % 1000;
  if (ans == 0) {
    cout << 0 << endl;
  } else {
    /* code */
    cout << 1000 - ans << endl;
  }
}


Measured memory_bytes: 3620
s = input()
Ls =len(s)
E = ""
O = ""

for i in range(Ls):
    if i%2 == 0:
        O = O + s[i]
    else:
        E = E + s[i]
Om = O.replace("L","")
Em = E.replace("R","")

if len(O)==len(Om) and len(E)==len(Em):
    ans = "Yes"
else:
    ans = "No"
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int e,v[400010],first[200010],nex[400010];
void AddEdge(int U,int V){
	v[++e]=V;
	nex[e]=first[U];
	first[U]=e;
}
typedef pair<int,int> Point;
set<Point>S;
int n,m;
int main(){
	int x,y;
//	freopen("a.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		scanf("%d%d",&x,&y);
		AddEdge(x,y);
		AddEdge(y,x);
		S.insert(make_pair(x,y));
		S.insert(make_pair(y,x));
	}
	for(int i=first[1];i;i=nex[i]){
		if(S.find(make_pair(v[i],n))!=S.end()){
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 22912
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>V(N);
	vector<int>C(N);
	rep(i, N) {
		cin >> V[i];
	}
	rep(i, N) {
		cin >> C[i];
	}
	vector<int>F(N);
	rep(i, N) {
		F[i] = V[i] - C[i];
	}
	int ans = 0;
	rep(i, N) {
		if (F[i] > 0) {
			ans += F[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

using Pi = pair<int, int>;

int N,M;
vector<int> A,B;


int main()
{
	
	cin >> N;
	cin >> M;
	A = vector<int>(N);
	B = vector<int>(N);
	auto W = vector <Pi>(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		cin >> B[i];

		W[i] = make_pair(A[i],B[i]);
	}

	sort(W.begin(), W.end(), [](Pi l, Pi r) {
		return l.first < r.first;
	});
	
	int ans = 0;

	auto c = [](Pi l, Pi r) {return l.second < r.second;};
	priority_queue<Pi, vector<Pi>, decltype(c) > q(c);

	int v = 0;
	for (int i = 0; i < M; i++) {
		while (v < N && W[v].first <= i+1) {
			q.push(W[v]);
			v++;
		}

		if (!q.empty()) {
			Pi w = q.top();
			q.pop();
			ans += w.second;
		}
	}


	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 2936
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=map(int, input().split())
if 4*a*b<(c-a-b)**2 and (c-a-b)>=0:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 62048
//abc054_a.cpp
//Fri Oct 19 23:08:11 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a,b;
	cin >> a >> b;
	if (a == b){
		cout << "Draw" << endl;
	}else if (b == 1){
		cout << "Bob" << endl;
	}else if (a == 1){
		cout << "Alice" << endl;
	}else if (a>b){
		cout << "Alice" << endl;
	}else if (b>a){
		cout << "Bob" << endl;
	}
}

Measured memory_bytes: 256
import sys

def furui(n):
  l = [1 for i in range(n+1)]
  l[0] = 0
  l[1] = 0
  for i in range(2,n+1):
    if l[i] == 1:
      for j in range(2,n//i+1):
        l[i*j] = 0
  l2 = []
  for i in range (len(l)):
    if l[i] == 1:
      l2.append(i)
  return l2

for line in sys.stdin:
  n = int(line)
  l = furui(n)
  if max(l) == n:
    i1 = l[len(l)-2]
  else:
    i1 = max(l)
  i2 = n
  while True:
    i2 += 1
    flag = 1
    for i in l:
      if i2 % i == 0:
        flag = 0
        break
    if flag:
      break
  print(str(i1) + " " + str(i2))

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

int main(void){
	int a, b;
	cin >> a >> b;
	int cnt = 0;
	for(int i = a; i <= b; ++i){
		if(i/10000==i%10&&i/1000%10==i%100/10) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 300001;
const ll MOD = 1e9 + 7;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll pw(ll a, ll b) {
    ll res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = res * a % MOD;
        }
        a = a * a % MOD;
    }
    return res;
}

template<typename Cont>
vector<vector<int>> accum2d(Cont a, int n, int m) {
    vector<vector<int>> res(n, vector<int>(m));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            res[i][j] = a[i][j];
            if (i > 0) {
                res[i][j] += res[i - 1][j];
            }
            if (j > 0) {
                res[i][j] += res[i][j - 1];
            }
            if (i > 0 && j > 0) {
                res[i][j] -= res[i - 1][j - 1];
            }
        }
    }
    return res;
}

vector<vector<int>> resize2d(vector<vector<int>> a, int n, int m) {
    a.resize(n);
    for (auto &x:a) {
        x.resize(m);
    }
    return a;
}

int up[1030][1030];
int down[1030][1030];
int lft[1030][1030];
int rght[1030][1030];
int ans[1030][1030];
int pref[1030][1030];
int arifm[1030][1030];
int dp1[1030][1030];
int dp2[1030][1030];

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    auto solve = [](int _) {
        int n;
        cin >> n;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                int x = i - 1;
                int y = j - 1;
                int val = x ^y;
                int f;
                for (f = 0;; ++f, val >>= 1) {
                    if (val & 1) {
                        break;
                    }
                }
                cout << f + 1 << " ";
            }
            cout<<"\n";
        }
    };


    fast_io();
    cout.precision(9);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    for (int i = 1; i <= 1; ++i)solve(i);
    auto end = chrono::steady_clock::now();

    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}


Measured memory_bytes: 512
/*
 * RD
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
#define pii pair<int,int>
#define sz(x) ((int)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const ll inf=1e18;
const int mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//12367769,266916112,123798211
ll powm(ll a, ll b, ll m);

int a[10];
void solve()
{
	int b;
	for(int i=0; i<4; i++)
	{
		cin>>b;
		a[b]=1;
	}
	if(a[1]&&a[9]&&a[7]&&a[4])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	auto clk=clock();
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}
ll powm(ll a,ll b, ll m) {
	ll te=1;
	while(b) {
		if(b&1) te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


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

using namespace std;

int main(int argc, const char * argv[])
{
    int height[10];
    for (int i=0; i<10; i++) {
        cin >> height[i];
    }
    sort(height, height+10, greater<int>());
    
    for (int i=0; i<3; i++) {
        cout << height[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	string s;
	cin >> s;
	int a[3];
	a[0] = a[1] = a[2] = 0;
	for(int i = 0; i < 3; i++) {
		a[(int)(s[i] - 'a')]++;
	}
	if(a[0] == 1 && a[1] == 1 && a[2] == 1) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int A,B;
  scanf("%d %d",&A, &B);
  if (A == B){
    printf("Draw");
  } else if (A == 1 && 1 < B < 13 || A !=1 && B !=1 && A-B>0){
    printf("Alice");
  } else if (B == 1 && 1 < A < 13 || B !=1 && A !=1 && B-A>0){
    printf("Bob");
  }else {
    printf("Invalid!");
  }
             return 0;
             }
    


Measured memory_bytes: 1728
#include <stdio.h>

int ketasu(int num){
	if(num == 0) return 0;
	int i;
	for(i = 0; num != 0; i++){
		num /= 10;
	}
	return i;
}
int main(){
	int a, b;
	while(scanf("%d %d", &a, &b) != EOF){
		printf("%d\n",ketasu(a + b));
	}
	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/pypy
import math
import sys
N, K =map(int, raw_input().split())
AN = map(int, raw_input().split())
FN = map(int, raw_input().split())

AN.sort()
FN.sort(reverse=True)

CN=[]
for i in range(N):
    CN.append(AN[i] * FN[i])

s = 0
e = max(CN) + 1
while True:
    m = (s + e) / 2
    tk = K
    for i in xrange(len(CN)):
        if CN[i] > m:
            tk -= math.ceil(1.0 * (CN[i] - m) / FN[i])
            if tk < 0:
                # fail
                if m == s:
                    print str(e)
                    sys.exit(0)
                s = m
                break
    else:
        if m == s:
            print str(0)
            sys.exit(0)
        e = m


Measured memory_bytes: 72436
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = [input() for _ in range(n)]
s = set(s)
print(len(s))

Measured memory_bytes: 36848
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int x = 0;
	for (int i = 0; i < n; i += 2)
		x ^= a[i] ^ a[i + 1];
	for (int i = 0; i < n; i++)
		cout << (x ^ a[i]) << ' ';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3960
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: u64,
    }
    let mut a = vec![s];
    let mut cnt = 1;
    let mut tmp = s;
    loop {
        tmp = *a.last().unwrap();
        cnt += 1;
        tmp = if tmp % 2 == 0 {tmp/2} else {tmp*3+1};
        if a.contains(&tmp) {
            println!("{}", cnt);
            return
        }
        a.push(tmp);
    }
}


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

using namespace std;

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> idx[100001];
    long long sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        idx[a[i]].push_back(i);
    }
    int q, b, c;
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> b >> c;
        for(auto &p : idx[b]) {
            idx[c].push_back(p);
            sum -= b;
            sum += c;
        }
        idx[b].clear();
        cout << sum << '\n';
    }
    return 0;
}


Measured memory_bytes: 30208
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int>V(5);
  int sum=0;
  int min1=10;
  rep(i,5){
    cin>>V[i];
    V[i]+=9;
//    int a=V[i]/10;
    sum+=V[i]/10*10;
    //cout<<sum<<endl;
    min1=min(min1,V[i]%10);
  }
  cout<<sum+min1-9<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
ll d[n];
ll sum=0;
for(int i=0;i<n;i++){
    cin>>d[i];
}
for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        sum+=d[i]*d[j];
    }
}
cout<<sum<<endl;
}










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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,Q,X[202020],S[202020],T[202020];
vector<pll> bx,ex;
ll D[202020];
ll i, j, k, l, bxi, exi;
set<pll> stps;

int main(){
    scanf("%lld%lld", &N,&Q);
    bx.resize(N);
    ex.resize(N);
    fornum(i,0,N){
        scanf("%lld%lld%lld", &S[i], &T[i], &X[i]);
        bx[i]={S[i]-X[i], i};
        ex[i]={T[i]-X[i], i};
    }
    fornum(i,0,Q){
        scanf("%lld", &D[i]);
    }
    sort(bx.begin(), bx.end());
    sort(ex.begin(), ex.end());
    /*
    fornum(i,0,N){
        printf("%lld:%lld\n", bx[i].first, X[bx[i].second]);
    }*/
    fornum(i,0,Q){
        while(bxi<bx.size()&& bx[bxi].first<=D[i]){
            ll ii=bx[bxi].second;
            stps.insert({X[ii], ii});
            bxi++;
        }
        while(exi<ex.size()&&ex[exi].first<=D[i]){
            ll ii=ex[exi].second;
            stps.erase({X[ii], ii});
            exi++;
        }
        if(stps.empty()){
            printf("-1\n");
            continue;
        }
        auto it = stps.begin();
        printf("%lld\n", it->first,stps.size());
    }
    return 0;
}

Measured memory_bytes: 26240
import java.util.*;
import java.io.*;
class Main {
    static class Line {
        long slope;
        long intercept;
        Line(long slope, long intercept) {
            this.slope = slope;
            this.intercept = intercept;
        }
        long getValue(int x) {
            return this.slope * 1l * x + this.intercept;
        }
        long[] intersection(Line other) {
            long one = other.intercept - this.intercept;
            long two = this.slope - other.slope;
            if(two<0) {
                two = -two;
                one = -one;
            }
            return new long[]{one, two};
        }
    }
    static long square(int a) {
        return a*1l*a;
    }
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long c = sc.nextLong();
        int[] heights = new int[n];
        for(int i = 0; i<n; i++)
            heights[i] = sc.nextInt();
        List<Line> deque = new ArrayList<>();
        int start = 0;
        for(int i = 0; i<n; i++) {
            while(start<=deque.size()-2) {
                Line a = deque.get(start);
                Line b = deque.get(start+1);
                if(a.getValue(heights[i])>=b.getValue(heights[i]))
                    start++;
                else break;
            }
            long best = 0;
            if(i!=0)
                best = deque.get(start).getValue(heights[i]) + square(heights[i]) + c;
            Line line = new Line(-2*1l*heights[i], best+square(heights[i]));
            while(start<=deque.size()-2) {
                Line a = deque.get(deque.size()-1);
                Line b = deque.get(deque.size()-2);
                long[] first = a.intersection(b);
                long[] second = b.intersection(line);
                if(first[0]*second[1]>=first[1]*second[0])
                    deque.remove(deque.size()-1);
                else break;
            }
            deque.add(line);
            if(i==n-1)
                System.out.println(best);
        }
    }
}

Measured memory_bytes: 94300
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        String s = in.next().trim();
        int q = in.nextInt();
        int f = 0,t = 0, tmp;
        char c='.';
        StringBuilder head = new StringBuilder();
        StringBuilder tail = new StringBuilder();
        while(q-->0){
            t = in.nextInt();
            if(t==1){
                f++;
            }else{
                tmp = in.nextInt();
                c = in.nextChar();
                if(f%2==0){// NOT REVERSED
                    if(tmp==1){
                        head.append(c);
                    }else{
                        tail.append(c);
                    }
                }else{// REVERSED
                    if(tmp==1){
                        tail.append(c);
                    }else{
                        head.append(c);
                    }
                }
            }
        }
        StringBuilder ans = new StringBuilder();
        if (f%2==1) {
            tail.reverse();
            ans.append(tail)
               .append(new StringBuilder(s).reverse())
               .append(head);
        } else {
            head.reverse();
            ans.append(head).append(s).append(tail);
        }
        out.println(ans.toString());
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 47216
int main(int argc, const char * argv[]) {
    // insert code here...
    int x,i;
    
    for(i = 1 ; 1 ; i++){
        scanf("%d",&x);
        if(x == 0) break;
        printf("Case %d: %d\n",i,x);
    }
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

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

		int n = sc.nextInt();
		String s = sc.next();
		int k = sc.nextInt();

		char[] c = s.toCharArray();
		for (int i = 0; i < n; i++) {
			if (c[i] != c[k - 1])
				c[i] = '*';
		}

		String ans = String.valueOf(c);
		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main() {
	stack<int> num;
	string str;
	int temp1,temp2;
	while(cin >> str) {
		if(str=="+") {
			temp1=num.top();
			num.pop();
			temp2=num.top();
			num.pop();
			num.push(temp1+temp2);
		} else if(str=="-") {
			temp1=num.top();
			num.pop();
			temp2=num.top();
			num.pop();
			num.push(temp2-temp1);
		} else if(str=="*") {
			temp1=num.top();
			num.pop();
			temp2=num.top();
			num.pop();
			num.push(temp1*temp2);
		} else {
			num.push(stoi(str));
		}
	}
	cout << num.top() << endl;
	return 0;
}

Measured memory_bytes: 3168
#include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int main(){
  int a[100000] , n, k;
  while(cin >> n >> k , n){
    int sum = 0 , ans = -INF;
    for(int i = 0 ; i < n ; i++ ) cin >> a[i];
    for(int i = 0 ; i < k - 1 ; i++ ) sum += a[i];
    for(int i = k - 1 ; i < n ; i++ ){
      sum += a[i];
      ans = max(sum,ans);
      sum -= a[i-k+1];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1552