akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

ll gcd(ll a, ll b)
{
    if(b == 0){
        return a;
    }
    return gcd(b,a%b);
}

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                ll tmp = gcd(i,j);
                tmp = gcd(tmp,k);
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main (){
 
  string s;
  cin >> s;
  int count=0, ans=0;
  
  for(int i=0; i<s.size(); i++){
    
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
    	count++;
      if(count > ans) ans=count;
    }
    else count=0;    
  }
  cout << ans << endl;
  
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool debug = 1;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

#define MAX 100010
int N, D[MAX];

const ll mod = 998244353LL;

ll modmultiply(ll a,ll b,ll c) {
    ll x = 0,y = a%c; 
    while(b > 0) {
        if(b%2 == 1) x = (x+y)%c; 
        y = (y*2)%c;
        b /= 2; 
     }
    return x%c;
  }


ll modpow(ll x, ll y, ll mod) {
  ll ret = 1;// ret = x^y%mod;
  while(y) {
    if(y&1)
      //ret = (ret*x)%mod;
      ret = modmultiply(ret, x, mod);
    //x = (x*x)%mod;
    x = modmultiply(x, x, mod);
    y >>= 1;
  }
  return ret;
}


void compute() {
  if( D[0] != 0 ) {
    puts("0");
    return;
  }
  REP(i,1,N) {
    if( D[i] == 0 ) {
      puts("0");
      return;
    }
  }
  int maxi = 0;
  rep(i,N) {
    maxi = max(maxi,D[i]);
  }
  map<ll,ll> mp;
  rep(i,N) ++mp[D[i]];
  rep(i,maxi+1) {
    if( mp.count(i) == 0 ) {
      puts("0");
      return;
    }
  }
  ll ans = 1LL;
  REP(i,2,maxi+1) {
    ll pre = mp[i-1];
    ans = ( ans * modpow(pre,mp[i],mod) ) % mod;
  }
  cout << ans << endl;
}

int main() {
  cin >> N;
  rep(i,N) cin >> D[i];
  compute();
  return 0;
}


Measured memory_bytes: 6912
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
int A[100010];
int main(){
  cin>>N;
  rep(i,N) cin>>A[i];
  int f=0,res=1;
  rep(i,N-1){
    if(A[i]==A[i+1]) continue;
    else if(A[i]<A[i+1]){
      if(f==1) continue;
      else if(f==0) f=1;
      else{
	res++;
	f=0;
      }
    }
    else{
      if(f==1){
	res++;
	f=0;
      }
      else if(f==0) f=-1;
      else continue;
    }
  }
  prin(res);
  return 0;
}


Measured memory_bytes: 640
n, t = map(int, input().split())
time = list(map(int, input().split()))

dif = [0] * (n - 1)

for i in range(n - 1):
    dif[i] = time[i + 1] - time[i]

ans = 0
for i in range(n - 1):
    tar = dif[i]
    if (tar < t):
        ans += tar
    else:
        ans += t

ans += t
print(ans)


Measured memory_bytes: 25200
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,ans=0,p; cin>>n;
    vector<int> h(n,0); 
    rep(i,n) cin>>h[i];
    for(int i=1;i<=100;i++){
        p=0;
        rep(j,n){
            if(p<i && h[j]>=i) ans++;
            p=h[j];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args)
			throws java.io.IOException{
		 BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
		String n=d.readLine();
		System.out.println(fact(Integer.parseInt(n)));
		// TODO 自動生成されたメソッド・スタブ
		
	}
	
	public static long fact(int n){
		if(n==0) return 1;
		return n*fact(n-1);
		
	}

}

