akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;

bool visit[100001];
ll dist[100001]; // kからの距離
vector<tuple<int, ll>> edges[100001];

void dfs(int s) {
  visit[s] = true;
  for (int i = 0; i < edges[s].size(); ++i) {
    int to;
    ll c;
    tie(to, c) = edges[s][i];
    if (visit[to]) continue;
    dist[to] = dist[s] + c;
    dfs(to);
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n-1; ++i) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    edges[a].emplace_back(b, c);
    edges[b].emplace_back(a, c);
  }
  int q, k;
  cin >> q >> k;
  k--;
  dfs(k);
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << dist[x]+dist[y] << endl;
  }
}



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

const int N = (int)2e5 + 500;
typedef long long ll;
const ll INF = (ll)1e18;

int n;
int num[N];
ll psum[N];

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

    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> num[i];
        num[i] -= i;
    }
    sort(num+1, num+1+n);
    for(int i = 1; i <= n; i++) psum[i] = psum[i-1] + num[i];
    ll res = INF;
    for(int i = 1; i <= n; i++){
        ll cur = (psum[n] - psum[i] - 1LL * (n - i) * num[i]) - (psum[i-1] - 1LL * (i-1) * num[i]);
        res = min(cur, res);
    }
    cout << res;

}

Measured memory_bytes: 2560
import numpy as np

N = int(input())
A = list(map(int,input().split()))

if N % 2 == 0:
    C = int(N / 2)
else:
    C = int((N+1)/2)


for j in range(0,N):
    A[j] = A[j]-j-1

A1 = np.array(A)

B = np.sort(A1)

if B[C-1] > 0:
    d = B[C-1]
    B2 = B - d
    print(sum(np.abs(B2)))
else:
    d = -B[C-1]
    B2 = B + d
    print(sum(np.abs(B2)))

Measured memory_bytes: 34224
#include <stdio.h>

