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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999

using namespace std;

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

    vector<pair<int, int> > v;
    REP(i, n){
        int a, b;
        cin >> a >> b;
        v.pb(make_pair(a, b));
    }
    SORT(v);

    int i = 0;
    while(k - v[i].second > 0){
        k -= v[i].second;
        i++;
    }

    cout << v[i].first << endl;
}

Measured memory_bytes: 2420
/*
 * Shubham Jain
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define MOD 10000000009

int main() {
    ll n,i,p=0,w=0,y=0,g=0;
    cin>>n;
    char a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]=='P')
            p++;
        else if(a[i]=='Y')
            y++;
        else if(a[i]=='G')
            g++;
        else if(a[i]=='W')
            w++;
     //   cout<<p<<" "<<y<<" "<<g<<" "<<w<<endl;
    }
    if(p>0 && w>0 && g>0 && y>0)
        cout<<"Four"<<endl;
    else if(p>0 && w>0 && g>0)
        cout<<"Three"<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long
#define ld long double

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	ll a[n];
	cina(a, n);
	sort(a, a+n, greater<int>());
	vector<ll> v;
	for (int i = 0; i < n - 1; ++i) {
		if (a[i] == a[i+1]) {
			v.push_back(a[i++]);
		}
	}
	if (v.size() >= 2)
		cout << v[0] * v[1];
	else
		cout << 0;
	return 0;
}

Measured memory_bytes: 4636
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main()
{
  int n, k;
  cin >> n >> k;
  vi a(n);
  for(int &i:a){
    cin >> i;
  }
  int ans = 0;
  while (true)
  {
    if(k*ans-(ans-1)>=n){
      break;
    }

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

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

string lcs(string a,string b,int n,int m){

   int dp[n+1][m+1];

    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 || j==0){
                dp[i][j]=0;
            }

            else if(a[i-1]==b[j-1]){

                dp[i][j]=1+dp[i-1][j-1];
            }

            else{

                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }

        }
    }

    int index=dp[n][m];

    string lcsindex;

    int i=n,j=m;

    while (i>0 && j>0){

        if(a[i-1]==b[j-1]){

            lcsindex+=a[i-1];
            i--;
            j--;
            index--;
        }
        else if(dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    string ans;
    for(int k=lcsindex.length()-1;k>=0;k--){
        ans+=lcsindex[k];
    }
    return ans;


}
int main()
{
    string a,b;
    cin>>a>>b;

    cout<<lcs(a,b,a.length(),b.length())<<endl;


    return 0;
} 


Measured memory_bytes: 35456
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private static final boolean TEST = false;

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String s = in.next();
		System.out.println(solve(s));
		if (TEST)
			System.out.println(testSolve(s));
		in.close();
	}

	private static int testSolve(String s) {
		int ss = 0;
		for (int i = 0; i < s.length(); i++) {
			ss *= 2;
			if (s.charAt(i) == '1')
				ss++;
		}
		int r = 0;
		for (int a = 0; a <= ss; a++)
			for (int b = 0; a + b <= ss; b++)
				if ((a + b) == (a ^ b))
					r++;
		return r % 1000000007;
	}

	private static long solve(String s) {
		long ra = 1;
		long re = 1;
		for (int i = 0; i < s.length(); i++) {
			ra *= 3;
			if (s.charAt(i) == '1')
				re *= 2;
			else {
				ra -= re * 2;
				while (ra < 0)
					ra += 1000000007;
			}
			ra %= 1000000007;
			re %= 1000000007;
		}
		return ra;
	}
}

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

typedef long long ll;
typedef unsigned long long ull;

enum query{
    UNITE,SAME
};

template<unsigned long long SIZE> class unionFind{
    protected:
        long long uni[SIZE];
        long long diff_weight[SIZE];
    public:
        unionFind(){
            for(int i=0;i<SIZE;i++){
                uni[i]=-1;
                diff_weight[i]=0;
            }
        }
        unsigned long long root(unsigned long long a){
            if(a>=SIZE) throw std::range_error("与えられたインデックスが木の範囲外です");
            if(uni[a]<0) return a;
            else{
                unsigned long long r=root(uni[a]);
                diff_weight[a]+=diff_weight[uni[a]];
                return uni[a]=r;
            }
        }
        long long weight(unsigned long long a){
            root(a);
            return diff_weight[a];
        }
        long long diff(unsigned long long a, unsigned long long b){
            if(isSame(a,b)) return weight(b)-weight(a);
            else return INT64_MAX;
        }
        unsigned long long count(unsigned long long a){
            return -uni[root(a)];
        }
        bool merge(unsigned long long a, unsigned long long b, long long w=1){
            w+=weight(a);  w-=weight(b);
            a=root(a);  b=root(b);
            if(a==b) return false;
            if(uni[a]>uni[b]){
                swap(a, b);
                w=(-w);
            }
            uni[a]+=uni[b];
            uni[b]=a;
            diff_weight[b]=w;
            return true;
        }
        bool isSame(unsigned long long a,unsigned long long b){
            return root(a)==root(b);
        }
};

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

    unionFind<10000> uf;
    for(int i=0;i<q;i++){
        int com,x,y;
        cin >> com >> x >> y;
        switch(com){
            case UNITE:
                uf.merge(x,y);
                break;
            case SAME:
                cout << (uf.isSame(x,y)?1:0) << endl;
                break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3268
import collections
N, M = map(int, input().split())
X = list(map(int, input().split()))

table = collections.defaultdict(list)
for x in X:
    table[x % M].append(x)
Count = [None]*M
for i in range(M):
    Count[i] = collections.Counter(table[i]).values()
ans = 0
for i in range(M // 2 + 1):
    tmp = min(len(table[i]), len(table[(M-i) % M]))
    if i != (M-i) % M:
        ans += tmp
    else:
        ans += tmp // 2

    k = 0
    l = 0
    for x in Count[i]:
        k += x % 2
        l += x // 2
    if tmp <= k:
        ans += l
    else:
        ans += ((k + l*2) - tmp) // 2

    if i != (M-i) % M:
        k = 0
        l = 0
        for x in Count[(M-i) % M]:
            k += x % 2
            l += x // 2
        if tmp <= k:
            ans += l
        else:
            ans += ((k + l*2) - tmp) // 2

print(ans)


Measured memory_bytes: 61460
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

int solve()
{
  ll n ,k;
  cin >> n >> k ;
  std::vector<int> h(n);
  rep(i,0,n) cin >> h[i] ;
  std::vector<int> m(100005,1e9);
  m[1] = 0 ;
  for(int i = 1 ; i < n ;i++)
  {
    for(int j = 1 ; j <= k ;j++)
    m[i+j] = min(abs(h[i+j-1]-h[i-1])+m[i],m[i+j]);
  }
    cout << m[n] ;




}
int main()
{
  fast;
  ll t;
  t=1;
  //cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

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

int main()
{
  int n, i = 0;
  int car[10] = {};
  while(cin >> n){
    if(n == 0){
      cout << car[i - 1] << endl;
      car[i - 1] = 0;
      i--;
    }else{
      car[i] = n;
      i++;
    }
  }
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_A = 1000005;
int_fast32_t used[MAX_A];

signed main()
{
  int N; cin >> N;
  vector<int> A(N);
  REP(n,N) {
    cin >> A[n];
    used[A[n]]++;
  }

  int ans = 0;
  REP(n,N) {
    bool flag = true;
    if (A[n] == 1) {
      if (2 <= used[1]) {
        flag = false;
      }
    } else {
      FOR(i,1,sqrt(A[n]+1)) {
        if (A[n]%i == 0) {
          int a = i, b = A[n]/i;
          if (a == 1 || b == 1) {
            if (2 <= used[A[n]] || used[1]) {
              flag = false;
            }
          } else {
            if (used[a] || used[b]) {
              flag = false;
            }
          }
        }
      }
    }

    if (flag) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12824
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(B % A == 0) {
			System.out.println(A + B);
		}else {
			System.out.println(B - A);
		}
	}
}

Measured memory_bytes: 21844
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
puts nums[gets.to_i - 1]


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

public class Main {
	private static void solve(){
		//Implement solution here.
		long a = nl();
		long b = nl();
		long gcd = gcd(a,b);
		int result = 1;
		for(int i = 2; i <= Math.sqrt(gcd) + 1; i++) {
			if(gcd % i == 0) {
				result++;
				while(gcd % i == 0) {
					gcd /= i;
				}		
			}				
		}
		if(gcd > 1) {
			result++;
		}
		System.out.println(result);
	}
	
	static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a%b) : a;
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		} 
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  string ans = "YES";
  string prev = "";
  for (int i = 0; i < s.size(); ) {
    if (s.substr(i, 5) == "erase") {
      prev = "erase";
      i += 5;
    } else if (s.substr(i, 5) == "dream") {
      prev = "dream";
      i += 5;
    } else if (prev == "dream" && s.substr(i, 2) == "er") {
      prev = "";
      i += 2;
    } else if (prev == "erase" && s[i] == 'r') {
      prev = "";
      i++;
    } else {
      ans = "NO";
      break;
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

int main(){
	string s;
	cin>>s;
	int q;
	cin>>q;
	bool rev=false;
	vector<char>front,back;
	char c;
	for(int i=0,t,f;i<q;++i){
		cin>>t;
		if(t==1){if(rev)rev=false;else rev=true;}
		else{
			cin>>f>>c;
			if(f==1){
				if(rev)back.push_back(c);
				else front.push_back(c);
			}else{
				if(rev)front.push_back(c);
				else back.push_back(c);
			}
		}
	}
	if(rev){
		for(int i=back.size()-1;i>=0;--i)cout<<back.at(i);
		for(int i=s.size()-1;i>=0;--i)cout<<s.at(i);
		for(int i=0;i<front.size();++i)cout<<front.at(i);
	}else{
		for(int i=front.size()-1;i>=0;--i)cout<<front.at(i);
		for(int i=0;i<s.size();++i)cout<<s.at(i);
		for(int i=0;i<back.size();++i)cout<<back.at(i);
	}
}

Measured memory_bytes: 1152
n,k,*v=map(int,open(0).read().split())
m=0
r=range
for i in r(n+1):
 for j in r(min(k-i+1,n-i+1)):
  t=sorted(v[:i]+v[-j:]*(j>0))[::-1];c=k-i-j
  while t and c*t[-1]<0:t.pop();c-=1
  m=max(m,sum(t))
print(m)

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

using namespace std;

int main()
{
  int n;
  int q;
  int time_cnt=0;
  std::queue<string> name;
  std::queue<int> time;
  std::string name1[100000];
  int time1[100000];
  std::string k_name;
  int k_time;

  std::cin>>n>>q;

  for(int i=0; i<n; i++){
    std::cin>>name1[i]>>time1[i];
    name.push(name1[i]);
    time.push(time1[i]);
  }

  while(name.size()!=0){
    if(time.front()<=q){
      time_cnt+=time.front();
      std::cout<<name.front()<<" "<<time_cnt<<'\n';
      name.pop();
      time.pop();
    }else{
      time.front()-=q;
      time_cnt+=q;
      k_name=name.front();
      k_time=time.front();
      name.pop();
      time.pop();
      name.push(k_name);
      time.push(k_time);
    }
  }
  return 0;
}


Measured memory_bytes: 6652
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  bool ans = false;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == 'A' && s[i+1] == 'C') ans = true;
  }

  // 解答
  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  string S;
  cin>>S;
  
  if(S[2]==S[3]&&S[4]==S[5]){
    cout<<"Yes"<<endl;
  }
else{
cout<<"No"<<endl;
}
}


Measured memory_bytes: 256
K,N=map(int,input().split())
A=list(map(int,input().split()))
A.append(A[0]+K)
MAX=A[1]-A[0]
for i in range(0,N):
    if A[i+1]-A[i]>MAX:
        MAX=A[i+1]-A[i]
print(K-MAX)

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

int main() {

    // preparation of table of prime numbers
    int is_prime[101]; // 1: prime or unchecked, 0: non-prime 

    for (int i = 1; i <= 100; i++){
        is_prime[i] = 1;
    }

    is_prime[1] = 0;
    for (int i = 2; i <= 100; i++){
        if (is_prime[i] == 0) {
            continue;
        } else {
            for ( int j = 2; i * j <= 100; j++) {
                is_prime[i * j] = 0;
            }
        }
    }
    // end of preparation

    int N;
    cin >> N;
    int mult[101] = {};

    for (int i = 1; i <= N; i++){
        if (!is_prime[i]) {
            continue;
        }
        for (int p = 1; pow(i, p) <= N; p ++) {
            for (int j = 1; pow(i, p) * j <= N; j++){
                mult[i] ++;
            }
        }
    }

    int two = 0;
    int four = 0;
    for (int i = 1; i <= 100; i++){
        if (mult[i] >= 2) {
            two ++;
        }
        if (mult[i] >= 4) {
            four++;
        }
    }

    int ans = 0;
    for (int i = 0; i <= 100; i++){
        if (mult[i] >= 74) {
            ans ++;
        }
        if (mult[i] >= 24) {
            ans += two - 1;
        }
        if (mult[i] >= 14) {
            ans += four - 1;
        }
    }
    ans += (four * (four - 1) * (two - 2)) / 2;

    cout << ans;
}


Measured memory_bytes: 384
n,b,f[50001];main(a){for(;++a<5e4;)if(!f[a])for(b=a;b+a<5e4;)f[b+=a]=1;for(;~scanf("%d",&n);n&&printf("%d\n",b))for(b=0,a=1;a++<n/2;)f[a]+f[n-a]||b++;}

Measured memory_bytes: 596
#include<stdio.h>

int main(){

    int a,b,c,j;

    scanf("%d %d %d",&a,&b,&c);

    if(a > b){
        j = a;
        a = b;
        b = j;

    }

    if(a > c){
        j = a;
        a = c;
        c = j;
    }
    if(b > c){
        j = b;
        b = c;
        c = j;
    }

    printf("%d %d %d\n",a,b,c);






    return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s;
	cin >> s;
	
	int ans = 700;
	for(int i = 0; i < (int)s.size(); ++i) {
		if( s[i] == 'o' ) ans += 100;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

typedef long long ll;
const int maxn = 200005;
const ll mod = 1e9+7;
const int MAX_int = 1e9;
const double eps = 1e-9;
int used[105]; //在一次汉子匹配妹子时 妹子是否已经被更改过对象了
int nice[105][105]; //汉子妹子是否互通好感
int girl[105]; //妹子是否名花有主

int n;
struct P
{
    int a,b;
} p1[105],p2[105];

int find1(int x)
{
    for(int i=0;i<n;i++)
    {
        if(used[i]==false && nice[x][i] == 1)
        {
            used[i]=1;
            if(girl[i]==-1|| find1(girl[i]))
            {

                girl[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int action()
{
    memset(nice,0,sizeof(nice));
    memset(girl,-1,sizeof(girl));

    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        p1[i].a=a;
        p1[i].b=b;
    }
    for(int i=0; i<n; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        p2[i].a=a;
        p2[i].b=b;
    }
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
        {
            if(p1[i].a <p2[j].a && p1[i].b <p2[j].b)
            {
                nice[i][j]=1;

            }
        }
    int all=0;

    for (int i=0; i<n; i++)
    {
        memset(used,0,sizeof(used));    //这个在每一步中清空
        if (find1(i))
            all+=1;
    }
    printf("%d\n",all);
}

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



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    long long exor = 0;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        exor ^= a[i];
    }
    for (auto i : a) {
        cout << (i ^ exor) << " ";
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 4792
#include <iostream>

using namespace std;
using ll = long long;


void f(ll &A, ll &B, ll K)
{
    if (A >= K)
    {
        A -= K;
        return;
    }

    K -= A;
    A = 0;

    if (B >= K)
    {
        B -= K;
        return;
    }

    B = 0;
}

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;

    f(A, B, K);
    cout <<A << " " << B << endl;
}


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

char solve(char c, int k) {
    for (int i = 0; i < k; i++) {
        if (c == 'a') c = 'Z';
        else if (c == 'A') c = 'z';
        else c--;
    }
    return c;
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> k(n);
        for (int& x : k) cin >> x;
        string s;
        cin >> s;
        for (int i = 0; i < s.size(); ++i) {
            cout << solve(s[i], k[i % n]);
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	
	cin>>N;
	
	N %= 10;
	
	if(N == 3) cout<<"bon"<<endl;
	else if(N <= 1 || N == 6 || N == 8) cout<<"pon"<<endl;
	else cout<<"hon"<<endl;
 	
	
	
	return 0;
}

/*#coding:utf-8
import RPi.GPIO as GPIO
import time

#macrio
led=24

#settings
GPIO.setmode(GPIO.BCM)
GPIO.setup(led,GPIO.OUT,initial=GPIO.LOW)

#10 times turn on/off
for i in range(10):
    GPIO.output(led,1)
    time.sleep(1)
    GPIO.output(led, 0)
    time.sleep(1)

GPIO.cleanup()


*/