Measured memory_bytes: 9364
#include<bits/stdc++.h>
#define N 200005
using namespace std;const int P=1e9+7;
int two[N],d[N],size[N],id[N],be[N],mul[N];
vector<int>a[N],F[N];int n,tot;
multiset<pair<int,int> >G[N];
void up(int &x){if (x>=P) x-=P;}
void Rebuild(int x,int st=0){
	if (!G[x].size()) return;
	int cnt=0,sum=1;
  auto it=G[x].end();
  for (int i=F[x].size()-1;i>=st;i--){
  	for (;it!=G[x].begin();){
  		auto New=it;--New;
  		if ((*New).first<i) break;
  		sum=1ll*sum*(*New).second%P;it=New;cnt++;
  	}
  	F[x][i]=1ll*F[x][i]*sum%P;
  }
	while (cnt--)
	  G[x].erase(--G[x].end());
	if (st>0&&sum>1)
	  G[x].insert(make_pair(st-1,sum));
}
int cmp(const int &A,const int &B){return d[A]>d[B];}
void DFS(int x,int fa){
	d[x]=0;size[x]=1;
	for (int i=0;i<a[x].size();i++)
	  if (a[x][i]!=fa){
	    DFS(a[x][i],x);
			size[x]+=size[a[x][i]];
			d[x]=max(d[x],d[a[x][i]]+1);
		}
	if (d[x]==0){
		F[be[x]=++tot].push_back(1);
		return;
	}
  int m=0;
	for (int i=0;i<a[x].size();i++)
	  if (a[x][i]!=fa)
	    id[++m]=a[x][i];
	sort(id+1,id+m+1,cmp);
	be[x]=be[id[1]];
	for (int i=2;i<=m;i++)
	  Rebuild(be[id[i]]);
	if (m>1) 
	  Rebuild(be[id[1]],d[id[1]]-d[id[2]]);
	mul[m+1]=1;
	for (int i=m;i;i--)
	  mul[i]=1ll*mul[i+1]*two[size[id[i]]]%P;
  int p=0;
  for (int k=m>=2?d[id[2]]:-1;k>=0;k--){
  	//deep=k
  	int A=2,B=0,i=1;
  	for (int y;i<=m&&F[be[id[i]]].size()>k;i++){
  		y=be[id[i]];
  		int newf=F[y][F[y].size()-k-1];
  		int newg=two[size[id[i]]]-newf;up(newg+=P);
  		B=1ll*B*newg%P;
  		up(B+=1ll*A*newf%P);
  		A=1ll*A*newg%P;
  	}
  	F[be[x]][d[x]-k-1]=1ll*B*mul[i]%P;
  }
  if (m==1)
  	G[be[x]].insert(make_pair(d[id[1]],2));
  else if (d[id[1]]>d[id[2]]) 
	  G[be[x]].insert(make_pair(d[id[1]]-d[id[2]]-1,2ll*mul[2]%P));
	  
  F[be[x]].push_back(two[size[x]-1]);
  //Rebuild(be[x]);
  /*printf("%d\n",x);
	for (int i=F[be[x]].size()-1;i>=0;i--)
	  printf("%d ",F[be[x]][i]);
	puts("");*/
}
/*F
	for (int k=1;k<=d[x];k++){
		int A=2,B=0;//all=2;
		for (int i=0,y;i<a[x].size();i++)
		  if ((y=a[x][i])!=fa){
		  	int newf=F[y].size()>=k?F[y][k-1]:0;
				int newg=two[size[y]]-newf;up(newg+=P);
		  	B=1ll*B*newg%P; 
		  	up(B+=1ll*A*newf%P);
		  	A=1ll*A*newg%P;
		  }
		F[x].push_back(B);
	}*/
int main(){
	/*F[1].push_back(2);F[1].push_back(3);F[1].push_back(4);F[1].push_back(5);
	G[1].push_back(make_pair(0,4));G[1].push_back(make_pair(2,3));
	Rebuild(1);
	for (int i=0;i<4;i++)
	  printf("%d ",F[1][i]);puts("");*/
  scanf("%d",&n);++n;
  for (int i=2;i<=n;i++){
  	int fa;scanf("%d",&fa);
  	++fa;a[fa].push_back(i);
  }
  two[0]=1;
  for (int i=1;i<=n;i++) 
	  two[i]=2ll*two[i-1]%P;
  DFS(1,0);
  int ans=0;
  Rebuild(be[1]);
  for (int i=0;i<=d[1];i++)
    up(ans+=F[be[1]][i]);
  printf("%d\n",ans);
}

Measured memory_bytes: 58868
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define mp make_pair
#define fi first
#define del(a,vec) vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v) binary_search(f,l,v)
#define iter(a,b) vector<int>::iterator a,b
#define lower(v,num) lower_bound (v.begin(), v.end(), num);
#define upper(v,num) upper_bound (v.begin(), v.end(), num); 
#define removecopy(a) unique(a.begin(), a.end()); 
#define ll long long int
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    ll pow (ll x, ll n,ll mod) {//calculate x^n
    if (n == 0) return 1;
 
    ll res = pow (x, n / 2,mod);
 
    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;
 
    return res;
    }
    ll _gcd(ll a,ll b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int main()
{
     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
        // cout<<"hi\n";
    int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22)
    	cout<<"bust";
  else
    cout<<"win";
 
}

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

typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const ll N=2e5 + 5;
const ll mod=1e9 + 7;

int main()
{
    fast();
    ll a;
    string s;
    cin>>a>>s;

    if(a>=3200)
        cout<<s;
    else
        cout<<"red";




}


Measured memory_bytes: 256
package main

import "fmt"

func main(){
  var ( a, b, c, d, e int
       ureshisa int
  )
  
  fmt.Scanf("%d", &a)
  
  ureshisa = 0
  
  b = a %500
  c = (a-b)/500
  d = b%5
  e = (b-d)/5
  
  ureshisa = c*1000+e*5
  
  fmt.Println(ureshisa)
}

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

const ll INF = 1e9;

