akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main(){
  ll n, k; cin >> n >> k;
  
  ll ans = pow(n/k, 3);
  if(k%2 == 0) ans += pow(n/(k/2) - n/k, 3);

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef complex<ld> base;

const ld PI = acos(-1.0l);
const int mod = 200003;
const int r = 2;

int pw[mod];
int n;
int vals[mod];
vector <ll> A, B, C;
ll res;

void fft (vector<base> & a, bool invert) {
	int n = (int) a.size();

	for (int i=1, j=0; i<n; ++i) {
		int bit = n >> 1;
		for (; j>=bit; bit>>=1)
			j -= bit;
		j += bit;
		if (i < j)
			swap (a[i], a[j]);
	}

	for (int len=2; len<=n; len<<=1) {
		ld ang = 2*PI/len * (invert ? -1 : 1);
		base wlen (cos(ang), sin(ang));
		for (int i=0; i<n; i+=len) {
			base w (1);
			for (int j=0; j<len/2; ++j) {
				base u = a[i+j],  v = a[i+j+len/2] * w;
				a[i+j] = u + v;
				a[i+j+len/2] = u - v;
				w *= wlen;
			}
		}
	}
	if (invert)
		for (int i=0; i<n; ++i)
			a[i] /= n;
}

void multiply (const vector<ll> & a, const vector<ll> & b, vector<ll> & res) {
	vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
	size_t n = 1;
	while (n < max (a.size(), b.size()))  n <<= 1;
	n <<= 1;
	fa.resize (n),  fb.resize (n);

	fft (fa, false),  fft (fb, false);
	for (size_t i=0; i<n; ++i)
		fa[i] *= fb[i];
	fft (fa, true);

	res.resize (n);
	for (size_t i=0; i<n; ++i)
		res[i] = ll (fa[i].real() + 0.5);
}

int main()
{
    pw[0] = 1;
    for (int i = 1; i < mod; i++)
        pw[i] = ll(r) * pw[i - 1] % mod;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int a; scanf("%d", &a);
        vals[a]++;
        res -= ll(a) * a % mod;
    }
    A.resize(mod - 1);
    B.resize(mod - 1);
    for (int i = 0; i < mod - 1; i++)
        A[i] = B[i] = vals[pw[i]];
    multiply(A, B, C);
    for (int i = 0; i < C.size(); i++)
        res += ll(pw[i % (mod - 1)]) * C[i];
    res = ll(res) / 2;
    cout << res << endl;
    return 0;
}


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

