akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
	int a,n,i,b,j,ans=0,x=0,c;
	a=100000;
	cin>>n;
	for(i=1;i<=n;i++){
		a=a*1.05;
		b=a%1000;
		if(b==0){
		}else{
			for(x=1;x<=999;x++){
				a=a-1;
				c=a%1000;
				if(c==0)break;
			}
			a=a+1000;
		}
	}
	cout<<a<<endl;
	return 0;
}

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

int now, ans, N;
string S;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> N >> S;
	for(char c : S) {
		now += c == 'I' ? 1 : -1;
		ans = max(ans, now);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	int X = 1000001;
	vector<vector<int>> yakusuu(X,vector<int>());
	
	for(int i=X-1;i>=1;i--){
		for(int j=i;j<=X-1;j+=i){
			yakusuu[j].push_back(i);
		}
	}
	
	
	
	vector<int> sum(X,0);
	
	for(int i=0;i<N;i++){
		for(int j=0;j<yakusuu[A[i]].size();j++){
			sum[yakusuu[A[i]][j]] = mod(sum[yakusuu[A[i]][j]] + A[i]);
		}
	}
	
	vector<int> gyaku(X,0);
	for(int i=1;i<X;i++){
		gyaku[i] = mod(gyaku[i] + gyakugen(i));
		for(int j=2*i;j<X;j+=i){
			gyaku[j] = mod(gyaku[j] - gyaku[i]);
		}
	}
	
	int ans = 0;
	
	for(int i=1;i<X;i++){
		int a = mod(sum[i]*sum[i]);
		a = mod(a*gyaku[i]);
		ans = mod(ans + a);
	}
	
	for(int i=0;i<N;i++){
		ans = mod(ans - A[i]);
	}
	ans = mod(ans * gyakugen(2));
	
	cout<<ans<<endl;
		
		
	
	
	return 0;
}



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

int main() {
  int64_t x,y;
  cin >> x >> y;
  int64_t a,b;
  a=x%y;
  b=y-a;
  cout << min(a,b) << endl;

}


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

#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

using ll = long long;

inline void Main() {
  // code
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);
  sort(all(H));

  ll X = 0;
  rep(i, N-K) X += H.at(i);
  cout << X << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
H = list(map(int, input().split()))
preH =[]
for i in range(M):
    preH.append(list(map(int, input().split())))
ans = [True]*N

for i in range(M):
    A,B = preH[i]


    if(H[A-1]<=H[B-1]):
        ans[A-1] = False
    if(H[B-1]<=H[A-1]):
        ans[B-1] = False

print(ans.count(True))

Measured memory_bytes: 32032
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<cstdint>
//#include<>
using namespace std;

typedef int64_t i64;typedef int32_t i32;
typedef int16_t i16;typedef int8_t i8;
typedef uint64_t ui64;typedef uint32_t ui32;
typedef uint16_t ui16;typedef uint8_t ui8;

typedef i32 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define repeat_eq(i,j,k) for(int__ i=(j);i<=(k);i++)
#define all(v) begin(v),end(v)

const i64 INF=1L<<62;//=10E10

class Path{

  public:
  struct Edge{i64 to,cost;Edge(i64 to_,i64 cost_):to(to_),cost(cost_){;}};


  vector< vector<i64> > G;//隣接行列
  i64 V_num;
  
  Path(i64 n){G.resize(n,vector<i64>(n,INF));V_num=n;}

  void add_arc(i64 x,i64 y,i64 c)
  {
    G[x][y]=c;
  }

  vector< vector<i64> > WarshallFloyd(){
    int V=G.size();

    vector< vector<i64> > &dist=G;
    
    rep(i,V)dist[i][i]=0;

    rep(k,V)rep(i,V)rep(j,V){
      if(G[i][k]!=INF && G[k][j]!=INF)
	dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    }
    //negative loop check
    rep(i,V)if(dist[i][i]<0)return vector<vector<i64> >(0);
    return dist;
  }
  
};



