akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int n,ans;
  ans=1;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++)
  {
    if(a.at(i)==a.at(i+1))
    {
      ans=0;
      break;
    }
  }
  if(ans==1)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 3968
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        Integer d[] = new Integer[N];
        
        for (int i = 0; i < N; i++) {
            d[i] = sc.nextInt();
        }
        
        Arrays.sort(d, Comparator.reverseOrder());
        
        int a = 0;
        int cnt = 0;
        
        for (int i = 0; i < N; i++) {
            if (a != d[i]) {
                cnt++;
            }
            a = d[i];
        }
        
        System.out.println(cnt);
    }
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
    public static int N = 0;
    public static int[] p;

    public static void main(String[] args) {

        String[] pStrArray;

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sc.nextLine();

        pStrArray = sc.nextLine().split(" ");
        p = new int[N];
        for (int i=0; i<N; i++) {
            p[i] = Integer.parseInt(pStrArray[i]);
        }

        int compareCount = 0;
        for (int i=0; i<N; i++) {
            if (p[i] != i+1) {
                compareCount++;
            }
        }

        String output = "";
        for (int i=0; i<N; i++) {
            if (compareCount == 0 || compareCount == 2) {
                output = "YES";
            } else {
                output = "NO";
            }
        }
        System.out.println(output);
    }
}


Measured memory_bytes: 23124
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#define _CRT_DISABLE_PERFCRIT_LOCKS

#include <iostream>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <set>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <math.h>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>	
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <thread>
#include <cassert>

using namespace std;

#define ll long long
#define ull unsigned long long
typedef int hv;
#define double long double
#define make(type, x) type x; cin>>x	
#define make2(type, x, y) type x, y; cin>>x>>y
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z
#define make4(type, x, y, z, q) type x, y, z, q; cin>>x>>y>>z>>q
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define PPII pair<PII, int>
#define M7 1000000007ll
#define M9 1000000009ll
#define MFFT 998244353ll 
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define outv(a) for(auto& x: a) cout << x << ' ';

const int MAXN = 500;
int a[MAXN], b[MAXN], n, k;

bool check(int val) {
	int sm = 0;
	for (int i = 0; i < n; ++i) {
		b[i] = a[i] % val;
		sm += b[i];
	}
	sort(b, b + n);
	return accumulate(b, b + n - sm / val, 0) <= k;
}