int H,W,K,sx,sy,gx,gy;
string c[1001000];
int d[1001000];
bool used[1001000];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };

int main(){
    cin >> H >> W >> K >> sx >> sy >> gx >> gy;
    rep(y,H) cin >> c[y];
    sx--; sy--; gx--; gy--; // 0-indexed

    queue<int> que;
    rep(i,1001000) d[i] = INF;

    que.push(sx * W + sy);
    used[sx * W + sy] = true;
    d[sx * W + sy] = 0;

    while(!(que.empty())){
        int q = que.front(); que.pop();

        int x = q/W;
        int y = q%W;

        if(x == gx && y == gy){
            cout << d[q] << endl;
            return 0;
        }

        rep(i,4){
            int nx = x;
            int ny = y;

            rep(j,K){
                nx += dx[i];
                ny += dy[i];

                if(nx < 0 || nx >= H || ny < 0 || ny >= W) break;
                if(c[nx][ny] == '@') break;

                int idx = nx * W + ny;
                if(used[idx] && d[q] + 1 != d[idx]) break;

                if(!used[idx]){
                    used[idx] = true;
                    d[idx] = d[q] + 1;
                    que.push(idx);
                }
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 41440
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if max(b-a,c-a,d-a,e-a,c-b,d-b,e-b,d-c,e-c,e-d,) <= k:
    print('Yay!')
else:
    print(':(')

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

#define ub        upper_bound            // first element >  val(itr)
#define lb        lower_bound            // first element >= val(itr)

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define mem(a,b) memset( a, b, sizeof(a) )

#define bitcount(a) __builtin_popcount(a)   // count set bits
#define lzcount(x) __builtin_clz(x)        // count leading zeros in binary representation of number
#define tzcount(x) __builtin_ctz(x)        // count trailing zeros in binary representation of number

#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

typedef long long int ll;
const ll MOD = 1e9+7;

template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template<typename T> T fast_power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
/*
inline ll mod(ll x,ll n) {if (x < n) return x; if (x >= n) return x - n;}
string IntToString(ll a){ ostringstream temp; temp << a; return temp.str();}
ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M,only if M is prime
ll add(ll a,ll b,ll M)  { return mod(( mod(a,M ) + mod(b,M )),M);     }
ll sub(ll a, ll b,ll M) { return mod((mod(a,M ) + M - mod(b,M )),M);   }
ll mult(ll a,ll b,ll M) { return  mod(( mod(a,M)*mod(b,M) ),M) ; }
bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

  
               /* -------------------------------Main Code------------------------------- */		


int main(){
	FAST
	ll n;cin>>n;
	cout<< ((n-1)*n)/2;
    return 0;
}
	

 	




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

int n;
vector<pair<int,int>> ba;

int main()
{
  int i;
  cin >> n;
  for(i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    ba.emplace_back(b,a);
  }

  sort(ba.begin(),ba.end());
  int sum=0;
  bool hikaku=true;

  for(auto v : ba){
    sum+=v.second;
    if(sum>v.first){
      hikaku=false;
      break;
    }
  }

  cout << (hikaku ? "Yes" : "No") << endl;

  return 0;

}

Measured memory_bytes: 2420
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  double h;
  cin>>h;

  ll cnt=0,ans=0;
  while(h!=0){
    if(h>1){
      h=floor(h/2);
      cnt++;
    }else{
      for(int i=0;i<cnt+1;i++){
          //cout<<i<<endl;
          ans+=pow(2,i);
      }
      h=0;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main() {
    	int n, maxim, sum=0, ans=1;
      	cin >> n >> maxim;
      	while(sum<=maxim && n--) {
          	int c;
          	cin >> c;
          	sum+=c;
          	if(sum<=maxim) ans++;
        }
      
      cout << ans << '\n';
    }

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

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

	static int M[101][101];
	int n;
	cin >> n;

	int u, k, v;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			M[u][v] = 1;
		}	
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (j != 1) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
xy.sort()

pq=[]
for i in range(n-1):
  for j in range(i+1,n):
    pq.append([xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]])

cnt=0
for p,q in pq:
  t_cnt=0
  for x,y in xy:
    if [x+p,y+q] in xy:
      t_cnt+=1
  cnt=max(cnt,t_cnt)

print(n-cnt)

Measured memory_bytes: 9224
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;


int main() {

	long long int ans = 1, div = pow(10, 9) + 7;
	int N;

	cin >> N;

	for (int i = 1; i <= N; i++) {
		ans *= i;
		if (ans >= div) {
			ans %= div;
		}
	}

	cout << ans;

	return 0;

}



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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

const int N = 1e7+7;

ll ans[N];

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n;  cin >> n;
  for (int i = 1; 2+i*(i+2) <= n; ++i){
    for (int j = 1; 2+j*(j+2) <= n; ++j){
      for (int k = 1; 2+k*(k+2) <= n; ++k){
        ans[i*i+j*j+k*k+i*j+j*k+k*i]++; 
      }
    }
  }
  for (int i = 0; i < n; ++i){
    cout << ans[i+1] << "\n";
  }
  return 0;
}

Measured memory_bytes: 3960
import java.util.Scanner;

/**
 *
 * @author must
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if (A==B){
            System.out.println(C);
        }else{
            if (A==C){
                System.out.println(B);
            }else{
                System.out.println(A);
            }
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<ll> w(n+1, 0);
  rep(i, n) {
    cin >> w[i+1];
    w[i+1] += w[i];
  }
  vector<vector<ll>> dp(n+1, vector<ll>(n+1, INF64)), k(n+1, vector<ll>(n+1, 0));
  rep(i, n) {
    dp[i][i] = 0;
    k[i][i] = i;
  }
  for(int d = -1; d >= -(n-1); --d) {
    rep(i, n) {
      int j =i-d;
      if(j >= n) continue;
      ll l = k[i][j-1];
      ll r = k[i+1][j];
      for(int s = l; s <= r; ++s) if(chmin(dp[i][j], dp[i][s]+dp[s+1][j])) k[i][j] = s;
      dp[i][j] += w[j+1]-w[i];
    }
  }
  cout << dp[0][n-1] << endl;
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vector<int>> mi;
typedef vector<vector<pair<int, int>>> w_graph;
typedef vector<vector<int>> uw_graph;

ll dp[105][(int)1e5 + 5];
int w[105], v[105];
int W, n;

ll solve(int i, int sum){
	if (sum > W) return -1e15;
	if (i == n) return 0;
	if (dp[i][sum] != -1) return dp[i][sum];
	return dp[i][sum] = max(solve(i + 1, sum), v[i] + solve(i + 1, sum + w[i]));
}



int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	#ifdef DEBUG
		freopen("out.txt", "w", stdout);
	#endif

	cin >> n >> W;
	for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
	for (int i = 0; i < 105; i++){
		for (int j = 0; j < 1e5 + 5; j++){
			dp[i][j] = -1;
		}
	}
	
	cout << solve(0, 0) << endl;


	return 0;
}


Measured memory_bytes: 82304
fn main() {
    proconio::input! {
        n: usize,
        ds: [(usize, usize);  n],
    }
    let mut count = 0;
    for d in ds {
        if d.0 == d.1 {
            count += 1;
            if count == 3 {
                println!("Yes");
                return;
            }
        } else {
            count = 0;
        }
    }
    println!("No");
}


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

using namespace std;

const int MAXN = 2e3 + 10;
const int MOD = 1e9 + 7;

int n, dp[2 * MAXN][2 * MAXN], go[2 * MAXN][2 * MAXN];
int fac[4 * MAXN];

long long po(long long v, long long u)
{
	return u ? (po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD) : 1;
}

int ente(int i, int j) {
	return (((fac[j] * po(fac[i], MOD - 2)) % MOD) * po(fac[j - i], MOD - 2)) % MOD;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	fac[0] = 1;
	for (int i = 1; i < 4 * MAXN; i++)
		fac[i] = (1ll * fac[i - 1] * i) % MOD;
	cin >> n;
	long long res = 0;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		dp[MAXN - a][MAXN - b]++;
		go[MAXN + a][MAXN + b]++;
		res = (res - ente(2 * a , 2 * (a + b)) + MOD) % MOD;
	}
	for (int i = 1; i < 2 * MAXN; i++)
	{
		for (int j = 1; j < 2 * MAXN; j++)
		{
			dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
			dp[i][j] %= MOD;
			res += 1ll * go[i][j] * dp[i][j];
			res %= MOD;
		}
	}
	cout << (res * (MOD / 2 + 1)) % MOD << endl;
	return 0;
}

Measured memory_bytes: 95872
n, x = map(int, input().split())

l = list(map(int, input().split()))
al = [0] * (n + 1)

count = 0
for i in range(0, n):
    al[i + 1] = al[i] + l[i]

for e in al:
    if e <= x:
        count += 1
    else:
        break

print(count)


Measured memory_bytes: 3060
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"] else stack.push(int(s)) for s in arr]
print(stack.pop())



Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

typedef long long ll;
const int INF = 1001001001;
const int MAX_N = 1000000000;

int main(){
    int Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    
    H = min(H, 2 * Q);
    S = min(S, 2 * H);
    
    ll sum = 0;
    if(2 * S > D){
        sum = (ll)(N / 2) * D + (N % 2) * S;
    }
    else{
        sum = (ll)N * S;
    }
    cout << sum << endl;
}

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

int main() {
  int N;

  cin >> N;
  vector<int> a(N);

  for (int i = 0; i < N; i++){
    cin >> a.at(i);
  }

  int Alice = 0, Bob = 0;

  sort(a.begin(),a.end());
  for(int i = N-1; i > -1; i -= 2){
    Alice += a.at(i);
  }
  for(int i = N-1; i > 0; i -= 2){
      Bob += a.at(i-1);
  }

  cout << Alice - Bob <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    char str[5]={0};
    scanf("%s", str);

    if(str[0]=='A') str[0]='T';
    else if(str[0]=='C') str[0]='G';
    else if(str[0]=='G') str[0]='C';
    else if(str[0]=='T') str[0]='A';
  
    printf("%s\n", str);
    return 0;
}


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

int main(void) {
	int n, i, j;
	int u, k, v;
	cin >> n;
	int G[n+1][n+1];
	for (i = 1; i <= n; i++) {
		for (j = 0; j <= n; j++) {
			G[i][j] = 0;
		}
	}
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		while (k--) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (j != 1) cout << " ";
			cout << G[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3120
#include <stdio.h>

int main(){
  int N, A[100], i = 0, j, flag = 1, ch, cnt = 0;
  scanf("%d",&N);
  
  for(i = 0; i < N; i++)scanf("%d",&A[i]);
  i = 0;
  while(flag){
    flag = 0;
    for(j = N-1; j > i; j--){
      if(A[j] < A[j-1]){
	cnt++;
	ch = A[j];
	A[j] = A[j-1];
	A[j-1] = ch;
	flag = 1;
      }
    }
    i++;
  }
  for(j = 0; j < N; j++){
    printf("%d",A[j]);
    if(j < N-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  return 0;
}




Measured memory_bytes: 2128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	vector<int> vw, vk;

	int tmp;
	for (int i = 0; i < 10; i++) {
		cin >> tmp;
		vw.push_back(tmp);
	}
	for (int i = 0; i < 10; i++) {
		cin >> tmp;
		vk.push_back(tmp);
	}

	sort(vw.begin(), vw.end());
	sort(vk.begin(), vk.end());

	int pw = 0, pk = 0;
	for (int i = 9; i >= 7; i--) {
		pw += vw[i];
		pk += vk[i];
	}

	cout << pw << " " << pk << endl;

	return 0;
}

Measured memory_bytes: 3004
def main():
    from collections import deque
    H, W = (int(i) for i in input().split())
    Ch, Cw = (int(i)-1 for i in input().split())
    Dh, Dw = (int(i)-1 for i in input().split())
    A = [input() for i in range(H)]
    V = [[-1]*W for i in range(H)]  # 頂点i
    d = ((1, 0), (0, 1), (-1, 0), (0, -1))

    def bfs_2d(sy, sx, v):
        que = deque()
        V[sy][sx] = v
        que.append(sy * (H*W) + sx)
        while que:
            uh = que.popleft()
            uw = uh % (H*W)
            uh //= (H*W)
            for dy, dx in d:
                next_h = uh + dy
                next_w = uw + dx
                if not(0 <= next_h < H and 0 <= next_w < W):
                    continue
                if V[next_h][next_w] != -1:
                    continue
                if A[next_h][next_w] == '#':
                    continue
                V[next_h][next_w] = v
                que.append(next_h * (H*W) + next_w)

    vertex = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" or V[h][w] != -1:
                continue
            bfs_2d(h, w, vertex)
            vertex += 1

    G = [[] for _ in range(vertex)]
    used = [set() for _ in range(vertex)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                continue
            for dh in range(-2, 3):
                for dw in range(-2, 3):
                    if h + dh < 0 or H <= h + dh or w + dw < 0 or W <= w + dw:
                        continue
                    if A[h+dh][w+dw] == "#":
                        continue
                    if V[h][w] == V[h+dh][w+dw]:
                        continue
                    if V[h+dh][w+dw] in used[V[h][w]]:
                        continue
                    G[V[h][w]].append((V[h+dh][w+dw]))
                    used[V[h][w]].add((V[h+dh][w+dw]))

    # for h in range(H):
    #     print(V[h])

    # for i in range(vertex):
    #     print(G[i])

    s = V[Ch][Cw]
    g = V[Dh][Dw]

    dist = [-1 for _ in range(vertex)]
    que = deque()
    dist[s] = 0
    que.append(s)
    while que:
        u = que.popleft()
        for v in G[u]:
            if dist[v] != -1:
                continue
            dist[v] = dist[u] + 1
            que.append(v)

    print(dist[g])


if __name__ == '__main__':
    main()


Measured memory_bytes: 155228
#include<stdio.h>
int a[110],s[110];
int main(){
	int n,i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",a+i);
	for(i=n;i>0;i--){
		for(j=i;j>0;j--){
			if(a[j]==j)break;
		}
		if(!j){
			printf("-1");
			return 0;
		}
		s[i]=j;
		for(;j<i;j++)a[j]=a[j+1];
	}
	for(i=1;i<=n;i++)printf("%d ",s[i]);
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int dp[100010];
int h[100005];
const int INF = 1e9 * 2;
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> h[i];
  fill(dp,dp+n+1,INF);

  dp[0] = 0;

  for(int i = 0; i < n; i++) {
    if(i + 1 < n) {
    dp[i+1] = min(dp[i+1],dp[i] + abs(h[i] - h[i+1]));
    }
    if(i + 2 < n) {
    dp[i+2] = min(dp[i+2],dp[i] + abs(h[i] - h[i+2]));
    }
    
  }

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


Measured memory_bytes: 1024
import sys
import bisect
input = sys.stdin.readline

def main():
    n=int(input())
    d = list(map(int,input().split()))
    cnt=0

    d.sort()
    a=d[(n//2)-1]
    b=d[(n//2)]
    ans=b-a
    print(ans)
    
main()




Measured memory_bytes: 13884
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A = reversed(A)
    left = 0
    right = N - 1
    res = [0] * N
    for i,val in enumerate(A):
        if i % 2 == 0:
            res[left] = val
            left += 1
        else:
            res[right] = val
            right -= 1
    print(" ".join(map(str,res)))

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

int mod=1000000007;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){

string n;
cin>>n;
int x=n.size();
int sum=0;

for(int i=0;i<x;i++){
  sum+=n.at(i)-48;
}
 

if(sum%9==0){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}


}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
    boost;
    ll x;
    cin>>x;
    x = 1-x;
    cout<<x<<"\n";
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>
#define INF 10000000000
int main(){
    int N,K;
    std::cin >> N >> K;
    std::vector<int> Log(N);
    int target = 0;
    for(int i=0;i<N;i++){
        std::cin >> Log[i];
        if(Log[i] > target){
            target = Log[i];
        }
    }

    int t_max = target,t_min = 0;
    int ans = target;
    while(t_max - t_min > 1) {
        int totalCut = 0;
        for (int i = 0; i < N; i++) {
            if (totalCut > K) {
                break;
            }
            if(Log[i] != target) {
                totalCut += std::ceil(Log[i] / target);
            }
        }


        if (totalCut <= K) {
            t_max = target;
            ans = target;
        } else {
            t_min = target;
            ans = target + 1;
        }
        target = std::ceil((t_max + t_min) / 2);
    }

    std::cout << ans;

    return 0;
}





Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    string ans="No";
    rep(i,0,x+1){
        if(2*i+4*(x-i)==y) ans="Yes";
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3620
import java.util.*;

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = 0;

        for(int i=1; i<=N; i++){
            String s = String.valueOf(i);
            int l = s.length();
            int sum = 0;
            for(int j=0; j<l; j++){
                sum += Integer.parseInt(s.substring(j, j+1));
            }
            if(sum>=A && sum<=B){
                ans += i;
            }
        }
        System.out.println(ans);
    } 
}

Measured memory_bytes: 25556
from fractions import gcd
 
d = gcd(*map(int, input().split()))
r = 1
i = 2
while i * i <= d:
    c = 0
    while d % i == 0:
        c += 1
        d //= i
    if c: r += 1
    i += 1
print(r + (d > 1))

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i=0;i<N;i++){
        ans += (i+1)*(N-i);
    }
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        if(a>b) swap(a,b);
        ans -= (a+1)*(N-b);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int n; cin >> n;
	n %= 10;
	if (n==3) cout << "bon" << endl;
	else if (n==0 || n==1 || n==6 || n==8) cout << "pon" << endl;
	else cout << "hon" << endl;
}


Measured memory_bytes: 3612
#include<stdio.h>
int main(void)
{
	int N,k[10000],i,c,n;
	scanf("%d",&N);
	while(N!=0){
		n=0;
		c=0;
		for(i=0;i!=N;i++){
			scanf("%d",&k[i]);
		}
		for(i=0;i!=N;i++){
			if(k[i]>1){
				c++;
			}
			if(k[i]==0){
				n++;
			}
		}
		if(c!=0){
			printf("%d\n",N+1-n);
		}
		else{
			printf("NA\n");
		}
	scanf("%d",&N);
	}
	return 0;
}

Measured memory_bytes: 1076
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A[5001],B[5001],C[5001],D[5001];
int N,M;
int S[101]={};
int main() {
	cin>>N;
	for(int i=0;i<(N*(N-1)/2);i++){
		cin>>A[i]>>B[i]>>C[i]>>D[i];
		if(C[i]>D[i])S[A[i]]+=3;
		if(C[i]<D[i])S[B[i]]+=3;
		if(C[i]==D[i])S[A[i]]+=1,S[B[i]]+=1;
	}

	int T=0;
	for(int i=1;i<N+1;i++){
		T=1;
		for(int j=1;j<N+1;j++){
			if(S[i]<S[j])T+=1;
		}
		cout<<T<<endl;

	}
	return 0;
}

Measured memory_bytes: 3152
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop


sys.setrecursionlimit(10 ** 7)

A, B = map(int, input().split())

if (A % B) == 0:
    a = A // B
else:
    a = (A//B)+1

print(a)


Measured memory_bytes: 22044
#include <iostream>
#include <vector>
#include <set>

struct UnionFind
{
    std::vector<std::size_t> _par;
    std::vector<std::size_t> _size;
    std::vector<std::size_t> _rank;

    UnionFind(std::size_t N)
        : _par(N), _size(N, 1), _rank(N, 0)
    {
        for (std::size_t i = 0; i < N; i++)
        {
            _par[i] = i;
        }
    }

    std::size_t Root(std::size_t x)
    {
        if (_par[x] == x)
        {
            return x;
        }
        return _par[x] = Root(_par[x]);
    }

    void Unite(std::size_t x, std::size_t y)
    {
        auto rx = Root(x);
        auto ry = Root(y);
        if (rx != ry)
        {
            if (_rank[rx] < _rank[ry])
            {
                _par[rx] = ry;
                _size[ry] += _size[rx];
            }
            else
            {
                _par[ry] = rx;
                _size[rx] += _size[ry];
                if (_rank[rx] == _rank[ry])
                {
                    _rank[ry]++;
                }
            }
        }
    }

    size_t Size(std::size_t x)
    {
        return _size[Root(x)];
    }

    bool Same(std::size_t x, std::size_t y)
    {
        auto rx = Root(x);
        auto ry = Root(y);
        return rx == ry;
    }
};

using namespace std;

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

    UnionFind uf(n);

    for (int i = 0; i < m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        uf.Unite(x - 1, y - 1);
    }

    set<int> s;
    for (int i = 0; i < n; i++)
    {
        s.insert(uf.Root(i));
    }

    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 7296
//y14-5 タクシー
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)

int N,K;
pair<int,int> CR[5000];
vector<int> m[5000];
bool m2[5000][5000];
int mm2[5000][5000];
vector<int> mm[5000];
LL cost[5000];

queue<int> que;

int move(int start, int now, int nokori){
    m2[start][now] = true;
    mm2[start][now] = nokori;
    if(nokori == 0) return 0;

    for(int i=0; i<m[now].size(); i++){
        if(mm2[start][m[now][i]] < nokori-1) move(start, m[now][i], nokori-1);
    }
}

int solve(int now){
    if(cost[now] > cost[N-1]) return 0;
    for(int i=0; i<mm[now].size(); i++){
        int tmp = mm[now][i];
        if(cost[tmp] > cost[now]+CR[now].first){
            cost[tmp] = cost[now]+CR[now].first;
            que.push(tmp);
        }
    }
}

int main(){

    cin >> N >> K;
    for(int i=0; i<N; i++){
        cin >> CR[i].first >> CR[i].second;
        for(int j=0; j<N; j++){
            m2[i][j] = false;
            mm2[i][j] = -1;
        }
        cost[i] = LL_MAX;
    }
    for(int i=0; i<K; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        m[a].push_back(b);
        m[b].push_back(a);
    }
    cost[0] = 0;

    for(int i=0; i<N; i++){
        for(int j=0; j<m[i].size(); j++){
            move(i, m[i][j], CR[i].second-1);
        }
    }
    
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(m2[i][j]) mm[i].push_back(j);
        }
    }

    que.push(0);
    while(!que.empty()){
        solve(que.front());
        que.pop();
    }
    
    cout << cost[N-1] << endl;

    return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

int main() {
    int n;cin>>n;
    int ans=0;
    vector<int>l(2*n);

    rep(i,2*n){
        cin>>l[i];
        }

    sort(l.begin(),l.end());
    rep(i,2*n){
        if(i%2==0){
            ans+=l[i];
        }
    }
    cout<<ans<<endl;
}



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

struct edge
{
  int to, cost;
};

vector< edge > g[100000];
long long dist[100000], ans[100000];


void dfs1(int idx, int par)//全方位木dp
{
  for(edge e : g[idx]) {
    if(e.to==par) continue;
    dfs1(e.to, idx);
    dist[idx] = max(dist[idx], dist[e.to] + e.cost);
  }
}

void dfs2(int idx, int d_par, int par)
{
  vector< pair< int, int > > d_child;
  d_child.push_back(make_pair(0, -1));
  for(edge &e : g[idx]) {
    if(e.to == par) d_child.push_back(make_pair(d_par + e.cost, e.to));
    else d_child.push_back(make_pair(e.cost + dist[e.to], e.to));
  }
  sort(d_child.rbegin(), d_child.rend());
  
  ans[idx] = max(d_child[0].first, d_child[1].first); 
  for(edge &e : g[idx]) {
    if(e.to == par) continue;
    dfs2(e.to, d_child[d_child[0].second == e.to].first, idx);
  }
}


int main()
{
  int N;
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    g[a].push_back((edge) {b, w});
    g[b].push_back((edge) {a, w});
  }
  
  dfs1(0, -1);
  dfs2(0, 0, -1);
  for(int i=0; i<N; i++){
      cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 7844
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;
int main()
{

    long long int a = 1, b = 1;
    long long int n;
    cin >> n;
    long long int ans = 999999999999;

    for (long long int i = 1; i * i <= n; i++) {
        if (n % i)continue;
        long long int x = n / i;
        ans = min(i - 1 + x - 1, ans);

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

}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int K, X;
  cin >> K >> X;

  string ans = "No";
  if(500*K >= X) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//



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

int main(int argc, const char * argv[]) {
    //提出時、消す
    //--------------//

    int k, x;
    cin >> k >> x;
    if(k * 500 >= x){
        cout << "Yes" << endl;
    }
    else{
        print("No");
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 1010000
ll MOD=1e9+7;
vector<vec> G;
vector<int> ans;

struct point{
    int x,y,z,num;
};


ll gcd(ll x,ll y){
    if(!x)return y;
    else return gcd(y%x,x);
}
int main(){
    int n=in(),m=in();
    vector<int> a,b;
    vector<vec> c(m);
    rep(i,m){
        a.pb(in());
        b.pb(in());
        int tmp=0;
        rep(j,b[i]){
            int c=in();
            tmp|=1<<(c-1);
        }
        b[i]=tmp;
    }
    vector<int> dp;
    dp.resize(1<<n);
    rep(i,1<<n){
        dp[i]=INF;
    }
    dp[0]=0;
    rep(i,m){
        rep3(j,(1<<n)-1,0){
            dp[j|b[i]]=min(dp[j|b[i]],dp[j]+a[i]);
        }
        //rep(j,1<<n)cout<<dp[j]<<" ";
        //cout<<endl;
    }
    cout<<(dp[(1<<n)-1]==INF?-1:dp[(1<<n)-1]);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
const int INF=1001001001;
using namespace std;
int a[12][12];
int main(){

  int n,m,x;
  cin>>n>>m>>x;
  vector<int> c(n);
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  int ans=INF;
  for(int bit=0;bit<(1<<n);bit++){
     int cost=0;
    vector<int> d(m);
    for(int i=0;i<n;i++){
      if(bit>>i&1){
        cost+=c[i];
        for(int j=0;j<m;j++) d[j]+=a[i][j];
      }
    }
    bool ok=true;
    for(int j=0;j<m;j++) if(d[j]<x) ok=false;
    if(ok) ans=min(ans,cost);
  }
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}

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

int main() {
    int n, h[101];

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

    int cnt = 0;
    bool end = false;
    while(!end) {
        bool zero = true;
        end = true;
        for(int i = 0; i < n; i++) {
            if(zero && h[i] > 0) {
                zero = false, end = false;
                cnt++;
            }
            else if(!zero && h[i] <= 0) zero = true;
            h[i]--;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int N;
cin>>N;
vector<pair<int,int>>v(N-1);
vector<vector<int>>l(N);
int cnt[N]={};
rep(i,N-1){
    int a,b;
    cin>>a>>b;
    a--,b--;
    v[i]=make_pair(a,b);
    l[a].emplace_back(b);
    l[b].emplace_back(a);
    cnt[a]++;
    cnt[b]++;
}
multimap<int,int>mp;
rep(i,N){
    mp.insert(make_pair(cnt[i],i));
}

vector<int> cost(N);
rep(i,N){
    cin>>cost[i];
}
sort(cost.begin(),cost.end());

int ans[N];
bool checked[N]={};

int p=N-1;
auto iter=mp.end();
iter--;
int root=iter->second;
queue<int>q;
q.push(root);
        

while(!q.empty()){
    int now=q.front();q.pop();
    ans[now]=cost[p];
    checked[now]=true;
    p--;
    for(auto vp:l[now])
    {
        if(checked[vp])continue;
        q.push(vp);
    }    
}

long long M=0;

rep(i,N-1){
    M+=min(ans[v[i].first],ans[v[i].second]);
}

cout<<M<<endl;
rep(i,N)cout<<ans[i]<<" ";
 return 0;
}
/*

5
1 2
2 3
3 4
4 5
1 2 3 4 5

10
1 2 3 4 5


5
1 2
1 3
1 4
1 5
3141 59 26 53 59

197
59 26 3141 59 53

*/

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
int a[MAX];
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; ++ i)
    {
        cin >> a[i];
    }

    int maxn = a[1] - a[0], minn = a[0];

    for(int i = 1; i < n; ++ i)
    {
        maxn = max(maxn, a[i] - minn);
        minn = min(minn, a[i]);
    }
    cout << maxn << endl;
    return 0;
}



Measured memory_bytes: 3880