akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#define M 200002
#define N 100001
int a[N],b[M],c[M],d[N],e[N],f[N],i,l,n,q[N],r,u,v,w,s,t;
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;i++)scanf("%d%d",&u,&v),b[++t]=a[u],c[a[u]=t]=v,b[++t]=a[v],c[a[v]=t]=u;
	for(q[l=1]=v=1,r=2;l<r;)for(i=a[u=q[l++]],v=e[v]<e[u]?u:v;i;i=b[i])if(c[i]!=f[u])e[q[r++]=c[i]]=e[f[c[i]]=u]+1;
	for(e[q[l=1]=w=v]=f[v]=0,r=2;l<r;)for(i=a[u=q[l++]],w=e[w]<e[u]?u:w;i;i=b[i])if(c[i]!=f[u])e[q[r++]=c[i]]=e[f[c[i]]=u]+1;
	for(u=w,t=0;u;u=f[u])for(i=a[u],t++;i;i=b[i])if(c[i]!=f[u])d[t]++,s++;
	if(d[1]++,++s!=n)return 0*puts("-1");
	for(u=1,v=t,s=0;v&&d[u]==d[v];u++)v--;if(v&&d[u]>d[v])for(u=1,v=t;u<v;u++,v--)d[u]^=d[v]^=d[u]^=d[v];
	for(i=1;i<=t;printf("%d%c",s-d[i]+1,i==t?'\n':' '),i++)for(s+=u=d[i];--u;)printf("%d ",s-u+1);
	return 0;
}

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

int main() {
	int N; cin >> N;
	int a[110];
	for(int i=0; i<N; ++i) cin >> a[i];
	sort(a, a + N);
	cout << a[N-1]-a[0] << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
	using System.Linq;

    class Program
    {
    	static void Main(string[] args)
    	{
    		int N = int.Parse(Console.ReadLine());
			long m = 0;
			long a = 0;
			long r = 0;
			long c = 0;
			long h = 0;
			string s;
			for (int i=0;i<N;i++){
				s = Console.ReadLine();
				if (s[0] == 'M') m++;
				else if (s[0] == 'A') a++;
				else if (s[0] == 'R') r++;
				else if (s[0] == 'C') c++;
				else if (s[0] == 'H') h++;
			}

    		// スペース区切りの整数の入力
			long ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
			Console.WriteLine(ans);
    	}
    }

Measured memory_bytes: 15188
#include<bits/stdc++.h>
using namespace std;
#define N 24
#define pb push_back
#define int long long
#define pi pair<int , int>
vector<int> edges[N];
bool visited[N];
int parent[N];
#define f first 
#define s second
int find(int x){
 if(parent[x] == -1){
 return x;
 }
 return find(parent[x]);
}
int n , m;
char grid[N][N];
map<pi , set<pi>> mp;
int dx[4] = {-1 , 1 , 0 , 0};
int dy[4] = {0 , 0 , 1 , -1};
int findd(pi st){
 queue<pi> q;
 q.push(st);
 int dp[N][N];
 memset(dp , INT_MAX , sizeof(dp));
 for(int i = 0 ; i < n ; i++){
 for(int j = 0 ; j < m ;j++){
   dp[i][j] = INT_MAX;
 }
}
 dp[st.f][st.s] = 0;
 while(q.size()){
	 pi val = q.front();
	 q.pop();
 for(int i = 0 ; i < 4 ; i++){
    int newx = val.f + dx[i];
    int newy = val.s + dy[i];
    if(newx >= 0 && newy >= 0 && newx < n && newy < m){
	      if(mp[val].find({newx , newy}) != mp[val].end()){
			  if(dp[newx][newy] > dp[val.f][val.s] + 1){
			       q.push({newx , newy});
			  }
		    dp[newx][newy] = min(dp[newx][newy] , dp[val.f][val.s] + 1);
		    
		  }
	}
 }
}
int maxi =  -1;
for(int i = 0 ; i < n ; i++){
 for(int j = 0 ; j < m ;j++){
   if(grid[i][j] == '.'){
     maxi = max(maxi , dp[i][j]);
   }
 }
}
return maxi;
}
int32_t main(){
	cin>>n>>m;
   for(int i = 0 ; i < n ;i++){
    for(int j = 0 ; j  <m ;j++){
	  cin>>grid[i][j];
	}
   }
   for(int i = 0 ; i < n ; i++){
     for(int j = 0 ; j  < m ;j++){
	   if(grid[i][j] == '.'){
	        if(i-1 >= 0 && grid[i-1][j] == '.'){
			   mp[{i , j}].insert({i-1 , j});
			    mp[{i-1 , j}].insert({i , j});
			}
			if(i+1 < n && grid[i+1][j] == '.'){
			   mp[{i , j}].insert({i+1 ,j});
			    mp[{i+1 , j}].insert({i , j});
			}
			if( j - 1 >= 0 && grid[i][j-1] == '.'){
			    mp[{i , j}].insert({i ,j-1});
			    mp[{i , j-1}].insert({i , j});
			}
			if(j+1 < m && grid[i][j+1] == '.'){
			   mp[{i , j}].insert({i ,j+1});
			    mp[{i , j+1}].insert({i , j});
			}
	   }
	 }
   }
   int maxi = -1;
   for(int i = 0 ; i < n ; i++){
     for(int j = 0 ; j  < m ;j++){
		 if(grid[i][j] == '.'){
		    maxi = max(maxi ,  findd({i , j}));
		 }
	 }
 }
 cout<<maxi<<endl;
   
}


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

typedef pair<int,int> P;
int n;

int main(){
  int V,E;cin>>V>>E;
  vector<P> edge[V];
  while(E--){
    int u,v,d;cin>>u>>v>>d;u--;v--;
    edge[u].push_back(P(v,d));
    edge[v].push_back(P(u,d));
  }
  int T;cin>>T;
  vector<int> good[T];
  for(int i=0;i<T;i++){
    cin>>n;
    if(n){
      int d;cin>>d>>d;d--;
      good[i].push_back(d);
    }
  }
  while(T--)cout<<-1<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
 	int a,b,c,jsq=1;
	cin>>a>>b;
	c=b;
	while(c)
	{
		c/=10;
		jsq*=10;
	}
	a=a*jsq+b;
	for(int i=1;i<=1000&&i*i<=a;i++)
		if(i*i==a)
		{
			cout<<"Yes\n";
			return 0;
		}	
	cout<<"No\n";
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 10005
#define P pair<int,int>
using namespace std;
ll f(ll n)
{
	ll ans=1;
while(ans<=n)
ans*=2;
return ans-1;
}
int main()
{
	
	ll h;
	ll a;
	cin >> h ;
	a=f(h);

	cout<<a<<endl;
}



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

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

	int N, K;
	N = sc.nextInt();
	K = sc.nextInt();

	int H[] = new int[N];
	for (int i = 0; i < N; i++)
	    H[i] = sc.nextInt();

	Arrays.sort(H);

	long sum = 0;
	for (int i = N - K - 1; i >= 0; i--)
	    sum += H[i];

	System.out.println(sum);
    }
}

