akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

class Belongings {
public:
  Belongings() : left(100),right(0),upper(100),lower(0){}
  int left,right,upper,lower;
};


bool check(char hypothesis[50][50],char stage[50][50],int W,int H){
  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      if(hypothesis[y][x] != stage[y][x]) return false;
    }
  }
  return true;
}

int main(){
  int N;
  while(~scanf("%d",&N)){
    for(int stage_idx = 0; stage_idx < N; stage_idx++){
      int H,W;
      
      scanf("%d %d",&H,&W);

      char stage[50][50];
      char hypothesis[50][50];

      memset(stage,'.',sizeof(stage));

      map<char,Belongings> layer;

      for(int y=0;y<H;y++){
	char line[51];
	scanf("%s",line);
	for(int x=0;x<W;x++){
	  stage[y][x] = line[x];
	  if(line[x] == '.') continue;
	  //x:0->...
	  //y:0
	  //  |
	  //  v
	  //  .
	  //  upper
	  //left right
	  //  lower
	  Belongings& be = layer[stage[y][x]];
	  be.left = min(be.left,x);
	  be.right = max(be.right,x);
	  be.upper = min(be.upper,y);
	  be.lower = max(be.lower,y);
	}
      }

      bool is_safe = false;

      vector<char> order;
      for(map<char,Belongings>::iterator it = layer.begin();
	  it != layer.end();
	  it++){
	order.push_back(it->first);
      }
      sort(order.begin(),order.end());


      do{
	memset(hypothesis,'.',sizeof(hypothesis));

	for(int i=0;i<order.size();i++){
	  char c = order[i];
	  Belongings& be = layer[c];
	  for(int y=be.upper; y<=be.lower; y++){
	    for(int x=be.left; x<=be.right; x++){
	      hypothesis[y][x] = c;
	    }
	  }
	}

	if(check(hypothesis,stage,W,H)){
	  is_safe = true;
	  break;
	}
      }while(next_permutation(order.begin(),order.end()));
      printf("%s\n",is_safe ? "SAFE" : "SUSPICIOUS");
      
    }
  }
  return 0;
}

Measured memory_bytes: 1196
object Main {
  val dir = List((-1, 0), (0, 1), (1, 0), (0, -1))
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextInt
    while(n != 0) {
      val pos = for(_ <- 1 to n - 1) yield (sc.nextInt, sc.nextInt)
      val poses = scala.collection.mutable.ArrayBuffer.empty[(Int, Int)]
      poses += ((0, 0))
      for(p <- pos) {
        poses += ((poses(p._1)._1 + dir(p._2)._1, poses(p._1)._2 + dir(p._2)._2))
      }
      val rangeX = poses.map(p => p._1).max - poses.map(p => p._1).min + 1
      val rangeY = poses.map(p => p._2).max - poses.map(p => p._2).min + 1
      println(List(rangeX, rangeY).mkString(" "))
      n = sc.nextInt
    }
  }
}

Measured memory_bytes: 59676
import math

Num,HP = (map(int,input().split()))
#Katanas = [list(map(int,input().split())) for _ in range(Num)]

CKatanaMax = 0
katanas = []

for _ in range(Num):
    a,b = map(int,input().split())
    CKatanaMax = max(CKatanaMax,a)
    katanas.append(b)

Tkatanas = sorted([x for x in katanas if x > CKatanaMax],reverse=True)

attake = 0
for Tkatana in Tkatanas:
    HP -= Tkatana
    attake += 1
    if HP <= 0:
        break
else:
    attake += math.ceil(HP/CKatanaMax)
print(attake)

Measured memory_bytes: 9056
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  ll n, a[5], num[5];
  cin >> n;
  ll mi = LINF;
  rep (i, 5) {
    cin >> a[i];
    mi = min(a[i], mi);
  }
  ll ans = 4;
  ans += n /mi;
  if (n % mi != 0) ans++;
  P(ans);
  return 0;
}



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

using namespace std;

typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n+1);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<pair<int, int>> orders(n+1);
    for (int i = 0; i <= n; ++i) {
        orders[i] = { 1e9, i };
    }
    vector<bool> reached(n+1);
    int start = 1;
    int goal = g[start][0];
    reached[start] = true;
    reached[goal] = true;
    orders[start].first = 0;
    orders[goal].first = 1;
    int count = 2;
    while (1) {
        bool finished = true;
        for (int v : g[start]) {
            if (!reached[v]) {
                finished = false;
                reached[v] = true;
                orders[v].first = orders[start].first - 1;
                start = v;
                count++;
                break;
            }
        }
        for (int v : g[goal]) {
            if (!reached[v]) {
                finished = false;
                reached[v] = true;
                orders[v].first = orders[goal].first + 1;
                goal = v;
                count++;
                break;
            }
        }
        if (finished) {
            break;
        }
    }
    sort(orders.begin(), orders.end());
    cout << count << endl;
    for (int i = 0; i < count; ++i) {
        cout << orders[i].second << ' ';
    }
    return 0;
}