/*
#coding:utf-8
import RPi.GPIO as GPIO
import time

#macrio
button=25

#settings
GPIO.setmode(GPIO.BCM)
GPIO.setup(button,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

print("push button")
while True:
    btn = GPIO.input(button)
    if btn == True:
        print("pushed")
        break
    time.sleep(1)

GPIO.cleanup()

*/

/*
import RPi.GPIO as GPIO
import dht11
import time
import datetime

# initialize GPIO
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)

# read data using pin 14
instance = dht11.DHT11(pin=14)

try:
	while True:
	    result = instance.read()
	    if result.is_valid():
	        print("Last valid input: " + str(datetime.datetime.now()))

	        print("Temperature: %-3.1f C" % result.temperature)
	        print("Humidity: %-3.1f %%" % result.humidity)

	    time.sleep(6)

except KeyboardInterrupt:
    print("Cleanup")
    GPIO.cleanup()
*/

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

int main() {
  int a,b,c,s;
  cin >> a >> b >> c >> s;
  int ans = 0;
  int m = 0;
  
  int i,j,k;
  for(int t = 0; t < s; t++){
    i = a * 2 + b + c;
    j = a + 2 * b + c;
    k = a + b + c * 2;
    m = max({i,j,k});

    if(m == i) a = 2 * a;
    else if(m == j) b = 2 * b;
    else if(m == k) c = 2 * c;
  }
cout << m << endl;  
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::{max, min};

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let a = read::<u32>();
  let b = read::<u32>();
  let c = read::<u32>();
  

  println!("{}", min(c, b / a));
}



