akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>

#define div1 1000000007

using namespace std;

int main(void)
{
    long long n, a[200001], b[200001], change[200001], i;

    cin >> n;

    for(i=1; i<=n; i++){
        cin >> a[i];
    }

    if(n == 1){
        cout << a[1];
    }

    else if(n % 2 == 0){
        for(i=1; i<=n/2; i++){
            cout << a[n-((i-1)*2)] << " ";
        }

        for(i=1; i<=n/2; i++){
            cout << a[1+((i-1)*2)] << " ";
        }
    }

    else{
        for(i=1; i<=n/2+1; i++){
            cout << a[n-((i-1)*2)] << " ";
        }

        for(i=1; i<=n/2; i++){
            cout << a[i*2] << " ";
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3712
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  char s[301];
  cin>>s;
  int ln=strlen(s);
  int a[256];
  memset(a,0,sizeof(a));
  for(i=0;i<ln;i++)
    a[(int)s[i]]++;
  cout<<min(min(min(a['K'],a['U']),a['P']),a['C'])<<endl;
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main()
{
	int d=read(),t=read(),s=read();
	if(t*s>=d)
		puts("Yes");
	else
		puts("No");
	return 0;
} 


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  int num=0;
  int n = s.size();
  for(int i=0; i<n; i=i+2){
  if(s[i]!='L'){
  num++;
  }
  }
   for(int j=1; j<n; j=j+2){
     if(s[j]!='R'){
       num++;
     }
  }
  
  if(num==n){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (string s; cin >> s&&s != "-";) {
		int m; cin >> m;
		for (int i = 0; i < m; i++) {
			int a; cin >> a;
			s = s.substr(a, s.size() - a) + s.substr(0, a);
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
N = int(input())
A = map(int, input().split())

A_plus = []
A_minus = []

for a in A:
    if a >= 0:
        A_plus.append(a)
    else:
        A_minus.append(a)

A_plus = sorted(A_plus)
A_minus = sorted(A_minus)


if len(A_minus) % 2 == 0:
    res = sum(A_plus) - sum(A_minus)
else:
    if len(A_plus) > 0:
        res = sum(A_plus) - sum(A_minus) - 2*min(A_plus[0], (-1)*A_minus[-1])
    else:
        res = sum(A_plus) - sum(A_minus) + 2*A_minus[-1]

print(res)


Measured memory_bytes: 85976
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] num = new int[n];
			for (int i = 0; i < n; i++)
				num[i] = scanner.nextInt();
			int cnt = 0;
			for (int i = 1; i < n; i++) {
				if (num[i] - num[i - 1] == 1)
					cnt++;
				else {
					if (cnt == 0)
						System.out.print(num[i - 1] + " ");
					else {
						System.out.print(num[i - cnt - 1] + "-" + num[i - 1]
								+ " ");
						cnt = 0;
					}
				}
			}
			if (cnt == 0)
				System.out.println(num[n - 1]);
			else
				System.out.println(num[n - 1 - cnt] + "-" + num[n - 1]);
		}
	}
}

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

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

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

    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    int dp[n + 1][m + 1] = {};
    ii pi[n + 1][m + 1];

    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (s[i - 1] == t[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1; // (i - 1, j - 1) => (i, j)
          pi[i][j] = ii(i - 1, j - 1);
        } else {
          if (dp[i - 1][j] >= dp[i][j - 1]) {
            dp[i][j] = dp[i - 1][j];
            pi[i][j] = ii(i - 1, j);
          } else {
            dp[i][j] = dp[i][j - 1];
            pi[i][j] = ii(i, j - 1);
          }
        }
      }
    }
    int i = n, j = m;
    string res = "";
    while (true) {
      auto p = pi[i][j];
      int pi = p.first, pj = p.second;
      if (dp[i][j] > dp[pi][pj]) {
        res = s[pi] + res;
      }
      if (!pi && !pj)
        break;
      i = pi, j = pj;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 105856
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, M; long long K;
	cin >> N;
	vector<int> X(N);
	for (int i = 0; i < N; ++i) cin >> X[i];
	cin >> M >> K;
	vector<int> perm(N - 1);
	for (int i = 0; i < N - 1; ++i) perm[i] = i;
	for (int i = 0; i < M; ++i) {
		int A;
		cin >> A;
		swap(perm[A - 2], perm[A - 1]);
	}
	vector<int> p(N - 1);
	for (int i = 0; i < N - 1; ++i) p[i] = i;
	for (int i = 0; i < 60; ++i) {
		if ((K >> i) & 1) {
			vector<int> nxtp(N - 1);
			for (int j = 0; j < N - 1; ++j) {
				nxtp[j] = p[perm[j]];
			}
			p = nxtp;
		}
		vector<int> nxtperm(N - 1);
		for (int j = 0; j < N - 1; ++j) {
			nxtperm[j] = perm[perm[j]];
		}
		perm = nxtperm;
	}
	long long ans = X[0];
	for (int i = 0; i < N; ++i) {
		cout << ans << '\n';
		if (i != N - 1) ans += X[p[i] + 1] - X[p[i]];
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int M = N;
  int x = 0;
  
  while (M > 0){
    x += M % 10;
    M = (M - M % 10) / 10;
  }
  
  if (N % x == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
string s,t;
int c=0;
int sfind(int m)
{
	for(int i=0;i<t.length();i++)
		s[i+m]=t[i];
	return 0;
}
int find(int m)
{
	int i;
	for(i=0;i<t.length();i++)
	{
		if(s[i+m]!=t[i]&&s[i+m]!='?')
			return 0;
	}
	return 1;
}
int main ()
{
	cin>>s>>t;
	for(int i=s.length()-t.length();i>=0;i--)
	{
		if(find(i))
			{
				c++;
			}
		if(c!=0)
		{
			sfind(i);
			break;
		}
	}
	if(c==0)
	{
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='?')
			cout<<"a";
		else
			cout<<s[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
int main(void)
{
	int cards[4][13] = {0};
	int i,j,n;
	char c;
	
	scanf("%d", &n); 
	while(n)
	{
		scanf(" %c %d", &c, &j);
		
		if(c == 'S') i = 0;  
		else if(c == 'H') i = 1; 
		else if(c == 'C') i = 2;
		else  i = 3;  
		
		cards[i][j-1] = 1; 
		n--;   
	}
	
	for(i=0; i<4; i++)
	{
		for(j=0; j<13; j++)
		{ 
			if(cards[i][j] == 0)
			{      
				if(i == 0)  c = 'S'; 
				else if(i == 1)  c = 'H';
				else if(i == 2)  c = 'C';  
				else  c = 'D';
				
				printf("%c %d\n",c,j+1);  
			}
		}
	}
	return 0; 
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, D;
  cin >> N >> D;
  vector<vector<int>> x(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> x[i][j];
    }
  }
  vector<int> f(40 * 40 * D + 1);
  dump((int)sqrt(f.size()) + 1);
  for (int i = 1; i < (int)sqrt(f.size()) + 1; i++) {
    if (i * i < f.size()) {
      f[i * i] = 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i; j < N; j++) {
      int sum = 0;
      for (int k = 0; k < D; k++) {
        int sub = abs(x[i][k] - x[j][k]);
        sum += (sub * sub);
      }
      if (f[sum])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

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

const string YES = "";
const string NO  = "";

typedef long long ll;

int N,K;

void solve() {

}
const ll mod = 1000000007;
int main() {
  cin >> N >> K;
  vector<ll> sum;
  rep(i,N+1) sum.pb(i);
  REP(i,1,N+1) sum[i] += sum[i-1];
  //rep(i,(int)sum.size()) cout << i << "-th: " << sum[i] << endl;
  ll ans = 0;
  REP(i,K,N+2) {
    ll mini = sum[i-1];
    ll maxi = sum.back();
    if( (int)sum.size()-1-i >= 0 ) maxi -= sum[(int)sum.size()-i-1];
    ans += ( ( maxi - mini + 1LL ) % mod );
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int keta(int x) {
    int res = 0;
    while (x) {
        res++;
        x /= 10;
    }
    return res;
}

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (keta(i) % 2 == 1)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


typedef struct Point{
  ll t;
  ll x;
  ll y;
}point;

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

  ll N; cin >> N; 

  vector<point> P;
  rep(i,N){
    ll t,x,y; 
    cin >> t >> x >> y;
    point inp;
    inp.t = t, inp.x = x, inp.y = y;
    P.pb(inp);
  }


  rep(i,P.size()){
    ll a, b;
    if(i == 0){
      a = P[i].t;
      b = abs(P[i].x) + abs(P[i].y);
    }
    else{
      a = P[i].t- P[i-1].t;
      b = abs(P[i].x - P[i-1].x) + abs(P[i].y - P[i-1].y);
    }
    if((a<b) || ((a-b)%2 == 1)){
      cerr << i << " " << a << " " << b << endl; 
      cout <<"No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int main(){
  ll N; cin>>N;
  ll h = N/2;
  map<ll,ll> v1_count;
  map<ll,ll> v2_count;
  ll low = pow(10,5)+1;
  ll high = 0;
  REP(i,N){
    ll v; cin>>v;
    if(v<low){low = v;}
    if(v>high){high = v;}
    if(i%2==0){ v1_count[v]++; }
    else{ v2_count[v]++; }
  }
  ll v1_m1 = 0;
  ll v1_idx1;
  ll v1_m2 = 0;
  ll v2_m1 = 0;
  ll v2_idx1;
  ll v2_m2 = 0;
  for(int i=low; i<=high;++i){
    if(v1_count[i]>v1_m1){
      v1_m2 = v1_m1;
      v1_m1 = v1_count[i];
      v1_idx1 = i;
    }else if(v1_count[i]>v1_m2){
      v1_m2 = v1_count[i];
    }
    if(v2_count[i]>v2_m1){
      v2_m2 = v2_m1;
      v2_m1 = v2_count[i];
      v2_idx1 = i;
    }else if(v2_count[i]>v2_m2){
      v2_m2 = v2_count[i];
    }
  }
  ll r;
  if(v1_idx1!=v2_idx1){ r = N - v1_m1 - v2_m1; }
  else{ r = N - max( v1_m1 + v2_m2, v1_m2 + v2_m1); }
  cout << r<<"\n";
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
using namespace std;

int main(){
  string S;
  cin >> S;
  vector<int> a(26, 0);
  for(int i = 0; i < S.size(); i++){
    a[S[i]-'a']++;
  }
  int odd = 0;
  for(int i = 0; i < 26; i++){
    if(a[i] % 2 == 1)odd++;
  }

  if(S.size() % 2) {
    assert(odd > 0);
    odd--;
  }

  cout << (odd) % 2 + (odd) / 2 << endl;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
double PI=acos(-1.0);
signed main(){
    vector<ll>a(3);
    rep(i,3)cin>>a[i];
    sort(all(a));
    if(a[0]==a[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(void){
   int n,k;
   cin >> n >> k;
   vector<int> a(n);
   for(int i=0;i<n;i++){
       cin >> a[i];
   }
   for(int i=0;i<n;i++){
       if((k-1)*(i-1) + k >= n){
            cout << i << endl;
            break;
       }
   }
}


Measured memory_bytes: 640
#include <stdio.h>

int m, n;
int arr[90][90];

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

int dfs(int y, int x) {
  int i;
  if (arr[y][x] == 0) return 0;
  arr[y][x] = 0;

  int ans = 0, a;
  for (i = 0; i < 4; ++i) {
    int py, px;

    py = y + dy[i];
    px = x + dx[i];

    if (py < 0 || px < 0 || py >= m || px >= n) continue;

    a = dfs(py, px);

    if (ans < a) ans = a;
  }
  arr[y][x] = 1;

  return ans + 1;
}

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

    if (m * n == 0) return 0;

    int i, j, ans = 0, k;
    for (i = 0; i < m; ++i) {
      for (j = 0; j < n; ++j) {
        scanf("%d", &arr[i][j]);
      }
    }

    for (i = 0; i < m; ++i) {
      for (j = 0; j < n; ++j) {
        k = dfs(i, j);

        if (k > ans) ans = k;
      }
    }

    printf("%d\n", ans);
  }
}


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

int main() {
    int ans = 0;
    int N;
    cin >> N;
    vector<char> c(N);
    int count_W = 0, count_R = 0;
    rep(i, N) {
        cin >> c[i];
        if(c[i] == 'W')
            count_W++;
        else
            count_R++;
    }
    rep(i, count_R) {
        if(c[i] == 'W')
            ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    int n = gcd(a,b);
    (c%n==0)? cout << "YES":cout << "NO";

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 30000
using namespace std;

int n, p, a[N];
int main()
{
	int i;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%d", &p);
		a[p] = i - n;
	}
	for (i = 1; i <= n; i++) printf("%d ", a[i] + i * N);
	puts("");
	for (i = 0; i < n; i++) printf("%d ", (n - i) * N);
    return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
#define LL long long
#define maxn 100005
using namespace std;
struct node { int v; LL l[2]; };
int n,m,s,t;
LL dist[2][maxn],ans[maxn];
vector<node> G[maxn];
queue<int> q;
bool inq[maxn];
void spfa(int s,int d)
{
	memset(dist[d],0x3f,sizeof(dist[d]));
	memset(inq,0,sizeof(inq));
	dist[d][s]=0;inq[s]=true;
	while(!q.empty()) q.pop();
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		inq[u]=false;
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].v,di=G[u][i].l[d];
			if(dist[d][v]>dist[d][u]+di)
			{
				dist[d][v]=dist[d][u]+di;
				if(!inq[v]) { inq[v]=true; q.push(v); }
			}
		}
	}
}
int main()
{
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=1;i<=m;i++)
	{
		int u;
		node p;
		scanf("%d%d%lld%lld",&u,&p.v,&p.l[0],&p.l[1]);
		G[u].push_back(p);
		swap(u,p.v);
		G[u].push_back(p);
	}
	spfa(s,0);spfa(t,1);
	ans[n]=dist[0][n]+dist[1][n];
	for(int i=n-1;i>0;i--) ans[i]=min(dist[0][i]+dist[1][i],ans[i+1]);
	for(int i=1;i<=n;i++) printf("%lld\n",(long long)(1e15)-ans[i]);
}

Measured memory_bytes: 13184
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

class Pair {

public:
	char first;
	int second;

	Pair(char ch, int a) {
		first = ch;
		second = a;
	}
};

int targetsecond;

bool PairCom(const Pair& A) {
	return targetsecond == A.second;
}

int main()
{
	string ground;

	cin >> ground;

	//タイルの種類と高さ 最初のタイルが高さ0
	vector<Pair> data;

	for (int i = 0; i < ground.size(); i++) {
		
		int y = (i > 0) ? data[i - 1].second : 0;
		char beforetil = (i > 0) ? data[i - 1].first : '/';

		switch (ground[i])
		{
		case '\\':
			if (beforetil == '\\') {
				y--;
			}
			break;

		case '/':
			if (beforetil == '/' || beforetil == '_') {
				y++;
			}
			break;

		case '_':
			if (beforetil == '\\') {
				y--;
			}
		}
		//cout << ground[i] << " " << y << endl;
		data.push_back(Pair(ground[i], y));
	}

	vector<Pair>::iterator front, end;
	front = data.begin();
	end = data.end();

	vector<int> areas;
	float allarea = 0;

	while (front != end)
	{
		if (front->first != '\\') {
			advance(front, 1);
			continue;
		}

		targetsecond = front->second;

		//find_ifでpairをclass化 ==をoperator定義
		vector<Pair>::iterator target = find_if(front + 1, end, PairCom);

		//無い場合はイテレータを一つ進めてもう一度探索
		if (target == end) {
			advance(front, 1);
			continue;
		}

		float area = 0;
		
		for (; front <= target; front++) {
			//高さの差
			area += abs(front->second - target->second);
			
			//斜めのとき
			if (front->first != '_') {
				area += 0.5F;
			}
		}
		allarea += area;
		areas.push_back((int)area);
	}

	cout << (int)allarea << endl;
	cout << areas.size();

	for (int i = 0; i < areas.size(); i++) {
		cout << " " << areas[i];
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 3476
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 233
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
const int n=read(),k=read(),mod=read();
int fac[N],inv[N],C[N][N],ans;
#define ck(x) (x>=mod?x-mod:x)
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return n;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2)%mod;
	for(int i=n-1;i>=0;--i){
		inv[i]=1LL*inv[i+1]*(i+1)%mod;
	}
	C[0][0]=1;
	for(int i=1;i<=n;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j){
			C[i][j]=ck(C[i-1][j]+C[i-1][j-1]);
		}
	}
}
int calc(int X,int Y,int k){
	static int dp[N][N];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int j=1;j<=Y;++j){
		int s=0;
		for(int i=0;i<X;++i){
			s=ck(s+dp[i][j-1]);
			if((Y-j+1)+(i-1)<=k&&(X-i)+(j-1)<=k){
				dp[i][j]=s;
			}
		}
	}
	int tot=0;
	for(int i=1;i<X;++i){
		tot=ck(tot+dp[i][Y]);
	}
	return tot;
}
int Solve(int n,int k){
	if(n==1)return 1;
	int tot=0;
	for(int i=1;i<=k+1;++i){
		tot=(tot+calc(i,n-i,k))%mod;
	}
	tot=1LL*tot*fac[n-1]%mod;
	return tot;
}
int main(){
	init(n);
	for(int i=0;i<=k;++i){
		ans=(ans+1LL*C[n][i]*fac[i]%mod*Solve(n-i,k-i))%mod;
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 4048
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = sc.nextInt();
        
        System.out.println(t/a * b);
        sc.close();

    }
 
}

Measured memory_bytes: 23764
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private static final int INF = Integer.MAX_VALUE / 2;

    private static class Score {
        public int seq;
        public int p;
        public int c;
        public Score(int seq, int p, int c) {
            this.seq = seq;
            this.p = p;
            this.c = c;
        }
        public String toString() {
            return "[" + seq + ", " + p + ", " + c + "]";
        }
    }
    private int min = Integer.MAX_VALUE;
    private void solve(Scanner sc) {
        int D = sc.nextInt();
        // (1+2+..+10)*100+10*10^6 = 5500 + 10^7 < Integer.MAX_VALUE
        int G = sc.nextInt();
        List<Score> list = new ArrayList<>();
        for (int i = 0; i < D; ++i) {
            Score s = new Score(i + 1, sc.nextInt(), sc.nextInt());
            list.add(s);
        }
        search(G, list, 0);
        _out.println(min);
    }
    private Set<String> memo = new HashSet<>();
    private void search(int g, List<Score> list, int cnt) {
        String key = g + ":" + cnt;
        if (memo.contains(key)) {
            return;
        }
        memo.add(key);

        if (g <= 0) {
            if (cnt < min) {
                min = cnt;
            }
            return;
        }

        for (Score s : list) {
            if (s.p > 0) {
                int i = 0;
                while (s.p - i > 0 && g - s.seq * 100 * i > 0) {
                    ++i;
                }
                s.p -= i;
                if (s.p == 0) {
                    search(g - s.seq * 100 * i - s.c, list, cnt + i);
                } else {
                    search(g - s.seq * 100 * i, list, cnt + i);
                }
                s.p += i;
            }
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 22100
using System;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int a=int.Parse(Console.ReadLine());
            if (a == 1) Console.WriteLine("Hello World");
            else
            {
                int b = int.Parse(Console.ReadLine());
                int c = int.Parse(Console.ReadLine());
                Console.WriteLine(c + b);
            }
        }
    }
}


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

typedef long long LL;

#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<int> s(N);
    REP(i, N) {
        cin >> s[i];
    }
    sort(ALL(s));
    int total = accumulate(ALL(s), 0);
    if(total%10) {
        cout << total << endl;
    }else{
        REP(i, N) {
            if(s[i]%10) {
                cout << total - s[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }
    return 0;
}



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

using namespace std;

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

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

  float d=sum/(float)(4*m);

  sort(a,a+n);

  if(a[n-m]>=d)
  cout<<"Yes";
  else
  {
   cout<<"No";
  }
  
 
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){

    int x,y;
    cin >> x >> y;
    if((y - 2 * x) % 2 == 0 && (y - 2 * x) >= 0){
        if((4 * x - y) % 2 ==0 && (4 * x - y) >= 0){
            if((y - 2 * x) / 2 + (-y + 4 * x) / 2 == x){
                Yes();
                return 0;
            }
        }
    }
    No();
    return 0;
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    VEC2(v,n,n);
    FOR(i,0,n){
      FOR(j,0,n){
        cin>>v[i][j];
      }
    }
    ll res=0;
    FOR(i,0,n){
      FOR(j,i+1,n){
        ll a = v[i][j];
        ll b = v[j][i];
        res += min(a,b);
      }
    }
    cout<<res<<endl;
}



Measured memory_bytes: 3264
#include<stdio.h>
#define N 100000
int A[N];
int x;
int i, j;

int partition(int *A, int p, int r){

  int tmp;
  x = A[r];
  i = p - 1;
  for( j = p; j < r; j++){
	if(A[j] <= x){
	  i = i + 1;
	  tmp = A[i];
	  A[i] = A[j];
	  A[j] = tmp;
	}
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i+1;
}

int main(){

  int p = 0;
  int n;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
	scanf("%d", &A[i]);
  }

  x = partition(A, 0, n-1);

  for(i = 0; i < x; i++){
	printf("%d ", A[i]);
  }
  printf("[%d] ",A[x]);

  for(i = x+1; i < n-1; i++){
	printf("%d ", A[i]);
  }
  printf("%d\n", A[n-1]);

  return 0;
}

Measured memory_bytes: 988
#include<iostream>

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int i = 0;
    int ans = 1;
    string s;
    cin >> s;

    size_t n = s.size();

    for(i = 0; i < n; i++){
        if(i % 2 == 0){
            if(s[i] == 'L'){
                ans = 0;
                i += n;
            }
        }else{
            if(s[i] == 'R'){
                ans = 0;
                i += n;
            }
        }
    }
    if(ans == 1){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

struct BiconectedGraph{
  typedef pair<int,int> P;
  vector<vector<int> > G,C,T;
  vector<int> ord,low,belong;
  vector<P> B;
  int V;
  BiconectedGraph(){}
  BiconectedGraph(int n){
    G.clear();
    C.clear();
    T.clear();
    G.resize(n);
    C.resize(n);
    T.resize(n);
  }
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bool is_bridge(int u,int v){
    if(ord[u]>ord[v]) swap(u,v);
    return ord[u]<low[v];
  }
  void dfs(int u,int p,int &k){
    ord[u]=low[u]=k;
    ++k;
    for(int v:G[u]){
      if(v==p) continue;
      if(ord[v]>=0){
	low[u]=min(low[u],ord[v]);
      }else{
	dfs(v,u,k);
	low[u]=min(low[u],low[v]);
      }
      if(is_bridge(u,v)) B.push_back(P(u,v));
    }
  }
  void fill_component(int c,int u){
    C[c].push_back(u);
    belong[u]=c;
    for(int v:G[u]){
      if(belong[v]>=0||is_bridge(u,v)) continue;
      fill_component(c,v);
    }
  }
  void add_component(int u,int &k){
    if(belong[u]>=0) return;
    fill_component(k++,u);
  }
  
  void build(int n){
    int k=0;
    ord.clear();
    ord.resize(n,-1);
    low.clear();
    low.resize(n);
    belong.clear();
    belong.resize(n,-1);
    for(int u=0;u<n;u++){
      if(ord[u]>=0) continue;
      dfs(u,-1,k);
    }
    k=0;
    for(int i=0;i<(int)B.size();i++){
      add_component(B[i].first,k);
      add_component(B[i].second,k);
    }
    add_component(0,k);
    V=k;
    for(int i=0;i<(int)B.size();i++){
      int u=belong[B[i].first],v=belong[B[i].second];
      T[u].push_back(v);
      T[v].push_back(u);
    }
  }
};
signed main(){
  int v,e;
  cin>>v>>e;
  BiconectedGraph bcc(v);
  for(int i=0;i<e;i++){
    int s,t;
    cin>>s>>t;
    bcc.add_edge(s,t);
  }
  bcc.build(v);
  typedef pair<int,int> P;
  vector<P> B=bcc.B;
  for(P &p:B) if(p.first>p.second) swap(p.first,p.second);
  sort(B.begin(),B.end());
  for(P p:B) cout<<p.first<<" "<<p.second<<endl;
  return 0;
}

Measured memory_bytes: 5784
#include "vector"
#include "set"
#include "map"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define MOD 1000000007

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

struct v {
    int x;
    int i;
    int closed;
};

bool comp(const v& x, const v& y) {
    return (x.x < y.x) || (x.x == y.x && x.closed < y.closed);
};

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}

ll pw(ll x, int n) {
    if (n == 1) {
        return x;
    }
    if (n%2 == 0) {
        return pw((x*x) % MOD, n/2);
    }
    return (pw(x, n-1) * x) % MOD;
}

int get_min(map<int, set<int> >& m) {
    return m.begin()->first;
}

int get_min(set<int>& m) {
    return *m.begin();
}

int get_max(map<int, set<int> >& m) {
    auto it = m.end();
    it--;
    return it->first;
}

int get_max(set<int>& m) {
    auto it = m.end();
    it--;
    return *it;
}

void solve() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;

    vi ans(n, 0);
    for (int j=0; j<n; j++) {
        for (int i=j+1; i<n; i++) {
            int d = min(i - j, abs(i-y) + 1 + abs(j-x));
            ans[d]++;
        }
    }

    for (int i=1; i<n; i++) {
        cout << ans[i] << endl;
    }
}

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

    if (0) {
        int tests;
        cin >> tests;
        while (tests--) {
            solve();
            cout << endl;
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    int count = 0;
    int pre = 0;
    int high = 0;
    for (int i = 0; i < N;i++)
    {
        if(pre >= H[i]){
            count++;
        }
        else{
            if(count >= high){
                high = count;
            }
            count = 0;
        }
        pre = H[i];
    }
    if(count >= high){
        high = count;
    }
    cout << high << endl;
}

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

using namespace std;

int main()
{
	int n; cin >> n;
	vector<int > a(n);
	for(auto &it: a)
	{
		cin >> it;
	}
	
	int res = INT_MAX;
	for(int i = -100; i <= 100; i++)
	{
		int curr = 0;
		for(auto it: a)
		{
			curr += (pow(abs(i - it), 2));
		}
		
		res = min(res, curr);
	}
	
	cout << res;
	return 0;
}

Measured memory_bytes: 3608
import collections
import heapq


class Dijkstra():
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d, directed=False):
        """
        #0-indexedでなくてもよいことに注意
        #u = from, v = to, d = cost
        #directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.e[u].append([v, d])
            self.e[v].append([u, d])
        else:
            self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def Dijkstra_search(self, s):
        """
        #0-indexedでなくてもよいことに注意
        #:param s: 始点
        #:return: 始点から各点までの最短経路と最短経路を求めるのに必要なprev
        """
        d = collections.defaultdict(lambda: float('inf'))
        prev = collections.defaultdict(lambda: None)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    prev[uv] = u
                    heapq.heappush(q, (vd, uv))

        return d, prev

    def getDijkstraShortestPath(self, start, goal):
        _, prev = self.Dijkstra_search(start)
        shortestPath = []
        node = goal
        while node is not None:
            shortestPath.append(node)
            node = prev[node]
        return shortestPath[::-1]


N = int(input())
graph = Dijkstra()
for i in range(N):
    a = int(input())
    graph.add(i+1, a, 1, True)

ans = graph.Dijkstra_search(1)[0][2]
if ans == float('inf'):
    print(-1)
    quit()
print(ans)

Measured memory_bytes: 63816
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
#define F first
#define S second

main(){
	int n,m;
	while(cin>>n>>m,n){
		int sum=0;
		r(i,n){
			int x;
			cin>>x;
			sum += min( x , m/n );
		}
		cout<< sum <<endl;
	}
}


Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int H, W, S;
int U[32][32];
pair<int,int> memo[32][32][32+1][32+1];
int sum[32+1][32+1];
void init() {
    for (int i = 0; i < 32; ++i) {
    for (int j = 0; j < 32; ++j) {
    for (int k = 0; k < 32+1; ++k) {
    for (int l = 0; l < 32+1; ++l) {
        memo[i][j][k][l] = { -1, -1 };
    }
    }
    }
    }
    for (int y = 0; y < H+1; ++y) sum[y][0] = 0;
    for (int x = 0; x < W+1; ++x) sum[0][x] = 0;
    for (int y = 1; y < H+1; ++y) {
        for (int x = 1; x < W+1; ++x) {
            sum[y][x] = U[y-1][x-1] + sum[y-1][x] + sum[y][x-1] - sum[y-1][x-1];
        }
    }
}
int sum_rect(int y, int x, int ey, int ex) {
    return sum[ey][ex] - sum[ey][x] - sum[y][ex] + sum[y][x];
}
pair<int,int> solve(int y, int x, int ey, int ex) {
    if (memo[y][x][ey][ex].first != -1) return memo[y][x][ey][ex];
// cerr << "f " << y << " " << x << ' ' << ey << ' ' << ex << endl;
    if (S < sum[H][W] - sum_rect(y,x,ey,ex)) return memo[y][x][ey][ex] = { -1000000, 0 };
    pair<int,int> p = { 1, sum_rect(y,x,ey,ex) };
    for (int i = y+1; i < ey; ++i) {
        pair<int,int> a = solve(y,x,i,ex);
        if (a.first < 0) continue;
        pair<int,int> b = solve(i,x,ey,ex);
        if (b.first < 0) continue;
        p = max(p, make_pair( a.first + b.first, min(a.second, b.second) ));
    }
    for (int i = x+1; i < ex; ++i) {
        pair<int,int> a = solve(y,x,ey,i);
        if (a.first < 0) continue;
        pair<int,int> b = solve(y,i,ey,ex);
        if (b.first < 0) continue;
        p = max(p, make_pair( a.first + b.first, min(a.second, b.second) ));
    }
    return memo[y][x][ey][ex] = p;
}
int main() {
    while (true) {
        cin >> H >> W >> S;
        if (H == 0 and W == 0 and S == 0) break;
        for (int y = 0; y < H; ++y) {
            for (int x = 0; x < W; ++x) {
                cin >> U[y][x];
            }
        }
        init();
        pair<int,int> p = solve(0, 0, H, W);
        cout << p.first << ' ' << (S + p.second - sum[H][W]) << endl;
    }
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    for(ll i = 0;i < s.size();i++){
        if(s[i] == 'A' and i + 1 < s.size() and s[i+1] == 'C'){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

struct union_find {
  vector<int> par;
  vector<int> rank;
  union_find(int n) : par(n), rank(n) {
    for(int i = 0;i < n;i++) par[i] = i;
  }

  int root(int i) {
    return par[i] == i ? i : par[i] = root(par[i]);
  }

  int unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return x;
    if(rank[x] < rank[y]) {
      par[x] = y;
      return y;
    }
    else {
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
      return x;
    }
  }
};

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

  vector<i64> g(n, -1);
  union_find uf(n);

  for(int i = 0;i < k;i++) {
    i64 q, a, b;
    cin >> q >> a >> b;
    if(q == 1) {
      a--;
      b--;
      a = uf.root(a);
      b = uf.root(b);
      i64 ga = g[a];
      i64 gb = g[b];
      if(ga == -1 || gb == -1) {
        if(ga == -1) {
          ga = gb;
        }
        else {
          gb = ga;
        }
      }
      else if(ga == gb) {
      }
      else {
        cout << i + 1 << endl;
        return 0;
      }
      uf.unite(a, b);
      g[a] = ga;
      g[b] = gb;
    }
    else {
      a--;
      i64 c = a;
      i64 x = b;
      c = uf.root(c);
      i64 gc = g[c];
      if(gc == -1 || gc == x) {
      }
      else {
        cout << i + 1 << endl;
        return 0;
      }
      g[c] = x;
    }
  }
  cout << 0 << endl;
  return 0;
}



Measured memory_bytes: 4408
#include<bits/stdc++.h>
#define ri register int
using namespace std;

int main()
{
	string s,t;
	int n;
	bool flag;
	cin>>s;
	cin>>t;
	n=s.length();
	for (ri i=0;i<n;i++)
	{
		flag=1;
		for (ri j=0;j<n;j++)
			if (s[j]!=t[(i+j)%n]) {flag=0;break;}
		if (flag) {printf("Yes\n");return 0;}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
f = 0
s = 0
from collections import deque
ps = [-1] * n
used = [False] * n
used[0] = True # 始めどこから行くか
q = deque([0])
while len(q) > 0:
    a = q.popleft()
    if a == n-1:
        break
    for u in edges[a]:
        if not used[u]:
            ps[u] = a
            q.append(u)
            used[u] = True

nx = n - 1
xs = [n-1]
while nx != 0:
    nx = ps[nx]
    xs.append(nx)

xs.reverse()
l = len(xs) - 2
f = (l+1)//2
s = l-f

if len(xs) == 2:
    z_lim = -1
    n_lim = 0
else:
    z_lim = (len(xs)+1)//2
    n_lim = z_lim - 1

# bfs 0側
used = [-1] * n
used[0] = 0 
q = deque([0])
cnt = 0
while len(q) > 0:
    a = q.popleft()
    for u in edges[a]:
        if used[u] == -1 and u != xs[z_lim]:
            q.append(u)
            used[u] = 0
            cnt += 1
# print("cnt",cnt)
f += cnt

# bfs n-1側
used = [-1] * n
used[n-1] = 0 
q = deque([n-1])
cnt = 0
while len(q) > 0:
    a = q.popleft()
    for u in edges[a]:
        if used[u] == -1 and u != xs[n_lim]:
            q.append(u)
            used[u] = 0
            cnt += 1

s += cnt
# print("z_lim",z_lim,"nlim",n_lim)
# print("f",f,"s",s)
if f > s:
    print("Fennec")
else:
    print("Snuke")


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

int main(){
  string array[4],name[4];
  int i=0,j;
  cin>>array[0]>>array[1]>>array[2];
  name[0]="A";
  name[1]="B";
  name[2]="C";
  for( ; ; ){
    if(array[i].size()==0){
      cout<<name[i]<<endl;
      return 0;
    }
    if(array[i].at(0)=='a'){
      j=0;
    }else if(array[i].at(0)=='b'){
      j=1;
    }else if(array[i].at(0)=='c'){
      j=2;
    }
    array[i].erase(array[i].begin());
    i=j;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 10000
#define Q 500

int main(void){
	int S[N],T[Q],c=0,n,q,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&S[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++) scanf("%d",&T[i]);
	
	//search
	for(i=0;i<q;i++){
		for(j=0;j<n;j++){
			if(T[i]==S[j]){
				c++;
				break;
			}
		}
	}
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2100
n=int(input())
a=input()
b=input()
c=input()
def d(i):
    x=a[i]
    y=b[i]
    z=c[i]
    if x==y and y==z:
        return 0
    elif x==y or y==z or z==x:
        return 1
    else:
        return 2
r=0
for i in range(n):
    r += d(i)

print(r)


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

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    for(int j=0; j<M; j++) {
        cin >> B[j];
    }

    for(int i=0; i+M<=N; i++) {
        for(int j=0; j+M<=N; j++) {
            bool ok = true;
            for(int k=0; k<M; k++) {
                if(A[i+k].substr(j, M) != B[k]) {
                    ok = false;
                }
            }
            if(ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
    std.range, std.container, std.bigint, std.ascii, std.typecons;

// }}}
// nep.scanner {{{
class Scanner
{
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.array : split;
    import std.string : chomp;

    private File file;
    private char[][] str;
    private size_t idx;

    this(File file = stdin)
    {
        this.file = file;
        this.idx = 0;
    }

    private char[] next()
    {
        if (idx < str.length)
        {
            return str[idx++];
        }

        char[] s;
        while (s.length == 0)
        {
            s = file.readln.chomp.to!(char[]);
        }

        str = s.split;
        idx = 0;

        return str[idx++];
    }

    T next(T)()
    {
        return next.to!(T);
    }

    T[] nextArray(T)(size_t len)
    {
        T[] ret = new T[len];

        foreach (ref c; ret)
        {
            c = next!(T);
        }

        return ret;
    }

    void scan()()
    {
    }

    void scan(T, S...)(ref T x, ref S args)
    {
        x = next!(T);
        scan(args);
    }
}
// }}}

void main()
{
    auto cin = new Scanner;
    int n, m, x;
    cin.scan(n, m, x);
    int[] a = cin.nextArray!int(m);
    int t;
    for (int i = x; i <= n; i++)
    {
        foreach (e; a)
        {
            if (e == i) t++;
        }
    }
    int y;
    for (int i = x; i >= 0; i--)
    {
        foreach (e; a)
        {
            if (e == i) y++;
        }
    }
    writeln(min(t, y));
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);

		try {
			String buf = br.readLine();
			StringTokenizer st = new StringTokenizer(buf);
			int W = Integer.parseInt(st.nextToken());
			int H = Integer.parseInt(st.nextToken());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			int r = Integer.parseInt(st.nextToken());

			if (x-r<0||x+r>W||y-r<0||y+r>H) 
				System.out.println("No");
			else System.out.println("Yes");
		} catch (IOException e) {
			System.out.println("IOException!");
		}
	}
}

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

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

    int N;
    string S;
    cin >> N >> S;

    string T1;
    string T2;
    string result;

    if(N%2 == 0){
        for(int i=0;i<N/2;i++){
            T1.push_back(S[i]);
            T2.push_back(S[N/2+i]);
        }
        if(T1 == T2){
            result = "Yes";
        }else{
            result = "No";
        }
    }else{
        result = "No";
    }

    cout << result << endl;
}

Measured memory_bytes: 256