int main()
{
  i64 v,e;cin>>v>>e;
  Path Graph(v);
  rep(i,e){
    i64 s,t,d;cin>>s>>t>>d;
    Graph.add_arc(s,t,d);
    //Graph.add_arc(t,s,d);
  }
  vector<vector<i64> > dist=Graph.WarshallFloyd();
  if(dist.size()==0)cout<<"NEGATIVE CYCLE"<<endl;
  else{
    rep(i,v){
      rep(j,v){
	if(dist[i][j]==INF)cout<<"INF";
	else cout<<dist[i][j];

	if(j!=v-1)cout<<" ";
      }
      cout<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1384
str = []
while True:
    s = input()
    if s == '-':
        break
    else:
        m = int(input())
        h = [int(input()) for i in range(m)]
        for i in range(len(h)):
            temp = s[:h[i]]
            temp2 = s[h[i]:]
            s = temp2 + temp
        str.append(s)

for i in str:
    print(i)


Measured memory_bytes: 5604
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int i,j,k;
	int a,b,c,d;
	char ch[2]={'+','-'};
	cin>>a;
	d=a%10;
	a/=10;
	c=a%10;
	a/=10;
	b=a%10;
	a/=10;
	int f,fl=0;
	FOR(i,0,2){
		FOR(j,0,2){
			FOR(k,0,2){
				if(fl==0){
				f=a;
				if(i==0){
					f+=b;
				}else{
					f-=b;
				}
				if(j==0){
					f+=c;
				}else{
					f-=c;
				}
				if(k==0){
					f+=d;
				}else{
					f-=d;
				}
					if(f==7){
						fl=1;
						cout<<a<<ch[i]<<b<<ch[j]<<c<<ch[k]<<d<<"=7"<<endl;
					}
				}
			}
		}
	}
	
	
	
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long M=1e9+7;
int solve(){
	int s;
	cin>>s;
	long long dp[s+5];
	long long sum=0; //upto i-3;
	sum=1;
	dp[0]=1;
	dp[1]=0;
	dp[2]=0;
	for(int i=3;i<=s;i++){
		dp[i]=sum;
		sum=(sum+dp[i-2])%M;
	}
	return dp[s];
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<solve()<<"\n";
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
  long long h, w, n, t;
  std::cin >> h >> w >> n;
  vi a(n);
  // std::vector<pii> a;
  // pii tmp;
  vvi c(h, vector<int>(w, 0));
  rep(i,n) {
    // std::cin >> t;
    // tmp=make_pair(i,t);
    std::cin >> a[i];
  }
  // rep(i,n) std::cout << a[i] << std::endl;
  int itr=0;
  rep(i,h){
    if(i%2==0) rep(j,w){
      c[i][j]=itr+1;
      a[itr]--;
      if(a[itr]==0) itr++;
    }else rep(j,w){
      c[i][w-j-1]=itr+1;
      a[itr]--;
      if(a[itr]==0) itr++;
    }
  }
  rep(i,h){
    rep(j,w){
      std::cout << c[i][j] ;
      if(w!=j-1) std::cout << " ";
    }
    std::cout << std::endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,X,count=0;
    cin>>N>>X;
    vector<int> D(N+1,0);
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        D[i+1]=x+D[i];
    }
    for(int i=0;i<=N;i++){
        if(D[i]<=X)
            count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using std::cin;
using std::cout;
int d, t, s;
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //cout << std::setiosflags(std::ios::fixed) << std::setprecision(3);
    cin >> d >> t >> s;
    s = t * s;
    if (d <= s) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i) >> b.at(i);
    }
    sort(all(a));
    sort(all(b), greater<ll>());
    ll ans = 0;
    if(n%2 == 1){
        ans = b.at(n - (n+1)/2) - a.at((n-1)/2) + 1;
    }else{
        ll ind1 = n/2-1;
        ll ind2 = n/2;
        ans = (b.at(ind1) + b.at(ind2)) - (a.at(ind1) + a.at(ind2)) + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,l[15];
int s;
int main(void){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	sort(l,l+n);
	for(int i=0;i<n-1;i++){
		s=s+l[i];
	}
	if(l[n-1]<s){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
}


Measured memory_bytes: 256
from collections import Counter

def is_straight(game):
    if 1 in game:
        if game == [1, 2, 3, 4, 5] or game == [1, 10, 11, 12, 13]:
            return True
        else:
            return False
    else:
        for i in range(len(game)-1):
            if game[i+1] != game[i]+1:
                return False
            return True

while True:
    try: start = input()
    except: break

    game = list(map(int, start.split(',')))
    game.sort()
    result = Counter(game)
    values, counts = zip(*result.most_common())

    if counts[0] == 2:
        if len(counts) == 4:
            print('one pair')
        else:
            print('two pair')
    elif counts[0] == 3:
        if len(counts) == 3:
            print('three card')
        else:
            print('full house')
    elif counts[0] == 4:
        print('four card')
    elif is_straight(game):
        print('straight')
    else:
        print('null')




Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pow2(x) (ll(1)<<x)
#define pb push_back
#define mp make_pair
#define w(t) int t;scanf("%d",&t);while(t--)
#define For(i,n) for(int i=0;i<n;i++)
#define scan(n) int n;scanf("%d", &n);
using namespace std;
const int sz = 1e5 + 7;
const int INF = 1e9;
int n;
vector<int> v(sz);
int mn;
int solve(int i=0)
{
    if(i>=n-1)
        return 0;
    if(i < n - 2)
        return mn = min(solve(i + 1) + abs(v[i] - v[i+1]), solve(i+2) + abs(v[i] - v[i+2]));
    else if(i==n-2)
        return abs(v[i] - v[i+1]);
}
int main()
{
    scan(n);
    For(i,n)
        scanf("%d", &v[i]);
    vector<int> ans(n,INF);
    ans[0] = 0;
    for(int i=1;i<n;i++)
    {
        ans[i] = min(ans[i],ans[i-1] + abs(v[i] - v[i-1]));
        if(i>=2)
            ans[i] = min(ans[i], ans[i-2] + abs(v[i] - v[i-2]));
//        cout<<i<<" "<<ans[i]<<endl;
    }
    cout<<ans[n-1];
}


Measured memory_bytes: 4056
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	ll n,m;
	cin>>n>>m;
	n-=2;m-=2;
	if(n<0)n=1;
	if(m<0)m=1;
	cout<<n*m;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        if (a + b +c >= 22) {
            System.out.println("bust");
        }
        else {
            System.out.println("win");
        }
    }
}


Measured memory_bytes: 22740
n = int(input())
ls = list(map(int,input().split()))
check = True
for i in range(n-1,0,-1):
        if ls[i] < ls[i-1]:
                ls[i-1] -= 1
        if ls[i] < ls[i-1]:
                check = False
if check:
        print('Yes')
else:
        print('No')

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

bool revp2(const pair<ll,ll>&a,const pair<ll,ll>&b){return a.first>b.first;}
bool revp3(const pair<ll,ll>&a,const pair<ll,ll>&b){if(a.first==b.first)return a.second<b.second;
return a.first>b.first;}

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll n,a,b;
    cin>>n;vector<pair<ll,ll>>v;
    ll l1[n+1],l2[n+1];
    for(int i=1;i<=n;i++){cin>>l1[i];v.push_back({l1[i],i});}
    sort(v.begin(),v.end());
    map<ll,ll>m;
    for(int i=1;i<=n;i++){
        if(i<=(n/2))m[v[i-1].second]=v[(n/2)].first;
        else m[v[i-1].second]=v[(n/2)-1].first;
    }
    for(int i=1;i<=n;i++){
        cout<<m[i]<<endl;
    }
}


Measured memory_bytes: 20176
#include <stdio.h>

unsigned int a[21];
unsigned int b[21];
unsigned int c[21];

int main(void)
{
    unsigned int n;
    unsigned int i;
    unsigned int ret = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n; i++) scanf("%d", &b[i]);
    for (i = 0; i < (n - 1 ); i++) scanf("%d", &c[i]);

    for (i = 0; i < n; i++) {
        ret += b[a[i] - 1];
        if ((i < (n - 1 )) && (a[i + 1] == (a[i] + 1))) {
            ret += c[a[i] - 1];
        }
    }

    printf("%d", ret);

    return 0;
}

Measured memory_bytes: 128
W,H,N=map(int,input().split())
maxX=W
maxY=H
minX=0
minY=0

for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    minX=max(minX,x)
  elif a==2:
    maxX=min(maxX,x)
  elif a==3:
    minY=max(minY,y)
  else:
    maxY=min(maxY,y)

print(max(maxX-minX,0)*max(maxY-minY,0))

Measured memory_bytes: 3064
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll n;
ll m;
vl u;
vl v;
vl s;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> n;
    cin >> m;
    u = vl(m);
    v = vl(m);
    s = vl(m);
    for(int i = 0; i < m; ++i){
        cin >> u[i];
        cin >> v[i];
        cin >> s[i];
    }
    solve();
}