Measured memory_bytes: 4352
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
x,y = gets.chomp.split.map(&:to_i)

if y.odd?
  puts 'No'
else
  b = y / 2 - x
  if b < 0
    puts 'No'
  else
    a = x - b
    if a < 0
      puts 'No'
    else
      puts 'Yes'
    end
  end
end




Measured memory_bytes: 14692
import java.util.*;
import java.util.Collections;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
    int Zero = 0;
    int cnt = 0;
    for (int i = 0; i < M; i++) {
      if (X > sc.nextInt()) {
        Zero++;
      } else {
        cnt++;
      }
    }
    System.out.println(Math.min(Zero, cnt));
  }
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

ll grundy(vvl &adj, vl &g, ll i) {
	ll res = 0;
	set<ll> s;
	for (ll j: adj[i]) s.insert(g[j]);
	while (has(s,res)) res++;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	vvl adj(n);
	vl p(n);
	vl outdeg(n);

	FOR(i,0,n) {
		cin >> p[i];
		p[i]--;
		adj[p[i]].pb(i);
		outdeg[p[i]]++;
	}
	
	queue<ll> q;
	FOR(i,0,n) if (!outdeg[i]) q.push(i);
	
	vl g(n,-1);
	while (sz(q)) {
		ll i = q.front(); q.pop();
		g[i] = grundy(adj,g,i);
		if (!--outdeg[p[i]]) q.push(p[i]);
	}
	
	ll x = 0, y = -1;
	while (!outdeg[x]) x++;
	for (ll j: adj[x]) if (outdeg[j]) y = j;

	vl gg = g;

	g[x] = grundy(adj,g,x);
	for (ll i = p[x]; i != x; i = p[i]) g[i] = grundy(adj,g,i);

	if (g[x] != g[y]) {
		cout << "POSSIBLE" << endl;
		return 0;
	}
	
	g = gg;

	g[y] = grundy(adj,g,x);
	for (ll i = x; i != y; i = p[i]) g[i] = grundy(adj,g,i);

	if (grundy(adj,g,y) == g[y]) {
		cout << "POSSIBLE" << endl;
		return 0;
	}

	cout << "IMPOSSIBLE" << endl;
}



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

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int xmax = -100, ymin = 100;
    for (int i = 0; i < n; i++) {
        int xs;
        cin >> xs;
        xmax = max(xs, xmax);
    }
    for (int i = 0; i < m; i++) {
        int ys;
        cin >> ys;
        ymin = min(ys, ymin);
    }
    if (xmax >= ymin || ymin <= x || y <= xmax) {
        cout << "War" << endl;
    } else {
        cout << "No War" << endl;
    }
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

