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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

struct SegT
{
  vector<int> tree;
  int n;
 
  SegT(int n_)
  {
    n = 1;
    while ( n < n_ ) n <<= 1;
    tree = vector<int>(2 * n - 1, INF);
  }
  int rmq(int a, int b, int k, int l, int r)
  {
    if ( a >= r || b <= l ) return INF;
    if ( a <= l && r <= b ) return tree[k];
    return min(rmq(a, b, 2 * k + 1, l, (l + r) >> 1),
               rmq(a, b, 2 * k + 2, (l + r) >> 1, r));
  }
  int rmq(int a, int b)
  {
    return (rmq(a, b, 0, 0, n));
  }
  int update(int k, int x)
  {
    k += n - 1;
    tree[k] = x;
    while ( k > 0 ) {
      k = (k - 1) >> 1;
      tree[k] = min(tree[2 * k + 1], tree[2 * k + 2]);
    }
  }
};


signed main() {
  int W, H, N;
  //SegT t1(100001), t2(100001);
  int Y[100001] = {0}, X[100001] = {0};
  int mY[100001] = {0}, mX[100001] = {0};
  
  cin >> W >> H >> N;
  Rep(i, N) {
    int x, y;
    cin >> x >> y;
    Y[y] = max(Y[y], x);
    X[x] = max(X[x], y);
  }

  mX[W-1] = X[W-1];
  for ( int i = W-2; i >= 0; i-- ) {
    mX[i] = max(mX[i+1], X[i]);
  }

  mY[H-1] = Y[H-1];
  for ( int i = H-2; i >= 0; i-- ) {
    mY[i] = max(mY[i+1], Y[i]);
  }

  /* Rep(i, H) {
    t2.update(i, -X[i]);
  }
  */
  int ans = min(W-1, H-1);
  Rep(i, W-1) {
    // ans = min(ans, i + -t1.rmq(i+1, W));
    ans = min(ans, i + mX[i+1]);
  }

  Rep(i, H-1) {
    //ans = min(ans, i + -t2.rmq(i+1, H));
    ans = min(ans, i + mY[i+1]);
  }

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

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

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(true){
			//input
			int w=scan.nextInt();
			int h=scan.nextInt();
			if(w==0 && h==0)break;
			int[][] wallUD=new int[h][w-1];
			int[][] wallLR=new int[h-1][w];
			for(int i=0;i<h-1;i++){
				for(int j=0;j<w-1;j++){
					wallUD[i][j]=scan.nextInt();
				}
				for(int j=0;j<w;j++){
					wallLR[i][j]=scan.nextInt();
				}
			}
			for(int j=0;j<w-1;j++){
				wallUD[h-1][j]=scan.nextInt();
			}
			
			//variable height*1000+width=place
			int[][] distance=new int[h][w];
			int step=2;
			ArrayList<Integer> nowPlace=new ArrayList<Integer>();
			ArrayList<Integer> nextPlace=new ArrayList<Integer>();
			
			//Start data
			nowPlace.add(0);
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					distance[i][j]=0;
				}
			}
			
			while(nowPlace.size()>0 && distance[h-1][w-1]==0){
				//see all
				for(int i=0;i<nowPlace.size();i++){
					int UD=nowPlace.get(i)/1000;
					int LR=nowPlace.get(i)%1000;
					//see up
					if(UD>0   && wallLR[UD-1][LR]==0 && distance[UD-1][LR]==0){
						distance[UD-1][LR]=step;
						nextPlace.add((UD-1)*1000+LR);
					}
					//see down
					if(UD<h-1 && wallLR[UD][LR]==0   && distance[UD+1][LR]==0){
						distance[UD+1][LR]=step;
						nextPlace.add((UD+1)*1000+LR);
					}
					//see left
					if(LR>0   && wallUD[UD][LR-1]==0 && distance[UD][LR-1]==0){
						distance[UD][LR-1]=step;
						nextPlace.add(UD*1000+LR-1);
					}
					//see right
					if(LR<w-1 && wallUD[UD][LR]==0   && distance[UD][LR+1]==0){
						distance[UD][LR+1]=step;
						nextPlace.add(UD*1000+LR+1);
					}
					//System.out.println(UD+" "+LR);
				}
				//make next
				nowPlace.clear();
				for(int i=0;i<nextPlace.size();i++){
					nowPlace.add(nextPlace.get(i));
				}
				nextPlace.clear();
				step++;
			}
			//output
			System.out.println(distance[h-1][w-1]);
		}
	}
}

