akhauriyash/Code-Regression huggingface dataset:
program answer
        implicit none
        integer :: i,N
        integer,allocatable,dimension(:) :: A,B,C
        integer :: ans
        ans = 0
        read(*,*) N
        allocate(A(N),B(N),C(N))
        read(*,*) (A(i),i=1,N)
        read(*,*) (B(i),i=1,N)
        read(*,*) (C(i),i=1,N-1)
        do i=1,N
          ans = ans + B(A(i))
          if(i .gt. 1) then
            if((A(i-1)+1) == A(i)) then
              ans = ans + C(A(i-1))
            end if
          end if
        end do
        write(*,'(I0)') ans
        stop
      end program answer


Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include <stdio.h>

constexpr int MAX_INPUT_SIZE = 2000'000; //'
char Input[MAX_INPUT_SIZE];
char* input = Input;

inline int getint(void){
    int res = 0, c; while((c = *input++ - '0') >= 0) res = 10 * res + c;
    return res;
}

struct coordinate{
    short x, y;
};

constexpr int MAX_N = 500;
coordinate Q[MAX_N * MAX_N];
short dist[MAX_N][MAX_N];
bool vacant[MAX_N][MAX_N];

int main(void){
    fread_unlocked(Input, 1, MAX_INPUT_SIZE, stdin);
    const short n = getint();
    {
        // initial distance
        const short p = n - 1;
        for(short i = 0; i < n; ++i){
            const short d1 = (i > p - i) ? p - i : i;
            for(short j = 0; j < n; ++j){
                const short d2 = (j > p - j) ? p - j : j;
                dist[i][j] = (d1 > d2) ? d2 : d1;
            }
        }
    }
    int res = 0;
    for(int _ = n * n; _--;){
        {
            const int p = getint() - 1;
            const short px = p / n, py = p % n;
            res += dist[px][py];
            vacant[px][py] = true;
            Q[0] = {px, py};
        }
        int head = 0, tail = 1;
        while(head != tail){
            const short x = Q[head].x, y = Q[head].y; ++head;
            const short nd = dist[x][y] + !vacant[x][y];
            if(x - 1 >= 0 and dist[x - 1][y] > nd){ dist[x - 1][y] = nd; Q[tail++] = {x - 1, y}; }
            if(y - 1 >= 0 and dist[x][y - 1] > nd){ dist[x][y - 1] = nd; Q[tail++] = {x, y - 1}; }
            if(y + 1 <  n and dist[x][y + 1] > nd){ dist[x][y + 1] = nd; Q[tail++] = {x, y + 1}; }
            if(x + 1 <  n and dist[x + 1][y] > nd){ dist[x + 1][y] = nd; Q[tail++] = {x + 1, y}; }
        }
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 4804
c = input().split(" ")
a = int(c[0])
b = int(c[1])

a_ans = 0
if a <= b:
    for i in range(b):
        a_ans += a * (10 ** i)
    print(a_ans)

b_ans = 0
if b < a:
    for i in range(a):
        b_ans += b * (10 ** i)
    print(b_ans)

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll g = 0;
    rep(i, N) g = gcd(g, A[i]);
    if (K % g == 0 && *max_element(all(A)) >= K) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> a(n);
  priority_queue<ll> q;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    q.push(a[i]);
    sum += a[i];
  }
  for (int i = 0; i < m; i++) {
    ll tmp = q.top();
    q.pop();
    sum -= tmp;
    sum += tmp/2;
    q.push(tmp/2);
  }
  cout << sum << endl;
  return 0;
}

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

string s;
int cnt[3];

int main() {
	cin >> s;
	
	int i;
	for (i = 0; i < 3; i++) cnt[s[i] - 'a']++;
	for (i = 0; i < 3; i++) if (cnt[i] != 1) break;
	if (i < 3) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

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

int n,x,y,v[100005],t[100005],f;

vector <int> g[100005];

void DFS(int nod){
    v[nod]=1;
    for(int i : g[nod]){
        if(!v[i]) DFS(i), t[nod]+=(!t[i]);
    }
    if(t[nod]>1) f=1;
}

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<n;i++){
        cin >> x >> y;
        g[x].push_back(y); g[y].push_back(x);
    }
    DFS(1);
    if(f || !t[1]) cout << "First";
    else cout << "Second";
}