ll gcd(ll a,ll b) {
	return b ? gcd(b, a%b) : a;
}

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

	ll x,y;
	cin>>x>>y;
	cout<<gcd(x,y)<<endl;

	return 0;
}



Measured memory_bytes: 3172
n=int(input())
a=[int(i) for i in input().split()]
ans=0
for i in range(n):
    m=i
    for j in range(i,n):
        if a[j]<a[m]:
            m=j
    if m!=i:
        a[i],a[m]=a[m],a[i]
        ans+=1
print(*a)
print(ans)


Measured memory_bytes: 5612
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

H,W = map(int,readline().split())
A = [line.rstrip().decode('utf-8') for line in readlines()]

class Dinic:
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink

    def add_edge(self, fr, to, cap):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, n2])
        self.G[to].append([fr, 0, n1]) # 逆辺を cap 0 で追加
        
    def add_edge_undirected(self, fr, to, cap):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, n2])
        self.G[to].append([fr, cap, n1]) # 逆辺を cap 0 で追加
        
    def bfs(self):
        level = [0] * self.N
        G = self.G; source = self.source; sink = self.sink
        q = deque([source])
        level[source] = 1
        pop = q.popleft; append = q.append
        while q:
            v = pop()
            lv = level[v] + 1
            for to, cap, rev in G[v]:
                if not cap:
                    continue
                if level[to]:
                    continue
                level[to] = lv
                if to == sink:
                    self.level = level
                    return
                append(to)
        self.level = level
        
    def dfs(self,v,f):
        if v == self.sink:
            return f
        G = self.G
        prog = self.progress
        level = self.level
        lv = level[v]
        E = G[v]
        for i in range(prog[v],len(E)):
            to, cap, rev = E[i]
            prog[v] = i
            if not cap:
                continue
            if level[to] <= lv:
                continue
            x = f if f < cap else cap
            ff = self.dfs(to, x)
            if ff:
                E[i][1] -= ff
                G[to][rev][1] += ff
                return ff
        return 0
    
    def max_flow(self):
        INF = 10**18
        flow = 0
        while True:
            self.bfs()
            if not self.level[self.sink]:
                return flow
            self.progress = [0] * self.N
            while True:
                f = self.dfs(self.source, INF)
                if not f:
                    break
                flow += f
        return flow