int main(){
  vector<int> seq = {
    1, 1, 1, 2, 1, 2, 1, 5,
    2, 2, 1, 5, 1, 2, 1, 14,
    1, 5, 1, 5, 2, 2, 1, 15,
    2, 2, 5, 4, 1, 4, 1, 51
  };
  
  int K;
  cin >> K;
  cout << seq.at(K-1);
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
    //cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N; cin >> N;
    ves W(N);
    rep(i,N) cin >> W[i];

    //初見の単語か
    rep(i,N){
        for(int j = i + 1; j< N; j++){
            if (W[i] == W[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    //末尾一致か
    rep(i,N - 1) {
        if (W[i][W[i].length() - 1] != W[i + 1][0]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pr;
typedef vector<pr> vpr;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    double n,k,ans=0;
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        ll cnt=0,tmp=i;
        while(tmp*pow(2,cnt)<k) cnt++;
        ans+=(1/n)*pow(0.5,cnt);
    }
    printf("%.20f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<string>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;

void bubbleSort(vector<string> &v) {
    for(size_t i=0; i<v.size(); ++i) {
        for(size_t j=v.size()-1; j>0; --j) {
            if(v[j][1] < v[j-1][1]) {
                swap(v[j], v[j-1]);
            }
        }
    }
}

void selectionSort(vector<string> &v) {
    for(size_t i=0; i<v.size(); ++i) {
        int minj = i;
        for(size_t j=i; j<v.size(); ++j) {
            if(v[j][1] < v[minj][1]) {
                minj = j;
            }
        }
        swap(v[i], v[minj]);
    }
}

void print(vector<string> &v) {
    for(int i=0; i<v.size(); ++i) {
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<string> v1(n);
    vector<string> v2(n);
    rep(i, n) {
        cin >> v1[i];
        v2[i] = v1[i];
    }
    bubbleSort(v1);
    print(v1);
    cout << "Stable" << endl;
    selectionSort(v2);
    print(v2);
    for(int i=0; i<n; ++i) {
        if(v1[i] != v2[i]) {
            cout << "Not stable" << endl;
            return 0;
        }
    }
    cout << "Stable" << endl;

    return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define int long
#define MOD (1000000007)
const int MX = 777777 + 5;
int fac[MX+5],fac_inv[MX+5];

int power(int x,int y,int p){
	int res=1;
	x=x%p;
	while(y){
		if(y&1)res=(res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void init(){
  int n=MX+4;
	fac[0] = 1;
  for(int i=0;i<n;++i)fac[i+1]=fac[i]*(i+1)%MOD;
  fac_inv[n]=power(fac[n],MOD-2,MOD);
  for(int i=n-1;i>=0;--i)fac_inv[i]=fac_inv[i+1]*(i+1)%MOD;
}
int comb(int n,int r){return (fac[n]*fac_inv[r])%MOD*fac_inv[n-r]%MOD;}
int H(int n,int r){
  return comb(n+r-1,r)%MOD;
}
main(){
  int n,k;
  init();
  cin>>n>>k;
  for(int i=1;i<=k;++i){
    cout<<(i-1>n-k?0:(H(i,k-i)*H(i+1,n-k-i+1))%MOD)<<"\n";
  }
}

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

using namespace std;

int main()
{
    int a,b,c,d,e,k;

    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);

    if(a>=0 && a<=123 && b>=0 && b<=123 && c>=0 && c<=123 && d>=0 && d<=123 && e>=0 && e<=123 && k>=0 && k<=123 && e>d && d>c && c>b && b>a){

        if(b-a >k || c-a >k || d-a > k || e-a > k){
            printf(":(\n");
        }

        else if(c-b>k || d-b>k || e-b>k){
            printf(":(\n");
        }

        else if(d-c>k || e-c>k){
            printf(":(\n");
        }

        else if(e-d>k){
            printf(":(\n");
        }

        else{
            printf("Yay!\n");
        }

    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 10000
#define NIL -1

struct Node {int parent,left,right;};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL)return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1 =0;
  int h2 =0;
  if(T[u].left != NIL){
    h1 = setHeight(T[u].left) + 1;
  }
  if(T[u].right != NIL){
    h2 = setHeight(T[u].right) + 1;
  }
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent == NIL)return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL){
    return T[T[u].parent].left;
  }
  if(T[T[u].parent].right !=u && T[T[u].parent].right !=NIL){
    return T[T[u].parent].right;
  }
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if (T[u].left != NIL)deg++;
  if(T[u].right != NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }
  else {
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root = 0;
  scanf("%d",&n);
  int i;
  for (i=0;i<n;i++)T[i].parent = NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL)T[l].parent = v;
    if(r != NIL)T[r].parent = v;
  }

  for(i=0;i<n;i++)if(T[i].parent == NIL)root = i;

  setDepth(root,0);
  setHeight(root);

  for (i=0;i<n;i++)print(i);

  return 0;

}
  



Measured memory_bytes: 2128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int ans = t.length();
    for(int i = 0; i <= s.length() - t.length(); i++) {
      int tt = 0;
      for(int j = i; j < i + t.length(); j++) {
        if(s.charAt(j) != t.charAt(j - i)) tt++;
      }
      ans = Math.min(ans, tt);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    char ch;
    while((ch=getchar())!=EOF)
    {
        if(ch >= 97 && ch <= 122)
        {
            ch=ch-32;
            cout<<ch;
        }
        else if(ch >= 65 && ch <= 90)
        {
            ch=ch+32;
            cout<<ch;
        }
        else
	    cout<<ch;
    }
    return 0;
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int long long
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

signed main() {
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp;
    rep (i, 0, n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    int ans = 0;
    for (auto i : mp) {
        if (i.first < i.second) {
            ans += i.second - i.first;
        } else if (i.first > i.second) {
            ans += i.second;
        }
    }
    cout << ans << "\n";
}


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

int main (){
  int N ,K,l[51];
  cin >> N >> K;
  for (int i=0;i<N;i++){
    cin >> l[i];
  }
  sort(l,l+N,greater<int>());
  int sum =0;
  for(int i=0;i<K;i++){
    sum += l[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def main():
    A, B, C, D, E, F = map(int, input().split())
    weight = 0.1
    sugar = 0

    for p in range(F // (100 * A) + 1):
        for q in range(0, (F - 100 * A * p) // (100 * B) + 1):
            upper = (A * p + B * q) * E
            water = (A * p + B * q) * 100
            if water == 0: continue
            for r in range(0, upper // C + 1):
                if water + C * r > F: continue
                s = (upper - C * r) // D
                while s >= 0 and water + C * r + D * s > F: s -= 1
                if s < 0: continue
                if sugar * (water + C * r + D * s) < (C * r + D * s) * weight:
                    weight = water + C * r + D * s
                    sugar = C * r + D * s
    if sugar == 0:
        print("{} 0".format(100 * A))
    else:
        print("{} {}".format(weight, sugar))

    


if __name__ == "__main__":
    main()


Measured memory_bytes: 67120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int a[105];
int main(){
int n;
cin>>n;
bool flag=true;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]%2==0&&(a[i]%3!=0&&a[i]%5!=0)){
			flag=false;
		}
	}
	if(flag)cout<<"APPROVED";
	else cout<<"DENIED";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;

class cake{
public:
  int w,d;
  cake(int w=0,int d=0):w(w),d(d){}

  int get_area(){ return w*d; }

  pair<cake,cake> cut(int S){
    pair<cake,cake> pc;
    S=S%(2*w+2*d);
    if(S<w){
      pc.f=cake(w-S,d);
      pc.s=cake(S,d);
    }
    else  if(S<w+d){
      pc.f=cake(w,d+w-S);
      pc.s=cake(w,S-w);
    }
    else if(S<2*w+d){
      pc.f=cake(S-(w+d),d);
      pc.s=cake((2*w+d)-S,d);
    }
    else {
      pc.f=cake(w,(2*w+2*d)-S);
      pc.s=cake(w,S-(2*w+d));
    }
    return pc;
  }
  bool operator<(cake c)const{
    return w*d<c.get_area();
  }
};

int main()
{
  int n,w,d,p,s;

  while(1){
    cin>>n>>w>>d;
    if(n+w+d==0)break;
    vector<cake> vc;
    vc.push_back(cake(w,d));
    for(int i=0;i<n;i++){
      cin>>p>>s;
      p--;
      cake c=vc[p];
      vc.erase(vc.begin()+p);
      pair<cake,cake> pc=c.cut(s);
      if(pc.f.get_area()<=pc.s.get_area()){
	vc.push_back(pc.f);
	vc.push_back(pc.s);
      }
      else {
	vc.push_back(pc.s);
	vc.push_back(pc.f);
      }
    }
    sort(vc.begin(),vc.end());
    for(int i=0;i<vc.size();i++){
      cout<<vc[i].get_area();
      if(i!=vc.size()-1)cout<<" ";
    }
    cout<<endl;
  }
  return 0;
}

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

int main() {

  while (1) {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0){
      return 0;
    } else {
      cout << min(x,y) << " " << max(x,y) << endl;
    }
  }

  return 0;

}


Measured memory_bytes: 3068
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input ().split()])

for i in range(m):
     b.append(int(input()))

c = []
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)

Measured memory_bytes: 7012
/*  In the name of ALLAH */

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define ll long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif



int main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    
    ll n,m,s=0;
    cin>>n>>m;
    rep(i,0,m){
        ll e;
        cin>>e;
        s+=e;
    }

    cout<<max(-1ll,n-s);
 
 
    
 
    return 0;
}


Measured memory_bytes: 3652
using System;

    class Program
    {
        static void Main(string[] args)
        {

		// 整数の入力
		float a = float.Parse(Console.ReadLine());
		
		// スペース区切りの整数の入力
		float b = a * 2f * 3.14159f;
		
		//出力
		Console.WriteLine(b);

        }
    }

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i=0; i<n; i++)
    cin >> h.at(i);
  
  int m = h.at(0);
  int count = 1;
  
  for(int i=1; i<n; i++) {
    if(h.at(i) >= m) {
      count++;
      m = h.at(i);
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=2e6+1;
int n,k;
char c[N];
int main(){
	ios::sync_with_stdio(false);
	cin >> k;
	if(k%2==0 || k%5==0){
		return cout << "-1\n",0;
	}
	int cur=7%k;
	int ans=1;
	while(cur!=0){
		cur=cur*10+7;
		cur%=k;
		ans++;
	}
	cout << ans << endl;
}

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

int is_wonder(int cnt[]){
	for(int i = 'a'; i <= 'z'; i++){
		if(cnt[i] % 2 == 1) return 0;
	}
	return 1;
}

int main(){
	string w;
	int cnt[256];

	cin >> w;
	for(int i = 0; i < 256; i++){
		cnt[i] = 0;
	}
	for(int i = 0; i < w.length(); i++){
		cnt[w[i]]++;
	}

	//美しい文字列かどうかの判定
	if(is_wonder(cnt)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

import static java.lang.Integer.parseInt;

/**
 * Fast Division
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int n = parseInt(br.readLine());
		if (n == 0 || n == 2) {
			System.out.println(1);
		} else if (n == 1) {
			System.out.println(2);
		} else {
			System.out.println(0);
		}

	} //end main
}

Measured memory_bytes: 24460
N, T = map(int, input().split())
tlist = list(map(int, input().split()))

num = 0
for i in range(1, N):
    sbn = tlist[i] - tlist[i - 1]
    if sbn < T:
        num += sbn
    else:
        num += T
num += T
print(num)


Measured memory_bytes: 25196
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    int n = b - a;
    int an = (1 + n) * n / 2;
    int x = an - b;
    cout << x << endl;

    return 0;
}


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

const int N = (int) 1e5 + 5;

int n, q;
string s;

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> s;
	n = s.size();
	cin >> q;
	deque <char> left, right;
	bool reverse = false;
	for (int i = 1; i <= q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			reverse = !reverse;
		} else {
			int f; char c;
			cin >> f >> c;
			if (f == 1) { // add to begin
				if (reverse == false) {
					left.push_front(c);
				} else {
					right.push_back(c);
				}
			} else { // add to end 
				if (reverse == false) {
					right.push_back(c);
				} else {
					left.push_front(c);
				}	
			}
		}
	}
	if (reverse == false) {
		while (!left.empty()) {
			cout << left.front();
			left.pop_front();
		}
		cout << s;
		while (!right.empty()) {
			cout << right.front();
			right.pop_front();
		}
	} else {
		while (!right.empty()) {
			cout << right.back();
			right.pop_back();
		}
		for (int i = s.size() - 1; i >= 0; i--) cout << s[i];
		while (!left.empty()) {
			cout << left.back();
			left.pop_back();
		}
	}
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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 (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

int N;
int A[111111];

signed main() {
  cin >> N;
  int minus = 0;
  rep (i, N) {
    cin >> A[i];
    if (A[i] < 0) {
      minus++;
    }
  }

  if (minus % 2 == 0) {
    int ans = 0;
    rep (i, N) {
      ans += abs(A[i]);
    }
    cout << ans << endl;
  } else {
    rep (i, N) {
      A[i] = abs(A[i]);
    }
    sort(A, A+N);
    int ans = -A[0];
    repp (i, 1, N) {
      ans += A[i];
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
a1 = [i+a[i] for i in range(n)]
a2 = [i-a[i] for i in range(n)]
d = defaultdict(int)
ans = 0
for x in a1: d[x] += 1
for x in a2: ans += d[x]
print(ans)


Measured memory_bytes: 65980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, x;
    cin >> n >> x;
    vector<tuple<ll,ll,ll,ll>> vp(n);
    REP(i, n) {
        ll b, l, u;
        cin >> b >> l >> u;
        vp[i] = make_tuple(x*u-b*u+b*l, u, b, l);
    }
    sort(ALL(vp), greater<>());

    vector<ll> b(n), l(n), u(n);
    REP(i, n) tie(ignore, u[i], b[i], l[i]) = vp[i];
    ll sumb = 0;
    REP(i, n) sumb += l[i] * b[i];

    dump(b);
    dump(l);
    dump(u);

    auto check = [&](ll mid) {
        ll num = mid/x, pt = mid%x, sum0 = 0, sum1 = 0;
        if(num >= n) return true;
        REP(i, num) {
            sum0 += u[i]*x;
            sum1 += (u[i]-l[i])*b[i];
        }
        REP(i, n) {
            ll scorea = 0, scoreb = sumb;
            // i番目の分
            if(pt < b[i]) {
                scorea += l[i]*pt; 
            } else {
                scorea += u[i]*pt;
                scoreb += u[i]*b[i] - l[i]*b[i];
            }
            // 大きい方からnum個
            if(i < num) {
                scorea += sum0 - u[i]*x + u[num]*x;
                scoreb += sum1 - (u[i]-l[i])*b[i] + (u[num]-l[num])*b[num];
            } else {
                scorea += sum0;
                scoreb += sum1;
            }
            if(scorea >= scoreb) return true;
        }
        return false;
    };

    // ll ret = check(114);
    // dump(ret);

    ll lb = -1, ub = n*x;
    while(ub-lb>1) {
        ll mid = (lb+ub)/2;
        if(check(mid)) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N, T;
	while(cin >> N >> T){
		vector<int> t(N);
		for(int i=0;i<N;i++) cin >> t[i];
		long long res = T;
		for(int i=0;i+1<N;i++){
			res += min(T, t[i+1]-t[i]);
		}
		cout << res << endl;

	}
}



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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    unordered_set<string> se;
    string last;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (se.find(s) != se.end() || (last.length() != 0 && last.back() != s[0])) {
            cout << "No" << endl;
            return 0;
        }
        se.insert(s);
        last = s;
    }
    cout << "Yes" << endl;

}


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

if S[K-1] == "A" : 
    S[K-1] = "a"
elif S[K-1] == "B" : 
    S[K-1] = "b"
elif S[K-1] == "C" : 
    S[K-1] = "c"
S = "".join(S)
    
print(S)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define ff first
#define ss second

using namespace std;

ll t,n,m,r,l,h,i,j,x[1000001][3],y[1000001],z,g,a,b,c,d,dp[1000001][3],k,q;
vector <ll> v[1000001];
vector <pair <ll,ll> > vv;
queue <pair <ll,ll> > qq;
pair <ll,ll> p[1000001];
map <ll,ll> mp,mpp,mppp,mx,vis;
set <pair<ll,ll>, greater<pair<ll,ll> > > se;
set <ll> :: iterator it;
string s[1000001],sss;
char cc;

int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for(i=0;i<n;i++)
        cin >> x[i][0] >> x[i][1] >> x[i][2];
    memset(dp,-1,sizeof(dp));
    dp[0][0]=x[0][0];
    dp[0][1]=x[0][1];
    dp[0][2]=x[0][2];
    for(i=0;i<n;i++)
    {
        if(i==n-1)
        {
            dp[n][0]=max(max(dp[i][0],dp[i][1]),dp[i][2]);
            break;
        }
        for(j=0;j<3;j++)
        {
            if(j==0)
                continue;
            dp[i+1][j]=max(dp[i+1][j],dp[i][0]+x[i+1][j]);
        }
        for(j=0;j<3;j++)
        {
            if(j==1)
                continue;
            dp[i+1][j]=max(dp[i+1][j],dp[i][1]+x[i+1][j]);
        }
        for(j=0;j<3;j++)
        {
            if(j==2)
                continue;
            dp[i+1][j]=max(dp[i+1][j],dp[i][2]+x[i+1][j]);
        }
    }
    cout << dp[n][0];
    return 0;
}


Measured memory_bytes: 61696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,v,n,i;
    vector<int>s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        s.push_back(a);
    }
    int c=0;
    sort(s.begin(),s.end());
    for(i=0;i<n-1;i++){
        v=abs(s[i]-s[i+1]);
        c=c+v;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
N     = input()
num_s = input()
num   = [int(i) for i in num_s.split(" ")]

match_cnt = 0
for i in range(1,len(num)-1):
    nums = num[i-1:i+2]
    if nums[1] == sorted(nums)[1]:
        match_cnt += 1
print(match_cnt)    

Measured memory_bytes: 3060
N,*L = map(int, open(0).read().split())
ans = 0
inf = [0]*(N-1)
for i,(c,s,f) in enumerate(zip(*[iter(L)]*3)):
  inf[i] = (c,s,f)
for i in range(N-1):
  ans = 0
  for j in range(i,N-1):
    c,s,f = inf[j]
    m = ((ans-1)//f+1)*f
    ans = max(m,s)
    ans += c
  print(ans)
print(0)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,m,l;
    string str,x,y,z;
    cin>>str>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x=="print"){
            cin>>m>>l;
            cout<<str.substr(m,l-m+1)<<endl;
        }
        else if(x=="replace"){
            cin>>m>>l>>y;
            str.replace(m,l-m+1,y);
        }
        else{
            cin>>m>>l;
            z=str.substr(m,l-m+1);
            for(int j=z.size()-1;j>=0;j--){
                str[m]=z[j];
                m++;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3212
#define _USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, A;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N;
	A = 0;
	
	for (ll p = 2; p <= 1000000; p++) {
		ll e = 0;
		while (N % p == 0) {
			N /= p;
			e++;
		}
		ll c;
		for (c = 1; c <= e; c++) e -= c;
		A += c - 1;
	}
	
	if (N > 1) A++;
	
	cout << A;
	
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  ll tmp = n;
  ll keta = n % 10;
  while(tmp / 10) {
    tmp = tmp / 10;
    keta += tmp % 10;
  }

  if (n % keta == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;

LL quickpow(LL a,LL n)
{
	LL res=1;
	while(n)
	{
		if(n&1) res=res*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return res;
}

LL C(LL n,LL m)
{
	LL f=1; LL g=1;
	for(LL i=n,j=1;j<=m;j++,i--) f=f*i%mod;
	for(LL i=1;i<=m;i++) g=g*i%mod;	
	return f*quickpow(g,mod-2)%mod;
} 
int main(void)
{
	LL n,a,b; scanf("%lld%lld%lld",&n,&a,&b);
	LL res=(quickpow(2ll,n)-1-C(n,a)-C(n,b))%mod;
	res=(res%mod+mod)%mod;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
counta=0
countb=0
for i in a:
  if i%4==0:
    counta+=1
  elif i%2==0:
    countb+=1

if len(a)%2 ==0:
    if counta+countb//2 >= N/2:
    	print('Yes')
    else:
        print('No') 
else:
    if counta+countb//2 >= (N-1)/2:
    	print('Yes')
    else:
        print('No')


Measured memory_bytes: 14252
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
// clang-format on
using namespace std;

long long f(long long a) {
  long long res[] = {a, 1, a + 1, 0};
  return res[a % 4];
}

long long getXor(long long a, long long b) { return f(b) ^ f(a - 1); }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  //  std::random_device rd;std::mt19937 ran(rd());
  long long A, B;
  cin >> A >> B;
  if (A > 0 and B > 0)
    cout << getXor(A, B) << endl;
  else if (B > 0) {
    cout << getXor(1, B) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


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

ll a, b;

ll gcd(ll x, ll y){return y == 0 ? x : gcd(y, x % y);}
ll lcm(ll x, ll y){return x / gcd(x, y) * y;}

int main(){
	scanf("%lld %lld", &a, &b);
	printf("%lld\n", lcm(a, b));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  int cnt = 0;

  for (int i=1; i<=n; i++) {
    int j = i;
    int sum = 0;
    while (j>0)
    {
      sum += j % 10;
      j /= 10;
    }
    if (a<=sum && sum<=b) {
      cnt += i;
    }
    
  }  
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int i, x, y, a;
	for(i = 1;;i++){
		scanf("%d %d", &x, &y);
		if(x > y){
			a = x;
			x = y;
			y = a;
		}
		if(x, y == 0){
			break;
		}
		else
		{
			printf("%d %d\n", x, y);
		}
	}
	return 0;
}


Measured memory_bytes: 2052
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e5 + 1;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int a[N];

int main() {
	int n = read();
	for(int i = 1; i <= n; i++) a[i] = read();
	sort(a + 1, a + n + 1), reverse(a + 1, a + n + 1);
	int p;
	for(int i = 1; i <= n; i++) if(i + 1 > a[i + 1]) {p = i; break;}
	int q = p;
	while(q < n && a[q + 1] >= p) q++;
	int g;
	if(p == q) g = (a[p] - p) & 1;
	else if(a[p] == p) g = (q - p) & 1;
	else g = ((a[p] - p) & 1) | ((q - p) & 1);
	if(g) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	if d.get(i, -1) == -1:
		d[i] = 0
	d[i] += 1
s = 0
for i in d:
	s += d[i] * (d[i] - 1) // 2
for i in a:
	print(s - d[i] + 1)


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

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

  int flag = 0;
  int ans1 = 0;
  int ans2 = 0;
  int ans3 = 0;

  for(int i=0;i<=min((y/10000),2000);i++){
    for(int j=0;j<=min(((y-(i*10000))/5000),2000);j++){
      int rest = y - (i*10000) - (j*5000);

      // if(i==2000){                                                                                          
      //   cout << i << j << rest << endl;                                                                     
      // }                                                                                                     

        if((rest >= 0) &&
           ((rest % 1000) == 0) &&
           ((rest / 1000) <= 2000) &&
           ((i + j + (rest / 1000) == n)))
          {
            ans1 = i;
            ans2 = j;
            ans3 = rest / 1000;
            flag = 1;
          }
        if(flag == 1){
          break;
        }
      }
    if(flag == 1){
      break;
    }
  }

  if(flag == 1){
    cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
  }
  else{
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  }
  return 0;
}


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

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

using namespace std;

struct Data{
	int id,pos,len;
	Data(){}
	Data(int I,int P,int L):id(I),pos(P),len(L){}
};

int main(){
	for(int n;scanf("%d",&n),n;){
		list<Data> L;
		while(n--){
			char type; scanf(" %c",&type);
			if(type=='W'){
				int id,len; scanf("%d%d",&id,&len);
				int pos=0;
				list<Data>::iterator it;
				for(it=L.begin();it!=L.end();++it){
					Data &a=*it;
					if(pos<a.pos){
						int d=min(a.pos-pos,len);
						len-=d;
						L.insert(it,Data(id,pos,d));
					}
					if(len==0) break;
					pos=a.pos+a.len;
				}
				if(len>0){
					L.insert(it,Data(id,pos,len));
				}
			}
			else if(type=='D'){
				int id; scanf("%d",&id);
				list<Data>::iterator it;
				for(it=L.begin();it!=L.end();){
					Data &a=*it;
					if(id==a.id) it=L.erase(it);
					else ++it;
				}
			}
			else{ // type=='R'
				int pos; scanf("%d",&pos);
				int ans=-1;
				list<Data>::iterator it;
				for(it=L.begin();it!=L.end();++it){
					Data &a=*it;
					if(a.pos<=pos && pos<a.pos+a.len){
						ans=a.id;
						break;
					}
					if(pos<a.pos) break;
				}
				printf("%d\n",ans);
			}
		}
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 904
#include <iostream>
#include <string>

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

using namespace std;

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

	rep(i,s.length()){
		if(i%2==0 && s[i]=='L') { cout<<"No"<<endl; return 0; }
		if(i%2==1 && s[i]=='R') { cout<<"No"<<endl; return 0; }
	}
	cout<<"Yes"<<endl;

	return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        d: [usize; k],
    };
    let mut x = vec![true; 10];
    for &d_i in d.iter() {
        x[d_i] = false;
    }
    for i in n.. {
        let mut ok = true;
        let mut m = i;
        while m > 0 {
            if !x[m % 10] {
                ok = false;
                break;
            }
            m /= 10;
        }
        if ok {
            println!("{}", i);
            return;
        }
    }
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 1000010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

int n;

int A[N], B[N], C[N];

int P(int val){
    int lo = 1, hi = n, ret = 0;
    if(val <= A[1]) return 0;
    while(lo <= hi){
        int mid = (lo + hi) >> 1;
        if(A[mid] >= val){
            hi = mid - 1;
        } else {
            lo = mid + 1;
            ret = mid;
        }
    }
    return ret;
}

int Q(int val){
    int lo = 1, hi = n, ret = 0;
    if(val >= C[n]) return 0;
    while(lo <= hi){
        int mid = (lo + hi) >> 1;
        if(C[mid] > val){
            ret = n - mid + 1;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    return (ret);
}

int main(){
    fastScan(n);
    for(int i = 1; i <= n; i++){
        fastScan(A[i]);
    }
    for(int i = 1; i <= n; i++){
        fastScan(B[i]);
    }
    for(int i = 1; i <= n; i++){
        fastScan(C[i]);
    }
    sort(A + 1, A + n + 1);
    sort(B + 1, B + n + 1);
    sort(C + 1, C + n + 1);
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        //int x = upper_bound(A + 1, A + n + 1, B[i]) - A - 1;
        //int y = upper_bound(C + 1, C + n + 1, B[i]) - C;
        int x = P(B[i]), y = Q(B[i]);
        ans = ans + 1ll * x * y;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define INF (1e9+5)
using namespace std;
typedef long long ll;
    
ll mod = 998244353;
    
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i=0; i<n; i++) {
    int x;
    scanf("%d", &x);
    if ((i==0 && (x!=0)) || ((i!=0) && (x==0))) {
      printf("0\n");
      return 0;
    }
    a[x]++;
  }

  if (a[0] != 1) {
    printf("0\n");
    return 0;
  } 
      
  ll ans=1;
  for (int i=1; i<a.size(); i++) {
    ll pls = 1;
    for (int j=0; j<a[i]; j++) {
      pls = (pls * a[i-1]) % mod;
    }
    ans = (ans * pls) % mod;
  }

  printf("%lld\n", ans);
}


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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
#define HYPP(x) hypot(x.first,x.second)

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;
constexpr int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	vector<lli> v(N),vs(N+1);

	for (int i = 0; i < N; i++) {
		cin >> v[i];
		vs[i] = v[i];
	}

	for (int i = 0; i < N; i++) {
		vs[i + 1] += vs[i];
	}

	lli ans = LIMIT;
	for (int i = 0; i < N-1; i++) {
		lli a = abs(vs[i]-(vs[N]-vs[i]));
		if (a > vs[i] - i - 1 && a > vs[N] - vs[i] - (N - i - 1)) {
			continue;
		}
		
		ans = min(ans, a);
	}

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


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int a[25],b[25],c[25];
int ans;
int main(void){
    int n; cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        ans+=b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]+1){
            ans+=c[a[i-1]-1];
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, t{};
  cin >> N;
  vector<pair<int, int>> P(N);
  for (auto &[a, b] : P) cin >> a >> b;
  sort(begin(P), end(P), [](auto p, auto q) { return p.second < q.second; });
  bool ans{1};
  for (auto [a, b] : P) {
    t += a;
    if (t > b) ans = 0;
  }
  cout << (ans ? "Yes" : "No") << endl;
}


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

int main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	bool flag=false;
	for(int i=0;i<n-2;i++)
	{

		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])
		{
			flag=true;
			break;
		}
	}
	if(flag==true)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

Measured memory_bytes: 3624
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<cstdlib>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds; 
//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef long double ld;
typedef vector < pair < ll, ll > > vpll;
#define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define forn(i,n) for (ll i = 0; i < n; i++)
#define fo(i,n) for (ll i = 1; i <= n; i++)
#define fore(i,l,r) for (ll i = l; i <= r; i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
#define back(c,it) for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define fi first
#define se second
#define MOD 998244353
#define MAX 1000000007
ll power(ll a,ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1;}return res;}
ll fact[500009];
ll fermat_inv(ll y){return power(y,MOD-2);}
ll nCrMod(ll n, ll r){ ll p=fact[n];ll q=(fact[r]*fact[n-r])%MOD;return (p*fermat_inv(q))%MOD;} 
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
const ld PI = acos(-1.0);
vl g[20];

  int main(){
      #ifndef ONLINE_JUDGE
      freopen("input.cpp","r",stdin);
      freopen("output.cpp","w",stdout);
      #endif
      Boost();
      int t;
      //cin>>t;
      t=1;
      int t1=t;
      while(t--)
      {
        ll x;
        cin>>x;
        if(x<600)
          cout<<8<<endl;
        else if(x<800)
          cout<<7<<endl;
        else if(x<1000)
          cout<<6<<endl;
        else if(x<1200)
          cout<<5<<endl;
        else if(x<1400)
          cout<<4<<endl;
        else if(x<1600)
          cout<<3<<endl;
        else if(x<1800)
          cout<<2<<endl;
        else
          cout<<1<<endl;
      }
      return 0;
      }
  

Measured memory_bytes: 3656
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int X[100000];
int AC, WA;

int main()
{
	int N, M, p;
	string S;
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		cin >> p >> S;

		if (S == "AC")
		{
			if (X[p] != -1)
			{
				WA += X[p];
				AC++;
				X[p] = -1;
			}
		}
		else
		{
			if (X[p] != -1) 
			{
				X[p]++;
			}
		}
	}
	cout << AC << " " << WA;
		 
	return 0;
}

Measured memory_bytes: 640
def main():
    from collections import Counter
    
    N = int(input())
    S = [input() for _ in range(N)]
    
    c = Counter(S)
    _max = max(c.values())
    
    ans = []
    for k, v in c.items():
        if v == _max:
           ans += [k]
    
    for a in sorted(ans):
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 35568
N = input().split()
T = input().split()
H = input().split()
maxtemp=9999999
ans = 0
for c,i in enumerate(H):
	P = int(T[0]) - int(i) * 0.006 - int(T[1])
	#print(P,c)
	#print("maxtemp",maxtemp)
	if min(maxtemp,abs(P)) == abs(P):
		maxtemp = abs(P)
		#print("chane")
		ans = c
		#print(ans)
print(str(ans+1))

Measured memory_bytes: 3064