akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma target("avx")
#define ll long long
#define mod 1000000007ll
#define Mod 8223300057563100000ll
using namespace std;
int head[5005],nxt[10005],v[10005],tot=0,n;
int sz[5005],maxn[5005],p[5005],cnt=0,nsz=0;
ll fac[5005],inv[5005],f2[5005],i2[5005],dp[5005],ans=0;
inline void add(int a,int b)
{tot++;nxt[tot]=head[a];head[a]=tot;v[tot]=b;}
inline int max(int a,int b)
{return a>b?a:b;}
void dfs(int pos,int f)
{sz[pos]=1;
for (int i=head[pos];i;i=nxt[i])
{if (v[i]==f) continue;
dfs(v[i],pos);
sz[pos]+=sz[v[i]];
maxn[pos]=max(maxn[pos],sz[v[i]]);
}
maxn[pos]=max(maxn[pos],n-sz[pos]);
}
inline ll cal(int a,int b)
{return (((f2[a]*i2[a-b])%mod)*inv[b])%mod;}
inline ll qpow(ll a,ll b)
{ll res=1,tp=a;
while (b)
{if (b&1ll) res=res*tp%mod;
tp=tp*tp%mod;b>>=1ll;
}
return res;
}
inline void add(int sz)
{int i,j;
for (i=nsz;i>=0;i--)
{for (j=sz;j>=1;j--)
{dp[i+j]+=dp[i]*cal(sz,j);
if (dp[i+j]>Mod) dp[i+j]%=mod;
}
}
nsz+=sz;
for (i=0;i<=nsz;i++) 
{if (dp[i]>=mod) 
{dp[i]%=mod;}
}
}
int main (){
	int i,a,b,msz=233333,num=0,pos;
	scanf ("%d",&n);
	fac[0]=1ll;
	for (i=1;i<=n;i++) fac[i]=fac[i-1]*((ll)(i))%mod;
	inv[n]=qpow(fac[n],mod-2);
	for (i=n-1;i>=0;i--) inv[i]=inv[i+1]*((ll)(i+1))%mod;
	for (i=0;i<=n;i++)
	{f2[i]=fac[i]*fac[i]%mod;
	i2[i]=inv[i]*inv[i]%mod;
	}
	for (i=1;i<n;i++)
	{scanf ("%d%d",&a,&b);
	add(a,b);add(b,a);
	}
	dfs(1,0);
	for (i=1;i<=n;i++)
	{msz=min(msz,maxn[i]);}
	for (i=1;i<=n;i++)
	{if (maxn[i]==msz)
	{pos=i;num++;}
	}
	if (num==2) {printf ("%lld\n",(fac[n/2]*fac[n/2])%mod);return 0;}
	for (i=head[pos];i;i=nxt[i])
	{if (sz[v[i]]>sz[pos]) continue;
	p[++cnt]=sz[v[i]];
	}
	dp[0]=1;
	p[++cnt]=n-sz[pos];
	sort(p+1,p+cnt+1);
	for (i=1;i<=cnt;i++) add(p[i]);
	for (i=0;i<=n;i++)
	{if (i&1) {ans-=dp[i]*fac[n-i];}
	else {ans+=dp[i]*fac[n-i];}
	ans%=mod;
	}
	if (ans<0) ans+=mod;
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdint.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pi 3.1415926535897932
#define nui 100
using namespace std;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int ac=0, wa=0, tle=0, re=0;
    while(n--){
        string s; cin >> s;
        char c = s[0];
        if(c=='A'){
            ac++;
        }
        else if(c=='W'){
            wa++;
        }
        else if(c=='T'){
            tle++;
        }
        else if(c=='R'){
            re++;
        }
    }
    cout << "AC" << " x " << ac << endl;
    cout << "WA" << " x " << wa << endl;
    cout << "TLE" << " x " << tle << endl;
    cout << "RE" << " x " << re << endl;
    return 0;
}

Measured memory_bytes: 3656
MAX = 2 * 10 ** 5 + 1
finv = [0] * MAX
inv = [0] * MAX
MOD = 10 ** 9 + 7


def COMinit():
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def COM(n, k):
    if n < k or k < 0:
        return 0
    res = 1
    for i in range(n, n - k, -1):
        res *= i
        res %= MOD
    res *= finv[k]
    return res % MOD


n, a, b = map(int, input().split())
total = pow(2, n, MOD) - 1
COMinit()
not_a = COM(n, a)
not_b = COM(n, b)
ans = total - not_a - not_b
while ans < 0:
    ans += MOD
print(ans)