Measured memory_bytes: 6656
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        // int k=sc.nextInt();
        // int a[]=new int[n];
        // int max=5000;
        long s=0,ans=0;
        for (int i=0; true; i++) {
            s+=i+1;
            if(n<=s){ans=i+1;break;}
        }

        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    ll n,a[100100],dp[100100];
    ll rec(ll i)
    {
        if(i<0)
            return 1e9;
        if(i==0)
            return 0;
        if(dp[i]!=-1)
            return dp[i];
        ll c1=rec(i-1)+abs(a[i-1]-a[i]);
        ll c2=rec(i-2)+abs(a[i-2]-a[i]);
        return dp[i]=min(c1,c2);
    }
    int main()
    {
        cin>>n;
        for(ll i= 0 ; i<n ; i++)
            cin>>a[i];
        memset(dp,-1,sizeof dp);
        cout<<rec(n-1)<<endl;
        return 0;
    }


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

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int[] menu = new int[5];
		for(int i = 0; i < 5; i++)
			menu[i] = sc.nextInt();
		
		int amari = 99, number = -1;
		for(int i = 0; i < 5; i++) {
			int num = menu[i] % 10;
			if (num == 0) num = 10;
			if (num < amari) {
				amari = num;
				number = i;
			}
		}
		int sum = 0;
		for(int i = 0; i < 5; i++) {
			if (i == number)
				sum += menu[i];
			else
				sum += func(menu[i]);
		}
		out.println(sum);
	
		out.close();
	}
	static int func(int n) {
		int res = n;
		int num = n % 10;
		if (num != 0)
			res = res - num + 10;
		return res;
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int a, b;
  cin >> a >> b;
  int cnt =0;
  for(int i=a; i<=b; ++i){
    string str = to_string(i);
    int n = str.size();
    if(n%2==0) continue;
    else{
      string cp = str;
      reverse(cp.begin(), cp.end());
      if(str==cp) cnt++;
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int H, W; cin >> H >> W;
  vector<bool> out_x(W, false);
  vector<bool> out_y(H, false);
  vector<string> A(H); rep(i,H) cin >> A[i];
  rep(y,H) {
    int whitecount = 0;
    rep(x,W){
      if(A[y][x] == '.') whitecount++;
    }
    if(whitecount == W){
      out_y[y] = true;
    }
  }
  rep(x,W){
    int whitecount = 0;
    rep(y,H){
      if(A[y][x] == '.') whitecount++;
    }
    if(whitecount == H){
      out_x[x] = true;
    }
  }
  rep(i,H){
    if(out_y[i]) continue;
    rep(j,W){
      if(out_x[j]) continue;
      cout << A[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);

  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  vector<pair<int, int>> q;

  int dx, dy;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      dx = v[i].first - v[j].first;
      dy = v[i].second - v[j].second;
      q.push_back(make_pair(dx, dy));
      q.push_back(make_pair(-dx, -dy));
    }
  }

  sort(q.begin(), q.end());
  q.push_back(make_pair(0, 0));

  int tmp_pq = 1, max_pq = 0;
  for (int i = 0; i < q.size(); i++) {
    if (i == 0 | i == q.size() - 1 || q[i] != q[i - 1]) {
      max_pq = max(tmp_pq, max_pq);
      tmp_pq = 1;
      continue;
    }
    tmp_pq++;
  }

  cout << (n == 1 ? 1 : n - max_pq) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
    v[i] -= i + 1;
  }
  sort(v.begin(), v.end());
  ll b = v[N / 2];
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += abs(v[i] - b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 1e9 + 7;
typedef long long ll;
int n, a[N];
ll dp[N], sum[N], ans = 0;
ll check(int pos){
    ll t1, t2, tmp1, tmp2, tmp3, tmp4, tmp11, Max, Min;

    t1 = dp[pos] / 2;
    tmp1 = dp[lower_bound(dp+1, dp+pos+1, t1) - dp];
    tmp2 = dp[pos] - tmp1;
    tmp3 = sum[lower_bound(sum+n-pos+1, sum+n+1, t1) - sum];
    //cout << "**********" << pos << " " << t1 << " " << tmp1 << " " << tmp2 << " " << tmp3 << endl;
    if(abs(tmp3-t1) < abs(tmp1-t1)){
        tmp1 = tmp3;
        tmp2 = dp[pos] - tmp1;
    }

    t2 = sum[n - pos] / 2;
    tmp3 = sum[lower_bound(sum+1, sum+n-pos+1, t2) - sum];
    tmp4 = sum[n - pos] - tmp3;
    tmp11 = dp[lower_bound(dp+pos+1, dp+n+1, t2) - dp];
    if(abs(t2 - tmp11) < abs(t2 - tmp3)){
        tmp3 = tmp1;
        tmp4 = sum[n-pos] - tmp3;
    }

    Max = max(tmp1, max(tmp2, max(tmp3, tmp4)));
    Min = min(tmp1, min(tmp2, min(tmp3, tmp4)));
    cout << pos << " " << tmp1 << " " << tmp2 << " " << tmp3 << " " << tmp4 << " " << Max - Min << endl;
    return Max - Min;
}
int main(){
    dp[0] = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
         scanf("%d", a+i);
         dp[i] = dp[i-1] + a[i];
    }
    /*
    sum[n+1] = 0;
    for(int i = n; i >= 1; --i){
        sum[i] = sum[i+1] + a[i];
    }
    int i = 1, j = n;
    while(i <= j){
        swap(sum[i++], sum[j--]);
    }

    for(int i = 2; i <= n - 2; ++i){
        ans = min(ans, check(i));
    }
    */
    ll ans = (1LL<<61);
    int l = 1, r = 3;
    for(int i = 2; i < n - 1;  ++i){
        while(l < i && abs(dp[l] - (dp[i] - dp[l])) >= abs(dp[l+1] - (dp[i] - dp[l+1]))) l++;
        while(r < n && abs((dp[r] - dp[i]) - (dp[n] - dp[r])) >= abs((dp[r+1]-dp[i])-(dp[n]-dp[r+1]))) r++;
        ll Max = max(dp[l], max(dp[i]-dp[l], max(dp[r]-dp[i], dp[n]-dp[r])));
        ll Min = min(dp[l], min(dp[i]-dp[l], min(dp[r]-dp[i], dp[n]-dp[r])));
        ans = min(ans, 1LL * (Max - Min));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2560
/*
t.me/ivanesipovvpered
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;

const double EPS = 1e-5;
const int mod = 1e9 + 7;
const ll INFLL = 1e18;
const int INF = 1e9;
const int maxn = 1e6 + 3;

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

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

bool is_prime(ll a){
    if (a == 2 | a == 3 || a == 5 || a == 7) return true;
    if (a % 2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0)
        return false;
    for (ll i = 11; i * i <= a; i += 2){
        if (a % i == 0)
            return false;
    }
    return true;
}

ll binpow(ll a, int n){
    if (a == 0)
        return 1;
    if (a % 2 == 0){
        ll q = binpow(a, n / 2);
        return (q * q)  ;
    }else return (a * binpow(a, n - 1) ) ;
}





















main(){
    int n, w;
    cin >> n >> w;
    w++;
    vi dp(w), dr(w);
    vi a(n), we(n);
    rep(i, n)
        cin >> we[i] >> a[i];
    rep(i, n){
        rer(j, we[i], w){
            dp[j] = max(dp[j], dr[j - we[i]] + a[i]);
        }
        dr = dp;
    }
    int maxx = 0;
    rep(i, w)
        maxx = max(maxx, dp[i]);
    cout << maxx;


}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 300002
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int N;
  char S[MAX];
  scanf("%d %s", &N, S);

  int W[MAX] = {0};
  int E[MAX] = {0};
  for (int i = 0; i < N; i++) {
    if ( S[i] == 'E' ) W[i + 1] = W[i];
    else if ( S[i] == 'W' ) W[i + 1] = W[i] + 1;
  }
  for (int i = N - 1; i >= 0; i--) {
    if ( S[i] == 'W' ) E[i] = E[i + 1];
    else if ( S[i] == 'E' ) E[i] = E[i + 1] + 1;
  }

  int ans = MAX;
  for (int i = 0; i < N; i++) {
    ans = min(ans, W[i] + E[i + 1]);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<string>

bool CheckGoodInt(std::string str) {
	if (str.size() != 4) {
		//std::cerr << "not 4keta integer!" << std::endl;
		return false;
	}

	if (str[1] == str[2]) {
		if (str[0] == str[1] || str[3] == str[1]) return true;
	}
	return false;
}

int main(void) {
	int N;
	std::string str;

	std::cin >> N;

	str = std::to_string(N);

	if (CheckGoodInt(str)) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  long long int ans = 0;
  vector<int> id(20, -1), B(N);
  for(int i = 0; i < N; ++i){
    int l = -1;
    for(int j = 0; j < 20; ++j){
      if(!((A[i]>>j)&1)) continue;
      l = max(l, id[j]);
      id[j] = i;
    }
    B[i] = l + 1;
  }
  ans += 1;
  //for(int i = 0; i < N; ++i) cout << B[i] << " "; cout << endl;
  for(int i = 1; i < N; ++i){
    B[i] = max(B[i], B[i-1]);
    ans += i - B[i] + 1;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define DS pair<int, int>

const int N = 17;

int bad[N];
vector<DS> g[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    while (x--) {
      int u, v;
      scanf("%d %d", &u, &v);
      g[i].push_back({u - 1, v});
    }
  }
  int ans = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    bool good = 1;
    for (int i = 0; i < n; i++) {
      if ((mask & (1 << i))) {
        for (auto x : g[i]) {
          int z = mask & (1 << x.first);
          if ((x.second == 0 && z == 0) || (x.second && z)) {
            continue;
          } else {
            good = 0;
            break;
          }
        }
      }
    }
    //cout << mask << " " << good << endl;
    if (good) ans = max(ans, __builtin_popcount(mask));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<cstdio>
#include<string>
#include<iostream>

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

using namespace std;

bool regularize(string &s,const set<string> &D,const set<string> &F){
	if(s[0]!='/') return false;

// cout<<'\"'<<s<<'\"'<<endl;
	string path;
	for(int i=1;i<s.length();i++){
		path+='/';
		if(D.count(path)==0) return false;
		int pre=i;
		for(;i<s.length();i++) if(s[i]=='/') break;
		string t=s.substr(pre,i-pre);
		if(t==".."){
			if(path=="/") return false;
			int j;
			for(j=(int)path.length()-2;path[j]!='/';j--);
			path.resize(j);
		}
		else if(t=="."){
			path.resize((int)path.length()-1); // 次に '/' が追加されるので, 一つ分消しておく
		}
		else{
			path+=t;
		}
	}

	if(*path.rbegin()!='/' && *s.rbegin()=='/') path+='/';

	if(F.count(path)==1){
		s=path;
		return true;
	}
	if(*path.rbegin()!='/') path+='/';
	if(D.count(path)==1 && F.count(path+"index.html")==1){
		s=path+"index.html";
		return true;
	}
	else return false;
}

int main(){
	for(int n,m;cin>>n>>m,n;){
		set<string> D,F; // 有効な directory, file の集合
		rep(_,n){
			string s; cin>>s;
			string path;
			for(int i=1;i<s.length();i++){
				path+='/';
				D.insert(path);
				int pre=i;
				for(;i<s.length();i++) if(s[i]=='/') break;
				path+=s.substr(pre,i-pre);
			}
			F.insert(path);
		}

		rep(_,m){
			string s1,s2; cin>>s1>>s2;
			bool b1=regularize(s1,D,F);
			bool b2=regularize(s2,D,F);
			cout<<(b1&&b2?s1==s2?"yes":"no":"not found")<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1228
N = int(input())
arr = [[0 for i in range(2)] for _ in range(N)]

for n in range(N):
    arr[n] = list(map(int, input().split()))
    
arr.sort(key=lambda x:x[0])
max_order = arr[0][0]
min_order = arr[N-1][0]
min_score = arr[N-1][1]

print(max_order + (min_order-max_order) + min_score)

Measured memory_bytes: 28840
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define ii pair <int, int>
#define f first
#define s second
#define INF 1e9
#define MOD 1000000007
#define MAXN 1000
#define debug(x) cerr << #x << " = " << x << endl
#define debug_arr(x, tam) cerr << #x << " = "; for (int i=0;i<tam;i++) cout << x[i] << " "; printf("\n")
using namespace std;


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

	if (b == 100) b++;
	if (a == 0) printf("%d\n", b);
	else if (a == 1) printf("%d\n", b * 100);
	else if (a == 2) printf("%d\n", b * 10000);
	// else if (a == 3) printf("%d\n", b * 1000000);

	return 0;
}


Measured memory_bytes: 256
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main()
{      
  fastio();
  int n,m,i,j,t;
  cin>>n;
  long double a[n];
  long double sum=0;
  long double product=1;
  for(i=0;i<n;i++)
  {
  	cin>>a[i];
  	a[i]=1.0/a[i];
  	sum+=a[i];
  }
  cout<<1.0/sum;
  
  return 0;
}

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

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;


void solve()
{
	long long int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	long long int ans = 0;
	ans = X * A + Y * B;
	if (X < Y)
	{
		ans = min(ans, X * 2 * C + (Y - X) * B);
		ans = min(ans, Y * 2 * C);
	}
	else
	{
		ans = min(ans, Y * 2 * C + (X - Y) * A);
		ans = min(ans, X * 2 * C);
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int M = 2999;
int n;
double p[M], dp[M + 1][M + 1];

int main() {
	cin >> n;
	inc(i, n) { cin >> p[i]; }
	
	dp[0][0] = 1;
	inc(i, n) {
	incII(j, 0, i) {
		dp[i + 1][j + 1] += dp[i][j] * p[i];
		dp[i + 1][j + 0] += dp[i][j] * (1 - p[i]);
	}
	}
	
	double ans = 0;
	incII(j, (n + 1) / 2, n) { ans += dp[n][j]; }
	
	printf("%.12f\n", ans);
	
	return 0;
}


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

#define ll long long
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define xx first
#define yy second

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

    long double a, b;
    cin >> a >> b;

    ll ans = a*b;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3748
n=int(input())
a=[int(input()) for _ in range(n)]
a.sort()
if n%2==0:
    res=[]
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[-i-1])
        z.append(a[n//2-i-2])
    z.append(a[n//2])
    res.append(z)
    
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[-i-1])
        z.append(a[i])
    z.append(a[n//2])
    res.append(z)
    
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[n//2+i])
        z.append(a[n//2-i-2])
    z.append(a[-1])
    res.append(z)
    
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[n//2+i])
        z.append(a[i])
    z.append(a[-1])
    res.append(z)
    
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[n//2-i-2])
        z.append(a[-i-1])
    z.append(a[n//2])
    res.append(z)
    
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[i])
        z.append(a[-i-1])
    z.append(a[n//2])
    res.append(z)
    
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[n//2-i-2])
        z.append(a[n//2+i])
    z.append(a[-1])
    res.append(z)
    
    z=[a[n//2-1]]
    for i in range(n//2-1):
        z.append(a[i])
        z.append(a[n//2+i])
    z.append(a[-1])
    res.append(z)
    
    ans=[]
    for z in res:
        t=0
        for i in range(1,n):
            t+=abs(z[i]-z[i-1])
        ans.append(t)
    print(max(ans))
else:
    res=[]
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[-i-1])
        z.append(a[i])
    res.append(z)
    
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[n//2+1+i])
        z.append(a[i])
    res.append(z)
    
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[-i-1])
        z.append(a[n//2-i-1])
    res.append(z)
    
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[-i-1])
        z.append(a[i])
    res.append(z)
    
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[i])
        z.append(a[-i-1])
    res.append(z)
    
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[i])
        z.append(a[n//2+1+i])
    res.append(z)
    
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[n//2-i-1])
        z.append(a[-i-1])
    res.append(z)
    
    z=[a[n//2]]
    for i in range(n//2):
        z.append(a[i])
        z.append(a[-i-1])
    res.append(z)
    
    ans=[]
    for z in res:
        t=0
        for i in range(1,n):
            t+=abs(z[i]-z[i-1])
        ans.append(t)
    print(max(ans))

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

using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	vector<double> x(N);
	vector<string> u(N);
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> u[i];
	}

	double res = 0;
	for (int i = 0; i < N; ++i) {
		if (u[i] == "JPY") {
			res += x[i];
		} else {
			res += (x[i] * 380000);
		}
	}

	cout.precision(10);
	cout << fixed << res << endl;

	return 0;
}


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

int main(){
    long int a;
    cin >>a;
    long int p=1;

    for(int i=0;i<=20;i++){
        if(p>a){
            cout<<p/2<<endl;
            break;
        }
        p=p*2;
    }
    return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    int flag = 0;
    for(int i = 0; i < s.size(); i++)
        if(s[i] != t[i]) {flag = 1; break;}
    cout << ((flag) ? "No" : "Yes");
}


Measured memory_bytes: 3624
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp::*;
use std::collections::BTreeSet;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

#[derive(PartialEq, Eq)]
struct Sq {x: usize,y: usize,tr: usize} 

impl Sq {
    fn new(x: usize, y: usize) -> Self {
        Sq{x, y, tr: x*x + y*y}
    }
}

impl PartialOrd for Sq {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for Sq {
    fn cmp(&self, other: &Self) -> Ordering {
        match self.tr.cmp(&other.tr) {
            Ordering::Equal => self.x.cmp(&other.x),
            e => e,
        }
    }
}

fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
    let mut st = BTreeSet::new();
    for i in 1..150 {
        for j in i+1..150 {
            st.insert(Sq::new(i,j));
        }
    }
    loop{
        let (n,m) : (usize, usize) = (sc.read(), sc.read());
        if n == 0 {break;}
        let t = Sq::new(n,m);
        let ans = Sq::new(100,100);
        let mut r = st.range((t..));
        let n1 = r.next().unwrap();
        let n2 = r.next().unwrap();
        let n3 = r.next().unwrap();
        //println!("1: {} {}", n1.x, n1.y);
        println!("{} {}", n2.x, n2.y);
        //println!("3: {} {}", n3.x, n3.y);
        //println!("");
        //println!("{} {}", neighbor.x, neighbor.y);
    }
}




Measured memory_bytes: 5052
#include <stdio.h>
#include <math.h>
 
int main(void)
{
	long long K, i,A, B, C;
	
	scanf("%d%d%d%d", &A,&B,&C,&K);

	if(abs(A-B)>pow(10,18))
		printf("Unfair");
	else if(K%2==1)
		printf("%d", B-A);
	else
		printf("%d", A-B);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,ok;

signed main()
{
    string s;
    cin>>s;
    if(s[2] == s[3] && s[4] == s[5]) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N; vl A(N); REP(i, N) cin >> A[i];
    vl D(N, 0); ll suma = 0;
    REP(i, N){
        suma += A[i];
        ll nx = (i+1)%N;
        D[i] = A[nx]-A[i];
    }
    if(suma % (N*(N+1)/2) != 0){
        cout << "NO" << endstr; return 0;
    }
    ll K = suma / (N*(N+1)/2);
    REP(i, N){
        if(D[i]-K > 0 || (D[i]-K)%N != 0){
            cout << "NO" << endstr; return 0;
        }
    }
    cout << "YES" << endstr;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int array[10000];
  int tmp;
  int j=0;
  do{
    cin>>tmp;
    array[j]=tmp;
    j++;
  } while(tmp!=0);
  
  for(int i = 0; i < j-1 ; i ++){
    cout<<"Case "<<i+1<<": "<<array[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3124
def check_str( ss ):
  sslen = len(ss)
  
  if( sslen %2 == 0 ): 
    return (ss[:sslen//2] == ss[sslen//2:][::-1])
  else:
  	return (ss[:sslen//2] == ss[sslen//2+1:][::-1])
  
s = input()

slen = len(s)

if( not check_str( s ) ):
  print( "No" )
else:
#print(s[:slen//2])
#print(s[slen//2+1:][::-1])

  s1 =  s[:slen//2]
  s2 = s[slen//2+1:]
  
  
  if( (not check_str( s1 )) or (not check_str( s2 )) ):
    print( "No" )
  else:
    print( "Yes" )

#s1 = s[:len(s)-1]

#s1



Measured memory_bytes: 3060
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int main(void) {
    stack<int> s;
    string ss;
    while (cin >> ss) {
        if (ss == "+") {
            int next = s.top();
            s.pop();
            next += s.top();
            s.pop();
            s.push(next);
        } else if (ss == "-") {
            int next = s.top();
            s.pop();
            next -= s.top();
            s.pop();
            s.push(-next);
        } else if (ss == "*") {
            int next = s.top();
            s.pop();
            next *= s.top();
            s.pop();
            s.push(next);
        } else {
            int a = stoi(ss);
            s.push(a);
        }
    }
    cout << s.top() << endl;
    return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef vector<int> pos;
typedef pair<int,int> P;

int w,h;
string g[16];
int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};
bool vis[16][64][4][16][64][4];

int main(){
  int cnt=0;
  while(cin >> w >> h,w){
    cnt++;
    rep(i,h)cin >> g[i];
    //if(cnt!=11)continue;
    memset(vis,0,sizeof(vis));

    int sy,sx,sd, gy,gx,gd;
    rep(i,h){
      rep(j,w){
	if(g[i][j] == 'K'){
	  rep(k,4){
	    int ny = i+dy[k], nx = j+dx[k];
	    if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
	    if(g[ny][nx] == '.'){
	      sy = i; sx = j; sd = k;
	    }
	  }
	}
	if(g[i][j] == 'M'){
	  rep(k,4){
	    int ny = i+dy[k], nx = j+dx[k];
	    if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
	    if(g[ny][nx] == '.'){
	      gy = i; gx = j; gd = k;
	    }
	  }
	}
      }
    }
    set<P> check;

    stack<pos> s;
    pos p(6);
    p[0] = sy; p[1] = sx; p[2] = sd;
    p[3] = sy; p[4] = sx;

    rep(i,4){
      vis[sy][sx][sd][sy][sx][i] = true;
      p[5] = i;
      s.push(p);
    }

    while(s.size()){
      p = s.top(); s.pop();
      
      check.insert(make_pair(p[0],p[1]));
      //rep(i,6)cout << p[i] << " ";cout << endl;

      int d1 = p[2], y1 = p[0]+dy[d1], x1 = p[1]+dx[d1];
      while(g[y1][x1]!='#'){
	y1+=dy[d1]; x1+=dx[d1];
      }
      y1-=dy[d1]; x1-=dx[d1];

      int d2 = p[5], y2 = p[3], x2 = p[4];
      while(g[y2][x2]!='#'){
	int rd = (p[5]+1)%4, ry = y2+dy[rd], rx = x2+dx[rd];
	int ld = (p[5]+3)%4, ly = y2+dy[ld], lx = x2+dx[ld];

	if(g[ry][rx]=='#' || g[ly][lx]=='#'){
	  if(!vis[y1][x1][d1][y2][x2][d2]){
	    vis[y1][x1][d1][y2][x2][d2] = true;
	    if(g[ry][rx]=='#'){
	      pos tmp(6);
	      tmp[0] = y1; tmp[1] = x1; tmp[2] = (d1+1)%4;
	      tmp[3] = y2; tmp[4] = x2; tmp[5] = rd;
	      s.push(tmp);
	    }

	    if(g[ly][lx]=='#'){
	      pos tmp(6);
	      tmp[0] = y1; tmp[1] = x1; tmp[2] = (d1+3)%4;
	      tmp[3] = y2; tmp[4] = x2; tmp[5] = ld;
	      s.push(tmp);
	    }
	  }
	}
	y2-=dy[d2]; x2-=dx[d2];
      }
    }
    bool f1=false;
    rep(i,4){
      if(vis[gy][gx][i][gy][gx][gd])f1 = true;
    }

    if(f1)cout << "He can accomplish his mission." << endl;
    else{
      memset(vis,0,sizeof(vis));
      p.resize(3);
      p[0] = sy; p[1] = sx; p[2] = sd;
      s.push(p);

      while(s.size()){
	p = s.top(); s.pop();
	
	int ny = p[0]+dy[p[2]], nx = p[1]+dx[p[2]];
	while(g[ny][nx]!='#'){
	  ny += dy[p[2]]; nx += dx[p[2]];
	}
	ny -= dy[p[2]]; nx -= dx[p[2]];
	
	if(vis[ny][nx][p[2]][0][0][0])continue;
	vis[ny][nx][p[2]][0][0][0] = true;
	rep(d,2){
	  int nd = (p[2] + 2*d+1)%4;
	  pos tmp(3);
	  tmp[0] = ny; tmp[1] = nx; tmp[2] = nd;
	  s.push(tmp);
	}
      }	  
      
      bool f2=false;
      rep(i,4){
	if(vis[gy][gx][i][0][0][0])f2 = true;
      }
      if(f2)cout << "He cannot return to the kitchen." << endl;
      else cout << "He cannot bring tea to his master." << endl;
    }
  }
}

Measured memory_bytes: 18012
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,s1,t="";
	cin>>s>>s1;
	for(int i=0;i<s1.size()-1;i++)
	{
		t+=s1[i];
	}
//	t+=s[s.size()-1];
//	cout<<t<<endl;
	if(t==s)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
int main (void){
  int i;
  int x[10000];
  for(i = 0 ; i<10000 ; i++){
    scanf("%d\n",&x[i]);
    if(x[i] == 0){
      break;
    }
  }
  for(int j = 0; j<i ; j++){
      printf("Case %d: %d\n",j+1,x[j]);
  }
  return 0;
}


Measured memory_bytes: 2100
import java.util.*;

public class Main {
  static int[] par;
  static int[] rank;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    par = new int[n];
    rank = new int[n];
    init(n);
    for(int i = 0; i < m; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      unite(a, b);
    }
    int ans = 0;
    int[] t = new int[n];
    for(int i = 0; i < n; i++) {
      t[find(i)]++;
    }
    for(int i = 0; i < n; i++) {
      ans = Math.max(ans, t[i]);
    }
    System.out.println(ans);
  }
  static void init(int m) {
      for(int i = 0; i < m; i++) {
        par[i] = i;
        rank[i] = 1;
      }
    }
  static int find(int x) {
      if(par[x] == x) {
        return x;
      } else {
        return par[x] = find(par[x]);
      }
    }
  static void unite(int x, int y) {
      x = find(x);
      y = find(y);
      if(x != y) {
        if(rank[x] < rank[y]) {
          par[x] = y;
          rank[y] += rank[x];
        } else {
          if(rank[x] == rank[y]) {
            if(x > y) {
              par[x] = y;
              rank[y] += rank[x];
            } else {
              par[y] = x;
              rank[x] += rank[y];
            }
          } else {
            par[y] = x;
            rank[x] += rank[y];
          }
        }
      }
    }
  static boolean same(int x, int y) {
      return find(x) == find(y);
    }
}

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

int main() {
    string s; cin >> s;
    int par = 0, ans = 0;
    for(size_t i=0; i<s.size(); i++) {
        if(s[i] == '(') par++;
        if(s[i] == ')') par--;
        if(s[i] == '*') ans = par;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    string s, t;
    cin >> s;
    cin >> t;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<bool> A(N, false);
  ll a;
  for (int i = 0; i < M; i++) {
    cin >> a;
    A[a] = true;
  }
  ll i = X;
  ll ans1 = 0;
  while (i > 0) {
    i--;
    if (A[i]) ans1++;
  }
  i = X;
  ll ans2 = 0;
  while (i < N) {
    i++;
    if (A[i]) ans2++;
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 256
#+swank (declaim (optimize (speed 0) (safety 3) (debug 3)))
#-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))

(defconstant +mod+ 1000000007)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1
        (write obj :stream stream)
      (fresh-line stream))) body...)


(defmethod fast-sort ((sequence list) &key (test #'<))
  (declare (inline sort)
           (inline sb-impl::stable-sort-list))
  (sort sequence (lambda (x y)
                   (funcall test x y))))


(defmethod fast-sort ((sequence array) &key (test #'<))
  (declare (inline sort))
  (sort sequence (lambda (x y)
                   (funcall test x y))))

(defmacro read-numbers-to-list (size)
  `(loop repeat ,size collect (read)))



(defmacro read-numbers-to-array (size)
  `(progn
     (when (not (integerp ,size))
       (error "Size must be integer."))
     (when (< ,size 0)
       (error "Size must be plus or zero."))
     (make-array ,size :initial-contents (read-numbers-to-list ,size))))

(defmacro read-numbers-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size))))
       (dotimes (,r ,row-size)
         (dotimes (,c ,column-size)
           (setf (aref ,board ,r ,c) (read))))
       ,board)))


(defun princ-for-each-line (list)
  (format t "~{~a~&~}" list))

(defun unwrap (list)
  (format nil "~{~a~^ ~}" list))



(defmacro with-buffered-stdout (&body body)
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))




;;; Write code here

(defun solve (n s)
  (declare (fixnum n)
           (string s))
  (the fixnum
       (let ((ans (*
                   (count #\R s :test #'char-equal)
                   (count #\G s :test #'char-equal)
                   (count #\B s :test #'char-equal)
                   )))
         (declare (fixnum ans))
         (loop for i from 0 below (- n 2) do
              (loop for j from (1+ i) below (- n 1) do
                   (let ((k (- (* j 2)
                               i
                               )))
                     (unless (or
                              (>= k n)
                              (char-equal (elt s k)
                                          (elt s i))
                              (char-equal (elt s k)
                                          (elt s j))
                              (char-equal (elt s i)
                                          (elt s j)))
                       (decf ans))))
            finally
              (return ans)))))


(defun main ()
  (let ((n (read))
        (s (read-line)))
    (declare (fixnum n))
    (format t "~a~&" (solve n s))))

#-swank (main)


Measured memory_bytes: 25240