void Solve() {
	scanf("%d %d", &n, &k);
	int sm = 0;
	for (auto it = a; it != a + n; ++it) {
		scanf("%d", it);
		sm += *it;
	}
	int ans = 1;
	for (int d = 1; d * d <= sm; ++d) {
		if (sm % d) continue;
		if (check(sm / d)) {
			ans = sm / d;
			break;
		}
		if (check(d)) ans = d;
	}
	printf("%d", ans);
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _SUPER_DEFINE
	auto F1 = freopen("input.txt", "r", stdin);
	auto F2 = freopen("output.txt", "w", stdout);
	if (F1 == NULL || F2 == NULL) return 0;
	if (sizeof(int) != 8) cout << "NO LONG!!!\n";
	Solve();
	fflush(stdout);
	while (!cin.eof()) {
		string s = "_";
		do getline(cin, s);
		while (!cin.eof() && !s.empty());
		if (cin.eof()) break;
		FOR(2) cout << endl;
		Solve();
		fflush(stdout);
	}
	fclose(F1), fclose(F2);
#else
	Solve();
#endif
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	char a,b;
	cin >> a >> b;
  
  	if(a==b){
		cout << "=" << endl;
    }else if(a>b){
		cout << ">" << endl;
    }else{
		cout << "<" << endl;
    }

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int N, M, X, Y;
            cin >> N >> M >> X >> Y;
        vector<int> x(N);
        vector<int> y(M);
        int xmax = -100;
        int ymin = 100;
            for(int i = 0; i < N; i++){
                cin >> x.at(i);
                    if(x.at(i) > xmax){
                        xmax = x.at(i);
                    }
            }
            for(int j = 0; j < M; j++){
                cin >> y.at(j);
                    if(y.at(j) < ymin){
                        ymin = y.at(j);
                    }
            }
                //cout << xmax << ymin;
                    if(xmax < ymin){
                        if(Y <= xmax || ymin <= X){
                            //cout << "No War" << endl;
                                //return 0;
                        }else{
                            cout << "No War" << endl;
                                return 0;
                        }
                    }
                        cout << "War" << endl;
    }


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	while (true) {
		cin >> n;
		if (n==0) break;
		
		int count_zero;
		for (count_zero = 0; n>0; n/=5, count_zero += n);
		
		cout << count_zero << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  if(A == B && B == C && A %2 == 0){
    ans = -1;
  }
  else{
    for(int i=0; i<5000000; i++){
      if(A %2 == 1 || B %2 == 1 || C %2 == 1){
        ans = i;
        break;
      }
      int a = A;
      int b = B;
      int c = C;
      A = (b+c)/2;
      B = (a+c)/2;
      C = (a+b)/2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = []

for _ in range(M):
  a, b = map(int, input().split())
  AB.append((a, b))

Rsort = sorted(AB, key=lambda x: x[1])
cnt = 0
R = 0

for a, b in Rsort:
  if a <= R:
    continue
  else:
    cnt += 1
    R = b-1

print(cnt)

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)
#define Ans(s) cout << s << endl;

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int n, d, x;
	cin >> n >> d >> x;

	vector<int> a(n);
	int i;
	rep(i, n) cin >> a[i];

	int ans = 0;

	for (int i = 0; i < n; i++)
	{
		ans++;

		int power = 1;

		while (1)
		{
			if (a[i] * power + 1 <= d) ans++;
			else break;

			power++;
		}
	}

	cout << ans + x << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164

void init(double data[][2]){
	int i;
	double r,arg;

	data[0][0] = 1.0;
	data[0][1] = 1.0;

	arg = PI/4.0;

	for(i = 1;i < 1000;i++){
		r = sqrt((i+2)*1.0);
		arg += asin(1.0/r);
		data[i][0] = r*cos(arg);
		data[i][1] = r*sin(arg);
	}
}

int main(){
	int n;
	double data[1000][2];

	init(data);

	while(1){
		scanf("%d",&n);
		if(n == -1){
			break;
		}

		printf("%.2f\n%.2f\n",data[n-2][0],data[n-2][1]);
	}

	return 0;
}

Measured memory_bytes: 692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 5e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e15
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector< vector<ll> > array_2D;
typedef pair<ll, pair<ll, ll> > ppi;
typedef vector<ll> vi;



int main() {


    ll n, m, k;

    cin >> n >> m >> k;

    vector< vector<ll> > Book(n, vector< ll > (m + 1, 0));

    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j <= m; j++) cin >> Book[i][j];
    }


    // for(int i = 0; i < n; i++) {
    //     for(int j = 0; j <= m; j++) cout << Book[i][j] << " ";
    //     cout << "\n";
    // }

    ll ans = INT_MAX;
    for(ll i = 0; i < (1 << n); i++) {
        // cout << i << "\n";

        vector< ll > Buy(m + 1, 0);
        for(int j = 0; j < n; j++) {

            int flag = i & (1 << j);
            // cerr << "flag " << flag << " j " << j << "\n";
            if(flag) {

                for(int x = 0; x <= m; x++) {
                    // cout << Buy[x] << " " << Book[j][x] << "\n";
                    Buy[x] += Book[j][x];
                }
                // cout << "Hi\n";
            }
        }

        bool f = true;
        for(int j = 1; j <= m; j++) if(Buy[j] < k) f = false;

        if(f) {
            ans = min(ans, Buy[0]);
        }
    }


    if(ans != INT_MAX) {
        cout << ans << "\n";
    }
    else
        cout << -1 << "\n";

    return 0;
}

Measured memory_bytes: 3608
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import Control.Monad

step :: MP.Map B.ByteString Int -> B.ByteString -> MP.Map B.ByteString Int
step mp x = MP.insertWith (+) x 1 mp

step' :: Int -> Int -> Int
step' acc v
    | v == 1 = acc
    | otherwise = acc + sum [1..v-1]

main = do
    n <- readLn :: IO Int
    xs <- V.replicateM n (B.sort <$> B.getLine) :: IO (V.Vector B.ByteString)
    let mp = V.foldl' step MP.empty xs
    print $ MP.foldl step' 0 mp


Measured memory_bytes: 443004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tr1/unordered_map>

using namespace std;

#define FOREACH(var,v) for(__typeof(v.begin()) var = v.begin(); var != v.end(); ++var)

const int NEIGHBOR[13][4] = {
    {2, -1, -1, -1},
    {2, 5, -1, -1},
    {0, 1, 3, 6},
    {2, 7, -1, -1},
    {5, -1, -1, -1},
    {1, 4, 6, 9},
    {2, 5, 7, 10},
    {3, 6, 8, 11},
    {7, -1, -1, -1},
    {5, 10, -1, -1},
    {6, 9, 11, 12},
    {7, 10, -1, -1},
    {10, -1, -1, -1}
};
typedef tr1::unordered_map<long long,int> CacheType;
int field[13];

long long encode() {
    long long res = 0;
    for(int i = 0; i < 13; ++i) {
        res *= 12;
        res += field[i];
    }
    return res;
}

void decode(long long code, int *blank) {
    int *ptr = blank;
    for(int i = 12; i >= 0; --i) {
        field[i] = code % 12;
        if(field[i] == 0) {
            *ptr = i;
            ++ptr;
        }
        code /= 12;
    }
}

struct NullCallback {
    void operator()(long long, int) const {}
};
struct AnsCallback {
    CacheType *cache;
    int ans;
    AnsCallback(CacheType *c) : cache(c), ans(100) {}