int main() {
    int R, G, B, N, r,g,b;
    while (scanf("%d %d %d %d", &R, &G, &B, &N) != EOF) {
        int cnt = 0;
        int tb = 0, tr=0, tg=0;
        for (r = 0,tr=0; tr <= N; r++, tr += R) {
            for (g= 0,tg=0; tg <= N-tr; g++, tg += G) {
                    if ((N-tg-tr) % B == 0) {
                        cnt++;
                    }

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

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	string S;
	long cnt0start = 0, cnt1start = 0;

	cin >> S;
	for (long i = 0; S[i] != '\0'; i++) {
		/* code */

		if (i%2 == 0)
		{
			if (S[i] == '0') cnt1start++;
			else
			{
			cnt0start++;
			}
		}
		else
		{
			if (S[i] == '0') cnt0start++;
			else
			{
				cnt1start++;
			}
		}
	}

	long ans = min(cnt0start, cnt1start);
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main()
{
    int a, b;
    scanf("%d %d",&a, &b);

    if(a*b == 15 && a+b == 15) printf("x");

    else if(a+b == 15) printf("+");
    else if(a*b == 15) printf("*");
    else printf("x");

    return 0;
}

Measured memory_bytes: 128
// created by anaksoleh
// 27 Feb 2020
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<double,double> pd;

ll Sn(ll n){
    return (n*(1 + n))/2;
}

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

    int N;
    cin >> N;
    vector<string> v(N);
    for(int i = 0 ; i < N ; i++){
        cin >> v[i];
        sort(v[i].begin(),v[i].end());
    }

    sort(v.begin(),v.end());
    string curr = v[0];
    ll cnt = 0;
    ll ans = 0;
    for(int i = 1 ; i < N ; i++){
        if(curr == v[i]){
            cnt++;
        }else{
            ans += Sn(cnt);
            curr = v[i];
            cnt = 0;
        }
    }
    ans += Sn(cnt);
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std ;

struct Node
{
	int P ;
	int C ;
	Node ( ) { }
	Node ( int a , int b )
	{
		P = a ;
		C = b ;
	}
	bool operator < ( const Node &a ) const
	{
		return C > a.C ;
	}
} ;

vector < int > ListofRoad [110] ;
vector < int > ListofTime [110] ;
vector < int > ListofCost [110] ;

int CostAns [110][110] ;
int TimeAns [110][110] ;
bool vis[110] ;

void init ( ) ;
void Dijkstra ( int , int , int ) ;

int main ( )
{
	int n ;
	int m ;
	while ( scanf ( "%d %d" , &n , &m ) == 2 && ( n || m ) )
	{
		init ( ) ;
		for ( int i = 0 ; i < n ; i++ )
		{
			int a ;
			int b ;
			int c ;
			int d ;
			scanf ( "%d %d %d %d" , &a , &b , &c , &d ) ;
			ListofRoad[a].push_back ( b ) ;
			ListofCost[a].push_back ( c ) ;
			ListofTime[a].push_back ( d ) ;
			ListofRoad[b].push_back ( a ) ;
			ListofCost[b].push_back ( c ) ;
			ListofTime[b].push_back ( d ) ;
		}
		int Q ;
		scanf ( "%d" , &Q ) ;
		while ( Q-- )
		{
			int p ;
			int q ;
			int r ;
			scanf ( "%d %d %d" , &p , &q , &r ) ;
			if ( CostAns[p][1] == -1 && TimeAns[p][1] == -1 )
			{
				Dijkstra ( p , m , 0 ) ;
				Dijkstra ( p , m , 1 ) ;
			}
			if ( r == 0 )
			{
				printf ( "%d\n" , CostAns[p][q] ) ;
			}
			else
			{
				printf ( "%d\n" , TimeAns[p][q] ) ;
			}
		}
	}
	return 0 ;
}

void init ( )
{
	for ( int i = 0 ; i < 110 ; i++ )
	{
		ListofRoad[i].clear ( ) ;
		ListofTime[i].clear ( ) ;
		ListofCost[i].clear ( ) ;
	}
	memset ( CostAns , -1 , 110 * 110 * sizeof ( int ) ) ;
	memset ( TimeAns , -1 , 110 * 110 * sizeof ( int ) ) ;
}

void Dijkstra ( int source , int m , int type )
{
	memset ( vis , false , 110 * sizeof ( bool ) ) ;
	priority_queue < struct Node > pQ ;
	if ( type == 0 )
	{
		TimeAns[source][source] = 0 ;
	}
	else
	{
		CostAns[source][source] = 0 ;
	}
	pQ.push ( Node ( source , 0 ) ) ;
	for ( int i = 1 ; i <= m ; i++ )
	{
		struct Node var = ( struct Node ) { -1 , -1 } ;
		while ( pQ.empty ( ) == false && vis[( var = pQ.top ( ) ).P] == true )
		{
			pQ.pop ( ) ;
		}
		if ( var.P == -1 )
		{
			break ;
		}
		vis[var.P] = true ;
		if ( type == 0 )
		{
			vector < int > :: iterator iu = ListofTime[var.P].begin ( ) ;
			for ( vector < int > :: iterator it = ListofRoad[var.P].begin ( ) ;
				it != ListofRoad[var.P].end ( ) ;
				it++ , iu++ )
			{
				if ( vis[*it] == false )
				{
					if ( TimeAns[source][*it] == -1 || ( TimeAns[source][*it] > var.C + *( iu ) ) )
					{
						TimeAns[source][*it] = var.C + *( iu ) ;
						pQ.push ( Node ( *it , TimeAns[source][*it] ) ) ;
					}
				}
			}
		}
		else
		{
			vector < int > :: iterator iu = ListofCost[var.P].begin ( ) ;
			for ( vector < int > :: iterator it = ListofRoad[var.P].begin ( ) ;
				it != ListofRoad[var.P].end ( ) ;
				it++ , iu++ )
			{
				if ( vis[*it] == false )
				{
					if ( CostAns[source][*it] == -1 || ( CostAns[source][*it] > var.C + *( iu ) ) )
					{
						CostAns[source][*it] = var.C + *( iu ) ;
						pQ.push ( Node ( *it , CostAns[source][*it] ) ) ;
					}
				}
			}
		}
	}
}

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

const int INF=1000000000;


int main(){
    int n;
    cin>>n;
    int w[n];
    int s=0,t=0;
    rep(i,n){
        cin>>w[i];
        t+=w[i];
    }
    int dif=INF;
    rep(i,n){
        s+=w[i];
        t-=w[i];
        dif=min(dif,abs(s-t));
    }
    cout<<dif<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<functional>

#define LLI long long int

using namespace std;

int N,Q;
vector<vector<int> >V;
vector<vector<int> >child;
vector<int>x;
vector<bool> done;
vector<int>ans;
void dps1(int now){
	done[now]=true;
	for(int i=0;i<V[now].size();i++){
		if(done[V[now][i]]){
				continue;
		}else{
			child[now].push_back(V[now][i]);
			dps1(V[now][i]);
		}
	}
}
void dps2(int now,int count=0){
	count+=x[now];
	ans[now]=count;
	for(int i=0;i<child[now].size();i++){
		dps2(child[now][i],count);
	}
}
int main(){
	cin>>N>>Q;
	V=vector<vector<int> >(N+1);
	for(int i=1;i<N;i++){
		int a,b;cin>>a>>b;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	x=vector<int>(N+1,0);
	for(int i=0;i<Q;i++){
		int p,xx;
		cin>>p>>xx;
		x[p]+=xx;
	}
	child=vector<vector<int> >(N+1);
	done=vector<bool>(N+1,false);
	dps1(1);
	ans=vector<int>(N+1);	
	//for(int i=0;i<N+1;i++)for(int j=0;j<child[i].size();j++)cout<<child[i][j];
	for(int i=0;i<done.size();i++)done[i]=false;
	dps2(1);
	
	for(int i=1;i<N;i++)cout<<ans[i]<<" ";
	cout<<ans[N]<<endl;
	return 0;
}



Measured memory_bytes: 35200
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] bou = new int[N];
		for( int i=0; i<N; i++ ){
			bou[i]=sc.nextInt();
		}
		Arrays.sort(bou);        
		int count=0;
		for( int i=0; i<N-2; i++ ){
			for( int j=i+1; j<N-1; j++ ){
				for( int k=j+1; k<N; k++ ){
					if( bou[k]<bou[i]+bou[j] ){
						count++;
					}           
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 26592
/**
 *    author:  FromDihPout
 *    created: 2020-08-19
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        sum += x - 1;
    }
    cout << sum << '\n';
}

Measured memory_bytes: 3624
while True:
  h, w = map(int, input().split())
  if not h:
    break

  mp = [input() for _ in range(h)]
  visited = [[False for _ in range(w)] for _ in range(h)]
  x, y = 0, 0

  while True:
    if visited[y][x]:
      print("LOOP")
      break

    tile = mp[y][x]

    if tile == ".":
      print(x, y)
      break
    
    visited[y][x] = True

    if tile == ">":
      x += 1
    elif tile == "<":
      x -= 1
    elif tile == "^":
      y -= 1
    else:
      y += 1


Measured memory_bytes: 5792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int h,w;
    while(cin >> h >> w && (h != 0 || w != 0))
    {
        for(int i = 0;i < h;i++)
        {
            for(int j = 0;j < w;j++)
            {
                if((i + j) % 2 == 0)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << "\n";
        }
        cout << "\n";
    }
    
    return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define Mp make_pair
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

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

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 17
ll binpow(ll x, ll y) {
	ll z = 1;
	while(y > 0) {
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
// a^-1 (mod m) = a^(m-2) (mod m) - m is prime
ll inv(ll x) {return binpow(x, MOD - 2);}
ll divide(ll x, ll y) {return x* inv(y);}

// ************* MAIN *******************

ll N, C; 
int A[1000005];

void solve() {
    cin>>N;
    C= N;
    memset(A,0,sizeof(A));
    ll f = 2;
    while (f <= sqrt(N)) {
        while (N%f==0) {
            A[f]++;
            N/=f;
        }
        f++;
    }
    int ans=(N>1);
    REP(i,2,sqrt(C)) {
        if (A[i]==0) continue;
        int l = 1, r = 45, re = 1;
        while(l<=r) {
            int m = (l+r)/2;
            if (AritSum(1,1,m) <= A[i]) {
                re = m;
                l = m + 1;
            } else r = m - 1;
        }
        ans+=re;
    }
    cout << ans << endl;
}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test

./Test < in
*/
int main() {
    int _=1;
    // cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << solve() << endl;
    }
    return 0;
}


Measured memory_bytes: 7576
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>

using namespace std;

void chkmap(int w, int h, int x, int y, int map[50][50]) {
	if(map[x][y] == 0) return;
	map[x][y] = 0;
	if(x + 1 < w) chkmap(w,h,x+1,y,map);
	if(x > 0)	  chkmap(w,h,x-1,y,map);
	if(y + 1 < h) chkmap(w,h,x,y+1,map);
	if(y > 0)	  chkmap(w,h,x,y-1,map);
	if(x + 1 < w && y + 1 < h) chkmap(w,h,x+1,y+1,map);
	if(x + 1 < w && y > 0)	   chkmap(w,h,x+1,y-1,map);
	if(x > 0 && y + 1 < h)     chkmap(w,h,x-1,y+1,map);
	if(x > 0 && y > 0)		   chkmap(w,h,x-1,y-1,map);
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1) {

		int w, h, ans = 0;
		int map[50][50];
		cin >> w >> h;

		if( w == 0 && h == 0 ) break;	//終了処理

		//マップ読み取り
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j ++) {
				int tmp;
				cin >> tmp;
				map[j][i] = tmp;
			}
		}


		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if(map[j][i] == 1) ans ++;
				chkmap(w,h,j,i,map);
			}
		}

		cout << ans << endl;
	}

	
	//while(1){}
	return 0;
}

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

int main() {
	int n;
	char b[2];
	map<string,int> m;
	
	m["A"]=0;
	m["B"]=0;
	m["AB"]=0;
	m["O"]=0;
	
	while(~scanf("%d,%s",&n,b)){
		m[b]++;
	}
	
	printf("%d\n",m["A"]);
	printf("%d\n",m["B"]);
	printf("%d\n",m["AB"]);
	printf("%d\n",m["O"]);
	
	return 0;
}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    for(int i=0;i<n-2;i++){
        if(a[i]>a[i+1]&&a[i+1]>a[i+2]) ans++;
        if(a[i]<a[i+1]&&a[i+1]<a[i+2]) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}








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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

int n, m, q;
vvi g(100000 + 5);
map<pair<int, int>, int> e;
pair<int, int> con[200000 + 5];
int dist[100000 + 5];
vector<bool> visited(100000 + 5), connected(200000 + 5);
int Query[200000 + 5];
int cnt;



void dfs(int now, vector<bool>& vistied) {
    cnt++;
    visited[now] = true;
    for (auto nx : g[now]) {
        if (dist[nx] == dist[now] + 1) {
            if (!visited[nx] && connected[e[{min(nx, now), max(nx, now)}]]) {
                dfs(nx, visited);
            }
        }
    }
    return;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        e[{a, b}] = i;
        con[i] = {a, b};
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> que;
    fill(dist, dist + n, INF);
    que.push(0);
    dist[0] = 0;
    visited[0] = true;
    while(!que.empty()) {
        int now = que.front(); que.pop();
        for (auto nx: g[now]) {
            if (dist[nx] >= dist[now] + 1) {
                if (!visited[nx]) que.push(nx);
                dist[nx] = dist[now] + 1;
                visited[nx] = true;
                connected[e[{min(now, nx), max(now, nx)}]] = true;
            }
        }
    }
    rep(i, q) {
        cin >> Query[i];
        Query[i]--;
        connected[Query[i]] = false;
    }
    fill(all(visited), false);
    vector<int> ans;
    dfs(0, visited);
    rrep2(i, q - 1, -1) {
        ans.push_back(n - cnt);
        pair<int, int> p = con[Query[i]];
        if (visited[p.fi] && visited[p.se]) continue;
        if (dist[p.fi] > dist[p.se]) swap(p.fi, p.se);
        if (dist[p.fi] == dist[p.se] || dist[p.fi] + 1 < dist[p.se]) continue;
        connected[Query[i]] = true;
        if (visited[p.fi] && !visited[p.se]) {
            dfs(p.se, visited);
        }
    }
    reverse(all(ans));
    rep(i, q) cout << ans[i] << endl;
}

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

#define pb push_back

const int N = 3e3+5;

int dp[N][N];
string s , t;
vector<char> resp;

int LCS(int x , int y){
  if(x < 0 || y < 0) return 0;
  if(dp[x][y] != -1) return dp[x][y];
  if(s[x] == t[y]) return dp[x][y] = 1 + LCS(x-1,y-1);
  return dp[x][y] = max(LCS(x-1,y),LCS(x,y-1));
}

main(){
  cin >> s >> t;
  for(int i = 0 ; i < N ; i++)
    for(int j = 0 ; j < N ; j++) dp[i][j] = -1;
  LCS(s.size()-1,t.size()-1);

  int x = s.size() - 1 , y = t.size() - 1;
  while(x >= 0 && y >= 0){
    if(x == 0 || y == 0){
      if(s[x] == t[y]) resp.pb(s[x]) , x-- , y--;
      else if(x > 0) x--;
      else if(y > 0) y--;
      else break;
    }
    else if(dp[x][y] == dp[x-1][y]) x--;
    else if(dp[x][y] == dp[x][y-1]) y--;
    else if(dp[x][y] == dp[x-1][y-1] + 1) resp.pb(s[x]) , x-- , y--;
  }
  //cout << dp[s.size()-1][t.size()-1] << "\n";
  for(int i = resp.size() - 1 ; i >= 0 ; i--) cout << resp[i];
  cout << "\n";
}

Measured memory_bytes: 35840
#include <iostream>
/*#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>*/
using namespace std;

int main() {
	long long X;
	cin >> X;
	long long ans;
	for (long long i = -1000; i < 1001; i++) {
		for (long long j = -1000; j < 1001; j++) {
			ans = i * i * i * i * i - j * j * j * j * j;
			if (ans == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}


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

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int a = cin.NextInt();
			int b = cin.NextInt();
			int m = cin.NextInt();
			var aa = new int[a];
			var bb = new int[b];
			var x = new int[m];
			var y = new int[m];
			var c = new int[m];
            for (int i = 0; i < a; i++)
            {
				aa[i] = cin.NextInt();
            }
            for (int i = 0; i < b; i++)
            {
				bb[i] = cin.NextInt();
            }
            for (int i = 0; i < m; i++)
            {
				x[i] = cin.NextInt();
				y[i] = cin.NextInt();
				c[i] = cin.NextInt();
            }
			var ans = int.MaxValue;
            for (int i = 0; i < m; i++)
            {
				ans = Math.Min(ans, aa[x[i] - 1] + bb[y[i] - 1] - c[i]);
            }
			Array.Sort(aa);
			Array.Sort(bb);
			ans = Math.Min(ans, aa[0] + bb[0]);
            Console.WriteLine(ans);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 33244
A, B, C, X, Y = map(int,input().split())
value = 0
ans = []
ans.append(max(X,Y) * 2*C)
if X > 0 and Y > 0 and A + B > 2*C:
    m = min(X, Y)
    value += m * 2*C
    X = X - m
    Y = Y - m
value += (X * A + Y * B)
ans.append(value)
print(min(ans))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct Node{
  int key;
  struct Node *parent;
  struct Node *right;
  struct Node *left;

};

typedef struct Node* node;
node root; 


void insert(int k){
  node x,y,z;
  y = NIL;
  x = root;
  z = malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right = NIL;


  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x = x->left;
    }
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key)  y->left=z;
  else y->right = z;
}     

void inorder(node u){
  if(u->left!=NIL) 
    inorder(u->left);
  printf(" %d",u->key);
  if(u->right!=NIL) 
    inorder(u->right);
}

void preorder(node u){
  printf(" %d",u->key);   
  if(u->left!=NIL) 
    preorder(u->left);
  if(u->right!=NIL) 
    preorder(u->right);
}


int main(){
  int i,n,x;
  char a[5];

  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",a);
    if(a[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(a[0]=='p'){
      if(root!=NIL) 
	inorder(root);
      printf("\n");
      if(root!=NIL)
	preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
import bisect
n = int(input())
A =[]


for i in range(n):
  A.append(int(input()))

L = [A[0]]

for i in A:
  if L[-1] < i:
    L.append(i)
  else:
    L[bisect.bisect_left(L, i)] = i

print(len(L))


Measured memory_bytes: 10352
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int sum = 0;
        int n = in.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        int c[] = new int[n-1];
        for(int i=0;i<n;i++) a[i] = in.nextInt();
        for(int i=0;i<n;i++) b[i] = in.nextInt();
        for(int i=0;i<n-1;i++) c[i] = in.nextInt();
        for(int i=0;i<n;i++){
            sum+=b[a[i]-1];
            if(i>0){
                if(a[i-1]==a[i]-1){
                    sum+=c[a[i]-2];
                }
            }
        }
        out.println(sum);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21204
N = int(input())
# N = 100
# 素因数を足し合わせてみる
divisors = [0]*(N+1)
# 素因数分解(小さい方から順に割っていく)
for j in range(2,N+1):
    s = 0
    L = j
    while s == 0:
        for i in range(2,N+1):
            if L % i == 0:
                divisors[i] += 1
                L //= i
                if L == 1:
                    s = 1 #1はこれ以上素因数を産まない
                break
    # print("{}!:{}".format(j,divisors))

# 3パターン
# 75　*　1 パターン
# 25 * 3 パターン
# 5 * 15 パターン
# 5 * 5 * 3 パターン
list75 = [i for i,div in enumerate(divisors) if 74 <= div and i > 1]
list25 = [i for i,div in enumerate(divisors) if 24 <= div and i > 1]
list15 = [i for i,div in enumerate(divisors) if 14 <= div and i > 1]
list5 = [i for i,div in enumerate(divisors) if 4 <= div and i > 1]
list3 = [i for i,div in enumerate(divisors) if 2 <= div and i > 1]
# list2 = [i for i,div in enumerate(divisors) if 1 <= div and i > 1]
# print(list75)
# print(list25)
# print(list15)
# print(list5)
# print(list3)
# print(len(list75),len(list25),len(list15),len(list5),len(list3))
n75 = len(list75)
n25 = len(list25)
n15 = len(list15)
n5 = len(list5)
n3 = len(list3)
print(n75 + n25*(n3-1) + n15*(n5-1) + n5*(n5-1)//2*(n3-2))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <list>
#include <tuple>
#include <string>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////
#define mktp make_tuple
 

int H,W;
int a[505][505];
typedef struct {
    int y;
    int x;
} POs;
POs A,B,C;

vector<tuple<int,int,int,int>> ans;

//#define forx(A,B,C,D) for((B%2?C:D);))


void output(POs ap,POs bp){
    C=ap;
    while(C.y!=bp.y){
        for(;(C.y%2?C.x>1:C.x<W);C.x+=(C.y%2?-1:1)){
            ans.push_back(mktp(C.y,C.x,C.y,C.x+(C.y%2?-1:1)));
        //printf("%d %d %d %d\n",C.x,C.y,C.x-1,C.y);
        }
        ans.push_back(mktp(C.y,C.x,C.y-1,C.x));
        C.y--;
    }
    for(;(C.y%2?C.x>bp.x:C.x<bp.x);C.x+=(C.y%2?-1:1)){
            ans.push_back(mktp(C.y,C.x,C.y,C.x+(C.y%2?-1:1)));
        //printf("%d %d %d %d\n",C.x,C.y,C.x-1,C.y);
    }
}

int main(){
    scanf("%d%d",&H,&W);
    fornum(i,0,H){
        fornum(j,0,W){
            scanf("%d",&a[i][j]);
            a[i][j]%=2;
        }
    }
    B={999,999};
    A={999,999};
    for(i=1;i<=H;i++){
        for(j=(i%2?1:W);(i%2?j<=W:j>=1);j+=(i%2?1:-1)){
            if(a[i-1][j-1]==0)
                continue;
            if(A.x!=999){
                output({i,j},A);
                A={999,999};
            }else{
                A={i,j};
            }
        }
    }
    /*
    fornum(i,0,H){
        A={999,999};
        fornum(j,0,W){
            //printf("%d %d %d %d %d\n",i,j,a[i][j],A.x,A.y);
            if(a[i][j]==0)
                continue;
            if(A.x!=999){
                output({i+1,j+1},A);
                A={999,999};
            }else if(B.x<=j){
                output({i+1,j+1},B);
                B={999,999};
            }else {
                A={i+1,j+1};
            }
        }
        if(A.x!=999){
            if(B.x!=999){
                
                output(B,{B.y,W});
                output({B.y,W},A);
                B={999,999};
            }else{
                B=A;
            }
        }
    }
    */
    printf("%d\n",(int)(ans.size()));
    for(i=0;i<ans.size();i++){
        auto tp=ans[i];
        //for(j=0;j<4;j++){
        //    printf("%d ",get<j>(tp));
        //}
        printf("%d %d %d %d\n",get<0>(tp),get<1>(tp),get<2>(tp),get<3>(tp));
    }
    return 0;
}

Measured memory_bytes: 5232
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

int solve() {
	ll n;
	cin >> n;

	map<ll, ll> primes;

	ll sqrtn = sqrt(n) + 1LL;
	vector<ll> is_primes(sqrtn + 1, true);
	for (ll p = 2; p <= sqrtn; ++p) {
		if (n % p != 0LL) continue;
		for (ll j = 2; p * j <= sqrtn; ++j) {
			is_primes[p * j] = false;
		}
		while (n % p == 0) {
			if (primes.count(p) == 0) primes[p] = 0;
			++primes[p];
			n /= p;
		}
	}
	if (n != 1) {
		if (primes.count(n) == 0) primes[n] = 0;
		++primes[n];
	}

	ll res = 0;
	for (auto iter = primes.begin(); iter != primes.end(); ++iter) {
		ll count = iter->second;
		for (ll i = 0;; ++i) {
			if (count < i + 1) break;
			count -= i + 1;
			++res;
		}
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 11132
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<math.h>
#include<iomanip>

using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; ++i)


int dp[433][433][433][3];

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> rg,ry,gr,gy,yr,yg;
    int R=0, G=0, Y=0;
    rep(i,n){
        if(s[i]=='R'){
            ++R;
            rg.push_back(G);
            ry.push_back(Y);
        }
        if(s[i]=='G'){
            ++G;
            gr.push_back(R);
            gy.push_back(Y);
        }
        if(s[i]=='Y'){
            ++Y;
            yg.push_back(G);
            yr.push_back(R);
        }
    }
    rep(i,R+1)rep(j,G+1)rep(k,Y+1)rep(l,3)dp[i][j][k][l]=1e9;
    dp[0][0][0][0]=0;
    dp[0][0][0][1]=0;
    dp[0][0][0][2]=0;
    rep(i,R+1)rep(j,G+1)rep(k,Y+1)rep(l,3){
        if(i!=R&&l!=0){
            dp[i+1][j][k][0]=min(dp[i+1][j][k][0], dp[i][j][k][l]+max(rg[i]-j,0)+max(ry[i]-k,0));
        }
        if(j!=G&&l!=1){
            dp[i][j+1][k][1]=min(dp[i][j+1][k][1], dp[i][j][k][l]+max(gr[j]-i,0)+max(gy[j]-k,0));
        }
        if(k!=Y&&l!=2){
            dp[i][j][k+1][2]=min(dp[i][j][k+1][2], dp[i][j][k][l]+max(yr[k]-i,0)+max(yg[k]-j,0));
        }
    }
    int ans = 1e9;
    rep(i,3)ans=min(ans,dp[R][G][Y][i]);
    if(ans==1e9)cout<<-1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 165100
#include <iostream>
#define REP(i, a, n) for(int i = a; i <= n; i++)
#define SIZE 1001
#define MOD 1000000007
using namespace std;


int N;
bool prime[SIZE];
int pfact[SIZE];
int p;
long ans;

int main(void) {
  cin >> N;

  REP(i, 1, N) prime[i] = true;
  prime[1] = false;
  REP(i, 1, N) {
    if(!prime[i]) continue;
    REP(j, 2, N / i) prime[i * j] = false;
  }

  REP(i, 1, N) pfact[i] = 0;
  REP(i, 1, N) {
    p = i;
    REP(j, 1, N) {
      if(!prime[j]) continue;
      while(p % j == 0) {
        p /= j;
        pfact[j]++;
      }
    }
  }

  ans = 1;
  REP(i, 1, N) {
    ans *= (pfact[i] + 1);
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
s = input()
n = len(s)

white, black, ans = 0, 0, 0
for i in range(1, n):
    if s[-i] == 'W':
        black = 0
        white += 1
        if s[-i-1] == 'B':
            if i == n-1:
                black += 1
                ans += black*white
    else:
        black += 1
        if s[-i-1] == 'B':
            if i == n-1:
                black += 1
                ans += black*white
        else:
            ans += black*white
print(ans)

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

using namespace std;

int main()

{


    int a,b,c,k,s=0;

    cin>>a>>b>>c>>k;
    if(a>k)
    s=s+k;
    else{

        k=k-a;
        k=k-b;
         s=s+a*1+(k*0);
         //;
        if(k>0)

        s=s+k*(-1);

    }


    cout<<s<<"\n";
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

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

    int N = sc.nextInt();
    int K = sc.nextInt();
    int h;
    int counter = 0;
    for (int i = 0; i < N; i++) {
      h = sc.nextInt();
      if (h >= K) {
        counter++;
      }
    }
    System.out.println(counter);
  }
}


Measured memory_bytes: 45884
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {
    int n; cin >> n;
    int A = 0, C = 0;
    ll ans = 0;
    vector<ll> a(n),b(n),c(n),ma(n),mc(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    //進めるだけ進めて、位置を記録しておいてそこから再開すればとける。
    rep(i,b.size()){
        while(A < n && a[A] < b[i]){
            A ++;
        }
        ma[i] = A;
    }
    for(int i = b.size()-1; i >= 0; i --){
        while(C < n && b[i] < c[n-1-C]){
            C ++;
        }
        mc[i] = C;
    }

    rep(i,n) ans += mc[i]*ma[i];

    cout << ans;

}


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

int main()
{
    int n, l;
    cin >> n >> l;
    int ans = -1;
    int a[100002];
    cin >> a[0];
    for(int i = 1; i < n; i++){
        cin >> a[i];
        if(a[i - 1] + a[i] >= l) ans = i;
    }
    if(ans == -1) cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        for(int i = 1; i < ans; i++) cout << i << endl;
        for(int i = n - 1; i >= ans; i--) cout << i << endl;
    }
}

Measured memory_bytes: 1152
#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 <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int a, b;
    cin>>a>>b;
    cout<<a+b/2<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;


int main()
{
	int n, i, j, s1 = 0, s2, s = 0, sa = 1000000;
	int a[150] = {0};

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (i = 0; i < n; i++) {
		s += a[i];
	}
	for (i = 0; i < n; i++) {
		s1 += a[i];
		s2 = s - s1;
		if (abs(s1 - s2) < sa) {
			sa = abs(s1 - s2);
		}
	}
	cout << sa << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;

ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
ll h,w;
ll nowx,nowy;
char field[30][30];

void bfs(){
    ll d[30][30];
    queue<pll> que;
    rep(i,h)rep(j,w) d[i][j]=0;
    d[nowx][nowy]=1;
    que.push(pll(nowx,nowy));
    ll ans=1;
    while(!que.empty()){
        pll p = que.front();
        que.pop();
        rep(i,4){
            ll nx = p.first + dx[i] , ny = p.second + dy[i];
            if( nx>=0 && nx <h && ny >=0 && ny < w  && d[nx][ny] == 0 ){
                if(field[nx][ny]=='.'){
                    que.push(pll(nx,ny));
                    ans++;
                }
                d[nx][ny]=1;
            }
        }
    }
    cout<<ans<<endl;
    return ;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    
    while(true){
        cin>>w>>h;
        if(w==0&&h==0) break;
        rep(i,h)rep(j,w){
            cin>>field[i][j];
            if(field[i][j]=='@') {
                nowx=i,nowy=j;
            }
        }
        bfs();
    }
    return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> edges(N);
  while(M--)
  {
    int a, b;
    std::cin >> a >> b;
    --a;
    --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  std::vector<int> ans(N, -1);
  ans[0] = 0;
  std::queue<int> q;
  q.push(0);
  while(!q.empty())
  {
    auto x = q.front();
    q.pop();
    for(auto& val: edges[x])
    {
      if(ans[val] < 0)
      {
        ans[val] = x;
        q.push(val);
      }
    }
  }
  auto it = std::find(ans.begin(), ans.end(), -1);
  if(it != ans.end())
    std::cout << "No" << std::endl;
  else
  {
    std::cout << "Yes" << "\n";
    for(int i = 1; i < ans.size(); ++i)
      std::cout << ans[i]+1 << "\n";
  }
  return 0;
}



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

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

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    int inp[n];
    int total = 0;
    for (int i = 0; i < n; i++)
        scanf("%d", &inp[i]), total += inp[i];

    int target = (total + 4 * m - 1) / (4 * m);
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (inp[i] >= target)
            ans++;

    if (ans >= m)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef queue<int> qi;

int main() {
    ios::sync_with_stdio(false);

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

    vi ans;
    for (int i = 0; i < n; i++) {
        int v[n];
        fill(v, v + n, -1);
        qi q;
        for (int y : e[i]) {
            v[y] = i;
            q.push(y);
        }
        while (!q.empty()) {
            int x = q.front();
            q.pop();

            if (x == i) {
                vi t;
                x = v[x];
                while (x != i) {
                    t.push_back(x);
                    x = v[x];
                }
                t.push_back(i);
                
                if (ans.size() == 0 || t.size() < ans.size()) {
                    ans = t;
                }
                
                break;
            }

            for (int y : e[x]) {
                if (v[y] == -1) {
                    v[y] = x;
                    q.push(y);
                }
            }
        }
    }

    if (ans.size()) {
        cout << ans.size() << endl;
        for (int i = ans.size() - 1; i >= 0; i--) {
            cout << ans[i] + 1 << endl;
        }
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 384
m, n = gets.split.map(&:to_i)
k = gets.to_i
joi = Array.new(m)
m.times do |i|
  joi[i] = gets.chomp
end
js = Array.new(m){ Array.new(n, 0) }
os = Array.new(m){ Array.new(n, 0) }
is = Array.new(m){ Array.new(n, 0) }
m.times do |i|
  n.times do |j|
    if joi[i][j] == 'J' then js[i][j] = 1
    elsif joi[i][j] == 'O' then os[i][j] = 1
    else is[i][j] = 1
    end
  end
end
m.times do |i|
  (1...n).each do |j|
    js[i][j] += js[i][j-1]
    os[i][j] += os[i][j-1]
    is[i][j] += is[i][j-1]
  end
end

k.times do
  a, b, c, d = gets.split.map(&:to_i)
  jc, oc, ic = 0, 0, 0
  (a-1..c-1).each do |i|
    jc += b > 1 ? js[i][d-1] - js[i][b-2] : js[i][d-1]
    oc += b > 1 ? os[i][d-1] - os[i][b-2] : os[i][d-1]
    ic += b > 1 ? is[i][d-1] - is[i][b-2] : is[i][d-1]
  end
  puts "#{jc} #{oc} #{ic}"
end

Measured memory_bytes: 33944
//g++  5.4.0
 
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define L(p) 2*p+1
#define R(p) 2*p+2

const int mod = 1e9+7;

signed main()
{
    fast;
    int n , k;
    cin >> n >> k;
    
    vector<int> dp(k+2,0);
    dp[0] = 1;
    while( n-- )
    {
        int x;
        cin >> x;
        vector<int> a(k+2,0);
        for(int p = k-1 ; p >= 0 ; p-- )
        {
            int l = p+1;
            int h = min(p+x+1,k+1);
            a[l] += dp[p];
            a[h] -= dp[p];
            a[h] += mod;
            a[l] %= mod;
            a[h] %= mod;   
        }
        for(int i=1 ; i<=k ; i++ )
        {
            a[i] += a[i-1];
            a[i] %= mod;
            dp[i] += a[i];
            dp[i] %= mod;
            
        }
        
    }
    cout << dp[ k ];
}

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

int main(void){
    int count[101]={0};
    int a;
    while(cin>>a){
        count[a]+=1;
    }
    int max=0;
    for(int i=1;i<=100;i++){
        if (count[i]>max){
            max=count[i];
        }
    }
    for(int i=1;i<=100;i++){
        if(count[i]==max){
            cout<<i<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

#ifndef ONLINE_JUDGE
template<typename T>
void printerr(T a){std::cout<<a<<std::endl;}
template<typename T,typename... Args>
void printerr(T a, Args... args) {std::cout<<a<<' ',printerr(args...);}
#else
template<typename... Args>
void printerr(Args... args){}
#endif

using namespace std;
const int MM = 1e6+9;

int n;
char s[MM];

vector<pair<int, int>> pos, neg;

int main(){
    
    scanf("%d", &n);
    
    for(int j = 0; j < n; j++){
        scanf("%s", s);
        int m = strlen(s);
        int mn = 0, sum = 0;
        for(int i = 0; i < m; i++){
            if(s[i] == '(')
                sum++;
            else
                sum--;
            mn = min(mn, sum);
        }
//        print(-mn, sum);
        if(sum >= 0)
            pos.emplace_back(-mn, sum);
        else
            neg.emplace_back(-mn, sum);
    }
    sort(all(pos));
    reverse(all(pos));
    
    int sum = 0;
    
    while(pos.size() and pos.back().first <= sum){
        sum += pos.back().second;
        pos.pop_back();
    }
    if(pos.size()){
        return puts("No"), 0;
    }
    
    sort(all(neg), [](auto x, auto y){
        return x.first+x.second > y.first+y.second;
    });
    
    for(int i = 0; i < neg.size(); i++){
//        print(neg[i].first, neg[i].second, sum);
        if(neg[i].first > sum)
            return puts("No"), 0;
        
        sum += neg[i].second;
    }
    
    puts(sum ? "No" : "Yes");

    return 0;
}
/*

5
()(
(
))
))(
(())(

 */

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n;
ll res = 0;

ll c2(int n) {
    return 1LL * n * (n + 1 ) / 2;
}

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

    cin >> n;
    res = 1LL * n * (n + 1) / 2 * n;
    rep(i, 0, n - 1) {
        int a, b; cin >> a >> b; a--, b--;
        if(a > b) swap(a, b);
        res -= 1LL * (a + 1) * (n - b);
    }
    rep(i, 0, n) res -= 1LL * (c2(i) + c2(n - 1 - i));
    cout << res << endl;
}

Measured memory_bytes: 3652