akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<algorithm>
#define EPS 1e-6	

struct pt {
	int x, y;
	pt(){};
	pt(int _x, int _y) : x(_x), y(_y){};


	bool operator<(pt p) {
		return(x < p.x || (x == p.x && y < p.y));
	}

	bool operator==(pt p) const {
		return(x == p.x && y == p.y);
	};
};

pt points[100];


typedef std::pair<pt, pt> seg;

inline pt operator-(pt a, pt b) {
	return pt(a.x-b.x, a.y-b.y);
}

inline double cross(pt a, pt b) {
	return(a.x*b.y - a.y*b.x);
}

inline bool ccw(pt a, pt b, pt c) {
	return cross(b-a, c-a) >= 0;
}

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


void find(pt p, int numPoints) {
	double r;
	pt pa, pb;
	bool cut = false;

	// assume that there is a horizontal line ray with 
	// p as its origin in the easterly direction
	for (int i = 0; i < numPoints; ++i) {
		if (p == points[i]) {
			printf("1\n");
			return;
		}
		
		pa = points[i] - p;
		pb = points[(i+1)%numPoints] - p;

		// check that vectors are parallel && 
		// have 0 distance between the two
		// i.e. are collinear
		// printf("%lf %lf\n", cross(pa, pb), dot(pa, pb));
		if (cross(pa, pb) == 0 && dot(pa, pb) <= EPS) {
			printf("1\n");
			return;
		}

		// otherwise check if p-ray cuts across ab
		if (pa.y > pb.y) {
			pt temp = pa;
			pa = pb;
			pb = temp;
		}

		// pa points more up
		// pb points more down
		// i.e. ab is a vaguely vertical interval
		if (pa.y <= 0 && pb.y > 0) {
			// p-ray cuts between a and b
			if (cross(pa,pb) > 0) cut = (!cut);
		}

				
	}
	if (cut) {
		printf("2\n");
	} else {
		printf("0\n");
	}
}

int main() {
	int numPoints, numTests, val, a, b;
	scanf("%d", &numPoints);
	for (int i = 0; i < numPoints; ++i) {
		scanf("%d %d", &a, &b);
		points[i] = pt(a, b);
	}

	scanf("%d", &numTests);
	for (int i = 0; i < numTests; ++i) {
		scanf("%d %d", &a, &b);
		find(pt(a,b), numPoints);
	}

	return 0;
}


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

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

string N;

void D(int lvl, string s)
{
    if (lvl == 0) {cout << s << endl; return;}
    string indent(lvl * 1, '-');
    cout << indent << s << endl;
}

int rec(int k = 0, bool tight = true, int f753 = 0, bool lzero = false)
{
    if (k == N.size()) {
        return f753 == 7 ? 1 : 0;
    }

    int digit = N[k] - '0';

    int res = 0;
    if (k == 0 || lzero) {
        res += rec(k+1, tight && digit == 0, f753, true);
    }
    if (!tight|| digit >= 3) {
        res += rec(k+1, tight && digit == 3, f753 | 1);
    }
    if (!tight || digit >= 5) {
        res += rec(k+1, tight && digit == 5, f753 | 2);
    }
    if (!tight || digit >= 7) {
        res += rec(k+1, tight && digit == 7, f753 | 4);
    }

    return res;
}

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

    cout << rec() <<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int C[300001];

const int O = 998244353;
int add(int a, int b)
{
	return (a + b) % O;
}
int sub(int a, int b)
{
	return (a + O - b) % O;
}
int mul(int a, int b)
{
	return (a * b) % O;
}

int pow(int a, int b)
{
	if (b == 0)
	{
		return 1;
	}
	else if (b == 1)
	{
		return a % O;
	}
	else if (b % 2 == 0)
	{
		int p = pow(a, b / 2);
		return (p * p) % O;
	}
	else
	{
		int p = pow(a, b / 2);
		p = (p * p) % O;
		return (p * a) % O;
	}
}

int divide(int a, int b)
{
	return mul(a, pow(b, O - 2));
}

int N, A, B, K;