    void operator()(long long code, int step) {
        CacheType::const_iterator it = cache->find(code);
        if(it != cache->end()) {
            ans = min(ans, step + it->second);
        }
    }
};

template <class T>
void search(CacheType &cache, T &callback) {
    vector<long long> q[2];
    {
        long long code = encode();
        q[0].push_back(code);
        cache[code] = 0;
        callback(code, 0);
    }
    for(int step = 1; step <= 10; ++step) {
        q[1].clear();
        int buf[2];

        FOREACH(it, q[0]) {
            decode(*it, buf);
            for(int j = 0; j < 2; ++j) {
                const int blank = buf[j];
                for(int dir = 0; dir < 4; ++dir) {
                    if(NEIGHBOR[blank][dir] == -1) break;
                    swap(field[blank], field[NEIGHBOR[blank][dir]]);
                    long long code = encode();
                    CacheType::const_iterator cit = cache.find(code);
                    if(cit == cache.end()) {
                        q[1].push_back(code);
                        cache[code] = step;
                    }
                    swap(field[blank], field[NEIGHBOR[blank][dir]]);
                }
            }
        }
        sort(q[1].begin(), q[1].end());
        q[1].erase(unique(q[1].begin(), q[1].end()), q[1].end());
        q[0].swap(q[1]);
        FOREACH(it, q[0]) {
            callback(*it, step);
        }
    }
}

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

    while(true) {
        for(int i = 0; i < 13; ++i) {
            cin >> field[i];
        }
        if(field[0] == -1) break;

        CacheType c1, c2;
        NullCallback nc;
        search(c1, nc);

        for(int i = 1; i <= 11; ++i) {
            field[i] = i;
        }
        field[0] = field[12] = 0;
        AnsCallback ac(&c1);
        search(c2, ac);
        if(ac.ans > 20) cout << "NA" << endl;
        else cout << ac.ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

int main() {
	double x1, x2, y1, y2, ans;
	cin >> x1 >> y1 >> x2 >> y2;
	ans = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
	ans=sqrt(ans);
	printf("%.10lf", ans);
	return 0;
}

Measured memory_bytes: 3208
#include<stdio.h>

int gcd(long int a, long int b)
{
    while (a%b!=0)
    {
        long int z;
        z = a;
        a = b;
        b = z % b;
    }
    return b;
}

int main()
{
   long int A, B, g;
   scanf("%ld %ld",&A,&B);
   g = gcd(A,B);
   printf("%ld\n",A*B/g);
   return 0;
} 


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1e9+7;

int main() {
   int d,n;
   cin>>d>>n;
   if(n==100)n++;
   for(int i=0;i<d;i++){
        n*=100;
}
cout<<n<<endl;
}


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

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

int main(void)
{
	ll a, b, g, l;
	while (cin >> a >> b)
	{
	    g = gcd(a, b);
	    l = a*b / g;
	    cout << g << " " << l << endl;
	}
}


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

using namespace std;

int main(){
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int poss = 1; //It is true that index i is greater than [0, i -1]
        //Assuming
        for(int j = i - 1; j >= 0; j = j - 1){
            if( a[j] > a[i]){
                 poss = 0; //Our assumption fails
                 break;
            }
        }
        if(poss == 1){
            ans = ans + 1;
        } 
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
from itertools import product, chain
S = input()
ans = 0
if len(S) == 1:
    print(S)
    exit()

for i in product(['+', ''], repeat=len(S) - 1):
    ans += eval(S[0] + ''.join(chain.from_iterable(zip(i, S[1:]))))
print(ans)

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

signed main(){
	char a[5],b[5];
	scanf("%s",a);
	scanf("%s",b);
	int ans=0;
	for(int i=0;i<3;i++){
		if(a[i]==b[i])ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC117A
{
    class Program
    {
        static void Main(string[] args)
        {
            var T = ReadInt;
            var X = ReadInt;
            double ans = (double)T / X;

            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 11220
// Binary Search
#include <stdio.h>

int binarySearch(int*, int, int);

int main(){
  int i, n, q, S[100000], T[50000], count=0;

  // 数列Tに含まれる整数の数と、その内容を入力
  scanf("%d", &n);
  for(i=0; i < n; i++){
    scanf("%d", &S[i]);
  }

  // 数列Sに含まれる整数の数と、その内容を入力
  scanf("%d", &q);
  for(i=0; i < q; i++){
    scanf("%d", &T[i]);
  }

  // 二分探索を実行
  for(i=0; i < q; i++){
    if(binarySearch(S, n, T[i]))count++;
  }

  // 結果の個数を表示
  printf("%d\n", count);

  return 0;
}

int binarySearch(int *A, int n, int key){
  int left=0, right=n, mid;
  while(left < right){
    mid = (left + right) / 2;
    if(key == A[mid]){ // 一致しているとき(見つかったとき)
      return 1;
    }
    else if(key < A[mid]){ // keyがA[mid]より小さいとき
      right = mid; // 探索範囲を前半半分にする
    }
    else{           // keyがA[mid]より大きいとき
      left = mid + 1; // 探索範囲を後半半分にする
    }
  }
  return 0;
}



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

using namespace std;

inline void update(int &x,int y) {
  x=max(x,y);
}

char str[205][205];

int row[205][205],col[205][205];
int f[205][205][205],g[205][205][205];

void pre(int n,int m) {
  for(int i=1;i<=n;i++)
  	for(int j=m;j>0;j--) row[i][j]=((str[i][j]==str[i][j+1])?row[i][j+1]:0)+1;
  for(int i=1;i<=m;i++)
    for(int j=n;j>0;j--) col[j][i]=((str[j+1][i]==str[j][i])?col[j+1][i]:0)+1;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++) {
    	f[i][j][j]=col[i][j];
    	for(int k=j+1;k<=m;k++)
    	  f[i][j][k]=min(f[i][j][k-1],(str[i][k]==str[i][k-1])?col[i][k]:0);
	}
  for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++) {
    	g[i][j][j]=row[j][i];
    	for(int k=j+1;k<=n;k++)
    	  g[i][j][k]=min(g[i][j][k-1],(str[k][i]==str[k-1][i])?row[k][i]:0);
	}
}

int cur1[205][205][205],cur2[205][205][205];

void dp(int n,int m) {
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
      for(int k=j;k<=m;k++) {
	    f[i][j][k]+=f[i+f[i][j][k]][j][k];
	    if (f[i][j][k]) update(cur1[j][i][i+f[i][j][k]-1],k-j+1);
	  }
  for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++)
      for(int k=j;k<=n;k++) {
	    g[i][j][k]+=g[i+g[i][j][k]][j][k];
	    if (g[i][j][k]) update(cur2[j][i][i+g[i][j][k]-1],k-j+1);
	  }
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
      for(int k=m;k>=j;k--) update(f[i][j][k],max(f[i][j][k+1],cur2[i][j][k]));
  for(int i=1;i<=m;i++)
    for(int j=1;j<=n;j++)
      for(int k=n;k>=j;k--) update(g[i][j][k],max(g[i][j][k+1],cur1[i][j][k]));
}

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
  pre(n,m);
  int ans=0;
  while (f[1][1][m]<n) {
  	ans++;
  	dp(n,m);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 129280
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b) {
        int c = a + b;
        int res = 0;
        if (c == 0) {
            cout << 1 << endl;
            continue;
        }
        while (c) {
            c /= 10;
            res ++;
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
a=int(input())
List = list(map(int, input().split()))
List.sort(reverse=True)
res =List[0]
for i in range(1,a-1):
  if i%2 ==0:
    res += List[int(i/2)]
  else:
    res += List[int((i+1)/2)]
print(res)

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

int main(void){
    while(true){
        int n;
        cin >> n;
        if(n == 0){ break; }

        int ans = 0;
        for(int i = 0; i <= n; i++){
            for(int j = i + 2; j <= n; j++){
                int sum = j * (j + 1) / 2 - i * (i + 1) / 2;
                if(sum == n){ ++ans; }
            }
        }

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

Measured memory_bytes: 3088
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def fact(self,n):
        return self.fac[n]

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    n, k = map(int, input().split())
    comb = Combination(10 ** 6)
    MOD = 10 ** 9 + 7
    ans = 0
    if n - 1 <= k:
        ans = comb(n+n-1,n)
    else:
        ans = 0
        for i in range(1,k+1):
            ans += comb(n-1,i) * comb(n,i)
            ans %= MOD
        if k >= 2:
            ans += 1
        ans %= MOD




    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 125128
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[200005];
ll dp[200005][2];
int pre[200005][2];

void solve()
{
    scanf("%s", str);
    int n = strlen(str);
    int i;
    for (i = 0; i < 200005; i++) {
        dp[i][0] = dp[i][1] = -INF;
    }
    dp[0][0] = dp[0][1]=0;
    for (i = 0; i < n; i++) {
        if (str[i] != 'D') {
            if (dp[i + 1][0] < dp[i][0]) {
                dp[i + 1][0] = dp[i][0];
                pre[i + 1][0] = 0;
            }
            if (dp[i + 1][0] < dp[i][1]) {
                dp[i + 1][0] = dp[i][1];
                pre[i + 1][0] = 1;
            }
        }
        if (str[i] != 'P') {
            if (dp[i + 1][1] < dp[i][0] + 2) {
                dp[i + 1][1] = dp[i][0] + 2;
                pre[i + 1][1] = 0;
            }
            if (dp[i + 1][1] < dp[i][1] + 1) {
                dp[i + 1][1] = dp[i][1] + 1;
                pre[i + 1][1] = 1;
            }
        }
    }
    
    //printf("%lld %lld\n", dp[n][0], dp[n][1]);
    vector<int> ans;
    int curr = 0;
    if (dp[n][1] > dp[n][0]) {
        curr = 1;
    }
    ans.push_back(curr);
    for (i = n; i >1; i--) {
        curr = pre[i][curr];
        ans.push_back(curr);
    }

    reverse(ans.begin(), ans.end());
    for (i = 0; i < n; i++) {
        if (ans[i] == 0) printf("P");
        else printf("D");
    }
    printf("\n");

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 8656
#include<iostream>
using namespace std;
long long int dp[3001][3001][4];
long long int g[3001][3001]; 
int main(){
    int r,c,k;
    cin>>r>>c>>k;
    r=3000;
    c=3000;
    for(int i=0; i<3001; i++){
        for(int j=0; j<3001; j++){
            g[i][j]=0;
            for(int kk=0; kk<4;kk++){
                 dp[i][j][kk]=0;
            }}}
    long long int rr,cc,v;
    for(int i=0;i<k;i++){
        cin>>rr>>cc>>v;
        rr-=1;
        cc-=1;
        g[rr][cc]=v;
    }
    for(int i=1;i<r+1;i++){
        for(int j=1;j<c+1;j++){
            for(int k=0;k<4;k++){
                dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
                dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
                if (g[i-1][j-1]>0){
                    if (k>0){
                        if (dp[i][j][k]<dp[i][j-1][k-1]+g[i-1][j-1]){
                            dp[i][j][k]=dp[i][j-1][k-1]+g[i-1][j-1];
                        }}
                    if (dp[i][j][1]<dp[i-1][j][k]+g[i-1][j-1]){
                        dp[i][j][1]=dp[i-1][j][k]+g[i-1][j-1];
                    }       
                }
            }
        }
    } 
    long long int ans=0;
    for (int kk=0; kk<4; kk++){
        ans=max(ans,dp[r][c][kk]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 355436
#include<stdio.h>
int main()
{
	int x,i,j;
	scanf("%d",&x);
	for(i=0;i<120;i++)
	{
		for(j=i+1;j<=120;j++)
		{
			if(j*j*j*j*j-i*i*i*i*i==x)
			{
				printf ("%d %d",j,i);
				break;
			}
			if(j*j*j*j*j+i*i*i*i*i==x)
			{
				printf("%d %d",j,-i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1732
while True:
    m,f,r = map(int,input().split())
    if m==f==r==-1:
        exit()
    if m==-1 or f==-1:
        print("F")
        continue
    p = m + f
    if 80 <= p:
        print("A")
    elif 65 <= p:
        print("B")
    elif 50 <= p:
        print("C")
    elif 30 <= p:
        if f == -1:
            print("F")
        if 50 <= r:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX


struct segment_tree {
    int seguki[1048572],p=524286;
    void update(int x, int diff) {
        x += p;
        seguki[x] += diff;
        while(x) {
            x = (x-1) / 2;
            seguki[x] += diff;
        }
    }
    int count(int l, int r) {
        int diff = r-l+1,now=l+p,size=1;
        while(true) {
            if (now%2 && size*2 <= diff) {
                now = (now-1) / 2;
                size *= 2;
            } else {
                int ans = seguki[now];
                l += size;
                if (l==r+1) return ans;
                else return ans+count(l,r);
            }
        }
    }
};


int n,q;
string s;
segment_tree st[26];



signed main() {
    cin >> n >> s >> q;
    rep(i,n) {
        s[i] -= 'a';
        st[s[i]].update(i,1);
    }
    rep(i,q) {
        int a;
        cin >> a;
        if (a == 1) {
            int b;
            char c;
            cin >> b >> c;
            --b;
            c -= 'a';
            st[s[b]].update(b,-1);
            st[c].update(b,1);
            s[b] = c;
        }
        else {
            int l,r,cnt=0;
            cin >> l >> r;
            --l, --r;
            rep(j,26) if (st[j].count(l,r) != 0) cnt++;
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 213892
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node{
  int p, l, r;
};
struct Node T[MAX];

int n, depth[MAX], height[MAX];

void Depth(int, int);
int Height(int);
int Sibling(int);
void print(int);

int main()
{
  int i;
  int id, left, right, tmp=0;

  scanf("%d", &n);
  
  for( i = 0 ; i < n ; i++ ) T[i].p = NIL;
  
  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d%d", &id, &left, &right);
    T[id].l = left;
    T[id].r = right;
    if( left != NIL ) T[left].p = id;
    if( right != NIL ) T[right].p = id;
  }

  for( i = 0 ; i < n ; i++ ) if( T[i].p == NIL ) tmp = i;

  Depth(tmp, 0);
  Height(tmp);

  for( i = 0 ; i < n ; i++ ) print(i);

  return 0;
}

void Depth(int u, int p)
{
  if( u == NIL ) return;
  depth[u] = p;
  
  Depth(T[u].l, p+1);
  Depth(T[u].r, p+1);
}

int Height(int u)
{
  int h1=0, h2=0;
  
  if( T[u].l != NIL ) h1 = Height(T[u].l) + 1;
  if( T[u].r != NIL ) h2 = Height(T[u].r) + 1;

  if( h1 > h2 ) return height[u] = h1;
  else return height[u] = h2;
}

int Sibling(int u)
{
  if( T[u].p == NIL ) return NIL;
  if( T[T[u].p].l != u && T[T[u].p].l != NIL ) return T[T[u].p].l;
  if( T[T[u].p].r != u && T[T[u].p].r != NIL ) return T[T[u].p].r;
  return NIL;
}

void print(int node)
{
  int count=0;

  printf("node %d: parent = %d, sibling = %d, ", node, T[node].p, Sibling(node));

  if( T[node].l != NIL ) count++;
  if( T[node].r != NIL ) count++;
  
  printf("degree = %d, depth = %d, height = %d, ", count, depth[node], height[node]);

  if( T[node].p == NIL ) printf("root\n");
  else if( T[node].l == NIL && T[node].r == NIL ) printf("leaf\n");
  else printf("internal node\n");
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> m;
    if(s[0] == '0')m.push_back(0);
    int cnt = 0;
    char c = s[0];
    rep(i, n){
        if(c != s[i]){
            m.push_back(cnt);
            cnt = 1;
            c = s[i];
            if(i == n - 1)m.push_back(cnt);
        }else{
            cnt++;
            if(i == n - 1)m.push_back(cnt);
        }
    }
    if(s[n-1] == '0')m.push_back(0);
    int l = m.size() / 2;
    if(l <= k)cout << n << endl;
    else{
        vector<int> sum(2 * l + 2, 0);
        sum[0] = 0;
        rep(i, 2*l+1)sum[i+1] = sum[i] + m[i];
        int ans = 0;
        rep(i, l - k + 1)ans = max(ans, sum[2*(i+k)+1]-sum[2*i]);
        cout << ans << endl;
    }
    
}

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

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	vector<int>B(N);
	vector<pair<int, int>>AB(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i];
		AB[i] = make_pair(A[i], B[i]);
	}
	vector<int>C(N);
	vector<int>D(N);
	vector<pair<int, int>>CD(N);
	for (int i = 0; i < N; ++i) {
		cin >> C[i] >> D[i];
		CD[i] = make_pair(C[i], D[i]);
	}
	sort(AB.begin(), AB.end());
	sort(CD.begin(), CD.end());

	vector<bool>used(N, false);
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		pair<int, int>B = CD[i];
		int maxy = -1;
		int index = -1;
		for (int j = 0; j < N; ++j) {
			if ((false == used[j]) && (AB[j].second < B.second) && (AB[j].first < B.first) && (maxy < AB[j].second)) {
				index = j;
				maxy = AB[j].second;
			}
		}
		if (-1 != index) {
			used[index] = true;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string S;
    cin >>S;
    int l=S.size();
    int min=999;
    for(int i=0;i<l-2;i++){
        int k=abs((S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0')-753);
        if(k<min){
            min=k;
        }
    }
    cout <<min<<endl;
    return 0;
}

Measured memory_bytes: 384
S = input()
n = 0
nsl = [0]
for c in S:
  if c == "<":
    n += 1
  else:
    n = 0
  nsl.append(n)
n = 0
nsr = [0]
for c in reversed(S):
  if c == ">":
    n += 1
  else:
    n = 0
  nsr.append(n)
nsr.reverse()
#print(nsl)
#print(nsr)
r = 0
for i in range(len(S)+1):
  r += max(nsl[i], nsr[i])
print(r)


Measured memory_bytes: 78680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	}
}



Measured memory_bytes: 101240
def d_derangement(N, P):
    ans = 0
    is_target = True  # 要素番号iはチェックする必要があるか否か
    for i in range(N):
        if P[i] == i + 1 and is_target:
            # p_i=iならp_{i+1}とスワップすれば条件を満たす
            ans += 1
            is_target = False  # i+1番目はチェックする必要がない
        else:
            is_target = True
    return ans

N = int(input())
P = [int(i) for i in input().split()]
print(d_derangement(N, P))

Measured memory_bytes: 13880
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define D 365
#define INF 1001001001
typedef long long ll;
ll calcSat(int *tmpt, int s[][26], int *c) {
	int last[26] = {0};
	ll tmpSat = 0;
	for (int i = 0; i < D; i++) {
		tmpSat += s[i][tmpt[i] - 1];
		last[tmpt[i] - 1] = i + 1;
		for (int j = 0; j < 26; j++) {
			tmpSat -= (c[j] * (i + 1 - last[j]));
		}
		/**
		printf("%lld\n", tmpSat);
		/**/
	}
	return tmpSat;
}
int main() {
	clock_t start = clock(), now = clock();
	srand(629);
	scanf("%*d");
	int c[26], s[D][26];
	int t[D] = {0};
	ll bestSat = 0;
	for (int i = 0; i < 26; i++) {
		scanf("%d", &c[i]);
	}
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", &s[i][j]);
		}
	}
	/**/
	int last[26] = {0};
	for (int i = 0; i < D; i++) {
		ll bestNowSat = -INF;
		int bestType = 0;
		for (int j = 0; j < 26; j++) {
			ll tmpSat = 0;
			tmpSat += s[i][j];
			for (int k = 0; k < 26; k++) {
				if (k != j) {
					tmpSat -= (c[k] * (i + 1 - last[k]));
				}
			}
			if (bestNowSat < tmpSat) {
				bestNowSat = tmpSat;
				bestType = j;
			}
		}
		bestSat += bestNowSat;
		t[i] = bestType + 1;
		last[bestType] = i + 1;
	}
	int loopCnt = 0;
	while (loopCnt != 215000) {
		int pos1 = rand() % D;
		int pos2 = rand() % D;
		int oldt1 = t[pos1];
		int oldt2 = t[pos2];
		t[pos1] = rand() % 26 + 1;
		t[pos2] = rand() % 26 + 1;
		ll tmpSat = calcSat(t, s, c);
		if (tmpSat > bestSat) {
			bestSat = tmpSat;
		} else {
			t[pos1] = oldt1;
			t[pos2] = oldt2;
		}
		now = clock();
		loopCnt++;
	}
	// fprintf(stderr, "loop:%d", loopCnt);
	// printf("%lld\n", bestSat);

	for (int i = 0; i < D; i++) {
		printf("%d\n", t[i]);
	}
	return 0;
}


Measured memory_bytes: 1832
N, K = map(int, input().split())
A = list(map(lambda a: int(a) - 1, input().split()))

now = 0
for d in range(64):
    if ((1 << d) & K) > 0:
        now = A[now]
    A = [A[a] for a in A]
print(now + 1)


Measured memory_bytes: 171364
N,K = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]
MOD = 10**9+7

def mul(L,R):
    ret = [[0]*N for _ in range(N)]
    for i,row in enumerate(L):
        for j,col in enumerate(zip(*R)):
            ret[i][j] = sum(a*b for a,b in zip(row,col)) % MOD
    return ret

M = A
Z = [[int(i==j) for j in range(N)] for i in range(N)]
while K:
    if K%2:
        Z = mul(Z,M)
    M = mul(M,M)
    K //= 2

print(sum(sum(row) for row in Z) % MOD)

Measured memory_bytes: 3372
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] teleportation = new int[n];
        long stepsBeforeCycle = 0;
        int slow, fast;

        for(int i = 0; i < n; i++)
        	teleportation[i] = sc.nextInt() - 1;
        slow = fast = 0;

        while(true) {
        	slow = teleportation[slow];
        	fast = teleportation[teleportation[fast]];
        	if(slow == fast)
        		break;
        }
        int loopLen = 1;
        while(teleportation[fast] != slow) {
        	fast = teleportation[fast];
        	loopLen++;
        }

        fast = slow;
        slow = 0;
        while(slow != fast) {
        	slow = teleportation[slow];
        	fast = teleportation[fast];
        	stepsBeforeCycle++;
        }

        if(k <= stepsBeforeCycle) {
        	// slow = 0;
        	// while(k > 0) {
        	// 	slow = teleportation[slow];
        	// 	k--;
        	// }
        	// System.out.println(slow + 1);
        	// return;
        	System.out.println(solve(teleportation, k, 0));
        }
        else {
        	k -= stepsBeforeCycle;
        	k %= loopLen;
        	System.out.println(solve(teleportation, k, slow));
        	// while(k > 0) {
        	// 	slow = teleportation[slow];
        	// 	k--;
        	// }
        	// System.out.println(slow + 1);
        }

    }
    public static int solve(int[] teleportation, long k, int slow) {
    	while(k > 0) {
        		slow = teleportation[slow];
        		k--;
        	}
        return slow + 1;
    }
}

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

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>b){
		cout<<"a > b"<<endl;
	}else if(a<b){
		cout<<"a < b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3104
// Copyright 2019 yaito3014
#include <bits/stdc++.h>
using namespace std;
using namespace literals;

int main(){
	cin.tie(nullptr); ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<pair<int, int>> XL(N);
	for(auto& v : XL){
		int X, L;
		cin >> X >> L;
		v = make_pair(X+L, X-L);
	}
	sort(begin(XL), end(XL));
	int prev = INT_MIN;
	int ans = 0;
	for(auto& v : XL){
		if(v.second < prev)continue;
		++ans;
		prev = v.first;
	}
	cout << ans << endl;
}


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

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int x1;
int y1;
int x2;
int y2;
cin>>x1>>y1>>x2>>y2;
//if(x1==x2){
  //         cout<<x1-(abs(y2-y1))<<" "<<y2<<" "<<x1-(abs(y2-y1))<<" "<<y1;
//}
//else if(y1==y2){
  //         cout<<x2<<" "<<y1+(abs(x1-x2))<<" "<<x1<<" "<<y1+(abs(x1-x2));
//}
//else{
           int r=x2-x1;
           int f=y2-y1;
           cout<<x2-f<<" "<<y2+r;
           int o=((x2-f)+x1)-x2;
           int e=((y2+r)+y1)-y2;
           cout<<" "<<o<<" "<<e;
//}
return 0;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement
import sys
input = sys.stdin.readline
N,M,Q=(int(x) for x in input().rstrip('\n').split())
ress=[x for x in combinations_with_replacement(range(1,M+1),N)]
res_dict = {}
for i in range(Q):
  res_dict[i] = [int(x) for x in input().rstrip('\n').split()]
res_s = []
for i in ress:
  match=0
  for x in range(Q):
    if i[res_dict[x][1]-1]-i[res_dict[x][0]-1]==res_dict[x][2]:
      match += res_dict[x][3]
  res_s.append(match)
print(max(res_s))

Measured memory_bytes: 25232
def resolve():
	n, m, x = map(int, input().split())
	c_seq = []
	a_seq = []
	ans = float('inf')
	for i in range(n):
		c, *a = map(int, input().split())
		c_seq.append(c)
		a_seq.append(a)
	for i in range(1 << n):
		pay = 0
		skill = [0]*m
		for j in range(n):
			if i >> j & 1:
				pay += c_seq[j]
				for k in range(m):
					skill[k] += a_seq[j][k]
		ok = True
		for y in skill:
			if x > y:
				ok = False
		if ok:
			ans = min(ans, pay)
	print(ans if ans < float('inf') else -1)
resolve()

Measured memory_bytes: 9216
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD


def way3(ball, box):
    """ball: True / box: True / constraints: 1 or more
    -> ans = (包除原理)
    """
    if ball < box:
        return 0
    ans = 0
    for i in range(box + 1):
        ans += pow(-1, i, MOD) * comb.combination(box, i) * pow(box - i, ball, MOD)
        ans %= MOD
    return ans


n, k = map(int, input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 4, MOD)

print(way3(n, k))


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

int main(void) {

    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;

}


Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int A, P;
  cin >> A >> P;
  cout << (A*3+P)/2 << '\n';
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;

#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld\n",x)
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define F first
#define S second
#define f(i,n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

const ll mod = 1000000007;
const ll inf = (ll)5e16;
const ld eps = 1e-12;
const ll N = 100005;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}
ll n, p[N][20], h[N], subtree[N], d[N];
vector < pl > g[N];
void dfs(ll u, ll pre)
{
    p[u][0] = pre;
    for(ll i = 1; i <= LOGN; i++)
    {
        if(p[u][i - 1])
        {
            p[u][i] = p[p[u][i - 1]][i - 1];
        }
    }
    h[u] = h[pre] + 1;
    subtree[u]++;
    f(i, g[u].size())
    {
        ll v = g[u][i].F;
        if(v == pre)
        {
            continue;
        }
        d[v] = d[u] + g[u][i].S;
        dfs(v, u);
        subtree[u] += subtree[v];
    }
}
ll lca(ll u, ll v)
{
    if(u == v) return u;
    if(h[u] < h[v])
    {
        swap(u, v);
    }
    for(ll i = LOGN; i >= 0 ; i--)
    {
        if((p[u][i]) && h[p[u][i]] >= h[v])
        {
            u = p[u][i];
        }
    }
    if(u == v)
    {
        return v;
    }
    for(ll i = LOGN; i >= 0; i--)
    {
        if(p[u][i] != p[v][i])
        {
            u = p[u][i];
            v = p[v][i];
        }
    }
    return p[v][0];
}
ll dist(ll x, ll y)
{
    ll l = lca(x, y);
    return d[x] + d[y] - 2 * d[l];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    f(i, n - 1)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        g[a].pb({b, c});
        g[b].pb({a, c});
    }
    ll q, k;
    dfs(1, 0);
    cin >> q >> k;
    while(q--)
    {
        ll x, y;
        cin >> x >> y;
        ll ans = dist(x, k) + dist(y, k);
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  if(n%2==0) {
    ll x=n,y=n,z=n/2;
    pr(x,y,z);
  } else {
    REP(x,1,3501) {
      REP(y,1,3501) {
        ll d=x/__gcd(x,y)*y;
        d=d/__gcd(d,n)*n;
        ll a=d/n*4,xx=d/x,yy=d/y;
        ll z=a-xx-yy;
        if(z<0) continue;
        ll d2=__gcd(z,d);
        z/=d2;
        d/=d2;
        if(z==1) {
          pr(x,y,d);
          return;
        }
      }
    }
  }
}

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

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

int main() {
	int N, K;
	std::cin >> N >> K;
	std::vector<int> snuke(N);
	for (int i = 0; i < K; i++) {
		int d;
		std::cin >> d;
		for (int j = 0; j < d; j++) {
			int A;
			std::cin >> A;
			snuke[A - 1]++;
		}
	}
	int answer = 0;
	for (int i = 0; i < N; i++) {
		if (snuke[i] == 0) answer++;
	}
	std::cout << answer << std::endl;
	return 0;
}

Measured memory_bytes: 3640