Measured memory_bytes: 71504
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

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

    cout << pow(n, 3);

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  int n,m,X,Y; cin>>n>>m>>X>>Y;
  vector<int> x(n);
  vector<int> y(m);
  rep(i,n) cin>>x[i];
  rep(i,m) cin>>y[i];

  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  bool w=0;
  for(int i=X+1;i<=Y;i++){
    if((x[n-1]<i)&&(i<=y[0])){
      w=1;
      // cout<<i<<endl;
    }
  }
  if(w)
  cout<<"No War"<<endl;
  else
  cout<<"War"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll cal(int a,int b) {
	return 1LL*(a+a+b-1)*b/2;
}
int main() {
	int n,x,d;
	scanf("%d%d%d",&n,&x,&d);
	if(d==0) printf("%d\n",x?n+1:1);
	else {
		int t=__gcd(x,d);
		x/=t,d/=t;
		if(d<0) d=-d,x=-x;
		ll ans=0;
		for(int i=0;i<d;i++) {
			set<pair<ll,ll> > s;
			for(int j=i;j<=n;j+=d) {
				s.insert({1LL*j/d*x+cal(0,j),1LL*j/d*x+cal(n-j,j)+1});
			}
			ll res=-1e18;
			for(auto it:s) {
				ans+=max(0LL,it.second-max(res,it.first));
				res=max(res,it.second);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll N,M;
vector<int> A;

int main(){
  cin>>N>>M;
  A.resize(M);
  rep(i,M)cin>>A[i];
  if(M==1){
    cout<<A[0]<<endl;
    if(A[0]>1){
      cout<<2<<endl;
      cout<<A[0]-1<<" "<<1<<endl;
    }else{
      cout<<1<<endl;
      cout<<1<<endl;
    }
    return 0;
  }
  vector<int> os;
  rep(i,M){
    if(A[i]%2==1)os.push_back(i);
  }
  if(os.size()>2){
    cout<<"Impossible"<<endl;
    return 0;
  }
  if(os.size()==1){
    swap(A[0],A[os[0]]);
  }else if(os.size()==2){
    swap(A[0],A[os[0]]);
    swap(A[M-1],A[os[1]]);
  }
  rep(i,M)cout<<A[i]<<" ";
  cout<<endl;
  if(A[0]-1>0){
    cout<<M<<endl;
    cout<<A[0]-1<<" ";
  }else{
    cout<<M-1<<endl;
  }
  repl(i,1,M-1)cout<<A[i]<<" ";
  cout<<A[M-1]+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D) {
		cout << "Left" << endl;
	}
	else if (A + B == C + D) {
		cout << "Balanced" << endl;
	}
	else {
		cout << "Right" << endl;
	}
}

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

int main(int argc, char* argv[]) {
	std::string input;
	std::cin >> input;

	for (size_t i = 0; i < input.size(); ++i) {
		if (input[i] == '?') {
			if (input[i - 1] == 'P' && i != 0)
				input[i] = 'D';
			else if ((input[i + 1] == 'D' || input[i + 1] == '?') && i != input.size() - 1)
				input[i] = 'P';
			else
				input[i] = 'D';
		}

	}
	printf("%s", input.c_str());

	return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans =0;
    for (int i = 0; i < n-2; i++){
        if(s.at(i)=='A' and s.at(i+1)=='B' and s.at(i+2)=='C') ans+=1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	int x,n,t;
	cin>>x>>n;
	set<int> a;
	for(int i=0;i<n;i++)
	{
		cin>>t;
		a.insert(t);
	}
	for(int i=0;i<=n;i++)
	{
		if(a.find(x-i)==a.end())
		{
			cout<<x-i<<endl;
			break;
		}
		if(a.find(x+i)==a.end())
		{
			cout<<x+i<<endl;
			break;
		}
	}
}


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

using namespace std;

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}


int main()
{
	ll n;
	bool ans = true;
	cin >> n;
	rep(i,n){
		ll a;
		cin >> a;
		if(a % 2 == 0 && a % 3 != 0 && a % 5 != 0)ans = false;
	}

	cout << ((ans)? "APPROVED" : "DENIED") << endl;
    return 0;
}

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


int main(){
    int N,M;
    cin >> N >> M;
    vector<ll> x(N) , y(N), z(N);
    rep(i,N) cin >> x[i] >> y[i] >> z[i];
    ll ans=0;
    rep(bit,(1<<3)){
        vector<ll> res(N,0); 
        rep(i,N){
            if(bit&(1<<0))res[i]+=x[i];//1番目のビットが立っているか
            else res[i]-=x[i];
            if(bit&(1<<1))res[i]+=y[i];//2番目のビットが立っているか
            else res[i]-=y[i];
            if(bit&(1<<2))res[i]+=z[i];//3番目のビットが立っているか
            else res[i]-=z[i];
        }
        sort(res.rbegin(),res.rend());//降順ソート
        ll tmp = 0;
        rep(i,M)tmp+=res[i];//降順になっているので配列のはじめの方からM個足していけばよい
        ans=max(ans,tmp);//今までのやつのうち最大のものをとる
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll dp[1010];
int p[1010];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi v(n); rep(i, n) cin >> v[i];
	rep(i, n + 1) dp[i] = -1e18, p[i] = -1;
	rep(i, n){
		dp[i] = v[i];
		for(int j = i - 2; j >= 0; j -= 2){
			if(dp[i] < dp[j] + v[i]){
				dp[i] = dp[j] + v[i];
				p[i] = j;
			}
		}
	}
	ll ans = -1e18;
	int mi;
	rep(i, n) if(ans < dp[i]) ans = dp[mi = i];
	cout << ans << endl;
	
	dbg(mi);
	
	vi s;
	for(int i = n - 1; i > mi; i--) s.pb(i);
	while(p[mi] >= 0){
		int d = (mi - p[mi] + 1) / 2;
		rep(i, d) s.pb(p[mi] + (i == d-1 ? 1 : 2));
		mi = p[mi];
	}
	rep(i, mi) s.pb(0);
	cout << s.size() << endl;
	for(int i : s) cout << i+1 << endl;
	
	return 0;
}

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

int main(){
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if(c - b > 0 && b - a > 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
from numpy import cumsum
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += min(b[i], a[i] + a[i+1])
    a[i+1] -= max(0, min(b[i] - a[i], a[i+1]))

print(ans)


Measured memory_bytes: 42920
N,M = map(int,input().split())
SC = []

for i in range(M):
  sc = list(map(int,input().split()))
  SC.append(sc)

num = [0] * N

for i in range(M):
  s = SC[i][0]
  c = SC[i][1]
  #すでに値が入っており異なる値か、人ケタメに0を指定しているか
  if (num[s - 1] != 0 and num[s - 1] != c) or (N > 1 and s == 1 and c == 0):
    num = -1
    break
  else:
    num[s - 1] = SC[i][1]

if num == -1:
  print(-1)
else:
  ans = ""
  for i in range(N):
    if num[0] == 0 and len(num) > 1:
      num[0] = 1
    ans += str(num[i])
  ans = int(ans)
  print(ans)

Measured memory_bytes: 3064
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

counter = Counter(a)
sm = sum(a)
for b, c in bc:
    sm += counter[b] * (c - b)
    print(sm)
    counter[c] += counter[b]
    counter[b] = 0


Measured memory_bytes: 40240
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  map<ll,ll> m;
  rep(i,n) m[a[i]]++;
  ll sum=0;
  tr(it,m) {
    ll x=it->S;
    sum+=x*(x-1)/2;
  }
  rep(i,n) {
    ll x=m[a[i]],y=x-1;
    pr(sum-x*(x-1)/2+y*(y-1)/2);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 11136
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    int i;
    vector<int> a;
    for(i=0; i<3; i++) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    int cnt=0;
    for(i=0; i<2; i++) {
        while(a[i]+2<=a[2]) {
            a[i]+=2;
            cnt++;
        }
    }
    
    if(a[0]==a[1]&&a[1]==a[2]);
    else if(a[0]==a[1])
        cnt++;
    else if(a[0]==a[2] || a[1]==a[2])
        cnt+=2;
    cout << cnt << endl;
}

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

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

  vector<int> a(200000);
  vector<int> b(200000);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    b.at(a.at(i))++;
  }

  int c = 0;
  for(int i = 0; i < n; i++){
    if(b.at(i)){
      c++;
    }
  }

  sort(b.begin(), b.end(),greater<int>());

  int ans = 0;
  for(int i = k; i < n; i++){
    ans += b.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a,s;
    cin>>a>>s;
    if(a=='H'){
        if(s=='H')cout<<"H"<<endl;
        else cout<<'D'<<endl;
    }else{
        if(s=='H')cout<<'D'<<endl;
        else cout<<'H'<<endl;
    }
}
  


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

using namespace std;

const int N = 1e5 + 5;

int a[N], b[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int, int>> p;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    p.emplace_back(a[i], 0);
  }
  for (int j = 0; j < m; j++) {
    scanf("%d", b + j);
    p.emplace_back(b[j], 1);
  }
  sort(p.begin(), p.end());
  long long ans = 0;
  int ada_a = 0, ada_b = 0;
  for (auto it : p) {
    if (it.second == 0) {
      ans += 1LL * (m + 1 - ada_b) * it.first;
      ada_a++;
    } else {
      ans += 1LL * (n + 1 - ada_a) * it.first;
      ada_b++;
    }
    //cout << "haha " << ans << endl;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    int mm = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        int p;
        std::cin >> p;
        sum += p;
        mm = std::max(mm, p);
    }
    std::cout << sum - mm / 2 << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		int sum = 0;
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    sum += a[i];
		}
		Arrays.sort(a);
		
		// 計算
		String result = "Yes";
		int tmp = 0;
		if(sum%(4*m) == 0){
		        tmp = sum/(4*m);
		    }else{
		        tmp = (sum/(4*m)) + 1;
		    }
		for(int i = 0; i < m; i++){
		    if(a[n-i-1] < tmp){
		        result = "No";
		        break;
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    int n,m,q;
    cin>>n>>m>>q;
    vector<vector<int>> v(n+10,vector<int> (n+10,0));
    vector<P> pa1(m),pa2(q);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        v[a][b]++;
        pa1[i]={a,b};
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) v[i][j]+=(v[i-1][j]+v[i][j-1]-v[i-1][j-1]);
    }
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        pa2[i]={a,b};
    }
    for(int i=0;i<q;i++){
        ll f=pa2[i].first,s=pa2[i].second;
        cout<<v[s][s]-v[f-1][s]-v[s][f-1]+v[f-1][f-1]<<endl;
    }
    return 0;
}

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

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

  for (int i = 0; i < 7; i++) {
    if (pow(2, i + 1) > N) {
      cout << pow(2, i) << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 4112
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(v>w)
    {
        ll x=abs(a-b),y=(v-w)*t;
        if(x>y)
            cout<<"NO";
        else
            cout<<"YES";
    }
    else
        cout<<"NO";
    subt;
    return 0;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mod 1000000007
unordered_map<char,vector<string>> adj;
vector<ll> vis(100005,0);
vector<ll> p(100005,0);
ll c[100005];
/*void dfs(ll node,ll len)
{
	if(len==n)
	{
		ans++;
		return;
	}
	for(auto str:adj[node])
		dfs(str[0],len+1);
}*/
int main()
{
 ll n;
 cin>>n;
 ll a[n],dp[n+1];
 dp[n]=0;
 ll i;
 ll sum=0;
 for(i=0;i<n;i++)
   cin>>a[i];
  for(i=n-1;i>=0;i--)
  {
     dp[i]=(dp[i+1]+a[i])%mod;
  }
  for(i=0;i<n;i++)
  {
     sum=(sum+(a[i]*dp[i+1])% mod)% mod;
  }
  cout<<sum;
}

Measured memory_bytes: 7956
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    if (fopen("Test.INP", "r"))
        freopen("Test.INP", "r", stdin);

    int n;
    cin >> n;

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

    int dp[3][n + 1];
    dp[0][0] = 0;
    dp[1][0] = 0;
    dp[2][0] = 0;

    for (int i = 1; i <= n; ++i)
    {
        dp[0][i] = a[0][i - 1] + max(dp[1][i - 1], dp[2][i - 1]);
        dp[1][i] = a[1][i - 1] + max(dp[2][i - 1], dp[0][i - 1]);
        dp[2][i] = a[2][i - 1] + max(dp[0][i - 1], dp[1][i - 1]);
    }

    cout << max(dp[0][n], max(dp[1][n], dp[2][n]));
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;


int main(){
  int anum[1000000];
  int bnum[1000000];
  int cnum[10000];
  int a,b,cnt=0;
  int flag=0;

  cin >>a;

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

  cin >>b;

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

  int s=0;
for(int j=0; j<b; j++){
    s=0;
    anum[a]=bnum[j];
     
    while(anum[s] != anum[a]) s++;
    if(s < a) cnt++;
  }
   


  
  

  cout << cnt <<endl;
  
  return 0;
}

Measured memory_bytes: 3136
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	ll H,W,h,w;
	ll m = 1e8;
	inp >> H >>W >> h >> w;
	if(H%h==0 && W%w==0){
		cout << "No" << endl;
		return;
	}
	cout << "Yes" << endl;
	rep(x,H) rep(y,W){
		if(x%h==0 && y%w==0){
			cout << m-1;
		}
		else if(x%h==h-1 && y%w==w-1){
			cout << -m;
		}
		else{
			cout << 0;
		}
		if(y==W-1){
			cout << endl;
		}
		else{
			cout << " ";
		}
	}

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


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

void SelectionSort(vector<int> &A, int &count)
{
	for(int i = 0; i < A.size(); i++){
		int minj = i;
		for(int j = i; j < A.size(); j++){
			if(A[j] < A[minj]){
				minj = j;
			}
		}
		if(minj != i){
			swap(A[i], A[minj]);
			count++;
		}
	}
}

void Output(vector<int> A)
{
	int n = A.size() - 1;
	for(int i = 0; i < n; i++){
		cout << A[i] << ' ';
	}
	cout << A[n] << endl;
}

vector<int> Input()
{
	int N;
	cin >> N;
	vector<int> A;
	A.resize(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	return A;
}

int main()
{
	vector<int> A = Input();
	int count = 0;
	SelectionSort(A, count);
	Output(A);
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1216
# -*- coding: utf-8 -*-
#143_b

N = int(input())
d = [int(i) for i in input().split()]

ans = 0
for i, di in enumerate(d):
    for j, dj in enumerate(d):
        if i == j:
            continue
        else:
            ans += di*dj
print(ans//2)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,x,n) for(ll i=x; i<n; ++i)
#define INF LLONG_MAX
using ll = long long;
using ull = unsigned long long;
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) { a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) { a=b; return true;} return false;}

int main() {
  ll N; cin >> N;
  vector<ll> h(N), dp(N, INF);
  rep(i,0,N) cin >> h[i];

  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  rep(i, 2, N) {
    chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
    chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<iostream> 

using namespace std;

	int n;
	string s[205];
	string ch;
	int x[2005];
	int f[2005];
	int v[1005];
	int w[1005];
	int L;
	int V;
	string nowch;
	int tot=0;

int main()
{
	while (1)
	{	
		scanf("%d",&n);
		tot++;
		if (!n)
		{
			break;
		}
		for (int i=1;i<=n;i++)
		{
			cin>>s[i]>>v[i];
			w[i]=s[i].size();
		}
		cin>>ch;
		L=ch.size();
		memset(f,-1,sizeof(f));
		f[0]=0;
		for (int i=0;i<=L;i++)
		{
			for (int j=1;j<=n;j++)
			{
				if (i-w[j]>=0)
				{
					if (f[i-w[j]]>=0 && ch.substr(i-w[j],w[j])==s[j])
					{
						f[i]=max(f[i],f[i-w[j]]+v[j]);
					}
				}
			}
		}
		
		V=f[L];
		memset(f,0x3f3f3f3f,sizeof(f));
		f[0]=0;
		for (int i=1;i<=n;i++)
		{
			for (int j=v[i];j<=V;j++)
			{
				f[j]=min(f[j],f[j-v[i]]+w[i]);
			}	
		}
		printf("Case %d: %d\n",tot,f[V]);
	}
	
	return 0;
}

Measured memory_bytes: 1308
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    vll A(N); ll c = 0;
    cin >> A[0];
    if(A[0]<0){c++;}
    ll min = abs(A[0]);
    for(int i=1; i<N; i++){
        cin >> A[i];
        if(A[i] < 0){c++;}
        if(abs(A[i])<min){min = abs(A[i]);}
    }
    ll sum = 0;
    for(auto x: A){
        sum += abs(x);
    }
    if(c%2 == 0){cout << sum;}
    else{sum -= 2*min; cout << sum;}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h> 
using namespace std; 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = a; i <b; i++)
#define forn(i,a,b) for (int i = a; i >b; i--)
#define mod 1000000007
#define multiple_testcases_t int t;cin>>t;while(t--){solve();}
#define single_testcase_t solve();
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;


ll fact(ll n)
{
  if(n==0 || n==1)
  return 1;
  else
  return (n*fact(n-1)%mod)%mod;
}

int prime(ll n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}

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

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

int check_palin(string s)
{
  string str=s;
  reverse(str.begin(),str.end());
  if(str==s)
  return 1;
  else 
  return 0;
}

vector<ll> divisors(ll n)
{
  vector<ll> v;
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      if(i==n/i)
      v.PB(i);
      else
      v.PB(i),v.PB(n/i);
    }
  }
return v;
}

ll bin_expo(int x,int n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_expo(x*x,n/2);
    else                             //n is odd
        return x*bin_expo(x*x,(n-1)/2);
}

ll modular_expo(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modular_expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modular_expo((x*x)%M,(n-1)/2,M))%M;
}

// <----- Actual solve() function to print output -----> //
void solve()
{
  ll n,ans=0,z=0;
  cin>>n;
  string str;
  //cout<<mul<<" ";
  while(n!=0)
  {
   // cout<<n<<" "<<mul;
    if(n%26==0)
    {
      str.PB('z');
n=n/26;
n--;
    }
    else
    {
      char c=n%26+'a'-1;
        str.PB(c);
        n/=26;
    }
  }
z=str.size();
  
  reverse(str.begin(),str.end());
  cout<<str;
        //if t>1 uncomment this
}

// MAIN function --------------------------------------------------------------------------//
int main()
{
    fast_io
    single_testcase_t   //Uncomment this if only single testcase & single answer to print
   // multiple_testcases_t  //Uncomment this if t>1(t is given in question)(multiple testcases)      
return 0;
}
            
            
            
            

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#ifdef SIR
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define err(...) 42
#endif

typedef long long ll;

using namespace std;

vector<vector<int>> E;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> in(n);
    E.resize(n);

    for (int i = 0; i < n - 1 + m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        E[a].push_back(b);
        in[b]++;
    }

    vector<int> pr(n, -1), ans(n, -1);
    set<pair<int, int>> S;
    for (int i = 0; i < n; i++) S.insert({ in[i], i });


    while (S.size()) {
        vector<int> cur;
        while (S.size() && S.begin()->first == 0) {
            cur.push_back(S.begin()->second);
            S.erase(S.begin());
        }

        for (int v : cur) {
            ans[v] = pr[v];
            for (int to : E[v]) {
                pr[to] = v;
                S.erase({ in[to], to });
                in[to]--;
                S.insert({ in[to], to });
            }
        }
    }
    for (int i = 0; i < n; i++) cout << ans[i] + 1 << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef SIR
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
using namespace std;
int m,n;
int a[120];
int tot;
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		tot+=a[i];
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]*4*m>=tot)
			cnt++;
	}
	if(cnt>=m)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long D;