signed main()
{
	cin >> N >> A >> B >> K;

	int p = 1;
	C[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		p = divide(mul(p, (N - i + 1)), i);
		C[i] = p;
	}

	int ans = 0;
	int init_a = MIN(N, K / A);
	for (int a = init_a; a >= 0; a--)
	{
		int ama = K - (a * A);
		if (ama % B == 0)
		{
			int b = ama / B;
			if (a <= N && b <= N)
			{
				int n = C[a];
				n = mul(n, C[b]);
				ans = add(ans, n);
			}
		}
	}

	cout << ans << endl;
}






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

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    if(n<b)cout<<a*n/b<<endl;
    else{
        if(a>b)cout<<max(a*n/b-a*(n/b),a*(n-n%b-1)/b-a*((n-n%b-1)/b))<<endl;
        else cout<<a*(b-1)/b<<endl;
    }
    return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

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


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

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13)
        cout<<b;
    if(a<13&&a>=6)
        cout<<b/2;
    if(a<6)
        cout<<"0";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
   
const int INF = (1<<29);
   
class Point{
public:
    double x,y;
   
    Point(double x = 0, double y = 0):x(x),y(y){}
   
    bool operator < (const Point &a)const{
	if(x != a.x) return x < a.x;
	return y < a.y;
    }
};
   
bool compare(Point a, Point b){
    return a.y < b.y;
}
   
double solve(Point *a, int n){
    if(n <= 1) return INF;
    int m = n / 2;
    double xx = a[m].x;
    double d = min(solve(a,m),solve(a+m,n-m));
    inplace_merge(a,a+m,a+n,compare);
   
    vector<Point> v;
    for(int i = 0 ; i < n ; i++){
	if(fabs(a[i].x - xx) >= d) continue;
	int len = (int)v.size();
	for(int j = 0 ; j < len ; j++){
	    double dx = a[i].x - v[len-j-1].x;
	    double dy = a[i].y - v[len-j-1].y;
   
	    if(dy*dy >= d) break;
	    d = min(d,dx * dx + dy * dy);
	}
	v.push_back(a[i]);
    }
    return d;
}
   