source = 0
sink = H+W+1

dinic = Dinic(H+W+2, source, sink)
add = dinic.add_edge_undirected

INF = 10 ** 18
for h in range(1,H+1):
    for w,ox in enumerate(A[h-1],1):
        if ox == 'x':
            continue
        elif ox == 'o':
            add(h,H+w,1)
        elif ox == 'S':
            add(source,h,INF)
            add(source,H+w,INF)
        elif ox == 'T':
            add(sink,h,INF)
            add(sink,H+w,INF)

f = dinic.max_flow()
answer = f if f < INF else -1
print(answer)


Measured memory_bytes: 45532
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,n,k);
  int i;
  int a=1;
  rep(i,n)
    {
      if(a*2>a+k)
	a+=k;
      else
	a*=2;
    }
  putv(a);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll X = 0;
    rep(i,n){
        cin >> a[i];
        X += a[i];
    }
    ll x = 0;
    ll ans = LINF;
    rep(i,n){
        x += a[i];
        if(i+1 < n) ans = min(ans,abs(X - 2*x));
    }
    cout << ans << endl;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , m , k;
int p[MAXX];

int main()
{
    _FastIO;

    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p , p + n);
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String n = sc.next();
        
        boolean big = false;
        for(int i=1;i<n.length();i++){
            if(n.charAt(i)>n.charAt(0)){
                big=true;
                break;
            }
        }
        
        String ans = "";
        if(big){
            for(int i=0;i<n.length();i++){
                ans+=(char)(n.charAt(0)+1);
            }
        }
        else{
            for(int i=0;i<n.length();i++){
                ans+=n.charAt(0);
            }
        }
        
        System.out.println(ans);
        
    }
}
/*
112
*/

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