const int maxn=200003,maxm=4005,N=4002,mod=1000000007;
int Plus(int x,int y){return (x+=y)>=mod?x-mod:x;}
void Pluseq(int &x,int y){if((x+=y)>=mod)x-=mod;}
int Minus(int x,int y){return Plus(x,mod-y);}
void Minuseq(int &x,int y){Pluseq(x,mod-y);}
int mul(D x,int y){return x*y%mod;}
void muleq(int &x,int y){x=mul(x,y);}
int qpow(int x,int y){
    int ans=1;
    while(y){
        if(y&1)muleq(ans,x);
        muleq(x,x);
        y>>=1;
    }
    return ans;
}
int n,fac[maxn],facinv[maxn],dp[maxm][maxm],b[maxm][maxm],a[maxn][2];
int C(int n,int m){return mul(mul(fac[n],facinv[m]),facinv[n-m]);}
int main(){
    fac[0]=1;
    for(int i=1;i<maxn;i++)fac[i]=mul(fac[i-1],i);
    facinv[maxn-1]=qpow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)facinv[i]=mul(facinv[i+1],i+1);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",a[i],a[i]+1);
        b[N/2-a[i][0]][N/2-a[i][1]]++;
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            dp[i][j]=Plus(Plus(dp[i-1][j],dp[i][j-1]),b[i][j]);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        Pluseq(ans,dp[N/2+a[i][0]][N/2+a[i][1]]);
        Minuseq(ans,C((a[i][0]+a[i][1])*2,a[i][0]*2));
    }
    muleq(ans,500000004);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 92720
