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

using namespace std;

typedef long long ll;

const ll MOD = 1000000000 + 7;
// const ll N_MAX = 500000 + 3;

ll mul(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  ll ans = (a * b) % MOD;
  ans += MOD;
  ans %= MOD;
  return ans;
}

/*
// Iterative Function to calculate (x^y)%MOD in O(log y)
ll power(ll x, int y) {
  ll res = 1;
  x %= MOD;
  while(y > 0) {
    if(y % 2 == 1) {
      res = mul(res, x);
    }
    y /= 2;
    x = mul(x, x);
  }
  return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n) {
  return power(n, MOD - 2);
}

ll fact[N_MAX];

// Returns nCr % p using Fermat's little theorem.
ll comb(ll a, ll b) {
  if(b == 0) return 1;
  return mul(mul(fact[a], modInverse(fact[b])), modInverse(fact[a - b]));
}
*/

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

  /*
  // abc 172 E
  ll n, m;
  cin >> n >> m;

  if(m < n) {
    cout << "0\n";
    return 0;
  }

  fact[0] = 1;
  fact[1] = 1;
  for(int i = 2; i < N_MAX; ++i) fact[i] = mul(fact[i - 1], i);

  cout << "from " << m << " pick " << n << endl;
  ll total = comb(m, n);
  cout << total << endl;
  */
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }

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

  // if k is 1 -> pick largest element from all
  // if k is 2 -> pick 2 largest element from all and mul
  // -> pick 2 smallest element from all and mul
  ll ans = 1ll;

  if(k % 2 == 1) {
    if(a[n - 1] < 0) {
      for(int i = 0; i < k; ++i) {
        ans = mul(ans, a[n - 1 - i]); // from the back
      }
    }
    else if(a[n - 1] > 0) {
      ans = mul(ans, a[n - 1]);
      --k;
      int l = 0, r = n - 2;
      while(l + 1 <= r && k > 0) {
        ll L = a[l] * a[l + 1];
        ll R = a[r] * a[r - 1];
        if(L > R) {
          ans = mul(ans, L);
          l += 2;
        } else {
          ans = mul(ans, R);
          r -= 2;
        }
        k -= 2;
      }
    }
    else {
      ans = 0;
    }
  }
  else {
    int l = 0, r = n - 1;
    while(l + 1 <= r && k > 0) {
      ll L = a[l] * a[l + 1];
      ll R = a[r] * a[r - 1];
      if(L > R) {
        ans = mul(ans, L);
        l += 2;
      } else {
        ans = mul(ans, R);
        r -= 2;
      }
      k -= 2;
    }
  }

  cout << ans << '\n';
  return 0;
}


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

int main() {
	string str1, str2;
	cin >> str1 >> str2;
	
	int n = str1.length();
	int m = str2.length();
	
	vector<vector<int>>dp(n+1, vector<int>(m+1, 0));
	string str = "";
	
	for(int i=1; i<=n;i++){
	    for(int j=1; j<=m;j++){
	        if(str1[i-1] == str2[j-1]){
	            dp[i][j] = dp[i-1][j-1]+1;
	           // str += str1[i-1];
	        }
	        else{
	            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
	        }
	    }
	}
	
	int len = dp[n][m];
	
	int i = n;
	int j = m;
	
	while(len>0){
	    if(i>0 and dp[i-1][j] == dp[i][j])
	        i--;
	    else if (j>0 and dp[i][j-1] == dp[i][j])
	        j--;
	    else {
	        str += str2[j-1];
	        i--;
	        j--;
	        len--;
	    }
	}
	
	reverse(str.begin(), str.end());
	
	cout << str <<endl;
	
	return 0;
}


Measured memory_bytes: 35584
iN,iM = map(int,input().split())

if 2 < iN and 2 < iM:
    print((iN-2)*(iM-2))
elif iN == 2 or iM == 2:
    print(0)
else:
    if iN > 1:
        print(iN-2)
    elif iM > 1:
        print(iM-2)
    else:
        print(1)


Measured memory_bytes: 2940
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var N = intShift();
  
  var A = intShift();
  var B = intShift();
  
  var sum = 0;
  for(var i = 1 ; i <= N ; i++){
  	var a = i.toString().split("").map(a=>~~a).reduce((a,b)=>a+b)
    if(A <= a && a <= B)sum+=i;
  }
  return sum;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