using namespace std;

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

  string s;
  std::cin >> s;

  int score = 0;
  for(int i=1; i<s.size(); i++){
    if( s.at(i-1) == s.at(i) ) score += 1;
  }

  std::cout << std::min(score+2*k, n-1) << '\n';

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
typedef long long ll;

ll n, q, a[N], k[N], sa[N], sb[N];
int main() {
	ll i, j, x, t;
	scanf("%lld%lld", &n, &q);
	for(i=1+n%2, j=0; j<n; i++, j++) scanf("%lld", &a[i]);
	n += n%2;
	for(i=1; i<=n/2; i++) k[i] = (a[i*2] + a[n/2+i])/2;
	for(i=1; i<=n; i++) sa[i] = sa[i-1] + a[i];
	for(i=1; i<=n; i++) sb[i] = sb[i-1] + (i%2 ? 0:a[i]);
	while(q--) 
    {
		scanf("%lld", &x);
		t = lower_bound(k, k+n/2, x) - k;
		t = n/2 - t + 1;
		printf("%lld\n", sa[n] - sa[n-t] + sb[n-t*2]);
	}
	return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e18;
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int a,b,k;
	cin >> a >> b >> k;
	if(a>=k)cout << a-k <<  " " << b;
	else cout << 0 <<  ' ' << max(0LL,a+b-k) ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    ll x;
    cin >> x;
    ll sum = 0;
    int flag = 0;
    ll count = 0;
    ll num = x/11;
    if(x%11 <= 6 && x%11 != 0) {
        flag = 1;
    }
    else if(x%11 != 0) {
        flag = 2;
    }
    cout << num*2+flag << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>
#include <cmath>
#include <regex>
using namespace std;

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  // A/B の切り上げは A+B−1 /B の商と等しいらしい
  int N, D;
  cin >> N >> D;
  cout << ((N + D *2) / (2 * D + 1)) << endl;
}