#include<stdio.h>

int main(void)
{
	int x, y, temp;

	while (1){
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0)
		{
			break;
		}
		if (x > y)
		{
			temp = x;
			x = y;
			y = temp;
		}
		printf("%d %d", x, y);
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 604
#include <cassert>
#include <climits>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>


class TVertex;
struct TPath
{
    int Cost;
    TVertex* Target;
    TPath(TVertex* ATarget, int ACost)
     : Target(ATarget), Cost(ACost) {}
};
class TVertex
{
    int FIndex;
    std::vector<TPath> FList;
    int FDistance;

public:
    TVertex(int Index)
     : FIndex(Index), FDistance(INT_MAX)
    {}
    void AddPath(const TPath& Path)
    {
        FList.push_back(Path);
    }
    void PrintDistance(std::ostream& out)const
    {
        out << FIndex << " " << FDistance << std::endl;
    }
    void BreadthFirstSearch(int Distance)
    {
        if(FDistance <= Distance) return;
        FDistance = Distance;
        for(std::vector<TPath>::iterator It = FList.begin(); It != FList.end(); ++It){
            It->Target->BreadthFirstSearch(Distance + It->Cost);
        }
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
public:
    TGraph(int n)
    {
        Init(n);
    }
    
    void SetupVertex(std::istream& in)
    {
        int Index;
        in >> Index;
        assert(Index >= 0);
        assert(Index < FTable.size());
        int k;
        in >> k;
        for(int i = 0; i < k; ++i){
            int v, c;
            in >> v >> c;
            FTable[Index]->AddPath(TPath(FTable[v], c));
        }
    }
    void BreadthFirstSearch()
    {
        FTable[0]->BreadthFirstSearch(0);
    }
    void PrintDistance(std::ostream& out)
    {
        for(int i = 0; i < FTable.size(); ++i){
            FTable[i]->PrintDistance(out);
        }
    }
};

int main()
{
    int n;
    std::cin >> n;
    TGraph Graph(n);
    for(int i = 0; i < n; ++i){
        Graph.SetupVertex(std::cin);
    }
    Graph.BreadthFirstSearch();
    Graph.PrintDistance(std::cout);
    return 0;
    
}

Measured memory_bytes: 3200
import java.util.*;

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();
    }

    sc.close();

    Arrays.sort(a);

    System.out.println(a[a.length - 1] - a[0]);

  }

}