Measured memory_bytes: 65864
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
ll mod=1000000007;
typedef pair<int, int> P;

int main()
{
    ll X,Y;
    cin >> X >> Y;
    if(abs(X-Y)>=2) cout << "Alice" << endl;
    else cout << "Brown" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	long long int arr[10];
	for (int i = 0; i < 10; i++)
	{
		scanf("%lld", &arr[i]);
	}
	int temp;
	for (int i = 0; i < 10; i++)
	{
		for (int j = i+1; j < 10; j++)
		{
			if(arr[i]<arr[j])
			{
				temp = arr[i];
				arr[i] = arr[j];
				arr[j] = temp;
			}
		}
	}
	for (int i = 0; i < 3; i++)
	{
		printf("%lld\n", arr[i]);
	}
	cin.get();
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

const int MAX = 100010;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    COMinit();
    sort(A.begin(), A.end());

    int64_t minval = 0;
    int64_t maxval = 0;
    for(int i=0; i<N; i++) {
        minval = (minval + (COM(N-1-i, K-1) * A[i]) % MOD) % MOD;
    }
    for(int i=0; i<N; i++) {
        maxval = (maxval + (COM(i, K-1) * A[i]) % MOD) % MOD;
    }

    int64_t ans = (maxval - minval) % MOD;
    if(ans < 0) {
        ans += MOD;
    }
    cout << ans << endl;
    return 0;
}


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

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