Measured memory_bytes: 9512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


def main():
    n, k = map(int, input().split())
    s = input().strip()
    prevs = s[0]
    la = [0]
    for _s in s:
        if prevs == _s:
            la[-1] += 1
        else:
            la.append(1)
            prevs = _s
    
    ans = 0
    is_swap = False
    for i in range(0, len(la), 2):
        ans += la[i]-1
        if is_swap:
            ans += 1
            is_swap = False
        if i+1 < len(la) and k >= 1:
            ans += la[i+1]
            k -= 1
            is_swap = True
        elif i+1 < len(la):
            ans += la[i+1]-1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4088
#include<stdio.h>

int main(void)
{
    int town[4];
    for(int i = 0; i < 4; i++)
    {
        town[i] = 0;
    }
    
    for(int i = 0; i < 6; i++)
    {
        int tmp;
        scanf("%d",&tmp);
        town[tmp-1]++;
    }

    for(int i = 0; i < 4; i++)
    {
        if(town[i] == 3)
        {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 128
n=int(input())
tens=[]
for i in range(n):
    x,y=map(int,input().split())
    tens.append([x,y])

tasu=[]
hiku=[]

for i in range(n):
    tasu.append(tens[i][0]+tens[i][1])
    hiku.append(tens[i][0]-tens[i][1])

#print(tasu,hiku)

a=max(tasu)-min(tasu)
b=max(hiku)-min(hiku)

print(max(a,b))

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

int main()
{
	int r,d,x;
	int A, B, C, D, E, F, G, H, I;
	cin >> r >> d >> x;
	cout << r * x - d << endl;
	A = r* x - d;
	cout << r * A - d << endl;
	B = r* A - d;
	cout << r * B - d << endl;
	C = r * B - d;
	cout << r * C - d << endl;
	D = r * C - d;
	cout << r * D - d << endl;
	E = r * D - d;
	cout << r * E - d << endl;
	F = r * E - d;
	cout << r * F - d << endl;
	G = r * F - d;
	cout << r * G - d << endl;
	H = r * G - d;
	cout << r * H - d << endl;
	I = r * H - d;
	cout << r * I - d << endl;
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。

int main(){
    int n;
    cin>>n;
    int v[n],c[n];
    rep0(i,n) cin>>v[i];
    rep0(i,n) cin>>c[i];
    int ans=0;
    int N=(1<<n);
    rep0(i,N){
        int pos=0;
        rep0(j,n){
            if(((i>>j)&1)){
                pos+=v[j];
                pos-=c[j];
            }
        }
        ans=max(ans,pos);
        //cout<<i<<" "<<pos<<endl;

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

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

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine());
    var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    var s = a.Sum();
    var ans = s;
    var ps = 0;
    for (int i = 0; i < n; i++) {
      ps += a[i];
      ans = Math.Min(ans, Math.Abs(s - 2 * ps));
    }
    Console.WriteLine(ans);
  }
}

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

int main(){
  int n,a,b;
  cin >>n >>a >>b;
  string s;
  cin >>s;
  int cnt1 = 0;
  int cnt2 = 0;
  rep(i,n){
    if(s[i]=='a' && cnt1<a+b){
      cout << "Yes" << endl;
      cnt1++;
    }
    else if(s[i]=='b' && cnt1<a+b && cnt2<b){
      cout << "Yes" << endl;
      cnt1++;
      cnt2++;
    }
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll mypow(ll a, ll b) {
  ll two;
  ll tmp;
  ll ans = 1;
  while(b>0) {
    two = 1;
    tmp = a;
    while(2*two<b) {
      two *= 2;
      tmp *= tmp;
    }
    b -= two;
    ans *= tmp;
  }
  return ans;
}

int main() {
  ll N, P;
  cin>>N>>P;
  vector<ll> prime;
  map<ll, ll> amap;
  for(ll i=2;i*i<=P;++i) {
    if(P%i==0) prime.push_back(i);
    while(P%i==0) {
      amap[i]++;
      P /= i;
    }
  }
  if(P>1) {
    prime.push_back(P);
    amap[P]++;
  }
  ll ans = 1;
  for(int i=0;i<prime.size();++i) {
    ans *= mypow(prime[i], amap[prime[i]]/N);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3628
import java.util.Scanner;

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

		int B[] = new int[M];
		for (int i = 0; i < M; i++) {
			B[i] = sc.nextInt();
		}

		int ans = 0;

		for (int i = 0; i < N; i++) {

			int sum = 0;
			int A[] = new int[M];

			for (int j = 0; j < M; j++) {
				A[j] = sc.nextInt();

				sum += A[j]*B[j];
				if (j == M-1) {
					sum += C;
					if (sum > 0) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
 	}
}


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

int main() {
  int s,t,ans = 0;
  cin >> s;
  vector<string>datas(s);
  for(int i = 0;i < s;i++){
    cin >> datas.at(i);
  }
  cin >> t;
  vector<string>datat(t);
  for(int i = 0;i < t;i++){
    cin >> datat.at(i);
  }
  for(int i = 0;i < s;i++){
    int a = 0;
    for(int j = 0;j < s;j++){
      if(datas.at(i) == datas.at(j)){
        a++;
      }
    }
    for(int j = 0;j < t;j++){
      if(datas.at(i) == datat.at(j)){
        a--;
      }
    }
    if(a > ans){
      ans = a;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    n = int(input())
    s = input()

    west_list = []
    east_list = []
    west_list.append(0)
    east_list.append(0)

    for i in range(n - 1):
        prev = west_list.pop()
        now = prev + (1 if s[i] == "W" else 0)
        west_list.append(prev)
        west_list.append(now)
        prev = east_list.pop()
        now = prev + (1 if s[n - 1 - i] == "E" else 0)
        east_list.append(prev)
        east_list.append(now)
    east_list.reverse()

    print(min(a + b for a, b in zip(east_list, west_list)))


Measured memory_bytes: 27152
H, W = gets.split.map(&:to_i)

def bisect(x, y)
  if x.even? || y.even?
    s = x * y / 2
    [s, s]
  else
    x, y = y, x if x > y
    s = x * (y - 1) / 2
    [s, s + x]
  end
end

def trisect(x, y)
  [x/3, x/3 + 1].map{|a| [a*y, bisect(x-a, y)].flatten.minmax.inject(:-).abs}.min
end

puts (H%3) * (W%3) == 0 ? 0 : [trisect(H, W), trisect(W, H)].min

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

int main(){
    int n;
    cin >> n;
    int a[n];
    
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    for(int i = n - 1; i >= 0; i--){
        cout << a[i];
        
        if(i != 0) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char a[11],b[11],c[11];
    cin>>a>>b>>c;
    int ln1,ln2;
    ln1=strlen(a);
    ln2=strlen(b);
    if((a[ln1-1]==b[0])&&(b[ln2-1]==c[0])){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
count = 0

for i in range(1, n-1):
    if p[i-1] < p[i]:
        if p[i] < p[i+1]:
            count += 1
    if p[i-1] > p[i]:
        if p[i] > p[i+1]:
            count += 1
            
print(count)

Measured memory_bytes: 61540
#include <iostream>
#include <vector>

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

using namespace std;


const int mod = 1000000007;
struct mint
{
  long long x;
  mint(long long x=0):x(x%mod){}

  mint& operator+=(const mint a)
  {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a)
  {
    (x -= a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const
  {
    if(!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const
  {
    return pow(mod-2);
  }
  mint& operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

struct combination
{
  vector<mint> fact;
  combination(ll n):fact(n+1)
  {
    fact[0] = 1;
    for(ll i = 1; i < n+1; ++i)
    {
      fact[i] = fact[i-1] * i;
    }
  }

  //n! / r!(n-r)!
  mint comb(ll n, ll k)
  {
    if(n < 0 || n < k) return 0;

    return fact[n] / (fact[k] * fact[n-k]);
  }
};
mint f(ll x, ll y)
{
  ll n = 0, m = 0;
  bool ok = false;
  for(ll i = 0; i <= (y / 2); ++i)
  {
    if((x - i) & 1) continue;
    n = i; m = (x-i)/2;
    if((ok = ((n*2 + m) == y))) break;
  }
  if(!ok) return 0;
  mint nm = n + m;
  combination c(n + m + 1);
  return c.comb(n+m, n);
}

int main()
{
  ll x, y;
  cin >> x >> y;
  cout << f(x, y).x << endl;

  return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 2000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
int iv[N],inv[N],fac[N];
inline int C(int n,int m){return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{	int n,sum=0; cin>>n;
	iv[1]=fac[0]=inv[0]=1;for(rint i=2;i<=n;i++)iv[i]=(ll)(mod-mod/i)*iv[mod%i]%mod;
	for(rint i=1;i<=n;i++)fac[i]=(ll)fac[i-1]*i%mod,inv[i]=(ll)inv[i-1]*iv[i]%mod;
	for(rint i=(n+1)/2;i<n-1;i++)(sum+=(ll)C(i-1,n-i-1)*fac[i]%mod*fac[n-1-i]%mod)%=mod;
	cout<<((ll)(n-1)*fac[n-1]%mod-sum+mod)%mod;
	return 0;
}


Measured memory_bytes: 16640
import qualified Data.ByteString.Char8 as BS

main = do
  BS.getLine
  s <- BS.getLine
  t <- BS.getLine
  let ans = compute s t
  print ans

compute :: BS.ByteString -> BS.ByteString -> Int
compute s t = head
  [ BS.length s + d
  | (s1,d) <- zip (BS.tails s) [0..]
  , s1 `BS.isPrefixOf` t
  ]

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h,aa;
    cin>>h>>aa;
    ll a[100004],s=0;
    for(ll i=0; i<aa; i++){
    	cin>>a[i];
    	s+=a[i];
    }
    cout<<(s>=h?"Yes":"No")<<endl;

    return 0;
}

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

int a[200005],total=0;

int main()
{
	int n,k;
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		char x;
		cin>>x;
		if (x=='L')  a[i]=0;
		else a[i]=1;
	}
	for (int i=1;i<=n-1;i++)
	{
		if (a[i]==a[i+1])  total++;  
	}
	cout<<min(total+2*k,n-1)<<endl;
	return 0;
}

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

const int INF = 2147483647;

struct Node {
  int lp, rp; // [l, r)
  int v;
  Node *lc, *rc;
  Node(int v_, int lp_, int rp_)
    : v(v_), lp(lp_), rp(rp_) {
  }
  ~Node() {
    delete lc;
    delete rc;
  }
};

int minv(Node* x, Node* y) {
  if (!x) return (!y)?INF:y->v;
  if (!y) return x->v;
  return min(x->v, y->v);
}

void update(Node *t, int k, int a) {
  if (t->rp - t->lp == 1 and t->lp == k) {
    t->v = a;
    return;
  } 
  int mid = (t->lp + t->rp) / 2;
  if (k < mid) {
    if (!(t->lc)) t->lc = new Node(INF, t->lp, mid);
    update(t->lc, k, a);
  } else {
    if (!(t->rc)) t->rc = new Node(INF, mid, t->rp);
    update(t->rc, k, a);
  }
  t->v = minv(t->lc, t->rc);
  return;
}

// min([a,b))
int query(Node* t, int a, int b) {
  if (!t) return INF;
  if (t->rp <= a || b <= t->lp) return INF;
  else if (a <= t->lp && t->rp <= b) return t->v;
  else {
    int vl = query(t->lc, a, b);
    int vr = query(t->rc, a, b);
    return min(vl, vr);
  }
}

int main() {
  int nm, q;
  cin >> nm >> q;
  int n = 1;
  while (n < nm) n*=2;
  Node* t = new Node(INF, 0, n);
  for (int i = 0; i < q; ++i) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 1) {
      cout << query(t, x, y+1) << endl;
    } else {
      update(t, x, y);
    }
  }
}

Measured memory_bytes: 6692
import Data.Functor ((<$>))
import Data.List (transpose)

main :: IO ()
main = do
    sheet <- map (map read . words) . tail . lines <$> getContents :: IO [[Int]]
    let sheet' = sumRow $ sumCol sheet
    putStr . unlines . map (unwords . map show) $ sheet'
  where sumRow = map (\r -> r ++ [sum r])
        sumCol = transpose . sumRow . transpose



Measured memory_bytes: 7516
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    map<int, int> odd, even;
    int odd_cnt = 0, even_cnt = 0;
    for(int i = 0; i < n; i++){
        int num;
        cin >> num;
        if(i % 2 == 0){
            even[num]++;
            even_cnt++;

        }else{
            odd[num]++;
            odd_cnt++;
        }
    }
    vector<pair<int, int>> odd_list, even_list;
    for(auto o: odd){
        odd_list.push_back(make_pair(o.second, o.first));
    }
    odd_list.push_back(make_pair(0, -100));
    for(auto e: even){
        even_list.push_back(make_pair(e.second, e.first));
    }
    even_list.push_back(make_pair(0, -101));
    sort(odd_list.begin(), odd_list.end());
    sort(even_list.begin(), even_list.end());
    reverse(odd_list.begin(), odd_list.end());
    reverse(even_list.begin(), even_list.end());

    if(odd_list[0].second != even_list[0].second){
        cout << n - odd_list[0].first - even_list[0].first << endl;
        return 0;
    }

    int mini = min(odd_list[0].first, even_list[0].first);
    int maxi = max(odd_list[1].first, even_list[1].first);
    cout << n - mini - maxi << endl;

    return 0;
}


Measured memory_bytes: 6136
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemD_DigitSumReplace solver = new ProblemD_DigitSumReplace();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemD_DigitSumReplace {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int m = in.nextInt();
            Pair o = null;
            for (int i = 0; i < m; i++) {
                int d = in.nextInt();
                long c = in.nextLong();
                Pair t = reduce(d, c);
                if (i == 0) {
                    o = t;
                } else {
                    o = combine(o, t);
                }
            }
            out.println(o.ops);
        }

        private Pair combine(Pair a, Pair b) {
            int rem = a.rem + b.rem;
            long ops = 1 + a.ops + b.ops;
            int u = rem / 10;
            int v = rem % 10;
            if (u > 0) {
                ++ops;
                ++v;
            }
            return new Pair(ops, v);
        }

        private Pair reduce(int d, long c) {
            if (c == 0) {
                return new Pair(0, 0);
            }
            if (c == 1) {
                return new Pair(0, d);
            }
            if (c % 2 != 0) {
                Pair a = reduce(d, c - 1);
                Pair b = new Pair(0, d);
                return combine(a, b);
            }
            Pair a = reduce(d, c / 2);
            return combine(a, a);
        }

        class Pair {
            long ops;
            int rem;

            Pair(long ops, int rem) {
                this.ops = ops;
                this.rem = rem;
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 145948
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;


int main() {

	long long int x, y;
	cin >> x;
	long long int ans = 0;
	ans = (x / 11)*2;
	if (x % 11) {
		if (x % 11 > 6)ans += 2;
		else ans++;
	}
	cout << ans << endl;

	return 0;

}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int a, b, c, d, k;
  cin>>a>>b>>c>>d>>k;
  cout<<(c*60+d)-(a*60+b)-k<<'\n';
  return 0;
}


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

int vacation(int arr[][3], int n){
    if(n == 0)
        return 0;
    int m = INT_MIN, sm = INT_MIN, mc, smc;
    for(int j=0; j<3; j++)
        if(arr[n-1][j] > m){
            sm = m;
            m = arr[n-1][j];
            smc = mc;
            mc = j;
        }
        else if(arr[n-1][j] > sm){
            sm = arr[n-1][j];
            smc = j;
        }

    for(int i=n-2; i>=0; i--){
        int cm = INT_MIN, csm = INT_MIN, cmc, csmc;
        for(int j=0; j<3; j++){
            int currHappiness;
            if(j == mc){
                currHappiness = arr[i][j] + sm;
            }
            else
                currHappiness = arr[i][j] + m;
            if(currHappiness > cm){
                csm = cm;
                cm = currHappiness;
                csmc = cmc;
                cmc = j;
            }
            else if(currHappiness > csm){
                csm = currHappiness;
                csmc = j;
            }
        }
        m = cm;
        mc = cmc;
        sm = csm;
        smc = csmc;
    }
    return m;
}

int main()
{
 int n;
 cin>>n;
 int arr[n][3];
 for(int i=0; i<n; i++)
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
 int ans = vacation(arr, n);
 cout<<ans;
 return 0;
}



Measured memory_bytes: 4772
A = []
A.append(list(map(lambda x: int(x), input().split())))
A.append(list(map(lambda x: int(x), input().split())))
A.append(list(map(lambda x: int(x), input().split())))

answers = []
for _ in range(3):
  answers.append([False for _ in range(3)])

N = int(input())
numbers = []
for _ in range(N):
  numbers.append(int(input()))

for number in numbers:
  for y in range(3):
    # 同じ列に複数個要素が含まれている場合ができていない
    if number in A[y]:
      answers[y][A[y].index(number)] = True 

flg = False

# たてチェック
for i in range(3):
  if answers[0][i] and answers[1][i] and answers[2][i]:
    flg = True

# 横チェック
for i in range(3):
  if answers[i][0] and answers[i][1] and answers[i][2]:
    flg = True

# 斜めチェック
if answers[0][0] and answers[1][1] and answers[2][2]:
  flg = True

if answers[2][0] and answers[1][1] and answers[0][2]:
  flg = True

if flg:
  print("Yes")
else:
  print("No")

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

void DFS(int& ans, int n, int a, int b, int c, vector<int>& v, const vector<int>& l)
{
	if (v.size() == n) {
		int mp = 0;
		int aa = 0, bb = 0, cc = 0;
		int cnta = 0, cntb = 0, cntc = 0;
		for (int i = 0; i < n; i++) {
			if (v[i] == 0) aa += l[i], cnta++;
			else if (v[i] == 1) bb += l[i], cntb++;
			else if (v[i] == 2) cc += l[i], cntc++;
		}
		if (cnta == 0 || cntb == 0 || cntc == 0) return;
		mp += (max(0, cnta - 1) + max(0, cntb - 1) + max(0, cntc - 1)) * 10;
		mp += abs(a - aa) + abs(b - bb) + abs(c - cc);
		ans = min(ans, mp);
		return;
	}

	for (int i = 0; i < 4; i++) {
		v.push_back(i);
		DFS(ans, n, a, b, c, v, l);
		v.pop_back();
	}
}

int main()
{
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<int> l(n);
	for (int i = 0; i < n; i++) cin >> l[i];
	vector<int> v;
	int ans = INT_MAX;
	DFS(ans, n, a, b, c, v, l);
	cout << ans << endl;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back

const int INF = (1LL<<30);

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }

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

  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    vector<string> t(n);
    REP(i, n) cin >> t[i];

    // 内包されているようなのは消す
    vector<bool> del(n, false);
    REP(i, n) REP(j, n) {
      if(i==j || del[i] || del[j] || t[i].size() < t[j].size()) continue;
      REP(k, t[i].size()-t[j].size()+1) {
        string tmp = t[i].substr(k, t[j].size());
        // cout << tmp << endl;
        if(tmp == t[j]) del[j] = true;
      }
    }

    vector<string> s;
    REP(i, n) if(!del[i]) s.PB(t[i]);
    n = s.size();

    // i->j とつなげるときのsuffixとprefixが一致する最大の長さ
    VVI trans(n, VI(n, 0));
    REP(i, n) REP(j, n) {
      if(i==j) continue;
      REP(k, min(s[i].size(), s[j].size())) {
        string tmp1 = s[i].substr(s[i].size()-k-1), tmp2 = s[j].substr(0, k+1);
        // cout << tmp1 << " " << tmp2 << endl;
        if(tmp1 == tmp2) trans[i][j] = k+1;
      }
    }

    // bitDPする
    VVI dp(1LL<<n, VI(n, INF));
    REP(i, n) dp[1<<i][i] = s[i].size();
    REP(i, 1LL<<n) REP(j, n) {
      if(dp[i][j] == INF) continue;
      REP(k, n) {
        if(i&1<<k) continue;
        chmin(dp[i|1<<k][k], dp[i][j]+((int)s[k].size()-trans[j][k]));
      }
    }

    int ans = INF;
    REP(i, n) chmin(ans, dp[(1LL<<n)-1][i]);
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 5388
#include <bits/stdc++.h>
using namespace std;
 
const int MAXL = 128;
const int Q = 850;
int L;
int query(string s){
	cout<<"? "<<s<<endl;
	int v; cin>>v; return v;
}
bool is_subseq(string s){
	return (int)s.size()+query(s)==L;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	const string chars = 
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		"abcdefghijklmnopqrstuvwxyz"
		"0123456789";
	assert(chars.size() == 62);
	auto get_cnt = [&](char c) -> int {
		return MAXL - query(string(MAXL, c));
	};
	vector<int> cnts(62);
	for (int i = 0; i < 62; i++) {
		cnts[i] = get_cnt(chars[i]);
		L += cnts[i];
	}
	auto combine = [&](const string& a, const string& b) -> string {
		string res;
		int ia = 0, ib = 0;
		while (ia < int(a.size()) && ib < int(b.size())) {
			if (is_subseq(a.substr(0, ia+1) + b.substr(ib))) {
				res += a[ia++];
			} else {
				res += b[ib++];
			}
		}
		while (ia < int(a.size())) res += a[ia++];
		while (ib < int(b.size())) res += b[ib++];
		return res;
	};
	function<string(int , int)> solve = [&](int lx, int rx) {
		if (lx + 1 == rx) {
			return string(cnts[lx], chars[lx]);
		} else {
			return combine(solve(lx, (lx + rx) / 2), solve((lx + rx) / 2, rx));
		}
	};
	string ans = solve(0, 62);
	cout << '!' << ' ' << ans << '\n';
}

Measured memory_bytes: 3776
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

struct UF{
    vector<int> par, rank, size;
    UF(){}
    UF(int n){ init(n); }
    void init(int n){
        par.assign(n, 0);
        rank.assign(n, 0);
        size.assign(n, 1);
        for(int i=0;i<n;i++) par[i] = i;
    }
    int find(int x){
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x != y){
            if(rank[x] > rank[y]) swap(x, y);
            par[x] = y;
            size[y] += size[x];
        }
    }
    bool same(int x, int y){ return find(x) == find(y); }
    int get_size(int x){ return size[find(x)]; }
};

int main(void){
    using P = pair<int, int>;
    int n;
    cin >> n;
    vector< int > x(n), y(n);
    vector< P > v, u;
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
        v.push_back(P(x[i], i));
        u.push_back(P(y[i], i));
    }
    sort(v.begin(), v.end());
    sort(u.begin(), u.end());
    UF uf(n);

    int j = -1;
    for(P p: v){
        int i = p.second;
        if(j != -1 && y[i] > y[j]){
            uf.unite(i, j);
        }
        if(j == -1 || y[i] < y[j]) j = i;
    }
    reverse(v.begin(), v.end());
    j = -1;
    for(P p: v){
        int i = p.second;
        if(j != -1 && y[i] < y[j]){
            uf.unite(i, j);
        }
        if(j == -1 || y[i] > y[j]) j = i;
    }

    j = -1;
    for(P p: u){
        int i = p.second;
        if(j != -1 && x[i] > x[j]){
            uf.unite(i, j);
        }
        if(j == -1 || x[i] < x[j]) j = i;
    }
    reverse(u.begin(), u.end());
    j = -1;
    for(P p: u){
        int i = p.second;
        if(j != -1 && x[i] < x[j]){
            uf.unite(i, j);
        }
        if(j == -1 || x[i] > x[j]) j = i;
    }




    for(int i=0;i<n;i++){
        cout << uf.get_size(i) << endl;
    }
}


Measured memory_bytes: 10012
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int H,W;
while(true){
	cin>>H>>W;
	if(H==0&&W==0)break;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
		cout<<"#";	
		}
		cout<<endl;
	}
	cout<<endl;

}
return 0;
}

Measured memory_bytes: 1152
N = int(input())
t_list = [int(input()) for i in range(N)]

def gcd(a,b):
	while b:
		a,b = b, a%b
	return a

a = t_list[0]
for c in range(N-1):
	b = t_list[c+1]
	a =a*b//gcd(a,b)

print(a)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
// #define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

int main() {
	while(1) {
		int N; cin >> N;
		if (N == 0) { break; }

		vector<char> input(N);
		for (int i = 0; i < N; i++) {
			cin >> input[i];
		}

		int count[26] = {};
		int i;
		for (i = 0; i < N; i++) {
			int k = input[i] - 'A';
			count[k]++;

			vector<pair<int,char>> v(26);
			for (int j = 0; j < 26; j++) {
				v[j] = { count[j], 'A' + j };
			}
			sort(v.begin(), v.end());

			if (v[25].first - v[24].first >= N - i) {
				cout << v[25].second << " " << i + 1 << endl;
				break;
			}
		}
		if (i == N) {
			cout << "TIE" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
#include<string.h>

int main() {
	char n[5];
	int len;
	
	scanf("%s", &n);
	len = strlen(n);
	
	for(int i = 0; i < len; i++) {
		if(n[i] != n[len-i-1]) {
			puts("No");
			return 0;
		}
	}
	
	puts("Yes");
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  cout << accumulate(begin(a), end(a), 1, [](int acc, int i) { return acc * i / __gcd(acc, i); }) << endl;
  return 0;
}



Measured memory_bytes: 3108
n=input()
m=map(int,input().split())
a=[int(i) for i in m]
d=max(a)-min(a)
if d>1:
    ans=False
elif d==0:
    if (max(a)==len(a)-1 or max(a)*2<=len(a)):
        ans=True
    else:
        ans=False
else:
    max_num=a.count(max(a))
    min_num=a.count(min(a))
    dif=max(a)-min_num
    if (min_num<max(a) and dif*2<=max_num):
            ans=True
    else:
        ans=False
        
if ans:
    print("Yes")
else:
    print("No")
        

Measured memory_bytes: 13964
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int i,n;
string str;
int main()
{
cin>>str;
n=str.length();
for(i=0;i<n;i++)
{
	if(str[i]=='A'&&str[i+1]=='C')
	{
		cout<<"Yes"<<endl;
		return 0;
	}
}
cout<<"No"<<endl;
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 4e3;
typedef long long LL;
typedef pair < int, int > II;
typedef pair < int, II > III;

int n, m;

int main()
{
    #define TASK "ABC"
  //  freopen(TASK".inp","r",stdin);
//    freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    vector < vector < LL > > dp;
    vector < LL > a, b;
    dp.resize(n+1), a.resize(n+1), b.resize(n+1);
    for (int i = 0; i < n; i++){
        dp[i].resize(m+1);
        cin >> a[i] >> b[i];
    }
    dp[n].resize(m+1);
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= m; j++){
            if (j >= a[i])
                dp[i+1][j] = max (dp[i][j] , dp[i][j - a[i]] + b[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[n][m];


    return 0;
}




Measured memory_bytes: 79488
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

#define N_MAX (100000)
#define INF   (10000000000000000)

typedef struct {
  DWORD  dwTo;
  QWORD  qwDist;
}EDGE;

typedef enum {
  NUM_TYPE_ODD,
  NUM_TYPE_EVEN,
}NUM_TYPE;

typedef enum {
  WHITE = 0,
  BLACK,
  NONE,
}COLOR;

DWORD  N;
vector<EDGE>  vGraph[N_MAX + 1];
vector<COLOR> vColorGraph;


void dfs(COLOR eColor, DWORD dwVertex)
{
  if (vColorGraph[dwVertex] == NONE) {
    vColorGraph[dwVertex] = eColor;
  } else {
    return;
  }

  for (auto iterEdge : vGraph[dwVertex]) {
    
    COLOR   eNextColor;
    bool    bIsChangeColor = false;
    if (iterEdge.qwDist % 2 == 1) {
      bIsChangeColor = true;
    } 
    if (bIsChangeColor) {
      if (eColor == WHITE) {
        eNextColor = BLACK;
      } else {
        eNextColor = WHITE;
      }
    } else {
      eNextColor = eColor;
    }
    dfs(eNextColor, iterEdge.dwTo);
  }

}

void solve_main()
{
  QWORD qwAns = 0;
  DWORD Q;
  vector<QWORD> vecMaxDistance;

  cin >> N;


  REP(i, 0, N - 1) {
    DWORD tmpA, tmpB, tmpDist;
    cin >> tmpA >> tmpB >> tmpDist;

    vGraph[tmpA].push_back(EDGE{ tmpB, tmpDist});
    vGraph[tmpB].push_back(EDGE{ tmpA, tmpDist});
  }

  vColorGraph.resize(N + 1);
  REP(i, 0, N + 1) {
    vColorGraph[i] = NONE;
  }

  dfs(WHITE, 1);

  REP(i, 1, N + 1) {
    cout << vColorGraph[i] << endl;
  }

}

int main()
{
#ifdef FOR_IDE
  ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());
#endif

  solve_main();
  return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define MOD 1e9+7;

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector< vector<int> > ss;
    ss.resize(M);
    vector<int> p(M);
    REP(i, M) {
        int k;
        cin >> k;
        REP(j, k) {
            int s;
            cin >> s;
            --s;
            ss[i].push_back(s);
        }
    }
    REP(i, M) cin >> p[i];
    int res = 0;
    REP(S, (1<<N)) {
        bool flag = true;
        REP(j, M) {
            int m = 0;
            REP(k, (int)ss[j].size()) {
                if (S & (1<<ss[j][k])) m += 1;
            }
            if (m % 2 != p[j]) {
                flag = false;
                break;
            }
        }
        if (flag) res += 1;
    }
    cout << res << endl;
    return 0;
}

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

#define inf 1000000007
#define ll long long int


ll knapsack(int n, int W, int* wt, int* val) {
	int maxVal = n * 1000;
	ll dp[n + 1][maxVal + 1];

	for (int v = 0; v <= maxVal; v++) {
		dp[1][v] = inf;
	}
	dp[1][0] = 0;
	dp[1][val[0]] = wt[0];

	for (int i = 2; i <= n; i++) {
		for (int v = 0; v <= maxVal; v++) {
			dp[i][v] = dp[i - 1][v];
			if (val[i - 1] > v) {
				continue;
			}
			dp[i][v] = min(dp[i][v], wt[i - 1] + dp[i - 1][v - val[i - 1]]);
		}
	}

	ll ans = 0;
	for (int v = 0; v <= maxVal; v++) {
		if (dp[n][v] <= W) {
			ans = v;
		}
	}
	return ans;
}

int main() {
	int n, W;
	cin >> n >> W;
	int* wt = new int[n];
	int* val = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> wt[i] >> val[i];
	}

	cout << knapsack(n, W, wt, val) << endl;

	return 0;
}

Measured memory_bytes: 81264
s = input()
t = input()
a = "abcdefghijklmnopqrstuvwxyz"

flag = 0
i = 0 
while i < len(s):
	if s[i] != t[i]:
		if t[i] in a:
			c = s[i]
			s = s.replace(c, "1")
			s = s.replace(t[i], c)
			s = s.replace("1", t[i])
			a = a.replace(t[i], "1")
		else:
			break
	i += 1
if s == t:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3632
n = gets.to_i
s = gets.chomp.split(//).map &:to_i

a = [nil] * 10
b = [nil] * 100
c = [nil] * 1000

s.each do |m|
  100.times do |i|
    next unless b[i]
    c[i * 10 + m] = true
  end
  10.times do |i|
    next unless a[i]
    b[i * 10 + m] = true
  end
  a[m] = true

  # p "---"
  # p m
  # puts 1000.times.select{|i|c[i]}.join(" ")
end
puts c.count(&:itself)

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  string a, b;
  cin >> a >> b;
  if (a.size() == b.size()) {
    cout << (a > b ? "GREATER" : (a < b ? "LESS": "EQUAL")) << endl;
  } else {
    cout << (a.size() > b.size() ? "GREATER" : "LESS") << endl;
  }
}


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

int N;
const int MAX_N = 1.0e5 + 100;
string S[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> S[i];
    
    for (int i = 0; i < N; i++) {
        sort(begin(S[i]), end(S[i]));
    }

    sort(S, S+N);

    ll ans = 0;
    ll cnt = 0;
    for (int i = 0; i < N - 1; i++) {
        if (S[i] == S[i+1]) {
            cnt++;
        }
        else {
            ans += (cnt + 1)*cnt/2;
            cnt = 0;
        }
    }
    ans += (cnt + 1)*cnt/2;
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7296
/**
 *   author: sahushivam
 *   created: 01 February 2019  23:29:59
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff

void lcs( char *X, char *Y, int m, int n ) 
{ 
int L[m+1][n+1]; 
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		{L[i][j] = L[i-1][j-1] + 1;}
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} int index = L[m][n];
int gg=index; 
char lcs[index+1];
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; 
		i--; j--; index--;
	} 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

REP(i,0,gg)cout<<lcs[i]; 
} 

int main() 
{ 
char X[3005];
char Y[3005];
cin>>X>>Y;

int m = strlen(X); 
int n = strlen(Y); 
lcs(X, Y, m, n); 
return 0; 
} 


Measured memory_bytes: 35456
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    a = sc.intarr()[0]
    b = sc.intarr()[0]

    print(6 - a - b)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def natural_num(n):
    for j in range(2, int(math.sqrt(n))+1):
        if n % j == 0:
            return 0
    return 1


main()


Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
a[0]-=1
for i in range(1,len(a)):
  if a[i-1] != a[i]:
    a[i]-=1
  if a[i-1] > a[i]:
    print('No')
    exit(0)
print('Yes')


Measured memory_bytes: 14224