Measured memory_bytes: 256
from collections import deque

A = input().split(' ')
n = int(A[0])
q = int(A[1])

a = deque()
for _ in range(n):
    t = (input().split(' '))
    t[1] = int(t[1])
    a.append(t)

b = deque()
s = 0
while len(a) != 0:
    t = a.popleft()
    if t[1] - q <= 0:
        b.append((t[0], t[1] + s))
        s += t[1]
    else:
        t[1] -= q
        s += q
        a.append(t)

for i in b:
    print(i[0], i[1])



Measured memory_bytes: 18684
#include <bits/stdc++.h>
using namespace std;
void nil()
{
	int n,m;
	cin>>n>>m;
	if(m*2<n) 
	{
		cout<<n-(m*2)<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
	
}
int main()
{
	#ifndef ONLINE_JUDGE

		freopen("input1.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif	
		nil();

}

Measured memory_bytes: 3668
from collections import deque
n=int(input())
d=dict()
edge=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
c=list(map(int,input().split()))
c.sort(reverse=True)
visited=[-1]*n
def bfs(s):
  i=0
  q=deque([s])
  visited[s]=c[i]
  while q:
    x=q.popleft()
    for nx in edge[x]:
      if visited[nx]==-1:
        i+=1
        visited[nx]=c[i]
        q.append(nx)
  return
bfs(0)
print(sum(c)-max(c))
print(*visited)

Measured memory_bytes: 6168
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
string s[1000];
int p[1000];
void init(int n){
	rep(i,n) p[i]=i;
}
int find(int x){
	if(x==p[x]) return x;
	return p[x]=find(p[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	p[x]=y;
}
bool same(int x,int y){
	return find(x)==find(y);
}
int dp[1000][1000][2][2];
bool calc(int e,int o,int k,int turn){
	int &d=dp[e][o][k][turn];
	if(d==1) return true;
	if(d==-1) return false;
	if(e+o<=1){
		if(turn==1){
			d=1;
			return true;
		}else{
			d=-1;
			return false;
		}
	}
	if(turn==1){
		bool Awin=false;
		if(e>=2) if(calc(e-1,o,1-k,1-turn)) Awin=true;
		if(o>=2) if(calc(e+1,o-2,k,1-turn)) Awin=true;
		if(e>=1&&o>=1) if(calc(e-1,o,1-k,1-turn)) Awin=true;
		if(k==1) if(calc(e,o,0,1-turn)) Awin=true;
		if(Awin){
			d=1;
			return true;
		}else{
			d=-1;
			return false;
		}
	}else{
		bool Bwin=false;
		if(e>=2) if(!calc(e-1,o,1-k,1-turn)) Bwin=true;
		if(o>=2) if(!calc(e+1,o-2,k,1-turn)) Bwin=true;
		if(e>=1&&o>=1) if(!calc(e-1,o,1-k,1-turn)) Bwin=true;
		if(k==1) if(!calc(e,o,0,1-turn)) Bwin=true;
		if(Bwin){
			d=-1;
			return false;
		}else{
			d=1;
			return true;
		}
	}
}
int main(){
	int V;
	cin>>V;
	rep(i,V) cin>>s[i];
	init(V);
	int e=0;
	rep(i,V) rep(j,V){
		if(s[i][j]=='Y'){
			unite(i,j);
			e++;
		}
	}
	e/=2;
	int cnt[1000]={};
	rep(i,V) cnt[find(i)]++;
	int odd=0,even=0,k=0;
	rep(i,V){
		if(cnt[i]==0) continue;
		k+=cnt[i]*(cnt[i]-1)/2;
		if(cnt[i]%2==0) even++;
		else odd++;
	}
	cout<<(calc(even,odd,(k-e)%2,1) ? "Taro\n" : "Hanako\n");
}

Measured memory_bytes: 10524
#include<bits/stdc++.h>
using namespace std;
typedef unsigned int64;
#define __2012_12_21__ 735224
#define MAX_YEAR 10000000

int64 days[MAX_YEAR + 1];
int month[2][13] = {
  { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
  { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
};


bool urudosi(int year){
  return year % 400 == 0 || (year % 100 != 0 && year % 4 == 0);
}
void init_set() {
  for(int i = 1; i <= MAX_YEAR; i++) {
    days[i] = days[i - 1] + 365 + urudosi(i - 1);
  }
}

int main(){
  char buff[256];
  int y, m, d; //西暦
  int b, ka, t, w, ki; //マヤ長期歴

  init_set();
  while(strcmp(fgets( buff, sizeof(buff), stdin),"#\n") != 0){

    /* 入力 */
    if(sscanf( buff, "%d.%d.%d.%d.%d", &b, &ka, &t, &w, &ki) == 5){
      /*マヤ長期歴 → 西暦 */
      int64 allday = b * 144000 + ka * 7200 + t * 360 + w * 20 + ki + __2012_12_21__;
      y = lower_bound( days, days + MAX_YEAR, allday) - days - 1;
      allday -= days[y];
      bool uru = urudosi(y);
      m = lower_bound( month[uru], month[uru] + 13, allday) - month[uru];
      d = allday - month[uru][m - 1];
      printf("%d.%d.%d\n", y, m, d);
    }else{
      sscanf( buff, "%d.%d.%d", &y, &m, &d);
      int64 allday = days[y] + month[urudosi(y)][m - 1] + d - __2012_12_21__;
      ki = allday % 20;
      w = allday / 20 % 18;
      t = allday / 360 % 20;
      ka = allday / 7200 % 20;
      b = allday / 144000 % 13;
      printf("%d.%d.%d.%d.%d\n", b, ka, t, w, ki);
    }
  }
}

Measured memory_bytes: 40264
#include <iostream>
#include <set>
#include <string>
#include <iterator>
using namespace std;

int main() {
	int n,m; cin >> n;
	string s[n];
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	set<string> stb(s, s+n);
	multiset<string>  mstb(s, s+n);
	cin >> m;
	string t[m];
	for (int j = 0; j < m; ++j) {
		cin >> t[j];
	}
	multiset<string>  mstr(t, t+m);
	int maxout = 0;
	auto itr = stb.begin();
	for (itr; itr != stb.end(); ++itr) {
		int tmp = mstb.count(*itr);
		tmp -=  mstr.count(*itr);
		if (maxout < tmp) maxout = tmp;
	}
	cout << maxout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=25;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,ans,ansl;
int F[1<<21],G[1<<21];
int *f[N],*g[N];
char ch[1<<20];
int main(){
	n=read();m=read();
	for (int i=0;i<=n;i++){
		f[i]=F+(1<<i);g[i]=G+(1<<i);
		scanf(" %s",ch);
		for (int j=0;j<(1<<i);j++){
			f[i][j]=ch[j]-'0';
			int fl=(j>>(i-1))&1,k=i-1;
			for (;(k>=0)&&(((j>>k)&1)==fl);k--);
			g[i][j]=k+1;
		}
	}
	for (int i=0;i<=n;i++)
	for (int j=1;i+j<=n;j++)
	for (int k=0;k<(1<<(i+j));k++){
		int kl=k>>j,kr=k&((1<<j)-1),t=g[j][kr];
		f[i][k>>j]+=f[i+j][k];
		if (t) f[i+t][(kl<<t)|(kr&((1<<t)-1))]+=f[i+j][k];
	}
	ans=-1;
	for (int i=0;i<=n;i++)
	for (int k=(1<<i)-1;k>=0;k--)
	if (f[i][k]>=m){ans=i;ansl=k;}
	for (int i=ans-1;i>=0;i--) putchar('0'+((ansl>>i)&1));
	puts("");
	return 0;
}

Measured memory_bytes: 17792
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), c.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


int main() {
  int H, W;
  while(true) {
    int cnt=1;
    scanf("%d %d", &H, &W);
    if(W==0 && H==0) break;
    rep(i, H) {
      if(cnt==1||cnt==H) rep(j, W) printf("#");
      else {
        printf("#");
        rep(j, W-2) printf(".");
        printf("#");
      }
      printf("\n");
      cnt++;
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3104