akhauriyash/Code-Regression huggingface dataset:
use std::io;

fn main() {
    loop {
        let input = input_number();
        let m = input[0];
        let f = input[1];
        let r = input[2];
        if (m, f, r) == (-1, -1, -1) {
            break;
        }

        if m == -1 || f == -1 {
            println!("F");
        } else if m + f >= 80 {
            println!("A");
        } else if m + f >= 65 {
            println!("B");
        } else if m + f >= 50 {
            println!("C");
        } else if m + f >= 30 && r >= 50 {
            println!("C");
        } else if m + f >= 30 {
            println!("D");
        } else {
            println!("F");
        }
    }
}

#[allow(dead_code)]
fn input_number() -> Vec<i64> {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (char, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: char = iter.next().unwrap().chars().nth(0).unwrap();
    let n: usize = iter.next().unwrap().parse().unwrap();
    (c, n)
}



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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	int n , w ; cin >> n >> w;
	vector<ll> weight(110), value(110);
	rep(i,n){
		cin >>weight[i] >> value[i];
	}
	//Dp table
	vector<vector<ll>> dp(110,vector<ll>(100100));
	rep(i,110){
		rep(j,100100){
			dp[i][j] = 0;
		}
	}

	//i番目の品物を取る選択肢
	rep(i,n){
		for(int sum_w = 0 ;sum_w <= w ; sum_w ++){
			//選択するとき
			if(sum_w - weight[i] >= 0){
				chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]] +value[i]);
			}
			//選択しないっていうのもあり
			chmax(dp[i+1][sum_w],dp[i][sum_w]);//ここ何やってんの
		}
	}
	cout <<dp[n][w]<<endl;
}



Measured memory_bytes: 87296
n = gets.to_i
c = [1, 2, 3, 4, 5, 6, 7, 8, 9]
f = 9
if n > 9
  pre = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  tmp = []
  while f < n
    tmp = []
    pre.each do |c|
      tmp << c * 10 + c%10 - 1 if c%10 != 0
      tmp << c * 10 + c%10
      tmp << c * 10 + c%10 + 1 if c%10 != 9
      f += 2 if c%10 == 0 || c%10 == 0
      f += 3 if c%10 != 0 && c%10 != 9
    end
    pre = tmp.dup
    c << pre
  end

end

puts c.flatten.uniq.sort[n-1]


Measured memory_bytes: 20088
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int n;
  cin >> n;
  cout << fixed << setprecision(15) << ceill(n / 2.0) / n;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> p(n);
  int ans = 0;
  
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  
  int mini = p[0];
  for(int i=0; i<n; i++){
    if(p[i]<=mini){
      mini = p[i];
      ans++;
    }
  }
  cout << ans << endl;
}

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

signed main() {
  int h,w,a,b;
    scanf("%d%d%d%d",&h,&w,&a,&b);
    	std::string s(a,'0');
    	std::string t(w-a,'1');
  		std::string S(a,'1');
  		std::string T(w-a,'0');
  for(int i=0;i<h;++i){
    if(i<b){
    	printf("%s%s\n",s.c_str(),t.c_str());
    }
    else{
    	printf("%s%s\n",S.c_str(),T.c_str());
    }
  }
}

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