int main(){
    int n;
   
    cin >> n;
    Point p[n];
    for(int i = 0 ; i < n ; i++){
	scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    sort(p,p+n);
    cout << solve(p,n) << endl;
    return 0;
}

Measured memory_bytes: 22520
// 提出時に消す


import java.util.Scanner;
import java.util.stream.IntStream;

// 提出時にMainに変更する
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int p[] = IntStream.range(0, n).map(e -> sc.nextInt()).sorted().toArray();

        int ans = 0;
        for (int i = 0; i < k; i++) {
            ans += p[i];
        }

        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 39680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, k, j;
    cin >> n >> k;
    vll a(n), dp(n);
    for(i = 0; i < n; i++)
        cin >> a[i];
    dp[0] = 0;
    for(i = 1; i < k; i++)
    {
        dp[i] = LLONG_MAX;
        for(j = i - 1; j >= 0; j--)
            dp[i] = min(dp[j] + abs(a[i] - a[j]), dp[i]);
    }
    for(i = k; i < n; i++)
    {
        dp[i] = LLONG_MAX;
        for(j = i - 1; j >= i - k; j--)
            dp[i] = min(dp[j] + abs(a[i] - a[j]), dp[i]);
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main()
{
    ll N, K;
    cin >> N >> K;
    ll i = 0;
    while (N >= pow(K, i))
    {
        i++;
    }
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int n,i;
  
  scanf("%d",&n);
  
  int fib[44];
  
  fib[0]=fib[1]=1;
  for(i=2;i<=n;i++)fib[i]=fib[i-1]+fib[i-2];

  printf("%d\n",fib[n]);
  return 0;
}

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

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    int mi = min(min(a,b),c);
    int ma = max(max(a,b), c);
    if((a+b+c-mi-ma == 5)&&(ma==7)){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    



    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
sw=[]
for i in range(2**n):
    l=list(str(bin(i)))
    t=n-len(l[2:])
    if t!=0:
        L=['0'*t]+l[2:]
    else:
        L=l[2:]
    sw.append(''.join(L))

S=[]
K=[]
for i in range(m):
    a=[int(i) for i in input().split()]
    K.append(a[0])
    s=a[1:]
    S.append(s)
p=[int(i) for i in input().split()]

for j in range(m):
    SW=[]
    for h in sw:
        s=0
        for i in range(K[j]):
            if h[S[j][i]-1]=='1':
                s+=1
        if s%2==p[j]:
            SW.append(''.join(h))
    sw=set(sw)&set(SW)

    
print(len(sw))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

ll n;
ll ans = 1;

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

void dfs(vector<pair<ll, int>> &div, int i, ll acc) {
    if (i == div.size()) {
        if (acc == 1) return;
        ll x = n;
        while(x % acc == 0) x /= acc;
        if (x % acc == 1) {
            ans++;
        }
        return;
    }

    auto nxt = div[i];

    rep(j, nxt.se + 1) {
        dfs(div, i + 1, acc * pow(nxt.fi, j));
    }
}

void solve() {
    cin >> n;
    auto div = prime_factor(n - 1);
    for (auto d: div) ans *= d.se + 1;
    ans--;
    div = prime_factor(n);
    vector<pair<ll, int>> X;
    for(auto d : div) X.push_back(d);
    dfs(X, 0, 1);
    cout << ans << endl;
}

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


Measured memory_bytes: 3964
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
    unsigned int key;
    struct node *next;
    struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

void init();
void insert(int);
void deleteNode();
void deleteFirst();
void deleteLast();
void delete(int);
NodePointer listSerach(int);
void printList();

int main(){
    int key, n, a;
    int size=0;
    char command[20];
    
    scanf("%d",&n);
    init();
    //printf("n = %d\n",n);
    for(a = 0; a < n; a++){
        scanf("%s",command);
        //printf("%s",command);
        if(command[0] == 'i'){
            scanf("%d",&key);
            insert(key);
        }
        else if(command[0] == 'd'){
            if(strlen(command) > 6){
                if(command[6] == 'F') deleteFirst();
                else if(command[6] == 'L') deleteLast();
            }
            else{
                scanf("%d",&key);
                delete(key);
            }
        }
        //printList();
    }
    printList();
    return 0;
}

void init(){
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key){
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    x->next = nil->next;
    x->prev = nil;
    nil->next->prev = x;
    nil->next = x;
}

void deleteNode(NodePointer x){
    x->prev->next = x->next; //x = nil->next
    x->next->prev = x->prev;
    free(x);
}

void deleteFirst(){
    NodePointer x;
    x = nil->next;
    if(x == nil) return;
    deleteNode(x);
}

void deleteLast(){
    NodePointer x;
    x = nil->prev;
    if(x == nil) return;
    deleteNode(x);
}

void delete(int key){
    NodePointer x;
    if((x = listSerach(key)) == nil) return;
    deleteNode(x);
}

NodePointer listSerach(int key){
    NodePointer current_node;
    current_node = nil->next;
    while(current_node != nil){
        if(current_node->key == key) return current_node;
        current_node = current_node->next;
    }
    return nil;
}


void printList(){
    NodePointer current_node;
    current_node = nil->next;
    int isfirst = 1;
    while(1){
        if(current_node == nil) break;
        if(isfirst == 0) printf(" ");
        printf("%d",current_node->key);
        current_node = current_node->next;
        isfirst = 0;
    }
    printf("\n");
}


Measured memory_bytes: 32952
n, m, p = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
 
for i in range(m):
    lst[i][2] = - (lst[i][2] - p)

d = [10**100] * (n+1)
d[1] = 0
rep = 0
 
while True:
    update = False
    for edge in lst:
        a,b,c = edge
        if d[a] != 10**100 and d[b] > d[a]+ c:
            if rep >= n:
                d[b] = -10**100
            else:
                d[b] = d[a] + c
            update = True
    if not update:
        break
    rep += 1
    if rep > 2*n:
        break

if d[n] <= - 10**100:
    print(-1)
elif -d[n] < 0:
    print(0)
else:
    print(-d[n])

Measured memory_bytes: 51608
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
x,y=zip(*xy)
x=list(zip(range(n),x))
y=list(zip(range(n),y))
x.sort(key=lambda a:a[1])
y.sort(key=lambda a:a[1])
d=[]
for i in range(n-1):
  d.append([x[i+1][1]-x[i][1],x[i+1][0],x[i][0]])
  d.append([y[i+1][1]-y[i][1],y[i+1][0],y[i][0]])
d.sort(key=lambda a:a[0],reverse=True)
# Union FInd
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

ans=0
uf=UnionFind(n)
while d:
  dist,i,j=d.pop()
  if uf.same(i,j):
    continue
  uf.union(i,j)
  ans+=dist
print(ans)

Measured memory_bytes: 74068
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		// ���̓t�F�[�Y
        long N = long.Parse(Console.ReadLine());

        long cnt = 0;
        long ret = 0;
        while(true)
        {
            // cnt��1�����₵�Ă���
            cnt++;

            // 4�i���ƍl����cnt=(ex)111 ��555��N�𒴂�����I��
            if (stopCount(cnt, N)) break;

            // cnt��753���ł���Α���
            if (is753Num(cnt, N)) ret += 1;
        }
        //�o��
        Console.WriteLine(ret);
    }
    static bool is753Num(long cnt, long N)
    {
        // cnt(3�i���j��0,1,2�����ȏ㌻��Ă����true
        bool exist0 = false, exist1 = false, exist2 = false, exist4 = false;


        while(cnt > 0)
        {
            switch (cnt % 4)
            {
                case 1:
                    exist0 = true;
                    break;
                case 2:
                    exist1 = true;
                    break;
                case 3:
                    exist2 = true;
                    break;
                case 0:
                    exist4 = true;
                    break;
            }
            cnt /= 4;
        }
        bool e = exist0 && exist1 && exist2;

        //Console.WriteLine(cnt + " " + e);
        return (exist0 && exist1 && exist2 && !exist4);
    }

    static bool stopCount(long cnt, long N)
    {
        string S = "";
        //Console.Write(cnt + " " + N + " " );
        while(cnt > 0)
        {
            switch(cnt%4)
            {
                case 1:
                    S = "3" + S;
                    break;
                case 2:
                    S = "5" + S;
                    break;
                case 3:
                    S = "7" + S;
                    break;
            }
            cnt /= 4;
        }
        //Console.WriteLine(S);
        long convCnt = long.Parse(S);
        if (convCnt > N) return true;
        else return false;
    }

}

Measured memory_bytes: 15268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;

int main()
{
  ll n;cin>>n;
  ll hoge;
  for(ll i=0;i<n;i++){
    cin>>hoge;
    if(hoge%2==0){
      if(hoge%3!=0&&hoge%5!=0){
        cout<<"DENIED"<<endl;
        return 0;
      }
    }
  }
  cout<<"APPROVED"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int pow(int a, int i){
	if(i==0) return 1;
	return a*pow(a,i-1);
}

int main(void){
	int n; cin >> n;
	vi md(1,1);
	for(int i=1;;i++){
		int a = pow(6,i);
		if(a>100000) break;
		md.push_back(a);
	}
	for(int i=1;;i++){
		int a = pow(9,i);
		if(a>100000) break;
		md.push_back(a);
	}
	SORT(md);
	vi dp(n+1,INF);
	dp[0] = 0;
	rep(i,n){
		rep(j,md.size()){
			int b = md[j];
			if(i+1-b<0) break;
			dp[i+1] = min(dp[i+1],dp[i+1-b]+1);
		}
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 640
import numpy as np

r,g,b,N=map(int,input().split())
count=0

for i in range(N//r+1):
    for j in range((N-i*r)//g+1):
        if ((N-i*r-j*g)%b==0):
            #print(i,j)
            count+=1

print(count)

Measured memory_bytes: 21660
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

ll n,t[R],ans;
priority_queue <pair<ll,pair<ll,ll>>> q {};

int main()
{
	scanf("%lld", &n);
	for(int i=0;i<n;++i) scanf("%lld", &t[i]);
	sort(t,t+n);
	reverse(t,t+n);
	ans = t[0];
	q.push(mp(t[1],mp(t[0],t[1])));
	q.push(mp(t[1],mp(t[0],t[1])));
	for(int i=2;i<n;++i)
	{
		ll a,b;
		a = q.top().se.fi;
		b = q.top().se.se;
		q.pop();
		//  printf("%lld\n", ans);
		ans+=min(a,b);
		q.push(mp(min(t[i],a),mp(t[i],a)));
		q.push(mp(min(t[i],b),mp(t[i],b)));
	}
	printf("%lld\n", ans);
	return 0;
}


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int n;
    cin >> n;
    ll x = n*800;
    ll y = (n/15)*200;
    cout << x-y << endl;
    return 0;
}



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

int calc_calorie(int a, int b, int c) {
  return a*4 + b*9 + c*4;
}

int main() {
  int N;
  while(cin >> N, N) {
    bool exist = false;
    vector<int> s(N), p(N), q(N), r(N);
    for(int i=0; i<N; i++) {
      cin >> s[i] >> p[i] >> q[i] >> r[i];
    }
    int P, Q, R, C; cin >> P >> Q >> R >> C;

    for(int i=0; i<N; i++) {
      bool ok = true;
      ok &= (p[i] <= P);
      ok &= (q[i] <= Q);
      ok &= (r[i] <= R);
      ok &= (calc_calorie(p[i], q[i], r[i]) <= C);

      if(ok) {
        cout << s[i] << endl;
        exist = true;
      }
    }
    if(!exist) cout << "NA" << endl;
  }
  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define lld         double
#define pb          push_back
#define mp 			make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define PI 		   3.14159265
#define fr(i,a,b)  for(int i=a;i<b;i++)
using namespace std;



int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m,i;
    cin>>n>>m;
    ll g=1;
    for(i=1;i*i<=m;i++)
    {
        if(m%i==0)
        {
            ll x=m/i;
            if(i>=n)
            g=max(g,x);
            if(x>=n)
            g=max(g,i);
        }
    }
    cout<<g;


}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>
using f32 = float;
using f64 = double;
using i8 = int_fast8_t;
using u8 = uint_fast8_t;
using i16 = int_fast16_t;
using u16 = uint_fast16_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
void resolver();
inline void fast_io() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
template <class T>
inline std::vector<T> read_vector() {
    size_t n;
    std::cin >> n;
    std::vector<T> ret(n);
    for (T &i : ret) {
        std::cin >> i;
    }
    return ret;
}
void t_case() {
    i64 t;
    std::cin >> t;
    while (t--) {
        resolver();
    }
}
void single_case() { resolver(); }

int main(int argc, char *argv[]) {
    fast_io();
    // t_case();
    single_case();
}

void resolver() {
    using namespace std;

    i32 n, x, y;
    cin >> n >> x >> y;
    vector<i32> ans(n + 1);
    i32 d = y - x - 1;
    for (i32 i = 1; i <= n; i++) {
        for (i32 j = i + 1; j <= n; j++) {
            if (i == x && j == y) {
                ans[1]++;
            } else if (j <= x || i >= y) {
                ans[j - i]++;
            } else if (i <= x && j >= y) {
                ans[j - i - d]++;
            } else if (i <= x && j >= x) {
                ans[min(j - i, x - i + 1 + y - j)]++;
            } else if (i <= y && j >= y) {
                ans[min(j - i, j - y + 1 + i - x)]++;
            } else {
                ans[min(j - i, i - x + 1 + y - j)]++;
            }
        }
    }
    copy(ans.begin() + 1, ans.begin() + n, ostream_iterator<i32>{cout, "\n"});
}


Measured memory_bytes: 256
// template version 1.7

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define INF 1e18
// #define INF 2147483647
#define MOD 1e9+7
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int solve(){
  int n;cin>>n;
  int t[n];
  int v[n];
  int s = 0;
  rep(i, n){
    cin>>t[i]; 
    s += t[i];
  }
  rep(i, n){ cin>>v[i]; }

  vi upper(2*s+1, INF);
  int time=0;
  rep(i, n){
    rep(j, (2*t[i])+1){
      chmin(upper[time], v[i]);
      if (j!=(2*t[i]))time++;
    }
  }
  // dump(sz(upper), upper);

  vector<double> res(2*s+1);

  double sp=0;
  res[0]=0;
  rep(i, 1, (2*s)+1){
    if (sp<upper[i]) sp+=0.5;
    if (sp>upper[i]) sp=upper[i];
    res[i]=sp;
  }
  // dump(res);

  sp=0;
  res[2*s]=0;
  rrep(i, 0, 2*s){
    if (sp<upper[i]) sp+=0.5;
    if (sp>upper[i]) sp=upper[i];
    chmin(res[i], sp);
  }
  // dump(res);

  double ans=0;
  rep(i, 2*s){
    ans += (res[i]+res[i+1])/4.0;
  }
  printf("%.4f", ans);

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 896
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))

n = int(input())
a = list(map(int, input().split()))

ans=0
now=1
for i in range(n):
    if(a[i]==now):
        ans+=1
        now+=1
if(ans==0):
    print(-1)
else:
    print(n-ans)

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

int main()
{
    string str;
    int az[26] = { 0 };
 
    while (1) {
        if (!getline(cin, str)) break;

        int len = str.length();

        for (int i = 0; i < len; i++) {
            unsigned char c = str.at(i);
            if (isalpha(c)) {
                c = toupper(c) - 'A';
                az[c]++;
            }
        }
    }

    for (int i = 0; i < 26; i++) {
        unsigned char c = 'a' + i;
        cout << c << " : " << az[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

signed main() {
  //int p = 3;
  int p = 37;

  int k = p + 1;
  int n = p * p + p + 1;
  cout << n << ' ' << k << '\n';
  vector<vector<int>> A;
  for (int i = 0; i < p * p; ++i) {
    int a = i % p;
    int b = i / p;
    vector<int> v;
    for (int j = 0; j < p; ++j) {
      v.push_back(1 + (a + b * j) % p + (j + 1) * p);
    }
    v.push_back(b + 1);
    sort(v.begin(), v.end());
    A.push_back(v);
  }
  for (int i = 0; i < p + 1; ++i) {
    vector<int> v;
    for (int j = 0; j < p; ++j) {
      v.push_back(1 + j + p * i);
    }
    v.push_back(n);
    A.push_back(v);
  }

  for (auto v : A) {
    for (auto x : v) {
      cout << x << ' ';
    }
    cout << '\n';
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      vector<int> c;
      set_intersection(A[i].begin(), A[i].end(), A[j].begin(), A[j].end(), back_inserter(c));
      assert((int) c.size() == 1);
    }
  }
}


Measured memory_bytes: 768
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn min2(v: &&[u64]) -> u64 {
    let mut mv = v.to_vec();
    mv.sort();
    mv[1]
}

fn main() {
    read_line();
    let v: Vec<u64> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    
    let count = v.windows(3)
        .filter(|w| w[1] == min2(w))
        .count();
    
    println!("{}", count);
}


Measured memory_bytes: 4352
//Name: Tile
//Level: 2
//Cateogry: 数学
//Note:

/*
 * 線対称かつ点対称なので，左上区画に座標を正規化して考える．
 * 具体的にはfloor(N/2)の区画(大きさが奇数のときは中央を含むため)を考え，たとえばx座標がこの区画の幅をはみ出るときには
 * 元の正方形の右端からの距離を考え，これを左端からの距離として使うと左上区画に入る．
 * y座標も同様．
 * 色の判定は，左上隅から斜めに進んでいき，ある点から下か右に進むと考えればよい．
 */
#include <iostream>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    const int half = (N+1)/2;
    for(int i = 0; i < K; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        if(x >= half) {
            x = N-x-1;
        }
        if(y >= half) {
            y = N-y-1;
        }

        int level = min(x, y);
        cout << (level%3)+1 << endl;
    }
    return 0;
}

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

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

int main(void)
{
    ll n,m; cin>>n>>m;
    vector<vector<ll>> a(n,vector<ll>(m));
    rep(i,n){
        rep(j,m){
            cin>>a[i][j];
        }
    }
    vector<ll> b(m),c(n,0);
    rep(i,m) cin>>b[i];

    rep(i,n){
        rep(j,m){
            c[i]+=a[i][j]*b[j];
        }
    }
    rep(i,n){
        cout<<c[i]<<endl;
    }
    return 0;
} 


Measured memory_bytes: 3196
N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))

AB.sort(key=lambda x: x[1])
# print(AB)
base = AB[0][1]
ans = 1
for ab in AB[1:]:
    if ab[0] < base <= ab[1]:
        continue
    else:
        ans += 1
        base = ab[1]
print(ans)

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const ll MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  // 最短の矢の長さ（or-1）
  // 矢の長さをxとすると
  // l>=N-(x*M)を満たす最低のxが答え
  // N*l/M<=x
  // しかし当然ながら扇風機の範囲がかぶるところが存在する
  // xを順に伸ばして言ってDPに損失を保存していく
  int N,M;cin>>N>>M;
  vector<int> ms(M);
  REP(i,M) cin>>ms[i];

  // 損失にならない場はtrue
  bitset<100000> bs;
  REP(i,M) bs.set(N-1-(ms[i]-1));

  // 長さがiの時の損失の数をdp[i-1]とする
  vector<ll> dp(N,0);
  dp[0] = N-M;

  // 余計なzeroの数
  int red = 100000 - N;

  FOR(n,1,N) {
    bs |= bs>>1;
    dp[n] = 100000 - bs.count()-red;
  }
  // DUMP(dp);

  int Q;cin>>Q;

  // 逆順にして、l+1のlower_bound-begin-1=idxとしたとき、N-idxが答え
  reverse(ALL(dp));

  REP(i,Q) {
    int l;cin>>l;
    if (dp[0]>l) {
      OUT(-1);
    } else {
      ll idx = lower_bound(ALL(dp),l+1)-dp.begin()-1;
      OUT(N-idx);
    }
  }

  return 0;
}


Measured memory_bytes: 4164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int a = Integer.parseInt(br.readLine());
            int b = Integer.parseInt(br.readLine());
            int h = Integer.parseInt(br.readLine());
            System.out.println((a + b) * h / 2);
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
}


Measured memory_bytes: 21332
#include <stdio.h>

int main(void) {
    int a;  //  赤のカードに書かれた整数（1以上7以下）
    int b;  //  緑のカードに書かれた整数（1以上7以下）
    int c;  //  青のカードに書かれた整数（1以上7以下）
    int k;  //  操作可能な回数（1以上7以下）
    
    //  3枚のうちいずれか1枚のカードを選び、書かれた整数を2倍する
    //  赤＜緑＜青になれば成功
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d", &k);
    
    for (int i = 0; i < k; i++) {
        if (c > b && b > a) {
            continue;
        } else if (c <= b) {
            c *= 2;
        } else if (c >= b && b <= a) {
            b *= 2;
        }
    }
    
    if (a < b && b < c) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1616
S = input()
N = len(S)
ans=[0]*N


count=0
for i in range(N):
    if S[i]=="R":
        count+=1
    else:
        ans[i-1] += (count+1)//2
        ans[i] += count//2
        count=0

count=0
for i in range(1,N+1):
    if S[N-i]=="L":
        count+=1
    else:
        ans[N-i] += count//2
        ans[N-i+1] += (count+1)//2
        count=0

[print(x) for x in ans]

Measured memory_bytes: 54108
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
string S;
vector<ll> tree[200010];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll a[200010], b[200010];
    cin >> S;
    ll cA[200010] = {}, cB[200010] = {};
    rep(i,0,M){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        tree[a[i]].push_back(b[i]);
        tree[b[i]].push_back(a[i]);
        if(a[i] == b[i]){
            if(S[a[i]] == 'A'){
                cA[a[i]]++;
            }else{
                cB[a[i]]++;
            }
        }else{
            if(S[a[i]] == 'A'){
                cA[b[i]]++;
            }else{
                cB[b[i]]++;
            }
            if(S[b[i]] == 'A'){
                cA[a[i]]++;
            }else{
                cB[a[i]]++;
            }
        }
    }
    stack<ll> st;
    rep(i,0,N){
        if(cA[i] == 0 || cB[i] == 0){
            st.push(i);
        }
    }
    vector<ll> ans;
    bool check[200010] = {};
    while(not st.empty()){
        ll v = st.top();
        st.pop();
        if(check[v]) continue;
        ans.push_back(v);
        check[v] = true;
        for(auto &e: tree[v]){
            // print(v,e);
            if(e == v) continue;
            if(S[v] == 'A'){
                cA[e]--;
            }else{
                cB[e]--;
            }
            // print(e,cA[e], cB[e]);
            if(cA[e] == 0 || cB[e] == 0){
                if(not check[e]) st.push(e);
            }
        }
    }

    if(ans.size() == N){
        print("No");
    }else{
        print("Yes");
    }





}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// BIT avl cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination segtree st tmp topcoder uf vi 

bool solve(vvi &data, int pos)
{
//    cout << "call : " << pos << endl;
    vb state(data.size(), false);
    rep(i, data.size()) if (data[i][pos]) state[i] = true;

    for (int i = pos-1; i >= 0; i--) {
//    rep(yui, state.size()) cout << state[yui] << " "; cout << endl;
        rep(j, state.size()) {
            if (state[j] && data[j][i]) {
//                cout << "num : " << j << endl;
                rep(k, data.size()) {
                    if (data[k][i]) state[k] = true;
                }
            }
        }
    }

    bool ret = true;
    rep(i, state.size()) ret &= state[i];
    return ret;
}

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

    int n;
    while (cin >> n, n) {
        vvi data(n, vi(31, 0));
        rep(i, n) {
            Int(tmp);
            rep(j, tmp) {
                Int(hoge);
                data[i][hoge] = 1;
            }
        }
//        for (vi i : data) {for (int j : i) cout << j << " "; cout << endl;}

        int ans = -1;
        rep(i, 31) {
            if (solve(data, i)) {
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }

    return 0;
}






Measured memory_bytes: 3104
L, R = map(int, input().split())
if R-L >=2019:
    minimum = 0
else:
    left, right = L%2019, R%2019
    minimum = 2019**2
    for i in range(left, right + 1):
        for j in range(i+1, right+1):
            minimum = min(minimum, i*j%2019)
print(minimum)



Measured memory_bytes: 9168
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 日 10/22 19:58:41 2017
 * Ended  Time*  : 日 10/22 20:12:50 2017
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

inline void OPEN(string s){
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

int n;
int a[105];

LL qwe(LL x, LL y){
	LL ans = 1LL;
	while(y != 0){
		if(y & 1) ans = ans * x;
		x *= x;
		y >>= 1;
	}
	return ans;
}

int main()
{
	while(~scanf("%d", &n)){
		LL cnt1 = 0, cnt2 = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d", &a[i]);
			if(a[i] & 1) cnt1++;
			else cnt2++;
		}
		LL ans = qwe(3LL, (LL)n) - qwe(2LL, cnt2);
		printf("%lld\n", ans);
	}
    return 0;
}


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

int main(){
    int n,k,res=0;
    cin >> n >> k;
    int l[100];
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    sort(l,l+n,greater<int>());
    for(int i=0;i<k;i++){
        res+=l[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair

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

const int MOD = 1e9+7;
const int INF = 1e9;
const int H = 3;
const int W = 3;

bool check(int y, int x) {
  return (0<=y && y<H) && (0<=x && x<W);
}

int main() {
  int c[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[i][j];
    }
  }

  for (int y = 0; y < 3; y++) {
    for (int x = 0; x < 3; x++) {
      for (int hv = 0; hv < 2; hv++) {
        int mn = c[y][x];
        for (int pos = -2; pos <= 2; pos++) {
          int ny = y+(1-hv)*pos, nx = x+hv*pos;
          if (!check(ny, nx)) continue;
          if (c[ny][nx] < mn) mn = c[ny][nx];
        }

        for (int pos = -2; pos <= 2; pos++) {
          int ny = y+(1-hv)*pos, nx = x+hv*pos;
          if (!check(ny, nx)) continue;
          c[ny][nx] -= mn;
        }
      }
    }
  }

  bool ok = true;
  for (int y = 0; y < 3; y++) {
    for (int x = 0; x < 3; x++) {
      if (c[y][x] != 0) ok = false;
    }
  }

  cout << (ok?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int n;
string S[505];
int G[30][30];
int main()
{
    //freopen("data.in","r",stdin);
    while(cin>>n)
    {
        if(n==0) break;

        for(int i=1;i<=n;i++) cin>>S[i];

        memset(G,0,sizeof(G));
        bool ok=true;
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++)
        {
            bool t=true;

            for(int k=0;(k<S[i].size())&&(k<S[j].size());k++)
            {
                if(S[i][k]!=S[j][k])
                {
                    t=false;
                    G[S[j][k]-'a'][S[i][k]-'a']=1;
                    break;
                }
            }
            if(t&&(S[i].size()>S[j].size())) ok=false;
        }

        for(int i=0;i<26;i++)
            for(int j=0;j<26;j++)
                if(i!=j)
            {
                if(G[i][j]==1&&G[j][i]==1) ok=false;
            }
        if(ok) cout<<"yes"<<endl;
        else cout<<"no"<<endl;

    }
    return 0;
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)

typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
int mid(int a,int b,int c){
    if((a < b) ^ (a < c))return a;
    if((b < a) ^ (b < c))return b;
    return c;
}
main(){
    int N,x;
    cin >> N >> x;
    if(x == 1 || x == N * 2 - 1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    vector<int> V(N * 2 - 1);
    rep(i,0,N * 2 - 1){
        V[i] = (x - 1 + i + N) % (N * 2 - 1) + 1;
    }

    rep(i,0,N * 2 - 1){
        cout << V[i] << " \n"[i == N * 2 - 2];
    }

}

Measured memory_bytes: 2304
import sys
import math
from itertools import permutations
from itertools import combinations
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)

X, Y = map(int, input().split())

if (X + Y) % 3:
    print(0)
    exit()

n = (2*X - Y) // 3
m = (-X + 2*Y) // 3

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9 + 7
N = (n + m)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(n+m, m, mod)

print(a)


Measured memory_bytes: 82552
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    if(a > b) {
        out(0);
        re0;
    }

    if(n == 1 && a != b) {
        out(0);
        re0;
    }

    if(n == 1 && a == b) {
        out(1);
        re0;
    }

    out((b*(n-1) + a) - (a*(n-1) + b) + 1);
    re0;
}

Measured memory_bytes: 256