akhauriyash/Code-Regression huggingface dataset:
import sys


def get_checks(lefts, rights, used):
    def left_check(pos):
        while lefts:
            e, i = lefts.pop()
            if not used[i]:
                break
        else:
            return None

        used[i] = True
        if pos >= e:
            return None
        return e

    def right_check(pos):
        while rights:
            e, i = rights.pop()
            if not used[i]:
                break
        else:
            return None

        used[i] = True
        if pos <= e:
            return None
        return e

    return left_check, right_check


def simulate(left_first=True):
    ans = 0
    pos = 0
    _lefts = lefts.copy()
    _rights = rights.copy()
    used = [False] * n
    left_check, right_check = get_checks(_lefts, _rights, used)
    funcs = [left_check, right_check] if left_first else [right_check, left_check]
    dir = 0

    while True:
        e = funcs[dir](pos)
        if e is None:
            break
        ans += abs(e - pos)
        pos = e
        dir ^= 1
    ans += abs(pos)
    return ans


n = int(input())
lefts, rights = [], []
for i, line in enumerate(sys.stdin.readlines()):
    l, r = map(int, line.split())
    lefts.append((l, i))
    rights.append((r, i))

lefts.sort()
rights.sort(reverse=True)

lf = simulate(True)
rf = simulate(False)

print(max(lf, rf))


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

using namespace std;

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

    string s;
    cin >> s;

    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {
  public static void Main (string[] args) {
    var list = Console.ReadLine().Split(' ').Select(long.Parse);
    var n = list.ElementAt(0);
    var m = list.ElementAt(1);

    Console.WriteLine(n == m ? "Yes" : "No");
 
  }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

signed main(){
	ll N, S;
	cin >> N >> S;
	vector<ll> A(N);
	for(auto &a : A) cin >> a;
	vector<vector<ll>> dp(N+1, vector<ll>(S+1, 0));

	for(int i=0;i<=N;i++) dp[i][0] = 1;

	for(int i=1;i<=N;i++) {
		for(int j=0;j<=S;j++) {
			dp[i][j] += dp[i-1][j];
			if(j >= A[i-1]) dp[i][j] += dp[i-1][j-A[i-1]];
			dp[i][j] %= MOD;
		}
	}
	ll ans = 0;
	for(int i=0;i<=N;i++) {
		ans += dp[i][S];
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
	fast;
	int n;cin>>n;
	int a,b,c;
	vector<vector<int>> dp(3,vector<int>(n,0));
	cin>>dp[0][0];
	cin>>dp[1][0];
	cin>>dp[2][0];
	// n--;
	for(int i=1;i<n;i++){
		cin>>a>>b>>c;
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a;
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b;
		dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c;
	}
	cout<<max({dp[0][n-1],dp[1][n-1],dp[2][n-1]})<<endl;
	
}

Measured memory_bytes: 4716
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<String> list = new ArrayList<String>();
        int L[] = new int[N];
        for(int i = 0; i < N; i++){
            L[i] = sc.nextInt();
        }
        
        int ways = 0;
        String si, sj, sk;
        
        for(int i = 0; i < N-2; i++){
            for(int j = i+1; j < N-1; j++){
                for(int k = j+1; k < N; k++){
                    if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j] && L[i] != L[j] && L[i] != L[k] && L[j] != L[k]){
                        si = String.valueOf(L[i]);
                        sj = String.valueOf(L[j]);
                        sk = String.valueOf(L[k]);
                        ways++;
                    }
                }
            }
        }
        
        
        System.out.println(ways);
    }
}


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

#define COMMANDMAX 5000000
#define COMMANDNUM 3
std::string command[COMMANDNUM] = { "insert", "print", "find" };

class Node
{
public: 
    int key;
    Node *parent, *left, *right;
};

using namespace std;

class BinarySearchTree
{
public:
    BinarySearchTree();
    ~BinarySearchTree();

    Node *root;

    void insert(const int);
    void inorder(Node*);
    void preorder(Node*);
    void print();
    Node* find(Node*, int);
};