int main() {
    vector<int> p = {2, 3, 5, 7, 11, 13, 17};
    set<int> st;
    for(int i = 1; i <= 100; i++) {
        for(int i = 0)
    }
    string s;
    map<char, int> mp;
    bool prime[105] = {};
    for(int j = 0, i = 2; i < 105; i++) {
        if(!prime[i]) {
            mp['A' + j++] = i;
            for(int k = i + i; k < 105; k += i)
                prime[k] = 1;
        }
    }
    while(cin >> s) {
        printf("%d %d\n", 105, (int)s.size() - 1);
        for(int i = 1; i < (int)s.size(); i++) {
            printf("%d%c", mp[s[i - 1]] * mp[s[i]], " \n"[i == (int)s.size() - 1]);
        }
    }
    while(1) {
        double a, b;
        scanf("%lf%lf", &a, &b);
        printf("%f\n", a / b);
    }
    while(1) {
        double x, sum = 0, cnt = 0;
        char c;
        while(1) {
            scanf("%lf%c", &x, &c);
            cnt += 1.0; sum += x;
            if(c != ' ') break;
        }
        printf("%f\n", sum / cnt);
    }
    return 0;
}
*/
#include <functional>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> mp(n, vector<int>(m));
    for(int i = 0; i < n; i++) {
        string s; cin >> s;
        for(int j = 0; j < m; j++) {
            mp[i][j] = s[j] ^ 48;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            //cout << mp[i][j] << " \n"[j == m - 1];
        }
    }
    function<int(int)> cal = [&](int S) {
        //cout << "Test : " << S << '\n';
        vector<int> v, cnt(n, 0);
        int ret = __builtin_popcount(S);
        for(int i = 0; i < (n - 1); i++) {
            if(S & (1 << i)) {
                v.push_back(i);
            }
        }
        v.push_back(n - 1);
        for(int i = 0; i < m; i++) {
            int pre = -1;
            for(auto it : v) {
                int val = 0;
                for(int j = pre + 1; j <= it; j++) val += mp[j][i];
                if(val > k) {
                    return __INT_MAX__;
                }
                pre = it;
            }
        }
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                cnt[j] += mp[j][i];
            }
            int pre = -1;
            bool flag = false;
            for(auto it : v) {
                int val = 0;
                for(int j = pre + 1; j <= it; j++) val += cnt[j];
                if(val > k) {
                    //cout << "Get -->" << val << " on " << i << '\n';
                    flag = true;
                    break;
                }
                pre = it;
            }
            if(flag) {
                ret++;
                //cout << i << '\n';
                for(int j = 0; j < n; j++) {
                    cnt[j] = mp[j][i];
                }
            }
        }
        return ret;
    };
    int ans = __INT_MAX__;
    for(int i = 0; i < (1 << (n - 1)); i++) ans = min(ans, cal(i));
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int x, y;
    cin >> x >> y;
    for (int t = 0; t <= x; t++) {
        if (2*t + 4*(x-t) == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

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

N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

ans = A1[0] + sum(A2)
cur = ans
for i in range(N-1):
    cur -= A2[i]
    cur += A1[i+1]
    ans = max(ans, cur)
print(ans)

    

Measured memory_bytes: 7976
#include<stdio.h>
#define swap(x, y) {int z; z=y; y=x; x=z;}
int main()
{
	int a, b, c, i, div=0;
	scanf("%d %d %d", &a, &b, &c);
	for(i=a;i<=b;i++)
	{
		if(c%i == 0)
		{
			div++;
		}
	}
	printf("%d\n", div);
	return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;
int M = 100100100;
using namespace std;
int main()
{
	int n;
	cin >> n;
	int maxx = 0;
	int sum = 0;
	vector<ll> h(n);
	for (int i = 0;i < n;i++) {
		cin >> h[i];
	}
	for (int i = 1;i < n;i++) {
		if (h[i - 1] >=h[i]) {
			sum++;
			if (i != n - 1)
				continue;
		}
		maxx = max(maxx, sum);
		sum = 0;
	}
	cout << maxx;
}



Measured memory_bytes: 4024
using System;

class Program
{
  static void Main(string[] args)
  {
    int[] chk = new int[26];
    string s = Console.ReadLine();
    foreach (char c in s)
    {
      int idx = c - 'a';
      chk[idx]++;
    }
    string rtn = "None";
    for (int i = 0; i < 26; i++)
    {
      if (chk[i] == 0)
      {
        rtn = ((char)('a' + i)).ToString();
        break;
      }
    }
    Console.WriteLine(rtn);
  }
}


Measured memory_bytes: 26176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String[] card = new String[N];
		for(int i=0;i<N;i++){
			card[i] = sc.next();
		}
		
		String[] B = new String[N];
		String[] S = new String[N];
		for(int i=0;i<N;i++){
			B[i]=card[i];
			S[i]=card[i];
		}
		
		bubbleSort(B, N);
		selectionSort(S,N);
		
		//??????
		for(int i=0;i<N-1;i++){
			System.out.print(B[i]+" ");
		}
		System.out.println(B[N-1]);
		System.out.println("Stable");

		for(int i=0;i<N-1;i++){
			System.out.print(S[i]+" ");
		}
		System.out.println(S[N-1]);
		if(isStable(B,S,N)){
			System.out.println("Stable");
		}else{
			System.out.println("Not stable");
		}

	}
	
	public static void bubbleSort(String[] c,int N){
		for(int i=0;i<N-1;i++){
			for(int j=N-1;j>i;j--){
				int vj0=Integer.parseInt(c[j-1].substring(1,2));
				int vj1=Integer.parseInt(c[j].substring(1,2));
				if(vj1<vj0){
					String temp=c[j];
					c[j]=c[j-1];
					c[j-1]=temp;
				}
			}
		}
	}
	
	public static void selectionSort(String[] c,int N){
		for(int i=0;i<N-1;i++){
			int minj=i;
			for(int j=i;j<N;j++){
				int cj=Integer.parseInt(c[j].substring(1,2));
				int cmin=Integer.parseInt(c[minj].substring(1,2));
				if(cj<cmin) minj=j;
			}
			String temp=c[i];
			c[i]=c[minj];
			c[minj]=temp;
		}
	}
	
	public static boolean isStable(String[] b,String[] s, int N){
		boolean fstable = true;
		for(int i=0;i<N;i++){
			if(!b[i].equals(s[i])) fstable=false;
		}
		return fstable;
	}

}

Measured memory_bytes: 26428
#include<stdio.h>

#define N 100

int main(){
  int n;
  int A[N],v;
  int i,j,k;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  
  for(i=1;i<n;i++){
    for(k=0;k<n-1;k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[n-1]);
    
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
  }
  for(k=0;k<n-1;k++){
      printf("%d ",A[k]);
      
    }
  printf("%d\n",A[n-1]);
  return 0;
}



Measured memory_bytes: 2144
let s = read_line () in
let len = String.length s in
Scanf.scanf " %d" (fun q ->
    let buf = Array.make 500000 ' ' in
    String.iteri (fun i v -> buf.(i + 200000) <- v) s;
    let rec loop qq rev first last =
        if qq > 0 then (
            let t = Scanf.scanf " %d" (fun t -> t) in
            if t = 1 then (
                loop (qq - 1) (not rev) first last
            ) else (
                let f, c = Scanf.scanf " %d %c" (fun f c -> f, c) in
                match f, rev with
                | 1, false
                | 2, true -> (buf.(first - 1) <- c; loop (qq - 1) rev (first - 1) last)
                | _ -> (buf.(last + 1) <- c; loop (qq - 1) rev first (last + 1))
            )
        ) else (
            let len = last - first + 1 in
            let s =
                if rev then
                    String.init len (fun i -> buf.(last - i))
                else
                    String.init len (fun i -> buf.(first + i))
            in
            print_endline s
        )
    in
    loop q false 200000 (200000 + len - 1);
)

Measured memory_bytes: 9344
/***** ??????????????????????????? *****/

// ???????§???????????????????????§£?????????????????????????????°??§?????????
// ?????? |V| - 1 ??????????????????????????????????????????????????????????????????????????¨????????´??????
// V ????????§?????´??°??????????????? ??? ????????????????????????????????????


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define INF 999999999

// ????????¨???????????????????¨???????????§???????
struct Edge {
    int to, cost;
    Edge(int s, int d) : to(s), cost(d) {}
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;


// ???????????°V, ????????°E?????°????????????????????? s ???????????????????????????????????????????????¢????±???????
vector<int> bellman(Graph &G, int s) {
    // ???????????°??¨????????°?????°??????
    int V = G.size();
    vector<int> d(V);
    for(int i=0; i<V; i++) d[i] = INF;
    d[s] = 0;

    while(true) {
        bool update = false;
        for(int i=0; i<V; i++) {
            for(int j=0; j<G[i].size(); j++) {
                Edge e = G[i][j];
                if(d[i] != INF && d[e.to] > d[i] + e.cost) {
                    d[e.to] = d[i] + e.cost;
                    update = true;
                }
            }
        }
        if(!update) break;
    }
    return d;
}

/*
// ??°?????????????????????????????????????????????????????????
bool find_negative_loop() {

}
*/

int main() {
    int V, E, r;
    cin >> V >> E >> r;
    // Graph??????????????????????????°????????????
    Graph G(V);

    int s,t,d;
    rep(i,0,E) {
        cin >> s >> t >> d;
        G[s].push_back(Edge(t, d));
    }

    vector<int> ans = bellman(G, r);
    rep(i,0,ans.size()) (ans[i] != INF) ? cout << ans[i] << endl : cout << "INF" << endl;
    return 0;
}

Measured memory_bytes: 10176
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

struct Point{
	double x,y;
};

double GetDist(Point p,Point q){
	double a,b;
	a = p.x-q.x; b = p.y-q.y;
	return sqrt(a*a+b*b);
}

int main(){
	Point P[20];
	double ans=0;
	for(int i=0;scanf("%lf,%lf",&P[i].x,&P[i].y)!=EOF;i++){
		if(i>=2){
			double a,b,c;
			a = GetDist(P[0],P[i-1]);
			b = GetDist(P[i-1],P[i]);
			c = GetDist(P[i],P[0]);
			double z = (a+b+c)/2;
			ans += sqrt(z*(z-a)*(z-b)*(z-c));
		}
	}
	printf("%lf\n",ans);
}

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

struct P{
  char a;
  int n;
  bool operator ==(const P &p)const{
    return (a==p.a)&&(n==p.n);
  }
};

int main(){
  string t,p;
  vector<P> a,b;
  cin>>t>>p;
  if(t.size()>=p.size()){
    
    int cnt=0,num=0;
    P tmp;
    tmp.a=t[0];
    while(t.size()!=cnt){
      if(tmp.a==t[cnt])num++;
      else {
	tmp.n=num;
	a.push_back(tmp);
	num=1;
	tmp.a=t[cnt];
      }
      cnt++;
    }
    tmp.n=num;
    a.push_back(tmp);
    
    tmp.a=p[0];
    cnt=num=0;
    while(p.size()!=cnt){
      if(tmp.a==p[cnt])num++;
      else {
	tmp.n=num;
	b.push_back(tmp);
	num=1;
	tmp.a=p[cnt];
      }
      cnt++;
    }
    tmp.n=num;
    b.push_back(tmp);
    /*
    for(int i=0;i<a.size();i++){
      cout<<a[i].a<<" "<<a[i].n<<endl;
    }
    cout<<endl;
    for(int i=0;i<b.size();i++){
      cout<<b[i].a<<" "<<b[i].n<<endl;
    }
    */
    if(a.size()<b.size())return 0;
    if(b.size()==1){
      int ans=0;
      for(int i=0;i<a.size();i++){
	if(a[i].a==b[0].a){
	  for(int j=0;j<=a[i].n-b[0].n;j++)cout<<ans+j<<endl;
	}
	ans+=a[i].n;
      }
    }else{
      int ans=0;
      for(int i=0;i<a.size()-b.size()+1;i++){
	int f=0;
	for(int j=0;j<b.size();j++){
	  if(j==0||j==b.size()-1){
	    if(a[i+j].a!=b[j].a||a[i+j].n<b[j].n){
	      f=1;
	      break;
	    }
	  }else if(!(a[i+j]==b[j])){
	    f=1;
	    break;
	  }
	}
	if(!f)cout<<ans+a[i].n-b[0].n<<endl;
	ans+=a[i].n;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 12624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n, m;
	cin >> n >> m;
	VE<P<int>> info(m);
	rep(i, m) {
		cin >> info[i].second >> info[i].first;
	}
	sort(all(info));
	int ans = 0;
	int now = 0;
	rep(i, m) {
		if (now <= info[i].second) {
			now = info[i].first;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N ,count;
  string S;
  cin >> N ;
  count = 0;
  for(int i = 0 ; i < N ; i++){
    cin >> S;
    if (S =="Y"){
      cout << "Four" << endl;
      exit(0);
  	}
  }
  cout << "Three" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, d;
    cin >> h >> w >> d;
    string s = "RYGB";
    if (d % 2 == 1) {
        rep(i, 0, h) {
            rep(j, 0, w) cout << s[(i + j) % 4];
            cout << endl;
        }
        return 0;
    }

    vector<vector<int>> ans(d, vector<int>(w + d, -1));
    // while (ans[0].size() < w + d) {
    //     ans[0].emplace_back(tmp);
    //     rep(i, 1, d) {
    //         if (ans[0].size() == w + d) break;
    //         ans[0].emplace_back(tmp + 2);
    //     }
    //     tmp ^= 1;
    // }
    int sp = 0, cnt = 1;
    rep(q, 0, d / 2) {
        int tmp = 0, pos = sp;
        while (pos < w + d) {
            rep(i, 0, cnt) {
                if (0 > pos + i || pos + i >= w + d) continue;
                ans[q][pos + i] = tmp;
            }
            rep(i, cnt, d) {
                if (0 > pos + i || pos + i >= w + d) continue;
                ans[q][pos + i] = tmp + 2;
            }
            tmp ^= 1;
            pos += d;
        }
        cnt += 2;
        sp--;
    }
    rep(q, d / 2, d) {
        rep(i, 0, w) {
            ans[q][i] = 2 ^ ans[q - d / 2][i + d / 2];
        }
    }
    debug(ans);
    int tt = 0;
    rep(i, 0, h) {
        rep(j, 0, w) cout << s[ans[i % d][j] ^ tt];
        cout << endl;
        if (i % d == d - 1) tt ^= 1;
    }
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    string s, t;
    cin >> s >> t;

    string ans = "";
    rep (i, N+1) {
        ans = s.substr(0, i)+t;
        if (ans.substr(0, N) == s) {
            break;
        }
    }

    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"-1\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 5005;

ll dp[maxn][maxn];

signed main(){
    IOS();
    int n; cin>>n;
    vector<pii> v(n);
    for (int i = 0; i<n; ++i){
        cin>>v[i].f>>v[i].s;
    }
    sort(ALL(v) , [&](pii a, pii b){return a.f+a.s < b.f+b.s;});
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = 0;
    int re = 0;
    for (int i = 0; i<n; i++) {
        for (int k = 1; k<=n; k++) {
            dp[i+1][k] = dp[i][k];
            if (v[i].f >= dp[i][k-1]) dp[i+1][k] = min(dp[i+1][k], dp[i][k-1] + v[i].s);
            if (i==n-1 && dp[i+1][k] != 0x3f3f3f3f3f3f3f3f) {
                re = max(re, k);
            }
        }
    }
    cout<<re<<endl;
}


Measured memory_bytes: 196096
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(s: str):
    print(s[0] + str(len(s)-2) + s[-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
解説AC=True

n,k=map(int,input().split())
cnt=0

if k==0:
    print(n*n)
    exit()

for b in range(k+1,n+1):
    ans=(b-k)*(n//b)+max(0,n%b-k+1)
    cnt+=ans
    
    
print(cnt)

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

int main() {
  string n;
  cin >> n;
  
  for(int i = 0; i<3; i++) {
    if(n.at(i) == '1') {
      cout << "9";
    }
    else if(n.at(i) == '9') {
      cout << "1";
    }
  }
}



Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>

int main(void){
    int i=0;
    char c[1300];

    while(1){
        scanf("%c",&c[i]);

        if(c[i]=='\n')break;

        if(c[i]>=97)
        {
            printf("%c",toupper(c[i]));
        }
        else
        {
            printf("%c",tolower(c[i]));
        }

        i++;
    }
    printf("\n");
    return 0;
 }

Measured memory_bytes: 524
#include<stdio.h>

int main() {

    int N, p, max= -1, sum= 0;
    scanf("%d", &N);
    
    for(int m=1; m<=N; m++)
    {
        scanf("%d", &p);
        if(p >= max)
            max= p;
        sum+= p;
    }
    int s= sum-(max/2);
    printf("%d\n", s);
    return 0;

}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

ll A[100000], B[100000];

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

    int N;
    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i] >> B[i];
    }

    reverse(A, A+N);
    reverse(B, B+N);

    ll added = 0ll, res = 0ll;
    for(int i=0;i<N;++i){
        ll x = (A[i] + added) % B[i];
        x = x > 0 ? B[i] - x : 0;
        res += x;
        added += x;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9+7;
const int N  = 1e6+1;
vi isprime(N, 1);
vi min_div(N);

ll power(ll x, ll a)
{
    if(a==0)return(1);
    int z = power(x, a/2);
    z*=z;
    if(a%2)z*=x;
    return(z);
}

void sieve()
{
    isprime[0]=0;
    isprime[1]=0;
    int num = 2;
    while (num*num<N)
    {
        if(isprime[num])
        {
            min_div[num]=num;
            int no = num*num;
            while(no<N)
            {
                isprime[no]=0;
                min_div[no]=num;
                no+=num;
            }
        }
        num+=1;
    }
    while(num<N)
    {
        if(isprime[num])min_div[num]=num;
        num++;
    }    
}
 
int main()
{   
    fastio
    sieve();
    int n;
    cin>>n;
    vi arr(n);
    vvi factors(n);
    for (int i = 0; i < n; i++)
    {
        cin>>arr[i];
        int div , num = arr[i];
        while(num>1)
        {
            div = min_div[num];
            factors[i].push_back(div);            
            while(num%div==0)num/=div;            
        }
    }
    bool pairwise = true, check = true;
    map<int, int>m ;
    int gc = arr[0];
    for(int x : factors[0])m[x]=1;
    for (int i = 1; i < n; i++)
    {
        gc=__gcd(gc, arr[i]);
        if(check)
        {
            for (int x : factors[i])
            {
                if(m.find(x)!=m.end())
                {
                    pairwise=false;
                    check = false;
                    break;
                }
                m[x]=1;
            }
        }     
    }
    if(pairwise)
        cout<<"pairwise coprime"<<endl;
    else if (gc==1) 
        cout<<"setwise coprime"<<endl;
    else 
        cout<<"not coprime"<<endl;    
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

ll f(ll b, ll n){
	if(n < b) return n;
	else return f(b, n/b) + (n % b);
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	ll n, s;
	cin >> n >> s;

	if(n == s){
		cout << n + 1 << endl;
		return 0;
	}else if(n < s){
		puts("-1");
		return 0;
	}

	for(ll b=2; b*b <= n; b++){
		if(f(b, n) == s){
			cout << b << endl;
			return 0;
		}
	}

	ll ans = INF;
	for(ll p=1; p*p < n; p++){
		if((n-s)%p == 0){
			ll b = (n-s)/p + 1;
			if(f(b, n) == s){
				ans = min(ans, b);
			}
		}
	}


	if(ans == INF){
		puts("-1");
	}else{
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
S = list(input())

turn = 0
count_0 = 0
count_1 = 0

for char in S:
    if(turn % 2 == 0):
        if(char == '0'):
            count_0 += 1
        else:
            count_1 += 1
    else:
        if(char == '0'):
            count_1 += 1
        else:
            count_0 += 1
    turn += 1

if(count_0 < count_1):
    print(count_0)
else:
    print(count_1)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;


ll H, W;
string s[444];
ll clr[444][444];

vector<P> g[444][444];

void dfs(ll c, ll x, ll y) {
  clr[x][y]=c;
  ll i;
  
  for(i=0; i<g[x][y].size(); i++) {
    P p=g[x][y][i];
    
    if(clr[p.first][p.second]!=-1) continue;
    dfs(c, p.first, p.second);
  }
  
}


int main(void) {
  cin >> H >> W;
  ll i, j;
  
  for(i=0; i<H; i++) {
    cin >> s[i];
    s[i]+='x';
  }
  s[H]=string(W+1, 'x');
  
  
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(s[i][j]!=s[i+1][j]) {
        g[i][j].push_back({i+1, j});
        g[i+1][j].push_back({i, j});
      }
      
      if(s[i][j]!=s[i][j+1]) {
        g[i][j].push_back({i, j+1});
        g[i][j+1].push_back({i, j});
      }
    }
  }
  
  memset(clr, -1, sizeof(clr));
  ll c=0;
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(clr[i][j]!=-1) continue;
      
      dfs(c, i, j);
      c++;
    }
  }
  
  ll bc[444*444]={};
  ll wc[444*444]={};
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(clr[i][j]==-1) continue;
      
      if(s[i][j]=='#') bc[clr[i][j]]++;
      if(s[i][j]=='.') wc[clr[i][j]]++;
    }
  }
  
  ll ans=0;
  for(i=0; i<444*444; i++) {
    ans+=bc[i]*wc[i];
  }
  
  pt(ans);
}






Measured memory_bytes: 29696
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle { int f[N2], space, MD; };

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz) {
  int sum = 0;
  for ( int i = 0; i < N2; i++ ) {
    if ( pz.f[i] == N2 ) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

bool isSolved() {
  for ( int i = 0; i < N2; i++ ) if ( state.f[i] != i + 1 ) return false;
  return true;
}


bool dfs(int depth, int prev) {
  if ( state.MD == 0 ) return true;
  if ( depth + state.MD > limit ) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for ( int r = 0; r < 4; r++ ) {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
    if ( max(prev, r)-min(prev, r) == 2 ) continue;
    tmp = state;
    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
    swap(state.f[tx * N + ty], state.f[sx * N + sy]);
    state.space = tx * N + ty;
    if ( dfs(depth + 1, r) ) { path[depth] = r; return true; }
    state = tmp;
  }

  return false;
}

string iterative_deepening(Puzzle in) {
  in.MD = getAllMD(in);

  for ( limit = in.MD; limit <= LIMIT; limit++ ) {
    state = in;
    if ( dfs(0, -100) ) {
      string ans = "";
      for ( int i = 0; i < limit; i++ ) ans += dir[path[i]];
      return ans;
    }
  }

  return "unsolvable";
}

int main() {
  for ( int i = 0; i < N2; i++ )
    for ( int j = 0; j < N2; j++ )
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for ( int i = 0; i < N2; i++ ) {
    cin >> in.f[i];
    if ( in.f[i] == 0 ) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    if(n%1000==0){
        cout<<0<<endl;
    }else{
        cout<<1000-n%1000<<endl;
    }
    
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

class combination
{
public:
  vector<ll> fac, finv, inv;

  combination(ll M)
  {
    fac = vector<ll>(M, 1);
    finv = vector<ll>(M, 1);
    inv = vector<ll>(M, 1);

    for (ll i = 2; i < M; i++)
    {
      fac.at(i) = fac.at(i - 1) * i % MOD;
      inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
      finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
    }
  }

  ll P(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * finv.at(N - K) % MOD;
  }

  ll C(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * (finv.at(K) * finv.at(N - K) % MOD) % MOD;
  }

  ll H(ll N, ll K)
  {
    return C(N + K - 1, K);
  }
};

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  combination com(N + 10);

  ll ans = 0;
  for (ll i = 0, j = N - 1; i < N; i++, j--)
  {
    ll m = com.C(N - i - 1, K - 1);
    ll M = com.C(N - j - 1, K - 1);

    ans -= A.at(i) * m % MOD, ans += MOD, ans %= MOD;
    ans += A.at(i) * M % MOD, ans %= MOD;

    //cerr << m << " " << M << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  if(a < b)return gcd(b, a);
  return gcd(b, a%b);
}
ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}
int main()
{
  int n;
  cin >> n;
  ll ans = 1;
  ll tmp;
  REP(i,n){
    cin >> tmp;
    ans = lcm(ans,tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s;
    string str,str1;
    t=1;
    while(t--)
    {
          string str1;
          cin>>str1;
          int f=0;
          rep(i,0,str1.size())
          {
          	if(str1[i]=='7')
          	{
          		f=1;
          		break;
          	}
          }
          if(f==1)
          	cout<<"Yes"<<endl;
          else
          	cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#define REP(i,n) for (int i = 0 ; i < (int)n ; i++)
typedef long long ll;

int main(){
    char s[100];
    char t[100];
    int count = 0;
    scanf("%s",s);
    scanf("%s",t);

    REP(i,strlen(s)){
        if( s[i] == t[i] ){
            count++;
        }
    }

    if(count == strlen(s)){
        printf("Yes\n");
    }else
    {
        printf("No\n");
    }
}

Measured memory_bytes: 1660
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    ll K;
    int N;
    in2(K, N);

    vll A(N);
    inN(A, N);

    vll D(N);
    rep(i, N - 1) D[i] = A[i + 1] - A[i];

    D[N - 1] = A[0] + (K - A[N - 1]);

    ll ans = K;
    rep(i, N)
    {
        chmin(ans, K - D[i]);
    }

    outl(ans);
    return 0;
}

Measured memory_bytes: 6352
n=input()
a=list(map(int,input().split()))
ans=10**18
for s in -1,1:
  c=0
  if a[0]*s<0:c=abs(s-a[0])
  elif a[0]*s>0:s=a[0]
  else:c=1
  for i in a[1:]:
    if s<0:
      b=-s+1
      c+=max(0,b-i)
      s+=max(i,b)
    else:
      b=-s-1
      c+=max(0,i-b)
      s+=min(i,b)
  ans=min(ans,c)
print(ans)

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  const ll INF = 1LL<<60;
  ll ans = INF;
  int N, M, X; cin>>N>>M>>X;
  vector<int> C(N, 0);
  vector<vector<int> > A(N, vector<int>(M, 0));
  REP(i,N) {
    cin>>C[i];
    REP(j,M) cin>>A[i][j];
  }
  REP(pat,  (1<<N)) {
    vector<int> deg(M,0);
    ll sum = 0;
    REP(i,N) {
      if((pat >> i) & 1) {
	sum += C[i];
	REP(j,M) deg[j] += A[i][j];
      }
    }
    bool ok = true;
    REP(i,M) {
      if(deg[i] < X) {
	ok = false; break;
      } 
    }
    if(ok) chmin(ans, sum);
  }
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3188
# from functools import lru_cache

n = int(input())


# @lru_cache(maxsize=None)
# def dp(num, typ, mod=10 ** 9 + 7):
#     print(num, typ)
#     if num == 1:
#         if typ == 1:  # contain 0 not 9
#             return 1
#         elif typ == 2:  # contain 9 not 0
#             return 1
#         elif typ == 3:  # not contain
#             return 8
#         elif typ == 0:
#             return 0

#     if typ == 0:
#         return (dp(num - 1, 1) + dp(num - 1, 2) + dp(num - 1, 0) * 10) % mod
#     elif typ == 1:  # contain 0 not 9
#         return (dp(num - 1, 1) * 9 + dp(num - 1, 3)) % mod
#     elif typ == 2:  # contain 9 not 0
#         return (dp(num - 1, 2) * 9 + dp(num - 1, 3)) % mod
#     elif typ == 3:  # not contain
#         return (dp(num - 1, 3) * 8) % mod


# print(dp(n, 0))

dp = [[0 for j in range(4)] for i in range(n + 1)]

mod = 10 ** 9 + 7
for i in range(1, n + 1):
    for j in range(4):
        if j == 0:
            dp[i][j] = (dp[i - 1][0] * 10 + dp[i - 1][1] + dp[i - 1][2]) % mod
            if i == 1:
                dp[i][j] = 0
        elif j == 1:
            dp[i][j] = (dp[i - 1][1] * 9 + dp[i - 1][3]) % mod
            if i == 1:
                dp[i][j] = 1
        elif j == 2:
            dp[i][j] = (dp[i - 1][2] * 9 + dp[i - 1][3]) % mod
            if i == 1:
                dp[i][j] = 1
        elif j == 3:
            dp[i][j] = (dp[i - 1][3] * 8) % mod
            if i == 1:
                dp[i][j] = 8

print(dp[n][0])



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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

int main() {
  int i;
  string s, t;
  cin >> s;
  int n = s.size();
  int idx = 0;
  for (i=0; i<n; i++) {
    if (idx==0 && s[i]=='A') {
      t += 'A';
      idx = (idx+1) % 2;
    } else if (idx==1 && s[i]=='Z') {
      t += 'Z';
      idx = (idx+1) % 2;
    }
  }

  if (t.size() < 2)
    t = "-1";
  else if (t[t.size()-1]=='A')
    t = t.substr(0, t.size()-1);

  cout << t << endl;

	return 0;
}

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

int main(void) {
    long n;
    cin >> n;

    vector<long> a(n);
    for(auto &e: a) cin >> e;

    vector<long> b(n+1);
    for(long i=1; i<=n; i++)
        b[i] = b[i-1] + a[i-1];


    long r = 1e18;
    for(long i=2; i<=n-2; i++) {
        // 0 1 ... i-1 | i ... n-1
        long ls = b[i], rs = b[n] - b[i];
        for(long lls : {
                *prev(upper_bound(b.begin(), b.begin()+i+1, ls/2)),
                *lower_bound(b.begin(), b.begin()+i+1, ls/2),
                })
        for(long rls : {
                *prev(upper_bound(b.begin()+i+1, b.end(), ls + rs/2)) - ls,
                *lower_bound(b.begin()+i+1, b.end(), ls + rs/2) - ls,
                }) {
            long lrs = ls - lls;
            long rrs = rs - rls;

            long mx = max({lls, lrs, rls, rrs});
            long mn = min({lls, lrs, rls, rrs});

            r = min(r, mx-mn);
        }
    }
    cout << r << endl;
}


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

using namespace std;

int gcd(int a,int b){
    int tmp,r;
    if(b>a){
        tmp=a;
        a=b;
        b=tmp;
    }

    while ((r=a%b)) {
        a = b;
        b = r;
    }

    return b;
}

int main(){
    int n=0;
    long long ans=0;
    //char s[200];
    //bool flag = false;
    //vector<int> a(N,0);

    cin >> n;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                ans += gcd(gcd(i+1,j+1),gcd(k+1,j+1));
            }
        }
    }

    cout << ans << endl;
    //cout << ( (flag) ? "Yes" : "No" ) << endl;
}


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

int main()
{
    long long t,n,m,i,j,k,x=0,y=0,z;
    cin>>n;string s;
    cin>>s;
    long long a[n+5],b[n+5];

    for(i=0;i<n;i++){
        if(s[i]=='W'){
            x++;

        }
        else{

            y++;

        }
    }
    long long xx=0,yy=y,ans=x+y+1;
    for(i=0;i<n;i++){
        if(s[i]=='E'){
            yy--;
            z=yy+xx;
            ans=min(z,ans);
        }
        else{
            z=yy+xx;
            ans=min(z,ans);
            xx++;
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 900
#include<stdio.h>

int main(void)
{
 int n,m,x,a[100],i,j,s=0,c=0;
 scanf("%d%d%d", &n,&m,&x);

 for(i=0;i<m;i++)
  scanf("%d", &a[i]);

  for(i=x;i<n;i++){
   for(j=0;j<m;j++)
     if(i==a[j]) s++;
  }
 for(i=x;i>0;i--){
    for(j=0;j<m;j++)
      if(i==a[j]) c++;
 }

 if(s<c) printf("%d\n", s);
 else printf("%d\n", c);

 return 0;
}                                                              


Measured memory_bytes: 128
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    if(N%(A+B) >= A){
      System.out.print((N/(A+B))*A + A);
    }else{
      System.out.print((N/(A+B))*A + N%(A+B));
    }
  }
}

Measured memory_bytes: 23380
#include <cstdio>

int main() {
  int N, K, X, Y;
  scanf("%d %d %d %d", &N, &K, &X, &Y);

  if (N <= K) {
    printf("%d\n", X*N);
  } else {
    printf("%d\n", X*K+Y*(N-K));
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count=0;
  for(int a=0;a<=A;a++) {
    for(int b=0;b<=B;b++) {
      for(int c=0;c<=C;c++) {
        if(a*500+b*100+c*50 == X)
          count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int n,m; cin >> n >> m;
    vector<int> s(m),c(m);

    for(int i = 0;i < m;i ++){
        cin >> s.at(i) >> c.at(i);
    }

    if(m == 0){
        if(n == 1) cout << 0 << endl;
        if(n == 2) cout << 10 << endl;
        if(n == 3) cout << 100 << endl;
        return 0;
    }

    for(int i = 0;i < m-1;i ++){
        for(int j = 1;i + j < m;j ++){
            if(s.at(i) == s.at(i+j) && c.at(i) != c.at(i+j)){
                cout << -1 << endl;
                return 0;
            }
        }
    }

    vector<int> ans(n);
    ans.at(0) = 1;
    for(int i = 0;i < m;i ++){
        ans.at(s.at(i) -1) = c.at(i);
    }

    if(n > 1 && ans.at(0) == 0){
        cout << -1 << endl;
        return 0;
    }

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







Measured memory_bytes: 256