Measured memory_bytes: 21844
N=int(input())
A=list(map(int,input().split()))
ans=20202020200
sum_A=0
sum_B=sum(A)
for i in range(N):
    sum_A+=A[i]
    sum_B-=A[i]
    tmp=abs(sum_A-sum_B)
    if tmp<ans:
        ans=tmp
print(ans)

Measured memory_bytes: 31604
//DFS-标程
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
const int INF = 1e9;
using P = pair<ll,int>;
 
void dfs(int v, ll a, int signT, ll &maxT, ll &minT,
    vector<P> &vis,vector<vector<P>> &g){
    if(vis[v] != P(0,0)){
        ll b = vis[v].first;
        int sign = vis[v].second;
        if(sign==signT && a!=b) maxT = 0;
        if(sign!=signT){
            if(abs(a-b)&1) maxT = 0;
            minT = max(minT, abs(a-b)/2);
            maxT = min(maxT, abs(a-b)/2);
        }
        return;
    }
    vis[v] = {a,signT};
    if(signT == +1) minT = max(minT, 1-a);
    if(signT == -1) maxT = min(maxT, a-1);
    for(P &e : g[v]){
        ll sum = e.first;
        int to = e.second;
        dfs(to,sum-a,-signT,maxT,minT,vis,g);
    }
}
 