// 2 <= n <= 10^5
// 1 <= m <= 10^5
// 1 <= u_i < v_i <= n
// 2 <= s_i <= 10^9
// i!= j のとき u_i != u_j  または v_i != v_j
// グラフは連結
// 入力はすべて整数

template<typename T>
struct edge{
    int src,to;
    T cost;
    edge(int from,int to,T cost):src(src),to(to),cost(cost){}
    edge(int to,T cost):edge(-1,to,cost){}
    operator int()const{return to;}
};

template<typename T>
using Edges=vector<edge<T>>;

template<typename T>
using Graph=vector<Edges<T>>;

void ng(){cout<<0<<endl;exit(0);}

Graph<ll> g;
vvl cons(2);
void dfs(ll x,ll d=0){
    for(auto &e:g[x]){
        ll tmp_diff=e.cost-cons[d%2][x];
        if(cons[1-d%2][e.to]!=LINF){
            if(cons[1-d%2][e.to]!=tmp_diff)ng();
        }else{
            cons[1-d%2][e.to]=tmp_diff;
            dfs(e.to,d+1);
        }
    }
}

// ll n, ll m, vl u, vl v, vl s
// 条件を満たす正の整数の書き込み方が何通りあるか出力せよ。
void solve(){
    g.resize(n);
    rep(i,m){
        g[u[i]-1].emplace_back(v[i]-1,s[i]);
        g[v[i]-1].emplace_back(u[i]-1,s[i]);
    }

    rep(i,2)cons[i].assign(n,LINF);
    cons[0][0]=0;
    dfs(0);

    ll mx=LINF;
    ll mi=0;
    ll t2=LINF;
    rep(i,n){
        if(cons[0][i]!=LINF&&cons[1][i]!=LINF){
            ll tmp_t2=cons[1][i]-cons[0][i];
            if(tmp_t2%2||tmp_t2<=0)ng();
            if(t2!=LINF){
                if(tmp_t2!=t2)ng();
            }else{
                t2=tmp_t2;
            }
        }
        if(cons[1][i]!=LINF)chmin(mx,cons[1][i]);
        if(cons[0][i]!=LINF)chmax(mi,-cons[0][i]);
    }
    cout<<(t2==LINF?max(0LL,mx-mi-1):(mi<t2/2&&t2/2<mx?1:0))<<endl;
}


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

