akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
ll n,x,y;
vector<ll>v[222222];
struct item{
  ll c,w;
}a[222222];
struct tree{
  ll c,w,id;
  tree(){
    w=(ll)1e18;
  }
  friend bool operator <(tree a, tree b) {
    return a.w < b.w;
  }
};
tree t[2222222];
int st[222222];
int en[222222];

void build(int v=1,int tl=1,int tr=n){
  if(tl==tr){
    t[v].c=a[tl].c;
    t[v].w=a[tl].w;
    t[v].id=tl;
  } else {
    int mid=(tl+tr)/2;
    build(v+v,tl,mid);
    build(v+v+1,mid+1,tr);
    t[v]=min(t[v+v],t[v+v+1]);
  }
}
tree get(int l,int r,int v=1,int tl=1,int tr=n){
  if(tl>r||tr<l)return tree();
  if (l <=tl&&tr<=r)return t[v];
  int mid=(tl+tr)/2;
  return min(get(l,r,v+v,tl,mid),get(l,r,v+v+1,mid+1,tr));
}
void kill(int pos,int v=1,int tl=1,int tr=n){
  if(tl==tr)t[v].w=(ll)1e18;
  else {
    int mid=(tl+tr)/2;
    if(pos<=mid)kill(pos,v+v,tl,mid);
    else kill(pos,v+v+1,mid+1,tr);
    t[v]=min(t[v+v],t[v+v+1]);
  }
}
void read(ll &x)
{
  scanf("%lld",&x);
}
bool cmp(item a, item b)
{
  if(a.c!=b.c)
    return a.c<b.c;
  return a.w<b.w;
}
bool used[222222];
int fact[222222];
map<int, int>cnt;
int tot;
void dfs(int v){
  //cout<<v<<' ';
  used[v]=1;
  cnt[a[v].c]++;
  tot++;
  kill(v);
  int l=st[a[v].c];
  int r=en[a[v].c];
  //cout<<l<<' '<<r<<endl;
  while(1){
    auto it=get(l,r);
    //cout<<v<<"->"<<it.id<<' '<<it.w<<endl;
    if(a[v].w+it.w>x)
      break;
    dfs(it.id);
  }
  while(1){
    auto it=get(1,l-1);
    if(a[v].w+it.w>y)
      break;
    dfs(it.id);
  }
  while(1){
    auto it=get(r+1,n);
    if(a[v].w+it.w>y)
      break;
    dfs(it.id);
  }
}
const int MOD=(int)1e9+7;
int bin(int a, int b){
  int res=1;
  while(b){
    if(b&1)res=res*1ll*a%MOD;
    b>>=1;
    a=a*1ll*a%MOD;
  }
  return res;
}
int main()
{
  #ifdef LOCAL
  freopen("in.txt","r",stdin);
  #endif
  cin>>n>>x>>y;
  fact[0]=1;
  for(int i=1;i<=n;i++)
    fact[i]=fact[i-1]*1ll*i%MOD;
  for(ll i=1;i<=n;i++)
    read(a[i].c),read(a[i].w);
  sort(a+1,a+n+1,&cmp);
  for(int i=1;i<=n;i++)
    st[i]=0,en[i]=-1;
  for(int i=1;i<=n;i++){
    if(!st[a[i].c])
      st[a[i].c]=i;
    en[a[i].c]=i;
  }
  build();
  ll ans=1;
  for(int i=1;i<=n;i++){
    if(!used[i]){
      cnt.clear();
      tot=0;
      dfs(i);
      ans=ans*fact[tot]%MOD;
      for(auto it:cnt)
        ans=ans*bin(fact[it.second],MOD-2)%MOD;
      //cout<<endl;
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 87808
#include <bits/stdc++.h>
#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 MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int n, m;
int wei[200005];
pair<int, PII> E[100005];
int hv[100005];

int tot;
int par[200005], val[200005];
vector<int> T[200005];
void init()
{
	rep1(i, n) par[i] = i;
	tot = n;
}

int root(int x)
{
	return par[x] == x ? x : par[x] = root(par[x]);
}

int unite(int u, int v, int w)
{
	u = root(u);
	v = root(v); 
	if(u == v) return 0;
	
	tot ++;
	T[tot].clear();
	par[tot] = tot;
	val[tot] = w;
	
	par[u] = par[v] = tot;
	T[tot].push_back(u);
	T[tot].push_back(v);
	return tot;
}

int ans;
LL sz[200005];
bool gg[200005];

void dfs0(int v)
{
	sz[v] = wei[v];
	rep(i, T[v].size()) {
		dfs0(T[v][i]);
		sz[v] += sz[T[v][i]];
	}
}

void dfs1(int v)
{
	if(sz[v] < val[v]) {
		gg[v] = true;
		ans ++;
		rep(i, T[v].size()) dfs1(T[v][i]);
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	rep1(i, n) scanf("%d", &wei[i]);
	rep(i, m) scanf("%d%d%d", &E[i].second.first, &E[i].second.second, &E[i].first);
	sort(E, E + m);
	
	init();
	rep(i, m) hv[i] = unite(E[i].second.first, E[i].second.second, E[i].first);
	
	rep1(i, tot) if(par[i] == i) {
		dfs0(i);
		dfs1(i);
	}
	
	init();
	rep(i, m) if(hv[i] && !gg[hv[i]]) unite(E[i].second.first, E[i].second.second, E[i].first);
	rep1(i, tot) if(par[i] == i) dfs0(i);
	
	rep(i, m) if(!hv[i]) {
		int u = root(E[i].second.first), v = root(E[i].second.second);
		if(u != v || sz[u] < E[i].first) ans ++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 18176
A, B = map(int, input().split())

answer = 'IMPOSSIBLE'
start = (A + B) // 2 - 1
end = (A + B) // 2 + 1


for i in range(start, end+1):
    a = abs(A - i)
    b = abs(B - i)
    
    if a == b:
        answer = i
        break

print(answer)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner S = new Scanner(System.in);
    int N = S.nextInt();
    int T[] = new int[N];
    int sum = 0;
    for (int i = 0; i < N; i++){
      T[i] = S.nextInt();
      sum += T[i];
    }
    int M = S.nextInt();
    for (int i = 0; i < M; i++){
      int P = S.nextInt() -1 ;
      int X = S.nextInt();
      System.out.println(sum - T[P] + X);
    }
  }
}

Measured memory_bytes: 21460
#include <string>
#include <vector>
#include <map>
#include <deque>
#include <iostream>
#include <queue>
#include <math.h>
#include <algorithm>
#include <fstream>

using namespace std;
typedef long long ll;


int main(void) {
	int a,b;
//	vector<int> a(n);
//	vector<int> tmp(n);

	cin >> a >>b;
	cout << max({ a+b,a-b,a*b });
	
	return 0;
}


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

#define DIV 1000000007

using namespace std;

long modinv(long a, long mod){
    if(a == 0){
        perror("0 division");
        exit(1);
    }
    if(a == 1 || a%mod == 0){
        return 1;
    }
    
    else{
        long MOD = mod;
        long d = 0;
        long n = 0;
        vector<long> c(0);
        while( d != 1 ){
            n++;
            c.emplace_back(mod / a);
            d = mod % a;
            mod = a;
            a = d;
        } 
        long x = d;
        long y = -c[n-1];
        long temp;
        for(int i=n-2; i >= 0; i--){
            temp = y;
            y = x - c[i] * y;
            x = temp;
        }
        if(y>=0) return y;
        else return y + MOD;
    }
}

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

    int a, b;
    if((2*y - x )%3 !=0 || (2*x - y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    a = (2*y -x) / 3;
    b = (2*x - y) / 3;
    if(a < 0 || b < 0){
        cout << 0 << endl;
        return 0;
    }

    long ans = 1;
    for(int i = b + 1; i <= a + b; i++){
        ans *= i;
        ans %= DIV;
    }

    for(int i = 1; i<=a; i++){
        ans *= modinv(i, DIV);
        ans %= DIV;
    }
    cout<< ans <<endl;

    return 0;

}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	if n == 1
		println(1)
	else
	l = 1
	r = 1
	k = 0
	bb = zeros(Int,n,20)
	tmp = zeros(Int,20)
	for i in 1:n
		x = a[i]
		for j in 0:19
			if (x>>j)%2==1
				bb[i,j+1] = tmp[j+1]
				tmp[j+1] = i
			end
		end
	end
	mb = [maximum(bb[i,:]) for i in 1:n]
	l = 1
	r = 1
	while l<n||r<n
		if mb[r]<l
			if r == n
				k += (r-l+2)*(r-l+1)>>1
				l = r
			else
				r += 1
			end
		else
			k += (r-l+1)*(r-l)>>1-(r-mb[r])*(r-mb[r]-1)>>1
			if r == n
				k += (r-mb[r]+1)*(r-mb[r])>>1
				l = r
			else
				l = mb[r]+1
			end
		end
	end
	println(k)
end
end

main()

Measured memory_bytes: 194724
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

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

#define DEBUG
#undef DEBUG

using ll  = long long;
using ull = unsigned long long;

int N, M;
char A[50][50];
char B[50][50];

bool match(int i, int j)
{
    FOR(k, 0, M) {
        FOR(l, 0, M) {
            if(B[k][l] != A[i+k][j+l])
                return false;
        }
    }

    return true;
}

void solve()
{
    FOR(i, 0, N-M+1) {
        FOR(j, 0, N-M+1) {
            if(match(i, j)) {
                cout << "Yes\n";
                return;
            }
        }
    }

    cout << "No\n";
}

int main()
{
    cin >> N >> M;
    REP(i, N) {
        string s;
        cin >> s;
        REP(j, N) {
            A[i][j] = s[j];
        }
    }
    REP(i, M) {
        string s;
        cin >> s;
        REP(j, M) {
            B[i][j] = s[j];
        }
    }

    solve();

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.regex.Pattern;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int theta = 90; 
                double x = 0;
                double y = 0;
                String[] s = sc.nextLine().split(",");
                int r = Integer.parseInt(s[0]);
                while(r != 0){ 
                        x += r*Math.cos(Math.toRadians((double)theta));
                        y += r*Math.sin(Math.toRadians((double)theta));
                        theta = addTheta(theta,-Integer.parseInt(s[1]));
                        s = sc.nextLine().split(",");
                        r = Integer.parseInt(s[0]);
                }   
                sc.close();
                System.out.println((int)x);
                System.out.println((int)y);
        }   
        static int addTheta(int theta, int dtheta){
                theta += dtheta;
                if(theta < 0){ 
                        theta += 360;
                }else if(theta >= 360){
                        theta -= 360;
                }   
                return theta;
        }   
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int mx = -1;
  rep(i, n){
    cin >> a.at(i);
    mx = max(mx, a.at(i));
  }
  if(k > mx){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int g;
  rep(i, n){
    if(i == 0){
      g = a.at(i);
    }else{
      g = gcd(g, a.at(i));
    }
  }
  if(k % g == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 3668
import sys
K=1024
N=331
R=range(K)
B=[1,2,4,8,16,32,64,128,256,512]
C=[0]*K
D=[[0 for i in range(N)]for j in R]

for i in R:
  s=format(i,'b')
  n=s.count('1')
  C[i]=n
  if n==1:D[i][B.index(i)]=1
  else:
    for j in range(len(s)):
      if s[-j-1]=='1':
        dp=n*j
        i2=i-B[j]
        for k in range(N-dp):
          D[i][k+dp]+=D[i2][k]
   
for a in sys.stdin:
  n,s=map(int,a.split())
  x=0
  if s<N:x=sum([D[i][s] for i in R if C[i]==n])
  print x

Measured memory_bytes: 7144
//20
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int ns,nl;
int d[11][11];
int ln[11][11];
vector<int> mv,cv;
int m;

void dfs(int v,int ds){
  cv.push_back(v);
  for(int i=1;i<=ns;i++){
    if(d[v][i]){
      int cs=d[v][i];
      d[v][i]=d[i][v]=0;
      dfs(i,ds+cs);
      d[v][i]=d[i][v]=cs;
    }
  }
  if(ds>m){
    m=ds;
    mv=cv;
  }
  cv.pop_back();
}

int main(){
  while(cin>>ns>>nl,ns|nl){
    fill(d[0],d[11],0);
    for(int i=0;i<nl;i++){
      int s,t,dd;
      cin>>s>>t>>dd;
      d[s][t]=d[t][s]=dd;
      ln[s][t]=ln[t][s]=i;
    }
    m=0;
    for(int i=1;i<=ns;i++){
      dfs(i,0);
    }
    cout<<m<<endl;
    for(int i=0;i<mv.size();i++){
      cout<<mv[i]<<((i==mv.size()-1)?'\n':' ');
    }
  }
  return 0;
}

    

Measured memory_bytes: 1216
from bisect import bisect_left,bisect_right
import sys
def input(): return sys.stdin.readline().strip()

def main(bisect_left=bisect_left, bisect_right=bisect_right):
    a,b=map(int,input().split())
    if a < 10 and b < 10:
        print(a*b)
    else:
        print(-1)

main()

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

constexpr int INF = 100000;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> g(n, std::vector<int>(n, INF));
  std::vector<std::vector<int>> shortest(n, std::vector<int>(n, INF));
  for (int i = 0; i < m; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    g[a - 1][b - 1] = g[b - 1][a - 1] = c;
    shortest[a - 1][b - 1] = shortest[b - 1][a - 1] = c;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        shortest[i][j] =
            std::min(shortest[i][j], shortest[i][k] + shortest[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (g[i][j] != INF && shortest[i][j] < g[i][j]) ans++;
    }
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
string s;
int main(){FAST;
cin>>s;
sort(all(s));
if(s[0]==s[1] and s[1]!=s[2] and s[2]==s[3]){
	cout<<"Yes";
}
else{
	cout<<"No";
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool kaibun(string s,int l,int r){
    bool ok =true;
    int n=s.size();
    for(int i=0; i<r-l+1; i++){
        if(s.at(l-1+i) != s.at(r-1-i)) {
            ok =false;
            break;
        }
    }
    return ok;
}
int main(){
    string s;
    cin>>s;
    int n= s.size();
    cout<<(kaibun(s,1,n)&&kaibun(s,1,(n-1)/2 )&&kaibun(s,(n+3)/2,n)? "Yes":"No" );

}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var a = int.Parse(input);
            var ans = a * (1 + a*(1 + a));
            Console.WriteLine("{0}", ans);
        }
    }
}


Measured memory_bytes: 17628
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
#include <unordered_map>

using namespace std;

#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
//#define ll long long
using ll = long long;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
MIKUNO - 15/02/1999
*/
const int N = 1e5 + 5;
//	priority_queue <ll, vector<ll>, greater<ll> > q;
int n, m, k, cnt, rs, q;
string s;
vector<bitset<26>> seg(500000 * 4 + 5);
void build(int id, int l, int r) {
	if (l == r) {
		seg[id].set(s[l] - 'a', 1);
		return;
	}
	int mid = l + (r - l >> 1);
	build(id * 2, l, mid);
	build(id * 2 + 1, mid + 1, r);
	seg[id] = seg[id * 2] | seg[id * 2 + 1];
}
void update(int id, int l, int r, int ch, int pos) {
	if (l > pos || r < pos) return;
	if (l == r) {
		seg[id] = 0;
		seg[id].set(ch - 'a', 1);
		return;
	}
	int mid = l + (r - l >> 1);
	update(id * 2, l, mid, ch, pos);
	update(id * 2 + 1, mid + 1, r, ch, pos);
	seg[id] = seg[id * 2] | seg[id * 2 + 1];
}
bitset<26> get(int id, int l, int r, int ql, int qr) {
	if (l > qr || r < ql) return 0;
	if (l >= ql && r <= qr) {
		return seg[id];
	}
	int mid = l + (r - l >> 1);
	return get(id * 2, l, mid, ql, qr) | get(id * 2 + 1, mid + 1, r, ql, qr);
}
int main()
{
	
	fast_input();
	cin >> n;
	cin >> s >> q;
	build(1, 0, n - 1);

	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int pos;
			char ch;
			cin >> pos >> ch;
			pos--;
			update(1, 0, n - 1, (int)ch, pos);
		}
		else {
			int ql, qr;
			cin >> ql >> qr;
			ql--, qr--;
			cout << get(1, 0, n - 1, ql, qr).count() << "\n";
		}
	}

}

Measured memory_bytes: 16788
#include<cstdio>
#include<map>
using namespace std;

const int MAX_N = 1e5;
int n;
map<int, int> m;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        m[a]++;
    }

    int cnt = 0;
    for (auto &i : m) {
        if (!(i.second & 1)) cnt++;
    }

    int ans = m.size();
    printf("%d\n", (cnt & 1) ? ans - 1 : ans);
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  vector<int> D(10, 0);
  int d;
  for (int i = 0; i < K; ++i) {
    scanf("%d", &d);
    D[d] = 1;
  }
  int ans = N;
  while (true) {
    bool ok = true;
    for (int i = ans; i > 0; i /= 10) {
      if (D[i % 10]) {
        ok = false;
        break;
      }
    }
    if (ok) { break;}
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


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

int main (){    
    ll A, B, K;
    cin>>A>>B>>K;
    if(A-K>=0){
        cout<<A-K<<" "<<B;
    }
    else if(A+B-K>0){
        cout<<0<<" "<<A+B-K;
        
    }
    else{
        cout<<0<<" "<<0;
    }
}

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

int same(string a, string b){
    int i;
    for(i = 0; i < a.length(); i++){
        if(a[i] != '?' && a[i] != b[i]) break;
    }
    if(i == a.length()) return 1;
    else return 0;
}

int main(){
    int i, j;
    string s, t;
    cin >> s >> t;
    int c = 0;
    for(i = s.length()-t.length(); i >= 0; i--){
        if(same(s.substr(i, t.length()), t)){
            for(j = 0; j < t.length(); j++) s[i+j] = t[j];
            break;
        }
    }
    if(i < 0) cout << "UNRESTORABLE" << endl;
    else{
        for(i = 0; i < s.length(); i++){
            if(s[i] == '?') s[i] = 'a';
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	static int a,b;
	static int ans=0;
	static int[][] takeshi;
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		
		while(true){
			b=s.nextInt();
			a=s.nextInt();
			if(a==0)System.exit(0);
			takeshi=new int[a][b];
			String now;
			int p=0,q=0;
			for(int i=0;i<a;i++){
				now=s.next();
				for(int j=0;j<b;j++){
					if(now.charAt(j)=='#')takeshi[i][j]=0;
					else if(now.charAt(j)=='.')takeshi[i][j]=1;
					else{
						takeshi[i][j]=0;
						p=i;
						q=j;
					}
				}
			}
			
			
			System.out.println(solve(p,q));
		}
	}
	static int solve(int m,int n){
		int ret=0;
		
		takeshi[m][n]=0;
		
		if(m>0)
			if(takeshi[m-1][n]==1)ret+=solve(m-1,n);
		if(m<a-1)
			if(takeshi[m+1][n]==1)ret+=solve(m+1,n);
		if(n>0)
			if(takeshi[m][n-1]==1)ret+=solve(m,n-1);
		if(n<b-1)
			if(takeshi[m][n+1]==1)ret+=solve(m,n+1);
		
		
		return ret+1;
	}
}

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

int main(){

   int a,b,c;

   cin>>a>>b>>c;

   

   if( a > b ) swap(a, b);
   if( b > c ) swap(b, c);
   if( a > b ) swap(a, b);

 cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3096
// Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int ma[N];
void solve(){
    int n,ans=0;cin>>n;vi v(n+1,0);
    rep(i,1,n){
        cin>>v[i];
        ma[v[i]]++;
    }
    rep(I,1,n){
        ma[v[I]]--;
        rep(i,1,sqrt(v[I])){
            if((v[I]%i)==0){
                if(ma[i]>0){ans++;break;}
                if(ma[v[I]/i]>0){ans++;break;}
            }
        }
        ma[v[I]]++;
    }
    cout<<n-ans;
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 12520
tcase=['AC','WA','TLE','RE']
tcount=[0,0,0,0]

n=int(input())
for i in range(n):
    c=input()
    for t in range(4):
        if tcase[t]==c:
            tcount[t]+=1
            break

for i in range(4):
    print(tcase[i],'x',tcount[i])

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            
        }

    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1920
//
//AtCoder Regular Contest 081
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<ll> a(n);
    map<ll, int> cnt;
    REP(i, n) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    sort(RALL(a));

    ll ans=0;
    ll h=-1;
    ll w=-1;    
    REP(i,n){
        if (cnt[a[i]]<2) continue;
        if (h==-1) {
            h=a[i];
            cnt[a[i]]-=2;
        }

        if (cnt[a[i]]<2) continue;
        if (w==-1) {
            w=a[i];
            cnt[a[i]]-=2;
        }

        if (w!=-1&&h!=-1){
            ans=w*h;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10236
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Coor{
public:
    Coor(int xx=0,int yy=0,int hh=0){x=xx;y=yy;h=hh;}
    ~Coor(){}
    int x;
    int y;
    int h;
};
int main()
{
    int n;
    cin>>n;
    vector<Coor> input(n);
    for(int i=0;i<n;i++){
        cin>>input[i].x>>input[i].y>>input[i].h;
    }
    Coor center;
    for(center.x=0;center.x<=100;center.x++){
    	for(center.y=0;center.y<=100;center.y++){
    		for(int i=0;i<n;i++){
    			if(input[i].h>0){
    				center.h=input[i].h+(input[i].x-center.x>=0?input[i].x-center.x:center.x-input[i].x)+(input[i].y-center.y>=0?input[i].y-center.y:center.y-input[i].y);
    				int j=0;
					for(;j<n;j++){
    					if(input[j].h!=max(0,center.h-(input[j].x-center.x>=0?input[j].x-center.x:center.x-input[j].x)-(input[j].y-center.y>=0?input[j].y-center.y:center.y-input[j].y))) break;         
    				}
    				if(j==n){
    					cout<<center.x<<" "<<center.y<<" "<<center.h;
    					return 0;
					} 
    			}
			}
    	}
    }
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  set<char> se;
  REP(i,s.size()) se.insert(s[i]);
  if(se.size() == 26) {cout << "None" << endl; return 0; }
  REP(i,26) {
    char c = i + 'a';
    if(!se.count(c)) { cout << c << endl; return 0; }
  }
  return 0;
}
//templete by private_yusuke

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

int main(){
  int n;
  cin >> n;
  int x,y,z; //1~99
  vector<int> ans(100000);
  if(n>=6){
    for(int x=1;(x+1)*(x+1)<=n;x++){
      for(int y=1;(y+1)*(y+1)<=n;y++){
        for(int z=1;(z+1)*(z+1)<=n;z++){
          ans.at(x*x + y*y + z*z + x*y + y*z + z*x)++;
//          for(int m=6;m<=n;m++){
//            if(m==x*x + y*y + z*z + x*y + y*z + z*x){
//              ans.at(m)++;
//            }
//          }
        }
      }
    }
  }  
  for(int i=1;i<=n;i++){
    cout << ans.at(i) << endl;
  } 
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int K,m,x;
	cin >> K;
	long long ans = 0;

	for(int a = 1; a<=K; a++){
		for(int b = 1; b<=K; b++){
			for(int c = 1; c<=K; c++){
				if(a<=b){
					m = a;
				}
				else{
					m = b;
				}
				if(c<m){
					m = c;
				}
				for(int i = m; i>=1; i--){
					if(a%i == 0 && b%i == 0 && c%i == 0){
						x=i;
						break;
					}
				}
				ans = ans+x;
			}
		}
	}

	cout << ans;
	cin >> m;

	return 0;
}


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

const long int D = 1000000007;

int main() {
    long int n, k;
    cin >> n >> k;
    
    long int cnt = 0;
    for(long int i = k; i <= n+1; i++) {
        
        cnt += ((n-i+1) * i + 1) % D;
        cnt %= D;
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 3636
N, M = map(int, input().split())
B = [0 for _ in range(M+1)]
for _ in range(N):
    A = list(map(int, input().split()))
    A = A[1:]
    for a in A:
        B[a] += 1
cnt = 0
for b in B:
    if b == N:
        cnt += 1
print(cnt)

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
	int n;
	cin >> n;
	cout << n * n * n;
	return 0;
}

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

const double PI = 3.141592653589793;

bool ok(double t, double a, double b, double x)
{
  t *= PI / 180;
  double v;
  if (a < b * cos(t) / sin(t))
    v = a * a * b - a * a * a * sin(t) / cos(t) / 2;
  else
    v = a * b * b * cos(t) / sin(t) / 2;
  return v <= x;
}

int main()
{
  i64 a, b, x;
  cin >> a >> b >> x;
  double l = 0, r = 90;
  for (i64 _ = 0; _ < 100; _++)
  {
    double mid = (l + r) / 2;
    if (ok(mid, (double)a, (double)b, (double)x))
      r = mid;
    else
      l = mid;
  }
  cout << fixed << setprecision(10) << l << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    while (1) {
        
    
    
    int h,w;
    scanf("%d %d",&h,&w);
    
        if(h==0 && w==0){
            break;
        }
        
    int i,j;
    for (i=0; i<h; i++) {
        for(j=0;j<w;j++){
            printf("#");
        }
        printf("\n");
    }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,len,mem[64],que=850;
char alpha[64];
string s[64];
string ans="12341234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
int flag=0;
int dist(string a,string b){
	static int f[130][130];
	memset(f,0x3f,sizeof(f));
	int n=a.length(),m=b.length();
	a='$'+a;b='#'+b;
	for (int i=0;i<=n;i++) f[i][0]=i;
	for (int i=0;i<=m;i++) f[0][i]=i;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	if (a[i]==b[j]) f[i][j]=f[i-1][j-1];
	else f[i][j]=min(min(f[i][j-1],f[i-1][j]),f[i-1][j-1])+1;
	return f[n][m];
}

bool cmp(string a,string b){return a.length()>b.length();}
int ask(string s){
	assert(s.length()<=128);
	assert(que);que--;
	if (flag) return dist(s,ans);
	cout<<"? "<<s<<endl;
	cout.flush();
	int ret;cin>>ret;
	return ret;
}
string merge(string a,string b){
	string res;res.clear();
	int n=a.length(),m=b.length(),i=0,j=0;
	if (!n) return b;
	if (!m) return a;
	while ((i<n)||(j<m))
	if (i==n) res+=b[j++];
	else if (j==m) res+=a[i++];
	else{
		string t=res+a[i]+b[j];
		for (int k=j+1;k<m;k++) t+=b[k];
		if (ask(t)==len-(int)t.length()) res+=a[i++];
		else res+=b[j++];
	}
	return res;
}
int main(){
//	freopen("a.in","r",stdin);
	for (char i='0';i<='9';i++) alpha[m++]=i;
	for (char i='A';i<='Z';i++) alpha[m++]=i;
	for (char i='a';i<='z';i++) alpha[m++]=i;
	for (int i=0;i<m;i++){
		for (int j=0;j<128;j++) s[i]+=alpha[i];
		int curlen=128-ask(s[i]);
		len+=curlen;
		s[i].clear();
		for (int j=0;j<curlen;j++) s[i]+=alpha[i];
	}
	
	if (flag) cerr<<len<<endl;
	
	while (m>1){
		sort(s,s+m,cmp);
		s[m-2]=merge(s[m-2],s[m-1]);
		m--;
	}
	if (flag) assert(s[0]==ans);
	else assert(ask(s[0])==0);
	cout<<"! "<<s[0]<<endl;
	return 0;
}

Measured memory_bytes: 3768
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
}
int a[114514],b[114514];
signed main(){
	ic(n) ic(h)
	rep(0,i,n)cin>>a[i]>>b[i];
	int max=maxi(a,0,n);
	int ans=0;
	sort(b,b+n);
	reverse(b,b+n);
	rep(0,i,n){
		if(b[i]>max){
			h-=b[i];
			ans++;
		}
		if(h<=0){
			c(ans)
			return 0;
		}	
	}
	c(ans+(h-1)/max+1)
}		

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll p(n);
    rep(i, n){
        cin >> p[i];
    }
    ll ans = 0;
    repr(i, 1, n-1){
        vll x(3);
        x[0] = p[i-1];
        x[1] = p[i];
        x[2] = p[i+1];
        sort(ALL(x));
        if(x[1] == p[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int K;
    string s;
    cin >> s >> K;

    REP(i, s.size()) {
        if (s[i] == 'a')
            continue;
        int a = 'z' - s[i] + 1;
        if (0 <= K - a) {
            s[i] = 'a';
            K -= a;
        } else {
            continue;
        }
    }
    if (0 < K) {
        int cnt = K % 26;
        int nxt = s[s.size() - 1] - 'a' + cnt;
        nxt %= 26;
        s[s.size() - 1] = 'a' + nxt;
    }
    print(s);

    return 0;
}

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

typedef long long LL;
const int Max = 200005;
const int M = 1000000005;
int A[Max];
int a[Max/2], b[Max/2];
LL Merge(int S[], int left, int right, int mid)//归并（归并时比较排序）
{
    int n1 = mid-left, n2 = right-mid;//以mid为界限，分割为两个数组
    LL cnt = 0;
    for(int i=0; i<n1; i++)
    {
        a[i] = S[i+left];
        //Count++;
    }
    for(int i=0; i<n2; i++)
    {
        b[i] = S[i+mid];
        //Count++;
    }
    a[n1] = M, b[n2] = M;//确保最后一个数较大，利于以下排序（M超出了S中元素的范围）
    int k=left, ka=0, kb=0;
    //Count++;
    while(k<right)
    {
        if(a[ka]>b[kb])//升序排列，一定为大于，保证了稳定排序
        {
            S[k++] = b[kb++];
            cnt += n1-ka;
        }
        else
        {
            S[k++] = a[ka++];
        }
    }
    return cnt;
}

LL MergeSort(int S[], int left, int right)//用于分割数组，分别排序（分治）
{
    LL v1, v2, v3;
    if(left+1<right)//判断是否可以分割
    {
        int mid = (left+right)/2;
        v1 = MergeSort(S, left, mid);
        v2 = MergeSort(S, mid, right);
        v3 = Merge(S, left, right, mid);//归并
        return v1+v2+v3;
    }
    else
        return 0;
}


int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d", &A[i]);
    }
    LL ans = MergeSort(A, 0, n);
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 4772
import java.util.Scanner;

public class Main {

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

    int n = scanner.nextInt();
    int[] t = new int[n + 1];
    int[] x = new int[n + 1];
    int[] y = new int[n + 1];

    t[0] = x[0] = y[0] = 0;
    for (int i = 1; i <= n; i++) {
      t[i] = scanner.nextInt();
      x[i] = scanner.nextInt();
      y[i] = scanner.nextInt();
    }

    new Main().execute(n, t, x, y);
  }

  public void execute(int n, int[] t, int[] x, int[] y) {
    for (int i = 1; i <= n; i++) {
      int step = t[i] - t[i - 1];

      if (!canWalk(step, x[i - 1], y[i - 1], x[i], y[i])) {
        System.out.println("No");
        return;
      }
    }

    System.out.println("Yes");
  }

  /**
   * Can we walk from (startX, startY) to (endX, endY) in `stepCount` steps
   */
  private boolean canWalk(int stepCount, int startX, int startY, int endX, int endY) {
    int minStep = Math.abs(endX - startX) + Math.abs(endY - startY);
    return (stepCount >= minStep) &&
        ((stepCount - minStep) % 2 == 0);
  }
}


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

typedef long long ll;

int main() {
   string s;
   cin >> s;
   string b = s;
   reverse(b.begin(),b.end());
   int cnt = 0;
   if (s == b) {
	   cnt++;
   }
   int n = (int)s.size();
   string s1 = "";
   string s2 = "";
   for (int i = 0; i < (n - 1) / 2; ++i) {
	   s1 += s[i];
   } 
   for (int i = ((n + 3) / 2) - 1; i < n; ++i) {
	   s2 += s[i];
   }
 //  cout << s1 << " " << s2;
   string s3 = s1;
   string s4 = s2;
   reverse(s3.begin(),s3.end());
   reverse(s4.begin(),s4.end());
   if (s1 == s3) cnt++;
   if (s2 == s4) cnt++;
   if (cnt == 3) {
	   cout << "Yes";
   }else {
	   cout << "No";
   }
}



















Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << '\n'
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 998244353;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;
using mint = static_modint<mod>;
vector<mint> sum(200005);
struct S {
    mint v;
    mint x;
    int y;
    int keta;
};
S op (S a, S b) {
    if (a.y<b.y) swap(a, b);
    return S{a.v+b.v, a.x*mint(10).pow(a.y-b.y)+b.x, b.y, a.keta+b.keta};
}
S e() {
    return S{mint(0), mint(0), 0, 0};
}
using F = mint;
S mapping(F f, S s) {
    if (f.val()==0) return s;
    return S{f*(sum[s.keta+s.y]-sum[s.y]), f*sum[s.keta], s.y, s.keta};
}
F composition(F a, F b) {
    if (a.val()==0) return b;
    return a;
}
F id() {
    return mint(0);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;
    vector<S> x(n);
    rep(i, n) {
        sum[i+1] = sum[i]*10 + 1;
        //debug(sum[i+1].val());
    }
    
    rep(i, n) {
        x[i] = S{sum[n-i]-sum[n-i-1], mint(1), n-i-1, 1};
        //debug(x[i].v.val());
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> g(x);
    //debug(g.prod(0, n).keta);
    rep(qi, q) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        g.apply(l, r, mint(d));
        auto ans = g.prod(0, n);
        //debug(g.get(0).v.val());
        pr(ans.v.val());
    }
    
    return 0;
}


Measured memory_bytes: 16436
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);
	public void run() {
		double r=sc.nextDouble();
		ln(String.format("%.8f %8f",Math.PI*r*r, Math.PI*2*r));
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}
	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

using namespace std;

signed main() {
	int N;
	cin >> N;

	vector<int> d(N);
	REP(i, N) cin >> d[i];

	int ans = 0;
	REP(i, N) FOR(j, i+1, N) ans += d[i] * d[j];

	cout << ans << endl;

	return 0;
}

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

int main(){
    string S;
    int N;
    cin >> N >> S;
    int countW[N+10];
    int countE[N+10];
    int min_people = N;
    if(S.substr(0,1) == "W"){
        countW[0] = 1;
        countE[0] = 0;
    } else {
        countW[0] = 0;
        countE[0] = 1;
    }

    for(int i = 1; i < N; i++){
        if(S.substr(i,1) == "W"){
            countW[i] = countW[i-1] + 1;
            countE[i] = countE[i-1];
        } else {
            countW[i] = countW[i-1];
            countE[i] = countE[i-1] + 1;
        }
    }
    for(int i = 0; i < N; i++){
        int min_tmp;
        if(i == 0) min_tmp = countE[N-1];
        else min_tmp = countW[i-1] + countE[N-1] - countE[i];
        if(min_tmp < min_people) min_people = min_tmp;
    }
    cout << min_people << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[5],n;
    cin>>n;
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    int cur_time=0;
    for(int i=0;i<5;i++){
        if(n%a[i]==0){
            cur_time=max((n/a[i])+i,cur_time+1);
        }else{
            cur_time=max((n/a[i])+i+1,cur_time+1);
        }
    }
    cout<<cur_time<<endl;
 
    return 0;
    
}

Measured memory_bytes: 256