20 2 5
`);

Measured memory_bytes: 10856
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

const int N=100005;
const int M=12;

struct node{
	int c,id;
	node(){}
	node(int c,int id):c(c),id(id){}
	friend bool operator<(node a,node b){
		return a.id<b.id;
	}
}dp[N][M];
struct E{
	int to,next;
}mem[N<<1];
int n,num,x,y,d,c,T,m;
int head[N];

void add(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num;
}

int main(){
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	scanf("%d",&T);
	for (i=1;i<=T;i++){
		scanf("%d%d%d",&x,&d,&c);
		dp[x][d]=max(dp[x][d],node(c,i));
	}
	for (d=10;d;d--){
		for (x=1;x<=n;x++){
			dp[x][d-1]=max(dp[x][d-1],dp[x][d]);
			for (j=head[x];j;j=mem[j].next){
				y=mem[j].to;
				dp[y][d-1]=max(dp[y][d-1],dp[x][d]);
			}
		}
	}
	for (i=1;i<=n;i++) printf("%d\n",dp[i][0].c);
	return 0;
}

Measured memory_bytes: 12032
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

void solve(int cur_x, int cur_y, vector<vector<bool>> &visited,
        const int H, const int W, const vector<vector<int>> &field) {
    visited[cur_y][cur_x] = true;

    vector<pair<int, int>> diff_xy = {
        {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}
    };
    for (int i = 0; i < (int) diff_xy.size(); i++) {
        int next_x = cur_x + diff_xy[i].first;
        int next_y = cur_y + diff_xy[i].second;
        if (next_x < 0 || next_x >= W || next_y < 0 || next_y >= H) continue;
        if (visited[next_y][next_x]) continue;
        if (field[next_y][next_x] == 0) continue;
        solve(next_x, next_y, visited, H, W, field);
    }
}

int main(void) {
    while (1) {
        int w, h;
        cin >> w >> h;

        if (w == 0 && h == 0) break;

        vector<vector<int>> field(h, vector<int>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> field[i][j];
            }
        }

        vector<vector<bool>> visited(h, vector<bool>(w, false));
        int count = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (visited[i][j]) continue;
                if (field[i][j] == 0) continue;
                solve(j, i, visited, h, w, field);
                count++;
            }
        }

        cout << count << endl;
    }
    return 0;
}



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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 103;

vector<int> p[_];int np=0;
vector<pair<int,int>> ans;

int main()
{
	int n=ty();
	if(n&1)
	{
		np=n/2+1;
		for(int i=1;i<np;i++)p[i].emplace_back(i),p[i].emplace_back(n-i);
		p[np].emplace_back(n);
	}
	else
	{
		np=n/2;
		for(int i=1;i<=np;i++)p[i].emplace_back(i),p[i].emplace_back(n-i+1);
	}

	for(int i=1;i<=np;i++)
		for(int j=i+1;j<=np;j++)
			for(auto a:p[i])
				for(auto b:p[j])
					ans.emplace_back(a,b);
	printf("%lu\n",ans.size());
	for(auto i:ans)printf("%d %d\n",i.first,i.second);
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

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

    vector<P> p;
    rep(i, m){
        int a,b;
        cin >> a >> b;
        p.emplace_back(P(--b, --a));
    }

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

    int idx = p[0].first-1;
    int cnt = 1;

    rep(i, m){
        int a = p[i].second;
        if(a <= idx) continue;
        
        idx = p[i].first -1;
        cnt++;
    }

    cout << cnt << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1400
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    string s;cin >> s;
    vi w(n+1);
    w[0]=0;
    int wcount=0,rcount=0;
    rep(i, n) {
        if(s[i]=='W') {
            w[i+1]++;
            wcount++;
        }
        else rcount++;
        w[i+1]+=w[i];
    }
    cout << min({rcount,wcount,w[rcount]}) << endl;
    return 0;
}

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

ll solve() {
    ll K;
    cin >> K;

    auto gcd = [](ll a, ll b) {
        while ( b != 0 ) {
            ll t = b;
            b = a % b;
            a = t;
        }
        return a;
    };
    ll ans = 0;
    for ( int a = 1; a <= K; a++ ) {
        for ( int b = 1; b <= K; b++ ) {
            for ( int c = 1; c <= K; c++ ) {
                ll x = gcd(gcd(a,b),c);
                ans += x;
            }
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3624
N = int(input())
h = list(map(int, input().split()))

dp = [1e9 for _ in range(N+1)]
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]))

print(dp[N-1])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int n;

void dfs(string s,char mx){
    if(s.length()==n)cout << s << endl;
    else{
        rep(i,mx){
            char c='a'+i;
            if(i==mx-1)dfs(s+c,mx+1);
          	else dfs(s+c,mx);
        }
    }
}

int main() {
    cin >> n;
    dfs("",1);
}

/*



 */



Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using P = std::pair<unsigned, int>;

int main(int argc, char** argv) {
  unsigned N;
  std::cin >> N;
  std::vector<P> A(N);
  for (auto i = 0;i < N;++i) {
    std::cin >> A[i].first;
    A[i].second = i+1;
  }
  std::sort(A.begin(), A.end());
  bool is_top = true;
  for (auto& e : A) {
    if (is_top == false) std::cout << ' ';
    std::cout << e.second;
    is_top = false;
  }
  std::cout << '\n';
}


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

int main() {
  int N;
  bool a = false;
  cin >> N;

  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    if(S=="Y")a=true;
  }
  if(a)cout << "Four" << endl;
  else cout << "Three" << endl;
}


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

using namespace std;

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

int
main()
{
  unsigned int b, d;
  cin >> b >> d;

  if (b < d) {
    cout << "1" << endl;
    return 0;
  }
  unsigned int man = d*2+1;
  unsigned int res = b / man;

  if (b%man != 0) {
    res++;
  }

  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val hn = readLine()!!.split(" ").map(String::toInt)

    val dp = IntArray(N) { Integer.MAX_VALUE }
    dp[0] = 0
    dp[1] = Math.abs(hn[0] - hn[1])
    for (i in 2 until N) {
        dp[i] = Math.min(Math.abs(hn[i] - hn[i - 1]) + dp[i - 1], Math.abs(hn[i] - hn[i - 2]) + dp[i - 2])
    }
//    println(dp.joinToString(","))
    println(dp.last())

}


Measured memory_bytes: 48900
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n;in(n);
  vector<ll> S(n), T(n);
  loop(i,0,n) in(S[i]),in(T[i]);
  ll s = 1, t = 1;
  loop(i,0,n) {
    ll x = max(s/S[i] + (s%S[i]!=0), t/T[i] + (t%T[i]!=0));
    s = x * S[i], t = x * T[i];
  }
  print(s+t);
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
 
long long A, B, C, X, Y;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> A >> B >> C >> X >> Y;
  long long a = A*X + B*Y;
  long long b = C*2*min(X, Y);
  if(X > Y){
     X -= Y;
     b += min(X*A, X*C*2);
  }
  else{
    Y -= X;
    b += min(Y*B, Y*C*2);
  }
  cout << min(a, b) << "\n";
  return 0;
}



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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


LL po(LL i,ll p){
    if(p==0)return 1;
    else{
        if(p==1)return i;
        if(p%2==0)return po(i*i,p/2);
        return (i*po(i,p-1));
    }
}

int main(){fastio
    LL n;cin>>n;
    ll len=1;
    LL sum=0;
    while(sum<n){
        LL k=po(26,len);
        if(sum+k<n){
            sum+=k;
            len++;
        }else{
            break;
        }
    }
    string ans;
    n-=sum;
    n--;
    rep(i,0,len-1){
        ll t=(ll)n%26;
        ans+=(char)('a'+t);
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    
    
    return 0;
}






Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main() {
int A,B,X;
cin >> A >> B >> X;
int ans = 2000000000;
ans = min(ans,((X-1)/1000+1)*A);
ans = min(ans,ans-((X-1)/500+1)%2*A+B);
ans = min(ans,((X-1)/500+1)*B);
cout << ans << endl;
}


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

int main() {
  int N, i;
  char c;
  cin >> N;
  for(i = 0; i < N; i++)
  {
    cin >> c;
    if(c == 'Y')
    {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}


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

#pragma region Macros
using ll = long long;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define int ll
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#pragma endregion

template<typename T>
class BITree {
    public:
        BITree(int n) : m_N(n + 1) { m_Tree.assign(m_N, 0); }
        // [1, i] の合計値を返す (log m_N)
        // 閉区間であることに注意
        T Sum(int i) {
            assert(i >= 0 && i < m_N);
            T s = 0;
            while(i > 0) { s += m_Tree[i]; i -= i & -i; }
            return s;
        }
        // [i, j] の合計値を返す (log m_N)
        // i < j
        // 閉区間であることに注意
        T Sum(int i, int j) {
            assert(i <= j);
            return Sum(j) - Sum(i-1);
        }
        // i 番目の要素(1-indexed)に x を足して更新 O(log m_N)
        void Add(int i, T x){ while(i < m_N) { m_Tree[i] += x; i += i & -i; } }
    private:
        int m_N;            // 要素数
        vector<T> m_Tree;   // BIT 本体
};

const int MAX_N = 100010;

int N, Q;
string S;

signed main() {
    IOS;

    cin >> N >> S >> Q;

    // 各文字の場所を保存
    vector< BITree<int> > alph(30, BITree<int>(N));
    REP(i, N) {
        int ind = S[i] - 'a';
        alph[ind].Add(i + 1, 1);
    }

    // クエリの処理
    REP(q, Q) {
        int num;
        cin >> num;
        if(num == 1) {
            int i;
            char c;
            cin >> i >> c;
            int ind = S[i-1] - 'a';
            alph[ind].Add(i, -1);
            ind = c - 'a';
            alph[ind].Add(i, 1);
            S[i-1] = c;
        }
        else {
            int l, r;
            cin >> l >> r;
            int ans = 0;
            REP(i, alph.size()) {
                if(alph[i].Sum(l, r) > 0) { ans++; }
            }
            print(ans);
        }
    }



    return 0;
}


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

template<class T>
struct segment_tree {
    int n;
    vector<T> dat;
    segment_tree(int n_) {init(n_);}

    void init(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        dat.resize(2*n-1);
        rep(i,2*n-1) dat[i] = 0;
    }

    //kをaに変更
    void update(int k, T a) {
        k += n-1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k*2+1],dat[k*2+2]);
        }
    }

    //[a,b)のquery,kは節点番号
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        else {
            T vl = query(a,b,k*2+1,l,(l+r)/2);
            T vr = query(a,b,2*k+2,(l+r)/2,r);
            return max(vl,vr);
        }
    }

    T get(int a) {
        a += n-1;
        return dat[a];
    }

    void debug(int a, int b) {
        a += n-1; b += n-1;
        for (int i = a; i <= b; i++) {
            cout << dat[i] << " ";
        }
        cout << endl;
    }
};

int main() {
    int n; cin >> n;
    vint h(n), a(n);
    rep(i,n) cin >> h[i];
    rep(i,n) cin >> a[i];
    segment_tree<ll> seg(n+1);
    rep(i,n) {
        ll value = seg.query(0,h[i]);
        if (seg.get(h[i]) < value+a[i]) seg.update(h[i],value+a[i]);
    }
    cout << seg.query(0,n+1) << endl;
}

Measured memory_bytes: 5888
n,h,w=map(int,input().split())

cnt=0
a=[]
b=[]

for i in range(n):
  c,d=map(int,input().split())
  a.append(c)
  b.append(d)

for i in range(n):
  e=int(a[i]/h)
  f=int(b[i]/w)
  cnt=cnt+min(e,f)
print(cnt)

Measured memory_bytes: 3064
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_T _DEF(T,in,){return in<T>(gcu());}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	int D {in()}, L {in()};
	outl(D / L + D % L);
}


Measured memory_bytes: 2544
#include <iostream>

using ll = long long;
constexpr ll MOD = (1e9) + 7;

class Parser {
  private:
    std::string s;
    std::string::const_iterator it;
    
  public:
    Parser (std::string s) {
        this->s = s;
        it = this->s.begin();
    }

    ll number()
    {
        ll res = 0;
        while (isdigit(*it)) {
            res *= 10;
            res += *it - '0';
            ++it;
        }
        return res;
    }
    
    ll term()
    {
        ll res = 0;
        if (isdigit(*it)) {
            res = number();
        } else if (*it == 'S') {
            it += 2; // S <            
            res = expr() % MOD;            
            res = (res * res) % MOD;
            ++it; // >
        }
        return res;
    }

    bool is_term(char ch)
    {
        return (isdigit(ch) || ch == 'S');
    }

    ll mod_pow(ll x, ll n, ll mod)
    {
        if (n == 0) {
            return 1;
        }
        ll res = mod_pow(x * x % mod, n / 2, mod);
        if (n & 1) {
            res = res * x % mod;
        }
        return res;
    }

    void shift(ll &x, ll y)
    {
        for (ll i = 0; i < y; i++) {
            if (x == 0) {
                return;
            }
            x >>= 1;
        }
    }
    
    ll expr()
    {
        ll res = term();
        while (*it == '>' && *(it + 1) == '>' && is_term(*(it + 2))) {
            it += 2;
            shift(res, term());            
            res %= MOD;
        }
        return res;
    }
};

std::string remove_spaces(const std::string &s)
{
    std::string res;
    for (char c : s) {
        if (c != ' ') {
            res += c;
        }
    }
    return res;
}

int main()
{
    std::string s;
    while (1) {
        std::getline(std::cin, s);
        if (s == "#") {
            break;
        }
        s = remove_spaces(s);
        
        Parser p{s};
        std::cout << p.expr() << std::endl;
    }
    return 0;
}

Measured memory_bytes: 5856
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(read())


def divisor(N):
    x = np.arange(1, 10 ** 6 + 1, dtype=np.int64)
    div = set(x[N % x == 0])
    return div | set(N // x for x in div)


cand = divisor(N) | divisor(N - 1)


def test(N, K):
    if K == 1:
        return False
    while N % K == 0:
        N //= K
    return N % K == 1


answer = sum(test(N, d) for d in cand)
print(answer)


Measured memory_bytes: 38324
#include<bits/stdc++.h>
using namespace std;
int main(){
 int a,b,c,d;
 cin>>a>>b>>c>>d;
 int n1=ceil((float)a/(float)d);
 int n2=ceil((float)c/(float)b);
 if(n1>=n2)
    cout<<"Yes\n";
 else
    cout<<"No\n";
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
struct ${$(){ios_base::sync_with_stdio(0);cin.tie(0);}}$;

const int N = 200;

long long l[N];

int main() {
   l[0] = 2;
   l[1] = 1;

   for(int i = 2; i <= 86; i++) {
      l[i] = l[i - 1] + l[i - 2];
   }   

   cerr << l[86] << endl;
   int n;
   cin >> n;
   cout << l[n] << endl;
   return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,x_home,y_home;
  cin >> n >> m >> x_home >> y_home;
  vector<int> x(n);
  vector<int> y(m);
  for(int i=0;i<n;i++){
    cin >> x.at(i);
  }
  for(int i=0;i<m;i++){
    cin >> y.at(i);
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if( x_home < y.at(0) && y_home > x.at(n-1) && ( x.at(n-1) < y.at(0) ) ){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int t, n, a[maxn], b[maxn];
ll ans;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%d", &a[i]);
		ans += b[a[i]];
		++b[a[i]];
	}
	for(int i = 1; i <= n; ++i)
		printf("%lld\n", ans - (b[a[i]] - 1));
	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    int ans=0;

    scanf("%d",&n);
    // printf("%d\n",n);

    ans=n%10;
    // printf("%d\n",ans);

    if (ans==2 || ans==4 || ans==5 || ans==7 || ans==9)
        printf("hon");
    else if (ans==0 || ans==1 || ans==6 || ans==8)
        printf("pon");
    else if (ans==3)
        printf("bon");

    return 0;
    

}

Measured memory_bytes: 1732
import sys

sys.setrecursionlimit(10 ** 7)


def rec(ar, ac, br, bc, remains) -> None:
    # print(ar, ac, br, bc, remains)
    global curr
    if remains == 1:
        for r in range(ar, br):
            for c in range(ac, bc):
                ret[r][c] = curr
        curr += 1
        return

    cakes = 0
    cut = -1
    for r in range(ar, br):
        t = tbl[r + 1][bc] - tbl[ar][bc] - tbl[r + 1][ac] + tbl[ar][ac]
        if cakes < t:
            if cakes == 0:
                cakes = t
            else:
                cut = r
                break

    if cut >= 0:
        rec(ar, ac, cut, bc, cakes)
        rec(cut, ac, br, bc, remains - cakes)
        return

    cakes = 0
    cut = -1
    for c in range(ac, bc):
        t = tbl[br][c + 1] - tbl[br][ac] - tbl[ar][c + 1] + tbl[ar][ac]
        if cakes < t:
            if cakes == 0:
                cakes = t
            else:
                cut = c
                break

    if cut >= 0:
        rec(ar, ac, br, cut, cakes)
        rec(ar, cut, br, bc, remains - cakes)
        return


def build_table(h, w, s):
    """1-indexed, ケーキ個数の二次元累積和"""
    ret = [[0] * (w + 1) for _ in range(h + 1)]
    for r in range(h):
        for c in range(w):
            ret[r + 1][c + 1] = ret[r][c + 1] + ret[r + 1][c] - ret[r][c] + (1 if s[r][c] == '#' else 0)
    return ret


if __name__ == '__main__':
    h, w, k = map(int, input().split())
    s = tuple(input() for _ in range(h))
    tbl = build_table(h, w, s)  # 1-indexed, ケーキ個数の二次元累積和

    ret = [[-1] * w for _ in range(h)]
    curr = 1
    rec(0, 0, h, w, k)
    for row in ret:
        print(*row)


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

vector<int> d(10);

bool check(int x){
  string xs = to_string(x);
  int l = xs.size();
  for (int i = 0; i < l; i++)
  {
    int xi = xs[i] - '0';
    if(d[xi]) return false;
  }

  return true;
}

int main(){
  int n,k;
  cin >> n >> k;
  for (int i = 0; i < k; i++)
  {
    int m;
    cin >> m;
    d[m] = 1;
  }

  for (int i = n; i < 1000000; i++)
  {
    if(check(i)){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid (l+r)/2
const int mod=1e9+7,inf=0x3f3f3f3f,maxn=1e5+5;
int n,m,Q,K;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*f;
}
int a[5];


signed main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    for(int i=1;i<=3;++i)a[i]=read();
    sort(a+1,a+1+3);
    if((a[1]==a[2]&&a[2]!=a[3])||(a[2]==a[3]&&a[1]!=a[2])||(a[1]==a[3]&&a[2]!=a[3]))puts("Yes");
    else puts("No");



    return 0;
}


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

  int a,result=0,k,b;
  long long n,y,i;

  scanf("%d",&a);

  for(k = 0; k < a; k++){

    b=0;
    scanf("%lld",&n);

    for(i = 1; i < 65536; i++){

      if(n-i > 0 && (n-i)%(2*i+1) == 0){

	b++;
	break;

      }

    }

    if(b == 0) result++;

  }

  printf("%d\n",result);

  return 0;

}

Measured memory_bytes: 2684
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	int A[4];
	for (int i = 3; i >= 0; i--) {
		A[i] = N % 10;
		N /= 10;
	}
	if (A[0] + A[1] + A[2] + A[3] == 7) cout << A[0] << "+" << A[1] << "+" << A[2] << "+" << A[3] << "=7" << endl;
	else if (A[0] + A[1] + A[2] - A[3] == 7) cout << A[0] << "+" << A[1] << "+" << A[2] << "-" << A[3] << "=7" << endl;
	else if (A[0] + A[1] - A[2] + A[3] == 7) cout << A[0] << "+" << A[1] << "-" << A[2] << "+" << A[3] << "=7" << endl;
	else if (A[0] + A[1] - A[2] - A[3] == 7) cout << A[0] << "+" << A[1] << "-" << A[2] << "-" << A[3] << "=7" << endl;
	else if (A[0] - A[1] + A[2] + A[3] == 7) cout << A[0] << "-" << A[1] << "+" << A[2] << "+" << A[3] << "=7" << endl;
	else if (A[0] - A[1] + A[2] - A[3] == 7) cout << A[0] << "-" << A[1] << "+" << A[2] << "-" << A[3] << "=7" << endl;
	else if (A[0] - A[1] - A[2] + A[3] == 7) cout << A[0] << "-" << A[1] << "-" << A[2] << "+" << A[3] << "=7" << endl;
	else if (A[0] - A[1] - A[2] - A[3] == 7) cout << A[0] << "-" << A[1] << "-" << A[2] << "-" << A[3] << "=7" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class343
    {
        static void Main()
        {
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = r[0], M = r[1];
            var L = new Dictionary<int, List<int>>();
            var PY = new int[M][];
            for(int i = 0; i < M; i++)
            {
                PY[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (L.ContainsKey(PY[i][0]))
                {
                    L[PY[i][0]].Add(PY[i][1]);
                }
                else
                {
                    L[PY[i][0]] = new List<int>();
                    L[PY[i][0]].Add(PY[i][1]);
                }
            }
            foreach(var l in L.Keys)
            {
                L[l].Sort();
            }
            for(int i = 0;i< M; i++)
            {
                string a = PY[i][0].ToString("000000");
                string b = (L[PY[i][0]].BinarySearch(PY[i][1]) + 1).ToString("000000");
                Console.WriteLine(a + b);
            }
        }
    }
}


Measured memory_bytes: 36380
fun main(args:Array<String>) { 
  val bs = readLine()!!.toList().map(Char::toString).map(String::toInt)

  val fl = listOf( {it:Int -> 1*it }, { it:Int -> -1*it } )

  val af = { (0..1) }  

  val results = mutableListOf<Pair<Int, List<String>>>()
  (0..0).map { a1 -> af().map { a2 -> af().map { a3 -> af().map { a4 -> 
    val num = fl[a1](bs[0]!!) + fl[a2](bs[1]!!) + fl[a3](bs[2]!!) + fl[a4](bs[3]!!)
    val p = listOf( a1, a2, a3, a4 ).map { 
      if( it == 0 ) "+" 
      else "-"
    }.zip( bs ).map { 
      val (op, nu) = it
      listOf( "${op}", "${nu}" )
    }.flatten()
    
    val p2 = p.slice(1..p.size-1)
    results.add( Pair(num, p2) )
  } } } } 
  //println(results)
  results.filter { 
    val (k,v) = it
    k == 7
  }.first().let { 
    val (k, v) = it 
    println( v.joinToString("") + "=7" )
  }
}

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

#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define pii pair<int,int>
#define vi vector<int>
#define vit vector<int>::iterator it
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v.size())
#define si set<int>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf=0x7f7f7f7f;
const int N=1e5+10;

int main() {
    int n,m;
    cin>>n>>m;
    int ans=n*(n-1)/2+m*(m-1)/2;
    cout<<ans<<endl;
    return 0;
}

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

int A[1000];//商品Aの総数

int main() {
	int N, M;//N種類の商品、人気商品M

	cin >> N >> M;

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

	//得票数を計算
	int tokuhyou = 0;
	for (int i = 0; i < N; i++) {
		tokuhyou = tokuhyou + A[i];
	}

	//選べるか判定
	float select_tokuhyou = tokuhyou * (1.0 / (4.0 * (float)M));

	//cout << select_tokuhyou << endl;

	int selcount = 0;
	for (int i = 0; i < N; i++) {
		if (select_tokuhyou <= A[i]) {
			selcount++;
		}
	}

	//cout<< selcount << endl;

	if (selcount >= M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 9999999999;
const long long MOD = 1e9 + 7;
const double pi = 3.1415926535897932384626;
const int SIZE = 1 << 17;

int main() {
	int a, b;
	cin >> a >> b;
	if (b%a == 0) { cout << a + b; }
	else { cout << b - a; }
	cout << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

vector<ll> get_prime(ll n){
    bool is_prime[n+1];
    is_prime[0]=false;
    is_prime[1]=false;
    for(ll i=2; i<=n; i++) is_prime[i]=true;
    for(ll i=2; i*i<=n; i++){
		if(!is_prime[i]) continue;
		for(ll j=i*i; j<=n; j+=i){
			is_prime[j]=false;
        }
    }
    vector<ll> p;
    for(ll i=2; i<=n; i++){
        if(is_prime[i]) p.push_back(i);
    }
    return p;
}

int main(){
	int n;
	cin >> n;
	vector<ll> v=get_prime(55555);
	int cnt=0;
	for(int i=0; i<v.size(); i++){
		if(v[i]%5==1){
			cout << v[i];
			if(cnt!=n) cout << " ";
			cnt++;
		}
		if(cnt==n) break;
	}
	cout << endl;
	return 0;
}

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

using namespace std;


int main(){
    string S, T;
    cin >> S >> T;
    if(S == T){
        cout << "Yes" << endl;
        return 0;
    }

    for(int i = 0; i < S.length(); i++){
        if(S == T){
            cout << "Yes" << endl;
            return 0;
        }
        S = S[S.length()-1] + S.substr(0,S.length()-1);
    }
    cout << "No" << endl;
    

    return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int a; string s;
    while (cin >> a >> s) {
        if (a >= 3200)
            cout << s << endl;
        else
            cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    while True:
        num = int(input())
        if num == 0:
            break

        ans = 999999999
        for c in range(54):
            cubic = c * c * c
            if cubic > num:
                break
            for t in range(96):
                tetra = (t * (t+1) * (t+2)) // 6
                if cubic + tetra > num:
                    break
                if abs(cubic + tetra - num) < abs(num - ans):
                    ans = cubic + tetra
        print(ans)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;int a;
  cin>>a;
  int b=a;
  long long sum=a;
  for(int i=1;i<=n-2;++i)
  {
    cin>>b;
    sum+=min(a,b);
    a=b;
  }
  sum+=b;
  cout<<sum;
}

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

using namespace std;

typedef long long ll;

struct data{
    int l, r;
    ll c;
    bool operator<(const data &r)const{
        return l<r.l;
    }
};

int n, k;
data arr[100002];

struct segmentTree{
    ll tree[400002], lazy[400002];

    void initialize(int i, int l, int r){
        if(l==r){
            if(l!=1) tree[i] = 1e18;
            return;
        }
        int m = (l+r)>>1;
        initialize(i*2, l, m);
        initialize(i*2+1, m+1, r);
    }

    void propagate(int i, int l, int r){
        if(!lazy[i]) return;
        if(l==r) tree[i] = min(tree[i], lazy[i]);
        else{
            lazy[i*2] = min(lazy[i*2]?lazy[i*2]:LLONG_MAX, lazy[i]);
            lazy[i*2+1] = min(lazy[i*2+1]?lazy[i*2+1]:LLONG_MAX, lazy[i]);
        }
        lazy[i] = 0;
    }

    ll getTree(int i, int l, int r, int x){
        propagate(i, l, r);
        if(l==r){
            return tree[i];
        }
        int m = (l+r)>>1;
        if(x<=m) return getTree(i*2, l, m, x);
        return getTree(i*2+1, m+1, r, x);
    }

    void setTree(int i, int l, int r, int s, int e, ll val){
        propagate(i, l, r);
        if(l==s && r==e){
            lazy[i] = val;
            propagate(i, l, r);
            return;
        }
        int m = (l+r)>>1;
        if(s<=m) setTree(i*2, l, m, s, min(m, e), val);
        if(m<e) setTree(i*2+1, m+1, r, max(m+1, s), e, val);
    }
} tree;

int main(){
    scanf("%d %d", &n, &k);
    tree.initialize(1, 1, n);
    for(int i=1; i<=k; i++){
        scanf("%d %d %lld", &arr[i].l, &arr[i].r, &arr[i].c);
    }
    sort(arr+1, arr+k+1);
    for(int i=1; i<=k; i++){
        int l = arr[i].l, r = arr[i].r;
        ll c = arr[i].c;
        ll tmp = tree.getTree(1, 1, n, l)+c;
//        printf("tmp: %lld -> %lld\n", tmp-c, tmp);
        tree.setTree(1, 1, n, l+1, r, tmp);
    }
    ll tmp = tree.getTree(1, 1, n, n);
    if(tmp > 1e17){
        printf("-1");
    }
    else{
        printf("%lld", tmp);
    }
}


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

using namespace std;

int main(void)
{
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int l = 1001, r = -1;
    for (int i = 0; i < n; i++) {
        l = min(l, a[i]);
        r = max(r, a[i]);
    }
    cout << r - l << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int M, T, P, R;

	void run() {
		for (;;) {
			M = sc.nextInt();
			T = sc.nextInt();
			P = sc.nextInt();
			R = sc.nextInt();
			if ((M | T | P | R) == 0) {
				return;
			}
			Team[] team = new Team[T];
			for (int i = 0; i < T; i++) {
				Team t = new Team(i + 1);
				team[i] = t;
			}
			for (int i = 0; i < R; i++) {
				int m = sc.nextInt();
				int t = sc.nextInt();
				int p = sc.nextInt();
				int j = sc.nextInt();

				if (j != 0) {
					team[t - 1].wrong[p] += 20;
				} else {
					team[t - 1].time += m;
					team[t - 1].time += team[t - 1].wrong[p];
					team[t - 1].solve++;
				}
			}
			Arrays.sort(team);
			for (int i = 0; i < T; i++) {
				System.out.print(team[i].num);
				if (i != T - 1) {
					if (team[i].solve == team[i + 1].solve
							&& team[i].time == team[i + 1].time) {
						System.out.print("=");
					} else {
						System.out.print(",");
					}
				}
			}
			System.out.println();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	class Team implements Comparable<Team> {
		int num;
		int solve;
		int time;
		int[] wrong;

		Team(int num) {
			this.num = num;
			wrong = new int[P + 1];
		}

		@Override
		public int compareTo(Team arg0) {
			if (arg0.solve != this.solve) {
				return arg0.solve - this.solve;
			} else if (arg0.time != this.time) {
				return this.time - arg0.time;
			} else {
				return arg0.num - this.num;
			}
		}
	}
}

Measured memory_bytes: 60724
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
ll a[maxn], q, t, n, m, k;
void sol()
{
    cin >> n >> k >> q;
    for(int i = 1; i <= q; i ++)
    {
        cin >> m;
        ++a[m];
    }
    for(int i = 1; i <= n; i ++)
    {
        a[i] = k - q + a[i];
        if(a[i] <= 0)cout <<"No";
        else cout << "Yes";
        cout << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
long long int gcd(long long int a,long long int b){
    if (b==0) return a;
    else return gcd(b,a%b);
}
int main(){
    long long int k,ans=0;
    cin>>k;
    for (long long int a=1; a<=k; a++){
        for (long long int b=1; b<=k; b++){
            for (long long int c=1; c<=k; c++){
                ans+=gcd(a,gcd(b,c));
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3624
import math
N = int(input())
city = []
l=[]
for i in range(N):
    city.append(list(map(int, input().split())))
for j in range(N):
    for k in range(N-j-1):
        l.append( ((city[j][0]-city[N-k-1][0])**2 +(city[j][1]-city[N-k-1][1])**2)**0.5)
print(sum(l)*2/N)

Measured memory_bytes: 38384