int main(void){
    int n,m;
    cin>>n>>m;
    vector<vector<P>> g(n); // <sum,to>
    rep(i,m){
        int u,v;
        ll s;
        cin>>u>>v>>s;
        u--, v--;
        g[u].push_back({s,v});
        g[v].push_back({s,u});
    }
    ll maxT = INF, minT = 0;
    vector<P> vis(n); // <a,sign> (a + sign*t)
    dfs(0,0,+1,maxT,minT,vis,g);
    cout<<max(maxT-minT+1, 0LL)<<endl;
    return 0;
}

Measured memory_bytes: 18816
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collections;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        HashMap<Double, Integer> d1 = new HashMap<Double, Integer>();
        HashMap<Double, Integer> d2 = new HashMap<Double, Integer>();
        HashMap<Double, Integer> d3 = new HashMap<Double, Integer>();
        HashMap<Double, Integer> re = new HashMap<Double, Integer>();

        for (int i = 0; i < 8; i++) {
            String[] input = br.readLine().split(" ");
            d1.put(Double.parseDouble(input[1]), Integer.parseInt(input[0]));
        }
        for (int i = 0; i < 8; i++) {
            String[] input = br.readLine().split(" ");
            d2.put(Double.parseDouble(input[1]), Integer.parseInt(input[0]));
        }
        for (int i = 0; i < 8; i++) {
            String[] input = br.readLine().split(" ");
            d3.put(Double.parseDouble(input[1]), Integer.parseInt(input[0]));
        }

        ArrayList<Double> a1 = new ArrayList<Double>(d1.keySet());
        ArrayList<Double> a2 = new ArrayList<Double>(d2.keySet());
        ArrayList<Double> a3 = new ArrayList<Double>(d3.keySet());
        Collections.sort(a1);
        Collections.sort(a2);
        Collections.sort(a3);

        re.put(a1.get(2), d1.get(a1.get(2)));
        re.put(a1.get(3), d1.get(a1.get(3)));
        re.put(a2.get(2), d2.get(a2.get(2)));
        re.put(a2.get(3), d2.get(a2.get(3)));
        re.put(a3.get(2), d3.get(a3.get(2)));
        re.put(a3.get(3), d3.get(a3.get(3)));
        ArrayList<Double> r1 = new ArrayList<Double>(re.keySet());
        Collections.sort(r1);

        System.out.println(d1.get(a1.get(0)) + " " + a1.get(0));
        System.out.println(d1.get(a1.get(1)) + " " + a1.get(1));
        System.out.println(d2.get(a2.get(0)) + " " + a2.get(0));
        System.out.println(d2.get(a2.get(1)) + " " + a2.get(1));
        System.out.println(d3.get(a3.get(0)) + " " + a3.get(0));
        System.out.println(d3.get(a3.get(1)) + " " + a3.get(1));
        System.out.println(re.get(r1.get(0)) + " " + r1.get(0));
        System.out.println(re.get(r1.get(1)) + " " + r1.get(1));
    }
}


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