int main() {
    int N;
    cin >> N;
    vector<string> str(N, "");
    map<string, bool> m;
    REP(i, N) {
        cin >> str[i];
        if(m[str[i]]) {
            cout << "No" << endl;
            return 0;
        }
        m[str[i]] = true;
    }

    FOR(i, 1, N) {
        if(str[i - 1][str[i - 1].size() - 1] != str[i][0]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



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

typedef long long ll;

ll N;

ll BS(ll low, ll up, ll key){
    ll start = low, end = up;
    while (start<=end){
        ll mid = start + (end-start)/2;
        if (N/mid == key){
            if (N%mid == key) return mid;
            else if (N%mid > key) start = mid+1;
            else end = mid-1;
        }
        else if (N/mid > key) start = mid+1;
        else end = mid-1;
    }
    return -1;
}

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

    ll m;
    cin>>N;

    ll ans = 0;
    for (ll i=1;i*i<=N;++i){
        ll res = BS(1, N, i);
        if (res != -1) ans+=res;
    }
    cout<<ans<<endl;
    
    return 0;
}

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


int main(){
    int N, M; 


    scanf("%d %d", &N, &M);
    int p[M], AC[N], WA[N];
    char S[M][3];
     for (int i =0; i < N; i++){
        AC[i] = 0;
        WA[i] = 0;
    }
    for (int i =0; i < M; i++){
        scanf("%d %s", &p[i], S[i]);
        if (strcmp(S[i],"AC")==0){
            AC[p[i]-1] = 1;
        }
        else if (AC[p[i]-1] == 0){
            WA[p[i]-1] =WA[p[i]-1] + 1; 
        }
    }
    int sumAC=0, sumWA=0;
    for (int i = 0; i < N; i++){
        sumAC += AC[i];
        if (AC[i] ==1){
            sumWA += WA[i];
        }
    }
    printf("%d %d",sumAC,sumWA);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz size()
#define FORN(i,j,n) for(int i=j; i<(int)n;i++) 
#define FOR(i,n) FORN(i,0,n)
#define FORIT(i,x) for( auto i = x.begin() ; i != x.end() ; i++ )
#define MOD 998244353LL
#define LIM 262150
#define ones(x) __builtin_popcount(x)
#define trace(x)    cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
using namespace std;
 
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef vector <string> vs;
typedef vector <ii> vii;
ll n , k;
ll dp[100005][4];
ll arr1[100005];
ll arr2[100005];
ll arr3[100005];
int main() {
	fastio;
	cin>> n ;
	FOR(i,n) cin>> arr1[i+1] >> arr2[i+1] >> arr3[i+1];
	dp[1][1] = arr1[1];
	dp[1][2] = arr2[1];
	dp[1][3] = arr3[1];
	FORN(i,2,n+1){
		FORN(j,1,4){
		    dp[i][j] = -100000000000;
		}	
	}
	FORN(i,2,n+1){
		dp[i][1] = max(dp[i-1][2]+arr1[i],dp[i-1][3]+arr1[i]);
		dp[i][2] = max(dp[i-1][1]+arr2[i],dp[i-1][3]+arr2[i]);
		dp[i][3] = max(dp[i-1][1]+arr3[i],dp[i-1][2]+arr3[i]);
	}
	cout<< max(max(dp[n][1],dp[n][2]),dp[n][3]) << "\n";
	return 0;
}

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n,a,b; 
	cin >> n >> a >> b;
	int c,d,e,f,g;
	int m=0;
	for(int i=1; i<n+1;i++){
	c=i%10;
	d=(i/10)%10;
	e=(i/100)%10;
	f=(i/1000)%10;
	g=(i/10000)%10;
	if((c+d+e+f+g)>a-1 && (c+d+e+f+g)<b+1){
			m=m+i;
	}
}
		cout << m << endl;
return 0;
    }

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc175/tasks/abc175_c
#include <iostream>
#include <vector>
#include <deque>
#include <tuple>
#include <algorithm>
#include <iterator> // std::back_inserter
#include <climits>
#include <sstream>

using namespace std;

typedef long ll;

int main()
{
    string s, t;
    cin >> s >> t;
    ll min_diffs = LLONG_MAX;
    for (int i = 0; i < s.size() - t.size() + 1; i++)
    {
        ll diffs = 0;
        for (int j = 0; j < t.size(); j++)
        {
            if (t[j] != s[i + j])
            {
                diffs++;
            }
        }
        min_diffs = min(diffs, min_diffs);
    }
    cout << min_diffs << endl;
}


Measured memory_bytes: 3612
// AtCoder ABC067 C Factors of Factorial
// 2020.1.21 bal4u

#include <stdio.h>

typedef long long ll;

int power[1005];

int ptbl[] = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 0 };

void prime_factor(int n) {
    int b, *p;

    if ((n & 1) == 0) {
        do n >>= 1, power[2]++;
        while ((n & 1) == 0);
    }
	for (p = ptbl; n > 1 && *p > 0; p++) {
		if (n % *p) continue;
		b = *p;
		do n /= b, power[b]++;
	    while (n % b == 0);
	}
	if (n > 1) power[n]++;
}

#define MOD 1000000007

int main()
{
	int i, N, ans;
	
	scanf("%d", &N);
	if (N == 1) puts("1");
	else {
		for (i = 2; i <= N; ++i) prime_factor(i);
		ans = 1;
		for (i = 2; i <= N; ++i) {
			ans = (ll)ans * (power[i]+1) % MOD;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <stdlib.h> 
#include <stdio.h>
#include <iterator>
#include <chrono>
#include <iomanip>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <deque>
#include <stack>
#include <queue>
#include <fstream>
#include <limits>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>

using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

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

	int n, m;
	cin >> n >> m;
	vector <vector <int>> visited(n, vector <int>(m, INF));
	vector <string> grid(n);

	int x, y, x2, y2, dist, a, b;
	cin >> x >> y >> x2 >> y2;
	x--; y--; x2--; y2--;
	ffor(n) cin >> grid[i];
	visited[x][y] = 0;
	priority_queue <pair <int, pair <int, int>>> q, q2; // contains {dist, {x, y}}
	queue <pair <int, int>> bfs;
	map <pair <int, int>, bool> pushed;
	q.push({ 0, {x, y} });
	while (q.size() > 0) {
		while (q.size() > 0) {
			x = q.top().second.first, y = q.top().second.second;
			dist = q.top().first;
			q.pop();
			if (grid[x][y] == 'q') continue;
			bfs.push({ x, y });
			while (bfs.size() > 0) {
				a = bfs.front().first, b = bfs.front().second; bfs.pop();
				if (grid[a][b] == 'q') continue;

				visited[a][b] = dist;
				grid[a][b] = 'q';
				q2.push({ dist, {a, b} });
				pushed[{a, b}] = true;

				for (int i = a + 1; i < n; i++) {
					if (grid[i][b] != '.') break; // not supposed to reach this place
					if (pushed[{i, b}]) continue;
					bfs.push({ i, b });
					pushed[{i, b}] = true;
				}
				for (int i = a - 1; i >= 0; i--) {
					if (grid[i][b] != '.') break;
					if (pushed[{i, b}]) continue;
					bfs.push({ i, b });
					pushed[{i, b}] = true;
				}
				for (int i = b + 1; b < m; i++) {
					if (grid[a][i] != '.') break;
					if (pushed[{a, i}]) continue;
					bfs.push({ a, i });
					pushed[{a, i}] = true;
				}
				for (int i = b - 1; i >= 0; i--) {
					if (grid[a][i] != '.') break;
					if (pushed[{a, i}]) continue;
					bfs.push({ a, i });
					pushed[{a, i}] = true;
				}
			}
		}
		while (q2.size() > 0) {
			x = q2.top().second.first, y = q2.top().second.second, dist = q2.top().first;
			q2.pop();
			for (int i = x - 2; i <= x + 2; i++) {
				if (i < 0 || i >= n) continue;
				for (int j = y - 2; j <= y + 2; j++) {
					if (j < 0 || j >= m) continue;
					if (visited[i][j] > dist + 1 && grid[i][j] == '.') {
						visited[i][j] = dist + 1;
						q.push({ dist + 1, {i, j} });
					}
				}
			}
		}
	}
	cout << (visited[x2][y2] == INF ? -1 : visited[x2][y2]);
}
	




/*
C:\Users\User\Desktop\comp_programming\final_straw_after_this_im_switching_to_vs_code\final_straw_after_this_im_switching_to_vs_code.cpp
*/

Measured memory_bytes: 39576
#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;
    ll ans=0;
    vector<int>x(n+1,1);
    for(int i=2; i<=n; ++i){
        for(int j=i; j<=n; j+=i){
            x[j]++;
        }
    }
    for(int i=1; i<=n; ++i){
        ans+=(ll)x[i]*i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 42324
N = int(input())
X = list(map(int,input().split(" ")))
X2 = X[:]
X2.sort()
mid = (N-1)//2
l = X2[mid]
r = X2[mid+1]
for i in range(N):
	if X[i] <= l:
		print(r)
	else:
		print(l)


Measured memory_bytes: 25620
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
void mutu(int n,int z,string s) {
	if (n == 0) {
		cout << s << endl;
		return;
	}
	else {
		f(i, z + 2) {
			mutu(n - 1, max(i, z), s + char('a' + i));
		}
	}
}
signed main() {
	int n;
	cin >> n;
	mutu(n - 1, 0, "a");
}


Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 100000000

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

int memo1[33][33][33][33], memo2[33][33][33][33];

int h, w, s;
int u[33][33];
int sum[33][33];

P solve(int h1, int h2, int w1, int w2){
	if(memo1[h1][h2][w1][w2]!=0){
		return P(memo1[h1][h2][w1][w2], memo2[h1][h2][w1][w2]);
	}
	if(sum[h2][w2]-sum[h1-1][w2]-sum[h2][w1-1]+sum[h1-1][w1-1]<s){
		return P(-INF, -INF);
	}
	memo1[h1][h2][w1][w2]=1;
	memo2[h1][h2][w1][w2]=sum[h2][w2]-sum[h1-1][w2]-sum[h2][w1-1]+sum[h1-1][w1-1]-s;
	for(int i=h1; i<h2; i++){
		P p1=solve(h1, i, w1, w2), p2=solve(i+1, h2, w1, w2);
		if(memo1[h1][h2][w1][w2]<p1.first+p2.first){
			memo1[h1][h2][w1][w2]=p1.first+p2.first;
			memo2[h1][h2][w1][w2]=min(p1.second, p2.second);
		}else if(memo1[h1][h2][w1][w2]==p1.first+p2.first){
			memo2[h1][h2][w1][w2]=max(memo2[h1][h2][w1][w2], min(p1.second, p2.second));
		}
	}
	for(int j=w1; j<w2; j++){
		P p1=solve(h1, h2, w1, j), p2=solve(h1, h2, j+1, w2);
		if(memo1[h1][h2][w1][w2]<p1.first+p2.first){
			memo1[h1][h2][w1][w2]=p1.first+p2.first;
			memo2[h1][h2][w1][w2]=min(p1.second, p2.second);
		}else if(memo1[h1][h2][w1][w2]==p1.first+p2.first){
			memo2[h1][h2][w1][w2]=max(memo2[h1][h2][w1][w2], min(p1.second, p2.second));
		}
	}
	return P(memo1[h1][h2][w1][w2], memo2[h1][h2][w1][w2]);
}

int main()
{
	while(1){
		cin>>h>>w>>s;
		if(h==0 && w==0 && s==0) return 0;
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				cin>>u[i][j];
			}
		}
		for(int i=0; i<=h; i++){
			for(int j=0; j<=w; j++){
				if(i==0 || j==0){
					sum[i][j]=0;
				}else{
					sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+u[i][j];
				}
			}
		}
		s=sum[h][w]-s;
		for(int i=0; i<=h; i++){
			for(int j=i; j<=h; j++){
				for(int k=0; k<=w; k++){
					for(int l=k; l<=w; l++){
						memo1[i][j][k][l]=0, memo2[i][j][k][l]=0;
					}
				}
			}
		}
		P p=solve(1, h, 1, w);
		cout<<p.first<<" "<<p.second<<endl;
	}
	return 0;
}


Measured memory_bytes: 8144
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int sum = 1;
			for(int i=1; i <= n; i++){
				sum += i;
			}
			System.out.println(sum);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 12000
N=int(input())
A=[int(i) for i in input().split()]
def f(A):
    P=[0]*(N+1)
    S=[(-1,0)]
    for i,a in enumerate(A):
        while S[-1][1]>a:
            S.pop()
        t=i-S[-1][0]
        P[a]=t
        S.append((i,a))
    return P
P=f(A)
Q=f(A[::-1])
print(sum(a*P[a]*Q[a] for a in A))

Measured memory_bytes: 95056
/*-----------Author: Araz Jabrayilov---------*/
/*------------@araz17----(~~)#5371-----------*/

#include <bits/stdc++.h>

#define ll long long
#define endl '\n'

using namespace std;

int a[105];


int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int x = 0;
    int y = 0;
    int z = 0;

  cin >> x >> y >> z;

  cout << z << " "<< x << " "<< y << endl;






    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    if (A <= 5)
    {
        cout << 0 << endl;
    }
    else if (A >= 13)
    {
        cout << B << endl;
    }
    else
    {
        cout << B / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
N = gets.to_i
SCs = N.times.map{s, c = gets.split; [s, c.to_i]}

class String
  def pal?
    size > 0 &&(1 .. size/2).all?{|i|self[i - 1] == self[size - i]}
  end
end
class Word
  include Comparable
  attr_accessor :l, :r, :c

  def initialize(l, r, c)
    @l, @r, @c = l, r, c
  end

  def <=>(other)
    other.c <=> @c
  end
end

class PriorityQueue
  def initialize
    @q = [nil]
  end

  def bubble_up(i)
    pi = i / 2
    return if i <= 1 || @q[pi] >= @q[i]
    @q[i], @q[pi] = @q[pi], @q[i]
    bubble_up(pi)
  end

  def add(e)
    @q << e
    bubble_up(@q.size - 1)
  end

  def bubble_down(i)
    ci = i * 2
    return if ci > @q.size - 1
    ci += 1 if ci != @q.size - 1 && @q[ci] < @q[ci + 1]
    return if @q[i] >= @q[ci]
    @q[i], @q[ci] = @q[ci], @q[i]
    bubble_down(ci)
  end

  def pop
    @q[1], @q[-1] = @q[-1], @q[1]
    ret = @q.pop
    bubble_down(1)
    ret
  end

  def empty?
    @q.size == 1
  end
end

hs, hp = {}, {}
q = PriorityQueue.new
SCs.each{|s, c| q.add(Word.new(s, "", c)); q.add(Word.new("", s, c))}
while !q.empty?
  w = q.pop
  l, r, d = w.l, w.r, w.c
  ls, rs = l.length, r.length
  lr = l + r
  (puts d; exit) if lr.length > 0 && lr.pal?
  if ls > rs
    sf = l[rs, ls - rs].reverse
    next if hs[sf]
    hs[sf] = true
    SCs.select{|s, _| x, y = [s, sf].sort_by(&:length); y.end_with?(x)}.each{|s, c| q.add(Word.new(l, s + r, c + d))}
  else
    pf = r[0, rs - ls].reverse
    next if hs[pf]
    hp[pf] = true
    SCs.select{|s, _| x, y = [s, pf].sort_by(&:length); y.start_with?(x)}.each{|s, c| q.add(Word.new(l + s, r, c + d))}
  end
end
puts -1

Measured memory_bytes: 14572
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int x; cin>>x;
    int y; cin>>y;
    ll ans = 0;
    ans += 100000 * max(0, 4-x);
    ans += 100000 * max(0, 4-y);
    if (x + y == 2){
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H,N;
int A[10010];
int B[10010];
int dp[1010][20010];
int main(void){
    cin>>H>>N;
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
    }
    for(int i=0;i<=N;i++){
        for(int j=0;j<=20000;j++){
            dp[i][j]=1000000007;
        }
        dp[i][0]=0;
    }
    //dp[0][0]=0;
    //dp[i][j]
    //i番目までの魔法を使ったとき、モンスターのHPをちょうどj減らすために必要な魔力の最小値
    for(int i=0;i<N;i++){
        for(int j=0;j<=20000;j++){
            if (j>=A[i]){
                //dp[i+1][j]=min(1,2);
                dp[i+1][j]=min(min(dp[i][j-A[i]]+B[i],dp[i+1][j-A[i]]+B[i]),dp[i][j]);
            }
            else{
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            }
        }
    }
    /*
    for(int i=0;i<=N;i++){
        cout<<i<<endl;
        for(int j=0;j<=2*H+1;j++){
            if (dp[i][j]==1000000007){
                //cout<<0<<" ";
            }
            else{
                cout<<j<<" "<<dp[i][j]<<endl;
            }
        }
        cout<<endl;
    }
    */
    
    int ans=1000000007;
    for(int j=H;j<=20000;j++){
        ans=min(ans,dp[N][j]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 78464
import java.util.Scanner;

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


Measured memory_bytes: 26124
# -*- coding: utf-8 -*-
import fractions
 
mod = 10**9+7
 
n = int(input())
a = list(map(int, input().split()))
 
div = a[0]
for i in a[1:]:
    div = div*i//fractions.gcd(div, i)

ans = 0
for i in a:
    ans += div//i

print(ans%mod)


Measured memory_bytes: 6200
#include <stdio.h>

int main(){
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int b;
scanf("%d",&b);

printf("%d",a[b-1]);
}







Measured memory_bytes: 128
#include <iostream>
#include <string.h>
using namespace std;

int main(int args, char *argv[])
{
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    if (a + b >= c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
 
    vector<ll>a(5005);
    vector<ll>b(5005);
    vector<ll>track;
    bool vis[5005];
 
    void dfs(int u , long long total_cycle){
        if(vis[u]) return ;
        vis[u]=true;
        total_cycle+=b[u];
        track.push_back(total_cycle);
        dfs(a[u],total_cycle);
    }
    void solve(){
        int n,k;
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>a[i];
            a[i]--;
        }
        for(int i=0;i<n;i++)
            cin>>b[i];
        ll ans=-(1e18);
        for(int i=0;i<n;i++){
            memset(vis,false,sizeof(vis));
            dfs(i,0);
            if(track.back()>0 && k>=(int)(track.size())){
                ll cycles=(ll)(k/(int)track.size());
                ll left=(ll)(k%(int)track.size());
                ll maxi=-1e18;
                for(int x=0;x<(int)track.size();x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles-1LL)*(track.back())+maxi);
                maxi=-1e18;
                for(int x=0;x<left;x++)
                    maxi=max(maxi,track[x]);
                ans=max(ans,(cycles*track.back()) + maxi);
            }
            else{
                for(int j=0;j<(min((int)track.size(),k));j++){
                    ans=max(ans,track[j]);
                }
            }
            track.clear();
        }
        cout<<ans;
        return;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 4016
N = int(input())
A = [int(a) for a in input().split()]

dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
        
A.sort(reverse=True)
ans = 0
for a in A:
    if dic[a] == 0:
        continue
    dic[a] -= 1
    num = pow(2, len(bin(a))-2) - a
    if num in dic and dic[num] > 0:
        ans += 1
        dic[num] -= 1

print(ans)

Measured memory_bytes: 33696
from collections import defaultdict
n = int(input())
ans = 0
divide_minimam_prime = [i for i in range(n + 1)]
is_prime = [True for i in range(n + 1)]
is_prime[0] = False
is_prime[1] = False
for div in range(2,int(n**0.5) + 1):
    if is_prime[div]:
        # divが素数だった場合
        k = div
        divide_minimam_prime[k] = k
        k += div
        while k <= n:
            is_prime[k] = False
            if divide_minimam_prime[k] == k:
                divide_minimam_prime[k] = div
            k += div
for i in range(1,n):
    k = i
    use_divnum = defaultdict(int)
    while k != 1:
        div = divide_minimam_prime[k]
        while k % div == 0 and k > 1:
            k = k // div
            use_divnum[div] += 1
    count = 1

    for j in use_divnum.values():
        count *= j + 1
    ans += count
print(ans)

Measured memory_bytes: 166432
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N,K; cin>>N>>K;
    vector<int> a(N),b(N);
    for(int i=0;i<N;i++) cin>>a[i];
    for(int i=0;i<N;i++) cin>>b[i];

    int sum=accumulate(a.begin(),a.end(),0LL);
    if(K>=sum){
        cout<<0<<endl;
        return 0;
    }

    // cout<<"Hello"<<endl;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end(),greater<int>());
    function<bool(int)> check=[&](int X){
        // cout<<X<<endl;
        int cnt=0;
        for(int i=0;i<N;i++){
            int k=max(a[i]-X/b[i],0LL);
            cnt+=k;
        }
        // cout<<X<<' '<<cnt<<endl;
        return cnt<=K;
    };

    int ng=-1,ok=1e12;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        if(check(mid)) ok=mid;
        else ng=mid;
    }
    cout<<ok<<endl;
    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,ans;
vector<ll>v;
int main(){
    cin >> n;
    
    for(ll i=2; i<=sqrt(n); i++){
        if(n%i == 0){
            v.pb(i);
            if(i * i != n){
                v.pb(n / i);
            }
        }
    }
    if(n != 1)v.pb(n);
    
    for(int xD=0; xD<v.size(); xD++){
        ll x = v[xD];
        if(n == x * (n / (x - 1)))ans += x - 1;
    }
    
    cout << ans;
    
    
    
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        int K = int.Parse(Console.ReadLine());
        Console.WriteLine(UsingList(s, K));
        // Console.WriteLine(UsingHashSetOrderBy(s, K));
        // Console.WriteLine(UsingSortedSet(s, K));
    }

    // List→IEnumerable→IOrderedEnumerable
    static string UsingList(string s, int K)
    {
        List<string> list = new List<string>();
        for (int len = 1; len <= Math.Min(s.Length, 5); len++)
        {
            for (int i = 0; i <= s.Length - len; i++)
            {
                list.Add(s.Substring(i, len));
            }
        }
        var list_d = list.Distinct();
        var ranking = list_d.OrderBy(i => i);
        return ranking.ElementAt(K - 1);
    }

    // HashSet→IOrderedEnumerable
    static string UsingHashSetOrderBy(string s, int K)
    {
        HashSet<string> hs = new HashSet<string>();
        for (int len = 1; len <= Math.Min(s.Length, 5); len++)
        {
            for (int i = 0; i <= s.Length - len; i++)
            {
                hs.Add(s.Substring(i, len));
            }
        }
        var ranking = hs.OrderBy(i => i);
        return ranking.ElementAt(K - 1);
    }

    // SortedSetのみ！
    static string UsingSortedSet(string s, int K)
    {
        SortedSet<string> ss = new SortedSet<string>();
        for (int len = 1; len <= Math.Min(s.Length, 5); len++)
        {
            for (int i = 0; i <= s.Length - len; i++)
            {
                ss.Add(s.Substring(i, len));
            }
        }
        return ss.ElementAt(K - 1);
    }
}


Measured memory_bytes: 15456
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
int main(void){
    int N,X;
    cin>>N>>X;
    int L[N];
    for(int i=0;i<N;i++){
        cin>>L[i];
    }
    long long int D=0;
    int count=1;
    for(int i=1;i<N+1;i++){
        D=D+L[i-1];
        if(D<=X){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ ll.cpp -o ll.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

   string s;
   cin>>s;
   ll l;
   l=s.size();
   if(s[l-1]=='s')
    cout<<s<<"es"<<endl;
else
    cout<<s<<"s"<<endl;



    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;
/**==Info==
*Program:4
*Problem:Fennec Vs Snuke
*Date:2017-8-12
*Algorithm:Teacher's Vector DFS
*Stats:Unknown*/
int n;
vector<int> nei[100005];
vector<int> path;
int cnt[100005],can;

void dfs(int root,int parent){
	cnt[root]=1;
	path.push_back(root);
	if(root==n-1){
		can=path[(path.size()+1)/2];
	}
	for(int i=0;i<nei[root].size();i++){
		if(nei[root][i]==parent) continue;
		dfs(nei[root][i],root);
		cnt[root]+=cnt[nei[root][i]];
	}
	path.pop_back();
}
int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	
	can=-1;
	dfs(0,-1);
	bool ohYES=cnt[can]*2<n;
	cout<<(ohYES?"Fennec":"Snuke");
	
	return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	char c;int n=0;
	while(cin>>c){
		n=(n+(c-'0'))%9;
	}
	if(n==0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 400001
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};

ll modpow(ll x,ll n){
    if(n<0)return 1;
    if(n==0) return 1;
    ll res=modpow(x*x,n/2);
    if(n&1) res=res*x;
    return res;
}
main(){
    int n=in();
    int a[N];
    rep(i,n)a[i]=in();
    bool flag=true;
    rep(i,n-1)if(a[i]>=a[i+1])flag=false;
    if(flag){cout<<1;return 0;}
    int l=1,r=n;
    while(l<r-1){
        int mid=l+r>>1;
        flag=true;
        map<int,int>mp;
        rep2(i,1,n-1){
            if(a[i]>a[i-1])continue;
            int temp=a[i];
            mp.erase(mp.upper_bound(a[i]),mp.end());
            while(1){
                mp[temp]++;
                if(mp[temp]==mid){
                    mp[temp]=0;
                    --temp;
                }
                else break;
            }
            if(mp[0])flag=false;
        }
        (flag?r=mid:l=mid);
    }
  cout<<r;
}


Measured memory_bytes: 1024
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val N = StdIn.readLine().toInt
    val An = StdIn.readLine().split(" ").map(_.toInt)
    println(An.zipWithIndex.count { case (a, i) => An(a - 1) == (i+1) } / 2)
  }
}


Measured memory_bytes: 36312
#include <iostream>
#include <algorithm>

#define rep(i,n)    for(int i=0;i<n;i++)
#define INF         ( 1<<20 )

using namespace std;

int costs[11][11];

int main()
{
	int N;
	while(cin>>N,N)
	{
		rep(i,11)rep(j,11)costs[i][j]=INF;
		rep(i,11)costs[i][i]=0;

		int n_city = 0;
		rep(i,N)
		{
			int a, b, c;
			cin>>a>>b>>c;
			costs[a][b] = costs[b][a] = c;
			n_city = max(n_city, max(a, b));
		}
		n_city++;

		rep(k,n_city)rep(i,n_city)rep(j,n_city)
		{
			costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]);
		}

		int min_cost = INF, min_city = -1;
		rep(i,n_city)
		{
			int sum = 0;
			rep(j,n_city) sum += costs[i][j];
			if (sum < min_cost)
			{
				min_cost = sum;
				min_city = i;
			}
		}
		cout << min_city << " " << min_cost << endl;
	}
	return 0;
}

Measured memory_bytes: 0
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

LL N,W;
LL w[100],v[100];

LL ans = 0;
 
void solve(){
	//i個目までを見たときに
	//価値の総和がjになるような選び方があるなら
	//その重みの最小値をdp[i][j]とする
	vector<vector<LL>> dp(N+1,vector<LL>(100001,INF));
	dp[0][0] = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<=100000;j++){
			//何も取らないとき
			dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
			//とるとき
			if(j+v[i]<=100000 && dp[i][j]+w[i]<=W){
				dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
				ans = max(ans,j+v[i]);
			}
		}
	}
}
 
int main(){
	cin >> N >> W;
	for(int i=0;i<N;i++) cin >> w[i] >> v[i];
 
	solve();
 
	cout << ans << endl;
	return 0;
}

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

using LL = long long;

int main() {
  LL N;
  cin >> N;
  vector<LL> A(N), B(N);
  for(auto& i: A) cin >> i;
  for(auto& i: B) cin >> i;

  auto sum = 0ll;

  for(auto i=0; i<30; ++i) {
    auto T = (1ll << i);

    auto C = B;
    for(auto& i: C) i %= 2*T;
    sort(begin(C), end(C));
    auto count = [&](auto l, auto h) {
      auto n = lower_bound(begin(C), end(C), h) - lower_bound(begin(C), end(C), l);
      return (n&1) << i;
    };

    for(auto a: A) {
      a %= 2*T;
      sum ^= count(max(0ll,T-a), 2*T-a);
      sum ^= count(3*T-a, 4*T-a);
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 4992
//include
//------------------------------------------
#include <string>
#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 <cstring>
#include <ctime>

// namespace
using namespace std;

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

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

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

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

#define MAX_VALUE 9223372036854775807

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

	cin >> cs;

	ll rs = 0;
	REPD(i, 0, n) {
		if (cs[i] == 'R') ++rs;
	}

	ll res = 0;
	REPD(i, 0, rs) {
		if (cs[i] == 'W') ++res;
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define rez(v, n) (v).clear(), (v).resize(n)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

template<class T> struct Min {
  T nil;
  Min(){}
  Min(T nil):nil(nil){}
  T operator()(T a, T b) {
    return a < b ? a : b;
  }
};
template<class T> struct Max {
  T nil;
  Max(){}
  Max(T nil):nil(nil){}
  T operator()(T a, T b) {
    return a > b ? a : b;
  }
};

template<class T, class F>
struct SegmentTree {
  vector<T> data;
  F func;
  int sz;
  SegmentTree(int n, F f) {
    func = f;
    sz = 1; while(sz < n) sz <<= 1;
    data.resize(2*sz+1, func.nil);
  }
  void update(int k, T x) {
    k += sz-1;
    data[k] = x;
    while(k > 0) {
      k = (k-1)/2;
      data[k] = func(data[2*k+1], data[2*k+2]);
    }
  }
  T query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return func.nil;
    if(a <= l && r <= b) return data[k];
    return func(query(a, b, 2*k+1, l, (l+r)/2),
	       query(a, b, 2*k+2, (l+r)/2, r));
  }
  T query(int a, int b) {
    return query(a, b, 0, 0, sz);
  }
};

int N, L;
vint A, B, C, D;
vint sumC, sumD;
vint idx;

bool cmp(int i, int j) {
  return D[i] > D[j];
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> L;
  rez(A, N), rez(B, N), rez(C, N), rez(D, N);
  rep(i, N) {
    cin >> A[i] >> B[i];
    D[i] = A[i]-B[i];
  }
  rep(i, N) {
    cin >> C[i];
  }

  rez(idx, N);
  rep(i, N) idx[i] = i;
  sort(all(idx), cmp);
  rez(sumC, N+1), rez(sumD, N+1);
  rep(i, N) {
    sumD[i+1] = sumD[i] + D[idx[i]];
    sumC[i+1] = sumC[i] + C[i];
  }

  SegmentTree< int, Max<int> > segA(N, Max<int>(-inf)), segB(N, Max<int>(-inf));
  rep(i, N) {
    int k = idx[i];
    segA.update(i, A[k]);
    segB.update(i, B[k]);
  }

  SegmentTree< int, Min<int> > segX(N, Min<int>(inf));
  rep(i, N) {
    segX.update(i, sumD[i+1]-sumC[i+1]);
  }

  int ans = inf;
  rep(i, N) {
    int a = segA.query(i, N);
    if(sumD[i]+a >= L) {
      //cout<<sumD[i]+a<<" "<<L<<endl;
      chmin(ans, i);
      break;
    }

    //cout<<"BIN_SEARCH"<<endl;
    int lb = -1, ub = i;
    while(lb+1 < ub) {
      int mb = (lb+ub)/2;
      //cout<<idx[mb]<<" "<<idx[i]<<endl;
      //cout<<segX.query(mb, i) << " "<< D[idx[mb]]-D[idx[i]]<<endl;
      if(segX.query(mb, i) > D[idx[mb]]-D[idx[i]]) ub = mb;
      else lb = mb;
    }
    int b = segB.query(ub, i);
    if(b != -inf) {
      //cout<<"OK"<<endl;
      //cout << ub << " " << b << endl;
      //cout<<sumD[i+1]<<" " << b << endl;
      if(sumD[i+1]+b >= L) {
	chmin(ans, i);
	break;
      }
    }
    if(sumD[i+1] <= sumC[i+1]) break;
  }

  cout << (ans == inf ? -1 : ans+1) << endl;

  return 0;
}

Measured memory_bytes: 14396
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def get_init(n: int):
    left = 0
    right = n-1
    dic = {}
    
    
    print(left, flush=True)
    s = ns()
    if s == 'Vacant':
        exit()
    elif s == 'Male':
        dic.update({0: 'Male'})
    else:
        dic.update({0: 'Female'})
        
        
    print(right, flush=True)
    s = ns()
    if s == 'Vacant':
        exit()
    elif s == 'Male':
        dic.update({1: 'Male'})
    else:
        dic.update({1: 'Female'})
        
    return dic

def search(n:int, dic: dict):
    left = 0
    right = n-1
    
    while right-left > 1:
        middle = (right+left)//2
        print(middle, flush=True)
        s = ns()
        if s == 'Vacant':
            exit()
        elif s == dic[middle%2]:
            left = middle
        else:
            right = middle
            
    print(left, flush=True)
    s = ns()
    if s == 'Vacant':
        exit()
        
    print(right, flush=True)
    s = ns()
    if s == 'Vacant':
        exit()
            

n = ni()

dic = get_init(n)
search(n, dic)

Measured memory_bytes: 3788