int main(){
    int N, S;
    cin >> N >> S;
    int ans = 0;
    int ggg = 0;
    for (int i = 0; i <= N; i++)
    {
        ans = i * 2 + (N - i) * 4;
        if(ans==S){
            cout << "Yes";
            i = 1000;
            ggg = 1;
        }
    }
    if (ggg==0)
    {
        cout << "No";
    }
    
    
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> Ls(N);
    REP(n, N) cin >> Ls[n];
    sort(ALL(Ls));
    ll ans = 0;
    REP(i, N - 2) {
        FOR(j, i + 1, N - 1) {
            auto a = Ls[i];
            auto b = Ls[j];
            // jより右にありc < a + bであるcの数を数える
            auto it = lower_bound(ALL(Ls), a + b);
            auto idx = it - Ls.begin();
            auto tmp = max(0LL, (ll)idx - j - 1);
            // cerr << "a, b, idx, tmp = " << a << " " << b << " " << idx << " " << tmp << endl;
            ans += tmp;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] w = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            total += w[i];
        }

        int s1 = 0;
        int s2;
        int ans = total;
        for (int i = 0; i < n; i++) {
            s1 += w[i];
            s2 = total - s1;
            int candidate = Math.abs(s1 - s2);
            if (candidate < ans) {
                ans = candidate;
            }
        }
        System.out.println(ans);

        sc.close();

    }

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	string s;
	cin >> s;
	unordered_set<char> st;

	int n = s.size();
	for (char c : s)
		st.insert(c);
	if (n == (int)st.size())
		cout << "yes" << endl;
	else
		cout << "no" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextInt();
		}
		int allXor = A[0];
		for(int i = 1; i < N; ++i){
			allXor ^= A[i];
		}
		StringBuilder sb = new StringBuilder();
		for(int a : A){
			if(sb.length() > 0){
				sb.append(' ');
			}
			sb.append(a ^ allXor);
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 60880
// panasonic2020_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll a, b, c;
    cin >> a >> b >> c;

    if ((c - a - b) < 0){
        print("No");
    } else {
        if (4 * a * b < (c - a - b) * (c - a - b)){
            print("Yes");
        } else {
            print("No");
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
int main() {
    int n[26] = {};
    char s;
    while (cin >> s){
        s = tolower(s);
        if (isalpha(s)){
            n[s - 'a']++;
        }
    }
    for (int i=0; i<26; i++){
        printf("%c : %d\n", i+'a', n[i]);
    }
    return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long ans = 1;
		int n = in.nextInt();
		int k = in.nextInt();
		ans = k;
		for (int i = 1; i < n; i++) {
			ans *= (k - 1);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 9684
#include <iostream>
#include <set>
#include <string>

using namespace std;

typedef set<string> set_t;
set_t a;
int n;
string s;

int main()
{
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> s;
        if(s=="insert")
        {
            cin >> s;
            a.insert(s);
        }
        else if(s=="find")
        {
            cin >> s;
            if(a.count(s)==0)
            {
                cout << "no" << endl;
            }
            else
            {
                cout << "yes" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 32572
N = int(input())

biggest = 0
secandBiggest = 0
A = [0 for i in range(N)]
for i in range(N):
  A[i] = int(input())
  if(biggest <= A[i]):
    secandBiggest = biggest
    biggest = A[i]
  elif(secandBiggest <= A[i]):
    secandBiggest = A[i]
    
for i in range(N):
  if(A[i] == biggest):
    print(secandBiggest)
  else:
    print(biggest)

Measured memory_bytes: 12528
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int H,W,h,w,ans=0;
    cin >> H >> W >> h >> w;


    cout << (H-h)*(W-w) << endl;
    return 0;
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007ll
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;
li dp[10010];

li key_cost[1010];
vector<li> open[1010];

int main() {
    cin >> n >> m;
    rep(i, bit(n)) {
        dp[i] = INF;
    }

    rep(i, m) {
        cin >> key_cost[i];
        li num;
        cin >> num;
        rep(j, num) {
            li c;
            cin >> c;
            c--;
            open[i].pb(c);
        }
    }

    dp[0] = 0;
    rep(i, bit(n) - 1) {
        rep(j, m) {
            bitset<15> bs(i);
            for (auto && k : open[j]) {
                bs[k] = 1;
            }
            li next = bs.to_ulong();
            dp[next] = min(dp[next], dp[i] + key_cost[j]);
        }
    }

    li res = dp[bit(n) - 1];
    cout << (res == INF ? -1 : res) << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define flashio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
typedef long long ll;
int main()
{
	flashio;
	int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 1000; i++) {
        if(a == floor(i*0.08) && b == floor(i*0.1)) {
            cout << i ;
            return 0;
        }
    }
	cout << -1;
	return 0;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int n,m,x,y,ans,dp[100005];
vector<int> g[100005];
bool visited[100005];

void dfs(int x){
  visited[x]=true;
 // cout << x << " ";
  for(int u:g[x]){
    if(!visited[u]){
        dfs(u);
    }
    dp[x]=max(dp[x],1+dp[u]);
  }
}

int main(){
  cin >> n >> m;
  for(int i=0;i<m;++i){
    cin >> x >> y;
    g[x].push_back(y);
  }
  for(int i=1;i<=n;++i){
    if(!visited[i]){
        dfs(i);
    }
  //  cout << endl;
  }
  for(int i=1;i<=n;++i){
    ans=max(ans,dp[i]);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 8192
import java.util.*;
import java.io.*;

public class Main {

  private static void solve() {
    int n = nextInt();
    int a = nextInt();
    int b = nextInt();

    int[] p = new int[n];

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

    int ac = 0, bc = 0, cc = 0;
    for (int i = 0; i < n; i++) {
      if (p[i] <= a) {
        ac++;
      } else if (p[i] >= a + 1 && p[i] <= b) {
        bc++;
      } else {
        cc++;
      }
    }

    out.println(Math.min(ac, Math.min(bc, cc)));
  }

  private static void run() {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);

    solve();

    out.close();
  }

  private static StringTokenizer st;
  private static BufferedReader br;
  private static PrintWriter out;

  private static String next() {
    while (st == null || !st.hasMoreElements()) {
      String s;
      try {
        s = br.readLine();
      } catch (IOException e) {
        return null;
      }
      st = new StringTokenizer(s);
    }
    return st.nextToken();
  }

  private static int nextInt() {
    return Integer.parseInt(next());
  }

  private static long nextLong() {
    return Long.parseLong(next());
  }

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

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == '('){
      ans++;
    }
    if (S[i] == ')'){
      ans--;
    }
    if (S[i] == '*'){
      cout << ans << endl;
    }
  }
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;

	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	sort(begin(a), end(a), greater<int>());

	int s = a.front();
	int min = a.front() - a.back();
	int k = n - 1;
	for (int i = 1; i < n; i++) {
		int d = abs(a[i] - s / 2);
		if (d < min) {
			min = d;
			k = a[i];
		}
	}

	printf("%d %d\n", s, k);
	return 0;
}

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

int main(void)
{
	double a,b,x;

	cin >> a >> b >> x;

	double tmp,arg,ans=0;

	const double pi=acos(-1);

	if(x>a*a*b/2.0)
	{
		tmp=a*a*a/(2*a*a*b-2*x);

		arg=atan(tmp);

		ans=90.0-arg*180/pi;
	}

	else
	{
		tmp=2*x/(a*b*b);

		arg=atan(tmp);

		ans=90.0-arg*180/pi;

	}

	cout << fixed << setprecision(10) << ans << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int n,x;
scanf("%d%d",&n,&x);
int i,a[105],sum=0;
for(i=1;i<=n;i++)
{
    scanf("%d",&a[i]);
    sum=sum+a[i];
}

sum=x-sum;
sort(&a[1],&a[1+n]);
int k=sum/a[1];
printf("%d",k+n);


return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
vector<pii> G[100005];
ll d[100005];
bool vis[100005];
bool dfs(int v){
	vis[v]=true;
	rep(k,G[v].size()){
		int u=G[v][k].first;
		if(!vis[u]){
			d[u]=d[v]+G[v][k].second;
			if(!dfs(u))return false;
		}else if(d[u]!=d[v]+G[v][k].second)return false;
	}
	return true;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(k,m){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		G[u].push_back(MP(v,w));
		G[v].push_back(MP(u,-w));
	}
	rep1(k,n)if(!vis[k]&&!dfs(k)){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;
ll gcd(ll a, ll b)
{
    if(b == 0){
        return a;
    }
    return gcd(b,a%b);
}

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

int main()
{
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll num = b-a+1;
    a--;
    ll sub1 = b/c-a/c, sub2 = b/d - a/d;
    ll add = b/lcm(c,d) - a/lcm(c,d);
    cout << num - sub1 - sub2 + add;
}


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

// ====================================================================
template <int MOD_> struct modnum {
    static constexpr int MOD = MOD_;
    static_assert(MOD_ > 0, "MOD must be positive"); 
private:
    using ll = long long;
    int v;
    static int minv(int a, int m) {
        a %= m;
        assert(a);
        return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
    }

public:
    modnum() : v(0) {}
    modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
    explicit operator int() const { return v; }
    friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
    friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
    friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
    friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; } 
    modnum inv() const {
        modnum res;
        res.v = minv(v, MOD);
        return res;
    }
    friend modnum inv(const modnum& m) { return m.inv(); }
    modnum neg() const {
        modnum res;
        res.v = v ? MOD-v : 0;
        return res;
    }
    friend modnum neg(const modnum& m) { return m.neg(); }
    modnum operator- () const {
        return neg();
    }
    modnum operator+ () const {
        return modnum(*this);
    }
    modnum& operator ++ () {
        v ++;
        if (v == MOD) v = 0;
        return *this;
    }
    modnum& operator -- () {
        if (v == 0) v = MOD;
        v --;
        return *this;
    }
    modnum& operator += (const modnum& o) {
        v += o.v;
        if (v >= MOD) v -= MOD;
        return *this;
    }
    modnum& operator -= (const modnum& o) {
        v -= o.v;
        if (v < 0) v += MOD;
        return *this;
    }
    modnum& operator *= (const modnum& o) {
        v = int(ll(v) * ll(o.v) % MOD);
        return *this;
    }
    modnum& operator /= (const modnum& o) {
        return *this *= o.inv();
    }

    friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
    friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
    friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
    friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
    friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
    friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using Mint = modnum<1000000007>;
// ====================================================================

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n;
    std::cin >> n;

    std::vector<int> a(n + 1);
    std::vector<Mint> sum(n + 1);

    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }

    Mint ans = 0;

    for (int i = 1; i < n; i++) {
        ans += (sum[n] - sum[i]) * a[i];
    }

    std::cout << ans;

    return 0;
}



Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
int main(){
 int a,b,c,d=10;
 cin>>a>>b;
 c=b;
 while(c>9){
   c/=10;
   d*=10;
 }
 b+=a*d;
 for(int i=1;i<=1000;i++){
   if(b/i==i && b%i==0){
     cout<<"Yes"<<endl;
     return(0);
   }
 }
 cout<<"No"<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
struct Segtree{
    int siz=1;
    vector<int>dat;
    Segtree(int n){
        while(siz<n)siz*=2;
        dat.resize(siz*2-1,0);
    }
    void update(int k,int x){
        k+=siz-1;
        dat[k]=x;
        while(k>0){
            k=(k-1)/2;
            dat[k]=max(dat[k*2+1],dat[k*2+2]);
        }
    }
    int query(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=siz;
        if(r<=a||b<=l)return -INF;
        if(a<=l&&r<=b)return dat[k];
        int m=(l+r)/2;
        int vl=query(a,b,k*2+1,l,m);
        int vr=query(a,b,k*2+2,m,r);
        return max(vl,vr);
    }
};
int n,h[200010],a[200010],N;
map<int,int>mp;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>h[i];
        mp[h[i]]++;
    }
    rep(i,n)cin>>a[i];
    for(P p:mp){
        mp[p.fi]=N;
        N++;
    }
    rep(i,n)h[i]=mp[h[i]];
    Segtree seg(n+1);
    rep(i,n){
        if(seg.query(h[i]+1,h[i]+2)<seg.query(0,h[i]+1)+a[i]){
            seg.update(h[i]+1,seg.query(0,h[i]+1)+a[i]);
        }
    }
    int ans=0;
    rep(i,n+1)chmax(ans,seg.query(i,i+1));
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }

  bool visited[n];
  for(int i = 0; i < n; i++) {
    visited[i] = false;
  }
  visited[0] = true;
  int next = a[0];
  int count = 0;

  while(visited[next] == false) {
    visited[next] = true;
    count++;
    if(next == 1) {
      cout << count << endl;
      return 0;
    }
    next = a[next];
  }
  cout << "-1" << endl;
}

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

using namespace std;

#define DIM 100007

const long long MODULO = 1000000007;

long long n,k,i,j,res;
long long p[DIM], sum[DIM], f[3][DIM];
vector<int> a[DIM];

void dfs(int v, int par) {
    f[0][v] = f[1][v] = 1;
    for(auto to : a[v]) {
        if(to == par) continue;
        dfs(to,v);
        f[0][v] = (f[0][v] * f[1][to]) % MODULO;
        f[1][v] = f[1][v] * (f[0][to] + f[1][to]) % MODULO;
    }
}


int main() {
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int v1,v2;
    for(int i = 1; i < n; i++) {
        cin >> v1 >> v2;
        a[v1].push_back(v2);
        a[v2].push_back(v1);
    }
    dfs(1,0);
    cout<<(f[0][1]+f[1][1]) % MODULO<<endl;

    return 0;
}


Measured memory_bytes: 14464
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int d, g, p[101], c[101];

int main()
{
    cin >> d >> g;

    for (int i = 0; i < d; i++)
    {
        cin >> p[i] >> c[i];
    }

    int n = d, res = 1000000;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        int score = 0, tmp = 0, m = 0, index = -1;
        //ビットごとの処理
        for (int i = 0; i < n; i++)
        {
            if (bit & (1 << i))
            { // i が bit に入るかどうか
                score += 100 * (i + 1) * p[i] + c[i];
                tmp += p[i];
            }
            else
            {
                index = i;
            }
        }

        if (score < g && index != -1)
        {
            int a = (g - score);
            int b = (100 * (index + 1));
            int c = (a + (b - 1)) / b;

            if (c < p[index])
            {
                score += c * b;
                tmp += c;
            }
        }

        if (score >= g)
        {
            res = min(res, tmp);
        }
    }

    cout << res;
}

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

int main() {
    char b;
    cin >> b;
    char ans;
    if(b == 'A')ans = 'T';
    if(b == 'T')ans = 'A';
    if(b == 'C')ans = 'G';
    if(b == 'G')ans = 'C';
    cout << ans << endl;
}


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

using namespace std;

char s[10][10];
int ans[100][100];

long long sum = 0;
int main() {
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 1; i <= h; i++) {
        scanf("%s", s[i] + 1);
    }
    for (int l = 0; l < (1 << w) - 1; l++) {
        ans[l][0] = 1;
        for (int i = 1; i <= h; i++) {
            int cnt = 0;
            for (int j = 1; j <= w; j++) {
                if ((l & (1 << (j - 1))) == 0 && s[i][j] == '#') {
                    cnt++;
                }
            }
            for (int j = k - cnt; j >= 0; j--) {
                ans[l][j + cnt] = ans[l][j + cnt] + ans[l][j];
            }
        }
        sum += ans[l][k];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3700
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var itemList = new List<int>();
            itemList.Add(int.Parse(Console.ReadLine()));
            itemList.Add(int.Parse(Console.ReadLine()));
            itemList.Add(int.Parse(Console.ReadLine()));
            itemList.Add(int.Parse(Console.ReadLine()));
            itemList.Add(int.Parse(Console.ReadLine()));
            var canCommunicate = int.Parse(Console.ReadLine());
            var distance = itemList.Max() - itemList.Min();

            string answer;
            if (canCommunicate < distance)
            {
                answer = ":(";
            }
            else
            {
                answer = "Yay!";
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>

int main(void)
{
    int a;
    int b;
    int c;
    int tmp;

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

    if ( b < a ) {
        tmp = b;
        b = a;
        a = tmp;
    }

    if ( c < b ) {
        tmp = c;
        c = b;
        b = tmp;
    }

    if ( b < a ) {
        tmp = b;
        b = a;
        a = tmp;
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}


Measured memory_bytes: 2120
#include <iostream>
 
using namespace std;
 
int main()
{
 int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int cnt = 0;
  for(int i= 0; i <= A; i++)
  {
     for(int j= 0; j <= B; j++)
     {
        for(int k= 0; k <= C; k++)
        {
          cnt += (i*500) + (j*100) + (k*50) == X;
        }
     }
  }
  
  cout << cnt << endl;
}

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

int n;

void f(string s, int sl){
    if (s.size() == n){
        cout << s << '\n';
        return;
    }
    for (int i = 0; i < sl; i++){
        f(s+(char)('a'+i), sl);
    }
    f(s+(char)('a'+sl), sl+1);
}

int main(){

    cin >> n;
    f("a", 1);

}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

vector<vector<int>> id;

int to_id(int x, int y) {
    if (x > y) swap(x, y);
    return id[x][y];
}

int main() {
    int n; cin >> n;
    vector<int> in; //入次数
    vector<vector<int>> a;
    a.resize(n, vector<int>(n - 1));
    id.resize(n, vector<int>(n));
    int k = 0;
    REP(i, n-1) {
        FOR(j,i+1, n) {
            id[i][j] = k++;
        }
    }
    in.resize(k,0);
    vector<vector<int>> G(k);
    REP(i, n) {
        REP(j, n - 1) {
            cin >> a[i][j];
            a[i][j]--;
        }
        REP(j, n - 2) {
            G[to_id(i, a[i][j])].push_back(to_id(i, a[i][j + 1]));
            in[to_id(i, a[i][j + 1])]++;
        }
    }
    int ans = 0;
    stack<int> sta;
    vector<int> cost(k,1);
    int cnt = 0;
    REP(i, k) {
        if (in[i] == 0) {
            sta.push(i);
            cnt++;
        }
    }
    while (!sta.empty()) {
        int p = sta.top(); sta.pop();
        for (int v : G[p]) {
            in[v]--;
            cost[v] = max(cost[v], cost[p] + 1);
            if (in[v] == 0) {
                sta.push(v);
                cnt++;
            }
        }
    }
    if (cnt == k) {
        REP(i, k) {
            ans = max(ans, cost[i]);
        }
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 39424