Measured memory_bytes: 18804
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
	ll a, b, ans = 0;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		string s = to_string(i), x = s;
		reverse(s.begin(), s.end());
		if (s == x)ans++;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    if(s[k-1]=='A') s[k-1]='a';
    else if(s[k-1]=='B') s[k-1]='b';
    else s[k-1]='c';
    cout << s << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int sumOfDigits(ll n) {
  int ret = 0;
  while (n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

void solve() {
  int n; cin >> n;
  double a = int(log10(n));

  if (pow(10, a) == n) {
    outl(10);
  } else {
    outl(sumOfDigits(n));
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 504
#include <iostream>

const int MOD = 1000000007;

int main(){
   long long N, K;
   std::cin >> N >> K;
   int A[N];
   for(int i=0; i<N; ++i){
      std::cin >> A[i];
   }
   K %= MOD;

   long long factK1, factK2;
   factK1 = K * (K+1) / 2 % MOD;
   factK2 = (K-1) * K / 2 % MOD;

   long long count1, count2;
   long long ans = 0;
   for(int i=0; i<N; ++i){
      count1 = 0;
      count2 = 0;
      for(int j=i+1; j<N; ++j){
	 if(A[i]>A[j]) count1++;
      }
      for(int j=i-1; j>=0; --j){
	 if(A[i]>A[j]) count2++;
      }
      ans += count1 * factK1 % MOD;
      ans += count2 * factK2 % MOD;
   }

   std::cout << ans%MOD << std::endl;
   return 0;

}


Measured memory_bytes: 256
while True:
    a, op, b = map(str, input().split())
     
    if op == "+":
        print(str(int(a) + int(b)))
    if op == "-":
        print(str(int(a) - int(b)))
    if op == "*":
        print(str(int(a) * int(b)))
    if op == "/":
        print(str(int(a) // int(b)))
    if op == "?":
        break

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

#define len strlen(str)

int main(void)
{
	char str[101];
	int i, num, f;
	
	num = 0;
	
	while (scanf("%s", str) != EOF){
		f = 1;
		
		for (i = 0; i < len / 2; i++){
			if (str[i] != str[len - 1 - i]){
				f = 0;
				break;
			}
		}
		
		if (f == 1){
			num++;
		}
	}
	
	printf("%d\n", num);
	
	return (0);
}

Measured memory_bytes: 540
#include<stdio.h>
#include<string.h>
 
#define LEN 100005
#define MAX 100
 
typedef struct pp{
  char name[MAX];
  int t;
}P;
 
P Q[LEN+1];
int head, tail, n;
 
void initialize(void);
 
void enqueue(P);
P dequeue(void);
 
 
int main(){
  P u;
  int elaps = 0, n;
  int i, q;
  
  scanf("%d %d", &n, &q);
 
  for ( i = 1; i <= n; i++){
    scanf("%s", u.name);
    scanf("%d", &u.t);
    enqueue(u);
  }
  
  while(head != tail){
    u=dequeue();
    if(u.t>q){
      u.t=u.t-q;
      enqueue(u);
      elaps+=q;
    }
    else{
      printf("%s %d\n",u.name,u.t+elaps);
      elaps+=u.t;
    }
  }
   
  return 0;
}
void initialize(void){
  head=0;
  tail=0;
}
  
 
void enqueue(P x){
  
    Q[tail]=x;
    if(tail+1==LEN)
      tail=0;
    else
      tail++;
 
}
P dequeue(void){
  P x;
   
    x=Q[head];
    if(head+1==LEN)
      head=0;
    else
      head++;
 
  return x;
}

Measured memory_bytes: 12728
N=gets.to_i
array=gets.chomp.split(" ").map(&:to_i)
MOD=10**9+7
sum=Array.new(N,0)
array.each do |a|
    sum[a]+=1
end
ret = 1
sum.each_with_index do |s, i|
    if N.even?
        if i.even?
            if s != 0
                puts 0
                exit
            end
        else
            if s != 2
                puts 0
                exit
            end
            ret *= 2
            ret %= MOD
        end
    else
        if i == 0
            if s != 1
                puts 0
                exit
            end
        elsif i.even?
            if s != 2
                puts 0
                exit
            end
            ret *= 2
            ret %= MOD
        else
            if s != 0
                puts 0
                exit
            end            
        end        
    end
end
puts ret

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

using namespace std;

long long min_attack(long long H){
    if(H==1){
        return static_cast<long long>(1);
    }else{
        return min_attack( H/2 ) * static_cast<long long>(2) + static_cast<long long>(1);
    }
}


int main(){
    long long H;
    cin >> H;

    printf("%lld\n",  min_attack(H) );
    
    return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
#define mp make_pair
#define ni(x) scanf("%d", &(x))
#define nii(x,y) scanf("%d%d",&(x),&(y))
#define mul(x,y) ((ll)(x)*(y)%mod)
#define mtp make_tuple
#define F(i,n) for(int i = 0; i < (n); i++)
#define FF(i,n) for(int i = 1; i <= (n); i++)
#define FE(i,n) for(int i = 0; i <= (n); i++)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1000000007;
const int inf = 2012345678;
const ll infl = 9012345678901234567;
const double pi = 3.1415926535897932384626433832795;
//----------------------------------------------------------------------------//

const int N = 100000;
int a[N];
int gcd(int a, int b) {
	if (!b)return a;
	else return gcd(b, a%b);
}

bool solve(vector<int>& a) {
	int n = a.size();
	bool eq = false;
	ll sum = 0;
	F(i, n) {
		if (a[i] == 1)eq = true;
		sum += a[i];
	}
	if (eq) {
		if (sum % 2 == n % 2) {
			return false;
		}
		else {
			return true;
		}
	}
	int cnt = 0;
	F(i, n) {
		if (a[i] % 2 == 0) cnt++;
	}
	if (cnt & 1) {
		return true;
	}
	if (cnt != n - 1) {
		return false;
	}
	F(i, n)if (a[i] & 1)a[i]--;
	int gg = a[0];
	F(i, n) {
		gg = gcd(gg, a[i]);
	}
	F(i, n)a[i] /= gg;

	return !solve(a);
}

int main() {
#ifndef __GNUG__
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	vector<int> V;
	int n; ni(n);
	F(i, n) {
		int x; ni(x);
		V.push_back(x);
	}
	if (solve(V))puts("First");
	else puts("Second");

	return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#define N 100
#define M 1000
int top,S[M];

void push(int x){
  top++;
  if(top==M-1){
    fprintf(stderr,"over flow\n");
    exit(1);
  }
  S[top]=x;
}

int pop(){
  top--;
  if(top<0){
    fprintf(stderr,"empty\n");
    exit(2);
  }
  return S[top+1];
}

int main(){
  char num[N];
  top=0;
  int a,b;
  while(scanf("%s",num)!=EOF){
    if(num[0]=='+'){
      a=pop();
      b=pop();
      push(b+a);
    }
    else if(num[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(num[0]=='*'){
      a=pop();
      b=pop();
      push(b*a);
    }
    else push(atoi(num));
  }
  printf("%d\n",pop());
  return 0;

}



Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)



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

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;



int main(){
    int n;
    string s;
    cin>>s;
    n=s.size();
    int cnt=0;
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        //Rについてのみ考える
        if (s[i]=='R') cnt++;
        else {
            ans[i]+=cnt/2;
            ans[i-1]+=(cnt+1)/2;
            cnt=0;
        }
        
    }
    cnt=0;
    for (int i=n-1;i>=0;i--){
        if (s[i]=='L') cnt++;
        else {
            ans[i]+=cnt/2;
            ans[i+1]+=(cnt+1)/2;
            cnt=0;
        }
    }
    
    rep(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

A=input()

A=list(map(lambda x:ord(x)-97,A))

log=[0]*26
log[A[0]]+=1
ans=1


for i in range(1,len(A)):
    ans+=i-log[A[i]]
    log[A[i]]+=1

print(ans)

Measured memory_bytes: 10656
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	if(s<t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

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

    vector<int> dx;
    vector<int> dy;
    bool horizontal = true;

    int sx = 0;
    int sy = 0;

    dx.push_back(0);
    dy.push_back(0);
    REP(i, s.size()) {
        if(s[i] == 'T') {
            horizontal = !horizontal;
            if(horizontal) {
                dx.push_back(0);
            }else{
                dy.push_back(0);
            }
        }else{
            if(horizontal) {
                dx[dx.size() - 1]++;
                sx++;
            }else{
                dy[dy.size() - 1]++;
                sy++;
            }
        }
    }
    sx = max(abs(x), sx);
    sy = max(abs(y), sy);

    int X = sx*2 + 1;
    int Y = sy*2 + 1;
    bool xdp[dx.size() + 1][X];
    bool ydp[dy.size() + 1][Y];

    REP(i, dx.size() + 1) {
        fill(xdp[i], xdp[i] + X, false);
    }
    REP(i, dy.size() + 1) {
        fill(ydp[i], ydp[i] + Y, false);
    }

    xdp[0][sx] = true;
    xdp[1][sx + dx[0]] = true;
    FOR(i, 1, dx.size()) {
        REP(j, X) {
            if(xdp[i][j]) {
                xdp[i + 1][j + dx[i]] = true;
                xdp[i + 1][j - dx[i]] = true;
            }
        }
    }
    ydp[0][sy] = true;
    FOR(i, 0, dy.size()) {
        REP(j, Y) {
            if(ydp[i][j]) {
                ydp[i + 1][j + dy[i]] = true;
                ydp[i + 1][j - dy[i]] = true;
            }
        }
    }

    if(xdp[dx.size()][sx + x] && ydp[dy.size()][sy + y]) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 39168
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include <climits>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int n;
int t[20][20];
int dp[100000];

void solve(){
  int to = (1<<n);
  rep(i,to+2) dp[i] = INT_MAX;
  dp[0] = 0;

  rep(i,to){
    if(dp[i] == INT_MAX) continue;
    rep(next,n){
      if((i & (1<<next)) != 0) continue;
      int minCost = t[next][0];
      rep(j,n){
        if((i & (1<<j)) != 0){
          minCost = min(minCost,t[next][j+1]);
        }
      }

      int bit = (i | (1<<next));
      dp[bit] = min(dp[bit],dp[i]+minCost);
    }
  }

  cout<<dp[to-1]<<endl;
}

int main(){
  while(cin>>n,n){
    rep(i,n){
      rep(j,n+1){
        cin>>t[i][j];
      }
    }
    solve();
  }
}

Measured memory_bytes: 1128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
string s[1000000];
int main(){
    ll n;
    cin>>n;
    rep(i,n) cin>>s[i];
    vector<P> pl,mi;
    int z=1,SUM=0;
    rep(i,n)rep(j,s[i].size()){
        if(s[i][j]=='(') SUM++;
        else SUM--;
    }
    if(SUM!=0) z=0;
    rep(i,n){
        ll sum=0,mok=0;
        rep(j,s[i].size()){
            if(s[i][j]=='(') sum++;
            else sum--;
            mok=min(mok,sum);
        }
        if(sum>=0){
            pl.push_back(P(mok,sum));
        }
        else{
            mok=mok*(-1);
            sum=sum*(-1);
            mi.push_back(P(mok-sum,sum));
        }
    }
    ll sum=0;
    sort(all(pl),greater<P>());
    sort(all(mi),greater<P>());
    rep(i,pl.size()){
        if(sum<pl[i].first*(-1)) z=0;
        sum+=pl[i].second;
    }
    rep(i,mi.size()){
        if(sum<mi[i].first+mi[i].second) z=0;
        sum-=mi[i].second;
    }
    if(z) cout<<"Yes";
    else cout<<"No";
}

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

int main(){
  int N, i = 0, count = 0;
  cin >> N;
  string S;
  cin >> S;
  char *p = &S[0];
  while (i < N){
    if (p[i] == 'A' && p[i+1] == 'B' && p[i+2] == 'C'){
      count++;
      i += 3;
    }
    else
      i++;
  }
  cout << count << endl;
}


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

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

int dp[1000][1000]={0}; //dp[n+1][w] = max(dp[n][w-w[n+1]]+v[n+1],dp[n][w])

int main(){
    ll x1,x2,y1,y2;cin>>x1>>y1>>x2>>y2;
    ll x3,y3,x4,y4;
    ll a=y2-y1;
    ll b = x2-x1;
    y3 = y2+b;
    x3=x2-a;
    x4=x3-b;
    y4=y3-a;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll power(ll a,ll b){ll ans=1;while(b){if(b%2)ans=ans*a%mod;a=a*a%mod;b/=2;}return ans;}
int main(){
    ll n,k;
    cin>>n>>k;
    ll dp[2*(k+1)],ans=0;
    for(ll i=k;i>=1;i--){
        dp[i]=power(k/i,n);
        for(ll j=2*i;j<=k;j+=i) dp[i]-=dp[j];
        ans=(ans+i*dp[i]%mod)%mod;
    }
    cout<<(ans+mod)%mod;
    return 0;
}


Measured memory_bytes: 4436
N=int(input())
R=[input().split()+[i+1] for i in range(N)]
for i in range(N):
    R[i][1]=int(R[i][1])

R.sort(key=lambda x:x[1],reverse=True)
R.sort(key=lambda x:x[0])

for x,y,z in R:
    print(z)


Measured memory_bytes: 3060
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
const int MAX_V = 201;

void ChristmasEveEveEve(){
	int d;
	cin >> d;
	if (d == 25) {
		cout << "Christmas" << endl;
	}
	else if (d == 24) {
		cout << "Christmas Eve" << endl;

	}
	else if (d == 23) {
		cout << "Christmas Eve Eve" << endl;

	}
	else if (d == 22) {
		cout << "Christmas Eve Eve Eve" << endl;

	}
}
int main() {
	ChristmasEveEveEve();
	return 0;
}



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

int main(void) {
	int a, b;
	cin >> a >> b;
	int ret = 0;
	if (a > b) {
		ret += a;
		a--;
	}
	else{
		ret += b;
		b--;
	}

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


}

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

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int m=scan.nextInt();
  if(n==m){
System.out.println("Yes");}
  else{
    System.out.println("No");}
}
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  vector<int> W(N);
  for (int i = 0; i < N; ++i) {
    if (S.at(i) == '.')
      W.at(i) = 1;
    else
      W.at(i) = 0;
  }
  vector<int> Ws(N + 1, 0);
  for (int i = 0; i < N; ++i) Ws.at(i + 1) = Ws.at(i) + W.at(i);

  vector<int> B(N);
  for (int i = 0; i < N; ++i) {
    if (S.at(i) == '#')
      B.at(i) = 1;
    else
      B.at(i) = 0;
  }
  vector<int> Bs(N + 1, 0);
  for (int i = 0; i < N; ++i) Bs.at(i + 1) = Bs.at(i) + B.at(i);

  int ans = 1001001001;
  for (int i = 0; i < N; i++) {
    ans = min(ans, Bs.at(i) + Ws.at(N) - Ws.at(i + 1));
  }

  cout << ans << endl;
}

Measured memory_bytes: 3716
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);


        String tmp = in.nextLine();
        
        int ans =0;
        for(int i=0;i<tmp.length();i++){
        	if(ans==0&&tmp.charAt(i)=='C')
        		ans=1;
        	if(ans==1&&tmp.charAt(i)=='F')
        		ans=2;
        }
        if(ans==2)
        	System.out.println("Yes");
        else
        	System.out.println("No");
	        

	}

}


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

typedef long long ll;
typedef pair<int, int> pi;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int min = *max_element(vec.begin(), vec.end());
// int max = *max_element(vec.begin(), vec.end());
// int sum = accumulate(a.begin(), a.end(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

bool is_prime(int x)
{
    if (x <= 1)
    {
        return false;
    }
    for (int i = 2; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll div = n / (a + b);
    ll ans = div * a;

    ll sub = (n + a + b) % (a + b);
    ll temp = 0;
    if (sub > a)
    {
        temp = a;
    }
    else if (a >= sub)
    {
        temp = sub;
    }

    cout << ans + temp << endl;
}


Measured memory_bytes: 256
N= int(input())
if N<=9:
    print(N)
elif 10<= N <=99:
    print('9')
elif 100<= N <=999:
    print(N-90)
elif 1000<= N <=9999:
    print('909')
elif 10000<= N<= 99999:
    print(N-9090)
else:print(90909)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

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

//input
ll h,w;
ll ch,cw;
ll dh,dw;
char field[1010][1010];

bool seen[1010][1010];
ll id[1010][1010];

void dfs(int x,int y,int idx){
    seen[x][y]=true;
    id[x][y]=idx;
    for(int dir=0;dir<4;dir++){
        int nx = x+dx[dir];
        int ny = y+dy[dir];
        if(nx<0||nx>=h||ny<0||ny>=w)continue;
        if(field[nx][ny]=='#')continue;
        if(seen[nx][ny])continue;
        dfs(nx,ny,idx);
    }
}

int main(){
    cin >> h >> w;
    cin >> ch >> cw;
    cin >> dh >> dw;
    rep(i,h)rep(j,w){
        cin>>field[i][j];
        id[i][j]=-1;//壁のidは-1
    }
    ch--;cw--;dh--;dw--;
    int idx = 0;
    rep(i,h){
        rep(j,w){
            if(seen[i][j])continue;
            if(field[i][j]=='#')continue;
            dfs(i,j,idx);
            idx++;
        }
    }
    int id_max=idx;
    Graph g(id_max);
    set<P>done;
    rep(i,h){
        rep(j,w){
            if(field[i][j]=='#')continue;
            int now_id = id[i][j];
            for(int k=-2;k<=2;k++){
                for(int l=-2;l<=2;l++){
                    int ni = i+k;
                    int nj = j+l;
                    if(ni<0||ni>=h||nj<0||nj>=w)continue;
                    if(field[ni][nj]=='#')continue;
                    if(id[ni][nj]==now_id)continue;
                    int nx_id = id[ni][nj];
                    if(done.count({now_id,nx_id}))continue;
                    if(done.count({nx_id,now_id}))continue;
                    g[now_id].push_back(nx_id);
                    g[nx_id].push_back(now_id);
                    done.insert({now_id,nx_id});
                }
            }
        }
    }
    vector<ll>dist(id_max,-1);
    queue<ll>que;
    dist[id[ch][cw]]=0;
    que.push(id[ch][cw]);
    while (!que.empty()){
        int v = que.front();
        que.pop();
        for(int nv:g[v]){
            if(dist[nv]!=-1)continue;
            dist[nv]=dist[v]+1;
            que.push(nv);
        }
    }
    if(dist[id[dh][dw]]==-1){
        cout << -1 << endl;
    }
    else{
        cout << dist[id[dh][dw]] << endl;
    }
    

    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<int>> dist(n, vector<int>(n, inf));
    rep(i, n) dist[i][i] = 0;
    rep(_, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = dist[b][a] = c;
    }
    rep(k, n) rep(i, n) rep(j, n) {
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
    vector<vector<int>> dist2(n, vector<int>(n, inf));
    rep(i, n) rep(j, n) {
        if (dist[i][j] <= l) dist2[i][j] = 1;
    }
    rep(k, n) rep(i, n) rep(j, n) {
        chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);
    }
    int q;
    cin >> q;
    rep(_, q) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        int ans = dist2[s][t] - 1;
        if (dist2[s][t] == inf) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,k;
    cin >> n >> k;
    lint ans = 1;
    lint k2 = k;
    while(k2<=n){
        k2 *= k;
        ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n,k,q; cin >> n >> k >> q;
    int a[n];
    for(int i = 0; i < n; i++) a[i] = 0;
    for(int i = 0; i < q; i++){
        int num; cin >> num;
        a[num-1]++;
    }
    for(int i = 0; i < n; i++){
        if(k-q+a[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

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

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  int n;
  cin >> n;
  vector< map<ll, int> > v(n);
  vector<int> vT(n);
  vector<int> origin(n);

  map<ll, int> mp;
  ll ans = 0;
  rep (i, n) {
    int tmp;
    cin >> tmp;

    ll target = tmp - i - 1;
    auto itr = mp.find(target);
    if (itr != mp.end()) ans += mp[target];

    ll inNum = (tmp + i + 1) * -1;
    itr = mp.find(inNum);
    if (itr != mp.end()) mp[inNum]++;
    else mp[inNum] = 1;
  }
  P(ans);
  return 0;
}

Measured memory_bytes: 26532
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int p[] = new int[n];

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);

		int ans = 0;
		for (int i = 0; i < k; i++) {
			ans += p[i];
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 38992
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

ll in[200020];
ll dp[200020][2][2];
ll iodd[200100], ieven[200100];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    int i;
    rep(i, n) cin >> in[i];
    ll ans(0);
    if (n % 2 == 0) {
        ll aa(0), ab(0);
        for (i = 0; i < n; i+= 2) {
            aa += in[i];
            ab += in[i+1];
        }
        ans = max(aa, ab);
        for (i = n - 1; i >= 0; i--) {
            iodd[i] = iodd[i+1];
            ieven[i] = ieven[i+1];
            if (i % 2 == 0) {
                ieven[i] += in[i];
            } else {
                iodd[i] += in[i];
            }
        }
        ll even(0);
        for (i = 0; i < n - 3; i+=2) {
            even += in[i];
            ans = max(ans, even + iodd[i + 3]);
        }

    } else {
        memset(dp, 0xa1, sizeof(dp));
        dp[0][0][0] = in[0];
        dp[0][0][1] = 0;
        xrep(i, 1, n) {
            dp[i][0][0] = dp[i-1][0][1] + in[i];
            dp[i][0][1] = dp[i-1][0][0];
            if (i >= 2) {
                dp[i][1][0] = max(dp[i-1][1][1], dp[i-2][0][1]) + in[i];
                dp[i][1][1] = dp[i-1][1][0];
            }
        }
        ll aa(0), ab(0);
        for (i = 0; i < n - 1; i+= 2) {
            aa += in[i];
            ab += in[i+1];
        }
        ans = max(dp[n-1][1][0], dp[n-1][1][1]);
        ans = max(ans, max(dp[n-2][0][0], dp[n-2][0][1]));
        
        for (i = n - 1; i >= 0; i--) {
            iodd[i] = iodd[i+1];
            ieven[i] = ieven[i+1];
            if (i % 2 == 0) {
                ieven[i] += in[i];
            } else {
                iodd[i] += in[i];
            }
        }
        for (i = 3 ; i < n - 3; i+=2) {
            ans = max(ans, dp[i][1][0] + ieven[i + 3]);
        }
        for (i = 0; i < n - 4; i+=2) {
            ans = max(ans, dp[i][0][0] + ieven[i + 4]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 14556
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef double ld;
typedef pair<ll, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 100005;
int n, a[MX], b[MX], p[MX], q[MX];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	forn (i, n) cin >> a[i];
	forn (i, n) cin >> b[i];

	iota(q, q + n, 0);
	sort(q, q + n, [&] (int i, int j) {
		return b[i] < b[j];
	});

	iota(p, p + n, 0);
	sort(p, p + n, [&] (int i, int j) {
		return a[q[i]] < a[q[j]];
	});

	sort(a, a + n);
	sort(b, b + n);

	forn (i, n) if (a[i] > b[i]) {
		cout << "No" << endl;
		return 0;
	}

	int u = 0, sz = 1;
	while (p[u]) {
		u = p[u];
		sz++;
	}

	if (sz < n) {
		cout << "Yes" << endl;
		return 0;
	}

	forn (i, n - 1) if (a[i + 1] <= b[i]) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N;
int a[50], b[50];
int M;
int u[20], v[20];

const int N_MAX = 50;
const int N_LOG_MAX = 9;
vector<int> G[N_MAX];
int root;

int parent[N_LOG_MAX][N_MAX];
int depth[N_MAX];

void dfs(int v, int p, int d){
    parent[0][v] = p;
    depth[v] = d;
    for(int i = 0; i < G[v].size(); i++){
        if(G[v][i] != p) dfs(G[v][i], v, d+1); 
    }
}

void init(int V){
    dfs(root, -1, 0);
    for(int i = 0; i < N_LOG_MAX-1; i++){
        for(int v = 0; v < V; v++){
            if(parent[i][v] < 0) parent[i+1][v] = -1;
            else parent[i+1][v] = parent[i][parent[i][v]];
        }
    }
}

int lca(int u, int v){
    if(depth[u] > depth[v]) swap(u, v);
    for(int i = 0; i < N_LOG_MAX; i++){
        if((depth[v] - depth[u]) >> i & 1){
            v = parent[i][v];
        }
    }
    if(u == v) return u;
    for(int i = N_LOG_MAX-1; i >= 0; i--){
        if(parent[i][u] != parent[i][v]) {
            u = parent[i][u];
            v = parent[i][v];
        }
    }
    return parent[0][u];
}

int col[50];
bool used[50];
int lca_[20];
int cnt_e;
void clear(){
    for(int i = 0; i < N; i++) col[i] = 0;
    for(int i = 0; i < N; i++) used[i] = 0;
    cnt_e = 0;
}


void paint(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]) {
            paint(G[v][i]);
            col[v] += col[G[v][i]];
            if(col[G[v][i]] > 0){
                cnt_e++;
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    cin >> M;
    for(int i = 0; i < M; i++){
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }
    init(N);
    ll ans = 0;
    for(int j = 0; j < M; j++){
        lca_[j] = lca(v[j], u[j]);
    }
    for(int i = 0; i < ((ll)1<<M); i++){
        clear();
        int c = 0;
        for(int j = 0; j < M; j++){
            if(i&(1<<j)){
                c++;
                col[v[j]]++;
                col[u[j]]++;
                int l = lca_[j];
                col[l] -= 2;
            }
        }
        int cnt = 0;
        paint(0);
        
        if(c%2 == 0){
            ans += ((ll)1<< (N-cnt_e-1));
        }else{
            ans -= ((ll)1<< (N-cnt_e-1));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
_input = [i for i in open(0).read().split('\n') if i]
n, d = [int(i) for i in _input[0].split()]
x_list = [[int(i) for i in x.split()]for x in _input[1:]]
x_list2 = x_list[:]

import math

count = 0
for x1 in x_list:
    for x2 in x_list2:
        dist = math.sqrt(sum((x1[i]-x2[i])**2 for i in range(d)))
        if int(dist) == 0:
            continue
        if dist.is_integer():
            count += 1

print(count//2)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_120
{
    class Program
    {

        static void Main(string[] args)
        {
            int[] dataArr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int a = dataArr[0];
            int b = dataArr[1];
            int c = dataArr[2];

            int ans1 = (b / a) * a;
            int ans2 = a * c;

            int ret = 0;
            if (ans1 >= ans2) ret = c;
            else ret = b / a;
            
            Console.WriteLine(ret);

        }
    }
}


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

struct range_minimum_query{

  // 管理したい元の配列のサイズ以上の2冪。

  int n;

  // セグメント木(完全二分木)を管理する一次元配列。

  vector<int> segtree;

  // minの単位元としてのINF。値は2^31-1。

  const int INF = INT_MAX;

  

  // @param sz 管理したい元の配列のサイズ

  // nをsz以上の2冪にし、セグメント木のサイズを2*n-1、値をINFに初期化する。

  range_minimum_query(int sz){

    for(n = 1; n<sz;) n <<= 1;

    segtree.assign(2*n-1,INF);
  }
    
   // 元の配列の[l,r)のminを求める。

  // @param l,r [l,r)が求めたいminの元の配列での範囲。

  // @param a,b [a,b)が現在見ている頂点の持つminの元の配列における範囲。

  // @param k   セグメント木の現在見ている頂点のindex

  // @return    セグメント木により、求められた[l,r)の最小値。

  // 上からDFSして、[l,r)内の頂点であれば自身の値を返し、そうでなければ単位元を返す。

  // このようにして帰ってきた値を全てminしたものが求めたいものである。

  // デフォルト引数にn(非staticなメンバ変数)を指定できないため、オーバーロードしている。

  int find(int l, int r){

    return find(l,r,0,n,0);

  }

  int find(int l, int r, int a, int b, int k){

    // [a,b)が[l,r)の外側なら、影響のない単位元INFを返す。

    if(b<=l || r<=a) return INF;

    

    // [a,b)が[l,r)の内側なら、その頂点は[l,r)内で最も大きい区間minを持つので、それを返す。

    else if(l<=a && b<=r) return segtree[k];

    

    // どちらでもなければ(解説スライドでの赤線を跨いでいる状態)、もっと細分されたものを確認する必要があるため、子を確認する。

    // 左側の子は[a,(a+b)/2)の区間minを持ち、indexは2*k+1

    // 右側の子は[(a+b)/2,b)の区間minを持ち、indexは2*k+2

    // この２つの[l,r)内の区間minのminを返してやれば良い。

    // 現在見ている頂点が葉に該当する場合は必ず上の２つの条件のどちらかで捕捉されるため考えなくて良い。

    else return min(find(l,r,a,(a+b)/2,2*k+1), find(l,r,(a+b)/2,b,2*k+2));

  }

  

  // 指定した頂点とその影響する範囲の値を更新する。  

  // @param i 書き換えたい値の元の配列におけるindex

  // @param x 更新後の値

  void update(int i, int x){

    // 解説スライドの通り、元の配列を持つ最下段の長さをn(2冪)とすると、

    // その上のセグメント木の構造を持つ部分は n/2 + n/4 + n/8 + .. + 1 = n-1(等比級数の公式より)

    // よって、元の配列を最初に更新したいので、元の配列部分のindexに修正するため、n-1を加える。

    i += n-1;

    

    // その頂点をxに更新する。

    segtree[i] = x;

    // 更新した最下段の情報の影響する範囲を更新する。

    // 具体的には更新した頂点の祖先全てが対象となる。

    while(i>0){

      // 親ノードへと移動

      i = (i-1)/2;

      // 自分の子２つを比較し、小さい方を得る。

      segtree[i] = min(segtree[2*i+1], segtree[2*i+2]);

    }

  }

};
    

int main(){
    int n,q,l,r,c;
    cin>>n>>q;
    
    
    range_minimum_query rmq(n);
    
    
    for(int i=0;i<q;i++){

        cin>>c;
        
        if(c==0){
            cin>>l>>r;
            rmq.update(l,r);
        }
        else{
            cin>>l>>r;
            cout << rmq.find(l,r+1) << endl;
        }
    }
}
        

        
        
        
        




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

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


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n, a, b;

	scanf("%d", &n);
	for (a = 1; a <= 9; a++)
		for (b = 1; b <= 9; b++)
			if (a * b == n) {
				printf("Yes\n");
				return 0;
			}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = Vec::with_capacity(n);
    let mut s: usize = 10_000;
    for _ in 0..n {
        a.push(iterator.next().unwrap().parse().unwrap());
        s = min(s, *a.last().unwrap());
    }

    let mut b = a.clone();
    let mut v: Vec<bool> = vec![false; n];

    b.sort();

    let mut t: Vec<usize> = vec![0; 10_001];
    for i in 0..n {
        t[b[i]] = i;
    }

    let mut ans = 0;
    for i in 0..n {
        if v[i] {
            continue;
        }

        let mut cur = i;
        let mut S: isize = 0;
        let mut m: isize = 10_000;
        let mut an = 0;
        loop {
            v[cur] = true;
            an += 1;
            let val = a[cur];
            m = min(m, val as isize);
            S += val as isize;
            cur = t[val];
            if v[cur] {
                break;
            }
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s as isize);
    }

    // let mut ans = 0;
    // for i in 0..n {
    //     let mut j = i;
    //     let mut min = a[i];
    //     for k in (i + 1)..n {
    //         if min > a[k] {
    //             j = k;
    //             min = a[k];
    //         }
    //     }
    //     if j != i {
    //         ans += a[i] + a[j];
    //         a.swap(i, j);
    //     }
    // }

    return ans.to_string();
}



Measured memory_bytes: 5056
#include<stdio.h>
long long result = 0;
long long int two[55] = {}, hum[55] = {}, ban[55] = {};
int a=0;
long long int hantei(long long int num, long long int eat) {
  if(a==1){return 0;}
	if (eat >= 3 && num == 0&&a==0) { result += 3; return 0; }
  
	if (eat == hum[num] + 1) {
		result += ban[num];
		result++;
		return 0;
	}

	if (eat >= hum[num]) {
		eat -= hum[num];
		result += ban[num];

		if (eat == 0) { return 0; }
		result++;
		eat--;

	}

	if (eat == 0) { return 0; }
  if (num == 0) {  a=1;}
	hantei(num - 1, eat - 1);
}
int main() {
	long long int n, x;

	two[0] = 1;
	hum[0] = 1;
	ban[0] = 1;
	for (int i = 1; i <= 50; i++) {
		two[i] = 2 * two[i - 1];
		hum[i] = 2 * hum[i - 1] + 3;
		ban[i] = 2 * ban[i - 1] + 1;
	}
	scanf("%lld%lld", &n, &x);
	
	
	hantei(n, x);
		printf("%lld",result);
}

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

int main(){
	int a[6], b[3];
	int x, y, z;
	for (int i = 0; i < 3; i++){
		scanf("%d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
		x = 3600 * a[0] + 60 * a[1] + a[2];
		y = 3600 * a[3] + 60 * a[4] + a[5];
		z = y - x;
		b[2] = z % 60;
		b[1] = (z - b[2]) % 3600 / 60;
		b[0] = (z - b[2] - b[1] * 60) / 3600;
		printf("%d %d %d\n", b[0], b[1], b[2]);
	}

	return 0;
}

Measured memory_bytes: 1028
n,k=map(int,input().split())
a=[int(input())for i in range(n)]
from itertools import accumulate
l=[0]+list(accumulate(a))
l=[j-k*i for i,j in enumerate(l)]

#座圧
a_to_i={a:i for i,a in enumerate(sorted(set(l)),1)}
b=[a_to_i[a]for a in l]

size=len(a_to_i)+2
bit=[0]*size

#x(index)の値にvを足す
#indexは1スタート
def bit_update(x,v):
    while x<size:
        bit[x]+=v
        x+=(x&-x) #区間の長さ

#bit_1 + bit_2 + … + bit_nをO(log(n))で求める
def bit_sum(n):
    s=0
    if n==0:return 0
    x=n
    while x>0:
        s+=bit[x]
        x-=(x&-x)
    return s

ans=0
for i in b:
    ans+=bit_sum(i)
    bit_update(i,1)
print(ans)

Measured memory_bytes: 53212
#include<bits/stdc++.h>
#define p_ pair<int,int>
#define mp_ make_pair
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int op[maxn],n;
char res[maxn];
void dfs(ll a,ll b,ll c,int dfn)
{
    //cout<<a<<" "<<b<<" "<<c<<" "<<dfn<<endl;
    if(a<0||b<0||c<0) return ;
    if(dfn==n+1){
        cout<<"Yes"<<endl;
        rep(i,1,n) cout<<res[i]<<endl;
        exit(0);
    }
    if(op[dfn]==1){
        if(a>b) {res[dfn]='B';dfs(a-1,b+1,c,dfn+1);}
        else if(a<b) {res[dfn]='A';dfs(a+1,b-1,c,dfn+1);}
        else
        {
            res[dfn]='A';dfs(a+1,b-1,c,dfn+1);
            res[dfn]='B';dfs(a-1,b+1,c,dfn+1);
        }
    }
    else if(op[dfn]==2){
        if(a>c) {res[dfn]='C';dfs(a-1,b,c+1,dfn+1);}
        else if(a<b) {res[dfn]='A';dfs(a+1,b,c-1,dfn+1);}
        else{
            res[dfn]='A';dfs(a+1,b,c-1,dfn+1);
            res[dfn]='C';dfs(a-1,b,c+1,dfn+1);
        }
    }
    else{
        if(b>c) {res[dfn]='C';dfs(a,b-1,c+1,dfn+1);}
        else if(b<c) {res[dfn]='B';dfs(a,b+1,c-1,dfn+1);}
        else
        {
            res[dfn]='B';dfs(a,b+1,c-1,dfn+1);
            res[dfn]='C';dfs(a,b-1,c+1,dfn+1);
        }
    }
}
int main()
{
    fastio();
    ll a,b,c;
    cin>>n>>a>>b>>c;
    string s;
    rep(i,1,n){
        cin>>s;
        if(s=="AB") op[i]=1;
        else if(s=="AC") op[i]=2;
        else op[i] = 3;
    }
    dfs(a,b,c,1);
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 11908
import collections

def main():
    N, Q = map(int, input().split())

    graph = collections.defaultdict(list)
    for i in range(N-1):
        a, b = map(int, input().split())
        graph[a].append(b)

    ops = collections.defaultdict(int)
    for i in range(Q):
        p, x = map(int, input().split())
        ops[p] += x

    vals = [0 for _ in range(N)]
    v = 0
    if 1 in ops: v = ops[1]
    cur = [[1, v]]

    while cur:
        temp = []
        for a, v in cur:
            vals[a-1] += v
            for b in graph[a]:
                temp.append([b, v+ops[b]])
        cur = temp

    print(' '.join(map(str, vals)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 135876