int main(){
  int n;
  cin >> n;
  set<string> s;
  for(int i = 0; i < n; ++i){
    string a;
    cin >> a;
    s.insert(a);
  }
  
  cout << s.size() << endl;
}

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

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

    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

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

    int mini = 1e9;
    for(int i = 0; i <= n - k; i++){
        mini = min(mini, A[i + k - 1]- A[i]);
    }

    cout << mini << endl;

    return 0;
}

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

int main() {
	int A,B;
  	cin >> A >> B;
    
  	if(A == 1 && B == 1) cout << "Draw" << endl;
  	if(A == 1 && B != 1) cout << "Alice" <<  endl;
  	if(B == 1 && A != 1) cout << "Bob" << endl;
  
  	if(A != 1 && B != 1) {
    	if(A < B) cout << "Bob" << endl;
      	if(A > B) cout << "Alice" << endl;
      	if(A == B) cout << "Draw" << endl;
    }
}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    vector<int>N(3);
    for(int i=0;i<3;i++)cin>>N[i];
    int K;
    cin>>K;
    sort(N.begin(),N.end());
    for(int i=0;i<K;i++){
        N[2]=N[2]*2;
    }
    int ans=0;
    ans=N[0]+N[1]+N[2];

    cout<<ans<<endl;

}


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(){
	int n;
	cin >> n;
    int m = n;
	int fx = 0;
	while(n){
		fx += n%10;
		n /= 10;
	}
	if(m%fx == 0) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
#define I inline
#define R register
#define inf 1073742823
#define FOR(i,begin,end) for(R int i=begin;i<=end;++i)
#define ROF(i,begin,end) for(R int i=begin;i>=end;--i)
map<string,int>m;
vector<string>k;
signed main(){
    int n,mx=0;
    cin>>n;
    string s;
    FOR(i,1,n){
        cin>>s;
        m[s]++;
        if(m[s]>mx){
            mx=m[s];
            k.clear();
            k.push_back(s);
        }else if(m[s]==mx){
            k.push_back(s);
        }
    }
    sort(k.begin(),k.end());
    for(auto i:k)
        cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 26736
import collections
h,w = map(int, input().split())
s = ''.join([''.join(input().split()) for _ in range(h)])

ctr = collections.Counter(s)
if h % 2 == 0 and w % 2 == 0:
    four, two = h*w//4, 0
elif h % 2 == 0:
    four, two = (h*w-h)//4, h//2
elif w % 2 == 0:
    four, two = (h*w-w)//4, w//2
else:
    four, two = (h*w-h-w+1)//4, (h+w-1)//2

cf = sum([c//4 for c in ctr.values()])
ct = sum([(c%4)//2 for c in ctr.values()])

if cf >= four and ct + 2*(cf-four) >= two:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9428
#include<iostream>

int main() {
	int a, b,c=1;

	std::cin >> a >> b;


	if (b == 100) {
		b = 101;
	}

	if (a == 0) {
		std::cout << b << std::endl;
		exit(0);
	}

	for (int i = 0; i<a; i++) {
		c = c * 100;
	}

	std::cout << c * b << std::endl;

	return 0;
}

Measured memory_bytes: 256
/// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	tmp = input[1].split(" ");
  
	//出力
  	var num = 0;
	while(true){
     var count=0;
	for(i=0;i<input[0];i++){
      
		if(Number(tmp[i])%2==0){
        	tmp[i]=Number(tmp[i])/2;
          	count = count+1;
        }else{
        	break;
        }
    }
      
    if(count!==tmp.length){
    	break;
    }
  	num ++;
    }

	console.log(num);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                A[i][j] =0
flag=0
for i in range(3):
    if A[i][0] == 0 and A[i][1] == 0 and A[i][2]==0:
        flag =1
for i in range(3):
    if A[0][i] == 0 and A[1][i] == 0 and A[2][i]==0:
        flag =1
if A[0][0] ==0 and A[1][1] ==0 and A[2][2]==0:
    flag=1
if  A[0][2] ==0 and A[1][1] ==0 and A[2][0]==0:
    flag = 1

if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064