int main() {
    int commandnum = 0, key = 0;
    string s;
    Node *ret;
    BinarySearchTree _tree;

    cin >> commandnum;
    for(int i=0; i<commandnum; ++i) {
        cin >> s;
        if(s == command[0]) {
            cin >> key;
            _tree.insert(key);
        }

        else if(s == command[1]) _tree.print();

        else if(s == command[2]) {
            cin >> key;
            ret = _tree.find(_tree.root, key);
            if(ret != nullptr) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    
    return 0;
}

BinarySearchTree::BinarySearchTree() {
    root = nullptr;
}

BinarySearchTree::~BinarySearchTree() {

}

void BinarySearchTree::insert(const int key) {
    Node *x = root, *y = nullptr, *z = new Node;
    z->key = key;
    z->left = z->right = nullptr;

    while(x != nullptr) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        }

        else {
            x = x->right;
        } 
    }

    z->parent = y;
    if(y==nullptr) {
        root = z;
    }
    else {
        if(z->key < y->key) {
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void BinarySearchTree::inorder(Node *p) {
    if(p == nullptr) 
        return ;

    inorder(p->left);
    cout << " " << p->key;
    inorder(p->right);
}

void BinarySearchTree::preorder(Node *p) {
    if(p == nullptr) return ;
    cout << " " << p->key;
    preorder(p->left);
    preorder(p->right);
}

void BinarySearchTree::print() {
    inorder(root);
    cout << endl;

    preorder(root);
    cout << endl;
}

Node* BinarySearchTree::find(Node *x, int k) {
    while(x != nullptr && k != x->key) {
        if(k < x->key)
            x = x->left;
        
        else
            x = x->right;
    }

    return (x);
}


Measured memory_bytes: 21928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

template<class T> inline bool chmax(T &a, T b) {
    if(a<b) {
        a=b; return 1;
    } 
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if(a>b) {
        a=b; return 1;
    } 
    return 0;
}

//const ll INF = 1LL << 60;

int N;

//DPテーブル
//vector<ll> dp(100010);

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

int main() {
    cin >> N;
    ll sum=0;
    rep1(i,1,N+1) {
        rep1(j,1,N+1) {
            rep1(k,1,N+1) {
                sum+=gcd(i,gcd(j,k));
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")
#define int long long

using namespace std;

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

const int N = 3000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, dp[N][N], dp2[N][N], X[N], Y[N], q, a[N], lazy = 1, tav[N];

int POW(int x, int t){
	int res = 1;
	while (t){
		if (t & 1) res = res * 1ll * x % MOD;
		t >>= 1;
		x = x * 1ll * x % MOD;
	}
	return res;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) cin >> a[i];
	tav[0] = 1;
	for (int i = 1; i < N; i++) tav[i] = tav[i - 1] * 1ll * 2 % MOD;
	for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) dp[i][j] = 1;
	for (int i = q; i >= 1; i--){
		cin >> X[i] >> Y[i];
		if (X[i] > Y[i]) swap(X[i], Y[i]);
	}
	for (int cnt = 1; cnt <= q; cnt++){
	//	cout << X[cnt] << ' ' << Y[cnt] << '\n';
		for (int i = 1; i <= X[cnt] ; i++){
			dp2[i][X[cnt]] = lazy * 1ll * (dp[i][X[cnt]] + dp[i][Y[cnt]]) % MOD; 
		}
		for (int i = X[cnt] + 1; i < Y[cnt]; i++){
			dp2[X[cnt]][i] = lazy * 1ll * dp[X[cnt]][i] % MOD + (tav[cnt - 1] - lazy *1ll* dp[i][Y[cnt]] % MOD);
			dp2[X[cnt]][i] %= MOD;
			dp2[X[cnt]][i] += MOD;
			dp2[X[cnt]][i] %= MOD;
		}
		for (int i = Y[cnt] + 1; i <= n; i++){
			dp2[X[cnt]][i] = lazy * 1ll * (dp[X[cnt]][i] + dp[Y[cnt]][i]) % MOD;
		}
		for (int i = 1; i < X[cnt]; i++){
			dp2[i][Y[cnt]] = lazy * 1ll * (dp[i][Y[cnt]] + dp[i][X[cnt]]) % MOD;
		}
		for (int i = X[cnt] + 1; i <= Y[cnt]; i++){
			dp2[i][Y[cnt]] = lazy * 1ll * dp[i][Y[cnt]] % MOD + (tav[cnt - 1] - lazy * dp[X[cnt]][i] % MOD);
			dp2[i][Y[cnt]] %= MOD;
			dp2[i][Y[cnt]] += MOD;
			dp2[i][Y[cnt]] %= MOD;
		}
		for (int i = Y[cnt] + 1; i <= n; i++){
			dp2[Y[cnt]][i] = lazy * 1ll * (dp[Y[cnt]][i] + dp[X[cnt]][i]) % MOD; 
		}
		dp2[X[cnt]][Y[cnt]] = tav[cnt - 1];
		lazy = lazy * 1ll * 2 % MOD;
		int con = POW(lazy, MOD - 2);
		for (int i = 1; i <= X[cnt]; i++){
			dp[i][X[cnt]] = con * 1ll * dp2[i][X[cnt]] % MOD;
		}
		for (int i = X[cnt] + 1; i <= n; i++){
			dp[X[cnt]][i] = con * 1ll * dp2[X[cnt]][i] % MOD;
		}
		for (int i = 1; i <= Y[cnt]; i++){
			dp[i][Y[cnt]] = con * 1ll * dp2[i][Y[cnt]] % MOD;
		}
		for (int i = Y[cnt] + 1; i <= n; i++) dp[Y[cnt]][i] = con * 1ll * dp2[Y[cnt]][i] % MOD;
	//	for (int i = 1; i <= n; i++) for( int j = i; j <= n; j++) cout << cnt << ' ' << i << ' ' <<  j << ' ' << dp[i][j] * 1ll * lazy % MOD << '\n';
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++){
		for (int j = i + 1; j <= n; j++){
			if (a[i] == a[j]) continue;
			if (a[i] > a[j]) ans += dp[i][j] * 1ll * lazy % MOD;
			else{
				ans += tav[q] - lazy * 1ll * dp[i][j] % MOD;
				ans %= MOD;
				ans += MOD;
				ans %= MOD;
			}
			ans %= MOD;
		}
	}
	cout << ans;
	










	return 0;
}


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

int Partition(vector<pair<string, int>>& A, int p, int r)
{
    int x = A[r-1].second;
    int part = p;
    for (int j = p; j < r; ++j) {
        if (A[j].second <= x) {
            iter_swap(A.begin()+part, A.begin()+j);
            ++part;
        }
    }
    return part-1;
}

void quickSort(vector<pair<string, int>>& A, int p, int r) {
    if (p < r) {
        int q = Partition(A, p, r);
        quickSort(A, p, q);
        quickSort(A, q+1, r);
    }
}

int main() {
    int n;
    cin >> n;
    vector<pair<string, int>> A(n);
    for (auto& a : A) {
        cin >> a.first >> a.second;
    }

    map<int, vector<string>>  org;
    for (auto& a : A) {
        if (org.count(a.second) == 0) {
            org.emplace(a.second, vector<string>{a.first});
        }
        else {
            org.at(a.second).push_back(a.first);
        }
    }
    
    quickSort(A, 0, n);

    map<int, vector<string>>  sorted;
    for (auto& a : A) {
        if (sorted.count(a.second) == 0) {
            sorted.emplace(a.second, vector<string>{a.first});
        }
        else {
            sorted.at(a.second).push_back(a.first);
        }
    }

    bool stable = true;
    for (const auto& o : org) {
        for (int i = 0; i < o.second.size(); ++i) {
            if (o.second[i] != sorted.at(o.first)[i]) {
                stable = false;
            }
        }
    }

    if (stable) {
        cout << "Stable" << endl;
    }
    else {
        cout << "Not stable" << endl;
    }
    for (const auto& a : A) {
        cout << a.first << " " << a.second << endl;
    }
}


Measured memory_bytes: 15772
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mod = 10 ** 9 + 7
t = [10 ** 10 for _ in range(N)]
t[0] = a[0]
t[-1] = b[-1]
s = set()
s.add(0)
s.add(N - 1)
if a[0] > b[0] or (a[-1] < b[-1]):
  print(0)
  exit(0)
if a[-1] != b[0]:
  print(0)
  exit(0)
for i in range(N - 1):
  if a[i + 1] > a[i]:
    if t[i + 1] > 0 and (t[i + 1] in range(a[i + 1])):
      print(0)
      exit(0)
    s.add(i + 1)
    t[i + 1] = a[i + 1]
  else: t[i + 1] = min(t[i + 1], t[i])
#print(t)
for i in range(N - 1, 0, -1):
  if b[i - 1] > b[i]:
    if t[i - 1] > 0 and (t[i - 1] in range(b[i - 1])):
      print(0)
      exit(0)
    s.add(i - 1)
    t[i - 1] = b[i - 1]
  else: t[i - 1] = min(t[i - 1], t[i])
#print(t)
res = 1
for i in range(N):
  if i in s: continue
  res *= t[i]
  res %= mod
print(res)

Measured memory_bytes: 79588
# coding: utf-8

def getList():
    tmpList = []
    for i in range(N):
        for j in range(N):
            tmpList.append(4*i+7*j)
    return tmpList

def solve(N):
    tmpList = getList()
    
    if N in tmpList:
        return "Yes"
    else:
        return "No"
    
if __name__ == "__main__":
    N = int(input())
    print(solve(N))
        

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

int main() {
  char c;
  cin >> c;
  string ans = "consonant";
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    ans = "vowel";
  cout << ans << endl;
}

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

int main()
{
	string s;
	unsigned long long int k;
	cin >> s >> k;
	int count = 0;
	for (int i = 0; i < 100; ++i)
	{
		if (s[i] - '0' == 1)
		{
			++count;
		}
		if (s[i] != '1')
		{
			break;
		}
	}
	if (count >= k)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << s[count] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = K; i < N; i++) {
			if (A[i - K] >= A[i]) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		}
	}

}

Measured memory_bytes: 59660
#include<stdio.h>

int main(void)
{
	int S;
	scanf("%d",&S);
	int h=S/3600;
	int m=S%3600/60;
	int s=S-(3600*h+60*m);
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, A, B, v[55], ans;
double res;

ll com(ll x, ll y){
    ll res = 1;
    for (ll i = 0; i < y; i++) {
        res *= (x - i);
        res /= i + 1;
    }
    return res;
}

int main(void){
    // Your code here!
    cin >> n >> A >> B;
    for (ll i = 0; i < n; i++) cin >> v[i];
    sort(v, v + n);
    reverse(v, v + n);
    for (ll i = 0; i < A; i++) {
        res += v[i];
    }
    cout << fixed << res / A << endl;
    if (v[0] == v[A - 1]) {
        ll k = A;
        while(v[k] == v[k - 1]) k++;
        for (ll i = A; i <= k && i <= B; i++) {
            ans += com(k, i);
        }
        cout << ans << endl;
    } else {
        ll k = 1, l = 1, i = A, j = A;
        while(v[i - 1] == v[i - 2]){
            i--, k++, l++;
        }
        while(v[j - 1] == v[j]){
            j++, k++;
        }
        cout << com(k, l) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1000000000000005;
const int maxn=1e6+5;
ll n,m,p;
vector<int>v[300000];
int num[maxn];
ll z;
int work(int x)
{
    int sz=v[x].size();
    for(int i=0;i<sz;i++)
    {
        if(v[x][i]>z)
        {
            z=v[x][i];
            return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
        v[num[i]].push_back(i);
    }
    for(int i=1;i<=n;i++)
        sort(v[i].begin(),v[i].end());
    ll cot=0;
    for(int i=1;i<=n;i++)
    {
        if(v[i].size()==0) break;
        else if(i==1)
            z=v[i][0];
        else
        {
            int f=work(i);
            if(!f) break;
        }
        cot++;
    }
    printf("%lld\n",cot==0?-1:n-cot);
    return 0;
}


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

string s[2005];
char ans[10005];
int len[2005];
bitset<10005> can[2005];
pair<int,int> rec[2][2005];

#define mp make_pair
#define fi first
#define se second

int main () {
        int n, k; cin >> n >> k;
        for (int i = 1; i <= n; ++i) cin >> s[i], len[i] = s[i].size();
        can[n+1][0] = 1;
        for (int i = n; i >= 1; --i) can[i] = can[i+1] | (can[i+1]<<len[i]);
        int cur = 0, nxt = cur ^ 1, cnt = 0;
        for (int i = 1; i <= n; ++i) if (can[i+1][k-len[i]]) rec[0][++cnt] = mp (i, 0);
        for (int i = 0; i < k; ++i) {
                char Min = 'z';
                for (int j = 1; j <= cnt; ++j) Min = min (Min, s[rec[cur][j].fi][rec[cur][j].se]);
                ans[i] = Min;
                int minID = 1e9, ccnt = 0;
                for (int j = 1; j <= cnt; ++j) {
                        int id = rec[cur][j].fi, pos = rec[cur][j].se;
                        if (s[id][pos] != Min) continue;
                        if (pos+1 == len[id]) minID = min(minID,id);
                        else rec[nxt][++ccnt] = mp (id,pos+1);
                }
                for (int j = minID+1; j <= n; ++j)
                        if (k-len[j]-i-1>=0 && can[j+1][k-len[j]-i-1])
                                rec[nxt][++ccnt] = mp (j,0);    
                cur ^= 1, nxt ^= 1;
                cnt = ccnt;
        }
        ans[k] = '\0';
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int a, b;
      cin >> a >> b;
      int ans = max(a,b);
      if(a == b)cout << ans*2 << endl;
      else cout << ans*2-1 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int a = sc.nextInt();
			int b = sc.nextInt();
			
		
			for(int i = 1 ; i < 1500 ; i++ ) {
				
				int taxA = (int)Math.floor((double)i * 8 / 100);
				int taxB = (int)Math.floor((double)i / 10);
				
				
				if ( taxA == a && taxB == b) {
					System.out.println(i);
					return;
				}
			}
			
			System.out.println(-1);
			
		}
	}
}

Measured memory_bytes: 23124
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#include<bits/stdc++.h>
#define maxn 110
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define IL inline
#define ss system
using namespace std;

bool vis[maxn][maxn];
template <class T> void read(T &x){
	char ch=x=0;
	bool fl=false;
	while(!isdigit(ch))
		fl|=ch=='-',ch=getchar();
	while(isdigit(ch))
		x=x*10+ch-'0',ch=getchar();
	x=fl?-x:x;
}
int main(){
	int n,m,cnt=0;
	read(n),read(m);
	for(int i=1,k,x;i<=n;i++){
		read(k);
		while(k--)
			read(x),vis[i][x]=1;
	}
	for(int i=1;i<=m;i++){
		bool fl=true;
		for(int j=1;j<=n;j++)
			fl&=vis[j][i];
		cnt+=fl;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int w, h;
int c[100][100];
int ans;

void solve(int y, int x){
	c[y][x] = 0;

	for (int i = -1; i <= 1; i++){
		for (int j = -1; j <= 1; j++){
			int ny = y + i, nx = x + j;
			if (ny >= 0 && ny < h&&nx >= 0 && nx < w){
				if (c[ny][nx] == 1)solve(ny, nx);
			}
		}
	}
}

int main(){
	while (cin >> w >> h&&w + h){
		REP(i, h){
			REP(j, w){
				cin >> c[i][j];
			}
		}
		ans = 0;
		REP(i, h){
			REP(j, w){
				if (c[i][j] == 1){
					solve(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);


  int n; cin >> n;
  set<int> st;
  for(int i=0;i<n;++i) {
    int tmp; cin >> tmp;
    st.insert(tmp);
  }
  cout << SZ(st) << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


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

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

int main() {
  int a[] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  cin >> x >> y;
  cout << (a[x-1] == a[y-1] ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
import sys


def solve(n, aaa):
    if n == 2:
        h, m = divmod(sum(aaa), 2)
        if m == 1 or h > aaa[0]:
            return -1
        return aaa[0] - h

    x = 0
    for a in aaa[2:]:
        x ^= a
    a0, a1 = aaa[:2]
    s = a0 + a1

    if s & 1 != x & 1:
        return -1

    p, q = 0, 0

    b = 1 << 40
    last_b = -1
    while b:
        bx = x & b
        if bx == 0:
            if s >= 2 * b:
                if p | b <= a0:
                    p |= b
                    q |= b
                    s -= 2 * b
                elif last_b > 0:
                    p ^= last_b
                    q ^= last_b
                    p |= b
                    q |= b
                    s -= 2 * b
                else:
                    return -1
        else:
            if s < b:
                return -1
            if p | b <= a0 and q | b > a1:
                p |= b
                last_b = b
            else:
                q |= b
            s -= b

        b >>= 1

    if p == 0:
        return -1
    assert s == 0
    assert p ^ q == x
    assert a0 - p == q - a1
    return a0 - p


n, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, aaa))


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    map<string, ll> money;
    vector<pair<string, ll>> fs;
    ll N, M;
    cin >> N;
    for(ll i = 0;i < N;i++) {
        string s;
        cin >> s;
        money[s]++;
    }
    cin >> M;
    for(ll i = 0;i < M;i++) {
        string s;
        cin >> s;
        money[s]--;
    }
    fs = vector<pair<string, ll>>(money.begin(), money.end());
    sort(fs.begin(), fs.end(), [](pair<string, ll> a, pair<string, ll> b) { return a.second > b.second; });
    cout << max(0LL, fs.front().second) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()
using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (v.empty()) return os << "vector{}";
  os << "vector{" << *v.begin();
  for (auto it = ++v.begin(); it != v.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
  if (s.empty()) return os << "set{}";
  os << "set{" << *s.begin();
  for (auto it = ++s.begin(); it != s.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const map<S, T> &m) {
  if (m.empty()) return os << "map{}";
  os << "map{" << (*m.begin()).first << ": " << (*m.begin()).second;
  for (auto it = ++m.begin(); it != m.end(); ++it)
    os << ", " << (*it).first << ": " << (*it).second;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  return os << "pair{" << p.first << ", " << p.second << "}";
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (getenv("LOCAL") != nullptr) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N;
  cin >> N;
  vector<ll> A(N);
  rep (i, N) {
    cin >> A[i];
  }

  ll ans = INF;
  repr (k, -100, 101) {
    ll s = 0;
    each (a, A) {
      s += pow(a - k, 2);
    }
    ans = min(s, ans);
  }
  cout << ans << "\n";
}

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

int main(void){
  string a,b;
  cin>>a>>b;
  
  int digitA=a.size();
  int digitB=b.size();
  
  if(digitA>digitB){
   cout<<"GREATER"<<endl; 
  }else if(digitA<digitB){
   cout<<"LESS"<<endl; 
  }else{
    int i;
   for(i=0;i<digitA;i++){
     if(a[i]>b[i]){
       cout<<"GREATER"<<endl; 
       break;
     }
     else if(a[i]<b[i]){
       cout<<"LESS"<<endl;
     	break;
     }
   }
    if(i==digitA)cout<<"EQUAL"<<endl;
  }
  return 0;
  
}

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

using namespace std;


int main()
{
    long long int i=0,j, t,n;
    cin >> n;
    if(n% 10 == 3)
    {
        cout << "bon";
    }else if(n% 10 == 0 || n% 10 == 1 || n% 10 == 6 || n% 10 == 8)
    {
        cout << "pon";
    }else
    {
        cout << "hon";
    }


    return 0;
}


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

int main(){
  int w,h,n;
  cin >> w >> h >> n;
  // vector<int> x(n),y(n),a(n);
  // for(int i = 0; i < n; i++)
  //   cin >> x[i] >> y[i] >> a[i];
  vector<vector<bool> > white(w, vector<bool>(h, true));
  for(int i = 0; i < n; i++){
    int x,y,a;
    cin >> x >> y >> a;
    switch(a){
      case 1:
        for(int j = 0; j < x; j++){
          for(int k = 0; k < h; k++){
            white[j][k] = false;
          }
        }
        break;
      case 2:
        for(int j = x; j < w; j++){
          for(int k = 0; k < h; k++){
            white[j][k] = false;
          }
        }
        break;
      case 3:
        for(int j = 0; j < y; j++){
          for(int k = 0; k < w; k++){
            white[k][j] = false;
          }
        }
        break;
      case 4:
        for(int j = y; j < h; j++){
          for(int k = 0; k < w; k++){
            white[k][j] = false;
          }
        }
        break;
    }
  }

  int ans = 0;
  for(int i = 0; i < w; i++){
    for(int j = 0; j < h; j++){
      if(white[i][j])
        ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int a=gi();
	    int b=gi();

	    //System.out.print(s);

        if ((a==1 && b==2) || (a==2 && b==1)) {
        	System.out.print(3);
        } else if ((a==1 && b==3) || (a==3 && b==1)) {
        	System.out.print(2);
        }else {
        	System.out.print(1);
        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35556
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> t(N);
	vector<Int> a(N);
	for (Int i = 0; i < N; i++) {
		cin >> t[i] >> a[i];
	}

	Int temp;
	Int b, c;
	for (Int i = 0; i < N-1; i++) {
			temp = max((t[i] + (t[i + 1] - 1)) / t[i + 1], (a[i] + (a[i + 1] - 1)) / a[i + 1]);
			t[i + 1] *= temp;
			a[i + 1] *= temp;
	}

	cout << t[N - 1]+ a[N - 1] << "\n";

}

Measured memory_bytes: 256
uses crt;
var a:string;
i,n:integer;
ok:boolean;
begin
clrscr;
readln(n);
readln(a);
ok:=true;
if length(a) mod 2<>0 then write('No') else begin
for i:=1 to n div 2 do
if a[i]<>a[i+n div 2]     then begin ok:=false;  break;   end;
if ok=true then write('Yes') else write('No');
end;
readln;
end.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    string s, t; cin >> s >> t;
    int slen = s.size(), tlen = t.size();

    vector<vector<int>> dp(slen+5, vector<int>(tlen+5, 0));
    rep(i, slen) rep(j, tlen){
        if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
        else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }

    string ans = "";
    int i = slen, j = tlen;
    while(i>0 && j>0){
        if(s[i-1] == t[j-1]){
            ans += s[i-1];
            --i; --j;
        }
        else if(dp[i-1][j] > dp[i][j-1]) --i;
        else --j;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) 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 operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////


int main() {

	ll N, M;
	cin >> N >> M;

	repn(i, M) {
		ll a;
		cin >> a;
		N -= a;
	}

	cout << max(-1, N);

	system("PAUSE");
}


Measured memory_bytes: 3688
# https://atcoder.jp/contests/abc136/tasks/abc136_b
n = int(input())
if n <= 9 :
    print(n)
elif n <= 99:
    print(9)
elif n <= 999:
    print(9 - 99 + n)
elif n <= 9999:
    print(9 - 99 + 999)
elif n <= 99999:
    print(9 - 99 + 999 - 9999 + n )
else:
    print(9 - 99 + 999 - 9999 + 99999)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long M = 10e9+7;
int main()
{
	ll A,B,K;cin>>A>>B>>K;
	if(K>=A) {
		ll x  = K-A;
		 B -= x;
		 if(B<0)
		 { 
		 	B  = 0;
		 }
		 cout<<"0 "<<B<<"\n";
	}
	else {
		cout<<A-K<<" "<<B<<"\n";
	}
	return 0;
}

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

//solution:
void hike() {
  int k; cin >> k;
  for(int i = 0; i < k; ++i) cout << "ACL";
}

signed main() {
  int t = 1; //cin >> t;
  while(t--) hike();
  return 0;
} //farewell, until we meet again..

Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll a,b;
    cin>>a>>b;
    if(a>b){
    for(ll i=0;i<a;i++)
    {
        cout<<b;
    }
     return 0;
    }
    else
    {
        for(ll i=0;i<b;i++)
    {
        cout<<a;
    }
     return 0;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a = 0;
	int b = 0;
	for(int i=0;i<n;i++){
		string c,d;
		cin >> c >> d;
		int e = min(c.length(),d.length());
		bool w = true;
		for(int j=0;j<e;j++){
			if     (c[j]<d[j]){ w = false; a += 3; break; }
			else if(c[j]>d[j]){ w = false; b += 3; break; }
		}
		if(w){
			if     (c.length()<d.length()) a += 3;
			else if(c.length()>d.length()) b += 3; 
			else   { a++; b++; }
		}
	}
	cout << b << " " << a << endl;
}

Measured memory_bytes: 1208
import heapq
N = int(input())
A = list(map(int,input().split()))
heap = []
for i in range(N):
    heapq.heappush(heap,-A[i])
if N==2:
    ans = -heapq.heappop(heap)
elif N==3:
    ans = -heapq.heappop(heap)-heapq.heappop(heap)
else:
    ans = 0
    ans = -heapq.heappop(heap)
    if N%2==0:
        for _ in range((N-2)//2):
            a = -heapq.heappop(heap)
            ans += 2*a
    else:
        for _ in range((N-3)//2):
            a = -heapq.heappop(heap)
            ans += 2*a
        a = -heapq.heappop(heap)
        ans += a
print(ans)

Measured memory_bytes: 104728
using System;

public class hello
{
    public static void Main()
    {
        var hmax = 0m;
        var hmin = 1000000m;
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var h = decimal.Parse(line.Trim());
            if (h > hmax) hmax = h;
            if (h < hmin) hmin = h;
        }
        Console.WriteLine(hmax - hmin);
    }
}

Measured memory_bytes: 9404
#include<stdio.h>
#include<math.h>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p){ return Point(x + p.x, y + p.y); }
    Point operator - (Point p){ return Point(x - p.x, y - p.y); }
    Point operator * (Point p){ return Point(x * p.x, y * p.y); }
    Point operator / (Point p){ return Point(x / p.x, y / p.y); }

    Point operator * (double k){ return Point(x*k, y*k);}

    double abs() { return sqrt(norm()); }
    double norm() { return x * x + y * y; }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

typedef Point Vector;

struct Segment {
    Point p1, p2;
};

typedef Segment Line;

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
};

Point projection(Segment s, Point p) {
    Vector a = s.p2 - s.p1;
    Vector b = p - s.p1;
    double k = dot(a, b)/a.norm();
    a.x = k*a.x, a.y = k*a.y;
    return s.p1 + a;
};

Point reflect(Segment s, Point p) {
    Point x = projection(s, p);
    Vector c = x - p;
    c.x = c.x * 2, c.y = c.y * 2;
    return p + c;
}

int main() {
    Segment s;
    int q;
    Point p, P;
    double x0, y0, x1, y1;

    scanf("%lf %lf %lf %lf", &x0, &y0, &x1, &y1);
    scanf("%d", &q);
    s.p1.x = x0; s.p1.y = y0; s.p2.x = x1; s.p2.y = y1;

    for (int i=0; i<q; i++) {
        scanf("%lf %lf", &p.x, &p.y);
        P = reflect(s, p);
        printf("%.8lf %.8lf\n", P.x, P.y);
    }

    return 0;
}


Measured memory_bytes: 2760
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, m = 0, k = 0, sum = 0, MASK = 0;
ll A[500000] = {}, B[500000] = {}, X[1500][13], rui[500000] = {}, dp[1 << 12] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S, T;
bool check = true, check2 = false;

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

int main() {
	//Code Line

	cin >> n >> m;

	for (int i = 1; i < (1 << 12); i++)dp[i] = INF;
	for (int i = 0; i < m; i++) {
		cin >> A[i] >> B[i];
		for (int j = 0; j < B[i]; j++)cin >> X[i][j];
	}


	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < m; j++) {
			MASK = 0;
			for (int k = 0; k < B[j]; k++)MASK |= (1 << (X[j][k]-1));
			
			c = i | MASK;
			dp[c] = min(dp[c], dp[i] + A[j]);
		}
	}

	if (100000000 > dp[(1 << n) - 1])cout << dp[(1 << n) - 1] << endl;
	else cout << -1;

	return 0;
}


Measured memory_bytes: 6400
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	String s = scan.next();
	int a = Integer.parseInt(s);
	s = scan.next();
	int b = Integer.parseInt(s);
	System.out.println(a*b + " " + (a+b)*2);
    }
}



Measured memory_bytes: 26064
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 00:29:09 2020

@author: H_Hoshigi
"""
import sys

N = int(input())
a_list = list(map(int, input().split()))


#sunuke = a_list[0]
#araiguma = sum(a_list[1:])
#min_difference = abs(sunuke - araiguma)
sunuke = 0
sum_a = sum(a_list)

min_difference = sys.maxsize
#abs(sunuke - araiguma)は、abs(sum(a_list)-sunuke*2)として求められる。

#range(1,N-1)ではなく、最初の一枚目から比較する形にした。
for i in range(N-1):
    sunuke += a_list[i]
    #araiguma -= a_list[i]
    min_difference = min(min_difference,
                         abs(sum_a - 2*sunuke))

print(min_difference)


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

int n,m;
string pre[50000],suf[50000];

int count(string s,bool muki){
	if(s[s.length() - 1] == '*'){
		s = s.substr(0,s.length() - 1);
		string t = s;
		t[t.length() - 1]++;
		if(!muki) return lower_bound(pre,pre + n,t) - lower_bound(pre,pre + n,s);
		else return lower_bound(suf,suf + n,t) - lower_bound(suf,suf + n,s);
	}else{
		if(!muki) return upper_bound(pre,pre + n,s) - lower_bound(pre,pre + n,s);
		else return upper_bound(suf,suf + n,s) - lower_bound(suf,suf + n,s);
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		cin >> pre[i];
		suf[i] = pre[i];
		reverse(suf[i].begin(),suf[i].end());
	}
	sort(pre,pre + n);
	sort(suf,suf + n);
	for(int i = 0;i < m;i++){
		int ind = -1;
		string s;
		cin >> s;
		for(int j = 0;j < s.length();j++){
			if(s[j] == '?') ind = j;
		}
		if(s[s.length() - 1] == '*'){
			if(ind == -1) cout << count(s,false) << endl;
			else{
				int ans = 0;
				for(int j = 0;j < 26;j++){
					s[ind] = 'a' + j;
					ans += count(s,false);
				}
				cout << ans << endl;
			}
		}else if(s[0] == '*'){
			reverse(s.begin(),s.end());
			if(ind == -1) cout << count(s,true) << endl;
			else{
				for(int j = 0;j < s.length();j++){
					if(s[j] == '?') ind = j;
				}
				int ans = 0;
				for(int j = 0;j < 26;j++){
					s[ind] = 'a' + j;
					ans += count(s,true);
				}
				cout << ans << endl;
			}
		}else{
			if(ind == -1) cout << count(s,false) << endl;
			else{
				int ans = 0;
				for(int j = 0;j < 26;j++){
					s[ind] = 'a' + j;
					ans += count(s,false);
				}
				cout << ans << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 12252
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()
T = input()

for i in range(len(S)):
    S2 = S[i:] + S[:i]
    if S2 == T:
        print("Yes")
        sys.exit(0)
print("No")



Measured memory_bytes: 6444
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#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=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    int m = 1 << n;
    VL a(m);
    REP(i,m) a[i] = in();
    VL ma1(m), ma2(m, -1), ans(m);
    REP(i,m) ma1[i] = i;
    REP(i,m){
        if (i > 0){
            ans[i] = max(ans[i-1], a[ma1[i]] + a[ma2[i]]);
        }
        REP(j,n){
            if ((i >> j) & 1) continue;
            int x = (i | (1 << j));
            for (ll p : {ma1[i], ma2[i]}){
                if (p == -1 || p == ma1[x] || p == ma2[x]) continue;
                if (a[p] > a[ma1[x]]){
                    ma2[x] = ma1[x];
                    ma1[x] = p;
                }else if (ma2[x] == -1 || a[p] > a[ma2[x]]){
                    ma2[x] = p;
                }
            }
        }
        // cout << "   " << i << "   " << endl;
        // REP(k,m) cout << ma1[k] << " " << ma2[k] << endl;
    }
    FOR(i,1,m-1){
        printf("%lld\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 11264
#include<stdio.h>

int main(){
	int n,m;
	int i,j;
	int mas[1000];
	int me[1000];
	while(1){
	scanf("%d %d",&n,&m);
		if(n==0)return 0;
	for(i=0;i<n;i++)scanf("%d",&mas[i]);
	for(i=0;i<m;i++)scanf("%d",&me[i]);
	int pos=0;
	int t=0;
	while(pos<n-1){
		pos+=me[t++];
		if(pos>=n-1)break;
		pos+=mas[pos];
	}
	printf("%d\n",t);
	}
}

Measured memory_bytes: 1036